Lines Matching +full:iec +full:- +full:60958

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()
473 drm_warn(mtk_dp->drm_dev, "Unsupported color format: %d\n", in mtk_dp_set_color_format()
475 return -EINVAL; in mtk_dp_set_color_format()
562 switch (cfg->channels) { in mtk_dp_audio_setup_channels()
593 struct snd_aes_iec958 iec = { 0 }; in mtk_dp_audio_channel_status_set() local
595 switch (cfg->sample_rate) { in mtk_dp_audio_channel_status_set()
597 iec.status[3] = IEC958_AES3_CON_FS_32000; in mtk_dp_audio_channel_status_set()
600 iec.status[3] = IEC958_AES3_CON_FS_44100; in mtk_dp_audio_channel_status_set()
603 iec.status[3] = IEC958_AES3_CON_FS_48000; in mtk_dp_audio_channel_status_set()
606 iec.status[3] = IEC958_AES3_CON_FS_88200; in mtk_dp_audio_channel_status_set()
609 iec.status[3] = IEC958_AES3_CON_FS_96000; in mtk_dp_audio_channel_status_set()
612 iec.status[3] = IEC958_AES3_CON_FS_192000; in mtk_dp_audio_channel_status_set()
615 iec.status[3] = IEC958_AES3_CON_FS_NOTID; in mtk_dp_audio_channel_status_set()
619 switch (cfg->word_length_bits) { in mtk_dp_audio_channel_status_set()
621 iec.status[4] = IEC958_AES4_CON_WORDLEN_20_16; in mtk_dp_audio_channel_status_set()
624 iec.status[4] = IEC958_AES4_CON_WORDLEN_20_16 | in mtk_dp_audio_channel_status_set()
628 iec.status[4] = IEC958_AES4_CON_WORDLEN_24_20 | in mtk_dp_audio_channel_status_set()
632 iec.status[4] = IEC958_AES4_CON_WORDLEN_NOTID; in mtk_dp_audio_channel_status_set()
635 /* IEC 60958 consumer channel status bits */ in mtk_dp_audio_channel_status_set()
639 iec.status[3] << 8, CH_STATUS_1_DP_ENC0_P0_MASK); in mtk_dp_audio_channel_status_set()
641 iec.status[4], CH_STATUS_2_DP_ENC0_P0_MASK); in mtk_dp_audio_channel_status_set()
648 (min(8, channels) - 1) << 8, in mtk_dp_audio_sdp_asp_set_channels()
676 u32 db_addr = MTK_DP_ENC0_P0_30D8 + (MTK_DP_SDP_AUI - 1) * 8; in mtk_dp_sdp_set_header_aui()
693 mtk_dp_sdp_set_data(mtk_dp, sdp->db); in mtk_dp_setup_sdp_aui()
694 mtk_dp_sdp_set_header_aui(mtk_dp, &sdp->sdp_header); in mtk_dp_setup_sdp_aui()
766 (length - 1) << 12, in mtk_dp_aux_set_length()
786 while (--wait_reply) { in mtk_dp_aux_wait_for_completion()
804 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
810 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
820 return -EINVAL; in mtk_dp_aux_do_transfer()
855 dev_err(mtk_dp->dev, in mtk_dp_aux_do_transfer()
857 return -EIO; in mtk_dp_aux_do_transfer()
860 return -ETIMEDOUT; in mtk_dp_aux_do_transfer()
889 dev_dbg(mtk_dp->dev, in mtk_dp_set_swing_pre_emphasis()
890 "link training: swing_val = 0x%x, pre-emphasis = 0x%x\n", in mtk_dp_set_swing_pre_emphasis()
1070 struct device *dev = mtk_dp->dev; in mtk_dp_get_calibration_data()
1072 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_get_calibration_data()
1096 fmt = &mtk_dp->data->efuse_fmt[i]; in mtk_dp_get_calibration_data()
1097 cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask; in mtk_dp_get_calibration_data()
1099 if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) { in mtk_dp_get_calibration_data()
1100 dev_warn(mtk_dp->dev, "Invalid efuse data, idx = %d\n", i); in mtk_dp_get_calibration_data()
1110 dev_warn(mtk_dp->dev, "Use default calibration data\n"); in mtk_dp_get_calibration_data()
1112 cal_data[i] = mtk_dp->data->efuse_fmt[i].default_val; in mtk_dp_get_calibration_data()
1117 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_set_calibration_data()
1161 .ssc = mtk_dp->train_info.sink_ssc, in mtk_dp_phy_configure()
1168 ret = phy_configure(mtk_dp->phy, &phy_opts); in mtk_dp_phy_configure()
1198 pattern ? BIT(pattern - 1) << 12 : 0, in mtk_dp_train_set_pattern()
1231 mtk_dp->data->smc_cmd, enable, in mtk_dp_video_mute()
1234 dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n", in mtk_dp_video_mute()
1235 mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1); in mtk_dp_video_mute()
1273 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_aux_panel_poweron()
1277 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_aux_panel_poweron()
1320 bool plugged_in = (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP); in mtk_dp_initialize_priv_data()
1322 mtk_dp->train_info.link_rate = DP_LINK_BW_5_4; in mtk_dp_initialize_priv_data()
1323 mtk_dp->train_info.lane_count = mtk_dp->max_lanes; in mtk_dp_initialize_priv_data()
1324 mtk_dp->train_info.cable_plugged_in = plugged_in; in mtk_dp_initialize_priv_data()
1326 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_initialize_priv_data()
1327 memset(&mtk_dp->info.vm, 0, sizeof(struct videomode)); in mtk_dp_initialize_priv_data()
1328 mtk_dp->audio_enable = false; in mtk_dp_initialize_priv_data()
1336 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init()
1342 mtk_dp->train_info.link_rate * 2700 * 8 / in mtk_dp_sdp_set_down_cnt_init()
1345 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init()
1371 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1375 pix_clk_mhz = mtk_dp->info.format == DP_PIXELFORMAT_YUV420 ? in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1378 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1389 if (pix_clk_mhz > mtk_dp->train_info.link_rate * 27) in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1403 mtk_dp->info.vm.hactive / in mtk_dp_setup_tu()
1404 mtk_dp->train_info.lane_count / in mtk_dp_setup_tu()
1444 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_LANE0_SET + lane, in mtk_dp_train_update_swing_pre()
1458 aux_offset = mtk_dp->train_info.channel_eq_pattern; in mtk_dp_pattern()
1460 switch (mtk_dp->train_info.channel_eq_pattern) { in mtk_dp_pattern()
1477 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, aux_offset); in mtk_dp_pattern()
1485 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET, target_link_rate); in mtk_dp_train_setting()
1486 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, in mtk_dp_train_setting()
1489 if (mtk_dp->train_info.sink_ssc) in mtk_dp_train_setting()
1490 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_DOWNSPREAD_CTRL, in mtk_dp_train_setting()
1498 dev_dbg(mtk_dp->dev, in mtk_dp_train_setting()
1518 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_cr()
1520 return -ENODEV; in mtk_dp_train_cr()
1523 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_cr()
1528 drm_dp_link_train_clock_recovery_delay(&mtk_dp->aux, in mtk_dp_train_cr()
1529 mtk_dp->rx_cap); in mtk_dp_train_cr()
1532 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_cr()
1535 dev_dbg(mtk_dp->dev, "Link train CR pass\n"); in mtk_dp_train_cr()
1555 dev_dbg(mtk_dp->dev, "Link train CR fail\n"); in mtk_dp_train_cr()
1561 * re-calculate this retry count. in mtk_dp_train_cr()
1569 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_cr()
1573 return -ETIMEDOUT; in mtk_dp_train_cr()
1586 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_eq()
1588 return -ENODEV; in mtk_dp_train_eq()
1591 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_eq()
1596 drm_dp_link_train_channel_eq_delay(&mtk_dp->aux, in mtk_dp_train_eq()
1597 mtk_dp->rx_cap); in mtk_dp_train_eq()
1600 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_eq()
1602 dev_dbg(mtk_dp->dev, "Link train EQ pass\n"); in mtk_dp_train_eq()
1605 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1610 dev_dbg(mtk_dp->dev, "Link train EQ fail\n"); in mtk_dp_train_eq()
1614 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1618 return -ETIMEDOUT; in mtk_dp_train_eq()
1631 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP && in mtk_dp_parse_capabilities()
1632 mtk_dp->rx_cap[DP_MAX_LINK_RATE] && in mtk_dp_parse_capabilities()
1633 mtk_dp->train_info.sink_ssc) in mtk_dp_parse_capabilities()
1636 ret = drm_dp_read_dpcd_caps(&mtk_dp->aux, mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1640 if (drm_dp_tps4_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1641 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_4; in mtk_dp_parse_capabilities()
1642 else if (drm_dp_tps3_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1643 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_3; in mtk_dp_parse_capabilities()
1645 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_2; in mtk_dp_parse_capabilities()
1647 mtk_dp->train_info.sink_ssc = drm_dp_max_downspread(mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1649 ret = drm_dp_dpcd_readb(&mtk_dp->aux, DP_MSTM_CAP, &val); in mtk_dp_parse_capabilities()
1651 drm_err(mtk_dp->drm_dev, "Read mstm cap failed\n"); in mtk_dp_parse_capabilities()
1652 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1657 ret = drm_dp_dpcd_readb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1661 drm_err(mtk_dp->drm_dev, "Read irq vector failed\n"); in mtk_dp_parse_capabilities()
1662 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1666 ret = drm_dp_dpcd_writeb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1680 if (!mtk_dp->data->audio_supported) in mtk_dp_edid_parse_audio_capabilities()
1683 if (mtk_dp->info.audio_cur_cfg.sad_count <= 0) { in mtk_dp_edid_parse_audio_capabilities()
1684 drm_info(mtk_dp->drm_dev, "The SADs is NULL\n"); in mtk_dp_edid_parse_audio_capabilities()
1693 phy_reset(mtk_dp->phy); in mtk_dp_train_change_mode()
1702 link_rate = min_t(u8, mtk_dp->max_linkrate, in mtk_dp_training()
1703 mtk_dp->rx_cap[DP_MAX_LINK_RATE]); in mtk_dp_training()
1705 lane_count = min_t(u8, mtk_dp->max_lanes, in mtk_dp_training()
1706 drm_dp_max_lane_count(mtk_dp->rx_cap)); in mtk_dp_training()
1715 for (train_limit = 6; train_limit > 0; train_limit--) { in mtk_dp_training()
1723 if (ret == -ENODEV) { in mtk_dp_training()
1732 return -EIO; in mtk_dp_training()
1744 return -EINVAL; in mtk_dp_training()
1750 if (ret == -ENODEV) { in mtk_dp_training()
1755 return -EIO; in mtk_dp_training()
1765 return -ETIMEDOUT; in mtk_dp_training()
1767 mtk_dp->train_info.link_rate = link_rate; in mtk_dp_training()
1768 mtk_dp->train_info.lane_count = lane_count; in mtk_dp_training()
1803 frame.channels = cfg->channels; in mtk_dp_audio_sdp_setup()
1804 frame.sample_frequency = cfg->sample_rate; in mtk_dp_audio_sdp_setup()
1806 switch (cfg->word_length_bits) { in mtk_dp_audio_sdp_setup()
1821 mtk_dp_audio_sdp_asp_set_channels(mtk_dp, cfg->channels); in mtk_dp_audio_sdp_setup()
1840 return mtk_dp_set_color_format(mtk_dp, mtk_dp->info.format); in mtk_dp_video_config()
1862 if (mtk_dp->need_debounce && mtk_dp->train_info.cable_plugged_in) in mtk_dp_hpd_event_thread()
1865 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1866 status = mtk_dp->irq_thread_handle; in mtk_dp_hpd_event_thread()
1867 mtk_dp->irq_thread_handle = 0; in mtk_dp_hpd_event_thread()
1868 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1871 if (mtk_dp->bridge.dev) in mtk_dp_hpd_event_thread()
1872 drm_helper_hpd_irq_event(mtk_dp->bridge.dev); in mtk_dp_hpd_event_thread()
1874 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_hpd_event_thread()
1876 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_hpd_event_thread()
1877 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_hpd_event_thread()
1879 mtk_dp->need_debounce = false; in mtk_dp_hpd_event_thread()
1880 mod_timer(&mtk_dp->debounce_timer, in mtk_dp_hpd_event_thread()
1881 jiffies + msecs_to_jiffies(100) - 1); in mtk_dp_hpd_event_thread()
1886 dev_dbg(mtk_dp->dev, "Receive IRQ from sink devices\n"); in mtk_dp_hpd_event_thread()
1902 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1905 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_HPD_EVENT; in mtk_dp_hpd_event()
1909 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_CABLE_STATE_CHG; in mtk_dp_hpd_event()
1913 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1918 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_hpd_event()
1920 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_hpd_event()
1932 ret = regmap_read_poll_timeout(mtk_dp->regs, MTK_DP_TRANS_P0_3414, in mtk_dp_wait_hpd_asserted()
1936 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_wait_hpd_asserted()
1940 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_wait_hpd_asserted()
1944 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_wait_hpd_asserted()
1955 struct device *dev = &pdev->dev; in mtk_dp_dt_parse()
1965 mtk_dp->regs = devm_regmap_init_mmio(dev, base, &mtk_dp_regmap_config); in mtk_dp_dt_parse()
1966 if (IS_ERR(mtk_dp->regs)) in mtk_dp_dt_parse()
1967 return PTR_ERR(mtk_dp->regs); in mtk_dp_dt_parse()
1969 endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 1, -1); in mtk_dp_dt_parse()
1971 "data-lanes", sizeof(u32)); in mtk_dp_dt_parse()
1974 return -EINVAL; in mtk_dp_dt_parse()
1977 mtk_dp->max_lanes = len; in mtk_dp_dt_parse()
1979 ret = device_property_read_u32(dev, "max-linkrate-mhz", &linkrate); in mtk_dp_dt_parse()
1985 mtk_dp->max_linkrate = drm_dp_link_rate_to_bw_code(linkrate * 100); in mtk_dp_dt_parse()
1992 if (!mtk_dp->data->audio_supported || !mtk_dp->audio_enable) in mtk_dp_update_plugged_status()
1995 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
1996 if (mtk_dp->plugged_cb && mtk_dp->codec_dev) in mtk_dp_update_plugged_status()
1997 mtk_dp->plugged_cb(mtk_dp->codec_dev, in mtk_dp_update_plugged_status()
1998 mtk_dp->enabled & in mtk_dp_update_plugged_status()
1999 mtk_dp->info.audio_cur_cfg.detect_monitor); in mtk_dp_update_plugged_status()
2000 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
2007 bool enabled = mtk_dp->enabled; in mtk_dp_bdg_detect()
2009 if (!mtk_dp->train_info.cable_plugged_in) in mtk_dp_bdg_detect()
2023 if (drm_dp_read_sink_count(&mtk_dp->aux) > 0) in mtk_dp_bdg_detect()
2036 bool enabled = mtk_dp->enabled; in mtk_dp_edid_read()
2038 struct mtk_dp_audio_cfg *audio_caps = &mtk_dp->info.audio_cur_cfg; in mtk_dp_edid_read()
2041 drm_atomic_bridge_chain_pre_enable(bridge, connector->state->state); in mtk_dp_edid_read()
2045 drm_edid = drm_edid_read_ddc(connector, &mtk_dp->aux.ddc); in mtk_dp_edid_read()
2052 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_edid_read()
2071 audio_caps->sad_count = ret; in mtk_dp_edid_read()
2074 * FIXME: This should use connector->display_info.has_audio from in mtk_dp_edid_read()
2078 audio_caps->detect_monitor = drm_detect_monitor_audio(edid); in mtk_dp_edid_read()
2083 drm_atomic_bridge_chain_post_disable(bridge, connector->state->state); in mtk_dp_edid_read()
2098 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP && in mtk_dp_aux_transfer()
2099 !mtk_dp->train_info.cable_plugged_in) { in mtk_dp_aux_transfer()
2100 ret = -EIO; in mtk_dp_aux_transfer()
2104 switch (msg->request) { in mtk_dp_aux_transfer()
2110 request = msg->request & ~DP_AUX_I2C_WRITE_STATUS_UPDATE; in mtk_dp_aux_transfer()
2116 request = msg->request; in mtk_dp_aux_transfer()
2120 dev_err(mtk_dp->dev, "invalid aux cmd = %d\n", in mtk_dp_aux_transfer()
2121 msg->request); in mtk_dp_aux_transfer()
2122 ret = -EINVAL; in mtk_dp_aux_transfer()
2128 msg->size - accessed_bytes); in mtk_dp_aux_transfer()
2131 msg->address + accessed_bytes, in mtk_dp_aux_transfer()
2132 msg->buffer + accessed_bytes, in mtk_dp_aux_transfer()
2133 to_access, &msg->reply); in mtk_dp_aux_transfer()
2136 dev_info(mtk_dp->dev, in mtk_dp_aux_transfer()
2141 } while (accessed_bytes < msg->size); in mtk_dp_aux_transfer()
2143 return msg->size; in mtk_dp_aux_transfer()
2145 msg->reply = DP_AUX_NATIVE_REPLY_NACK | DP_AUX_I2C_REPLY_NACK; in mtk_dp_aux_transfer()
2153 ret = phy_init(mtk_dp->phy); in mtk_dp_poweron()
2155 dev_err(mtk_dp->dev, "Failed to initialize phy: %d\n", ret); in mtk_dp_poweron()
2168 phy_exit(mtk_dp->phy); in mtk_dp_poweroff()
2178 dev_err(mtk_dp->dev, "Driver does not provide a connector!"); in mtk_dp_bridge_attach()
2179 return -EINVAL; in mtk_dp_bridge_attach()
2182 mtk_dp->aux.drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2183 ret = drm_dp_aux_register(&mtk_dp->aux); in mtk_dp_bridge_attach()
2185 dev_err(mtk_dp->dev, in mtk_dp_bridge_attach()
2194 if (mtk_dp->next_bridge) { in mtk_dp_bridge_attach()
2195 ret = drm_bridge_attach(bridge->encoder, mtk_dp->next_bridge, in mtk_dp_bridge_attach()
2196 &mtk_dp->bridge, flags); in mtk_dp_bridge_attach()
2198 drm_warn(mtk_dp->drm_dev, in mtk_dp_bridge_attach()
2204 mtk_dp->drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2206 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_attach()
2207 irq_clear_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_bridge_attach()
2208 enable_irq(mtk_dp->irq); in mtk_dp_bridge_attach()
2217 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_attach()
2225 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_bridge_detach()
2227 disable_irq(mtk_dp->irq); in mtk_dp_bridge_detach()
2229 mtk_dp->drm_dev = NULL; in mtk_dp_bridge_detach()
2231 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_detach()
2240 mtk_dp->conn = drm_atomic_get_new_connector_for_encoder(old_state->base.state, in mtk_dp_bridge_atomic_enable()
2241 bridge->encoder); in mtk_dp_bridge_atomic_enable()
2242 if (!mtk_dp->conn) { in mtk_dp_bridge_atomic_enable()
2243 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_enable()
2253 drm_err(mtk_dp->drm_dev, "Training failed, %d\n", ret); in mtk_dp_bridge_atomic_enable()
2263 mtk_dp->audio_enable = in mtk_dp_bridge_atomic_enable()
2265 &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2266 if (mtk_dp->audio_enable) { in mtk_dp_bridge_atomic_enable()
2267 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2270 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_bridge_atomic_enable()
2271 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_bridge_atomic_enable()
2274 mtk_dp->enabled = true; in mtk_dp_bridge_atomic_enable()
2289 mtk_dp->enabled = false; in mtk_dp_bridge_atomic_disable()
2294 if (mtk_dp->train_info.cable_plugged_in) { in mtk_dp_bridge_atomic_disable()
2295 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_bridge_atomic_disable()
2314 u32 bpp = info->color_formats & DRM_COLOR_FORMAT_YCBCR422 ? 16 : 24; in mtk_dp_bridge_mode_valid()
2315 u32 lane_count_min = mtk_dp->train_info.lane_count; in mtk_dp_bridge_mode_valid()
2316 u32 rate = drm_dp_bw_code_to_link_rate(mtk_dp->train_info.link_rate) * in mtk_dp_bridge_mode_valid()
2321 *The down-spread amplitude shall either be disabled (0.0%) or up in mtk_dp_bridge_mode_valid()
2325 *mode->clock does not need to be multiplied by 10 in mtk_dp_bridge_mode_valid()
2327 if ((rate * 97 / 100) < (mode->clock * bpp / 8)) in mtk_dp_bridge_mode_valid()
2365 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2367 &conn_state->connector->display_info; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2368 u32 lane_count_min = mtk_dp->train_info.lane_count; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2369 u32 rate = drm_dp_bw_code_to_link_rate(mtk_dp->train_info.link_rate) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2379 if (((rate * 97 / 100) < (mode->clock * 24 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2380 ((rate * 97 / 100) > (mode->clock * 16 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2381 (display_info->color_formats & DRM_COLOR_FORMAT_YCBCR422)) { in mtk_dp_bridge_atomic_get_input_bus_fmts()
2407 struct drm_crtc *crtc = conn_state->crtc; in mtk_dp_bridge_atomic_check()
2410 input_bus_format = bridge_state->input_bus_cfg.format; in mtk_dp_bridge_atomic_check()
2412 dev_dbg(mtk_dp->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dp_bridge_atomic_check()
2413 bridge_state->input_bus_cfg.format, in mtk_dp_bridge_atomic_check()
2414 bridge_state->output_bus_cfg.format); in mtk_dp_bridge_atomic_check()
2417 mtk_dp->info.format = DP_PIXELFORMAT_YUV422; in mtk_dp_bridge_atomic_check()
2419 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_bridge_atomic_check()
2422 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_check()
2424 return -EINVAL; in mtk_dp_bridge_atomic_check()
2427 drm_display_mode_to_videomode(&crtc_state->adjusted_mode, &mtk_dp->info.vm); in mtk_dp_bridge_atomic_check()
2452 mtk_dp->need_debounce = true; in mtk_dp_debounce_timer()
2464 if (!mtk_dp->enabled) { in mtk_dp_audio_hw_params()
2465 dev_err(mtk_dp->dev, "%s, DP is not ready!\n", __func__); in mtk_dp_audio_hw_params()
2466 return -ENODEV; in mtk_dp_audio_hw_params()
2469 mtk_dp->info.audio_cur_cfg.channels = params->cea.channels; in mtk_dp_audio_hw_params()
2470 mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate; in mtk_dp_audio_hw_params()
2472 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_audio_hw_params()
2498 if (mtk_dp->enabled) in mtk_dp_audio_get_eld()
2499 memcpy(buf, mtk_dp->conn->eld, len); in mtk_dp_audio_get_eld()
2512 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2513 mtk_dp->plugged_cb = fn; in mtk_dp_audio_hook_plugged_cb()
2514 mtk_dp->codec_dev = codec_dev; in mtk_dp_audio_hook_plugged_cb()
2515 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2541 mtk_dp->audio_pdev = platform_device_register_data(dev, in mtk_dp_register_audio_driver()
2546 return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); in mtk_dp_register_audio_driver()
2551 struct device *dev = mtk_dp->dev; in mtk_dp_register_phy()
2553 mtk_dp->phy_dev = platform_device_register_data(dev, "mediatek-dp-phy", in mtk_dp_register_phy()
2555 &mtk_dp->regs, in mtk_dp_register_phy()
2557 if (IS_ERR(mtk_dp->phy_dev)) in mtk_dp_register_phy()
2558 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy_dev), in mtk_dp_register_phy()
2559 "Failed to create device mediatek-dp-phy\n"); in mtk_dp_register_phy()
2563 mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp"); in mtk_dp_register_phy()
2564 if (IS_ERR(mtk_dp->phy)) { in mtk_dp_register_phy()
2565 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_register_phy()
2566 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), "Failed to get phy\n"); in mtk_dp_register_phy()
2575 struct device *dev = mtk_aux->dev; in mtk_dp_edp_link_panel()
2578 mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); in mtk_dp_edp_link_panel()
2586 if (IS_ERR(mtk_dp->next_bridge)) { in mtk_dp_edp_link_panel()
2587 ret = PTR_ERR(mtk_dp->next_bridge); in mtk_dp_edp_link_panel()
2588 mtk_dp->next_bridge = NULL; in mtk_dp_edp_link_panel()
2593 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_edp_link_panel()
2603 struct device *dev = &pdev->dev; in mtk_dp_probe()
2608 return -ENOMEM; in mtk_dp_probe()
2610 mtk_dp->dev = dev; in mtk_dp_probe()
2611 mtk_dp->data = (struct mtk_dp_data *)of_device_get_match_data(dev); in mtk_dp_probe()
2624 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2625 mtk_dp->irq = platform_get_irq(pdev, 0); in mtk_dp_probe()
2626 if (mtk_dp->irq < 0) in mtk_dp_probe()
2627 return dev_err_probe(dev, mtk_dp->irq, in mtk_dp_probe()
2630 spin_lock_init(&mtk_dp->irq_thread_lock); in mtk_dp_probe()
2632 irq_set_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); in mtk_dp_probe()
2633 ret = devm_request_threaded_irq(dev, mtk_dp->irq, mtk_dp_hpd_event, in mtk_dp_probe()
2641 mtk_dp->need_debounce = true; in mtk_dp_probe()
2642 timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); in mtk_dp_probe()
2645 mtk_dp->aux.name = "aux_mtk_dp"; in mtk_dp_probe()
2646 mtk_dp->aux.dev = dev; in mtk_dp_probe()
2647 mtk_dp->aux.transfer = mtk_dp_aux_transfer; in mtk_dp_probe()
2648 mtk_dp->aux.wait_hpd_asserted = mtk_dp_wait_hpd_asserted; in mtk_dp_probe()
2649 drm_dp_aux_init(&mtk_dp->aux); in mtk_dp_probe()
2653 if (mtk_dp->data->audio_supported) { in mtk_dp_probe()
2654 mutex_init(&mtk_dp->update_plugged_status_lock); in mtk_dp_probe()
2668 mtk_dp->bridge.funcs = &mtk_dp_bridge_funcs; in mtk_dp_probe()
2669 mtk_dp->bridge.of_node = dev->of_node; in mtk_dp_probe()
2670 mtk_dp->bridge.type = mtk_dp->data->bridge_type; in mtk_dp_probe()
2672 if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) { in mtk_dp_probe()
2686 * Power on the AUX to allow reading the EDID from aux-bus: in mtk_dp_probe()
2695 ret = devm_of_dp_aux_populate_bus(&mtk_dp->aux, mtk_dp_edp_link_panel); in mtk_dp_probe()
2697 /* -ENODEV this means that the panel is not on the aux-bus */ in mtk_dp_probe()
2698 if (ret == -ENODEV) { in mtk_dp_probe()
2699 ret = mtk_dp_edp_link_panel(&mtk_dp->aux); in mtk_dp_probe()
2711 mtk_dp->bridge.ops = DRM_BRIDGE_OP_DETECT | in mtk_dp_probe()
2713 ret = devm_drm_bridge_add(dev, &mtk_dp->bridge); in mtk_dp_probe()
2728 pm_runtime_put(&pdev->dev); in mtk_dp_remove()
2729 pm_runtime_disable(&pdev->dev); in mtk_dp_remove()
2730 if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_remove()
2731 del_timer_sync(&mtk_dp->debounce_timer); in mtk_dp_remove()
2732 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_remove()
2733 if (mtk_dp->audio_pdev) in mtk_dp_remove()
2734 platform_device_unregister(mtk_dp->audio_pdev); in mtk_dp_remove()
2743 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_suspend()
2756 if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) in mtk_dp_resume()
2782 .compatible = "mediatek,mt8195-edp-tx",
2786 .compatible = "mediatek,mt8195-dp-tx",
2797 .name = "mediatek-drm-dp",
2806 MODULE_AUTHOR("Markus Schneider-Pargmann <msp@baylibre.com>");
2807 MODULE_AUTHOR("Bo-Chen Chen <rex-bc.chen@mediatek.com>");