Lines Matching full:anx6345
46 struct anx6345 { struct
58 /* I2C Slave addresses of ANX6345 are mapped as DPTX and SYS */
68 static inline struct anx6345 *connector_to_anx6345(struct drm_connector *c) in connector_to_anx6345() argument
70 return container_of(c, struct anx6345, connector); in connector_to_anx6345()
73 static inline struct anx6345 *bridge_to_anx6345(struct drm_bridge *bridge) in bridge_to_anx6345()
75 return container_of(bridge, struct anx6345, bridge); in bridge_to_anx6345()
91 struct anx6345 *anx6345 = container_of(aux, struct anx6345, aux); in anx6345_aux_transfer() local
93 return anx_dp_aux_transfer(anx6345->map[I2C_IDX_DPTX], msg); in anx6345_aux_transfer()
96 static int anx6345_dp_link_training(struct anx6345 *anx6345) in anx6345_dp_link_training() argument
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()
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()
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()
248 static int anx6345_tx_initialization(struct anx6345 *anx6345) in anx6345_tx_initialization() argument
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()
303 static void anx6345_poweron(struct anx6345 *anx6345) in anx6345_poweron() argument
308 gpiod_set_value_cansleep(anx6345->gpiod_reset, 1); in anx6345_poweron()
311 err = regulator_enable(anx6345->dvdd12); in anx6345_poweron()
321 err = regulator_enable(anx6345->dvdd25); 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()
347 static void anx6345_poweroff(struct anx6345 *anx6345) in anx6345_poweroff() argument
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()
378 static int anx6345_start(struct anx6345 *anx6345) in anx6345_start() argument
382 if (!anx6345->powered) in anx6345_start()
383 anx6345_poweron(anx6345); in anx6345_start()
386 err = anx6345_clear_bits(anx6345->map[I2C_IDX_TXCOM], in anx6345_start()
390 err = anx6345_tx_initialization(anx6345); in anx6345_start()
393 anx6345_poweroff(anx6345); in anx6345_start()
397 err = anx6345_dp_link_training(anx6345); in anx6345_start()
400 anx6345_poweroff(anx6345); in anx6345_start()
413 static int anx6345_config_dp_output(struct anx6345 *anx6345) in anx6345_config_dp_output() argument
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()
434 static int anx6345_get_downstream_info(struct anx6345 *anx6345) in anx6345_get_downstream_info() argument
439 err = drm_dp_dpcd_readb(&anx6345->aux, DP_SINK_COUNT, &value); in anx6345_get_downstream_info()
455 struct anx6345 *anx6345 = connector_to_anx6345(connector); in anx6345_get_modes() local
459 mutex_lock(&anx6345->lock); in anx6345_get_modes()
461 if (!anx6345->edid) { in anx6345_get_modes()
462 if (!anx6345->powered) { in anx6345_get_modes()
463 anx6345_poweron(anx6345); in anx6345_get_modes()
467 err = anx6345_get_downstream_info(anx6345); in anx6345_get_modes()
473 anx6345->edid = drm_get_edid(connector, &anx6345->aux.ddc); in anx6345_get_modes()
474 if (!anx6345->edid) in anx6345_get_modes()
478 anx6345->edid); in anx6345_get_modes()
485 num_modes += drm_add_edid_modes(connector, anx6345->edid); in anx6345_get_modes()
492 anx6345_poweroff(anx6345); in anx6345_get_modes()
494 mutex_unlock(&anx6345->lock); in anx6345_get_modes()
496 if (!num_modes && anx6345->panel) in anx6345_get_modes()
497 num_modes += drm_panel_get_modes(anx6345->panel, connector); in anx6345_get_modes()
523 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_attach() local
537 anx6345->aux.name = "DP-AUX"; in anx6345_bridge_attach()
538 anx6345->aux.dev = &anx6345->client->dev; in anx6345_bridge_attach()
539 anx6345->aux.drm_dev = bridge->dev; in anx6345_bridge_attach()
540 anx6345->aux.transfer = anx6345_aux_transfer; in anx6345_bridge_attach()
542 err = drm_dp_aux_register(&anx6345->aux); in anx6345_bridge_attach()
548 err = drm_connector_init(bridge->dev, &anx6345->connector, in anx6345_bridge_attach()
556 drm_connector_helper_add(&anx6345->connector, in anx6345_bridge_attach()
559 anx6345->connector.polled = DRM_CONNECTOR_POLL_HPD; in anx6345_bridge_attach()
561 err = drm_connector_attach_encoder(&anx6345->connector, in anx6345_bridge_attach()
568 err = drm_connector_register(&anx6345->connector); in anx6345_bridge_attach()
576 drm_connector_cleanup(&anx6345->connector); in anx6345_bridge_attach()
578 drm_dp_aux_unregister(&anx6345->aux); in anx6345_bridge_attach()
604 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_disable() local
607 anx6345_set_bits(anx6345->map[I2C_IDX_TXCOM], SP_POWERDOWN_CTRL_REG, in anx6345_bridge_disable()
609 if (anx6345->panel) in anx6345_bridge_disable()
610 drm_panel_disable(anx6345->panel); in anx6345_bridge_disable()
612 if (anx6345->powered) in anx6345_bridge_disable()
613 anx6345_poweroff(anx6345); in anx6345_bridge_disable()
618 struct anx6345 *anx6345 = bridge_to_anx6345(bridge); in anx6345_bridge_enable() local
621 if (anx6345->panel) in anx6345_bridge_enable()
622 drm_panel_enable(anx6345->panel); in anx6345_bridge_enable()
624 err = anx6345_start(anx6345); in anx6345_bridge_enable()
630 err = anx6345_config_dp_output(anx6345); in anx6345_bridge_enable()
643 static void unregister_i2c_dummy_clients(struct anx6345 *anx6345) in unregister_i2c_dummy_clients() argument
647 for (i = 1; i < ARRAY_SIZE(anx6345->i2c_clients); i++) in unregister_i2c_dummy_clients()
648 if (anx6345->i2c_clients[i] && in unregister_i2c_dummy_clients()
649 anx6345->i2c_clients[i]->addr != anx6345->client->addr) in unregister_i2c_dummy_clients()
650 i2c_unregister_device(anx6345->i2c_clients[i]); in unregister_i2c_dummy_clients()
664 static bool anx6345_get_chip_id(struct anx6345 *anx6345) in anx6345_get_chip_id() argument
668 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDL_REG, &idl)) in anx6345_get_chip_id()
671 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_IDH_REG, &idh)) in anx6345_get_chip_id()
674 anx6345->chipid = (u8)idl | ((u8)idh << 8); in anx6345_get_chip_id()
676 if (regmap_read(anx6345->map[I2C_IDX_TXCOM], SP_DEVICE_VERSION_REG, in anx6345_get_chip_id()
681 if (anx6345->chipid == anx6345_chipid_list[i]) { in anx6345_get_chip_id()
683 anx6345->chipid, version); in anx6345_get_chip_id()
689 anx6345->chipid, version); in anx6345_get_chip_id()
696 struct anx6345 *anx6345; in anx6345_i2c_probe() local
700 anx6345 = devm_kzalloc(&client->dev, sizeof(*anx6345), GFP_KERNEL); in anx6345_i2c_probe()
701 if (!anx6345) in anx6345_i2c_probe()
704 mutex_init(&anx6345->lock); in anx6345_i2c_probe()
706 anx6345->bridge.of_node = client->dev.of_node; in anx6345_i2c_probe()
708 anx6345->client = client; in anx6345_i2c_probe()
709 i2c_set_clientdata(client, anx6345); in anx6345_i2c_probe()
711 dev = &anx6345->client->dev; in anx6345_i2c_probe()
714 &anx6345->panel, NULL); in anx6345_i2c_probe()
722 anx6345->dvdd12 = devm_regulator_get(dev, "dvdd12"); in anx6345_i2c_probe()
723 if (IS_ERR(anx6345->dvdd12)) { in anx6345_i2c_probe()
724 if (PTR_ERR(anx6345->dvdd12) != -EPROBE_DEFER) in anx6345_i2c_probe()
726 PTR_ERR(anx6345->dvdd12)); in anx6345_i2c_probe()
727 return PTR_ERR(anx6345->dvdd12); in anx6345_i2c_probe()
731 anx6345->dvdd25 = devm_regulator_get(dev, "dvdd25"); in anx6345_i2c_probe()
732 if (IS_ERR(anx6345->dvdd25)) { in anx6345_i2c_probe()
733 if (PTR_ERR(anx6345->dvdd25) != -EPROBE_DEFER) in anx6345_i2c_probe()
735 PTR_ERR(anx6345->dvdd25)); in anx6345_i2c_probe()
736 return PTR_ERR(anx6345->dvdd25); in anx6345_i2c_probe()
740 anx6345->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in anx6345_i2c_probe()
741 if (IS_ERR(anx6345->gpiod_reset)) { in anx6345_i2c_probe()
743 return PTR_ERR(anx6345->gpiod_reset); in anx6345_i2c_probe()
746 /* Map slave addresses of ANX6345 */ in anx6345_i2c_probe()
749 anx6345->i2c_clients[i] = i2c_new_dummy_device(client->adapter, in anx6345_i2c_probe()
752 anx6345->i2c_clients[i] = client; in anx6345_i2c_probe()
754 if (IS_ERR(anx6345->i2c_clients[i])) { in anx6345_i2c_probe()
755 err = PTR_ERR(anx6345->i2c_clients[i]); in anx6345_i2c_probe()
761 anx6345->map[i] = devm_regmap_init_i2c(anx6345->i2c_clients[i], in anx6345_i2c_probe()
763 if (IS_ERR(anx6345->map[i])) { in anx6345_i2c_probe()
764 err = PTR_ERR(anx6345->map[i]); in anx6345_i2c_probe()
772 anx6345_poweron(anx6345); in anx6345_i2c_probe()
773 if (anx6345_get_chip_id(anx6345)) { in anx6345_i2c_probe()
774 anx6345->bridge.funcs = &anx6345_bridge_funcs; in anx6345_i2c_probe()
775 drm_bridge_add(&anx6345->bridge); in anx6345_i2c_probe()
779 anx6345_poweroff(anx6345); in anx6345_i2c_probe()
784 unregister_i2c_dummy_clients(anx6345); in anx6345_i2c_probe()
790 struct anx6345 *anx6345 = i2c_get_clientdata(client); in anx6345_i2c_remove() local
792 drm_bridge_remove(&anx6345->bridge); in anx6345_i2c_remove()
794 unregister_i2c_dummy_clients(anx6345); in anx6345_i2c_remove()
796 kfree(anx6345->edid); in anx6345_i2c_remove()
798 mutex_destroy(&anx6345->lock); in anx6345_i2c_remove()
802 { "anx6345", 0 },
808 { .compatible = "analogix,anx6345", },
815 .name = "anx6345",
824 MODULE_DESCRIPTION("ANX6345 eDP Transmitter driver");