.. | .. |
---|
11 | 11 | #include <linux/platform_device.h> |
---|
12 | 12 | #include <linux/regmap.h> |
---|
13 | 13 | #include <linux/regulator/consumer.h> |
---|
14 | | -#include <drm/drm_crtc_helper.h> |
---|
| 14 | + |
---|
15 | 15 | #include <sound/hdmi-codec.h> |
---|
16 | 16 | |
---|
17 | 17 | #include <drm/drm_atomic_helper.h> |
---|
18 | 18 | #include <drm/drm_bridge.h> |
---|
19 | 19 | #include <drm/drm_mipi_dsi.h> |
---|
20 | 20 | #include <drm/drm_print.h> |
---|
| 21 | +#include <drm/drm_probe_helper.h> |
---|
21 | 22 | |
---|
22 | 23 | #define EDID_SEG_SIZE 256 |
---|
23 | 24 | #define EDID_LEN 32 |
---|
.. | .. |
---|
46 | 47 | struct gpio_desc *enable_gpio; |
---|
47 | 48 | |
---|
48 | 49 | bool power_on; |
---|
| 50 | + bool sleep; |
---|
49 | 51 | |
---|
50 | 52 | struct regulator_bulk_data supplies[2]; |
---|
51 | 53 | |
---|
.. | .. |
---|
93 | 95 | { 1920, 1080, 60, 4, 1 }, /* 1080P 24bit 60Hz 4lane 1port */ |
---|
94 | 96 | { 1920, 1080, 30, 3, 1 }, /* 1080P 24bit 30Hz 3lane 1port */ |
---|
95 | 97 | { 1920, 1080, 24, 3, 1 }, |
---|
96 | | - { 1280, 720, 60, 4, 1 }, |
---|
97 | | - { 1280, 720, 30, 4, 1 }, |
---|
98 | 98 | { 720, 480, 60, 4, 1 }, |
---|
99 | 99 | { 720, 576, 50, 2, 1 }, |
---|
100 | 100 | { 640, 480, 60, 2, 1 }, |
---|
.. | .. |
---|
185 | 185 | |
---|
186 | 186 | regmap_write(lt9611->regmap, 0x8319, (u8)(hfront_porch % 256)); |
---|
187 | 187 | |
---|
188 | | - regmap_write(lt9611->regmap, 0x831a, (u8)(hsync_porch / 256)); |
---|
| 188 | + regmap_write(lt9611->regmap, 0x831a, (u8)(hsync_porch / 256) | |
---|
| 189 | + ((hfront_porch / 256) << 4)); |
---|
189 | 190 | regmap_write(lt9611->regmap, 0x831b, (u8)(hsync_porch % 256)); |
---|
190 | 191 | } |
---|
191 | 192 | |
---|
192 | | -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) |
---|
193 | 194 | { |
---|
| 195 | + unsigned int pcr_m = mode->clock * 5 * postdiv / 27000; |
---|
194 | 196 | const struct reg_sequence reg_cfg[] = { |
---|
195 | 197 | { 0x830b, 0x01 }, |
---|
196 | 198 | { 0x830c, 0x10 }, |
---|
.. | .. |
---|
205 | 207 | |
---|
206 | 208 | /* stage 2 */ |
---|
207 | 209 | { 0x834a, 0x40 }, |
---|
208 | | - { 0x831d, 0x10 }, |
---|
209 | 210 | |
---|
210 | 211 | /* MK limit */ |
---|
211 | 212 | { 0x832d, 0x38 }, |
---|
.. | .. |
---|
220 | 221 | { 0x8325, 0x00 }, |
---|
221 | 222 | { 0x832a, 0x01 }, |
---|
222 | 223 | { 0x834a, 0x10 }, |
---|
223 | | - { 0x831d, 0x10 }, |
---|
224 | | - { 0x8326, 0x37 }, |
---|
225 | 224 | }; |
---|
| 225 | + u8 pol = 0x10; |
---|
226 | 226 | |
---|
227 | | - 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); |
---|
228 | 232 | |
---|
229 | | - switch (mode->hdisplay) { |
---|
230 | | - case 640: |
---|
231 | | - regmap_write(lt9611->regmap, 0x8326, 0x14); |
---|
232 | | - break; |
---|
233 | | - case 1280: |
---|
234 | | - regmap_write(lt9611->regmap, 0x8326, 0x1c); |
---|
235 | | - break; |
---|
236 | | - case 1920: |
---|
237 | | - if (drm_mode_vrefresh(mode) == 30) |
---|
238 | | - regmap_write(lt9611->regmap, 0x8326, 0x1c); |
---|
239 | | - else |
---|
240 | | - regmap_write(lt9611->regmap, 0x8326, 0x37); |
---|
241 | | - break; |
---|
242 | | - case 3840: |
---|
| 233 | + if (mode->hdisplay == 3840) |
---|
243 | 234 | regmap_multi_reg_write(lt9611->regmap, reg_cfg2, ARRAY_SIZE(reg_cfg2)); |
---|
244 | | - break; |
---|
245 | | - } |
---|
| 235 | + else |
---|
| 236 | + regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); |
---|
| 237 | + |
---|
| 238 | + regmap_write(lt9611->regmap, 0x8326, pcr_m); |
---|
246 | 239 | |
---|
247 | 240 | /* pcr rst */ |
---|
248 | 241 | regmap_write(lt9611->regmap, 0x8011, 0x5a); |
---|
249 | 242 | regmap_write(lt9611->regmap, 0x8011, 0xfa); |
---|
250 | 243 | } |
---|
251 | 244 | |
---|
252 | | -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) |
---|
253 | 246 | { |
---|
254 | 247 | unsigned int pclk = mode->clock; |
---|
255 | 248 | const struct reg_sequence reg_cfg[] = { |
---|
.. | .. |
---|
263 | 256 | { 0x8126, 0x55 }, |
---|
264 | 257 | { 0x8127, 0x66 }, |
---|
265 | 258 | { 0x8128, 0x88 }, |
---|
| 259 | + { 0x812a, 0x20 }, |
---|
266 | 260 | }; |
---|
267 | 261 | |
---|
268 | 262 | regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); |
---|
269 | 263 | |
---|
270 | | - if (pclk > 150000) |
---|
| 264 | + if (pclk > 150000) { |
---|
271 | 265 | regmap_write(lt9611->regmap, 0x812d, 0x88); |
---|
272 | | - else if (pclk > 70000) |
---|
| 266 | + *postdiv = 1; |
---|
| 267 | + } else if (pclk > 70000) { |
---|
273 | 268 | regmap_write(lt9611->regmap, 0x812d, 0x99); |
---|
274 | | - else |
---|
| 269 | + *postdiv = 2; |
---|
| 270 | + } else { |
---|
275 | 271 | regmap_write(lt9611->regmap, 0x812d, 0xaa); |
---|
| 272 | + *postdiv = 4; |
---|
| 273 | + } |
---|
276 | 274 | |
---|
277 | 275 | /* |
---|
278 | 276 | * first divide pclk by 2 first |
---|
.. | .. |
---|
443 | 441 | regmap_write(lt9611->regmap, 0x8203, val); |
---|
444 | 442 | regmap_write(lt9611->regmap, 0x8207, 0xff); /* clear */ |
---|
445 | 443 | 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; |
---|
446 | 463 | } |
---|
447 | 464 | |
---|
448 | 465 | static int lt9611_power_on(struct lt9611 *lt9611) |
---|
.. | .. |
---|
743 | 760 | static struct mipi_dsi_device *lt9611_attach_dsi(struct lt9611 *lt9611, |
---|
744 | 761 | struct device_node *dsi_node) |
---|
745 | 762 | { |
---|
746 | | - const struct mipi_dsi_device_info info = { "lt9611", 0, NULL }; |
---|
| 763 | + const struct mipi_dsi_device_info info = { "lt9611", 0, lt9611->dev->of_node}; |
---|
747 | 764 | struct mipi_dsi_device *dsi; |
---|
748 | 765 | struct mipi_dsi_host *host; |
---|
749 | 766 | int ret; |
---|
.. | .. |
---|
762 | 779 | |
---|
763 | 780 | dsi->lanes = 4; |
---|
764 | 781 | dsi->format = MIPI_DSI_FMT_RGB888; |
---|
765 | | - 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; |
---|
766 | 784 | |
---|
767 | 785 | ret = mipi_dsi_attach(dsi); |
---|
768 | 786 | if (ret < 0) { |
---|
.. | .. |
---|
801 | 819 | |
---|
802 | 820 | drm_connector_helper_add(<9611->connector, |
---|
803 | 821 | <9611_bridge_connector_helper_funcs); |
---|
804 | | - drm_connector_attach_encoder(<9611->connector, bridge->encoder); |
---|
805 | 822 | |
---|
806 | 823 | if (!bridge->encoder) { |
---|
807 | 824 | DRM_ERROR("Parent encoder object not found"); |
---|
808 | 825 | return -ENODEV; |
---|
809 | 826 | } |
---|
810 | 827 | |
---|
| 828 | + drm_connector_attach_encoder(<9611->connector, bridge->encoder); |
---|
| 829 | + |
---|
811 | 830 | return 0; |
---|
812 | 831 | } |
---|
813 | 832 | |
---|
814 | | -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) |
---|
815 | 835 | { |
---|
816 | 836 | struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
---|
817 | 837 | 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 | + } |
---|
818 | 844 | |
---|
819 | 845 | /* Attach primary DSI */ |
---|
820 | 846 | lt9611->dsi0 = lt9611_attach_dsi(lt9611, lt9611->dsi0_node); |
---|
.. | .. |
---|
830 | 856 | } |
---|
831 | 857 | } |
---|
832 | 858 | |
---|
833 | | - ret = lt9611_connector_init(bridge, lt9611); |
---|
834 | | - |
---|
835 | | - return ret; |
---|
| 859 | + return 0; |
---|
836 | 860 | |
---|
837 | 861 | err_unregister_dsi0: |
---|
838 | 862 | lt9611_bridge_detach(bridge); |
---|
.. | .. |
---|
843 | 867 | } |
---|
844 | 868 | |
---|
845 | 869 | static enum drm_mode_status lt9611_bridge_mode_valid(struct drm_bridge *bridge, |
---|
| 870 | + const struct drm_display_info *info, |
---|
846 | 871 | const struct drm_display_mode *mode) |
---|
847 | 872 | { |
---|
848 | 873 | struct lt9611_mode *lt9611_mode = lt9611_find_mode(mode); |
---|
| 874 | + struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
---|
849 | 875 | |
---|
850 | | - 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; |
---|
851 | 882 | } |
---|
852 | 883 | |
---|
853 | 884 | static void lt9611_bridge_pre_enable(struct drm_bridge *bridge) |
---|
854 | 885 | { |
---|
855 | 886 | 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 | + }; |
---|
856 | 893 | |
---|
857 | | - lt9611_reset(lt9611); |
---|
858 | | - regmap_write(lt9611->regmap, 0x80ee, 0x01); |
---|
859 | | - lt9611_enable_hpd_interrupts(lt9611); |
---|
| 894 | + if (!lt9611->sleep) |
---|
| 895 | + return; |
---|
860 | 896 | |
---|
| 897 | + regmap_multi_reg_write(lt9611->regmap, |
---|
| 898 | + reg_cfg, ARRAY_SIZE(reg_cfg)); |
---|
| 899 | + |
---|
| 900 | + lt9611->sleep = false; |
---|
861 | 901 | } |
---|
862 | 902 | |
---|
863 | 903 | static void lt9611_bridge_post_disable(struct drm_bridge *bridge) |
---|
864 | 904 | { |
---|
| 905 | + struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
---|
| 906 | + |
---|
| 907 | + lt9611_sleep_setup(lt9611); |
---|
865 | 908 | } |
---|
866 | 909 | |
---|
867 | 910 | static void lt9611_bridge_mode_set(struct drm_bridge *bridge, |
---|
868 | | - struct drm_display_mode *mode, |
---|
869 | | - struct drm_display_mode *adj_mode) |
---|
| 911 | + const struct drm_display_mode *mode, |
---|
| 912 | + const struct drm_display_mode *adj_mode) |
---|
870 | 913 | { |
---|
871 | 914 | struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
---|
872 | 915 | struct hdmi_avi_infoframe avi_frame; |
---|
| 916 | + unsigned int postdiv; |
---|
873 | 917 | int ret; |
---|
874 | 918 | |
---|
875 | 919 | lt9611_bridge_pre_enable(bridge); |
---|
876 | 920 | |
---|
877 | 921 | lt9611_mipi_input_digital(lt9611, mode); |
---|
878 | | - lt9611_pll_setup(lt9611, mode); |
---|
| 922 | + lt9611_pll_setup(lt9611, mode, &postdiv); |
---|
879 | 923 | lt9611_mipi_video_setup(lt9611, mode); |
---|
880 | | - lt9611_pcr_setup(lt9611, mode); |
---|
| 924 | + lt9611_pcr_setup(lt9611, mode, postdiv); |
---|
881 | 925 | |
---|
882 | | - ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame, mode, false); |
---|
| 926 | + ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame, |
---|
| 927 | + <9611->connector, |
---|
| 928 | + mode); |
---|
883 | 929 | if (!ret) |
---|
884 | 930 | 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, ®_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); |
---|
885 | 962 | } |
---|
886 | 963 | |
---|
887 | 964 | static const struct drm_bridge_funcs lt9611_bridge_funcs = { |
---|
.. | .. |
---|
892 | 969 | .disable = lt9611_bridge_disable, |
---|
893 | 970 | .post_disable = lt9611_bridge_post_disable, |
---|
894 | 971 | .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, |
---|
895 | 975 | }; |
---|
896 | 976 | |
---|
897 | 977 | static int lt9611_parse_dt(struct device *dev, |
---|
.. | .. |
---|
1058 | 1138 | |
---|
1059 | 1139 | lt9611->dev = &client->dev; |
---|
1060 | 1140 | lt9611->client = client; |
---|
| 1141 | + lt9611->sleep = false; |
---|
1061 | 1142 | |
---|
1062 | 1143 | lt9611->regmap = devm_regmap_init_i2c(client, <9611_regmap_config); |
---|
1063 | 1144 | if (IS_ERR(lt9611->regmap)) { |
---|
.. | .. |
---|
1095 | 1176 | |
---|
1096 | 1177 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
---|
1097 | 1178 | lt9611_irq_thread_handler, |
---|
1098 | | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
---|
1099 | | - "lt9611", lt9611); |
---|
| 1179 | + IRQF_ONESHOT, "lt9611", lt9611); |
---|
1100 | 1180 | if (ret) { |
---|
1101 | 1181 | dev_err(dev, "failed to request irq\n"); |
---|
1102 | 1182 | goto err_disable_regulators; |
---|
.. | .. |
---|
1106 | 1186 | |
---|
1107 | 1187 | lt9611->bridge.funcs = <9611_bridge_funcs; |
---|
1108 | 1188 | 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; |
---|
1109 | 1192 | |
---|
1110 | 1193 | drm_bridge_add(<9611->bridge); |
---|
1111 | 1194 | |
---|