Lines Matching +full:i2c +full:- +full:lt +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/i2c.h>
10 #include <linux/media-bus-format.h>
52 static int lt8912_write_init_config(struct lt8912 *lt) in lt8912_write_init_config() argument
89 return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, ARRAY_SIZE(seq)); in lt8912_write_init_config()
92 static int lt8912_write_mipi_basic_config(struct lt8912 *lt) in lt8912_write_mipi_basic_config() argument
102 return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq)); in lt8912_write_mipi_basic_config()
105 static int lt8912_write_dds_config(struct lt8912 *lt) in lt8912_write_dds_config() argument
155 return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq)); in lt8912_write_dds_config()
158 static int lt8912_write_rxlogicres_config(struct lt8912 *lt) in lt8912_write_rxlogicres_config() argument
162 ret = regmap_write(lt->regmap[I2C_MAIN], 0x03, 0x7f); in lt8912_write_rxlogicres_config()
164 ret |= regmap_write(lt->regmap[I2C_MAIN], 0x03, 0xff); in lt8912_write_rxlogicres_config()
169 /* enable LVDS output with some hardcoded configuration, not required for the HDMI output */
170 static int lt8912_write_lvds_config(struct lt8912 *lt) in lt8912_write_lvds_config() argument
180 {0x52, 0x04}, // loopdiv=0, use second-order PLL in lt8912_write_lvds_config()
200 return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, ARRAY_SIZE(seq)); in lt8912_write_lvds_config()
219 static int lt8912_init_i2c(struct lt8912 *lt, struct i2c_client *client) in lt8912_init_i2c() argument
231 if (!lt) in lt8912_init_i2c()
232 return -ENODEV; in lt8912_init_i2c()
236 lt->i2c_client[i] = i2c_new_dummy_device(client->adapter, in lt8912_init_i2c()
238 if (IS_ERR(lt->i2c_client[i])) in lt8912_init_i2c()
239 return PTR_ERR(lt->i2c_client[i]); in lt8912_init_i2c()
242 lt->regmap[i] = devm_regmap_init_i2c(lt->i2c_client[i], in lt8912_init_i2c()
244 if (IS_ERR(lt->regmap[i])) in lt8912_init_i2c()
245 return PTR_ERR(lt->regmap[i]); in lt8912_init_i2c()
250 static int lt8912_free_i2c(struct lt8912 *lt) in lt8912_free_i2c() argument
255 i2c_unregister_device(lt->i2c_client[i]); in lt8912_free_i2c()
260 static int lt8912_hard_power_on(struct lt8912 *lt) in lt8912_hard_power_on() argument
264 ret = regulator_bulk_enable(ARRAY_SIZE(lt->supplies), lt->supplies); in lt8912_hard_power_on()
268 gpiod_set_value_cansleep(lt->gp_reset, 0); in lt8912_hard_power_on()
274 static void lt8912_hard_power_off(struct lt8912 *lt) in lt8912_hard_power_off() argument
276 gpiod_set_value_cansleep(lt->gp_reset, 1); in lt8912_hard_power_off()
279 regulator_bulk_disable(ARRAY_SIZE(lt->supplies), lt->supplies); in lt8912_hard_power_off()
281 lt->is_power_on = false; in lt8912_hard_power_off()
284 static int lt8912_video_setup(struct lt8912 *lt) in lt8912_video_setup() argument
291 if (!lt) in lt8912_video_setup()
292 return -EINVAL; in lt8912_video_setup()
294 hactive = lt->mode.hactive; in lt8912_video_setup()
295 hfp = lt->mode.hfront_porch; in lt8912_video_setup()
296 hpw = lt->mode.hsync_len; in lt8912_video_setup()
297 hbp = lt->mode.hback_porch; in lt8912_video_setup()
299 hsync_activehigh = lt->mode.flags & DISPLAY_FLAGS_HSYNC_HIGH; in lt8912_video_setup()
301 vactive = lt->mode.vactive; in lt8912_video_setup()
302 vfp = lt->mode.vfront_porch; in lt8912_video_setup()
303 vpw = lt->mode.vsync_len; in lt8912_video_setup()
304 vbp = lt->mode.vback_porch; in lt8912_video_setup()
306 vsync_activehigh = lt->mode.flags & DISPLAY_FLAGS_VSYNC_HIGH; in lt8912_video_setup()
313 ret = regmap_write(lt->regmap[I2C_CEC_DSI], 0x10, 0x01); in lt8912_video_setup()
314 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x11, settle); in lt8912_video_setup()
315 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x18, hpw); in lt8912_video_setup()
316 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x19, vpw); in lt8912_video_setup()
317 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1c, hactive & 0xff); in lt8912_video_setup()
318 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1d, hactive >> 8); in lt8912_video_setup()
320 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x2f, 0x0c); in lt8912_video_setup()
322 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x34, h_total & 0xff); in lt8912_video_setup()
323 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x35, h_total >> 8); in lt8912_video_setup()
325 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x36, v_total & 0xff); in lt8912_video_setup()
326 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x37, v_total >> 8); in lt8912_video_setup()
328 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x38, vbp & 0xff); in lt8912_video_setup()
329 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x39, vbp >> 8); in lt8912_video_setup()
331 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3a, vfp & 0xff); in lt8912_video_setup()
332 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3b, vfp >> 8); in lt8912_video_setup()
334 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3c, hbp & 0xff); in lt8912_video_setup()
335 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3d, hbp >> 8); in lt8912_video_setup()
337 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3e, hfp & 0xff); in lt8912_video_setup()
338 ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3f, hfp >> 8); in lt8912_video_setup()
340 ret |= regmap_update_bits(lt->regmap[I2C_MAIN], 0xab, BIT(0), in lt8912_video_setup()
342 ret |= regmap_update_bits(lt->regmap[I2C_MAIN], 0xab, BIT(1), in lt8912_video_setup()
344 ret |= regmap_update_bits(lt->regmap[I2C_MAIN], 0xb2, BIT(0), in lt8912_video_setup()
345 lt->connector.display_info.is_hdmi ? BIT(0) : 0); in lt8912_video_setup()
350 static int lt8912_soft_power_on(struct lt8912 *lt) in lt8912_soft_power_on() argument
352 if (!lt->is_power_on) { in lt8912_soft_power_on()
353 u32 lanes = lt->data_lanes; in lt8912_soft_power_on()
355 lt8912_write_init_config(lt); in lt8912_soft_power_on()
356 regmap_write(lt->regmap[I2C_CEC_DSI], 0x13, lanes & 3); in lt8912_soft_power_on()
358 lt8912_write_mipi_basic_config(lt); in lt8912_soft_power_on()
360 lt->is_power_on = true; in lt8912_soft_power_on()
366 static int lt8912_video_on(struct lt8912 *lt) in lt8912_video_on() argument
370 ret = lt8912_video_setup(lt); in lt8912_video_on()
374 ret = lt8912_write_dds_config(lt); in lt8912_video_on()
378 ret = lt8912_write_rxlogicres_config(lt); in lt8912_video_on()
382 ret = lt8912_write_lvds_config(lt); in lt8912_video_on()
390 static enum drm_connector_status lt8912_check_cable_status(struct lt8912 *lt) in lt8912_check_cable_status() argument
395 ret = regmap_read(lt->regmap[I2C_MAIN], 0xC1, ®_val); in lt8912_check_cable_status()
408 struct lt8912 *lt = connector_to_lt8912(connector); in lt8912_connector_detect() local
410 if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT) in lt8912_connector_detect()
411 return drm_bridge_detect(lt->hdmi_port); in lt8912_connector_detect()
413 return lt8912_check_cable_status(lt); in lt8912_connector_detect()
428 struct lt8912 *lt = connector_to_lt8912(connector); in lt8912_connector_get_modes() local
432 drm_edid = drm_bridge_edid_read(lt->hdmi_port, connector); in lt8912_connector_get_modes()
439 ret = drm_display_info_set_bus_formats(&connector->display_info, in lt8912_connector_get_modes()
456 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_mode_set() local
458 drm_display_mode_to_videomode(adj, <->mode); in lt8912_bridge_mode_set()
463 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_enable() local
465 lt8912_video_on(lt); in lt8912_bridge_enable()
468 static int lt8912_attach_dsi(struct lt8912 *lt) in lt8912_attach_dsi() argument
470 struct device *dev = lt->dev; in lt8912_attach_dsi()
473 int ret = -1; in lt8912_attach_dsi()
479 host = of_find_mipi_dsi_host_by_node(lt->host_node); in lt8912_attach_dsi()
481 return dev_err_probe(dev, -EPROBE_DEFER, "failed to find dsi host\n"); in lt8912_attach_dsi()
490 lt->dsi = dsi; in lt8912_attach_dsi()
492 dsi->lanes = lt->data_lanes; in lt8912_attach_dsi()
493 dsi->format = MIPI_DSI_FMT_RGB888; in lt8912_attach_dsi()
495 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | in lt8912_attach_dsi()
510 struct lt8912 *lt = data; in lt8912_bridge_hpd_cb() local
512 if (lt->bridge.dev) in lt8912_bridge_hpd_cb()
513 drm_helper_hpd_irq_event(lt->bridge.dev); in lt8912_bridge_hpd_cb()
519 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_connector_init() local
520 struct drm_connector *connector = <->connector; in lt8912_bridge_connector_init()
522 if (lt->hdmi_port->ops & DRM_BRIDGE_OP_HPD) { in lt8912_bridge_connector_init()
523 drm_bridge_hpd_enable(lt->hdmi_port, lt8912_bridge_hpd_cb, lt); in lt8912_bridge_connector_init()
524 connector->polled = DRM_CONNECTOR_POLL_HPD; in lt8912_bridge_connector_init()
526 connector->polled = DRM_CONNECTOR_POLL_CONNECT | in lt8912_bridge_connector_init()
530 ret = drm_connector_init(bridge->dev, connector, in lt8912_bridge_connector_init()
532 lt->hdmi_port->type); in lt8912_bridge_connector_init()
538 connector->dpms = DRM_MODE_DPMS_OFF; in lt8912_bridge_connector_init()
539 drm_connector_attach_encoder(connector, bridge->encoder); in lt8912_bridge_connector_init()
548 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_attach() local
551 ret = drm_bridge_attach(bridge->encoder, lt->hdmi_port, bridge, in lt8912_bridge_attach()
554 dev_err(lt->dev, "Failed to attach next bridge (%d)\n", ret); in lt8912_bridge_attach()
561 dev_err(lt->dev, "Failed to init bridge ! (%d)\n", ret); in lt8912_bridge_attach()
566 ret = lt8912_hard_power_on(lt); in lt8912_bridge_attach()
570 ret = lt8912_soft_power_on(lt); in lt8912_bridge_attach()
577 lt8912_hard_power_off(lt); in lt8912_bridge_attach()
583 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_detach() local
585 lt8912_hard_power_off(lt); in lt8912_bridge_detach()
587 if (lt->connector.dev && lt->hdmi_port->ops & DRM_BRIDGE_OP_HPD) in lt8912_bridge_detach()
588 drm_bridge_hpd_disable(lt->hdmi_port); in lt8912_bridge_detach()
596 if (mode->clock > 150000) in lt8912_bridge_mode_valid()
599 if (mode->hdisplay > 1920) in lt8912_bridge_mode_valid()
602 if (mode->vdisplay > 1080) in lt8912_bridge_mode_valid()
611 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_detect() local
613 if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT) in lt8912_bridge_detect()
614 return drm_bridge_detect(lt->hdmi_port); in lt8912_bridge_detect()
616 return lt8912_check_cable_status(lt); in lt8912_bridge_detect()
622 struct lt8912 *lt = bridge_to_lt8912(bridge); in lt8912_bridge_edid_read() local
628 if (lt->hdmi_port->ops & DRM_BRIDGE_OP_EDID) in lt8912_bridge_edid_read()
629 return drm_bridge_edid_read(lt->hdmi_port, connector); in lt8912_bridge_edid_read()
631 dev_warn(lt->dev, "The connected bridge does not supports DRM_BRIDGE_OP_EDID\n"); in lt8912_bridge_edid_read()
640 .enable = lt8912_bridge_enable,
647 struct lt8912 *lt = dev_get_drvdata(dev); in lt8912_bridge_resume() local
650 ret = lt8912_hard_power_on(lt); in lt8912_bridge_resume()
654 ret = lt8912_soft_power_on(lt); in lt8912_bridge_resume()
658 return lt8912_video_on(lt); in lt8912_bridge_resume()
663 struct lt8912 *lt = dev_get_drvdata(dev); in lt8912_bridge_suspend() local
665 lt8912_hard_power_off(lt); in lt8912_bridge_suspend()
672 static int lt8912_get_regulators(struct lt8912 *lt) in lt8912_get_regulators() argument
680 for (i = 0; i < ARRAY_SIZE(lt->supplies); i++) in lt8912_get_regulators()
681 lt->supplies[i].supply = supply_names[i]; in lt8912_get_regulators()
683 return devm_regulator_bulk_get(lt->dev, ARRAY_SIZE(lt->supplies), in lt8912_get_regulators()
684 lt->supplies); in lt8912_get_regulators()
687 static int lt8912_parse_dt(struct lt8912 *lt) in lt8912_parse_dt() argument
690 struct device *dev = lt->dev; in lt8912_parse_dt()
698 if (ret != -EPROBE_DEFER) in lt8912_parse_dt()
702 lt->gp_reset = gp_reset; in lt8912_parse_dt()
704 data_lanes = drm_of_get_data_lanes_count_ep(dev->of_node, 0, -1, 1, 4); in lt8912_parse_dt()
706 dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__); in lt8912_parse_dt()
710 lt->data_lanes = data_lanes; in lt8912_parse_dt()
712 lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1); in lt8912_parse_dt()
713 if (!lt->host_node) { in lt8912_parse_dt()
714 dev_err(lt->dev, "%s: Failed to get remote port\n", __func__); in lt8912_parse_dt()
715 return -ENODEV; in lt8912_parse_dt()
718 port_node = of_graph_get_remote_node(dev->of_node, 1, -1); in lt8912_parse_dt()
720 dev_err(lt->dev, "%s: Failed to get connector port\n", __func__); in lt8912_parse_dt()
721 ret = -ENODEV; in lt8912_parse_dt()
725 lt->hdmi_port = of_drm_find_bridge(port_node); in lt8912_parse_dt()
726 if (!lt->hdmi_port) { in lt8912_parse_dt()
727 ret = -EPROBE_DEFER; in lt8912_parse_dt()
728 dev_err_probe(lt->dev, ret, "%s: Failed to get hdmi port\n", __func__); in lt8912_parse_dt()
732 if (!of_device_is_compatible(port_node, "hdmi-connector")) { in lt8912_parse_dt()
733 dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__); in lt8912_parse_dt()
734 ret = -EINVAL; in lt8912_parse_dt()
738 ret = lt8912_get_regulators(lt); in lt8912_parse_dt()
747 of_node_put(lt->host_node); in lt8912_parse_dt()
751 static int lt8912_put_dt(struct lt8912 *lt) in lt8912_put_dt() argument
753 of_node_put(lt->host_node); in lt8912_put_dt()
759 static struct lt8912 *lt; in lt8912_probe() local
761 struct device *dev = &client->dev; in lt8912_probe()
763 lt = devm_kzalloc(dev, sizeof(struct lt8912), GFP_KERNEL); in lt8912_probe()
764 if (!lt) in lt8912_probe()
765 return -ENOMEM; in lt8912_probe()
767 lt->dev = dev; in lt8912_probe()
768 lt->i2c_client[0] = client; in lt8912_probe()
770 ret = lt8912_parse_dt(lt); in lt8912_probe()
774 ret = lt8912_init_i2c(lt, client); in lt8912_probe()
778 i2c_set_clientdata(client, lt); in lt8912_probe()
780 lt->bridge.funcs = <8912_bridge_funcs; in lt8912_probe()
781 lt->bridge.of_node = dev->of_node; in lt8912_probe()
782 lt->bridge.ops = (DRM_BRIDGE_OP_EDID | in lt8912_probe()
785 drm_bridge_add(<->bridge); in lt8912_probe()
787 ret = lt8912_attach_dsi(lt); in lt8912_probe()
794 drm_bridge_remove(<->bridge); in lt8912_probe()
795 lt8912_free_i2c(lt); in lt8912_probe()
797 lt8912_put_dt(lt); in lt8912_probe()
804 struct lt8912 *lt = i2c_get_clientdata(client); in lt8912_remove() local
806 drm_bridge_remove(<->bridge); in lt8912_remove()
807 lt8912_free_i2c(lt); in lt8912_remove()
808 lt8912_put_dt(lt); in lt8912_remove()
821 MODULE_DEVICE_TABLE(i2c, lt8912_id);