| .. | .. |
|---|
| 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 | |
|---|
| .. | .. |
|---|
| 183 | 185 | |
|---|
| 184 | 186 | regmap_write(lt9611->regmap, 0x8319, (u8)(hfront_porch % 256)); |
|---|
| 185 | 187 | |
|---|
| 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)); |
|---|
| 187 | 190 | regmap_write(lt9611->regmap, 0x831b, (u8)(hsync_porch % 256)); |
|---|
| 188 | 191 | } |
|---|
| 189 | 192 | |
|---|
| 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) |
|---|
| 191 | 194 | { |
|---|
| 195 | + unsigned int pcr_m = mode->clock * 5 * postdiv / 27000; |
|---|
| 192 | 196 | const struct reg_sequence reg_cfg[] = { |
|---|
| 193 | 197 | { 0x830b, 0x01 }, |
|---|
| 194 | 198 | { 0x830c, 0x10 }, |
|---|
| .. | .. |
|---|
| 203 | 207 | |
|---|
| 204 | 208 | /* stage 2 */ |
|---|
| 205 | 209 | { 0x834a, 0x40 }, |
|---|
| 206 | | - { 0x831d, 0x10 }, |
|---|
| 207 | 210 | |
|---|
| 208 | 211 | /* MK limit */ |
|---|
| 209 | 212 | { 0x832d, 0x38 }, |
|---|
| .. | .. |
|---|
| 218 | 221 | { 0x8325, 0x00 }, |
|---|
| 219 | 222 | { 0x832a, 0x01 }, |
|---|
| 220 | 223 | { 0x834a, 0x10 }, |
|---|
| 221 | | - { 0x831d, 0x10 }, |
|---|
| 222 | | - { 0x8326, 0x37 }, |
|---|
| 223 | 224 | }; |
|---|
| 225 | + u8 pol = 0x10; |
|---|
| 224 | 226 | |
|---|
| 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); |
|---|
| 226 | 232 | |
|---|
| 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) |
|---|
| 235 | 234 | 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); |
|---|
| 238 | 239 | |
|---|
| 239 | 240 | /* pcr rst */ |
|---|
| 240 | 241 | regmap_write(lt9611->regmap, 0x8011, 0x5a); |
|---|
| 241 | 242 | regmap_write(lt9611->regmap, 0x8011, 0xfa); |
|---|
| 242 | 243 | } |
|---|
| 243 | 244 | |
|---|
| 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) |
|---|
| 245 | 246 | { |
|---|
| 246 | 247 | unsigned int pclk = mode->clock; |
|---|
| 247 | 248 | const struct reg_sequence reg_cfg[] = { |
|---|
| .. | .. |
|---|
| 255 | 256 | { 0x8126, 0x55 }, |
|---|
| 256 | 257 | { 0x8127, 0x66 }, |
|---|
| 257 | 258 | { 0x8128, 0x88 }, |
|---|
| 259 | + { 0x812a, 0x20 }, |
|---|
| 258 | 260 | }; |
|---|
| 259 | 261 | |
|---|
| 260 | 262 | regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); |
|---|
| 261 | 263 | |
|---|
| 262 | | - if (pclk > 150000) |
|---|
| 264 | + if (pclk > 150000) { |
|---|
| 263 | 265 | regmap_write(lt9611->regmap, 0x812d, 0x88); |
|---|
| 264 | | - else if (pclk > 70000) |
|---|
| 266 | + *postdiv = 1; |
|---|
| 267 | + } else if (pclk > 70000) { |
|---|
| 265 | 268 | regmap_write(lt9611->regmap, 0x812d, 0x99); |
|---|
| 266 | | - else |
|---|
| 269 | + *postdiv = 2; |
|---|
| 270 | + } else { |
|---|
| 267 | 271 | regmap_write(lt9611->regmap, 0x812d, 0xaa); |
|---|
| 272 | + *postdiv = 4; |
|---|
| 273 | + } |
|---|
| 268 | 274 | |
|---|
| 269 | 275 | /* |
|---|
| 270 | 276 | * first divide pclk by 2 first |
|---|
| .. | .. |
|---|
| 435 | 441 | regmap_write(lt9611->regmap, 0x8203, val); |
|---|
| 436 | 442 | regmap_write(lt9611->regmap, 0x8207, 0xff); /* clear */ |
|---|
| 437 | 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; |
|---|
| 438 | 463 | } |
|---|
| 439 | 464 | |
|---|
| 440 | 465 | static int lt9611_power_on(struct lt9611 *lt9611) |
|---|
| .. | .. |
|---|
| 735 | 760 | static struct mipi_dsi_device *lt9611_attach_dsi(struct lt9611 *lt9611, |
|---|
| 736 | 761 | struct device_node *dsi_node) |
|---|
| 737 | 762 | { |
|---|
| 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}; |
|---|
| 739 | 764 | struct mipi_dsi_device *dsi; |
|---|
| 740 | 765 | struct mipi_dsi_host *host; |
|---|
| 741 | 766 | int ret; |
|---|
| .. | .. |
|---|
| 754 | 779 | |
|---|
| 755 | 780 | dsi->lanes = 4; |
|---|
| 756 | 781 | 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; |
|---|
| 758 | 784 | |
|---|
| 759 | 785 | ret = mipi_dsi_attach(dsi); |
|---|
| 760 | 786 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 793 | 819 | |
|---|
| 794 | 820 | drm_connector_helper_add(<9611->connector, |
|---|
| 795 | 821 | <9611_bridge_connector_helper_funcs); |
|---|
| 796 | | - drm_connector_attach_encoder(<9611->connector, bridge->encoder); |
|---|
| 797 | 822 | |
|---|
| 798 | 823 | if (!bridge->encoder) { |
|---|
| 799 | 824 | DRM_ERROR("Parent encoder object not found"); |
|---|
| 800 | 825 | return -ENODEV; |
|---|
| 801 | 826 | } |
|---|
| 802 | 827 | |
|---|
| 828 | + drm_connector_attach_encoder(<9611->connector, bridge->encoder); |
|---|
| 829 | + |
|---|
| 803 | 830 | return 0; |
|---|
| 804 | 831 | } |
|---|
| 805 | 832 | |
|---|
| 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) |
|---|
| 807 | 835 | { |
|---|
| 808 | 836 | struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
|---|
| 809 | 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 | + } |
|---|
| 810 | 844 | |
|---|
| 811 | 845 | /* Attach primary DSI */ |
|---|
| 812 | 846 | lt9611->dsi0 = lt9611_attach_dsi(lt9611, lt9611->dsi0_node); |
|---|
| .. | .. |
|---|
| 822 | 856 | } |
|---|
| 823 | 857 | } |
|---|
| 824 | 858 | |
|---|
| 825 | | - ret = lt9611_connector_init(bridge, lt9611); |
|---|
| 826 | | - |
|---|
| 827 | | - return ret; |
|---|
| 859 | + return 0; |
|---|
| 828 | 860 | |
|---|
| 829 | 861 | err_unregister_dsi0: |
|---|
| 830 | 862 | lt9611_bridge_detach(bridge); |
|---|
| .. | .. |
|---|
| 835 | 867 | } |
|---|
| 836 | 868 | |
|---|
| 837 | 869 | static enum drm_mode_status lt9611_bridge_mode_valid(struct drm_bridge *bridge, |
|---|
| 870 | + const struct drm_display_info *info, |
|---|
| 838 | 871 | const struct drm_display_mode *mode) |
|---|
| 839 | 872 | { |
|---|
| 840 | 873 | struct lt9611_mode *lt9611_mode = lt9611_find_mode(mode); |
|---|
| 874 | + struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
|---|
| 841 | 875 | |
|---|
| 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; |
|---|
| 843 | 882 | } |
|---|
| 844 | 883 | |
|---|
| 845 | 884 | static void lt9611_bridge_pre_enable(struct drm_bridge *bridge) |
|---|
| 846 | 885 | { |
|---|
| 847 | 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 | + }; |
|---|
| 848 | 893 | |
|---|
| 849 | | - lt9611_reset(lt9611); |
|---|
| 850 | | - regmap_write(lt9611->regmap, 0x80ee, 0x01); |
|---|
| 851 | | - lt9611_enable_hpd_interrupts(lt9611); |
|---|
| 894 | + if (!lt9611->sleep) |
|---|
| 895 | + return; |
|---|
| 852 | 896 | |
|---|
| 897 | + regmap_multi_reg_write(lt9611->regmap, |
|---|
| 898 | + reg_cfg, ARRAY_SIZE(reg_cfg)); |
|---|
| 899 | + |
|---|
| 900 | + lt9611->sleep = false; |
|---|
| 853 | 901 | } |
|---|
| 854 | 902 | |
|---|
| 855 | 903 | static void lt9611_bridge_post_disable(struct drm_bridge *bridge) |
|---|
| 856 | 904 | { |
|---|
| 905 | + struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
|---|
| 906 | + |
|---|
| 907 | + lt9611_sleep_setup(lt9611); |
|---|
| 857 | 908 | } |
|---|
| 858 | 909 | |
|---|
| 859 | 910 | 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) |
|---|
| 862 | 913 | { |
|---|
| 863 | 914 | struct lt9611 *lt9611 = bridge_to_lt9611(bridge); |
|---|
| 864 | 915 | struct hdmi_avi_infoframe avi_frame; |
|---|
| 916 | + unsigned int postdiv; |
|---|
| 865 | 917 | int ret; |
|---|
| 866 | 918 | |
|---|
| 867 | 919 | lt9611_bridge_pre_enable(bridge); |
|---|
| 868 | 920 | |
|---|
| 869 | 921 | lt9611_mipi_input_digital(lt9611, mode); |
|---|
| 870 | | - lt9611_pll_setup(lt9611, mode); |
|---|
| 922 | + lt9611_pll_setup(lt9611, mode, &postdiv); |
|---|
| 871 | 923 | lt9611_mipi_video_setup(lt9611, mode); |
|---|
| 872 | | - lt9611_pcr_setup(lt9611, mode); |
|---|
| 924 | + lt9611_pcr_setup(lt9611, mode, postdiv); |
|---|
| 873 | 925 | |
|---|
| 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 | + <9611->connector, |
|---|
| 928 | + mode); |
|---|
| 875 | 929 | if (!ret) |
|---|
| 876 | 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); |
|---|
| 877 | 962 | } |
|---|
| 878 | 963 | |
|---|
| 879 | 964 | static const struct drm_bridge_funcs lt9611_bridge_funcs = { |
|---|
| .. | .. |
|---|
| 884 | 969 | .disable = lt9611_bridge_disable, |
|---|
| 885 | 970 | .post_disable = lt9611_bridge_post_disable, |
|---|
| 886 | 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, |
|---|
| 887 | 975 | }; |
|---|
| 888 | 976 | |
|---|
| 889 | 977 | static int lt9611_parse_dt(struct device *dev, |
|---|
| .. | .. |
|---|
| 1050 | 1138 | |
|---|
| 1051 | 1139 | lt9611->dev = &client->dev; |
|---|
| 1052 | 1140 | lt9611->client = client; |
|---|
| 1141 | + lt9611->sleep = false; |
|---|
| 1053 | 1142 | |
|---|
| 1054 | 1143 | lt9611->regmap = devm_regmap_init_i2c(client, <9611_regmap_config); |
|---|
| 1055 | 1144 | if (IS_ERR(lt9611->regmap)) { |
|---|
| .. | .. |
|---|
| 1087 | 1176 | |
|---|
| 1088 | 1177 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
|---|
| 1089 | 1178 | lt9611_irq_thread_handler, |
|---|
| 1090 | | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
|---|
| 1091 | | - "lt9611", lt9611); |
|---|
| 1179 | + IRQF_ONESHOT, "lt9611", lt9611); |
|---|
| 1092 | 1180 | if (ret) { |
|---|
| 1093 | 1181 | dev_err(dev, "failed to request irq\n"); |
|---|
| 1094 | 1182 | goto err_disable_regulators; |
|---|
| .. | .. |
|---|
| 1098 | 1186 | |
|---|
| 1099 | 1187 | lt9611->bridge.funcs = <9611_bridge_funcs; |
|---|
| 1100 | 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; |
|---|
| 1101 | 1192 | |
|---|
| 1102 | 1193 | drm_bridge_add(<9611->bridge); |
|---|
| 1103 | 1194 | |
|---|