Lines Matching +full:edp +full:- +full:bridge

1 /* SPDX-License-Identifier: GPL-2.0-only */
31 #include "analogix-i2c-dptx.h"
32 #include "analogix-i2c-txcommon.h"
48 struct drm_bridge bridge; member
73 static inline struct anx6345 *bridge_to_anx6345(struct drm_bridge *bridge) in bridge_to_anx6345() argument
75 return container_of(bridge, struct anx6345, bridge); in bridge_to_anx6345()
93 return anx_dp_aux_transfer(anx6345->map[I2C_IDX_DPTX], msg); in anx6345_aux_transfer()
102 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_dp_link_training()
108 err = drm_dp_dpcd_readb(&anx6345->aux, DP_MAX_LINK_RATE, &dp_bw); in anx6345_dp_link_training()
119 return -EINVAL; in anx6345_dp_link_training()
122 err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG, in anx6345_dp_link_training()
127 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_dp_link_training()
133 err = drm_dp_dpcd_read(&anx6345->aux, DP_DPCD_REV, in anx6345_dp_link_training()
134 &anx6345->dpcd, DP_RECEIVER_CAP_SIZE); in anx6345_dp_link_training()
141 err = anx6345_clear_bits(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
150 if (anx6345->dpcd[DP_DPCD_REV] >= 0x11) { in anx6345_dp_link_training()
151 err = drm_dp_dpcd_readb(&anx6345->aux, DP_SET_POWER, &dpcd[0]); in anx6345_dp_link_training()
161 err = drm_dp_dpcd_writeb(&anx6345->aux, DP_SET_POWER, dpcd[0]); in anx6345_dp_link_training()
171 * Table 5-52, "Sink Control Field" (register 0x600). in anx6345_dp_link_training()
177 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
182 if (anx6345->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5) { in anx6345_dp_link_training()
185 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
190 err = drm_dp_dpcd_writeb(&anx6345->aux, DP_DOWNSPREAD_CTRL, in anx6345_dp_link_training()
195 err = drm_dp_dpcd_writeb(&anx6345->aux, DP_DOWNSPREAD_CTRL, 0); in anx6345_dp_link_training()
201 if (drm_dp_enhanced_frame_cap(anx6345->dpcd)) in anx6345_dp_link_training()
202 err = anx6345_set_bits(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
206 err = anx6345_clear_bits(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
213 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
218 dpcd[1] = drm_dp_max_lane_count(anx6345->dpcd); in anx6345_dp_link_training()
220 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
225 if (drm_dp_enhanced_frame_cap(anx6345->dpcd)) in anx6345_dp_link_training()
228 err = drm_dp_dpcd_write(&anx6345->aux, DP_LINK_BW_SET, dpcd, in anx6345_dp_link_training()
237 err = regmap_write(anx6345->map[I2C_IDX_DPTX], SP_DP_LT_CTRL_REG, in anx6345_dp_link_training()
242 return regmap_read_poll_timeout(anx6345->map[I2C_IDX_DPTX], in anx6345_dp_link_training()
253 err = regmap_write(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL2_REG, in anx6345_tx_initialization()
258 err = regmap_write(anx6345->map[I2C_IDX_DPTX], SP_DP_PLL_CTRL_REG, 0); in anx6345_tx_initialization()
262 err = regmap_write(anx6345->map[I2C_IDX_TXCOM], in anx6345_tx_initialization()
267 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_tx_initialization()
273 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_tx_initialization()
279 err = anx6345_set_bits(anx6345->map[I2C_IDX_DPTX], in anx6345_tx_initialization()
287 err = regmap_write(anx6345->map[I2C_IDX_DPTX], in anx6345_tx_initialization()
294 err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_tx_initialization()
299 return anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_tx_initialization()
308 gpiod_set_value_cansleep(anx6345->gpiod_reset, 1); in anx6345_poweron()
311 err = regulator_enable(anx6345->dvdd12); in anx6345_poweron()
318 /* T1 - delay between VDD12 and VDD25 should be 0-2ms */ in anx6345_poweron()
321 err = regulator_enable(anx6345->dvdd25); in anx6345_poweron()
328 /* T2 - delay between RESETN and all power rail stable, in anx6345_poweron()
329 * should be 2-5ms in anx6345_poweron()
333 gpiod_set_value_cansleep(anx6345->gpiod_reset, 0); in anx6345_poweron()
336 anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG, in anx6345_poweron()
338 anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG, in anx6345_poweron()
341 if (anx6345->panel) in anx6345_poweron()
342 drm_panel_prepare(anx6345->panel); in anx6345_poweron()
344 anx6345->powered = true; in anx6345_poweron()
351 gpiod_set_value_cansleep(anx6345->gpiod_reset, 1); in anx6345_poweroff()
354 if (anx6345->panel) in anx6345_poweroff()
355 drm_panel_unprepare(anx6345->panel); in anx6345_poweroff()
357 err = regulator_disable(anx6345->dvdd25); in anx6345_poweroff()
366 err = regulator_disable(anx6345->dvdd12); in anx6345_poweroff()
375 anx6345->powered = false; in anx6345_poweroff()
382 if (!anx6345->powered) in anx6345_start()
386 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_start()
392 DRM_ERROR("Failed eDP transmitter initialization: %d\n", err); in anx6345_start()
417 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG, in anx6345_config_dp_output()
423 err = anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_VID_CTRL1_REG, in anx6345_config_dp_output()
429 return anx6345_set_bits(anx6345->map[I2C_IDX_DPTX], in anx6345_config_dp_output()
439 err = drm_dp_dpcd_readb(&anx6345->aux, DP_SINK_COUNT, &value); in anx6345_get_downstream_info()
447 return -EIO; in anx6345_get_downstream_info()
459 mutex_lock(&anx6345->lock); in anx6345_get_modes()
461 if (!anx6345->drm_edid) { in anx6345_get_modes()
462 if (!anx6345->powered) { in anx6345_get_modes()
473 anx6345->drm_edid = drm_edid_read_ddc(connector, &anx6345->aux.ddc); in anx6345_get_modes()
474 if (!anx6345->drm_edid) in anx6345_get_modes()
477 err = drm_edid_connector_update(connector, anx6345->drm_edid); in anx6345_get_modes()
487 connector->display_info.bpc = 6; in anx6345_get_modes()
493 mutex_unlock(&anx6345->lock); in anx6345_get_modes()
495 if (!num_modes && anx6345->panel) in anx6345_get_modes()
496 num_modes += drm_panel_get_modes(anx6345->panel, connector); in anx6345_get_modes()
519 static int anx6345_bridge_attach(struct drm_bridge *bridge, in anx6345_bridge_attach() argument
522 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_attach()
526 DRM_ERROR("Fix bridge driver to make connector optional!"); in anx6345_bridge_attach()
527 return -EINVAL; in anx6345_bridge_attach()
531 anx6345->aux.name = "DP-AUX"; in anx6345_bridge_attach()
532 anx6345->aux.dev = &anx6345->client->dev; in anx6345_bridge_attach()
533 anx6345->aux.drm_dev = bridge->dev; in anx6345_bridge_attach()
534 anx6345->aux.transfer = anx6345_aux_transfer; in anx6345_bridge_attach()
536 err = drm_dp_aux_register(&anx6345->aux); in anx6345_bridge_attach()
542 err = drm_connector_init(bridge->dev, &anx6345->connector, in anx6345_bridge_attach()
550 drm_connector_helper_add(&anx6345->connector, in anx6345_bridge_attach()
553 anx6345->connector.polled = DRM_CONNECTOR_POLL_HPD; in anx6345_bridge_attach()
555 err = drm_connector_attach_encoder(&anx6345->connector, in anx6345_bridge_attach()
556 bridge->encoder); in anx6345_bridge_attach()
562 err = drm_connector_register(&anx6345->connector); in anx6345_bridge_attach()
570 drm_connector_cleanup(&anx6345->connector); in anx6345_bridge_attach()
572 drm_dp_aux_unregister(&anx6345->aux); in anx6345_bridge_attach()
576 static void anx6345_bridge_detach(struct drm_bridge *bridge) in anx6345_bridge_detach() argument
578 drm_dp_aux_unregister(&bridge_to_anx6345(bridge)->aux); in anx6345_bridge_detach()
582 anx6345_bridge_mode_valid(struct drm_bridge *bridge, in anx6345_bridge_mode_valid() argument
586 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in anx6345_bridge_mode_valid()
590 if (mode->clock > 154000) in anx6345_bridge_mode_valid()
596 static void anx6345_bridge_disable(struct drm_bridge *bridge) in anx6345_bridge_disable() argument
598 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_disable()
601 anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG, in anx6345_bridge_disable()
603 if (anx6345->panel) in anx6345_bridge_disable()
604 drm_panel_disable(anx6345->panel); in anx6345_bridge_disable()
606 if (anx6345->powered) in anx6345_bridge_disable()
610 static void anx6345_bridge_enable(struct drm_bridge *bridge) in anx6345_bridge_enable() argument
612 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_enable()
615 if (anx6345->panel) in anx6345_bridge_enable()
616 drm_panel_enable(anx6345->panel); in anx6345_bridge_enable()
641 for (i = 1; i < ARRAY_SIZE(anx6345->i2c_clients); i++) in unregister_i2c_dummy_clients()
642 if (anx6345->i2c_clients[i] && in unregister_i2c_dummy_clients()
643 anx6345->i2c_clients[i]->addr != anx6345->client->addr) in unregister_i2c_dummy_clients()
644 i2c_unregister_device(anx6345->i2c_clients[i]); in unregister_i2c_dummy_clients()
662 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG, &idl)) in anx6345_get_chip_id()
665 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDH_REG, &idh)) in anx6345_get_chip_id()
668 anx6345->chipid = (u8)idl | ((u8)idh << 8); in anx6345_get_chip_id()
670 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_VERSION_REG, in anx6345_get_chip_id()
675 if (anx6345->chipid == anx6345_chipid_list[i]) { in anx6345_get_chip_id()
676 DRM_INFO("Found ANX%x (ver. %d) eDP Transmitter\n", in anx6345_get_chip_id()
677 anx6345->chipid, version); in anx6345_get_chip_id()
683 anx6345->chipid, version); in anx6345_get_chip_id()
694 anx6345 = devm_kzalloc(&client->dev, sizeof(*anx6345), GFP_KERNEL); in anx6345_i2c_probe()
696 return -ENOMEM; in anx6345_i2c_probe()
698 mutex_init(&anx6345->lock); in anx6345_i2c_probe()
700 anx6345->bridge.of_node = client->dev.of_node; in anx6345_i2c_probe()
702 anx6345->client = client; in anx6345_i2c_probe()
705 dev = &anx6345->client->dev; in anx6345_i2c_probe()
707 err = drm_of_find_panel_or_bridge(client->dev.of_node, 1, 0, in anx6345_i2c_probe()
708 &anx6345->panel, NULL); in anx6345_i2c_probe()
709 if (err == -EPROBE_DEFER) in anx6345_i2c_probe()
716 anx6345->dvdd12 = devm_regulator_get(dev, "dvdd12"); in anx6345_i2c_probe()
717 if (IS_ERR(anx6345->dvdd12)) { in anx6345_i2c_probe()
718 if (PTR_ERR(anx6345->dvdd12) != -EPROBE_DEFER) in anx6345_i2c_probe()
720 PTR_ERR(anx6345->dvdd12)); in anx6345_i2c_probe()
721 return PTR_ERR(anx6345->dvdd12); in anx6345_i2c_probe()
725 anx6345->dvdd25 = devm_regulator_get(dev, "dvdd25"); in anx6345_i2c_probe()
726 if (IS_ERR(anx6345->dvdd25)) { in anx6345_i2c_probe()
727 if (PTR_ERR(anx6345->dvdd25) != -EPROBE_DEFER) in anx6345_i2c_probe()
729 PTR_ERR(anx6345->dvdd25)); in anx6345_i2c_probe()
730 return PTR_ERR(anx6345->dvdd25); in anx6345_i2c_probe()
734 anx6345->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in anx6345_i2c_probe()
735 if (IS_ERR(anx6345->gpiod_reset)) { in anx6345_i2c_probe()
737 return PTR_ERR(anx6345->gpiod_reset); in anx6345_i2c_probe()
742 if (anx6345_i2c_addresses[i] >> 1 != client->addr) in anx6345_i2c_probe()
743 anx6345->i2c_clients[i] = i2c_new_dummy_device(client->adapter, in anx6345_i2c_probe()
746 anx6345->i2c_clients[i] = client; in anx6345_i2c_probe()
748 if (IS_ERR(anx6345->i2c_clients[i])) { in anx6345_i2c_probe()
749 err = PTR_ERR(anx6345->i2c_clients[i]); in anx6345_i2c_probe()
755 anx6345->map[i] = devm_regmap_init_i2c(anx6345->i2c_clients[i], in anx6345_i2c_probe()
757 if (IS_ERR(anx6345->map[i])) { in anx6345_i2c_probe()
758 err = PTR_ERR(anx6345->map[i]); in anx6345_i2c_probe()
768 anx6345->bridge.funcs = &anx6345_bridge_funcs; in anx6345_i2c_probe()
769 drm_bridge_add(&anx6345->bridge); in anx6345_i2c_probe()
774 err = -ENODEV; in anx6345_i2c_probe()
786 drm_bridge_remove(&anx6345->bridge); in anx6345_i2c_remove()
790 drm_edid_free(anx6345->drm_edid); in anx6345_i2c_remove()
792 mutex_destroy(&anx6345->lock); in anx6345_i2c_remove()
818 MODULE_DESCRIPTION("ANX6345 eDP Transmitter driver");