Lines Matching refs:mhdp

58 	struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge);  in cdns_mhdp_bridge_hpd_enable()  local
61 if (mhdp->bridge_attached) in cdns_mhdp_bridge_hpd_enable()
62 writel(readl(mhdp->regs + CDNS_APB_INT_MASK) & in cdns_mhdp_bridge_hpd_enable()
64 mhdp->regs + CDNS_APB_INT_MASK); in cdns_mhdp_bridge_hpd_enable()
69 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_bridge_hpd_disable() local
71 writel(readl(mhdp->regs + CDNS_APB_INT_MASK) | in cdns_mhdp_bridge_hpd_disable()
73 mhdp->regs + CDNS_APB_INT_MASK); in cdns_mhdp_bridge_hpd_disable()
76 static int cdns_mhdp_mailbox_read(struct cdns_mhdp_device *mhdp) in cdns_mhdp_mailbox_read() argument
80 WARN_ON(!mutex_is_locked(&mhdp->mbox_mutex)); in cdns_mhdp_mailbox_read()
82 ret = readx_poll_timeout(readl, mhdp->regs + CDNS_MAILBOX_EMPTY, in cdns_mhdp_mailbox_read()
88 return readl(mhdp->regs + CDNS_MAILBOX_RX_DATA) & 0xff; in cdns_mhdp_mailbox_read()
91 static int cdns_mhdp_mailbox_write(struct cdns_mhdp_device *mhdp, u8 val) in cdns_mhdp_mailbox_write() argument
95 WARN_ON(!mutex_is_locked(&mhdp->mbox_mutex)); in cdns_mhdp_mailbox_write()
97 ret = readx_poll_timeout(readl, mhdp->regs + CDNS_MAILBOX_FULL, in cdns_mhdp_mailbox_write()
103 writel(val, mhdp->regs + CDNS_MAILBOX_TX_DATA); in cdns_mhdp_mailbox_write()
108 static int cdns_mhdp_mailbox_recv_header(struct cdns_mhdp_device *mhdp, in cdns_mhdp_mailbox_recv_header() argument
118 ret = cdns_mhdp_mailbox_read(mhdp); in cdns_mhdp_mailbox_recv_header()
134 if (cdns_mhdp_mailbox_read(mhdp) < 0) in cdns_mhdp_mailbox_recv_header()
143 static int cdns_mhdp_mailbox_recv_data(struct cdns_mhdp_device *mhdp, in cdns_mhdp_mailbox_recv_data() argument
150 ret = cdns_mhdp_mailbox_read(mhdp); in cdns_mhdp_mailbox_recv_data()
160 static int cdns_mhdp_mailbox_send(struct cdns_mhdp_device *mhdp, u8 module_id, in cdns_mhdp_mailbox_send() argument
171 ret = cdns_mhdp_mailbox_write(mhdp, header[i]); in cdns_mhdp_mailbox_send()
177 ret = cdns_mhdp_mailbox_write(mhdp, message[i]); in cdns_mhdp_mailbox_send()
186 int cdns_mhdp_reg_read(struct cdns_mhdp_device *mhdp, u32 addr, u32 *value) in cdns_mhdp_reg_read() argument
193 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_reg_read()
195 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_GENERAL, in cdns_mhdp_reg_read()
201 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_GENERAL, in cdns_mhdp_reg_read()
207 ret = cdns_mhdp_mailbox_recv_data(mhdp, resp, sizeof(resp)); in cdns_mhdp_reg_read()
220 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_reg_read()
222 dev_err(mhdp->dev, "Failed to read register\n"); in cdns_mhdp_reg_read()
230 int cdns_mhdp_reg_write(struct cdns_mhdp_device *mhdp, u16 addr, u32 val) in cdns_mhdp_reg_write() argument
238 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_reg_write()
240 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_reg_write()
243 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_reg_write()
249 int cdns_mhdp_reg_write_bit(struct cdns_mhdp_device *mhdp, u16 addr, in cdns_mhdp_reg_write_bit() argument
260 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_reg_write_bit()
262 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_reg_write_bit()
265 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_reg_write_bit()
271 int cdns_mhdp_dpcd_read(struct cdns_mhdp_device *mhdp, in cdns_mhdp_dpcd_read() argument
280 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_dpcd_read()
282 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_dpcd_read()
287 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_dpcd_read()
293 ret = cdns_mhdp_mailbox_recv_data(mhdp, reg, sizeof(reg)); in cdns_mhdp_dpcd_read()
297 ret = cdns_mhdp_mailbox_recv_data(mhdp, data, len); in cdns_mhdp_dpcd_read()
300 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_dpcd_read()
306 int cdns_mhdp_dpcd_write(struct cdns_mhdp_device *mhdp, u32 addr, u8 value) in cdns_mhdp_dpcd_write() argument
315 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_dpcd_write()
317 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_dpcd_write()
322 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_dpcd_write()
327 ret = cdns_mhdp_mailbox_recv_data(mhdp, reg, sizeof(reg)); in cdns_mhdp_dpcd_write()
335 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_dpcd_write()
338 dev_err(mhdp->dev, "dpcd write failed: %d\n", ret); in cdns_mhdp_dpcd_write()
343 int cdns_mhdp_set_firmware_active(struct cdns_mhdp_device *mhdp, bool enable) in cdns_mhdp_set_firmware_active() argument
354 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_set_firmware_active()
357 ret = cdns_mhdp_mailbox_write(mhdp, msg[i]); in cdns_mhdp_set_firmware_active()
363 ret = cdns_mhdp_mailbox_recv_data(mhdp, msg, sizeof(msg)); in cdns_mhdp_set_firmware_active()
370 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_set_firmware_active()
373 dev_err(mhdp->dev, "set firmware active failed\n"); in cdns_mhdp_set_firmware_active()
378 int cdns_mhdp_get_hpd_status(struct cdns_mhdp_device *mhdp) in cdns_mhdp_get_hpd_status() argument
383 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_get_hpd_status()
385 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_get_hpd_status()
390 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_get_hpd_status()
396 ret = cdns_mhdp_mailbox_recv_data(mhdp, &status, sizeof(status)); in cdns_mhdp_get_hpd_status()
400 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_get_hpd_status()
402 dev_dbg(mhdp->dev, "%s: HPD %splugged\n", __func__, in cdns_mhdp_get_hpd_status()
408 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_get_hpd_status()
417 struct cdns_mhdp_device *mhdp = data; in cdns_mhdp_get_edid_block() local
421 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_get_edid_block()
427 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_get_edid_block()
432 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_get_edid_block()
438 ret = cdns_mhdp_mailbox_recv_data(mhdp, reg, sizeof(reg)); in cdns_mhdp_get_edid_block()
442 ret = cdns_mhdp_mailbox_recv_data(mhdp, edid, length); in cdns_mhdp_get_edid_block()
450 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_get_edid_block()
453 dev_err(mhdp->dev, "get block[%d] edid failed: %d\n", in cdns_mhdp_get_edid_block()
460 int cdns_mhdp_read_hpd_event(struct cdns_mhdp_device *mhdp) in cdns_mhdp_read_hpd_event() argument
465 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_read_hpd_event()
467 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_read_hpd_event()
472 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_read_hpd_event()
477 ret = cdns_mhdp_mailbox_recv_data(mhdp, &event, sizeof(event)); in cdns_mhdp_read_hpd_event()
479 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_read_hpd_event()
484 dev_dbg(mhdp->dev, "%s: %s%s%s%s\n", __func__, in cdns_mhdp_read_hpd_event()
494 int cdns_mhdp_adjust_lt(struct cdns_mhdp_device *mhdp, unsigned int nlanes, in cdns_mhdp_adjust_lt() argument
504 dev_err(mhdp->dev, "invalid number of lanes: %u\n", nlanes); in cdns_mhdp_adjust_lt()
513 mutex_lock(&mhdp->mbox_mutex); in cdns_mhdp_adjust_lt()
515 ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_adjust_lt()
522 ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_DP_TX, in cdns_mhdp_adjust_lt()
528 ret = cdns_mhdp_mailbox_recv_data(mhdp, hdr, sizeof(hdr)); in cdns_mhdp_adjust_lt()
536 ret = cdns_mhdp_mailbox_recv_data(mhdp, link_status, in cdns_mhdp_adjust_lt()
540 mutex_unlock(&mhdp->mbox_mutex); in cdns_mhdp_adjust_lt()
543 dev_err(mhdp->dev, "Failed to adjust Link Training.\n"); in cdns_mhdp_adjust_lt()
645 static unsigned int cdns_mhdp_max_link_rate(struct cdns_mhdp_device *mhdp) in cdns_mhdp_max_link_rate() argument
647 return min(mhdp->host.link_rate, mhdp->sink.link_rate); in cdns_mhdp_max_link_rate()
650 static u8 cdns_mhdp_max_num_lanes(struct cdns_mhdp_device *mhdp) in cdns_mhdp_max_num_lanes() argument
652 return min(mhdp->sink.lanes_cnt, mhdp->host.lanes_cnt); in cdns_mhdp_max_num_lanes()
655 static u8 cdns_mhdp_eq_training_pattern_supported(struct cdns_mhdp_device *mhdp) in cdns_mhdp_eq_training_pattern_supported() argument
657 return fls(mhdp->host.pattern_supp & mhdp->sink.pattern_supp); in cdns_mhdp_eq_training_pattern_supported()
660 static bool cdns_mhdp_get_ssc_supported(struct cdns_mhdp_device *mhdp) in cdns_mhdp_get_ssc_supported() argument
663 return mhdp->host.ssc && mhdp->sink.ssc; in cdns_mhdp_get_ssc_supported()
666 static enum drm_connector_status cdns_mhdp_detect(struct cdns_mhdp_device *mhdp) in cdns_mhdp_detect() argument
668 dev_dbg(mhdp->dev, "%s: %d\n", __func__, mhdp->plugged); in cdns_mhdp_detect()
670 if (mhdp->plugged) in cdns_mhdp_detect()
676 static int cdns_mhdp_check_fw_version(struct cdns_mhdp_device *mhdp) in cdns_mhdp_check_fw_version() argument
681 fw_ver = (readl(mhdp->regs + CDNS_VER_H) << 8) in cdns_mhdp_check_fw_version()
682 | readl(mhdp->regs + CDNS_VER_L); in cdns_mhdp_check_fw_version()
684 lib_ver = (readl(mhdp->regs + CDNS_LIB_H_ADDR) << 8) in cdns_mhdp_check_fw_version()
685 | readl(mhdp->regs + CDNS_LIB_L_ADDR); in cdns_mhdp_check_fw_version()
700 dev_err(mhdp->dev, "Unsupported FW version: fw_ver = %u, lib_ver = %u\n", in cdns_mhdp_check_fw_version()
711 dev_dbg(mhdp->dev, "FW version: v%u.%u.%u\n", major_num, minor_num, in cdns_mhdp_check_fw_version()
717 struct cdns_mhdp_device *mhdp) in cdns_mhdp_fw_activate() argument
723 writel(CDNS_CPU_STALL, mhdp->regs + CDNS_APB_CTRL); in cdns_mhdp_fw_activate()
725 memcpy_toio(mhdp->regs + CDNS_MHDP_IMEM, fw->data, fw->size); in cdns_mhdp_fw_activate()
728 writel(0, mhdp->regs + CDNS_APB_CTRL); in cdns_mhdp_fw_activate()
734 ret = readl_poll_timeout(mhdp->regs + CDNS_KEEP_ALIVE, reg, in cdns_mhdp_fw_activate()
738 dev_err(mhdp->dev, in cdns_mhdp_fw_activate()
743 ret = cdns_mhdp_check_fw_version(mhdp); in cdns_mhdp_fw_activate()
748 readl(mhdp->regs + CDNS_SW_EVENT0); in cdns_mhdp_fw_activate()
749 readl(mhdp->regs + CDNS_SW_EVENT1); in cdns_mhdp_fw_activate()
750 readl(mhdp->regs + CDNS_SW_EVENT2); in cdns_mhdp_fw_activate()
751 readl(mhdp->regs + CDNS_SW_EVENT3); in cdns_mhdp_fw_activate()
754 ret = cdns_mhdp_set_firmware_active(mhdp, true); in cdns_mhdp_fw_activate()
758 spin_lock(&mhdp->start_lock); in cdns_mhdp_fw_activate()
760 mhdp->hw_state = MHDP_HW_READY; in cdns_mhdp_fw_activate()
771 cdns_mhdp_bridge_hpd_enable(&mhdp->bridge); in cdns_mhdp_fw_activate()
773 spin_unlock(&mhdp->start_lock); in cdns_mhdp_fw_activate()
775 wake_up(&mhdp->fw_load_wq); in cdns_mhdp_fw_activate()
776 dev_dbg(mhdp->dev, "DP FW activated\n"); in cdns_mhdp_fw_activate()
783 struct cdns_mhdp_device *mhdp = context; in cdns_mhdp_fw_cb() local
787 dev_dbg(mhdp->dev, "firmware callback\n"); in cdns_mhdp_fw_cb()
790 dev_err(mhdp->dev, "%s: No firmware.\n", __func__); in cdns_mhdp_fw_cb()
794 ret = cdns_mhdp_fw_activate(fw, mhdp); in cdns_mhdp_fw_cb()
809 spin_lock(&mhdp->start_lock); in cdns_mhdp_fw_cb()
810 bridge_attached = mhdp->bridge_attached; in cdns_mhdp_fw_cb()
811 spin_unlock(&mhdp->start_lock); in cdns_mhdp_fw_cb()
813 if (mhdp->connector.dev) in cdns_mhdp_fw_cb()
814 drm_kms_helper_hotplug_event(mhdp->bridge.dev); in cdns_mhdp_fw_cb()
816 drm_bridge_hpd_notify(&mhdp->bridge, cdns_mhdp_detect(mhdp)); in cdns_mhdp_fw_cb()
820 static int cdns_mhdp_load_firmware(struct cdns_mhdp_device *mhdp) in cdns_mhdp_load_firmware() argument
824 ret = request_firmware_nowait(THIS_MODULE, true, FW_NAME, mhdp->dev, in cdns_mhdp_load_firmware()
825 GFP_KERNEL, mhdp, cdns_mhdp_fw_cb); in cdns_mhdp_load_firmware()
827 dev_err(mhdp->dev, "failed to load firmware (%s), ret: %d\n", in cdns_mhdp_load_firmware()
838 struct cdns_mhdp_device *mhdp = dev_get_drvdata(aux->dev); in cdns_mhdp_transfer() local
850 ret = cdns_mhdp_dpcd_write(mhdp, in cdns_mhdp_transfer()
855 dev_err(mhdp->dev, in cdns_mhdp_transfer()
862 ret = cdns_mhdp_dpcd_read(mhdp, msg->address, in cdns_mhdp_transfer()
865 dev_err(mhdp->dev, in cdns_mhdp_transfer()
876 static int cdns_mhdp_link_training_init(struct cdns_mhdp_device *mhdp) in cdns_mhdp_link_training_init() argument
882 drm_dp_dpcd_writeb(&mhdp->aux, DP_TRAINING_PATTERN_SET, in cdns_mhdp_link_training_init()
887 if (!mhdp->host.scrambler) in cdns_mhdp_link_training_init()
890 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_PHY_CONFIG, reg32); in cdns_mhdp_link_training_init()
892 cdns_mhdp_reg_write(mhdp, CDNS_DP_ENHNCD, in cdns_mhdp_link_training_init()
893 mhdp->sink.enhanced & mhdp->host.enhanced); in cdns_mhdp_link_training_init()
895 cdns_mhdp_reg_write(mhdp, CDNS_DP_LANE_EN, in cdns_mhdp_link_training_init()
896 CDNS_DP_LANE_EN_LANES(mhdp->link.num_lanes)); in cdns_mhdp_link_training_init()
898 cdns_mhdp_link_configure(&mhdp->aux, &mhdp->link); in cdns_mhdp_link_training_init()
899 phy_cfg.dp.link_rate = mhdp->link.rate / 100; in cdns_mhdp_link_training_init()
900 phy_cfg.dp.lanes = mhdp->link.num_lanes; in cdns_mhdp_link_training_init()
905 phy_cfg.dp.ssc = cdns_mhdp_get_ssc_supported(mhdp); in cdns_mhdp_link_training_init()
909 ret = phy_configure(mhdp->phy, &phy_cfg); in cdns_mhdp_link_training_init()
911 dev_err(mhdp->dev, "%s: phy_configure() failed: %d\n", in cdns_mhdp_link_training_init()
916 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_PHY_CONFIG, in cdns_mhdp_link_training_init()
922 drm_dp_dpcd_writeb(&mhdp->aux, DP_TRAINING_PATTERN_SET, in cdns_mhdp_link_training_init()
928 static void cdns_mhdp_get_adjust_train(struct cdns_mhdp_device *mhdp, in cdns_mhdp_get_adjust_train() argument
937 max_pre_emph = CDNS_PRE_EMPHASIS(mhdp->host.pre_emphasis) in cdns_mhdp_get_adjust_train()
939 max_volt_swing = CDNS_VOLT_SWING(mhdp->host.volt_swing); in cdns_mhdp_get_adjust_train()
941 for (i = 0; i < mhdp->link.num_lanes; i++) { in cdns_mhdp_get_adjust_train()
998 static void cdns_mhdp_adjust_requested_eq(struct cdns_mhdp_device *mhdp, in cdns_mhdp_adjust_requested_eq() argument
1001 u8 max_pre = CDNS_PRE_EMPHASIS(mhdp->host.pre_emphasis); in cdns_mhdp_adjust_requested_eq()
1002 u8 max_volt = CDNS_VOLT_SWING(mhdp->host.volt_swing); in cdns_mhdp_adjust_requested_eq()
1006 for (i = 0; i < mhdp->link.num_lanes; i++) { in cdns_mhdp_adjust_requested_eq()
1012 if (mhdp->host.volt_swing & CDNS_FORCE_VOLT_SWING) in cdns_mhdp_adjust_requested_eq()
1015 if (mhdp->host.pre_emphasis & CDNS_FORCE_PRE_EMPHASIS) in cdns_mhdp_adjust_requested_eq()
1022 struct cdns_mhdp_device *mhdp, in cdns_mhdp_print_lt_status() argument
1029 for (i = 0; i < mhdp->link.num_lanes; i++) { in cdns_mhdp_print_lt_status()
1037 dev_dbg(mhdp->dev, "%s, %u lanes, %u Mbps, vs %s, pe %s\n", in cdns_mhdp_print_lt_status()
1039 mhdp->link.num_lanes, mhdp->link.rate / 100, in cdns_mhdp_print_lt_status()
1043 static bool cdns_mhdp_link_training_channel_eq(struct cdns_mhdp_device *mhdp, in cdns_mhdp_link_training_channel_eq() argument
1054 dev_dbg(mhdp->dev, "Starting EQ phase\n"); in cdns_mhdp_link_training_channel_eq()
1061 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_PHY_CONFIG, reg32); in cdns_mhdp_link_training_channel_eq()
1063 drm_dp_dpcd_writeb(&mhdp->aux, DP_TRAINING_PATTERN_SET, in cdns_mhdp_link_training_channel_eq()
1067 drm_dp_dpcd_read_link_status(&mhdp->aux, link_status); in cdns_mhdp_link_training_channel_eq()
1070 cdns_mhdp_get_adjust_train(mhdp, link_status, lanes_data, in cdns_mhdp_link_training_channel_eq()
1072 phy_cfg.dp.lanes = mhdp->link.num_lanes; in cdns_mhdp_link_training_channel_eq()
1073 phy_cfg.dp.ssc = cdns_mhdp_get_ssc_supported(mhdp); in cdns_mhdp_link_training_channel_eq()
1077 ret = phy_configure(mhdp->phy, &phy_cfg); in cdns_mhdp_link_training_channel_eq()
1079 dev_err(mhdp->dev, "%s: phy_configure() failed: %d\n", in cdns_mhdp_link_training_channel_eq()
1084 cdns_mhdp_adjust_lt(mhdp, mhdp->link.num_lanes, in cdns_mhdp_link_training_channel_eq()
1087 r = drm_dp_clock_recovery_ok(link_status, mhdp->link.num_lanes); in cdns_mhdp_link_training_channel_eq()
1091 if (drm_dp_channel_eq_ok(link_status, mhdp->link.num_lanes)) { in cdns_mhdp_link_training_channel_eq()
1092 cdns_mhdp_print_lt_status("EQ phase ok", mhdp, in cdns_mhdp_link_training_channel_eq()
1099 cdns_mhdp_adjust_requested_eq(mhdp, link_status); in cdns_mhdp_link_training_channel_eq()
1103 cdns_mhdp_print_lt_status("EQ phase failed", mhdp, &phy_cfg); in cdns_mhdp_link_training_channel_eq()
1108 static void cdns_mhdp_adjust_requested_cr(struct cdns_mhdp_device *mhdp, in cdns_mhdp_adjust_requested_cr() argument
1112 const u8 max_volt = CDNS_VOLT_SWING(mhdp->host.volt_swing); in cdns_mhdp_adjust_requested_cr()
1113 const u8 max_pre = CDNS_PRE_EMPHASIS(mhdp->host.pre_emphasis); in cdns_mhdp_adjust_requested_cr()
1116 for (i = 0; i < mhdp->link.num_lanes; i++) { in cdns_mhdp_adjust_requested_cr()
1119 val = mhdp->host.volt_swing & CDNS_FORCE_VOLT_SWING ? in cdns_mhdp_adjust_requested_cr()
1123 val = mhdp->host.pre_emphasis & CDNS_FORCE_PRE_EMPHASIS ? in cdns_mhdp_adjust_requested_cr()
1130 void cdns_mhdp_validate_cr(struct cdns_mhdp_device *mhdp, bool *cr_done, in cdns_mhdp_validate_cr() argument
1136 const u8 max_volt = CDNS_VOLT_SWING(mhdp->host.volt_swing); in cdns_mhdp_validate_cr()
1137 const u8 max_pre = CDNS_PRE_EMPHASIS(mhdp->host.pre_emphasis); in cdns_mhdp_validate_cr()
1144 *cr_done = drm_dp_clock_recovery_ok(after_cr, mhdp->link.num_lanes); in cdns_mhdp_validate_cr()
1146 for (i = 0; i < mhdp->link.num_lanes; i++) { in cdns_mhdp_validate_cr()
1169 static bool cdns_mhdp_link_training_cr(struct cdns_mhdp_device *mhdp) in cdns_mhdp_link_training_cr() argument
1178 dev_dbg(mhdp->dev, "Starting CR phase\n"); in cdns_mhdp_link_training_cr()
1180 ret = cdns_mhdp_link_training_init(mhdp); in cdns_mhdp_link_training_cr()
1184 drm_dp_dpcd_read_link_status(&mhdp->aux, link_status); in cdns_mhdp_link_training_cr()
1191 cdns_mhdp_get_adjust_train(mhdp, link_status, lanes_data, in cdns_mhdp_link_training_cr()
1193 phy_cfg.dp.lanes = mhdp->link.num_lanes; in cdns_mhdp_link_training_cr()
1194 phy_cfg.dp.ssc = cdns_mhdp_get_ssc_supported(mhdp); in cdns_mhdp_link_training_cr()
1198 ret = phy_configure(mhdp->phy, &phy_cfg); in cdns_mhdp_link_training_cr()
1200 dev_err(mhdp->dev, "%s: phy_configure() failed: %d\n", in cdns_mhdp_link_training_cr()
1205 cdns_mhdp_adjust_lt(mhdp, mhdp->link.num_lanes, 100, in cdns_mhdp_link_training_cr()
1208 cdns_mhdp_validate_cr(mhdp, &cr_done, &same_before_adjust, in cdns_mhdp_link_training_cr()
1215 dev_err(mhdp->dev, "CR: max swing reached\n"); in cdns_mhdp_link_training_cr()
1220 cdns_mhdp_print_lt_status("CR phase ok", mhdp, in cdns_mhdp_link_training_cr()
1238 cdns_mhdp_adjust_requested_cr(mhdp, link_status, in cdns_mhdp_link_training_cr()
1244 cdns_mhdp_print_lt_status("CR phase failed", mhdp, &phy_cfg); in cdns_mhdp_link_training_cr()
1264 static int cdns_mhdp_link_training(struct cdns_mhdp_device *mhdp, in cdns_mhdp_link_training() argument
1268 const u8 eq_tps = cdns_mhdp_eq_training_pattern_supported(mhdp); in cdns_mhdp_link_training()
1272 if (!cdns_mhdp_link_training_cr(mhdp)) { in cdns_mhdp_link_training()
1273 if (drm_dp_link_rate_to_bw_code(mhdp->link.rate) != in cdns_mhdp_link_training()
1275 dev_dbg(mhdp->dev, in cdns_mhdp_link_training()
1277 cdns_mhdp_lower_link_rate(&mhdp->link); in cdns_mhdp_link_training()
1280 } else if (mhdp->link.num_lanes > 1) { in cdns_mhdp_link_training()
1281 dev_dbg(mhdp->dev, in cdns_mhdp_link_training()
1283 mhdp->link.num_lanes >>= 1; in cdns_mhdp_link_training()
1284 mhdp->link.rate = cdns_mhdp_max_link_rate(mhdp); in cdns_mhdp_link_training()
1289 dev_err(mhdp->dev, in cdns_mhdp_link_training()
1294 if (cdns_mhdp_link_training_channel_eq(mhdp, eq_tps, in cdns_mhdp_link_training()
1298 if (mhdp->link.num_lanes > 1) { in cdns_mhdp_link_training()
1299 dev_dbg(mhdp->dev, in cdns_mhdp_link_training()
1301 mhdp->link.num_lanes >>= 1; in cdns_mhdp_link_training()
1304 } else if (drm_dp_link_rate_to_bw_code(mhdp->link.rate) != in cdns_mhdp_link_training()
1306 dev_dbg(mhdp->dev, in cdns_mhdp_link_training()
1308 cdns_mhdp_lower_link_rate(&mhdp->link); in cdns_mhdp_link_training()
1309 mhdp->link.num_lanes = cdns_mhdp_max_num_lanes(mhdp); in cdns_mhdp_link_training()
1314 dev_err(mhdp->dev, "Link training failed during EQ phase\n"); in cdns_mhdp_link_training()
1318 dev_dbg(mhdp->dev, "Link training ok. Lanes: %u, Rate %u Mbps\n", in cdns_mhdp_link_training()
1319 mhdp->link.num_lanes, mhdp->link.rate / 100); in cdns_mhdp_link_training()
1321 drm_dp_dpcd_writeb(&mhdp->aux, DP_TRAINING_PATTERN_SET, in cdns_mhdp_link_training()
1322 mhdp->host.scrambler ? 0 : in cdns_mhdp_link_training()
1325 ret = cdns_mhdp_reg_read(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, &reg32); in cdns_mhdp_link_training()
1327 dev_err(mhdp->dev, in cdns_mhdp_link_training()
1333 reg32 |= CDNS_DP_NUM_LANES(mhdp->link.num_lanes); in cdns_mhdp_link_training()
1336 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, reg32); in cdns_mhdp_link_training()
1340 if (!mhdp->host.scrambler) in cdns_mhdp_link_training()
1342 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_PHY_CONFIG, reg32); in cdns_mhdp_link_training()
1348 if (!mhdp->host.scrambler) in cdns_mhdp_link_training()
1350 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_PHY_CONFIG, reg32); in cdns_mhdp_link_training()
1352 drm_dp_dpcd_writeb(&mhdp->aux, DP_TRAINING_PATTERN_SET, in cdns_mhdp_link_training()
1358 static u32 cdns_mhdp_get_training_interval_us(struct cdns_mhdp_device *mhdp, in cdns_mhdp_get_training_interval_us() argument
1365 dev_err(mhdp->dev, in cdns_mhdp_get_training_interval_us()
1370 static void cdns_mhdp_fill_host_caps(struct cdns_mhdp_device *mhdp) in cdns_mhdp_fill_host_caps() argument
1376 mhdp->host.lanes_cnt = mhdp->phy->attrs.bus_width; in cdns_mhdp_fill_host_caps()
1377 if (!mhdp->host.lanes_cnt) in cdns_mhdp_fill_host_caps()
1378 mhdp->host.lanes_cnt = 4; in cdns_mhdp_fill_host_caps()
1380 link_rate = mhdp->phy->attrs.max_link_rate; in cdns_mhdp_fill_host_caps()
1387 mhdp->host.link_rate = link_rate; in cdns_mhdp_fill_host_caps()
1388 mhdp->host.volt_swing = CDNS_VOLT_SWING(3); in cdns_mhdp_fill_host_caps()
1389 mhdp->host.pre_emphasis = CDNS_PRE_EMPHASIS(3); in cdns_mhdp_fill_host_caps()
1390 mhdp->host.pattern_supp = CDNS_SUPPORT_TPS(1) | in cdns_mhdp_fill_host_caps()
1393 mhdp->host.lane_mapping = CDNS_LANE_MAPPING_NORMAL; in cdns_mhdp_fill_host_caps()
1394 mhdp->host.fast_link = false; in cdns_mhdp_fill_host_caps()
1395 mhdp->host.enhanced = true; in cdns_mhdp_fill_host_caps()
1396 mhdp->host.scrambler = true; in cdns_mhdp_fill_host_caps()
1397 mhdp->host.ssc = false; in cdns_mhdp_fill_host_caps()
1400 static void cdns_mhdp_fill_sink_caps(struct cdns_mhdp_device *mhdp, in cdns_mhdp_fill_sink_caps() argument
1403 mhdp->sink.link_rate = mhdp->link.rate; in cdns_mhdp_fill_sink_caps()
1404 mhdp->sink.lanes_cnt = mhdp->link.num_lanes; in cdns_mhdp_fill_sink_caps()
1405 mhdp->sink.enhanced = !!(mhdp->link.capabilities & in cdns_mhdp_fill_sink_caps()
1409 mhdp->sink.ssc = !!(dpcd[DP_MAX_DOWNSPREAD] & in cdns_mhdp_fill_sink_caps()
1413 mhdp->sink.pattern_supp = CDNS_SUPPORT_TPS(1) | CDNS_SUPPORT_TPS(2); in cdns_mhdp_fill_sink_caps()
1415 mhdp->sink.pattern_supp |= CDNS_SUPPORT_TPS(3); in cdns_mhdp_fill_sink_caps()
1417 mhdp->sink.pattern_supp |= CDNS_SUPPORT_TPS(4); in cdns_mhdp_fill_sink_caps()
1420 mhdp->sink.fast_link = !!(dpcd[DP_MAX_DOWNSPREAD] & in cdns_mhdp_fill_sink_caps()
1424 static int cdns_mhdp_link_up(struct cdns_mhdp_device *mhdp) in cdns_mhdp_link_up() argument
1432 WARN_ON(!mutex_is_locked(&mhdp->link_mutex)); in cdns_mhdp_link_up()
1434 drm_dp_dpcd_readb(&mhdp->aux, DP_TRAINING_AUX_RD_INTERVAL, in cdns_mhdp_link_up()
1442 err = drm_dp_dpcd_read(&mhdp->aux, addr, dpcd, DP_RECEIVER_CAP_SIZE); in cdns_mhdp_link_up()
1444 dev_err(mhdp->dev, "Failed to read receiver capabilities\n"); in cdns_mhdp_link_up()
1448 mhdp->link.revision = dpcd[0]; in cdns_mhdp_link_up()
1449 mhdp->link.rate = drm_dp_bw_code_to_link_rate(dpcd[1]); in cdns_mhdp_link_up()
1450 mhdp->link.num_lanes = dpcd[2] & DP_MAX_LANE_COUNT_MASK; in cdns_mhdp_link_up()
1453 mhdp->link.capabilities |= DP_LINK_CAP_ENHANCED_FRAMING; in cdns_mhdp_link_up()
1455 dev_dbg(mhdp->dev, "Set sink device power state via DPCD\n"); in cdns_mhdp_link_up()
1456 cdns_mhdp_link_power_up(&mhdp->aux, &mhdp->link); in cdns_mhdp_link_up()
1458 cdns_mhdp_fill_sink_caps(mhdp, dpcd); in cdns_mhdp_link_up()
1460 mhdp->link.rate = cdns_mhdp_max_link_rate(mhdp); in cdns_mhdp_link_up()
1461 mhdp->link.num_lanes = cdns_mhdp_max_num_lanes(mhdp); in cdns_mhdp_link_up()
1464 err = cdns_mhdp_reg_read(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, &resp); in cdns_mhdp_link_up()
1466 dev_err(mhdp->dev, in cdns_mhdp_link_up()
1473 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, resp); in cdns_mhdp_link_up()
1476 amp[0] = cdns_mhdp_get_ssc_supported(mhdp) ? DP_SPREAD_AMP_0_5 : 0; in cdns_mhdp_link_up()
1478 drm_dp_dpcd_write(&mhdp->aux, DP_DOWNSPREAD_CTRL, amp, 2); in cdns_mhdp_link_up()
1480 if (mhdp->host.fast_link & mhdp->sink.fast_link) { in cdns_mhdp_link_up()
1481 dev_err(mhdp->dev, "fastlink not supported\n"); in cdns_mhdp_link_up()
1486 interval_us = cdns_mhdp_get_training_interval_us(mhdp, interval); in cdns_mhdp_link_up()
1488 cdns_mhdp_link_training(mhdp, interval_us)) { in cdns_mhdp_link_up()
1489 dev_err(mhdp->dev, "Link training failed. Exiting.\n"); in cdns_mhdp_link_up()
1493 mhdp->link_up = true; in cdns_mhdp_link_up()
1498 static void cdns_mhdp_link_down(struct cdns_mhdp_device *mhdp) in cdns_mhdp_link_down() argument
1500 WARN_ON(!mutex_is_locked(&mhdp->link_mutex)); in cdns_mhdp_link_down()
1502 if (mhdp->plugged) in cdns_mhdp_link_down()
1503 cdns_mhdp_link_power_down(&mhdp->aux, &mhdp->link); in cdns_mhdp_link_down()
1505 mhdp->link_up = false; in cdns_mhdp_link_down()
1508 static const struct drm_edid *cdns_mhdp_edid_read(struct cdns_mhdp_device *mhdp, in cdns_mhdp_edid_read() argument
1511 if (!mhdp->plugged) in cdns_mhdp_edid_read()
1514 return drm_edid_read_custom(connector, cdns_mhdp_get_edid_block, mhdp); in cdns_mhdp_edid_read()
1519 struct cdns_mhdp_device *mhdp = connector_to_mhdp(connector); in cdns_mhdp_get_modes() local
1523 if (!mhdp->plugged) in cdns_mhdp_get_modes()
1526 drm_edid = cdns_mhdp_edid_read(mhdp, connector); in cdns_mhdp_get_modes()
1531 dev_err(mhdp->dev, "Failed to read EDID\n"); in cdns_mhdp_get_modes()
1544 mhdp->display_fmt.color_format)) in cdns_mhdp_get_modes()
1545 dev_warn(mhdp->dev, in cdns_mhdp_get_modes()
1550 connector->display_info.bpc < mhdp->display_fmt.bpc) in cdns_mhdp_get_modes()
1551 dev_warn(mhdp->dev, "%s: Display bpc only %d < %d\n", in cdns_mhdp_get_modes()
1553 mhdp->display_fmt.bpc); in cdns_mhdp_get_modes()
1562 struct cdns_mhdp_device *mhdp = connector_to_mhdp(conn); in cdns_mhdp_connector_detect() local
1564 return cdns_mhdp_detect(mhdp); in cdns_mhdp_connector_detect()
1593 bool cdns_mhdp_bandwidth_ok(struct cdns_mhdp_device *mhdp, in cdns_mhdp_bandwidth_ok() argument
1606 bpp = cdns_mhdp_get_bpp(&mhdp->display_fmt); in cdns_mhdp_bandwidth_ok()
1610 dev_dbg(mhdp->dev, in cdns_mhdp_bandwidth_ok()
1624 struct cdns_mhdp_device *mhdp = connector_to_mhdp(conn); in cdns_mhdp_mode_valid() local
1626 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_mode_valid()
1628 if (!cdns_mhdp_bandwidth_ok(mhdp, mode, mhdp->link.num_lanes, in cdns_mhdp_mode_valid()
1629 mhdp->link.rate)) { in cdns_mhdp_mode_valid()
1630 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_mode_valid()
1634 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_mode_valid()
1641 struct cdns_mhdp_device *mhdp = connector_to_mhdp(conn); in cdns_mhdp_connector_atomic_check() local
1646 if (!mhdp->hdcp_supported) in cdns_mhdp_connector_atomic_check()
1693 static int cdns_mhdp_connector_init(struct cdns_mhdp_device *mhdp) in cdns_mhdp_connector_init() argument
1696 struct drm_connector *conn = &mhdp->connector; in cdns_mhdp_connector_init()
1697 struct drm_bridge *bridge = &mhdp->bridge; in cdns_mhdp_connector_init()
1705 dev_err(mhdp->dev, "Failed to initialize connector with drm\n"); in cdns_mhdp_connector_init()
1718 dev_err(mhdp->dev, "Failed to attach connector to encoder\n"); in cdns_mhdp_connector_init()
1722 if (mhdp->hdcp_supported) in cdns_mhdp_connector_init()
1731 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_attach() local
1735 dev_dbg(mhdp->dev, "%s\n", __func__); in cdns_mhdp_attach()
1737 mhdp->aux.drm_dev = bridge->dev; in cdns_mhdp_attach()
1738 ret = drm_dp_aux_register(&mhdp->aux); in cdns_mhdp_attach()
1743 ret = cdns_mhdp_connector_init(mhdp); in cdns_mhdp_attach()
1748 spin_lock(&mhdp->start_lock); in cdns_mhdp_attach()
1750 mhdp->bridge_attached = true; in cdns_mhdp_attach()
1751 hw_ready = mhdp->hw_state == MHDP_HW_READY; in cdns_mhdp_attach()
1753 spin_unlock(&mhdp->start_lock); in cdns_mhdp_attach()
1761 drm_dp_aux_unregister(&mhdp->aux); in cdns_mhdp_attach()
1765 static void cdns_mhdp_configure_video(struct cdns_mhdp_device *mhdp, in cdns_mhdp_configure_video() argument
1773 u8 stream_id = mhdp->stream_id; in cdns_mhdp_configure_video()
1777 pxlfmt = mhdp->display_fmt.color_format; in cdns_mhdp_configure_video()
1778 bpc = mhdp->display_fmt.bpc; in cdns_mhdp_configure_video()
1788 bpp = cdns_mhdp_get_bpp(&mhdp->display_fmt); in cdns_mhdp_configure_video()
1837 cdns_mhdp_reg_write(mhdp, CDNS_BND_HSYNC2VSYNC(stream_id), in cdns_mhdp_configure_video()
1845 cdns_mhdp_reg_write(mhdp, CDNS_HSYNC2VSYNC_POL_CTRL(stream_id), in cdns_mhdp_configure_video()
1848 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_PXL_REPR(stream_id), pxl_repr); in cdns_mhdp_configure_video()
1856 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_SP(stream_id), dp_framer_sp); in cdns_mhdp_configure_video()
1860 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRONT_BACK_PORCH(stream_id), in cdns_mhdp_configure_video()
1864 cdns_mhdp_reg_write(mhdp, CDNS_DP_BYTE_COUNT(stream_id), in cdns_mhdp_configure_video()
1868 cdns_mhdp_reg_write(mhdp, CDNS_DP_MSA_HORIZONTAL_0(stream_id), in cdns_mhdp_configure_video()
1877 cdns_mhdp_reg_write(mhdp, CDNS_DP_MSA_HORIZONTAL_1(stream_id), in cdns_mhdp_configure_video()
1881 cdns_mhdp_reg_write(mhdp, CDNS_DP_MSA_VERTICAL_0(stream_id), in cdns_mhdp_configure_video()
1890 cdns_mhdp_reg_write(mhdp, CDNS_DP_MSA_VERTICAL_1(stream_id), in cdns_mhdp_configure_video()
1896 if (mhdp->display_fmt.y_only) in cdns_mhdp_configure_video()
1902 cdns_mhdp_reg_write(mhdp, CDNS_DP_MSA_MISC(stream_id), in cdns_mhdp_configure_video()
1905 cdns_mhdp_reg_write(mhdp, CDNS_DP_HORIZONTAL(stream_id), in cdns_mhdp_configure_video()
1909 cdns_mhdp_reg_write(mhdp, CDNS_DP_VERTICAL_0(stream_id), in cdns_mhdp_configure_video()
1918 cdns_mhdp_reg_write(mhdp, CDNS_DP_VERTICAL_1(stream_id), dp_vertical_1); in cdns_mhdp_configure_video()
1920 cdns_mhdp_reg_write_bit(mhdp, CDNS_DP_VB_ID(stream_id), 2, 1, in cdns_mhdp_configure_video()
1924 ret = cdns_mhdp_reg_read(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, &framer); in cdns_mhdp_configure_video()
1926 dev_err(mhdp->dev, in cdns_mhdp_configure_video()
1933 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, framer); in cdns_mhdp_configure_video()
1936 static void cdns_mhdp_sst_enable(struct cdns_mhdp_device *mhdp, in cdns_mhdp_sst_enable() argument
1946 rate = mhdp->link.rate / 1000; in cdns_mhdp_sst_enable()
1948 bpp = cdns_mhdp_get_bpp(&mhdp->display_fmt); in cdns_mhdp_sst_enable()
1951 available_bandwidth = mhdp->link.num_lanes * rate; in cdns_mhdp_sst_enable()
1961 line_thresh = line_thresh1 - line_thresh2 / (s32)mhdp->link.num_lanes; in cdns_mhdp_sst_enable()
1964 mhdp->stream_id = 0; in cdns_mhdp_sst_enable()
1966 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_TU, in cdns_mhdp_sst_enable()
1971 cdns_mhdp_reg_write(mhdp, CDNS_DP_LINE_THRESH(0), in cdns_mhdp_sst_enable()
1974 cdns_mhdp_reg_write(mhdp, CDNS_DP_STREAM_CONFIG_2(0), in cdns_mhdp_sst_enable()
1978 cdns_mhdp_configure_video(mhdp, mode); in cdns_mhdp_sst_enable()
1984 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_atomic_enable() local
1995 dev_dbg(mhdp->dev, "bridge enable\n"); in cdns_mhdp_atomic_enable()
1997 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_atomic_enable()
1999 if (mhdp->plugged && !mhdp->link_up) { in cdns_mhdp_atomic_enable()
2000 ret = cdns_mhdp_link_up(mhdp); in cdns_mhdp_atomic_enable()
2005 if (mhdp->info && mhdp->info->ops && mhdp->info->ops->enable) in cdns_mhdp_atomic_enable()
2006 mhdp->info->ops->enable(mhdp); in cdns_mhdp_atomic_enable()
2009 ret = cdns_mhdp_reg_read(mhdp, CDNS_DPTX_CAR, &resp); in cdns_mhdp_atomic_enable()
2011 dev_err(mhdp->dev, "Failed to read CDNS_DPTX_CAR %d\n", ret); in cdns_mhdp_atomic_enable()
2015 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_CAR, in cdns_mhdp_atomic_enable()
2027 if (mhdp->hdcp_supported && in cdns_mhdp_atomic_enable()
2028 mhdp->hw_state == MHDP_HW_READY && in cdns_mhdp_atomic_enable()
2031 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_atomic_enable()
2032 cdns_mhdp_hdcp_enable(mhdp, conn_state->hdcp_content_type); in cdns_mhdp_atomic_enable()
2033 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_atomic_enable()
2046 if (!cdns_mhdp_bandwidth_ok(mhdp, mode, mhdp->link.num_lanes, in cdns_mhdp_atomic_enable()
2047 mhdp->link.rate)) { in cdns_mhdp_atomic_enable()
2052 cdns_mhdp_sst_enable(mhdp, mode); in cdns_mhdp_atomic_enable()
2062 dev_dbg(mhdp->dev, "%s: Enabling mode %s\n", __func__, mode->name); in cdns_mhdp_atomic_enable()
2064 mhdp->bridge_enabled = true; in cdns_mhdp_atomic_enable()
2067 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_atomic_enable()
2069 schedule_work(&mhdp->modeset_retry_work); in cdns_mhdp_atomic_enable()
2075 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_atomic_disable() local
2078 dev_dbg(mhdp->dev, "%s\n", __func__); in cdns_mhdp_atomic_disable()
2080 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_atomic_disable()
2082 if (mhdp->hdcp_supported) in cdns_mhdp_atomic_disable()
2083 cdns_mhdp_hdcp_disable(mhdp); in cdns_mhdp_atomic_disable()
2085 mhdp->bridge_enabled = false; in cdns_mhdp_atomic_disable()
2086 cdns_mhdp_reg_read(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, &resp); in cdns_mhdp_atomic_disable()
2089 cdns_mhdp_reg_write(mhdp, CDNS_DP_FRAMER_GLOBAL_CONFIG, resp); in cdns_mhdp_atomic_disable()
2091 cdns_mhdp_link_down(mhdp); in cdns_mhdp_atomic_disable()
2094 cdns_mhdp_reg_read(mhdp, CDNS_DPTX_CAR, &resp); in cdns_mhdp_atomic_disable()
2095 cdns_mhdp_reg_write(mhdp, CDNS_DPTX_CAR, in cdns_mhdp_atomic_disable()
2098 if (mhdp->info && mhdp->info->ops && mhdp->info->ops->disable) in cdns_mhdp_atomic_disable()
2099 mhdp->info->ops->disable(mhdp); in cdns_mhdp_atomic_disable()
2101 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_atomic_disable()
2106 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_detach() local
2108 dev_dbg(mhdp->dev, "%s\n", __func__); in cdns_mhdp_detach()
2110 drm_dp_aux_unregister(&mhdp->aux); in cdns_mhdp_detach()
2112 spin_lock(&mhdp->start_lock); in cdns_mhdp_detach()
2114 mhdp->bridge_attached = false; in cdns_mhdp_detach()
2116 spin_unlock(&mhdp->start_lock); in cdns_mhdp_detach()
2118 writel(~0, mhdp->regs + CDNS_APB_INT_MASK); in cdns_mhdp_detach()
2191 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_atomic_check() local
2194 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_atomic_check()
2196 if (!cdns_mhdp_bandwidth_ok(mhdp, mode, mhdp->link.num_lanes, in cdns_mhdp_atomic_check()
2197 mhdp->link.rate)) { in cdns_mhdp_atomic_check()
2198 dev_err(mhdp->dev, "%s: Not enough BW for %s (%u lanes at %u Mbps)\n", in cdns_mhdp_atomic_check()
2199 __func__, mode->name, mhdp->link.num_lanes, in cdns_mhdp_atomic_check()
2200 mhdp->link.rate / 100); in cdns_mhdp_atomic_check()
2201 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_atomic_check()
2209 if (mhdp->info) in cdns_mhdp_atomic_check()
2210 bridge_state->input_bus_cfg.flags = *mhdp->info->input_bus_flags; in cdns_mhdp_atomic_check()
2212 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_atomic_check()
2218 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_bridge_detect() local
2220 return cdns_mhdp_detect(mhdp); in cdns_mhdp_bridge_detect()
2226 struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); in cdns_mhdp_bridge_edid_read() local
2228 return cdns_mhdp_edid_read(mhdp, connector); in cdns_mhdp_bridge_edid_read()
2247 static bool cdns_mhdp_detect_hpd(struct cdns_mhdp_device *mhdp, bool *hpd_pulse) in cdns_mhdp_detect_hpd() argument
2253 hpd_event = cdns_mhdp_read_hpd_event(mhdp); in cdns_mhdp_detect_hpd()
2257 dev_warn(mhdp->dev, "%s: read event failed: %d\n", in cdns_mhdp_detect_hpd()
2262 hpd_status = cdns_mhdp_get_hpd_status(mhdp); in cdns_mhdp_detect_hpd()
2264 dev_warn(mhdp->dev, "%s: get hpd status failed: %d\n", in cdns_mhdp_detect_hpd()
2275 static int cdns_mhdp_update_link_status(struct cdns_mhdp_device *mhdp) in cdns_mhdp_update_link_status() argument
2279 bool old_plugged = mhdp->plugged; in cdns_mhdp_update_link_status()
2285 mutex_lock(&mhdp->link_mutex); in cdns_mhdp_update_link_status()
2287 mhdp->plugged = cdns_mhdp_detect_hpd(mhdp, &hpd_pulse); in cdns_mhdp_update_link_status()
2289 if (!mhdp->plugged) { in cdns_mhdp_update_link_status()
2290 cdns_mhdp_link_down(mhdp); in cdns_mhdp_update_link_status()
2291 mhdp->link.rate = mhdp->host.link_rate; in cdns_mhdp_update_link_status()
2292 mhdp->link.num_lanes = mhdp->host.lanes_cnt; in cdns_mhdp_update_link_status()
2302 if (hpd_pulse && old_plugged == mhdp->plugged) { in cdns_mhdp_update_link_status()
2303 ret = drm_dp_dpcd_read_link_status(&mhdp->aux, status); in cdns_mhdp_update_link_status()
2310 drm_dp_channel_eq_ok(status, mhdp->link.num_lanes) && in cdns_mhdp_update_link_status()
2311 drm_dp_clock_recovery_ok(status, mhdp->link.num_lanes)) in cdns_mhdp_update_link_status()
2315 mhdp->link_up = false; in cdns_mhdp_update_link_status()
2318 if (!mhdp->link_up) { in cdns_mhdp_update_link_status()
2319 ret = cdns_mhdp_link_up(mhdp); in cdns_mhdp_update_link_status()
2324 if (mhdp->bridge_enabled) { in cdns_mhdp_update_link_status()
2325 state = drm_priv_to_bridge_state(mhdp->bridge.base.state); in cdns_mhdp_update_link_status()
2343 if (!cdns_mhdp_bandwidth_ok(mhdp, current_mode, mhdp->link.num_lanes, in cdns_mhdp_update_link_status()
2344 mhdp->link.rate)) { in cdns_mhdp_update_link_status()
2349 dev_dbg(mhdp->dev, "%s: Enabling mode %s\n", __func__, in cdns_mhdp_update_link_status()
2352 cdns_mhdp_sst_enable(mhdp, current_mode); in cdns_mhdp_update_link_status()
2355 mutex_unlock(&mhdp->link_mutex); in cdns_mhdp_update_link_status()
2361 struct cdns_mhdp_device *mhdp; in cdns_mhdp_modeset_retry_fn() local
2364 mhdp = container_of(work, typeof(*mhdp), modeset_retry_work); in cdns_mhdp_modeset_retry_fn()
2366 conn = &mhdp->connector; in cdns_mhdp_modeset_retry_fn()
2379 drm_kms_helper_hotplug_event(mhdp->bridge.dev); in cdns_mhdp_modeset_retry_fn()
2384 struct cdns_mhdp_device *mhdp = data; in cdns_mhdp_irq_handler() local
2388 apb_stat = readl(mhdp->regs + CDNS_APB_INT_STATUS); in cdns_mhdp_irq_handler()
2392 sw_ev0 = readl(mhdp->regs + CDNS_SW_EVENT0); in cdns_mhdp_irq_handler()
2400 spin_lock(&mhdp->start_lock); in cdns_mhdp_irq_handler()
2401 bridge_attached = mhdp->bridge_attached; in cdns_mhdp_irq_handler()
2402 spin_unlock(&mhdp->start_lock); in cdns_mhdp_irq_handler()
2405 schedule_work(&mhdp->hpd_work); in cdns_mhdp_irq_handler()
2409 mhdp->sw_events |= (sw_ev0 & ~CDNS_DPTX_HPD); in cdns_mhdp_irq_handler()
2410 wake_up(&mhdp->sw_events_wq); in cdns_mhdp_irq_handler()
2416 u32 cdns_mhdp_wait_for_sw_event(struct cdns_mhdp_device *mhdp, u32 event) in cdns_mhdp_wait_for_sw_event() argument
2420 ret = wait_event_timeout(mhdp->sw_events_wq, in cdns_mhdp_wait_for_sw_event()
2421 mhdp->sw_events & event, in cdns_mhdp_wait_for_sw_event()
2424 dev_dbg(mhdp->dev, "SW event 0x%x timeout\n", event); in cdns_mhdp_wait_for_sw_event()
2428 ret = mhdp->sw_events; in cdns_mhdp_wait_for_sw_event()
2429 mhdp->sw_events &= ~event; in cdns_mhdp_wait_for_sw_event()
2437 struct cdns_mhdp_device *mhdp = container_of(work, in cdns_mhdp_hpd_work() local
2442 ret = cdns_mhdp_update_link_status(mhdp); in cdns_mhdp_hpd_work()
2443 if (mhdp->connector.dev) { in cdns_mhdp_hpd_work()
2445 schedule_work(&mhdp->modeset_retry_work); in cdns_mhdp_hpd_work()
2447 drm_kms_helper_hotplug_event(mhdp->bridge.dev); in cdns_mhdp_hpd_work()
2449 drm_bridge_hpd_notify(&mhdp->bridge, cdns_mhdp_detect(mhdp)); in cdns_mhdp_hpd_work()
2456 struct cdns_mhdp_device *mhdp; in cdns_mhdp_probe() local
2462 mhdp = devm_kzalloc(dev, sizeof(*mhdp), GFP_KERNEL); in cdns_mhdp_probe()
2463 if (!mhdp) in cdns_mhdp_probe()
2472 mhdp->clk = clk; in cdns_mhdp_probe()
2473 mhdp->dev = dev; in cdns_mhdp_probe()
2474 mutex_init(&mhdp->mbox_mutex); in cdns_mhdp_probe()
2475 mutex_init(&mhdp->link_mutex); in cdns_mhdp_probe()
2476 spin_lock_init(&mhdp->start_lock); in cdns_mhdp_probe()
2478 drm_dp_aux_init(&mhdp->aux); in cdns_mhdp_probe()
2479 mhdp->aux.dev = dev; in cdns_mhdp_probe()
2480 mhdp->aux.transfer = cdns_mhdp_transfer; in cdns_mhdp_probe()
2482 mhdp->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_mhdp_probe()
2483 if (IS_ERR(mhdp->regs)) { in cdns_mhdp_probe()
2485 return PTR_ERR(mhdp->regs); in cdns_mhdp_probe()
2488 mhdp->sapb_regs = devm_platform_ioremap_resource_byname(pdev, "mhdptx-sapb"); in cdns_mhdp_probe()
2489 if (IS_ERR(mhdp->sapb_regs)) { in cdns_mhdp_probe()
2490 mhdp->hdcp_supported = false; in cdns_mhdp_probe()
2494 mhdp->hdcp_supported = true; in cdns_mhdp_probe()
2497 mhdp->phy = devm_of_phy_get_by_index(dev, pdev->dev.of_node, 0); in cdns_mhdp_probe()
2498 if (IS_ERR(mhdp->phy)) { in cdns_mhdp_probe()
2500 return PTR_ERR(mhdp->phy); in cdns_mhdp_probe()
2503 platform_set_drvdata(pdev, mhdp); in cdns_mhdp_probe()
2505 mhdp->info = of_device_get_match_data(dev); in cdns_mhdp_probe()
2517 if (mhdp->info && mhdp->info->ops && mhdp->info->ops->init) { in cdns_mhdp_probe()
2518 ret = mhdp->info->ops->init(mhdp); in cdns_mhdp_probe()
2527 writel(rate % 1000000, mhdp->regs + CDNS_SW_CLK_L); in cdns_mhdp_probe()
2528 writel(rate / 1000000, mhdp->regs + CDNS_SW_CLK_H); in cdns_mhdp_probe()
2532 writel(~0, mhdp->regs + CDNS_APB_INT_MASK); in cdns_mhdp_probe()
2535 ret = devm_request_threaded_irq(mhdp->dev, irq, NULL, in cdns_mhdp_probe()
2537 "mhdp8546", mhdp); in cdns_mhdp_probe()
2544 cdns_mhdp_fill_host_caps(mhdp); in cdns_mhdp_probe()
2547 mhdp->link.rate = mhdp->host.link_rate; in cdns_mhdp_probe()
2548 mhdp->link.num_lanes = mhdp->host.lanes_cnt; in cdns_mhdp_probe()
2551 mhdp->display_fmt.y_only = false; in cdns_mhdp_probe()
2552 mhdp->display_fmt.color_format = DRM_COLOR_FORMAT_RGB444; in cdns_mhdp_probe()
2553 mhdp->display_fmt.bpc = 8; in cdns_mhdp_probe()
2555 mhdp->bridge.of_node = pdev->dev.of_node; in cdns_mhdp_probe()
2556 mhdp->bridge.funcs = &cdns_mhdp_bridge_funcs; in cdns_mhdp_probe()
2557 mhdp->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | in cdns_mhdp_probe()
2559 mhdp->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; in cdns_mhdp_probe()
2561 ret = phy_init(mhdp->phy); in cdns_mhdp_probe()
2563 dev_err(mhdp->dev, "Failed to initialize PHY: %d\n", ret); in cdns_mhdp_probe()
2568 INIT_WORK(&mhdp->modeset_retry_work, cdns_mhdp_modeset_retry_fn); in cdns_mhdp_probe()
2569 INIT_WORK(&mhdp->hpd_work, cdns_mhdp_hpd_work); in cdns_mhdp_probe()
2571 init_waitqueue_head(&mhdp->fw_load_wq); in cdns_mhdp_probe()
2572 init_waitqueue_head(&mhdp->sw_events_wq); in cdns_mhdp_probe()
2574 ret = cdns_mhdp_load_firmware(mhdp); in cdns_mhdp_probe()
2578 if (mhdp->hdcp_supported) in cdns_mhdp_probe()
2579 cdns_mhdp_hdcp_init(mhdp); in cdns_mhdp_probe()
2581 drm_bridge_add(&mhdp->bridge); in cdns_mhdp_probe()
2586 phy_exit(mhdp->phy); in cdns_mhdp_probe()
2588 if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit) in cdns_mhdp_probe()
2589 mhdp->info->ops->exit(mhdp); in cdns_mhdp_probe()
2594 clk_disable_unprepare(mhdp->clk); in cdns_mhdp_probe()
2601 struct cdns_mhdp_device *mhdp = platform_get_drvdata(pdev); in cdns_mhdp_remove() local
2605 drm_bridge_remove(&mhdp->bridge); in cdns_mhdp_remove()
2607 ret = wait_event_timeout(mhdp->fw_load_wq, in cdns_mhdp_remove()
2608 mhdp->hw_state == MHDP_HW_READY, in cdns_mhdp_remove()
2610 spin_lock(&mhdp->start_lock); in cdns_mhdp_remove()
2611 mhdp->hw_state = MHDP_HW_STOPPED; in cdns_mhdp_remove()
2612 spin_unlock(&mhdp->start_lock); in cdns_mhdp_remove()
2615 dev_err(mhdp->dev, "%s: Timeout waiting for fw loading\n", in cdns_mhdp_remove()
2618 ret = cdns_mhdp_set_firmware_active(mhdp, false); in cdns_mhdp_remove()
2620 dev_err(mhdp->dev, "Failed to stop firmware (%pe)\n", in cdns_mhdp_remove()
2624 phy_exit(mhdp->phy); in cdns_mhdp_remove()
2626 if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit) in cdns_mhdp_remove()
2627 mhdp->info->ops->exit(mhdp); in cdns_mhdp_remove()
2632 cancel_work_sync(&mhdp->modeset_retry_work); in cdns_mhdp_remove()
2633 flush_work(&mhdp->hpd_work); in cdns_mhdp_remove()
2636 clk_disable_unprepare(mhdp->clk); in cdns_mhdp_remove()