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

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019-2022 MediaTek Inc.
17 #include <linux/arm-smccc.h>
22 #include <linux/media-bus-format.h>
23 #include <linux/nvmem-consumer.h>
32 #include <sound/hdmi-codec.h>
315 .name = "mtk-dp-registers",
328 ret = regmap_read(mtk_dp->regs, offset, &read_val); in mtk_dp_read()
330 dev_err(mtk_dp->dev, "Failed to read register 0x%x: %d\n", in mtk_dp_read()
340 int ret = regmap_write(mtk_dp->regs, offset, val); in mtk_dp_write()
343 dev_err(mtk_dp->dev, in mtk_dp_write()
352 int ret = regmap_update_bits(mtk_dp->regs, offset, mask, val); in mtk_dp_update_bits()
355 dev_err(mtk_dp->dev, in mtk_dp_update_bits()
389 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_set_msa()
397 vm->hsync_len + vm->hback_porch, in mtk_dp_set_msa()
400 vm->hsync_len, HSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
404 vm->hactive, HWIDTH_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
410 vm->vsync_len + vm->vback_porch, in mtk_dp_set_msa()
413 vm->vsync_len, VSW_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
417 vm->vactive, VHEIGHT_SW_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
421 vm->hactive, HDE_NUM_LAST_DP_ENC0_P0_MASK); in mtk_dp_set_msa()
425 vm->hfront_porch, in mtk_dp_set_msa()
428 vm->hsync_len, in mtk_dp_set_msa()
431 vm->hback_porch + vm->hsync_len, in mtk_dp_set_msa()
434 vm->hactive, in mtk_dp_set_msa()
442 vm->vfront_porch, in mtk_dp_set_msa()
445 vm->vsync_len, in mtk_dp_set_msa()
448 vm->vback_porch + vm->vsync_len, in mtk_dp_set_msa()
451 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()
557 switch (cfg->channels) { in mtk_dp_audio_setup_channels()
590 switch (cfg->sample_rate) { in mtk_dp_audio_channel_status_set()
614 switch (cfg->word_length_bits) { in mtk_dp_audio_channel_status_set()
643 (min(8, channels) - 1) << 8, in mtk_dp_audio_sdp_asp_set_channels()
671 u32 db_addr = MTK_DP_ENC0_P0_30D8 + (MTK_DP_SDP_AUI - 1) * 8; in mtk_dp_sdp_set_header_aui()
688 mtk_dp_sdp_set_data(mtk_dp, sdp->db); in mtk_dp_setup_sdp_aui()
689 mtk_dp_sdp_set_header_aui(mtk_dp, &sdp->sdp_header); in mtk_dp_setup_sdp_aui()
761 (length - 1) << 12, in mtk_dp_aux_set_length()
781 while (--wait_reply) { in mtk_dp_aux_wait_for_completion()
799 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
805 return -ETIMEDOUT; in mtk_dp_aux_wait_for_completion()
816 return -EINVAL; in mtk_dp_aux_do_transfer()
851 drm_err(mtk_dp->drm_dev, in mtk_dp_aux_do_transfer()
853 return -EIO; in mtk_dp_aux_do_transfer()
856 return -ETIMEDOUT; in mtk_dp_aux_do_transfer()
885 dev_dbg(mtk_dp->dev, in mtk_dp_set_swing_pre_emphasis()
886 "link training: swing_val = 0x%x, pre-emphasis = 0x%x\n", in mtk_dp_set_swing_pre_emphasis()
1061 struct device *dev = mtk_dp->dev; in mtk_dp_get_calibration_data()
1062 struct nvmem_cell *cell; in mtk_dp_get_calibration_data() local
1063 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_get_calibration_data()
1068 cell = nvmem_cell_get(dev, "dp_calibration_data"); in mtk_dp_get_calibration_data()
1069 if (IS_ERR(cell)) { in mtk_dp_get_calibration_data()
1070 dev_warn(dev, "Failed to get nvmem cell dp_calibration_data\n"); in mtk_dp_get_calibration_data()
1074 buf = (u32 *)nvmem_cell_read(cell, &len); in mtk_dp_get_calibration_data()
1075 nvmem_cell_put(cell); in mtk_dp_get_calibration_data()
1087 fmt = &mtk_dp->data->efuse_fmt[i]; in mtk_dp_get_calibration_data()
1088 cal_data[i] = (buf[fmt->idx] >> fmt->shift) & fmt->mask; in mtk_dp_get_calibration_data()
1090 if (cal_data[i] < fmt->min_val || cal_data[i] > fmt->max_val) { in mtk_dp_get_calibration_data()
1091 dev_warn(mtk_dp->dev, "Invalid efuse data, idx = %d\n", i); in mtk_dp_get_calibration_data()
1101 dev_warn(mtk_dp->dev, "Use default calibration data\n"); in mtk_dp_get_calibration_data()
1103 cal_data[i] = mtk_dp->data->efuse_fmt[i].default_val; in mtk_dp_get_calibration_data()
1108 u32 *cal_data = mtk_dp->cal_data; in mtk_dp_set_calibration_data()
1152 .ssc = mtk_dp->train_info.sink_ssc, in mtk_dp_phy_configure()
1159 ret = phy_configure(mtk_dp->phy, &phy_opts); in mtk_dp_phy_configure()
1189 pattern ? BIT(pattern - 1) << 12 : 0, in mtk_dp_train_set_pattern()
1222 mtk_dp->data->smc_cmd, enable, in mtk_dp_video_mute()
1225 dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n", in mtk_dp_video_mute()
1226 mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1); in mtk_dp_video_mute()
1288 mtk_dp->train_info.link_rate = DP_LINK_BW_5_4; in mtk_dp_initialize_priv_data()
1289 mtk_dp->train_info.lane_count = mtk_dp->max_lanes; in mtk_dp_initialize_priv_data()
1290 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_initialize_priv_data()
1292 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_initialize_priv_data()
1293 memset(&mtk_dp->info.vm, 0, sizeof(struct videomode)); in mtk_dp_initialize_priv_data()
1294 mtk_dp->audio_enable = false; in mtk_dp_initialize_priv_data()
1302 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init()
1308 mtk_dp->train_info.link_rate * 2700 * 8 / in mtk_dp_sdp_set_down_cnt_init()
1311 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init()
1337 struct videomode *vm = &mtk_dp->info.vm; in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1341 pix_clk_mhz = mtk_dp->info.format == DP_PIXELFORMAT_YUV420 ? in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1344 switch (mtk_dp->train_info.lane_count) { in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1355 if (pix_clk_mhz > mtk_dp->train_info.link_rate * 27) in mtk_dp_sdp_set_down_cnt_init_in_hblank()
1369 mtk_dp->info.vm.hactive / in mtk_dp_setup_tu()
1370 mtk_dp->train_info.lane_count / in mtk_dp_setup_tu()
1410 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_LANE0_SET + lane, in mtk_dp_train_update_swing_pre()
1424 aux_offset = mtk_dp->train_info.channel_eq_pattern; in mtk_dp_pattern()
1426 switch (mtk_dp->train_info.channel_eq_pattern) { in mtk_dp_pattern()
1443 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, aux_offset); in mtk_dp_pattern()
1451 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET, target_link_rate); in mtk_dp_train_setting()
1452 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, in mtk_dp_train_setting()
1455 if (mtk_dp->train_info.sink_ssc) in mtk_dp_train_setting()
1456 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_DOWNSPREAD_CTRL, in mtk_dp_train_setting()
1464 dev_dbg(mtk_dp->dev, in mtk_dp_train_setting()
1484 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_cr()
1486 return -ENODEV; in mtk_dp_train_cr()
1489 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_cr()
1494 drm_dp_link_train_clock_recovery_delay(&mtk_dp->aux, in mtk_dp_train_cr()
1495 mtk_dp->rx_cap); in mtk_dp_train_cr()
1498 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_cr()
1501 dev_dbg(mtk_dp->dev, "Link train CR pass\n"); in mtk_dp_train_cr()
1514 * level over five times. in mtk_dp_train_cr()
1521 dev_dbg(mtk_dp->dev, "Link train CR fail\n"); in mtk_dp_train_cr()
1527 * re-calculate this retry count. in mtk_dp_train_cr()
1535 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_cr()
1539 return -ETIMEDOUT; in mtk_dp_train_cr()
1552 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_train_eq()
1554 return -ENODEV; in mtk_dp_train_eq()
1557 drm_dp_dpcd_read(&mtk_dp->aux, DP_ADJUST_REQUEST_LANE0_1, in mtk_dp_train_eq()
1562 drm_dp_link_train_channel_eq_delay(&mtk_dp->aux, in mtk_dp_train_eq()
1563 mtk_dp->rx_cap); in mtk_dp_train_eq()
1566 drm_dp_dpcd_read_link_status(&mtk_dp->aux, link_status); in mtk_dp_train_eq()
1568 dev_dbg(mtk_dp->dev, "Link train EQ pass\n"); in mtk_dp_train_eq()
1571 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1576 dev_dbg(mtk_dp->dev, "Link train EQ fail\n"); in mtk_dp_train_eq()
1580 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_TRAINING_PATTERN_SET, in mtk_dp_train_eq()
1584 return -ETIMEDOUT; in mtk_dp_train_eq()
1592 drm_dp_read_dpcd_caps(&mtk_dp->aux, mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1594 if (drm_dp_tps4_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1595 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_4; in mtk_dp_parse_capabilities()
1596 else if (drm_dp_tps3_supported(mtk_dp->rx_cap)) in mtk_dp_parse_capabilities()
1597 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_3; in mtk_dp_parse_capabilities()
1599 mtk_dp->train_info.channel_eq_pattern = DP_TRAINING_PATTERN_2; in mtk_dp_parse_capabilities()
1601 mtk_dp->train_info.sink_ssc = drm_dp_max_downspread(mtk_dp->rx_cap); in mtk_dp_parse_capabilities()
1603 ret = drm_dp_dpcd_readb(&mtk_dp->aux, DP_MSTM_CAP, &val); in mtk_dp_parse_capabilities()
1605 drm_err(mtk_dp->drm_dev, "Read mstm cap failed\n"); in mtk_dp_parse_capabilities()
1606 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1611 ret = drm_dp_dpcd_readb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1615 drm_err(mtk_dp->drm_dev, "Read irq vector failed\n"); in mtk_dp_parse_capabilities()
1616 return ret == 0 ? -EIO : ret; in mtk_dp_parse_capabilities()
1620 drm_dp_dpcd_writeb(&mtk_dp->aux, in mtk_dp_parse_capabilities()
1631 if (!mtk_dp->data->audio_supported) in mtk_dp_edid_parse_audio_capabilities()
1634 if (mtk_dp->info.audio_cur_cfg.sad_count <= 0) { in mtk_dp_edid_parse_audio_capabilities()
1635 drm_info(mtk_dp->drm_dev, "The SADs is NULL\n"); in mtk_dp_edid_parse_audio_capabilities()
1644 phy_reset(mtk_dp->phy); in mtk_dp_train_change_mode()
1653 link_rate = min_t(u8, mtk_dp->max_linkrate, in mtk_dp_training()
1654 mtk_dp->rx_cap[DP_MAX_LINK_RATE]); in mtk_dp_training()
1656 lane_count = min_t(u8, mtk_dp->max_lanes, in mtk_dp_training()
1657 drm_dp_max_lane_count(mtk_dp->rx_cap)); in mtk_dp_training()
1666 for (train_limit = 6; train_limit > 0; train_limit--) { in mtk_dp_training()
1674 if (ret == -ENODEV) { in mtk_dp_training()
1683 return -EIO; in mtk_dp_training()
1695 return -EINVAL; in mtk_dp_training()
1701 if (ret == -ENODEV) { in mtk_dp_training()
1706 return -EIO; in mtk_dp_training()
1716 return -ETIMEDOUT; in mtk_dp_training()
1718 mtk_dp->train_info.link_rate = link_rate; in mtk_dp_training()
1719 mtk_dp->train_info.lane_count = lane_count; in mtk_dp_training()
1754 frame.channels = cfg->channels; in mtk_dp_audio_sdp_setup()
1755 frame.sample_frequency = cfg->sample_rate; in mtk_dp_audio_sdp_setup()
1757 switch (cfg->word_length_bits) { in mtk_dp_audio_sdp_setup()
1772 mtk_dp_audio_sdp_asp_set_channels(mtk_dp, cfg->channels); in mtk_dp_audio_sdp_setup()
1791 return mtk_dp_set_color_format(mtk_dp, mtk_dp->info.format); in mtk_dp_video_config()
1817 if (mtk_dp->need_debounce && mtk_dp->train_info.cable_plugged_in) in mtk_dp_hpd_event_thread()
1820 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1821 status = mtk_dp->irq_thread_handle; in mtk_dp_hpd_event_thread()
1822 mtk_dp->irq_thread_handle = 0; in mtk_dp_hpd_event_thread()
1823 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event_thread()
1826 drm_helper_hpd_irq_event(mtk_dp->bridge.dev); in mtk_dp_hpd_event_thread()
1828 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_hpd_event_thread()
1830 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_hpd_event_thread()
1831 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_hpd_event_thread()
1833 mtk_dp->need_debounce = false; in mtk_dp_hpd_event_thread()
1834 mod_timer(&mtk_dp->debounce_timer, in mtk_dp_hpd_event_thread()
1835 jiffies + msecs_to_jiffies(100) - 1); in mtk_dp_hpd_event_thread()
1840 dev_dbg(mtk_dp->dev, "Receive IRQ from sink devices\n"); in mtk_dp_hpd_event_thread()
1856 spin_lock_irqsave(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1859 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_HPD_EVENT; in mtk_dp_hpd_event()
1863 mtk_dp->irq_thread_handle |= MTK_DP_THREAD_CABLE_STATE_CHG; in mtk_dp_hpd_event()
1867 spin_unlock_irqrestore(&mtk_dp->irq_thread_lock, flags); in mtk_dp_hpd_event()
1872 mtk_dp->train_info.cable_plugged_in = true; in mtk_dp_hpd_event()
1874 mtk_dp->train_info.cable_plugged_in = false; in mtk_dp_hpd_event()
1884 struct device *dev = &pdev->dev; in mtk_dp_dt_parse()
1894 mtk_dp->regs = devm_regmap_init_mmio(dev, base, &mtk_dp_regmap_config); in mtk_dp_dt_parse()
1895 if (IS_ERR(mtk_dp->regs)) in mtk_dp_dt_parse()
1896 return PTR_ERR(mtk_dp->regs); in mtk_dp_dt_parse()
1898 endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 1, -1); in mtk_dp_dt_parse()
1900 "data-lanes", sizeof(u32)); in mtk_dp_dt_parse()
1903 return -EINVAL; in mtk_dp_dt_parse()
1906 mtk_dp->max_lanes = len; in mtk_dp_dt_parse()
1908 ret = device_property_read_u32(dev, "max-linkrate-mhz", &linkrate); in mtk_dp_dt_parse()
1914 mtk_dp->max_linkrate = drm_dp_link_rate_to_bw_code(linkrate * 100); in mtk_dp_dt_parse()
1921 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
1922 if (mtk_dp->plugged_cb && mtk_dp->codec_dev) in mtk_dp_update_plugged_status()
1923 mtk_dp->plugged_cb(mtk_dp->codec_dev, in mtk_dp_update_plugged_status()
1924 mtk_dp->enabled & in mtk_dp_update_plugged_status()
1925 mtk_dp->info.audio_cur_cfg.detect_monitor); in mtk_dp_update_plugged_status()
1926 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_update_plugged_status()
1933 bool enabled = mtk_dp->enabled; in mtk_dp_bdg_detect()
1936 if (!mtk_dp->train_info.cable_plugged_in) in mtk_dp_bdg_detect()
1946 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_bdg_detect()
1956 drm_dp_dpcd_readb(&mtk_dp->aux, DP_SINK_COUNT, &sink_count); in mtk_dp_bdg_detect()
1962 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_bdg_detect()
1978 bool enabled = mtk_dp->enabled; in mtk_dp_get_edid()
1980 struct mtk_dp_audio_cfg *audio_caps = &mtk_dp->info.audio_cur_cfg; in mtk_dp_get_edid()
1992 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_get_edid()
1996 new_edid = drm_get_edid(connector, &mtk_dp->aux.ddc); in mtk_dp_get_edid()
2003 drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n"); in mtk_dp_get_edid()
2008 audio_caps->sad_count = drm_edid_to_sad(new_edid, &sads); in mtk_dp_get_edid()
2009 audio_caps->detect_monitor = drm_detect_monitor_audio(new_edid); in mtk_dp_get_edid()
2014 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_get_edid()
2039 if (!mtk_dp->train_info.cable_plugged_in) { in mtk_dp_aux_transfer()
2040 ret = -EAGAIN; in mtk_dp_aux_transfer()
2044 switch (msg->request) { in mtk_dp_aux_transfer()
2050 request = msg->request & ~DP_AUX_I2C_WRITE_STATUS_UPDATE; in mtk_dp_aux_transfer()
2056 request = msg->request; in mtk_dp_aux_transfer()
2060 drm_err(mtk_aux->drm_dev, "invalid aux cmd = %d\n", in mtk_dp_aux_transfer()
2061 msg->request); in mtk_dp_aux_transfer()
2062 ret = -EINVAL; in mtk_dp_aux_transfer()
2068 msg->size - accessed_bytes); in mtk_dp_aux_transfer()
2071 msg->address + accessed_bytes, in mtk_dp_aux_transfer()
2072 msg->buffer + accessed_bytes, in mtk_dp_aux_transfer()
2076 drm_info(mtk_dp->drm_dev, in mtk_dp_aux_transfer()
2081 } while (accessed_bytes < msg->size); in mtk_dp_aux_transfer()
2083 msg->reply = DP_AUX_NATIVE_REPLY_ACK | DP_AUX_I2C_REPLY_ACK; in mtk_dp_aux_transfer()
2084 return msg->size; in mtk_dp_aux_transfer()
2086 msg->reply = DP_AUX_NATIVE_REPLY_NACK | DP_AUX_I2C_REPLY_NACK; in mtk_dp_aux_transfer()
2094 ret = phy_init(mtk_dp->phy); in mtk_dp_poweron()
2096 dev_err(mtk_dp->dev, "Failed to initialize phy: %d\n", ret); in mtk_dp_poweron()
2109 phy_exit(mtk_dp->phy); in mtk_dp_poweroff()
2119 dev_err(mtk_dp->dev, "Driver does not provide a connector!"); in mtk_dp_bridge_attach()
2120 return -EINVAL; in mtk_dp_bridge_attach()
2123 mtk_dp->aux.drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2124 ret = drm_dp_aux_register(&mtk_dp->aux); in mtk_dp_bridge_attach()
2126 dev_err(mtk_dp->dev, in mtk_dp_bridge_attach()
2135 if (mtk_dp->next_bridge) { in mtk_dp_bridge_attach()
2136 ret = drm_bridge_attach(bridge->encoder, mtk_dp->next_bridge, in mtk_dp_bridge_attach()
2137 &mtk_dp->bridge, flags); in mtk_dp_bridge_attach()
2139 drm_warn(mtk_dp->drm_dev, in mtk_dp_bridge_attach()
2145 mtk_dp->drm_dev = bridge->dev; in mtk_dp_bridge_attach()
2154 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_attach()
2163 mtk_dp->drm_dev = NULL; in mtk_dp_bridge_detach()
2165 drm_dp_aux_unregister(&mtk_dp->aux); in mtk_dp_bridge_detach()
2174 mtk_dp->conn = drm_atomic_get_new_connector_for_encoder(old_state->base.state, in mtk_dp_bridge_atomic_enable()
2175 bridge->encoder); in mtk_dp_bridge_atomic_enable()
2176 if (!mtk_dp->conn) { in mtk_dp_bridge_atomic_enable()
2177 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_enable()
2187 if (mtk_dp->train_info.cable_plugged_in) { in mtk_dp_bridge_atomic_enable()
2188 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); in mtk_dp_bridge_atomic_enable()
2195 drm_err(mtk_dp->drm_dev, "Training failed, %d\n", ret); in mtk_dp_bridge_atomic_enable()
2205 mtk_dp->audio_enable = in mtk_dp_bridge_atomic_enable()
2207 &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2208 if (mtk_dp->audio_enable) { in mtk_dp_bridge_atomic_enable()
2209 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_bridge_atomic_enable()
2212 memset(&mtk_dp->info.audio_cur_cfg, 0, in mtk_dp_bridge_atomic_enable()
2213 sizeof(mtk_dp->info.audio_cur_cfg)); in mtk_dp_bridge_atomic_enable()
2216 mtk_dp->enabled = true; in mtk_dp_bridge_atomic_enable()
2231 mtk_dp->enabled = false; in mtk_dp_bridge_atomic_disable()
2236 if (mtk_dp->train_info.cable_plugged_in) { in mtk_dp_bridge_atomic_disable()
2237 drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); in mtk_dp_bridge_atomic_disable()
2256 u32 bpp = info->color_formats & DRM_COLOR_FORMAT_YCBCR422 ? 16 : 24; in mtk_dp_bridge_mode_valid()
2257 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_mode_valid()
2258 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_mode_valid()
2259 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_mode_valid()
2260 mtk_dp->max_lanes); in mtk_dp_bridge_mode_valid()
2262 if (rate < mode->clock * bpp / 8) in mtk_dp_bridge_mode_valid()
2300 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2302 &conn_state->connector->display_info; in mtk_dp_bridge_atomic_get_input_bus_fmts()
2303 u32 rate = min_t(u32, drm_dp_max_link_rate(mtk_dp->rx_cap) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2304 drm_dp_max_lane_count(mtk_dp->rx_cap), in mtk_dp_bridge_atomic_get_input_bus_fmts()
2305 drm_dp_bw_code_to_link_rate(mtk_dp->max_linkrate) * in mtk_dp_bridge_atomic_get_input_bus_fmts()
2306 mtk_dp->max_lanes); in mtk_dp_bridge_atomic_get_input_bus_fmts()
2315 if ((rate < (mode->clock * 24 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2316 (rate > (mode->clock * 16 / 8)) && in mtk_dp_bridge_atomic_get_input_bus_fmts()
2317 (display_info->color_formats & DRM_COLOR_FORMAT_YCBCR422)) { in mtk_dp_bridge_atomic_get_input_bus_fmts()
2343 struct drm_crtc *crtc = conn_state->crtc; in mtk_dp_bridge_atomic_check()
2346 input_bus_format = bridge_state->input_bus_cfg.format; in mtk_dp_bridge_atomic_check()
2348 dev_dbg(mtk_dp->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dp_bridge_atomic_check()
2349 bridge_state->input_bus_cfg.format, in mtk_dp_bridge_atomic_check()
2350 bridge_state->output_bus_cfg.format); in mtk_dp_bridge_atomic_check()
2353 mtk_dp->info.format = DP_PIXELFORMAT_YUV422; in mtk_dp_bridge_atomic_check()
2355 mtk_dp->info.format = DP_PIXELFORMAT_RGB; in mtk_dp_bridge_atomic_check()
2358 drm_err(mtk_dp->drm_dev, in mtk_dp_bridge_atomic_check()
2360 return -EINVAL; in mtk_dp_bridge_atomic_check()
2363 drm_display_mode_to_videomode(&crtc_state->adjusted_mode, &mtk_dp->info.vm); in mtk_dp_bridge_atomic_check()
2388 mtk_dp->need_debounce = true; in mtk_dp_debounce_timer()
2400 if (!mtk_dp->enabled) { in mtk_dp_audio_hw_params()
2401 dev_err(mtk_dp->dev, "%s, DP is not ready!\n", __func__); in mtk_dp_audio_hw_params()
2402 return -ENODEV; in mtk_dp_audio_hw_params()
2405 mtk_dp->info.audio_cur_cfg.channels = params->cea.channels; in mtk_dp_audio_hw_params()
2406 mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate; in mtk_dp_audio_hw_params()
2408 mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg); in mtk_dp_audio_hw_params()
2434 if (mtk_dp->enabled) in mtk_dp_audio_get_eld()
2435 memcpy(buf, mtk_dp->conn->eld, len); in mtk_dp_audio_get_eld()
2448 mutex_lock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2449 mtk_dp->plugged_cb = fn; in mtk_dp_audio_hook_plugged_cb()
2450 mtk_dp->codec_dev = codec_dev; in mtk_dp_audio_hook_plugged_cb()
2451 mutex_unlock(&mtk_dp->update_plugged_status_lock); in mtk_dp_audio_hook_plugged_cb()
2477 mtk_dp->audio_pdev = platform_device_register_data(dev, in mtk_dp_register_audio_driver()
2482 return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); in mtk_dp_register_audio_driver()
2488 struct device *dev = &pdev->dev; in mtk_dp_probe()
2493 return -ENOMEM; in mtk_dp_probe()
2495 mtk_dp->dev = dev; in mtk_dp_probe()
2496 mtk_dp->data = (struct mtk_dp_data *)of_device_get_match_data(dev); in mtk_dp_probe()
2503 mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); in mtk_dp_probe()
2504 if (IS_ERR(mtk_dp->next_bridge) && in mtk_dp_probe()
2505 PTR_ERR(mtk_dp->next_bridge) == -ENODEV) in mtk_dp_probe()
2506 mtk_dp->next_bridge = NULL; in mtk_dp_probe()
2507 else if (IS_ERR(mtk_dp->next_bridge)) in mtk_dp_probe()
2508 return dev_err_probe(dev, PTR_ERR(mtk_dp->next_bridge), in mtk_dp_probe()
2515 drm_dp_aux_init(&mtk_dp->aux); in mtk_dp_probe()
2516 mtk_dp->aux.name = "aux_mtk_dp"; in mtk_dp_probe()
2517 mtk_dp->aux.transfer = mtk_dp_aux_transfer; in mtk_dp_probe()
2519 spin_lock_init(&mtk_dp->irq_thread_lock); in mtk_dp_probe()
2529 mutex_init(&mtk_dp->update_plugged_status_lock); in mtk_dp_probe()
2533 if (mtk_dp->data->audio_supported) { in mtk_dp_probe()
2542 mtk_dp->phy_dev = platform_device_register_data(dev, "mediatek-dp-phy", in mtk_dp_probe()
2544 &mtk_dp->regs, in mtk_dp_probe()
2546 if (IS_ERR(mtk_dp->phy_dev)) in mtk_dp_probe()
2547 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy_dev), in mtk_dp_probe()
2548 "Failed to create device mediatek-dp-phy\n"); in mtk_dp_probe()
2552 mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp"); in mtk_dp_probe()
2554 if (IS_ERR(mtk_dp->phy)) { in mtk_dp_probe()
2555 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_probe()
2556 return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), in mtk_dp_probe()
2560 mtk_dp->bridge.funcs = &mtk_dp_bridge_funcs; in mtk_dp_probe()
2561 mtk_dp->bridge.of_node = dev->of_node; in mtk_dp_probe()
2563 mtk_dp->bridge.ops = in mtk_dp_probe()
2565 mtk_dp->bridge.type = mtk_dp->data->bridge_type; in mtk_dp_probe()
2567 drm_bridge_add(&mtk_dp->bridge); in mtk_dp_probe()
2569 mtk_dp->need_debounce = true; in mtk_dp_probe()
2570 timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); in mtk_dp_probe()
2582 pm_runtime_put(&pdev->dev); in mtk_dp_remove()
2583 pm_runtime_disable(&pdev->dev); in mtk_dp_remove()
2584 del_timer_sync(&mtk_dp->debounce_timer); in mtk_dp_remove()
2585 drm_bridge_remove(&mtk_dp->bridge); in mtk_dp_remove()
2586 platform_device_unregister(mtk_dp->phy_dev); in mtk_dp_remove()
2587 if (mtk_dp->audio_pdev) in mtk_dp_remove()
2588 platform_device_unregister(mtk_dp->audio_pdev); in mtk_dp_remove()
2636 .compatible = "mediatek,mt8195-edp-tx",
2640 .compatible = "mediatek,mt8195-dp-tx",
2651 .name = "mediatek-drm-dp",
2660 MODULE_AUTHOR("Markus Schneider-Pargmann <msp@baylibre.com>");
2661 MODULE_AUTHOR("Bo-Chen Chen <rex-bc.chen@mediatek.com>");