Lines Matching +full:five +full:- +full:cell

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019-2022 MediaTek Inc.
18 #include <linux/arm-smccc.h>
23 #include <linux/media-bus-format.h>
24 #include <linux/nvmem-consumer.h>
33 #include <sound/hdmi-codec.h>
317 .name = "mtk-dp-registers",
330 ret = regmap_read(mtk_dp->regs, offset, &read_val); in mtk_dp_read()
332 dev_err(mtk_dp->dev, "Failed to read register 0x%x: %d\n", in mtk_dp_read()
342 int ret = regmap_write(mtk_dp->regs, offset, val); in mtk_dp_write()
345 dev_err(mtk_dp->dev, in mtk_dp_write()
354 int ret = regmap_update_bits(mtk_dp->regs, offset, mask, val); in mtk_dp_update_bits()
357 dev_err(mtk_dp->dev, in mtk_dp_update_bits()
391 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_set_msa()
399 vm->hsync_len + vm->hback_porch, in mtk_dp_set_msa()
402 vm->hsync_len, HSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
406 vm->hactive, HWIDTH_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
412 vm->vsync_len + vm->vback_porch, in mtk_dp_set_msa()
415 vm->vsync_len, VSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
419 vm->vactive, VHEIGHT_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
423 vm->hactive, HDE_NUM_LAST_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
427 vm->hfront_porch, in mtk_dp_set_msa()
430 vm->hsync_len, in mtk_dp_set_msa()
433 vm->hback_porch + vm->hsync_len, in mtk_dp_set_msa()
436 vm->hactive, in mtk_dp_set_msa()
444 vm->vfront_porch, in mtk_dp_set_msa()
447 vm->vsync_len, in mtk_dp_set_msa()
450 vm->vback_porch + vm->vsync_len, in mtk_dp_set_msa()
453 vm->vactive, in mtk_dp_set_msa()
475 drm_warn(mtk_dp->drm_dev, "Unsupported color format: %d\n", in mtk_dp_set_color_format()
477 return -EINVAL; in mtk_dp_set_color_format()
559 switch (cfg->channels) { in mtk_dp_audio_setup_channels()
592 switch (cfg->sample_rate) { in mtk_dp_audio_channel_status_set()
616 switch (cfg->word_length_bits) { in mtk_dp_audio_channel_status_set()
645 (min(8, channels) - 1) << 8, in mtk_dp_audio_sdp_asp_set_channels()
673 u32 db_addr = MTK_DP_ENC0_P0_30D8 + (MTK_DP_SDP_AUI - 1) * 8; in mtk_dp_sdp_set_header_aui()
690 mtk_dp_sdp_set_data(mtk_dp, sdp->db); in mtk_dp_setup_sdp_aui()
691 mtk_dp_sdp_set_header_aui(mtk_dp, &sdp->sdp_header); in mtk_dp_setup_sdp_aui()
763 (length - 1) << 12, in mtk_dp_aux_set_length()
783 while (--wait_reply) { in mtk_dp_aux_wait_for_completion()
801 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
807 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
817 return -EINVAL; in mtk_dp_aux_do_transfer()
852 dev_err(mtk_dp->dev, in mtk_dp_aux_do_transfer()
854 return -EIO; in mtk_dp_aux_do_transfer()
857 return -ETIMEDOUT; in mtk_dp_aux_do_transfer()
886 dev_dbg(mtk_dp->dev, in mtk_dp_set_swing_pre_emphasis()
887 "link training: swing_val = 0x%x, pre-emphasis = 0x%x\n", in mtk_dp_set_swing_pre_emphasis()
1067 struct device *dev = mtk_dp->dev; in mtk_dp_get_calibration_data()
1068 struct nvmem_cell *cell; in mtk_dp_get_calibration_data() local
1069 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_get_calibration_data()
1074 cell = nvmem_cell_get(dev, "dp_calibration_data"); in mtk_dp_get_calibration_data()
1075 if (IS_ERR(cell)) { in mtk_dp_get_calibration_data()
1076 dev_warn(dev, "Failed to get nvmem cell dp_calibration_data\n"); in mtk_dp_get_calibration_data()
1080 buf = (u32 *)nvmem_cell_read(cell, &len); in mtk_dp_get_calibration_data()
1081 nvmem_cell_put(cell); in mtk_dp_get_calibration_data()
1093 fmt = &mtk_dp->data->efuse_fmt[i]; in mtk_dp_get_calibration_data()
1094 cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask; in mtk_dp_get_calibration_data()
1096 if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) { in mtk_dp_get_calibration_data()
1097 dev_warn(mtk_dp->dev, "Invalid efuse data, idx = %d\n", i); in mtk_dp_get_calibration_data()
1107 dev_warn(mtk_dp->dev, "Use default calibration data\n"); in mtk_dp_get_calibration_data()
1109 cal_data[i] = mtk_dp->data->efuse_fmt[i].default_val; in mtk_dp_get_calibration_data()
1114 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_set_calibration_data()
1158 .ssc = mtk_dp->train_info.sink_ssc, in mtk_dp_phy_configure()
1165 ret = phy_configure(mtk_dp->phy, &phy_opts); in mtk_dp_phy_configure()
1195 pattern ? BIT(pattern - 1) << 12 : 0, in mtk_dp_train_set_pattern()
1228 mtk_dp->data->smc_cmd, enable, in mtk_dp_video_mute()
1231 dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n", in mtk_dp_video_mute()
1232 mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1); in mtk_dp_video_mute()
1270 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_aux_panel_poweron()
1274 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_aux_panel_poweron()
1317 bool plugged_in = (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP); in mtk_dp_initialize_priv_data()
1319 mtk_dp->train_info.link_rate = DP_LINK_BW_5_4; in mtk_dp_initialize_priv_data()
1320 mtk_dp->train_info.lane_count = mtk_dp->max_lanes; in mtk_dp_initialize_priv_data()
1321 mtk_dp->train_info.cable_plugged_in = plugged_in; in mtk_dp_initialize_priv_data()
1323 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_initialize_priv_data()
1324 memset(&mtk_dp->info.vm, 0, sizeof(struct videomode)); in mtk_dp_initialize_priv_data()
1325 mtk_dp->audio_enable = false; in mtk_dp_initialize_priv_data()
1333 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init()
1339 mtk_dp->train_info.link_rate * 2700 * 8 / in mtk_dp_sdp_set_down_cnt_init()
1342 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init()
1368 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1372 pix_clk_mhz = mtk_dp->info.format == DP_PIXELFORMAT_YUV420 ? in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1375 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1386 if (pix_clk_mhz > mtk_dp->train_info.link_rate * 27) in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1400 mtk_dp->info.vm.hactive / in mtk_dp_setup_tu()
1401 mtk_dp->train_info.lane_count / in mtk_dp_setup_tu()
1441 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_LANE0_SET + lane, in mtk_dp_train_update_swing_pre()
1455 aux_offset = mtk_dp->train_info.channel_eq_pattern; in mtk_dp_pattern()
1457 switch (mtk_dp->train_info.channel_eq_pattern) { in mtk_dp_pattern()
1474 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, aux_offset); in mtk_dp_pattern()
1482 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET, target_link_rate); in mtk_dp_train_setting()
1483 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, in mtk_dp_train_setting()
1486 if (mtk_dp->train_info.sink_ssc) in mtk_dp_train_setting()
1487 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_DOWNSPREAD_CTRL, in mtk_dp_train_setting()
1495 dev_dbg(mtk_dp->dev, in mtk_dp_train_setting()
1515 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_cr()
1517 return -ENODEV; in mtk_dp_train_cr()
1520 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_cr()
1525 drm_dp_link_train_clock_recovery_delay(&mtk_dp->aux, in mtk_dp_train_cr()
1526 mtk_dp->rx_cap); in mtk_dp_train_cr()
1529 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_cr()
1532 dev_dbg(mtk_dp->dev, "Link train CR pass\n"); in mtk_dp_train_cr()
1545 * level over five times. in mtk_dp_train_cr()
1552 dev_dbg(mtk_dp->dev, "Link train CR fail\n"); in mtk_dp_train_cr()
1558 * re-calculate this retry count. in mtk_dp_train_cr()
1566 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_cr()
1570 return -ETIMEDOUT; in mtk_dp_train_cr()
1583 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_eq()
1585 return -ENODEV; in mtk_dp_train_eq()
1588 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_eq()
1593 drm_dp_link_train_channel_eq_delay(&mtk_dp->aux, in mtk_dp_train_eq()
1594 mtk_dp->rx_cap); in mtk_dp_train_eq()
1597 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_eq()
1599 dev_dbg(mtk_dp->dev, "Link train EQ pass\n"); in mtk_dp_train_eq()
1602 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1607 dev_dbg(mtk_dp->dev, "Link train EQ fail\n"); in mtk_dp_train_eq()
1611 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1615 return -ETIMEDOUT; in mtk_dp_train_eq()
1628 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP && in mtk_dp_parse_capabilities()
1629 mtk_dp->rx_cap[DP_MAX_LINK_RATE] && in mtk_dp_parse_capabilities()
1630 mtk_dp->train_info.sink_ssc) in mtk_dp_parse_capabilities()
1633 ret = drm_dp_read_dpcd_caps(&mtk_dp->aux, mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1637 if (drm_dp_tps4_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1638 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_4; in mtk_dp_parse_capabilities()
1639 else if (drm_dp_tps3_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1640 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_3; in mtk_dp_parse_capabilities()
1642 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_2; in mtk_dp_parse_capabilities()
1644 mtk_dp->train_info.sink_ssc = drm_dp_max_downspread(mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1646 ret = drm_dp_dpcd_readb(&mtk_dp->aux, DP_MSTM_CAP, &val); in mtk_dp_parse_capabilities()
1648 drm_err(mtk_dp->drm_dev, "Read mstm cap failed\n"); in mtk_dp_parse_capabilities()
1649 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1654 ret = drm_dp_dpcd_readb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1658 drm_err(mtk_dp->drm_dev, "Read irq vector failed\n"); in mtk_dp_parse_capabilities()
1659 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1663 ret = drm_dp_dpcd_writeb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1677 if (!mtk_dp->data->audio_supported) in mtk_dp_edid_parse_audio_capabilities()
1680 if (mtk_dp->info.audio_cur_cfg.sad_count <= 0) { in mtk_dp_edid_parse_audio_capabilities()
1681 drm_info(mtk_dp->drm_dev, "The SADs is NULL\n"); in mtk_dp_edid_parse_audio_capabilities()
1690 phy_reset(mtk_dp->phy); in mtk_dp_train_change_mode()
1699 link_rate = min_t(u8, mtk_dp->max_linkrate, in mtk_dp_training()
1700 mtk_dp->rx_cap[DP_MAX_LINK_RATE]); in mtk_dp_training()
1702 lane_count = min_t(u8, mtk_dp->max_lanes, in mtk_dp_training()
1703 drm_dp_max_lane_count(mtk_dp->rx_cap)); in mtk_dp_training()
1712 for (train_limit = 6; train_limit > 0; train_limit--) { in mtk_dp_training()
1720 if (ret == -ENODEV) { in mtk_dp_training()
1729 return -EIO; in mtk_dp_training()
1741 return -EINVAL; in mtk_dp_training()
1747 if (ret == -ENODEV) { in mtk_dp_training()
1752 return -EIO; in mtk_dp_training()
1762 return -ETIMEDOUT; in mtk_dp_training()
1764 mtk_dp->train_info.link_rate = link_rate; in mtk_dp_training()
1765 mtk_dp->train_info.lane_count = lane_count; in mtk_dp_training()
1800 frame.channels = cfg->channels; in mtk_dp_audio_sdp_setup()
1801 frame.sample_frequency = cfg->sample_rate; in mtk_dp_audio_sdp_setup()
1803 switch (cfg->word_length_bits) { in mtk_dp_audio_sdp_setup()
1818 mtk_dp_audio_sdp_asp_set_channels(mtk_dp, cfg->channels); in mtk_dp_audio_sdp_setup()
1837 return mtk_dp_set_color_format(mtk_dp, mtk_dp->info.format); in mtk_dp_video_config()
1859 if (mtk_dp->need_debounce && mtk_dp->train_info.cable_plugged_in) in mtk_dp_hpd_event_thread()
1862 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1863 status = mtk_dp->irq_thread_handle; in mtk_dp_hpd_event_thread()
1864 mtk_dp->irq_thread_handle = 0; in mtk_dp_hpd_event_thread()
1865 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1868 if (mtk_dp->bridge.dev) in mtk_dp_hpd_event_thread()
1869 drm_helper_hpd_irq_event(mtk_dp->bridge.dev); in mtk_dp_hpd_event_thread()
1871 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_hpd_event_thread()
1873 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_hpd_event_thread()
1874 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_hpd_event_thread()
1876 mtk_dp->need_debounce = false; in mtk_dp_hpd_event_thread()
1877 mod_timer(&mtk_dp->debounce_timer, in mtk_dp_hpd_event_thread()
1878 jiffies + msecs_to_jiffies(100) - 1); in mtk_dp_hpd_event_thread()
1883 dev_dbg(mtk_dp->dev, "Receive IRQ from sink devices\n"); in mtk_dp_hpd_event_thread()
1899 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1902 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_HPD_EVENT; in mtk_dp_hpd_event()
1906 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_CABLE_STATE_CHG; in mtk_dp_hpd_event()
1910 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1915 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_hpd_event()
1917 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_hpd_event()
1929 ret = regmap_read_poll_timeout(mtk_dp->regs, MTK_DP_TRANS_P0_3414, in mtk_dp_wait_hpd_asserted()
1933 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_wait_hpd_asserted()
1937 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_wait_hpd_asserted()
1941 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_wait_hpd_asserted()
1952 struct device *dev = &pdev->dev; in mtk_dp_dt_parse()
1962 mtk_dp->regs = devm_regmap_init_mmio(dev, base, &mtk_dp_regmap_config); in mtk_dp_dt_parse()
1963 if (IS_ERR(mtk_dp->regs)) in mtk_dp_dt_parse()
1964 return PTR_ERR(mtk_dp->regs); in mtk_dp_dt_parse()
1966 endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 1, -1); in mtk_dp_dt_parse()
1968 "data-lanes", sizeof(u32)); in mtk_dp_dt_parse()
1971 return -EINVAL; in mtk_dp_dt_parse()
1974 mtk_dp->max_lanes = len; in mtk_dp_dt_parse()
1976 ret = device_property_read_u32(dev, "max-linkrate-mhz", &linkrate); in mtk_dp_dt_parse()
1982 mtk_dp->max_linkrate = drm_dp_link_rate_to_bw_code(linkrate * 100); in mtk_dp_dt_parse()
1989 if (!mtk_dp->data->audio_supported || !mtk_dp->audio_enable) in mtk_dp_update_plugged_status()
1992 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
1993 if (mtk_dp->plugged_cb && mtk_dp->codec_dev) in mtk_dp_update_plugged_status()
1994 mtk_dp->plugged_cb(mtk_dp->codec_dev, in mtk_dp_update_plugged_status()
1995 mtk_dp->enabled & in mtk_dp_update_plugged_status()
1996 mtk_dp->info.audio_cur_cfg.detect_monitor); in mtk_dp_update_plugged_status()
1997 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
2004 bool enabled = mtk_dp->enabled; in mtk_dp_bdg_detect()
2007 if (!mtk_dp->train_info.cable_plugged_in) in mtk_dp_bdg_detect()
2020 drm_dp_dpcd_readb(&mtk_dp->aux, DP_SINK_COUNT, &sink_count); in mtk_dp_bdg_detect()
2034 bool enabled = mtk_dp->enabled; in mtk_dp_edid_read()
2036 struct mtk_dp_audio_cfg *audio_caps = &mtk_dp->info.audio_cur_cfg; in mtk_dp_edid_read()
2039 drm_atomic_bridge_chain_pre_enable(bridge, connector->state->state); in mtk_dp_edid_read()
2043 drm_edid = drm_edid_read_ddc(connector, &mtk_dp->aux.ddc); in mtk_dp_edid_read()
2050 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_edid_read()
2069 audio_caps->sad_count = ret; in mtk_dp_edid_read()
2072 * FIXME: This should use connector->display_info.has_audio from in mtk_dp_edid_read()
2076 audio_caps->detect_monitor = drm_detect_monitor_audio(edid); in mtk_dp_edid_read()
2081 drm_atomic_bridge_chain_post_disable(bridge, connector->state->state); in mtk_dp_edid_read()
2096 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP && in mtk_dp_aux_transfer()
2097 !mtk_dp->train_info.cable_plugged_in) { in mtk_dp_aux_transfer()
2098 ret = -EIO; in mtk_dp_aux_transfer()
2102 switch (msg->request) { in mtk_dp_aux_transfer()
2108 request = msg->request & ~DP_AUX_I2C_WRITE_STATUS_UPDATE; in mtk_dp_aux_transfer()
2114 request = msg->request; in mtk_dp_aux_transfer()
2118 dev_err(mtk_dp->dev, "invalid aux cmd = %d\n", in mtk_dp_aux_transfer()
2119 msg->request); in mtk_dp_aux_transfer()
2120 ret = -EINVAL; in mtk_dp_aux_transfer()
2126 msg->size - accessed_bytes); in mtk_dp_aux_transfer()
2129 msg->address + accessed_bytes, in mtk_dp_aux_transfer()
2130 msg->buffer + accessed_bytes, in mtk_dp_aux_transfer()
2131 to_access, &msg->reply); in mtk_dp_aux_transfer()
2134 dev_info(mtk_dp->dev, in mtk_dp_aux_transfer()
2139 } while (accessed_bytes < msg->size); in mtk_dp_aux_transfer()
2141 return msg->size; in mtk_dp_aux_transfer()
2143 msg->reply = DP_AUX_NATIVE_REPLY_NACK | DP_AUX_I2C_REPLY_NACK; in mtk_dp_aux_transfer()
2151 ret = phy_init(mtk_dp->phy); in mtk_dp_poweron()
2153 dev_err(mtk_dp->dev, "Failed to initialize phy: %d\n", ret); in mtk_dp_poweron()
2166 phy_exit(mtk_dp->phy); in mtk_dp_poweroff()
2176 dev_err(mtk_dp->dev, "Driver does not provide a connector!"); in mtk_dp_bridge_attach()
2177 return -EINVAL; in mtk_dp_bridge_attach()
2180 mtk_dp->aux.drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2181 ret = drm_dp_aux_register(&mtk_dp->aux); in mtk_dp_bridge_attach()
2183 dev_err(mtk_dp->dev, in mtk_dp_bridge_attach()
2192 if (mtk_dp->next_bridge) { in mtk_dp_bridge_attach()
2193 ret = drm_bridge_attach(bridge->encoder, mtk_dp->next_bridge, in mtk_dp_bridge_attach()
2194 &mtk_dp->bridge, flags); in mtk_dp_bridge_attach()
2196 drm_warn(mtk_dp->drm_dev, in mtk_dp_bridge_attach()
2202 mtk_dp->drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2204 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_attach()
2205 irq_clear_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_bridge_attach()
2206 enable_irq(mtk_dp->irq); in mtk_dp_bridge_attach()
2215 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_attach()
2223 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_detach()
2225 disable_irq(mtk_dp->irq); in mtk_dp_bridge_detach()
2227 mtk_dp->drm_dev = NULL; in mtk_dp_bridge_detach()
2229 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_detach()
2238 mtk_dp->conn = drm_atomic_get_new_connector_for_encoder(old_state->base.state, in mtk_dp_bridge_atomic_enable()
2239 bridge->encoder); in mtk_dp_bridge_atomic_enable()
2240 if (!mtk_dp->conn) { in mtk_dp_bridge_atomic_enable()
2241 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_enable()
2251 drm_err(mtk_dp->drm_dev, "Training failed, %d\n", ret); in mtk_dp_bridge_atomic_enable()
2261 mtk_dp->audio_enable = in mtk_dp_bridge_atomic_enable()
2263 &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2264 if (mtk_dp->audio_enable) { in mtk_dp_bridge_atomic_enable()
2265 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2268 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_bridge_atomic_enable()
2269 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_bridge_atomic_enable()
2272 mtk_dp->enabled = true; in mtk_dp_bridge_atomic_enable()
2287 mtk_dp->enabled = false; in mtk_dp_bridge_atomic_disable()
2292 if (mtk_dp->train_info.cable_plugged_in) { in mtk_dp_bridge_atomic_disable()
2293 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_bridge_atomic_disable()
2312 u32 bpp = info->color_formats & DRM_COLOR_FORMAT_YCBCR422 ? 16 : 24; in mtk_dp_bridge_mode_valid()
2313 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_mode_valid()
2314 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_mode_valid()
2315 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_mode_valid()
2316 mtk_dp->max_lanes); in mtk_dp_bridge_mode_valid()
2318 if (rate < mode->clock * bpp / 8) in mtk_dp_bridge_mode_valid()
2356 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2358 &conn_state->connector->display_info; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2359 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2360 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_atomic_get_input_bus_fmts()
2361 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2362 mtk_dp->max_lanes); in mtk_dp_bridge_atomic_get_input_bus_fmts()
2371 if ((rate < (mode->clock * 24 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2372 (rate > (mode->clock * 16 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2373 (display_info->color_formats & DRM_COLOR_FORMAT_YCBCR422)) { in mtk_dp_bridge_atomic_get_input_bus_fmts()
2399 struct drm_crtc *crtc = conn_state->crtc; in mtk_dp_bridge_atomic_check()
2402 input_bus_format = bridge_state->input_bus_cfg.format; in mtk_dp_bridge_atomic_check()
2404 dev_dbg(mtk_dp->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dp_bridge_atomic_check()
2405 bridge_state->input_bus_cfg.format, in mtk_dp_bridge_atomic_check()
2406 bridge_state->output_bus_cfg.format); in mtk_dp_bridge_atomic_check()
2409 mtk_dp->info.format = DP_PIXELFORMAT_YUV422; in mtk_dp_bridge_atomic_check()
2411 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_bridge_atomic_check()
2414 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_check()
2416 return -EINVAL; in mtk_dp_bridge_atomic_check()
2419 drm_display_mode_to_videomode(&crtc_state->adjusted_mode, &mtk_dp->info.vm); in mtk_dp_bridge_atomic_check()
2444 mtk_dp->need_debounce = true; in mtk_dp_debounce_timer()
2456 if (!mtk_dp->enabled) { in mtk_dp_audio_hw_params()
2457 dev_err(mtk_dp->dev, "%s, DP is not ready!\n", __func__); in mtk_dp_audio_hw_params()
2458 return -ENODEV; in mtk_dp_audio_hw_params()
2461 mtk_dp->info.audio_cur_cfg.channels = params->cea.channels; in mtk_dp_audio_hw_params()
2462 mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate; in mtk_dp_audio_hw_params()
2464 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_audio_hw_params()
2490 if (mtk_dp->enabled) in mtk_dp_audio_get_eld()
2491 memcpy(buf, mtk_dp->conn->eld, len); in mtk_dp_audio_get_eld()
2504 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2505 mtk_dp->plugged_cb = fn; in mtk_dp_audio_hook_plugged_cb()
2506 mtk_dp->codec_dev = codec_dev; in mtk_dp_audio_hook_plugged_cb()
2507 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2533 mtk_dp->audio_pdev = platform_device_register_data(dev, in mtk_dp_register_audio_driver()
2538 return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); in mtk_dp_register_audio_driver()
2543 struct device *dev = mtk_dp->dev; in mtk_dp_register_phy()
2545 mtk_dp->phy_dev = platform_device_register_data(dev, "mediatek-dp-phy", in mtk_dp_register_phy()
2547 &mtk_dp->regs, in mtk_dp_register_phy()
2549 if (IS_ERR(mtk_dp->phy_dev)) in mtk_dp_register_phy()
2550 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy_dev), in mtk_dp_register_phy()
2551 "Failed to create device mediatek-dp-phy\n"); in mtk_dp_register_phy()
2555 mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp"); in mtk_dp_register_phy()
2556 if (IS_ERR(mtk_dp->phy)) { in mtk_dp_register_phy()
2557 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_register_phy()
2558 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), "Failed to get phy\n"); in mtk_dp_register_phy()
2567 struct device *dev = mtk_aux->dev; in mtk_dp_edp_link_panel()
2570 mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); in mtk_dp_edp_link_panel()
2578 if (IS_ERR(mtk_dp->next_bridge)) { in mtk_dp_edp_link_panel()
2579 ret = PTR_ERR(mtk_dp->next_bridge); in mtk_dp_edp_link_panel()
2580 mtk_dp->next_bridge = NULL; in mtk_dp_edp_link_panel()
2585 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_edp_link_panel()
2595 struct device *dev = &pdev->dev; in mtk_dp_probe()
2600 return -ENOMEM; in mtk_dp_probe()
2602 mtk_dp->dev = dev; in mtk_dp_probe()
2603 mtk_dp->data = (struct mtk_dp_data *)of_device_get_match_data(dev); in mtk_dp_probe()
2616 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2617 mtk_dp->irq = platform_get_irq(pdev, 0); in mtk_dp_probe()
2618 if (mtk_dp->irq < 0) in mtk_dp_probe()
2619 return dev_err_probe(dev, mtk_dp->irq, in mtk_dp_probe()
2622 spin_lock_init(&mtk_dp->irq_thread_lock); in mtk_dp_probe()
2624 irq_set_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_probe()
2625 ret = devm_request_threaded_irq(dev, mtk_dp->irq, mtk_dp_hpd_event, in mtk_dp_probe()
2633 mtk_dp->need_debounce = true; in mtk_dp_probe()
2634 timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); in mtk_dp_probe()
2637 mtk_dp->aux.name = "aux_mtk_dp"; in mtk_dp_probe()
2638 mtk_dp->aux.dev = dev; in mtk_dp_probe()
2639 mtk_dp->aux.transfer = mtk_dp_aux_transfer; in mtk_dp_probe()
2640 mtk_dp->aux.wait_hpd_asserted = mtk_dp_wait_hpd_asserted; in mtk_dp_probe()
2641 drm_dp_aux_init(&mtk_dp->aux); in mtk_dp_probe()
2645 if (mtk_dp->data->audio_supported) { in mtk_dp_probe()
2646 mutex_init(&mtk_dp->update_plugged_status_lock); in mtk_dp_probe()
2660 mtk_dp->bridge.funcs = &mtk_dp_bridge_funcs; in mtk_dp_probe()
2661 mtk_dp->bridge.of_node = dev->of_node; in mtk_dp_probe()
2662 mtk_dp->bridge.type = mtk_dp->data->bridge_type; in mtk_dp_probe()
2664 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2678 * Power on the AUX to allow reading the EDID from aux-bus: in mtk_dp_probe()
2687 ret = devm_of_dp_aux_populate_bus(&mtk_dp->aux, mtk_dp_edp_link_panel); in mtk_dp_probe()
2689 /* -ENODEV this means that the panel is not on the aux-bus */ in mtk_dp_probe()
2690 if (ret == -ENODEV) { in mtk_dp_probe()
2691 ret = mtk_dp_edp_link_panel(&mtk_dp->aux); in mtk_dp_probe()
2703 mtk_dp->bridge.ops = DRM_BRIDGE_OP_DETECT | in mtk_dp_probe()
2705 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_probe()
2720 pm_runtime_put(&pdev->dev); in mtk_dp_remove()
2721 pm_runtime_disable(&pdev->dev); in mtk_dp_remove()
2722 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_remove()
2723 del_timer_sync(&mtk_dp->debounce_timer); in mtk_dp_remove()
2724 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_remove()
2725 if (mtk_dp->audio_pdev) in mtk_dp_remove()
2726 platform_device_unregister(mtk_dp->audio_pdev); in mtk_dp_remove()
2735 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_suspend()
2748 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_resume()
2774 .compatible = "mediatek,mt8195-edp-tx",
2778 .compatible = "mediatek,mt8195-dp-tx",
2789 .name = "mediatek-drm-dp",
2798 MODULE_AUTHOR("Markus Schneider-Pargmann <msp@baylibre.com>");
2799 MODULE_AUTHOR("Bo-Chen Chen <rex-bc.chen@mediatek.com>");