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
7 Get the link rate and lanes from sink device.
8 Remove user specific set by device tree.
10 Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
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(-)
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)
25 - struct drm_dp_link link;
26 u32 lane_mapping = mhdp->lane_mapping;
28 + struct drm_dp_link *link = &mhdp->dp.link;
32 memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
34 @@ -125,8 +125,6 @@ static void cdns_dp_mode_set(struct cdns
36 cdns_mhdp_plat_call(mhdp, pclk_rate);
38 - cdns_mhdp_plat_call(mhdp, phy_set);
40 ret = drm_dp_downstream_id(&mhdp->dp.aux, linkid);
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
47 - ret = drm_dp_link_probe(&mhdp->dp.aux, &link);
48 + ret = drm_dp_link_probe(&mhdp->dp.aux, link);
50 DRM_INFO("Failed to probe DP link: %d\n", ret);
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);
62 + /* check the max link rate */
63 + if (link->rate > CDNS_DP_MAX_LINK_RATE)
64 + link->rate = CDNS_DP_MAX_LINK_RATE;
66 - drm_dp_link_power_up(&mhdp->dp.aux, &mhdp->dp.link);
67 + drm_dp_link_power_up(&mhdp->dp.aux, link);
69 DRM_INFO("Failed to power DP link: %d\n", ret);
73 - /* always use the number of lanes from the display*/
74 - mhdp->dp.link.num_lanes = link.num_lanes;
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);
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);
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);
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);
98 DRM_DEV_ERROR(mhdp->dev, "Failed to set host cap %d\n", ret);
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");
103 dev_info(mhdp->dev, "lane-mapping 0x%02x\n", mhdp->lane_mapping);
105 - ret = of_property_read_u32(of_node, "link-rate", &mhdp->dp.link_rate);
107 - mhdp->dp.link_rate = 162000 ;
108 - dev_warn(mhdp->dev, "Failed to get link-rate, use default 1620MHz\n");
110 - dev_info(mhdp->dev, "link-rate %d\n", mhdp->dp.link_rate);
112 - ret = of_property_read_u32(of_node, "num-lanes", &mhdp->dp.num_lanes);
114 - mhdp->dp.num_lanes = 4;
115 - dev_warn(mhdp->dev, "Failed to get num_lanes - using default\n");
117 - dev_info(mhdp->dev, "dp_num_lanes 0x%02x\n", mhdp->dp.num_lanes);
119 - mhdp->dp.link.num_lanes = mhdp->dp.num_lanes;
120 - mhdp->dp.link.rate= mhdp->dp.link_rate;
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:
128 EXPORT_SYMBOL(cdns_mhdp_set_firmware_active);
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)
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 @@ -305,12 +305,10 @@ static int cdn_dp_connector_mode_valid(s
146 requested = mode->clock * bpc * 3 / 1000;
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);
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;
158 actual = rate * lanes / 100;
160 @@ -365,21 +363,25 @@ static int cdn_dp_firmware_init(struct c
162 static int cdn_dp_get_sink_capability(struct cdn_dp_device *dp)
164 + struct cdns_mhdp_device *mhdp = &dp->mhdp;
165 + struct drm_dp_link *link = &mhdp->dp.link;
168 if (!cdn_dp_check_sink_connection(dp))
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);
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);
180 + if (link->rate > CDNS_DP_MAX_LINK_RATE)
181 + link->rate = CDNS_DP_MAX_LINK_RATE;
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);
191 @@ -421,7 +423,8 @@ static int cdn_dp_enable_phy(struct cdn_
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);
199 DRM_DEV_ERROR(dev, "set host capabilities failed: %d\n",
201 @@ -576,9 +579,9 @@ static bool cdn_dp_check_link_status(str
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;
208 - if (!port || !dp->mhdp.dp.link.rate || !dp->mhdp.dp.link.num_lanes)
209 + if (!port || !dp->mhdp.dp.link.rate || !sink_lanes)
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 {
219 - u8 dpcd[DP_RECEIVER_CAP_SIZE];
222 #endif /* _CDN_DP_CORE_H */
223 --- a/include/drm/bridge/cdns-mhdp-common.h
224 +++ b/include/drm/bridge/cdns-mhdp-common.h
226 #define HDCP_TX_IS_RECEIVER_ID_VALID_EVENT BIT(7)
229 -#define CDNS_DP_MAX_LINK_RATE DP_LINK_BW_5_4
230 +#define CDNS_DP_MAX_LINK_RATE 540000
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;
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);