forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/drm/bridge/lontium-lt9611.c
....@@ -11,13 +11,14 @@
1111 #include <linux/platform_device.h>
1212 #include <linux/regmap.h>
1313 #include <linux/regulator/consumer.h>
14
-#include <drm/drm_crtc_helper.h>
14
+
1515 #include <sound/hdmi-codec.h>
1616
1717 #include <drm/drm_atomic_helper.h>
1818 #include <drm/drm_bridge.h>
1919 #include <drm/drm_mipi_dsi.h>
2020 #include <drm/drm_print.h>
21
+#include <drm/drm_probe_helper.h>
2122
2223 #define EDID_SEG_SIZE 256
2324 #define EDID_LEN 32
....@@ -46,6 +47,7 @@
4647 struct gpio_desc *enable_gpio;
4748
4849 bool power_on;
50
+ bool sleep;
4951
5052 struct regulator_bulk_data supplies[2];
5153
....@@ -183,12 +185,14 @@
183185
184186 regmap_write(lt9611->regmap, 0x8319, (u8)(hfront_porch % 256));
185187
186
- regmap_write(lt9611->regmap, 0x831a, (u8)(hsync_porch / 256));
188
+ regmap_write(lt9611->regmap, 0x831a, (u8)(hsync_porch / 256) |
189
+ ((hfront_porch / 256) << 4));
187190 regmap_write(lt9611->regmap, 0x831b, (u8)(hsync_porch % 256));
188191 }
189192
190
-static void lt9611_pcr_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode)
193
+static void lt9611_pcr_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode, unsigned int postdiv)
191194 {
195
+ unsigned int pcr_m = mode->clock * 5 * postdiv / 27000;
192196 const struct reg_sequence reg_cfg[] = {
193197 { 0x830b, 0x01 },
194198 { 0x830c, 0x10 },
....@@ -203,7 +207,6 @@
203207
204208 /* stage 2 */
205209 { 0x834a, 0x40 },
206
- { 0x831d, 0x10 },
207210
208211 /* MK limit */
209212 { 0x832d, 0x38 },
....@@ -218,30 +221,28 @@
218221 { 0x8325, 0x00 },
219222 { 0x832a, 0x01 },
220223 { 0x834a, 0x10 },
221
- { 0x831d, 0x10 },
222
- { 0x8326, 0x37 },
223224 };
225
+ u8 pol = 0x10;
224226
225
- regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg));
227
+ if (mode->flags & DRM_MODE_FLAG_NHSYNC)
228
+ pol |= 0x2;
229
+ if (mode->flags & DRM_MODE_FLAG_NVSYNC)
230
+ pol |= 0x1;
231
+ regmap_write(lt9611->regmap, 0x831d, pol);
226232
227
- switch (mode->hdisplay) {
228
- case 640:
229
- regmap_write(lt9611->regmap, 0x8326, 0x14);
230
- break;
231
- case 1920:
232
- regmap_write(lt9611->regmap, 0x8326, 0x37);
233
- break;
234
- case 3840:
233
+ if (mode->hdisplay == 3840)
235234 regmap_multi_reg_write(lt9611->regmap, reg_cfg2, ARRAY_SIZE(reg_cfg2));
236
- break;
237
- }
235
+ else
236
+ regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg));
237
+
238
+ regmap_write(lt9611->regmap, 0x8326, pcr_m);
238239
239240 /* pcr rst */
240241 regmap_write(lt9611->regmap, 0x8011, 0x5a);
241242 regmap_write(lt9611->regmap, 0x8011, 0xfa);
242243 }
243244
244
-static int lt9611_pll_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode)
245
+static int lt9611_pll_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode, unsigned int *postdiv)
245246 {
246247 unsigned int pclk = mode->clock;
247248 const struct reg_sequence reg_cfg[] = {
....@@ -255,16 +256,21 @@
255256 { 0x8126, 0x55 },
256257 { 0x8127, 0x66 },
257258 { 0x8128, 0x88 },
259
+ { 0x812a, 0x20 },
258260 };
259261
260262 regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg));
261263
262
- if (pclk > 150000)
264
+ if (pclk > 150000) {
263265 regmap_write(lt9611->regmap, 0x812d, 0x88);
264
- else if (pclk > 70000)
266
+ *postdiv = 1;
267
+ } else if (pclk > 70000) {
265268 regmap_write(lt9611->regmap, 0x812d, 0x99);
266
- else
269
+ *postdiv = 2;
270
+ } else {
267271 regmap_write(lt9611->regmap, 0x812d, 0xaa);
272
+ *postdiv = 4;
273
+ }
268274
269275 /*
270276 * first divide pclk by 2 first
....@@ -435,6 +441,25 @@
435441 regmap_write(lt9611->regmap, 0x8203, val);
436442 regmap_write(lt9611->regmap, 0x8207, 0xff); /* clear */
437443 regmap_write(lt9611->regmap, 0x8207, 0x3f);
444
+}
445
+
446
+static void lt9611_sleep_setup(struct lt9611 *lt9611)
447
+{
448
+ const struct reg_sequence sleep_setup[] = {
449
+ { 0x8024, 0x76 },
450
+ { 0x8023, 0x01 },
451
+ { 0x8157, 0x03 }, /* set addr pin as output */
452
+ { 0x8149, 0x0b },
453
+
454
+ { 0x8102, 0x48 }, /* MIPI Rx power down */
455
+ { 0x8123, 0x80 },
456
+ { 0x8130, 0x00 },
457
+ { 0x8011, 0x0a },
458
+ };
459
+
460
+ regmap_multi_reg_write(lt9611->regmap,
461
+ sleep_setup, ARRAY_SIZE(sleep_setup));
462
+ lt9611->sleep = true;
438463 }
439464
440465 static int lt9611_power_on(struct lt9611 *lt9611)
....@@ -735,7 +760,7 @@
735760 static struct mipi_dsi_device *lt9611_attach_dsi(struct lt9611 *lt9611,
736761 struct device_node *dsi_node)
737762 {
738
- const struct mipi_dsi_device_info info = { "lt9611", 0, NULL };
763
+ const struct mipi_dsi_device_info info = { "lt9611", 0, lt9611->dev->of_node};
739764 struct mipi_dsi_device *dsi;
740765 struct mipi_dsi_host *host;
741766 int ret;
....@@ -754,7 +779,8 @@
754779
755780 dsi->lanes = 4;
756781 dsi->format = MIPI_DSI_FMT_RGB888;
757
- dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST;
782
+ dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
783
+ MIPI_DSI_MODE_VIDEO_HSE;
758784
759785 ret = mipi_dsi_attach(dsi);
760786 if (ret < 0) {
....@@ -793,20 +819,28 @@
793819
794820 drm_connector_helper_add(&lt9611->connector,
795821 &lt9611_bridge_connector_helper_funcs);
796
- drm_connector_attach_encoder(&lt9611->connector, bridge->encoder);
797822
798823 if (!bridge->encoder) {
799824 DRM_ERROR("Parent encoder object not found");
800825 return -ENODEV;
801826 }
802827
828
+ drm_connector_attach_encoder(&lt9611->connector, bridge->encoder);
829
+
803830 return 0;
804831 }
805832
806
-static int lt9611_bridge_attach(struct drm_bridge *bridge)
833
+static int lt9611_bridge_attach(struct drm_bridge *bridge,
834
+ enum drm_bridge_attach_flags flags)
807835 {
808836 struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
809837 int ret;
838
+
839
+ if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
840
+ ret = lt9611_connector_init(bridge, lt9611);
841
+ if (ret < 0)
842
+ return ret;
843
+ }
810844
811845 /* Attach primary DSI */
812846 lt9611->dsi0 = lt9611_attach_dsi(lt9611, lt9611->dsi0_node);
....@@ -822,9 +856,7 @@
822856 }
823857 }
824858
825
- ret = lt9611_connector_init(bridge, lt9611);
826
-
827
- return ret;
859
+ return 0;
828860
829861 err_unregister_dsi0:
830862 lt9611_bridge_detach(bridge);
....@@ -835,45 +867,98 @@
835867 }
836868
837869 static enum drm_mode_status lt9611_bridge_mode_valid(struct drm_bridge *bridge,
870
+ const struct drm_display_info *info,
838871 const struct drm_display_mode *mode)
839872 {
840873 struct lt9611_mode *lt9611_mode = lt9611_find_mode(mode);
874
+ struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
841875
842
- return lt9611_mode ? MODE_OK : MODE_BAD;
876
+ if (!lt9611_mode)
877
+ return MODE_BAD;
878
+ else if (lt9611_mode->intfs > 1 && !lt9611->dsi1)
879
+ return MODE_PANEL;
880
+ else
881
+ return MODE_OK;
843882 }
844883
845884 static void lt9611_bridge_pre_enable(struct drm_bridge *bridge)
846885 {
847886 struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
887
+ static const struct reg_sequence reg_cfg[] = {
888
+ { 0x8102, 0x12 },
889
+ { 0x8123, 0x40 },
890
+ { 0x8130, 0xea },
891
+ { 0x8011, 0xfa },
892
+ };
848893
849
- lt9611_reset(lt9611);
850
- regmap_write(lt9611->regmap, 0x80ee, 0x01);
851
- lt9611_enable_hpd_interrupts(lt9611);
894
+ if (!lt9611->sleep)
895
+ return;
852896
897
+ regmap_multi_reg_write(lt9611->regmap,
898
+ reg_cfg, ARRAY_SIZE(reg_cfg));
899
+
900
+ lt9611->sleep = false;
853901 }
854902
855903 static void lt9611_bridge_post_disable(struct drm_bridge *bridge)
856904 {
905
+ struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
906
+
907
+ lt9611_sleep_setup(lt9611);
857908 }
858909
859910 static void lt9611_bridge_mode_set(struct drm_bridge *bridge,
860
- struct drm_display_mode *mode,
861
- struct drm_display_mode *adj_mode)
911
+ const struct drm_display_mode *mode,
912
+ const struct drm_display_mode *adj_mode)
862913 {
863914 struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
864915 struct hdmi_avi_infoframe avi_frame;
916
+ unsigned int postdiv;
865917 int ret;
866918
867919 lt9611_bridge_pre_enable(bridge);
868920
869921 lt9611_mipi_input_digital(lt9611, mode);
870
- lt9611_pll_setup(lt9611, mode);
922
+ lt9611_pll_setup(lt9611, mode, &postdiv);
871923 lt9611_mipi_video_setup(lt9611, mode);
872
- lt9611_pcr_setup(lt9611, mode);
924
+ lt9611_pcr_setup(lt9611, mode, postdiv);
873925
874
- ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame, mode, false);
926
+ ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame,
927
+ &lt9611->connector,
928
+ mode);
875929 if (!ret)
876930 lt9611->vic = avi_frame.video_code;
931
+}
932
+
933
+static enum drm_connector_status lt9611_bridge_detect(struct drm_bridge *bridge)
934
+{
935
+ struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
936
+ unsigned int reg_val = 0;
937
+ int connected;
938
+
939
+ regmap_read(lt9611->regmap, 0x825e, &reg_val);
940
+ connected = reg_val & BIT(2);
941
+
942
+ lt9611->status = connected ? connector_status_connected :
943
+ connector_status_disconnected;
944
+
945
+ return lt9611->status;
946
+}
947
+
948
+static struct edid *lt9611_bridge_get_edid(struct drm_bridge *bridge,
949
+ struct drm_connector *connector)
950
+{
951
+ struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
952
+
953
+ lt9611_power_on(lt9611);
954
+ return drm_do_get_edid(connector, lt9611_get_edid_block, lt9611);
955
+}
956
+
957
+static void lt9611_bridge_hpd_enable(struct drm_bridge *bridge)
958
+{
959
+ struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
960
+
961
+ lt9611_enable_hpd_interrupts(lt9611);
877962 }
878963
879964 static const struct drm_bridge_funcs lt9611_bridge_funcs = {
....@@ -884,6 +969,9 @@
884969 .disable = lt9611_bridge_disable,
885970 .post_disable = lt9611_bridge_post_disable,
886971 .mode_set = lt9611_bridge_mode_set,
972
+ .detect = lt9611_bridge_detect,
973
+ .get_edid = lt9611_bridge_get_edid,
974
+ .hpd_enable = lt9611_bridge_hpd_enable,
887975 };
888976
889977 static int lt9611_parse_dt(struct device *dev,
....@@ -1050,6 +1138,7 @@
10501138
10511139 lt9611->dev = &client->dev;
10521140 lt9611->client = client;
1141
+ lt9611->sleep = false;
10531142
10541143 lt9611->regmap = devm_regmap_init_i2c(client, &lt9611_regmap_config);
10551144 if (IS_ERR(lt9611->regmap)) {
....@@ -1087,8 +1176,7 @@
10871176
10881177 ret = devm_request_threaded_irq(dev, client->irq, NULL,
10891178 lt9611_irq_thread_handler,
1090
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
1091
- "lt9611", lt9611);
1179
+ IRQF_ONESHOT, "lt9611", lt9611);
10921180 if (ret) {
10931181 dev_err(dev, "failed to request irq\n");
10941182 goto err_disable_regulators;
....@@ -1098,6 +1186,9 @@
10981186
10991187 lt9611->bridge.funcs = &lt9611_bridge_funcs;
11001188 lt9611->bridge.of_node = client->dev.of_node;
1189
+ lt9611->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID |
1190
+ DRM_BRIDGE_OP_HPD | DRM_BRIDGE_OP_MODES;
1191
+ lt9611->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
11011192
11021193 drm_bridge_add(&lt9611->bridge);
11031194