Lines Matching +full:hdcp +full:- +full:bus

1 // SPDX-License-Identifier: GPL-2.0-only
29 #include "analogix-anx78xx.h"
112 return anx_dp_aux_transfer(anx78xx->map[I2C_IDX_TX_P0], msg); in anx78xx_aux_transfer()
119 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_set_hpd()
124 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL3_REG, in anx78xx_set_hpd()
136 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL3_REG, in anx78xx_clear_hpd()
141 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_clear_hpd()
163 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG, in anx78xx_rx_initialization()
168 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], SP_CHIP_CTRL_REG, in anx78xx_rx_initialization()
174 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
180 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
187 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
193 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
199 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], SP_AUDVID_CTRL_REG, in anx78xx_rx_initialization()
204 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
209 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
215 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_rx_initialization()
221 err = regmap_multi_reg_write(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_rx_initialization()
248 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_ANALOG_CTRL0_REG, in anx78xx_link_phy_initialization()
256 err = regmap_bulk_write(anx78xx->map[I2C_IDX_TX_P1], in anx78xx_link_phy_initialization()
272 err = regmap_update_bits(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_xtal_clk_sel()
279 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL3_REG, in anx78xx_xtal_clk_sel()
284 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL4_REG, in anx78xx_xtal_clk_sel()
289 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_xtal_clk_sel()
294 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_xtal_clk_sel()
300 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_MISC_CTRL_REG, in anx78xx_xtal_clk_sel()
301 XTAL_CLK / 10 - 1); in anx78xx_xtal_clk_sel()
305 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_xtal_clk_sel()
311 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_xtal_clk_sel()
314 ((((XTAL_CLK / 10) >> 1) - 2) << 3)); in anx78xx_xtal_clk_sel()
332 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_AUX_CH_CTRL2_REG, in anx78xx_tx_initialization()
338 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
343 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
349 err = regmap_multi_reg_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
355 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
360 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL8_REG, in anx78xx_tx_initialization()
366 * DP HDCP auto authentication wait timer (when downstream starts to in anx78xx_tx_initialization()
369 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_HDCP_AUTO_TIMER_REG, in anx78xx_tx_initialization()
374 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
379 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
384 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_tx_initialization()
393 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_AUX_DEFER_CTRL_REG, in anx78xx_tx_initialization()
398 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
406 * polling for HDCP CTS item 1A-07 in anx78xx_tx_initialization()
408 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
413 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
419 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
429 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_tx_initialization()
445 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_INT_CTRL_REG, 0x01); in anx78xx_enable_interrupts()
449 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_enable_interrupts()
454 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_MASK1_REG, in anx78xx_enable_interrupts()
459 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_INT_MASK1_REG, in anx78xx_enable_interrupts()
469 struct anx78xx_platform_data *pdata = &anx78xx->pdata; in anx78xx_poweron()
472 if (WARN_ON(anx78xx->powered)) in anx78xx_poweron()
475 if (pdata->dvdd10) { in anx78xx_poweron()
476 err = regulator_enable(pdata->dvdd10); in anx78xx_poweron()
486 gpiod_set_value_cansleep(pdata->gpiod_reset, 1); in anx78xx_poweron()
489 gpiod_set_value_cansleep(pdata->gpiod_pd, 0); in anx78xx_poweron()
492 gpiod_set_value_cansleep(pdata->gpiod_reset, 0); in anx78xx_poweron()
495 anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG, in anx78xx_poweron()
497 anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG, in anx78xx_poweron()
500 anx78xx->powered = true; in anx78xx_poweron()
505 struct anx78xx_platform_data *pdata = &anx78xx->pdata; in anx78xx_poweroff()
508 if (WARN_ON(!anx78xx->powered)) in anx78xx_poweroff()
511 gpiod_set_value_cansleep(pdata->gpiod_reset, 1); in anx78xx_poweroff()
514 gpiod_set_value_cansleep(pdata->gpiod_pd, 1); in anx78xx_poweroff()
517 if (pdata->dvdd10) { in anx78xx_poweroff()
518 err = regulator_disable(pdata->dvdd10); in anx78xx_poweroff()
528 anx78xx->powered = false; in anx78xx_poweroff()
536 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_start()
576 struct anx78xx_platform_data *pdata = &anx78xx->pdata; in anx78xx_init_pdata()
577 struct device *dev = &anx78xx->client->dev; in anx78xx_init_pdata()
580 pdata->dvdd10 = devm_regulator_get(dev, "dvdd10"); in anx78xx_init_pdata()
581 if (IS_ERR(pdata->dvdd10)) { in anx78xx_init_pdata()
582 if (PTR_ERR(pdata->dvdd10) != -EPROBE_DEFER) in anx78xx_init_pdata()
585 return PTR_ERR(pdata->dvdd10); in anx78xx_init_pdata()
589 pdata->gpiod_hpd = devm_gpiod_get(dev, "hpd", GPIOD_IN); in anx78xx_init_pdata()
590 if (IS_ERR(pdata->gpiod_hpd)) in anx78xx_init_pdata()
591 return PTR_ERR(pdata->gpiod_hpd); in anx78xx_init_pdata()
594 pdata->gpiod_pd = devm_gpiod_get(dev, "pd", GPIOD_OUT_HIGH); in anx78xx_init_pdata()
595 if (IS_ERR(pdata->gpiod_pd)) in anx78xx_init_pdata()
596 return PTR_ERR(pdata->gpiod_pd); in anx78xx_init_pdata()
599 pdata->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in anx78xx_init_pdata()
601 return PTR_ERR_OR_ZERO(pdata->gpiod_reset); in anx78xx_init_pdata()
609 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG, in anx78xx_dp_link_training()
614 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_dp_link_training()
620 err = drm_dp_dpcd_readb(&anx78xx->aux, DP_MAX_LINK_RATE, &dp_bw); in anx78xx_dp_link_training()
632 return -EINVAL; in anx78xx_dp_link_training()
635 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG, in anx78xx_dp_link_training()
640 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_dp_link_training()
646 err = drm_dp_dpcd_read(&anx78xx->aux, DP_DPCD_REV, in anx78xx_dp_link_training()
647 &anx78xx->dpcd, DP_RECEIVER_CAP_SIZE); in anx78xx_dp_link_training()
654 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
663 if (anx78xx->dpcd[DP_DPCD_REV] >= 0x11) { in anx78xx_dp_link_training()
664 err = drm_dp_dpcd_readb(&anx78xx->aux, DP_SET_POWER, &dpcd[0]); in anx78xx_dp_link_training()
674 err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_SET_POWER, dpcd[0]); in anx78xx_dp_link_training()
684 * Table 5-52, "Sink Control Field" (register 0x600). in anx78xx_dp_link_training()
690 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
695 if (anx78xx->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5) { in anx78xx_dp_link_training()
698 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
703 err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_DOWNSPREAD_CTRL, in anx78xx_dp_link_training()
708 err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_DOWNSPREAD_CTRL, 0); in anx78xx_dp_link_training()
714 if (drm_dp_enhanced_frame_cap(anx78xx->dpcd)) in anx78xx_dp_link_training()
715 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
719 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
725 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_dp_link_training()
727 anx78xx->dpcd[DP_MAX_LINK_RATE]); in anx78xx_dp_link_training()
731 dpcd[1] = drm_dp_max_lane_count(anx78xx->dpcd); in anx78xx_dp_link_training()
733 if (drm_dp_enhanced_frame_cap(anx78xx->dpcd)) in anx78xx_dp_link_training()
736 err = drm_dp_dpcd_write(&anx78xx->aux, DP_LINK_BW_SET, dpcd, in anx78xx_dp_link_training()
744 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0], SP_DP_LT_CTRL_REG, in anx78xx_dp_link_training()
756 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG, in anx78xx_config_dp_output()
762 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_VID_CTRL1_REG, in anx78xx_config_dp_output()
782 err = anx78xx_clear_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_send_video_infoframe()
787 err = regmap_bulk_write(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_send_video_infoframe()
789 frame->length); in anx78xx_send_video_infoframe()
793 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_send_video_infoframe()
798 err = anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P0], in anx78xx_send_video_infoframe()
811 err = drm_dp_dpcd_readb(&anx78xx->aux, DP_SINK_COUNT, &value); in anx78xx_get_downstream_info()
819 return -EIO; in anx78xx_get_downstream_info()
830 if (WARN_ON(!anx78xx->powered)) in anx78xx_get_modes()
833 if (anx78xx->drm_edid) in anx78xx_get_modes()
836 mutex_lock(&anx78xx->lock); in anx78xx_get_modes()
844 anx78xx->drm_edid = drm_edid_read_ddc(connector, &anx78xx->aux.ddc); in anx78xx_get_modes()
846 err = drm_edid_connector_update(connector, anx78xx->drm_edid); in anx78xx_get_modes()
848 if (!anx78xx->drm_edid) { in anx78xx_get_modes()
861 mutex_unlock(&anx78xx->lock); in anx78xx_get_modes()
875 if (!gpiod_get_value(anx78xx->pdata.gpiod_hpd)) in anx78xx_detect()
898 return -EINVAL; in anx78xx_bridge_attach()
902 anx78xx->aux.name = "DP-AUX"; in anx78xx_bridge_attach()
903 anx78xx->aux.dev = &anx78xx->client->dev; in anx78xx_bridge_attach()
904 anx78xx->aux.drm_dev = bridge->dev; in anx78xx_bridge_attach()
905 anx78xx->aux.transfer = anx78xx_aux_transfer; in anx78xx_bridge_attach()
907 err = drm_dp_aux_register(&anx78xx->aux); in anx78xx_bridge_attach()
913 err = drm_connector_init(bridge->dev, &anx78xx->connector, in anx78xx_bridge_attach()
921 drm_connector_helper_add(&anx78xx->connector, in anx78xx_bridge_attach()
924 anx78xx->connector.polled = DRM_CONNECTOR_POLL_HPD; in anx78xx_bridge_attach()
926 err = drm_connector_attach_encoder(&anx78xx->connector, in anx78xx_bridge_attach()
927 bridge->encoder); in anx78xx_bridge_attach()
933 err = drm_connector_register(&anx78xx->connector); in anx78xx_bridge_attach()
941 drm_connector_cleanup(&anx78xx->connector); in anx78xx_bridge_attach()
943 drm_dp_aux_unregister(&anx78xx->aux); in anx78xx_bridge_attach()
949 drm_dp_aux_unregister(&bridge_to_anx78xx(bridge)->aux); in anx78xx_bridge_detach()
957 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in anx78xx_bridge_mode_valid()
961 if (mode->clock > 154000) in anx78xx_bridge_mode_valid()
972 anx78xx_set_bits(anx78xx->map[I2C_IDX_TX_P2], SP_POWERDOWN_CTRL_REG, in anx78xx_bridge_disable()
984 if (WARN_ON(!anx78xx->powered)) in anx78xx_bridge_mode_set()
987 mutex_lock(&anx78xx->lock); in anx78xx_bridge_mode_set()
990 &anx78xx->connector, in anx78xx_bridge_mode_set()
1002 mutex_unlock(&anx78xx->lock); in anx78xx_bridge_mode_set()
1035 if (anx78xx->powered) in anx78xx_hpd_threaded_handler()
1038 mutex_lock(&anx78xx->lock); in anx78xx_hpd_threaded_handler()
1047 mutex_unlock(&anx78xx->lock); in anx78xx_hpd_threaded_handler()
1058 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_STATUS1_REG, in anx78xx_handle_dp_int_1()
1078 err = regmap_write(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_handle_common_int_4()
1086 DRM_DEBUG_KMS("IRQ: Hot plug detect - cable is pulled out\n"); in anx78xx_handle_common_int_4()
1090 drm_edid_free(anx78xx->drm_edid); in anx78xx_handle_common_int_4()
1091 anx78xx->drm_edid = NULL; in anx78xx_handle_common_int_4()
1093 DRM_DEBUG_KMS("IRQ: Hot plug detect - cable plug\n"); in anx78xx_handle_common_int_4()
1107 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_INT_STATUS1_REG, in anx78xx_handle_hdmi_int_1()
1117 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0], in anx78xx_handle_hdmi_int_1()
1147 mutex_lock(&anx78xx->lock); in anx78xx_intp_threaded_handler()
1149 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DP_INT_STATUS1_REG, in anx78xx_intp_threaded_handler()
1159 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], in anx78xx_intp_threaded_handler()
1171 if (!anx78xx->powered) in anx78xx_intp_threaded_handler()
1174 err = regmap_read(anx78xx->map[I2C_IDX_RX_P0], SP_INT_STATUS1_REG, in anx78xx_intp_threaded_handler()
1185 mutex_unlock(&anx78xx->lock); in anx78xx_intp_threaded_handler()
1188 drm_helper_hpd_irq_event(anx78xx->connector.dev); in anx78xx_intp_threaded_handler()
1197 for (i = 0; i < ARRAY_SIZE(anx78xx->i2c_dummy); i++) in unregister_i2c_dummy_clients()
1198 i2c_unregister_device(anx78xx->i2c_dummy[i]); in unregister_i2c_dummy_clients()
1223 anx78xx = devm_kzalloc(&client->dev, sizeof(*anx78xx), GFP_KERNEL); in anx78xx_i2c_probe()
1225 return -ENOMEM; in anx78xx_i2c_probe()
1227 pdata = &anx78xx->pdata; in anx78xx_i2c_probe()
1229 mutex_init(&anx78xx->lock); in anx78xx_i2c_probe()
1231 anx78xx->bridge.of_node = client->dev.of_node; in anx78xx_i2c_probe()
1233 anx78xx->client = client; in anx78xx_i2c_probe()
1238 if (err != -EPROBE_DEFER) in anx78xx_i2c_probe()
1244 pdata->hpd_irq = gpiod_to_irq(pdata->gpiod_hpd); in anx78xx_i2c_probe()
1245 if (pdata->hpd_irq < 0) { in anx78xx_i2c_probe()
1246 DRM_ERROR("Failed to get HPD IRQ: %d\n", pdata->hpd_irq); in anx78xx_i2c_probe()
1247 return -ENODEV; in anx78xx_i2c_probe()
1250 pdata->intp_irq = client->irq; in anx78xx_i2c_probe()
1251 if (!pdata->intp_irq) { in anx78xx_i2c_probe()
1253 return -ENODEV; in anx78xx_i2c_probe()
1257 i2c_addresses = device_get_match_data(&client->dev); in anx78xx_i2c_probe()
1261 i2c_dummy = i2c_new_dummy_device(client->adapter, in anx78xx_i2c_probe()
1265 DRM_ERROR("Failed to reserve I2C bus %02x: %d\n", in anx78xx_i2c_probe()
1270 anx78xx->i2c_dummy[i] = i2c_dummy; in anx78xx_i2c_probe()
1271 anx78xx->map[i] = devm_regmap_init_i2c(anx78xx->i2c_dummy[i], in anx78xx_i2c_probe()
1273 if (IS_ERR(anx78xx->map[i])) { in anx78xx_i2c_probe()
1274 err = PTR_ERR(anx78xx->map[i]); in anx78xx_i2c_probe()
1284 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_IDL_REG, in anx78xx_i2c_probe()
1289 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_IDH_REG, in anx78xx_i2c_probe()
1294 anx78xx->chipid = (u8)idl | ((u8)idh << 8); in anx78xx_i2c_probe()
1296 err = regmap_read(anx78xx->map[I2C_IDX_TX_P2], SP_DEVICE_VERSION_REG, in anx78xx_i2c_probe()
1302 if (anx78xx->chipid == anx78xx_chipid_list[i]) { in anx78xx_i2c_probe()
1304 anx78xx->chipid, version); in anx78xx_i2c_probe()
1312 anx78xx->chipid, version); in anx78xx_i2c_probe()
1313 err = -ENODEV; in anx78xx_i2c_probe()
1317 err = devm_request_threaded_irq(&client->dev, pdata->hpd_irq, NULL, in anx78xx_i2c_probe()
1320 "anx78xx-hpd", anx78xx); in anx78xx_i2c_probe()
1327 err = devm_request_threaded_irq(&client->dev, pdata->intp_irq, NULL, in anx78xx_i2c_probe()
1330 "anx78xx-intp", anx78xx); in anx78xx_i2c_probe()
1336 anx78xx->bridge.funcs = &anx78xx_bridge_funcs; in anx78xx_i2c_probe()
1338 drm_bridge_add(&anx78xx->bridge); in anx78xx_i2c_probe()
1341 if (!gpiod_get_value(anx78xx->pdata.gpiod_hpd)) in anx78xx_i2c_probe()
1358 drm_bridge_remove(&anx78xx->bridge); in anx78xx_i2c_remove()
1362 drm_edid_free(anx78xx->drm_edid); in anx78xx_i2c_remove()