forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/rockchip/rockchip_rgb.c
....@@ -68,7 +68,8 @@
6868 };
6969
7070 struct rockchip_rgb_data {
71
- u32 max_dclk_rate;
71
+ u32 rgb_max_dclk_rate;
72
+ u32 mcu_max_dclk_rate;
7273 const struct rockchip_rgb_funcs *funcs;
7374 };
7475
....@@ -129,7 +130,9 @@
129130 struct rockchip_rgb {
130131 u8 id;
131132 u32 max_dclk_rate;
133
+ u32 mcu_pix_total;
132134 struct device *dev;
135
+ struct device_node *np_mcu_panel;
133136 struct drm_panel *panel;
134137 struct drm_bridge *bridge;
135138 struct drm_connector connector;
....@@ -137,7 +140,6 @@
137140 struct phy *phy;
138141 struct regmap *grf;
139142 bool data_sync_bypass;
140
- bool is_mcu_panel;
141143 bool phy_enabled;
142144 const struct rockchip_rgb_funcs *funcs;
143145 struct rockchip_drm_sub_dev sub_dev;
....@@ -277,6 +279,15 @@
277279 s->output_mode = ROCKCHIP_OUT_MODE_P565;
278280 s->output_if = VOP_OUTPUT_IF_RGB;
279281 break;
282
+ case MEDIA_BUS_FMT_RGB565_2X8_LE:
283
+ case MEDIA_BUS_FMT_BGR565_2X8_LE:
284
+ s->output_mode = ROCKCHIP_OUT_MODE_S565;
285
+ s->output_if = VOP_OUTPUT_IF_RGB;
286
+ break;
287
+ case MEDIA_BUS_FMT_RGB666_3X6:
288
+ s->output_mode = ROCKCHIP_OUT_MODE_S666;
289
+ s->output_if = VOP_OUTPUT_IF_RGB;
290
+ break;
280291 case MEDIA_BUS_FMT_RGB888_3X8:
281292 case MEDIA_BUS_FMT_BGR888_3X8:
282293 s->output_mode = ROCKCHIP_OUT_MODE_S888;
....@@ -323,7 +334,7 @@
323334 {
324335 struct rockchip_rgb *rgb = encoder_to_rgb(encoder);
325336
326
- if (rgb->is_mcu_panel) {
337
+ if (rgb->np_mcu_panel) {
327338 struct rockchip_mcu_panel *mcu_panel = to_rockchip_mcu_panel(rgb->panel);
328339
329340 mcu_panel->prepared = true;
....@@ -358,11 +369,22 @@
358369 {
359370 struct rockchip_rgb *rgb = encoder_to_rgb(encoder);
360371 struct device *dev = rgb->dev;
372
+ struct drm_display_info *info = &rgb->connector.display_info;
361373 u32 request_clock = mode->clock;
362374 u32 max_clock = rgb->max_dclk_rate;
375
+ u32 bus_format;
376
+
377
+ if (info->num_bus_formats)
378
+ bus_format = info->bus_formats[0];
379
+ else
380
+ bus_format = MEDIA_BUS_FMT_RGB888_1X24;
363381
364382 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
365383 request_clock *= 2;
384
+
385
+ if (rgb->np_mcu_panel)
386
+ request_clock *= rockchip_drm_get_cycles_per_pixel(bus_format) *
387
+ (rgb->mcu_pix_total + 1);
366388
367389 if (max_clock != 0 && request_clock > max_clock) {
368390 DRM_DEV_ERROR(dev, "mode [%dx%d] clock %d is higher than max_clock %d\n",
....@@ -444,16 +466,18 @@
444466 return 0;
445467 }
446468
447
-static int rockchip_mcu_panel_init(struct rockchip_rgb *rgb, struct device_node *np_mcu_panel)
469
+static int rockchip_mcu_panel_init(struct rockchip_rgb *rgb)
448470 {
449471 struct device *dev = rgb->dev;
450
- struct device_node *port, *endpoint, *np_crtc, *remote;
472
+ struct device_node *np_mcu_panel = rgb->np_mcu_panel;
473
+ struct device_node *port, *endpoint, *np_crtc, *remote, *np_mcu_timing;
451474 struct rockchip_mcu_panel *mcu_panel = to_rockchip_mcu_panel(rgb->panel);
452475 struct drm_display_mode *mode;
453476 const void *data;
454477 int len;
455478 int ret;
456479 u32 bus_flags;
480
+ u32 val;
457481
458482 mcu_panel->enable_gpio = devm_fwnode_gpiod_get_index(dev, &np_mcu_panel->fwnode,
459483 "enable", 0, GPIOD_ASIS,
....@@ -544,6 +568,8 @@
544568 if (remote) {
545569 np_crtc = of_get_next_parent(remote);
546570 mcu_panel->np_crtc = np_crtc;
571
+
572
+ of_node_put(np_crtc);
547573 break;
548574 }
549575 }
....@@ -553,6 +579,31 @@
553579 DRM_DEV_ERROR(dev, "failed to find available crtc for mcu panel\n");
554580 return -EINVAL;
555581 }
582
+
583
+ np_mcu_timing = of_get_child_by_name(mcu_panel->np_crtc, "mcu-timing");
584
+ if (!np_mcu_timing) {
585
+ np_crtc = of_get_parent(mcu_panel->np_crtc);
586
+ if (np_crtc)
587
+ np_mcu_timing = of_get_child_by_name(np_crtc, "mcu-timing");
588
+
589
+ if (!np_mcu_timing) {
590
+ DRM_DEV_ERROR(dev, "failed to find timing config for mcu panel\n");
591
+ of_node_put(np_crtc);
592
+ return -EINVAL;
593
+ }
594
+
595
+ of_node_put(np_crtc);
596
+ }
597
+
598
+ ret = of_property_read_u32(np_mcu_timing, "mcu-pix-total", &val);
599
+ if (ret || val == 0) {
600
+ DRM_DEV_ERROR(dev, "failed to parse mcu_pix_total config\n");
601
+ of_node_put(np_mcu_timing);
602
+ return -EINVAL;
603
+ }
604
+ rgb->mcu_pix_total = val;
605
+
606
+ of_node_put(np_mcu_timing);
556607 }
557608
558609 return 0;
....@@ -741,9 +792,10 @@
741792 .get_modes = rockchip_mcu_panel_get_modes,
742793 };
743794
744
-static struct backlight_device *rockchip_mcu_panel_find_backlight(struct device_node *np_mcu_panel)
795
+static struct backlight_device *rockchip_mcu_panel_find_backlight(struct rockchip_rgb *rgb)
745796 {
746797 struct backlight_device *bd = NULL;
798
+ struct device_node *np_mcu_panel = rgb->np_mcu_panel;
747799 struct device_node *np = NULL;
748800
749801 np = of_parse_phandle(np_mcu_panel, "backlight", 0);
....@@ -768,45 +820,35 @@
768820 struct drm_device *drm_dev = data;
769821 struct drm_encoder *encoder = &rgb->encoder;
770822 struct drm_connector *connector;
771
- struct fwnode_handle *fwnode_mcu_panel;
772823 int ret;
773824
774
- fwnode_mcu_panel = device_get_named_child_node(dev, "mcu-panel");
775
- if (fwnode_mcu_panel) {
825
+ if (rgb->np_mcu_panel) {
776826 struct rockchip_mcu_panel *mcu_panel;
777
- struct device_node *np_mcu_panel = to_of_node(fwnode_mcu_panel);
778827
779828 mcu_panel = devm_kzalloc(dev, sizeof(*mcu_panel), GFP_KERNEL);
780829 if (!mcu_panel) {
781
- of_node_put(np_mcu_panel);
782830 return -ENOMEM;
783831 }
784832 mcu_panel->drm_dev = drm_dev;
785833
786834 rgb->panel = &mcu_panel->base;
787835
788
- ret = rockchip_mcu_panel_init(rgb, np_mcu_panel);
836
+ ret = rockchip_mcu_panel_init(rgb);
789837 if (ret < 0) {
790838 DRM_DEV_ERROR(dev, "failed to init mcu panel: %d\n", ret);
791
- of_node_put(np_mcu_panel);
792839 return ret;
793840 }
794841
795
- rgb->panel->backlight = rockchip_mcu_panel_find_backlight(np_mcu_panel);
842
+ rgb->panel->backlight = rockchip_mcu_panel_find_backlight(rgb);
796843 if (!rgb->panel->backlight) {
797844 DRM_DEV_ERROR(dev, "failed to find backlight device");
798
- of_node_put(np_mcu_panel);
799845 return -EINVAL;
800846 }
801
-
802
- of_node_put(np_mcu_panel);
803847
804848 drm_panel_init(&mcu_panel->base, dev, &rockchip_mcu_panel_funcs,
805849 DRM_MODE_CONNECTOR_DPI);
806850
807851 drm_panel_add(&mcu_panel->base);
808
-
809
- rgb->is_mcu_panel = true;
810852 } else {
811853 ret = drm_of_find_panel_or_bridge(dev->of_node, 1, -1,
812854 &rgb->panel, &rgb->bridge);
....@@ -899,6 +941,7 @@
899941 struct device *dev = &pdev->dev;
900942 struct rockchip_rgb *rgb;
901943 const struct rockchip_rgb_data *rgb_data;
944
+ struct fwnode_handle *fwnode_mcu_panel;
902945 int ret, id;
903946
904947 rgb = devm_kzalloc(&pdev->dev, sizeof(*rgb), GFP_KERNEL);
....@@ -909,17 +952,23 @@
909952 if (id < 0)
910953 id = 0;
911954
955
+ rgb->data_sync_bypass = of_property_read_bool(dev->of_node, "rockchip,data-sync-bypass");
956
+
957
+ fwnode_mcu_panel = device_get_named_child_node(dev, "mcu-panel");
958
+ if (fwnode_mcu_panel)
959
+ rgb->np_mcu_panel = to_of_node(fwnode_mcu_panel);
960
+
912961 rgb_data = of_device_get_match_data(dev);
913962 if (rgb_data) {
914
- rgb->max_dclk_rate = rgb_data->max_dclk_rate;
915963 rgb->funcs = rgb_data->funcs;
964
+ if (rgb->np_mcu_panel)
965
+ rgb->max_dclk_rate = rgb_data->mcu_max_dclk_rate;
966
+ else
967
+ rgb->max_dclk_rate = rgb_data->rgb_max_dclk_rate;
916968 }
917969 rgb->id = id;
918970 rgb->dev = dev;
919971 platform_set_drvdata(pdev, rgb);
920
-
921
- rgb->data_sync_bypass =
922
- of_property_read_bool(dev->of_node, "rockchip,data-sync-bypass");
923972
924973 if (dev->parent && dev->parent->of_node) {
925974 rgb->grf = syscon_node_to_regmap(dev->parent->of_node);
....@@ -1061,7 +1110,8 @@
10611110 };
10621111
10631112 static const struct rockchip_rgb_data rv1106_rgb = {
1064
- .max_dclk_rate = 74250,
1113
+ .rgb_max_dclk_rate = 74250,
1114
+ .mcu_max_dclk_rate = 150000,
10651115 .funcs = &rv1106_rgb_funcs,
10661116 };
10671117