| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 79d32025a54899fe7d82c88906c1e3ad911c498d Mon Sep 17 00:00:00 2001 |
| 2 | From: Sandor Yu <Sandor.yu@nxp.com> |
| 3 | Date: Thu, 26 Sep 2019 15:46:43 +0800 |
| 4 | Subject: [PATCH] drm: bridge: cdns dp: Remove link rate/lanes set by device |
| 5 | tree |
| 6 | |
| 7 | Get the link rate and lanes from sink device. |
| 8 | Remove user specific set by device tree. |
| 9 | |
| 10 | Signed-off-by: Sandor Yu <Sandor.yu@nxp.com> |
| 11 | --- |
| 12 | drivers/gpu/drm/bridge/cadence/cdns-dp-core.c | 56 ++++++----------------- |
| 13 | drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c | 6 +-- |
| 14 | drivers/gpu/drm/rockchip/cdn-dp-core.c | 27 ++++++----- |
| 15 | drivers/gpu/drm/rockchip/cdn-dp-core.h | 1 - |
| 16 | include/drm/bridge/cdns-mhdp-common.h | 6 +-- |
| 17 | 5 files changed, 35 insertions(+), 61 deletions(-) |
| 18 | |
| 19 | --- a/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c |
| 20 | +++ b/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c |
| 21 | @@ -111,10 +111,10 @@ static void dp_pixel_clk_reset(struct cd |
| 22 | static void cdns_dp_mode_set(struct cdns_mhdp_device *mhdp, |
| 23 | const struct drm_display_mode *mode) |
| 24 | { |
| 25 | - struct drm_dp_link link; |
| 26 | u32 lane_mapping = mhdp->lane_mapping; |
| 27 | - int ret; |
| 28 | + struct drm_dp_link *link = &mhdp->dp.link; |
| 29 | char linkid[6]; |
| 30 | + int ret; |
| 31 | |
| 32 | memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode)); |
| 33 | |
| 34 | @@ -125,8 +125,6 @@ static void cdns_dp_mode_set(struct cdns |
| 35 | |
| 36 | cdns_mhdp_plat_call(mhdp, pclk_rate); |
| 37 | |
| 38 | - cdns_mhdp_plat_call(mhdp, phy_set); |
| 39 | - |
| 40 | ret = drm_dp_downstream_id(&mhdp->dp.aux, linkid); |
| 41 | if (ret < 0) { |
| 42 | DRM_INFO("Failed to Get DP link ID: %d\n", ret); |
| 43 | @@ -137,35 +135,28 @@ static void cdns_dp_mode_set(struct cdns |
| 44 | linkid[5]); |
| 45 | |
| 46 | /* Check dp link */ |
| 47 | - ret = drm_dp_link_probe(&mhdp->dp.aux, &link); |
| 48 | + ret = drm_dp_link_probe(&mhdp->dp.aux, link); |
| 49 | if (ret < 0) { |
| 50 | DRM_INFO("Failed to probe DP link: %d\n", ret); |
| 51 | return; |
| 52 | } |
| 53 | - DRM_INFO("DP revision: 0x%x\n", link.revision); |
| 54 | - DRM_INFO("DP rate: %d Mbps\n", link.rate); |
| 55 | - DRM_INFO("DP number of lanes: %d\n", link.num_lanes); |
| 56 | - DRM_INFO("DP capabilities: 0x%lx\n", link.capabilities); |
| 57 | + DRM_INFO("DP revision: 0x%x\n", link->revision); |
| 58 | + DRM_INFO("DP rate: %d Mbps\n", link->rate); |
| 59 | + DRM_INFO("DP number of lanes: %d\n", link->num_lanes); |
| 60 | + DRM_INFO("DP capabilities: 0x%lx\n", link->capabilities); |
| 61 | + |
| 62 | + /* check the max link rate */ |
| 63 | + if (link->rate > CDNS_DP_MAX_LINK_RATE) |
| 64 | + link->rate = CDNS_DP_MAX_LINK_RATE; |
| 65 | |
| 66 | - drm_dp_link_power_up(&mhdp->dp.aux, &mhdp->dp.link); |
| 67 | + drm_dp_link_power_up(&mhdp->dp.aux, link); |
| 68 | if (ret < 0) { |
| 69 | DRM_INFO("Failed to power DP link: %d\n", ret); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | - /* always use the number of lanes from the display*/ |
| 74 | - mhdp->dp.link.num_lanes = link.num_lanes; |
| 75 | - |
| 76 | - /* Use the lower link rate */ |
| 77 | - if (mhdp->dp.link_rate != 0) { |
| 78 | - mhdp->dp.link.rate = min(mhdp->dp.link_rate, (u32)link.rate); |
| 79 | - DRM_DEBUG("DP actual link rate: 0x%x\n", link.rate); |
| 80 | - } |
| 81 | - |
| 82 | - /* initialize phy if lanes or link rate differnt */ |
| 83 | - if (mhdp->dp.link.num_lanes != mhdp->dp.num_lanes || |
| 84 | - mhdp->dp.link.rate != mhdp->dp.link_rate) |
| 85 | - cdns_mhdp_plat_call(mhdp, phy_set); |
| 86 | + /* Initialize link rate/num_lanes as panel max link rate/max_num_lanes */ |
| 87 | + cdns_mhdp_plat_call(mhdp, phy_set); |
| 88 | |
| 89 | /* Video off */ |
| 90 | ret = cdns_mhdp_set_video_status(mhdp, CONTROL_VIDEO_IDLE); |
| 91 | @@ -178,7 +169,7 @@ static void cdns_dp_mode_set(struct cdns |
| 92 | cdns_mhdp_reg_write(mhdp, LANES_CONFIG, 0x00400000 | lane_mapping); |
| 93 | |
| 94 | /* Set DP host capability */ |
| 95 | - ret = cdns_mhdp_set_host_cap(mhdp, mhdp->dp.link.num_lanes, false); |
| 96 | + ret = cdns_mhdp_set_host_cap(mhdp, false); |
| 97 | if (ret) { |
| 98 | DRM_DEV_ERROR(mhdp->dev, "Failed to set host cap %d\n", ret); |
| 99 | return; |
| 100 | @@ -412,23 +403,6 @@ static void cdns_dp_parse_dt(struct cdns |
| 101 | dev_warn(mhdp->dev, "Failed to get lane_mapping - using default 0xc6\n"); |
| 102 | } |
| 103 | dev_info(mhdp->dev, "lane-mapping 0x%02x\n", mhdp->lane_mapping); |
| 104 | - |
| 105 | - ret = of_property_read_u32(of_node, "link-rate", &mhdp->dp.link_rate); |
| 106 | - if (ret) { |
| 107 | - mhdp->dp.link_rate = 162000 ; |
| 108 | - dev_warn(mhdp->dev, "Failed to get link-rate, use default 1620MHz\n"); |
| 109 | - } |
| 110 | - dev_info(mhdp->dev, "link-rate %d\n", mhdp->dp.link_rate); |
| 111 | - |
| 112 | - ret = of_property_read_u32(of_node, "num-lanes", &mhdp->dp.num_lanes); |
| 113 | - if (ret) { |
| 114 | - mhdp->dp.num_lanes = 4; |
| 115 | - dev_warn(mhdp->dev, "Failed to get num_lanes - using default\n"); |
| 116 | - } |
| 117 | - dev_info(mhdp->dev, "dp_num_lanes 0x%02x\n", mhdp->dp.num_lanes); |
| 118 | - |
| 119 | - mhdp->dp.link.num_lanes = mhdp->dp.num_lanes; |
| 120 | - mhdp->dp.link.rate= mhdp->dp.link_rate; |
| 121 | } |
| 122 | |
| 123 | static int __cdns_dp_probe(struct platform_device *pdev, |
| 124 | --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c |
| 125 | +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c |
| 126 | @@ -494,13 +494,13 @@ err_set_firmware_active: |
| 127 | } |
| 128 | EXPORT_SYMBOL(cdns_mhdp_set_firmware_active); |
| 129 | |
| 130 | -int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, u8 lanes, bool flip) |
| 131 | +int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, bool flip) |
| 132 | { |
| 133 | u8 msg[8]; |
| 134 | int ret; |
| 135 | |
| 136 | - msg[0] = CDNS_DP_MAX_LINK_RATE; |
| 137 | - msg[1] = lanes | SCRAMBLER_EN; |
| 138 | + msg[0] = drm_dp_link_rate_to_bw_code(mhdp->dp.link.rate); |
| 139 | + msg[1] = mhdp->dp.link.num_lanes | SCRAMBLER_EN; |
| 140 | msg[2] = VOLTAGE_LEVEL_2; |
| 141 | msg[3] = PRE_EMPHASIS_LEVEL_3; |
| 142 | msg[4] = PTS1 | PTS2 | PTS3 | PTS4; |
| 143 | --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c |
| 144 | +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c |
| 145 | @@ -307,12 +307,10 @@ cdn_dp_connector_mode_valid(struct drm_c |
| 146 | requested = mode->clock * bpc * 3 / 1000; |
| 147 | |
| 148 | source_max = dp->lanes; |
| 149 | - sink_max = drm_dp_max_lane_count(dp->dpcd); |
| 150 | + sink_max = dp->mhdp.dp.link.num_lanes; |
| 151 | lanes = min(source_max, sink_max); |
| 152 | |
| 153 | - source_max = drm_dp_bw_code_to_link_rate(CDNS_DP_MAX_LINK_RATE); |
| 154 | - sink_max = drm_dp_max_link_rate(dp->dpcd); |
| 155 | - rate = min(source_max, sink_max); |
| 156 | + rate = dp->mhdp.dp.link.rate; |
| 157 | |
| 158 | actual = rate * lanes / 100; |
| 159 | |
| 160 | @@ -367,21 +365,25 @@ static int cdn_dp_firmware_init(struct c |
| 161 | |
| 162 | static int cdn_dp_get_sink_capability(struct cdn_dp_device *dp) |
| 163 | { |
| 164 | + struct cdns_mhdp_device *mhdp = &dp->mhdp; |
| 165 | + struct drm_dp_link *link = &mhdp->dp.link; |
| 166 | int ret; |
| 167 | |
| 168 | if (!cdn_dp_check_sink_connection(dp)) |
| 169 | return -ENODEV; |
| 170 | |
| 171 | - ret = cdns_mhdp_dpcd_read(&dp->mhdp, DP_DPCD_REV, dp->dpcd, |
| 172 | - DP_RECEIVER_CAP_SIZE); |
| 173 | + ret = drm_dp_link_probe(&mhdp->dp.aux, link); |
| 174 | if (ret) { |
| 175 | - DRM_DEV_ERROR(dp->mhdp.dev, "Failed to get caps %d\n", ret); |
| 176 | + DRM_DEV_ERROR(mhdp->dev, "Failed to get caps %d\n", ret); |
| 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | + if (link->rate > CDNS_DP_MAX_LINK_RATE) |
| 181 | + link->rate = CDNS_DP_MAX_LINK_RATE; |
| 182 | + |
| 183 | kfree(dp->edid); |
| 184 | - dp->edid = drm_do_get_edid(&dp->mhdp.connector.base, |
| 185 | - cdns_mhdp_get_edid_block, &dp->mhdp); |
| 186 | + dp->edid = drm_do_get_edid(&mhdp->connector.base, |
| 187 | + cdns_mhdp_get_edid_block, mhdp); |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | @@ -423,7 +425,8 @@ static int cdn_dp_enable_phy(struct cdn_ |
| 192 | } |
| 193 | |
| 194 | port->lanes = cdn_dp_get_port_lanes(port); |
| 195 | - ret = cdns_mhdp_set_host_cap(&dp->mhdp, port->lanes, property.intval); |
| 196 | + dp->mhdp.dp.link.num_lanes = port->lanes; |
| 197 | + ret = cdns_mhdp_set_host_cap(&dp->mhdp, property.intval); |
| 198 | if (ret) { |
| 199 | DRM_DEV_ERROR(dev, "set host capabilities failed: %d\n", |
| 200 | ret); |
| 201 | @@ -578,9 +581,9 @@ static bool cdn_dp_check_link_status(str |
| 202 | { |
| 203 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 204 | struct cdn_dp_port *port = cdn_dp_connected_port(dp); |
| 205 | - u8 sink_lanes = drm_dp_max_lane_count(dp->dpcd); |
| 206 | + u8 sink_lanes = dp->mhdp.dp.link.num_lanes; |
| 207 | |
| 208 | - if (!port || !dp->mhdp.dp.link.rate || !dp->mhdp.dp.link.num_lanes) |
| 209 | + if (!port || !dp->mhdp.dp.link.rate || !sink_lanes) |
| 210 | return false; |
| 211 | |
| 212 | if (cdns_mhdp_dpcd_read(&dp->mhdp, DP_LANE0_1_STATUS, link_status, |
| 213 | --- a/drivers/gpu/drm/rockchip/cdn-dp-core.h |
| 214 | +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.h |
| 215 | @@ -61,7 +61,6 @@ struct cdn_dp_device { |
| 216 | u8 lanes; |
| 217 | int active_port; |
| 218 | |
| 219 | - u8 dpcd[DP_RECEIVER_CAP_SIZE]; |
| 220 | bool sink_has_audio; |
| 221 | }; |
| 222 | #endif /* _CDN_DP_CORE_H */ |
| 223 | --- a/include/drm/bridge/cdns-mhdp-common.h |
| 224 | +++ b/include/drm/bridge/cdns-mhdp-common.h |
| 225 | @@ -436,7 +436,7 @@ |
| 226 | #define HDCP_TX_IS_RECEIVER_ID_VALID_EVENT BIT(7) |
| 227 | |
| 228 | #define TU_SIZE 30 |
| 229 | -#define CDNS_DP_MAX_LINK_RATE DP_LINK_BW_5_4 |
| 230 | +#define CDNS_DP_MAX_LINK_RATE 540000 |
| 231 | |
| 232 | #define F_HDMI_ENCODING(x) (((x) & ((1 << 2) - 1)) << 16) |
| 233 | #define F_VIF_DATA_WIDTH(x) (((x) & ((1 << 2) - 1)) << 2) |
| 234 | @@ -697,8 +697,6 @@ struct cdns_mhdp_device { |
| 235 | struct cdns_mhdp_mst_cbs cbs; |
| 236 | bool is_mst; |
| 237 | bool can_mst; |
| 238 | - u32 link_rate; |
| 239 | - u32 num_lanes; |
| 240 | } dp; |
| 241 | struct _hdmi_data { |
| 242 | #ifdef CONFIG_DRM_CDNS_HDMI_CEC |
| 243 | @@ -720,7 +718,7 @@ u32 cdns_mhdp_get_fw_clk(struct cdns_mhd |
| 244 | int cdns_mhdp_load_firmware(struct cdns_mhdp_device *mhdp, const u32 *i_mem, |
| 245 | u32 i_size, const u32 *d_mem, u32 d_size); |
| 246 | int cdns_mhdp_set_firmware_active(struct cdns_mhdp_device *mhdp, bool enable); |
| 247 | -int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, u8 lanes, bool flip); |
| 248 | +int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, bool flip); |
| 249 | int cdns_mhdp_event_config(struct cdns_mhdp_device *mhdp); |
| 250 | u32 cdns_mhdp_get_event(struct cdns_mhdp_device *mhdp); |
| 251 | int cdns_mhdp_get_hpd_status(struct cdns_mhdp_device *mhdp); |