Lines Matching +full:mt8195 +full:- +full:efuse

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>
402 .name = "mtk-dp-registers",
415 ret = regmap_read(mtk_dp->regs, offset, &read_val); in mtk_dp_read()
417 dev_err(mtk_dp->dev, "Failed to read register 0x%x: %d\n", in mtk_dp_read()
427 int ret = regmap_write(mtk_dp->regs, offset, val); in mtk_dp_write()
430 dev_err(mtk_dp->dev, in mtk_dp_write()
439 int ret = regmap_update_bits(mtk_dp->regs, offset, mask, val); in mtk_dp_update_bits()
442 dev_err(mtk_dp->dev, in mtk_dp_update_bits()
476 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_set_msa()
484 vm->hsync_len + vm->hback_porch, in mtk_dp_set_msa()
487 vm->hsync_len, HSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
491 vm->hactive, HWIDTH_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
497 vm->vsync_len + vm->vback_porch, in mtk_dp_set_msa()
500 vm->vsync_len, VSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
504 vm->vactive, VHEIGHT_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
508 vm->hactive, HDE_NUM_LAST_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
512 vm->hfront_porch, in mtk_dp_set_msa()
515 vm->hsync_len, in mtk_dp_set_msa()
518 vm->hback_porch + vm->hsync_len, in mtk_dp_set_msa()
521 vm->hactive, in mtk_dp_set_msa()
529 vm->vfront_porch, in mtk_dp_set_msa()
532 vm->vsync_len, in mtk_dp_set_msa()
535 vm->vback_porch + vm->vsync_len, in mtk_dp_set_msa()
538 vm->vactive, in mtk_dp_set_msa()
560 drm_warn(mtk_dp->drm_dev, "Unsupported color format: %d\n", in mtk_dp_set_color_format()
562 return -EINVAL; in mtk_dp_set_color_format()
644 switch (cfg->channels) { in mtk_dp_audio_setup_channels()
677 switch (cfg->sample_rate) { in mtk_dp_audio_channel_status_set()
701 switch (cfg->word_length_bits) { in mtk_dp_audio_channel_status_set()
730 (min(8, channels) - 1) << 8, in mtk_dp_audio_sdp_asp_set_channels()
737 mtk_dp->data->audio_m_div2_bit, in mtk_dp_audio_set_divider()
758 u32 db_addr = MTK_DP_ENC0_P0_30D8 + (MTK_DP_SDP_AUI - 1) * 8; in mtk_dp_sdp_set_header_aui()
775 mtk_dp_sdp_set_data(mtk_dp, sdp->db); in mtk_dp_setup_sdp_aui()
776 mtk_dp_sdp_set_header_aui(mtk_dp, &sdp->sdp_header); in mtk_dp_setup_sdp_aui()
848 (length - 1) << 12, in mtk_dp_aux_set_length()
868 while (--wait_reply) { in mtk_dp_aux_wait_for_completion()
886 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
892 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
902 return -EINVAL; in mtk_dp_aux_do_transfer()
937 dev_err(mtk_dp->dev, in mtk_dp_aux_do_transfer()
939 return -EIO; in mtk_dp_aux_do_transfer()
942 return -ETIMEDOUT; in mtk_dp_aux_do_transfer()
971 dev_dbg(mtk_dp->dev, in mtk_dp_set_swing_pre_emphasis()
972 "link training: swing_val = 0x%x, pre-emphasis = 0x%x\n", in mtk_dp_set_swing_pre_emphasis()
1152 struct device *dev = mtk_dp->dev; in mtk_dp_get_calibration_data()
1154 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_get_calibration_data()
1178 fmt = &mtk_dp->data->efuse_fmt[i]; in mtk_dp_get_calibration_data()
1179 cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask; in mtk_dp_get_calibration_data()
1181 if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) { in mtk_dp_get_calibration_data()
1182 dev_warn(mtk_dp->dev, "Invalid efuse data, idx = %d\n", i); in mtk_dp_get_calibration_data()
1192 dev_warn(mtk_dp->dev, "Use default calibration data\n"); in mtk_dp_get_calibration_data()
1194 cal_data[i] = mtk_dp->data->efuse_fmt[i].default_val; in mtk_dp_get_calibration_data()
1199 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_set_calibration_data()
1243 .ssc = mtk_dp->train_info.sink_ssc, in mtk_dp_phy_configure()
1250 ret = phy_configure(mtk_dp->phy, &phy_opts); in mtk_dp_phy_configure()
1280 pattern ? BIT(pattern - 1) << 12 : 0, in mtk_dp_train_set_pattern()
1313 mtk_dp->data->smc_cmd, enable, in mtk_dp_video_mute()
1316 dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n", in mtk_dp_video_mute()
1317 mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1); in mtk_dp_video_mute()
1355 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_aux_panel_poweron()
1359 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_aux_panel_poweron()
1402 bool plugged_in = (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP); in mtk_dp_initialize_priv_data()
1404 mtk_dp->train_info.link_rate = DP_LINK_BW_5_4; in mtk_dp_initialize_priv_data()
1405 mtk_dp->train_info.lane_count = mtk_dp->max_lanes; in mtk_dp_initialize_priv_data()
1406 mtk_dp->train_info.cable_plugged_in = plugged_in; in mtk_dp_initialize_priv_data()
1408 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_initialize_priv_data()
1409 memset(&mtk_dp->info.vm, 0, sizeof(struct videomode)); in mtk_dp_initialize_priv_data()
1410 mtk_dp->audio_enable = false; in mtk_dp_initialize_priv_data()
1418 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init()
1424 mtk_dp->train_info.link_rate * 2700 * 8 / in mtk_dp_sdp_set_down_cnt_init()
1427 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init()
1453 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1457 pix_clk_mhz = mtk_dp->info.format == DP_PIXELFORMAT_YUV420 ? in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1460 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1471 if (pix_clk_mhz > mtk_dp->train_info.link_rate * 27) in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1485 if (!mtk_dp->data->audio_pkt_in_hblank_area) in mtk_dp_audio_sample_arrange_disable()
1497 mtk_dp->info.vm.hactive / in mtk_dp_setup_tu()
1498 mtk_dp->train_info.lane_count / in mtk_dp_setup_tu()
1539 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_LANE0_SET + lane, in mtk_dp_train_update_swing_pre()
1553 aux_offset = mtk_dp->train_info.channel_eq_pattern; in mtk_dp_pattern()
1555 switch (mtk_dp->train_info.channel_eq_pattern) { in mtk_dp_pattern()
1572 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, aux_offset); in mtk_dp_pattern()
1580 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET, target_link_rate); in mtk_dp_train_setting()
1581 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, in mtk_dp_train_setting()
1584 if (mtk_dp->train_info.sink_ssc) in mtk_dp_train_setting()
1585 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_DOWNSPREAD_CTRL, in mtk_dp_train_setting()
1593 dev_dbg(mtk_dp->dev, in mtk_dp_train_setting()
1613 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_cr()
1615 return -ENODEV; in mtk_dp_train_cr()
1618 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_cr()
1623 drm_dp_link_train_clock_recovery_delay(&mtk_dp->aux, in mtk_dp_train_cr()
1624 mtk_dp->rx_cap); in mtk_dp_train_cr()
1627 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_cr()
1630 dev_dbg(mtk_dp->dev, "Link train CR pass\n"); in mtk_dp_train_cr()
1650 dev_dbg(mtk_dp->dev, "Link train CR fail\n"); in mtk_dp_train_cr()
1656 * re-calculate this retry count. in mtk_dp_train_cr()
1664 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_cr()
1668 return -ETIMEDOUT; in mtk_dp_train_cr()
1681 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_eq()
1683 return -ENODEV; in mtk_dp_train_eq()
1686 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_eq()
1691 drm_dp_link_train_channel_eq_delay(&mtk_dp->aux, in mtk_dp_train_eq()
1692 mtk_dp->rx_cap); in mtk_dp_train_eq()
1695 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_eq()
1697 dev_dbg(mtk_dp->dev, "Link train EQ pass\n"); in mtk_dp_train_eq()
1700 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1705 dev_dbg(mtk_dp->dev, "Link train EQ fail\n"); in mtk_dp_train_eq()
1709 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1713 return -ETIMEDOUT; in mtk_dp_train_eq()
1726 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP && in mtk_dp_parse_capabilities()
1727 mtk_dp->rx_cap[DP_MAX_LINK_RATE] && in mtk_dp_parse_capabilities()
1728 mtk_dp->train_info.sink_ssc) in mtk_dp_parse_capabilities()
1731 ret = drm_dp_read_dpcd_caps(&mtk_dp->aux, mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1735 if (drm_dp_tps4_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1736 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_4; in mtk_dp_parse_capabilities()
1737 else if (drm_dp_tps3_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1738 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_3; in mtk_dp_parse_capabilities()
1740 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_2; in mtk_dp_parse_capabilities()
1742 mtk_dp->train_info.sink_ssc = drm_dp_max_downspread(mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1744 ret = drm_dp_dpcd_readb(&mtk_dp->aux, DP_MSTM_CAP, &val); in mtk_dp_parse_capabilities()
1746 drm_err(mtk_dp->drm_dev, "Read mstm cap failed\n"); in mtk_dp_parse_capabilities()
1747 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1752 ret = drm_dp_dpcd_readb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1756 drm_err(mtk_dp->drm_dev, "Read irq vector failed\n"); in mtk_dp_parse_capabilities()
1757 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1761 ret = drm_dp_dpcd_writeb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1775 if (!mtk_dp->data->audio_supported) in mtk_dp_edid_parse_audio_capabilities()
1778 if (mtk_dp->info.audio_cur_cfg.sad_count <= 0) { in mtk_dp_edid_parse_audio_capabilities()
1779 drm_info(mtk_dp->drm_dev, "The SADs is NULL\n"); in mtk_dp_edid_parse_audio_capabilities()
1788 phy_reset(mtk_dp->phy); in mtk_dp_train_change_mode()
1797 link_rate = min_t(u8, mtk_dp->max_linkrate, in mtk_dp_training()
1798 mtk_dp->rx_cap[DP_MAX_LINK_RATE]); in mtk_dp_training()
1800 lane_count = min_t(u8, mtk_dp->max_lanes, in mtk_dp_training()
1801 drm_dp_max_lane_count(mtk_dp->rx_cap)); in mtk_dp_training()
1810 for (train_limit = 6; train_limit > 0; train_limit--) { in mtk_dp_training()
1818 if (ret == -ENODEV) { in mtk_dp_training()
1827 return -EIO; in mtk_dp_training()
1839 return -EINVAL; in mtk_dp_training()
1845 if (ret == -ENODEV) { in mtk_dp_training()
1850 return -EIO; in mtk_dp_training()
1860 return -ETIMEDOUT; in mtk_dp_training()
1862 mtk_dp->train_info.link_rate = link_rate; in mtk_dp_training()
1863 mtk_dp->train_info.lane_count = lane_count; in mtk_dp_training()
1898 frame.channels = cfg->channels; in mtk_dp_audio_sdp_setup()
1899 frame.sample_frequency = cfg->sample_rate; in mtk_dp_audio_sdp_setup()
1901 switch (cfg->word_length_bits) { in mtk_dp_audio_sdp_setup()
1916 mtk_dp_audio_sdp_asp_set_channels(mtk_dp, cfg->channels); in mtk_dp_audio_sdp_setup()
1935 return mtk_dp_set_color_format(mtk_dp, mtk_dp->info.format); in mtk_dp_video_config()
1957 if (mtk_dp->need_debounce && mtk_dp->train_info.cable_plugged_in) in mtk_dp_hpd_event_thread()
1960 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1961 status = mtk_dp->irq_thread_handle; in mtk_dp_hpd_event_thread()
1962 mtk_dp->irq_thread_handle = 0; in mtk_dp_hpd_event_thread()
1963 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1966 if (mtk_dp->bridge.dev) in mtk_dp_hpd_event_thread()
1967 drm_helper_hpd_irq_event(mtk_dp->bridge.dev); in mtk_dp_hpd_event_thread()
1969 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_hpd_event_thread()
1971 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_hpd_event_thread()
1972 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_hpd_event_thread()
1974 mtk_dp->need_debounce = false; in mtk_dp_hpd_event_thread()
1975 mod_timer(&mtk_dp->debounce_timer, in mtk_dp_hpd_event_thread()
1976 jiffies + msecs_to_jiffies(100) - 1); in mtk_dp_hpd_event_thread()
1981 dev_dbg(mtk_dp->dev, "Receive IRQ from sink devices\n"); in mtk_dp_hpd_event_thread()
1997 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
2000 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_HPD_EVENT; in mtk_dp_hpd_event()
2004 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_CABLE_STATE_CHG; in mtk_dp_hpd_event()
2008 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
2013 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_hpd_event()
2015 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_hpd_event()
2027 ret = regmap_read_poll_timeout(mtk_dp->regs, MTK_DP_TRANS_P0_3414, in mtk_dp_wait_hpd_asserted()
2031 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_wait_hpd_asserted()
2035 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_wait_hpd_asserted()
2039 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_wait_hpd_asserted()
2050 struct device *dev = &pdev->dev; in mtk_dp_dt_parse()
2060 mtk_dp->regs = devm_regmap_init_mmio(dev, base, &mtk_dp_regmap_config); in mtk_dp_dt_parse()
2061 if (IS_ERR(mtk_dp->regs)) in mtk_dp_dt_parse()
2062 return PTR_ERR(mtk_dp->regs); in mtk_dp_dt_parse()
2064 endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 1, -1); in mtk_dp_dt_parse()
2066 "data-lanes", sizeof(u32)); in mtk_dp_dt_parse()
2069 return -EINVAL; in mtk_dp_dt_parse()
2072 mtk_dp->max_lanes = len; in mtk_dp_dt_parse()
2074 ret = device_property_read_u32(dev, "max-linkrate-mhz", &linkrate); in mtk_dp_dt_parse()
2080 mtk_dp->max_linkrate = drm_dp_link_rate_to_bw_code(linkrate * 100); in mtk_dp_dt_parse()
2087 if (!mtk_dp->data->audio_supported || !mtk_dp->audio_enable) in mtk_dp_update_plugged_status()
2090 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
2091 if (mtk_dp->plugged_cb && mtk_dp->codec_dev) in mtk_dp_update_plugged_status()
2092 mtk_dp->plugged_cb(mtk_dp->codec_dev, in mtk_dp_update_plugged_status()
2093 mtk_dp->enabled & in mtk_dp_update_plugged_status()
2094 mtk_dp->info.audio_cur_cfg.detect_monitor); in mtk_dp_update_plugged_status()
2095 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
2102 bool enabled = mtk_dp->enabled; in mtk_dp_bdg_detect()
2105 if (!mtk_dp->train_info.cable_plugged_in) in mtk_dp_bdg_detect()
2118 drm_dp_dpcd_readb(&mtk_dp->aux, DP_SINK_COUNT, &sink_count); in mtk_dp_bdg_detect()
2132 bool enabled = mtk_dp->enabled; in mtk_dp_edid_read()
2134 struct mtk_dp_audio_cfg *audio_caps = &mtk_dp->info.audio_cur_cfg; in mtk_dp_edid_read()
2137 drm_atomic_bridge_chain_pre_enable(bridge, connector->state->state); in mtk_dp_edid_read()
2141 drm_edid = drm_edid_read_ddc(connector, &mtk_dp->aux.ddc); in mtk_dp_edid_read()
2148 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_edid_read()
2167 audio_caps->sad_count = ret; in mtk_dp_edid_read()
2170 * FIXME: This should use connector->display_info.has_audio from in mtk_dp_edid_read()
2174 audio_caps->detect_monitor = drm_detect_monitor_audio(edid); in mtk_dp_edid_read()
2179 drm_atomic_bridge_chain_post_disable(bridge, connector->state->state); in mtk_dp_edid_read()
2194 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP && in mtk_dp_aux_transfer()
2195 !mtk_dp->train_info.cable_plugged_in) { in mtk_dp_aux_transfer()
2196 ret = -EIO; in mtk_dp_aux_transfer()
2200 switch (msg->request) { in mtk_dp_aux_transfer()
2206 request = msg->request & ~DP_AUX_I2C_WRITE_STATUS_UPDATE; in mtk_dp_aux_transfer()
2212 request = msg->request; in mtk_dp_aux_transfer()
2216 dev_err(mtk_dp->dev, "invalid aux cmd = %d\n", in mtk_dp_aux_transfer()
2217 msg->request); in mtk_dp_aux_transfer()
2218 ret = -EINVAL; in mtk_dp_aux_transfer()
2224 msg->size - accessed_bytes); in mtk_dp_aux_transfer()
2227 msg->address + accessed_bytes, in mtk_dp_aux_transfer()
2228 msg->buffer + accessed_bytes, in mtk_dp_aux_transfer()
2229 to_access, &msg->reply); in mtk_dp_aux_transfer()
2232 dev_info(mtk_dp->dev, in mtk_dp_aux_transfer()
2237 } while (accessed_bytes < msg->size); in mtk_dp_aux_transfer()
2239 return msg->size; in mtk_dp_aux_transfer()
2241 msg->reply = DP_AUX_NATIVE_REPLY_NACK | DP_AUX_I2C_REPLY_NACK; in mtk_dp_aux_transfer()
2249 ret = phy_init(mtk_dp->phy); in mtk_dp_poweron()
2251 dev_err(mtk_dp->dev, "Failed to initialize phy: %d\n", ret); in mtk_dp_poweron()
2264 phy_exit(mtk_dp->phy); in mtk_dp_poweroff()
2274 dev_err(mtk_dp->dev, "Driver does not provide a connector!"); in mtk_dp_bridge_attach()
2275 return -EINVAL; in mtk_dp_bridge_attach()
2278 mtk_dp->aux.drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2279 ret = drm_dp_aux_register(&mtk_dp->aux); in mtk_dp_bridge_attach()
2281 dev_err(mtk_dp->dev, in mtk_dp_bridge_attach()
2290 if (mtk_dp->next_bridge) { in mtk_dp_bridge_attach()
2291 ret = drm_bridge_attach(bridge->encoder, mtk_dp->next_bridge, in mtk_dp_bridge_attach()
2292 &mtk_dp->bridge, flags); in mtk_dp_bridge_attach()
2294 drm_warn(mtk_dp->drm_dev, in mtk_dp_bridge_attach()
2300 mtk_dp->drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2302 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_attach()
2303 irq_clear_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_bridge_attach()
2304 enable_irq(mtk_dp->irq); in mtk_dp_bridge_attach()
2313 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_attach()
2321 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_detach()
2323 disable_irq(mtk_dp->irq); in mtk_dp_bridge_detach()
2325 mtk_dp->drm_dev = NULL; in mtk_dp_bridge_detach()
2327 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_detach()
2336 mtk_dp->conn = drm_atomic_get_new_connector_for_encoder(old_state->base.state, in mtk_dp_bridge_atomic_enable()
2337 bridge->encoder); in mtk_dp_bridge_atomic_enable()
2338 if (!mtk_dp->conn) { in mtk_dp_bridge_atomic_enable()
2339 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_enable()
2349 drm_err(mtk_dp->drm_dev, "Training failed, %d\n", ret); in mtk_dp_bridge_atomic_enable()
2359 mtk_dp->audio_enable = in mtk_dp_bridge_atomic_enable()
2361 &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2362 if (mtk_dp->audio_enable) { in mtk_dp_bridge_atomic_enable()
2363 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2366 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_bridge_atomic_enable()
2367 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_bridge_atomic_enable()
2370 mtk_dp->enabled = true; in mtk_dp_bridge_atomic_enable()
2385 mtk_dp->enabled = false; in mtk_dp_bridge_atomic_disable()
2390 if (mtk_dp->train_info.cable_plugged_in) { in mtk_dp_bridge_atomic_disable()
2391 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_bridge_atomic_disable()
2410 u32 bpp = info->color_formats & DRM_COLOR_FORMAT_YCBCR422 ? 16 : 24; in mtk_dp_bridge_mode_valid()
2411 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_mode_valid()
2412 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_mode_valid()
2413 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_mode_valid()
2414 mtk_dp->max_lanes); in mtk_dp_bridge_mode_valid()
2416 if (rate < mode->clock * bpp / 8) in mtk_dp_bridge_mode_valid()
2454 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2456 &conn_state->connector->display_info; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2457 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2458 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_atomic_get_input_bus_fmts()
2459 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2460 mtk_dp->max_lanes); in mtk_dp_bridge_atomic_get_input_bus_fmts()
2469 if ((rate < (mode->clock * 24 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2470 (rate > (mode->clock * 16 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2471 (display_info->color_formats & DRM_COLOR_FORMAT_YCBCR422)) { in mtk_dp_bridge_atomic_get_input_bus_fmts()
2497 struct drm_crtc *crtc = conn_state->crtc; in mtk_dp_bridge_atomic_check()
2500 input_bus_format = bridge_state->input_bus_cfg.format; in mtk_dp_bridge_atomic_check()
2502 dev_dbg(mtk_dp->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dp_bridge_atomic_check()
2503 bridge_state->input_bus_cfg.format, in mtk_dp_bridge_atomic_check()
2504 bridge_state->output_bus_cfg.format); in mtk_dp_bridge_atomic_check()
2507 mtk_dp->info.format = DP_PIXELFORMAT_YUV422; in mtk_dp_bridge_atomic_check()
2509 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_bridge_atomic_check()
2512 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_check()
2514 return -EINVAL; in mtk_dp_bridge_atomic_check()
2517 drm_display_mode_to_videomode(&crtc_state->adjusted_mode, &mtk_dp->info.vm); in mtk_dp_bridge_atomic_check()
2542 mtk_dp->need_debounce = true; in mtk_dp_debounce_timer()
2554 if (!mtk_dp->enabled) { in mtk_dp_audio_hw_params()
2555 dev_err(mtk_dp->dev, "%s, DP is not ready!\n", __func__); in mtk_dp_audio_hw_params()
2556 return -ENODEV; in mtk_dp_audio_hw_params()
2559 mtk_dp->info.audio_cur_cfg.channels = params->cea.channels; in mtk_dp_audio_hw_params()
2560 mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate; in mtk_dp_audio_hw_params()
2562 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_audio_hw_params()
2588 if (mtk_dp->enabled) in mtk_dp_audio_get_eld()
2589 memcpy(buf, mtk_dp->conn->eld, len); in mtk_dp_audio_get_eld()
2602 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2603 mtk_dp->plugged_cb = fn; in mtk_dp_audio_hook_plugged_cb()
2604 mtk_dp->codec_dev = codec_dev; in mtk_dp_audio_hook_plugged_cb()
2605 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2631 mtk_dp->audio_pdev = platform_device_register_data(dev, in mtk_dp_register_audio_driver()
2636 return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); in mtk_dp_register_audio_driver()
2641 struct device *dev = mtk_dp->dev; in mtk_dp_register_phy()
2643 mtk_dp->phy_dev = platform_device_register_data(dev, "mediatek-dp-phy", in mtk_dp_register_phy()
2645 &mtk_dp->regs, in mtk_dp_register_phy()
2647 if (IS_ERR(mtk_dp->phy_dev)) in mtk_dp_register_phy()
2648 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy_dev), in mtk_dp_register_phy()
2649 "Failed to create device mediatek-dp-phy\n"); in mtk_dp_register_phy()
2653 mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp"); in mtk_dp_register_phy()
2654 if (IS_ERR(mtk_dp->phy)) { in mtk_dp_register_phy()
2655 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_register_phy()
2656 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), "Failed to get phy\n"); in mtk_dp_register_phy()
2665 struct device *dev = mtk_aux->dev; in mtk_dp_edp_link_panel()
2668 mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); in mtk_dp_edp_link_panel()
2676 if (IS_ERR(mtk_dp->next_bridge)) { in mtk_dp_edp_link_panel()
2677 ret = PTR_ERR(mtk_dp->next_bridge); in mtk_dp_edp_link_panel()
2678 mtk_dp->next_bridge = NULL; in mtk_dp_edp_link_panel()
2683 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_edp_link_panel()
2693 struct device *dev = &pdev->dev; in mtk_dp_probe()
2698 return -ENOMEM; in mtk_dp_probe()
2700 mtk_dp->dev = dev; in mtk_dp_probe()
2701 mtk_dp->data = (struct mtk_dp_data *)of_device_get_match_data(dev); in mtk_dp_probe()
2714 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2715 mtk_dp->irq = platform_get_irq(pdev, 0); in mtk_dp_probe()
2716 if (mtk_dp->irq < 0) in mtk_dp_probe()
2717 return dev_err_probe(dev, mtk_dp->irq, in mtk_dp_probe()
2720 spin_lock_init(&mtk_dp->irq_thread_lock); in mtk_dp_probe()
2722 irq_set_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_probe()
2723 ret = devm_request_threaded_irq(dev, mtk_dp->irq, mtk_dp_hpd_event, in mtk_dp_probe()
2731 mtk_dp->need_debounce = true; in mtk_dp_probe()
2732 timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); in mtk_dp_probe()
2735 mtk_dp->aux.name = "aux_mtk_dp"; in mtk_dp_probe()
2736 mtk_dp->aux.dev = dev; in mtk_dp_probe()
2737 mtk_dp->aux.transfer = mtk_dp_aux_transfer; in mtk_dp_probe()
2738 mtk_dp->aux.wait_hpd_asserted = mtk_dp_wait_hpd_asserted; in mtk_dp_probe()
2739 drm_dp_aux_init(&mtk_dp->aux); in mtk_dp_probe()
2743 if (mtk_dp->data->audio_supported) { in mtk_dp_probe()
2744 mutex_init(&mtk_dp->update_plugged_status_lock); in mtk_dp_probe()
2756 mtk_dp->bridge.funcs = &mtk_dp_bridge_funcs; in mtk_dp_probe()
2757 mtk_dp->bridge.of_node = dev->of_node; in mtk_dp_probe()
2758 mtk_dp->bridge.type = mtk_dp->data->bridge_type; in mtk_dp_probe()
2760 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2774 * Power on the AUX to allow reading the EDID from aux-bus: in mtk_dp_probe()
2783 ret = devm_of_dp_aux_populate_bus(&mtk_dp->aux, mtk_dp_edp_link_panel); in mtk_dp_probe()
2785 /* -ENODEV this means that the panel is not on the aux-bus */ in mtk_dp_probe()
2786 if (ret == -ENODEV) { in mtk_dp_probe()
2787 ret = mtk_dp_edp_link_panel(&mtk_dp->aux); in mtk_dp_probe()
2799 mtk_dp->bridge.ops = DRM_BRIDGE_OP_DETECT | in mtk_dp_probe()
2801 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_probe()
2816 pm_runtime_put(&pdev->dev); in mtk_dp_remove()
2817 pm_runtime_disable(&pdev->dev); in mtk_dp_remove()
2818 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_remove()
2819 del_timer_sync(&mtk_dp->debounce_timer); in mtk_dp_remove()
2820 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_remove()
2821 if (mtk_dp->audio_pdev) in mtk_dp_remove()
2822 platform_device_unregister(mtk_dp->audio_pdev); in mtk_dp_remove()
2831 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_suspend()
2844 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_resume()
2881 .compatible = "mediatek,mt8188-edp-tx",
2885 .compatible = "mediatek,mt8188-dp-tx",
2889 .compatible = "mediatek,mt8195-edp-tx",
2893 .compatible = "mediatek,mt8195-dp-tx",
2904 .name = "mediatek-drm-dp",
2913 MODULE_AUTHOR("Markus Schneider-Pargmann <msp@baylibre.com>");
2914 MODULE_AUTHOR("Bo-Chen Chen <rex-bc.chen@mediatek.com>");