Lines Matching +full:mipi +full:- +full:dsi1
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2019-2020. Linaro Limited.
10 #include <linux/media-bus-format.h>
17 #include <sound/hdmi-codec.h>
45 struct mipi_dsi_device *dsi1; member
103 { 0x811c, 0x03 }, /* PortA clk lane no-LP mode */ in lt9611_mipi_input_analog()
104 { 0x8120, 0x03 }, /* PortB clk lane with-LP mode */ in lt9611_mipi_input_analog()
107 return regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); in lt9611_mipi_input_analog()
122 if (lt9611->dsi1_node) in lt9611_mipi_input_digital()
125 return regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); in lt9611_mipi_input_digital()
134 h_total = mode->htotal; in lt9611_mipi_video_setup()
135 v_total = mode->vtotal; in lt9611_mipi_video_setup()
137 hactive = mode->hdisplay; in lt9611_mipi_video_setup()
138 hsync_len = mode->hsync_end - mode->hsync_start; in lt9611_mipi_video_setup()
139 hfront_porch = mode->hsync_start - mode->hdisplay; in lt9611_mipi_video_setup()
140 hsync_porch = mode->htotal - mode->hsync_start; in lt9611_mipi_video_setup()
142 vactive = mode->vdisplay; in lt9611_mipi_video_setup()
143 vsync_len = mode->vsync_end - mode->vsync_start; in lt9611_mipi_video_setup()
144 vfront_porch = mode->vsync_start - mode->vdisplay; in lt9611_mipi_video_setup()
145 vsync_porch = mode->vtotal - mode->vsync_start; in lt9611_mipi_video_setup()
147 regmap_write(lt9611->regmap, 0x830d, (u8)(v_total / 256)); in lt9611_mipi_video_setup()
148 regmap_write(lt9611->regmap, 0x830e, (u8)(v_total % 256)); in lt9611_mipi_video_setup()
150 regmap_write(lt9611->regmap, 0x830f, (u8)(vactive / 256)); in lt9611_mipi_video_setup()
151 regmap_write(lt9611->regmap, 0x8310, (u8)(vactive % 256)); in lt9611_mipi_video_setup()
153 regmap_write(lt9611->regmap, 0x8311, (u8)(h_total / 256)); in lt9611_mipi_video_setup()
154 regmap_write(lt9611->regmap, 0x8312, (u8)(h_total % 256)); in lt9611_mipi_video_setup()
156 regmap_write(lt9611->regmap, 0x8313, (u8)(hactive / 256)); in lt9611_mipi_video_setup()
157 regmap_write(lt9611->regmap, 0x8314, (u8)(hactive % 256)); in lt9611_mipi_video_setup()
159 regmap_write(lt9611->regmap, 0x8315, (u8)(vsync_len % 256)); in lt9611_mipi_video_setup()
160 regmap_write(lt9611->regmap, 0x8316, (u8)(hsync_len % 256)); in lt9611_mipi_video_setup()
162 regmap_write(lt9611->regmap, 0x8317, (u8)(vfront_porch % 256)); in lt9611_mipi_video_setup()
164 regmap_write(lt9611->regmap, 0x8318, (u8)(vsync_porch % 256)); in lt9611_mipi_video_setup()
166 regmap_write(lt9611->regmap, 0x8319, (u8)(hfront_porch % 256)); in lt9611_mipi_video_setup()
168 regmap_write(lt9611->regmap, 0x831a, (u8)(hsync_porch / 256) | in lt9611_mipi_video_setup()
170 regmap_write(lt9611->regmap, 0x831b, (u8)(hsync_porch % 256)); in lt9611_mipi_video_setup()
175 unsigned int pcr_m = mode->clock * 5 * postdiv / 27000; in lt9611_pcr_setup()
197 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in lt9611_pcr_setup()
199 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in lt9611_pcr_setup()
201 regmap_write(lt9611->regmap, 0x831d, pol); in lt9611_pcr_setup()
203 regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); in lt9611_pcr_setup()
204 if (lt9611->dsi1_node) { in lt9611_pcr_setup()
205 unsigned int hact = mode->hdisplay; in lt9611_pcr_setup()
210 regmap_write(lt9611->regmap, 0x830b, hact / 256); in lt9611_pcr_setup()
211 regmap_write(lt9611->regmap, 0x830c, hact % 256); in lt9611_pcr_setup()
212 regmap_write(lt9611->regmap, 0x8348, hact / 256); in lt9611_pcr_setup()
213 regmap_write(lt9611->regmap, 0x8349, hact % 256); in lt9611_pcr_setup()
216 regmap_write(lt9611->regmap, 0x8326, pcr_m); in lt9611_pcr_setup()
219 regmap_write(lt9611->regmap, 0x8011, 0x5a); in lt9611_pcr_setup()
220 regmap_write(lt9611->regmap, 0x8011, 0xfa); in lt9611_pcr_setup()
225 unsigned int pclk = mode->clock; in lt9611_pll_setup()
240 regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); in lt9611_pll_setup()
243 regmap_write(lt9611->regmap, 0x812d, 0x88); in lt9611_pll_setup()
246 regmap_write(lt9611->regmap, 0x812d, 0x99); in lt9611_pll_setup()
249 regmap_write(lt9611->regmap, 0x812d, 0xaa); in lt9611_pll_setup()
255 * - write divide by 64k to 19:16 bits which means shift by 17 in lt9611_pll_setup()
256 * - write divide by 256 to 15:8 bits which means shift by 9 in lt9611_pll_setup()
257 * - write remainder to 7:0 bits, which means shift by 1 in lt9611_pll_setup()
259 regmap_write(lt9611->regmap, 0x82e3, pclk >> 17); /* pclk[19:16] */ in lt9611_pll_setup()
260 regmap_write(lt9611->regmap, 0x82e4, pclk >> 9); /* pclk[15:8] */ in lt9611_pll_setup()
261 regmap_write(lt9611->regmap, 0x82e5, pclk >> 1); /* pclk[7:0] */ in lt9611_pll_setup()
263 regmap_write(lt9611->regmap, 0x82de, 0x20); in lt9611_pll_setup()
264 regmap_write(lt9611->regmap, 0x82de, 0xe0); in lt9611_pll_setup()
266 regmap_write(lt9611->regmap, 0x8016, 0xf1); in lt9611_pll_setup()
267 regmap_write(lt9611->regmap, 0x8016, 0xf3); in lt9611_pll_setup()
277 ret = regmap_read(lt9611->regmap, reg, &temp); in lt9611_read_video_check()
281 ret = regmap_read(lt9611->regmap, reg + 1, &temp2); in lt9611_read_video_check()
325 dev_info(lt9611->dev, in lt9611_video_check()
332 dev_err(lt9611->dev, "read video check error\n"); in lt9611_video_check()
358 regmap_write(lt9611->regmap, 0x8440 + i, buf[i]); in lt9611_hdmi_set_infoframes()
371 regmap_write(lt9611->regmap, 0x8474 + i, buf[i]); in lt9611_hdmi_set_infoframes()
376 regmap_write(lt9611->regmap, 0x843d, iframes); /* UD1 infoframe */ in lt9611_hdmi_set_infoframes()
382 regmap_write(lt9611->regmap, 0x82d6, 0x8c); in lt9611_hdmi_tx_digital()
384 regmap_write(lt9611->regmap, 0x82d6, 0x0c); in lt9611_hdmi_tx_digital()
385 regmap_write(lt9611->regmap, 0x82d7, 0x04); in lt9611_hdmi_tx_digital()
408 if (lt9611->ac_mode) in lt9611_hdmi_tx_phy()
411 regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); in lt9611_hdmi_tx_phy()
420 regmap_read(lt9611->regmap, 0x820f, &irq_flag3); in lt9611_irq_thread_handler()
421 regmap_read(lt9611->regmap, 0x820c, &irq_flag0); in lt9611_irq_thread_handler()
425 dev_info(lt9611->dev, "hdmi cable disconnected\n"); in lt9611_irq_thread_handler()
427 regmap_write(lt9611->regmap, 0x8207, 0xbf); in lt9611_irq_thread_handler()
428 regmap_write(lt9611->regmap, 0x8207, 0x3f); in lt9611_irq_thread_handler()
433 dev_info(lt9611->dev, "hdmi cable connected\n"); in lt9611_irq_thread_handler()
435 regmap_write(lt9611->regmap, 0x8207, 0x7f); in lt9611_irq_thread_handler()
436 regmap_write(lt9611->regmap, 0x8207, 0x3f); in lt9611_irq_thread_handler()
439 if (irq_flag3 & 0xc0 && lt9611->bridge.dev) in lt9611_irq_thread_handler()
440 drm_kms_helper_hotplug_event(lt9611->bridge.dev); in lt9611_irq_thread_handler()
444 dev_info(lt9611->dev, "video input changed\n"); in lt9611_irq_thread_handler()
445 regmap_write(lt9611->regmap, 0x829e, 0xff); in lt9611_irq_thread_handler()
446 regmap_write(lt9611->regmap, 0x829e, 0xf7); in lt9611_irq_thread_handler()
447 regmap_write(lt9611->regmap, 0x8204, 0xff); in lt9611_irq_thread_handler()
448 regmap_write(lt9611->regmap, 0x8204, 0xfe); in lt9611_irq_thread_handler()
458 regmap_read(lt9611->regmap, 0x8203, &val); in lt9611_enable_hpd_interrupts()
461 regmap_write(lt9611->regmap, 0x8203, val); in lt9611_enable_hpd_interrupts()
462 regmap_write(lt9611->regmap, 0x8207, 0xff); /* clear */ in lt9611_enable_hpd_interrupts()
463 regmap_write(lt9611->regmap, 0x8207, 0x3f); in lt9611_enable_hpd_interrupts()
474 { 0x8102, 0x48 }, /* MIPI Rx power down */ in lt9611_sleep_setup()
480 regmap_multi_reg_write(lt9611->regmap, in lt9611_sleep_setup()
482 lt9611->sleep = true; in lt9611_sleep_setup()
513 if (lt9611->power_on) in lt9611_power_on()
516 ret = regmap_multi_reg_write(lt9611->regmap, seq, ARRAY_SIZE(seq)); in lt9611_power_on()
518 lt9611->power_on = true; in lt9611_power_on()
527 ret = regmap_write(lt9611->regmap, 0x8130, 0x6a); in lt9611_power_off()
529 lt9611->power_on = false; in lt9611_power_off()
536 gpiod_set_value_cansleep(lt9611->reset_gpio, 1); in lt9611_reset()
539 gpiod_set_value_cansleep(lt9611->reset_gpio, 0); in lt9611_reset()
542 gpiod_set_value_cansleep(lt9611->reset_gpio, 1); in lt9611_reset()
548 if (!lt9611->enable_gpio) in lt9611_assert_5v()
551 gpiod_set_value_cansleep(lt9611->enable_gpio, 1); in lt9611_assert_5v()
559 lt9611->supplies[0].supply = "vdd"; in lt9611_regulator_init()
560 lt9611->supplies[1].supply = "vcc"; in lt9611_regulator_init()
562 ret = devm_regulator_bulk_get(lt9611->dev, 2, lt9611->supplies); in lt9611_regulator_init()
566 return regulator_set_load(lt9611->supplies[0].consumer, 300000); in lt9611_regulator_init()
573 ret = regulator_enable(lt9611->supplies[0].consumer); in lt9611_regulator_enable()
579 ret = regulator_enable(lt9611->supplies[1].consumer); in lt9611_regulator_enable()
581 regulator_disable(lt9611->supplies[0].consumer); in lt9611_regulator_enable()
594 regmap_read(lt9611->regmap, 0x825e, ®_val); in lt9611_bridge_detect()
597 lt9611->status = connected ? connector_status_connected : in lt9611_bridge_detect()
600 return lt9611->status; in lt9611_bridge_detect()
610 memset(lt9611->edid_buf, 0, sizeof(lt9611->edid_buf)); in lt9611_read_edid()
612 regmap_write(lt9611->regmap, 0x8503, 0xc9); in lt9611_read_edid()
615 regmap_write(lt9611->regmap, 0x8504, 0xa0); in lt9611_read_edid()
617 regmap_write(lt9611->regmap, 0x8505, 0x00); in lt9611_read_edid()
620 regmap_write(lt9611->regmap, 0x8506, EDID_LEN); in lt9611_read_edid()
621 regmap_write(lt9611->regmap, 0x8514, 0x7f); in lt9611_read_edid()
625 regmap_write(lt9611->regmap, 0x8505, i * EDID_LEN); in lt9611_read_edid()
626 regmap_write(lt9611->regmap, 0x8507, 0x36); in lt9611_read_edid()
627 regmap_write(lt9611->regmap, 0x8507, 0x31); in lt9611_read_edid()
628 regmap_write(lt9611->regmap, 0x8507, 0x37); in lt9611_read_edid()
631 regmap_read(lt9611->regmap, 0x8540, &temp); in lt9611_read_edid()
635 regmap_read(lt9611->regmap, 0x8583, &temp); in lt9611_read_edid()
636 lt9611->edid_buf[i * EDID_LEN + j] = temp; in lt9611_read_edid()
640 dev_err(lt9611->dev, "read edid failed: no ack\n"); in lt9611_read_edid()
641 ret = -EIO; in lt9611_read_edid()
645 dev_err(lt9611->dev, "read edid failed: access not done\n"); in lt9611_read_edid()
646 ret = -EIO; in lt9611_read_edid()
652 regmap_write(lt9611->regmap, 0x8507, 0x1f); in lt9611_read_edid()
663 return -EINVAL; in lt9611_get_edid_block()
668 return -EINVAL; in lt9611_get_edid_block()
673 dev_err(lt9611->dev, "edid read failed\n"); in lt9611_get_edid_block()
679 memcpy(buf, lt9611->edid_buf + (block * 128), len); in lt9611_get_edid_block()
690 struct drm_atomic_state *state = old_bridge_state->base.state; in lt9611_bridge_atomic_enable()
697 connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); in lt9611_bridge_atomic_enable()
705 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); in lt9611_bridge_atomic_enable()
709 mode = &crtc_state->adjusted_mode; in lt9611_bridge_atomic_enable()
717 dev_err(lt9611->dev, "power on failed\n"); in lt9611_bridge_atomic_enable()
723 lt9611_hdmi_tx_digital(lt9611, connector->display_info.is_hdmi); in lt9611_bridge_atomic_enable()
731 regmap_write(lt9611->regmap, 0x8130, 0xea); in lt9611_bridge_atomic_enable()
742 ret = regmap_write(lt9611->regmap, 0x8130, 0x6a); in lt9611_bridge_atomic_disable()
744 dev_err(lt9611->dev, "video on failed\n"); in lt9611_bridge_atomic_disable()
749 dev_err(lt9611->dev, "power on failed\n"); in lt9611_bridge_atomic_disable()
757 const struct mipi_dsi_device_info info = { "lt9611", 0, lt9611->dev->of_node}; in lt9611_attach_dsi()
760 struct device *dev = lt9611->dev; in lt9611_attach_dsi()
765 return ERR_PTR(dev_err_probe(lt9611->dev, -EPROBE_DEFER, "failed to find dsi host\n")); in lt9611_attach_dsi()
769 dev_err(lt9611->dev, "failed to create dsi device\n"); in lt9611_attach_dsi()
773 dsi->lanes = 4; in lt9611_attach_dsi()
774 dsi->format = MIPI_DSI_FMT_RGB888; in lt9611_attach_dsi()
775 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | in lt9611_attach_dsi()
792 return drm_bridge_attach(bridge->encoder, lt9611->next_bridge, in lt9611_bridge_attach()
802 if (mode->hdisplay > 3840) in lt9611_bridge_mode_valid()
805 if (mode->vdisplay > 2160) in lt9611_bridge_mode_valid()
808 if (mode->hdisplay == 3840 && in lt9611_bridge_mode_valid()
809 mode->vdisplay == 2160 && in lt9611_bridge_mode_valid()
813 if (mode->hdisplay > 2000 && !lt9611->dsi1_node) in lt9611_bridge_mode_valid()
830 if (!lt9611->sleep) in lt9611_bridge_atomic_pre_enable()
833 regmap_multi_reg_write(lt9611->regmap, in lt9611_bridge_atomic_pre_enable()
836 lt9611->sleep = false; in lt9611_bridge_atomic_pre_enable()
883 /* This is the DSI-end bus format */ in lt9611_atomic_get_input_bus_fmts()
910 lt9611->dsi0_node = of_graph_get_remote_node(dev->of_node, 0, -1); in lt9611_parse_dt()
911 if (!lt9611->dsi0_node) { in lt9611_parse_dt()
912 dev_err(lt9611->dev, "failed to get remote node for primary dsi\n"); in lt9611_parse_dt()
913 return -ENODEV; in lt9611_parse_dt()
916 lt9611->dsi1_node = of_graph_get_remote_node(dev->of_node, 1, -1); in lt9611_parse_dt()
918 lt9611->ac_mode = of_property_read_bool(dev->of_node, "lt,ac-mode"); in lt9611_parse_dt()
920 return drm_of_find_panel_or_bridge(dev->of_node, 2, -1, NULL, <9611->next_bridge); in lt9611_parse_dt()
925 struct device *dev = lt9611->dev; in lt9611_gpio_init()
927 lt9611->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); in lt9611_gpio_init()
928 if (IS_ERR(lt9611->reset_gpio)) { in lt9611_gpio_init()
930 return PTR_ERR(lt9611->reset_gpio); in lt9611_gpio_init()
933 lt9611->enable_gpio = devm_gpiod_get_optional(dev, "enable", in lt9611_gpio_init()
935 if (IS_ERR(lt9611->enable_gpio)) { in lt9611_gpio_init()
937 return PTR_ERR(lt9611->enable_gpio); in lt9611_gpio_init()
948 regmap_write(lt9611->regmap, 0x80ee, 0x01); in lt9611_read_device_rev()
949 ret = regmap_read(lt9611->regmap, 0x8002, &rev); in lt9611_read_device_rev()
951 dev_err(lt9611->dev, "failed to read revision: %d\n", ret); in lt9611_read_device_rev()
953 dev_info(lt9611->dev, "LT9611 revision: 0x%x\n", rev); in lt9611_read_device_rev()
964 if (hparms->sample_rate == 48000) in lt9611_hdmi_hw_params()
965 regmap_write(lt9611->regmap, 0x840f, 0x2b); in lt9611_hdmi_hw_params()
966 else if (hparms->sample_rate == 96000) in lt9611_hdmi_hw_params()
967 regmap_write(lt9611->regmap, 0x840f, 0xab); in lt9611_hdmi_hw_params()
969 return -EINVAL; in lt9611_hdmi_hw_params()
971 regmap_write(lt9611->regmap, 0x8435, 0x00); in lt9611_hdmi_hw_params()
972 regmap_write(lt9611->regmap, 0x8436, 0x18); in lt9611_hdmi_hw_params()
973 regmap_write(lt9611->regmap, 0x8437, 0x00); in lt9611_hdmi_hw_params()
982 regmap_write(lt9611->regmap, 0x82d6, 0x8c); in lt9611_audio_startup()
983 regmap_write(lt9611->regmap, 0x82d7, 0x04); in lt9611_audio_startup()
985 regmap_write(lt9611->regmap, 0x8406, 0x08); in lt9611_audio_startup()
986 regmap_write(lt9611->regmap, 0x8407, 0x10); in lt9611_audio_startup()
988 regmap_write(lt9611->regmap, 0x8434, 0xd5); in lt9611_audio_startup()
997 regmap_write(lt9611->regmap, 0x8406, 0x00); in lt9611_audio_shutdown()
998 regmap_write(lt9611->regmap, 0x8407, 0x00); in lt9611_audio_shutdown()
1018 return -EINVAL; in lt9611_hdmi_i2s_get_dai_id()
1037 lt9611->audio_pdev = in lt9611_audio_init()
1042 return PTR_ERR_OR_ZERO(lt9611->audio_pdev); in lt9611_audio_init()
1047 if (lt9611->audio_pdev) { in lt9611_audio_exit()
1048 platform_device_unregister(lt9611->audio_pdev); in lt9611_audio_exit()
1049 lt9611->audio_pdev = NULL; in lt9611_audio_exit()
1056 struct device *dev = &client->dev; in lt9611_probe()
1059 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in lt9611_probe()
1061 return -ENODEV; in lt9611_probe()
1066 return -ENOMEM; in lt9611_probe()
1068 lt9611->dev = dev; in lt9611_probe()
1069 lt9611->client = client; in lt9611_probe()
1070 lt9611->sleep = false; in lt9611_probe()
1072 lt9611->regmap = devm_regmap_init_i2c(client, <9611_regmap_config); in lt9611_probe()
1073 if (IS_ERR(lt9611->regmap)) { in lt9611_probe()
1074 dev_err(lt9611->dev, "regmap i2c init failed\n"); in lt9611_probe()
1075 return PTR_ERR(lt9611->regmap); in lt9611_probe()
1106 ret = devm_request_threaded_irq(dev, client->irq, NULL, in lt9611_probe()
1116 lt9611->bridge.funcs = <9611_bridge_funcs; in lt9611_probe()
1117 lt9611->bridge.of_node = client->dev.of_node; in lt9611_probe()
1118 lt9611->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | in lt9611_probe()
1120 lt9611->bridge.type = DRM_MODE_CONNECTOR_HDMIA; in lt9611_probe()
1122 drm_bridge_add(<9611->bridge); in lt9611_probe()
1125 lt9611->dsi0 = lt9611_attach_dsi(lt9611, lt9611->dsi0_node); in lt9611_probe()
1126 if (IS_ERR(lt9611->dsi0)) { in lt9611_probe()
1127 ret = PTR_ERR(lt9611->dsi0); in lt9611_probe()
1132 if (lt9611->dsi1_node) { in lt9611_probe()
1133 lt9611->dsi1 = lt9611_attach_dsi(lt9611, lt9611->dsi1_node); in lt9611_probe()
1134 if (IS_ERR(lt9611->dsi1)) { in lt9611_probe()
1135 ret = PTR_ERR(lt9611->dsi1); in lt9611_probe()
1149 drm_bridge_remove(<9611->bridge); in lt9611_probe()
1152 regulator_bulk_disable(ARRAY_SIZE(lt9611->supplies), lt9611->supplies); in lt9611_probe()
1155 of_node_put(lt9611->dsi1_node); in lt9611_probe()
1156 of_node_put(lt9611->dsi0_node); in lt9611_probe()
1165 disable_irq(client->irq); in lt9611_remove()
1167 drm_bridge_remove(<9611->bridge); in lt9611_remove()
1169 regulator_bulk_disable(ARRAY_SIZE(lt9611->supplies), lt9611->supplies); in lt9611_remove()
1171 of_node_put(lt9611->dsi1_node); in lt9611_remove()
1172 of_node_put(lt9611->dsi0_node); in lt9611_remove()