aff53595b0ba523415d699fb38bd9995fb783f71
[openwrt/staging/hauke.git] /
1 From 2a77bbf7f6494d4d618fc6ff70b1a21f04cb8a22 Mon Sep 17 00:00:00 2001
2 From: Sandor Yu <Sandor.yu@nxp.com>
3 Date: Wed, 10 Jul 2019 10:50:25 +0800
4 Subject: [PATCH] drm/rockchip: prepare common code for cdns and rk dpi/dp
5 driver
6
7 - Extracted common fields from cdn_dp_device to a new cdns_mhdp_device
8 structure which will be used by two separate drivers later on.
9 - Moved some datatypes (audio_format, audio_info,
10 vic_pxl_encoding_format, video_info) from cdn-dp-core.c to cdn-dp-reg.h.
11 - Changed prefixes from cdn_dp to cdns_mhdp cdn -> cdns to match the other Cadence's drivers
12 dp -> mhdp to distinguish it from a "just a DP" as the IP underneath this registers map can be a HDMI (which is
13 internally different, but the interface for commands, events is pretty much the same).
14 - Modified cdn-dp-core.c to use the new driver structure and new function names.
15
16 Signed-off-by: Damian Kos<dkos@cadence.com>
17 Reviewed-by: Andrzej Hajda<a.hajda@samsung.com>
18 Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
19 ---
20 drivers/gpu/drm/rockchip/cdn-dp-core.c | 220 +++++++++--------
21 drivers/gpu/drm/rockchip/cdn-dp-core.h | 40 +---
22 drivers/gpu/drm/rockchip/cdn-dp-reg.c | 415 +++++++++++++++++----------------
23 drivers/gpu/drm/rockchip/cdn-dp-reg.h | 114 +++++++--
24 4 files changed, 423 insertions(+), 366 deletions(-)
25
26 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c
27 +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c
28 @@ -22,11 +22,10 @@
29 #include <drm/drm_probe_helper.h>
30
31 #include "cdn-dp-core.h"
32 -#include "cdn-dp-reg.h"
33 #include "rockchip_drm_vop.h"
34
35 #define connector_to_dp(c) \
36 - container_of(c, struct cdn_dp_device, connector)
37 + container_of(c, struct cdn_dp_device, mhdp.connector)
38
39 #define encoder_to_dp(c) \
40 container_of(c, struct cdn_dp_device, encoder)
41 @@ -61,17 +60,18 @@ MODULE_DEVICE_TABLE(of, cdn_dp_dt_ids);
42 static int cdn_dp_grf_write(struct cdn_dp_device *dp,
43 unsigned int reg, unsigned int val)
44 {
45 + struct device *dev = dp->mhdp.dev;
46 int ret;
47
48 ret = clk_prepare_enable(dp->grf_clk);
49 if (ret) {
50 - DRM_DEV_ERROR(dp->dev, "Failed to prepare_enable grf clock\n");
51 + DRM_DEV_ERROR(dev, "Failed to prepare_enable grf clock\n");
52 return ret;
53 }
54
55 ret = regmap_write(dp->grf, reg, val);
56 if (ret) {
57 - DRM_DEV_ERROR(dp->dev, "Could not write to GRF: %d\n", ret);
58 + DRM_DEV_ERROR(dev, "Could not write to GRF: %d\n", ret);
59 return ret;
60 }
61
62 @@ -82,24 +82,25 @@ static int cdn_dp_grf_write(struct cdn_d
63
64 static int cdn_dp_clk_enable(struct cdn_dp_device *dp)
65 {
66 + struct device *dev = dp->mhdp.dev;
67 int ret;
68 unsigned long rate;
69
70 ret = clk_prepare_enable(dp->pclk);
71 if (ret < 0) {
72 - DRM_DEV_ERROR(dp->dev, "cannot enable dp pclk %d\n", ret);
73 + DRM_DEV_ERROR(dev, "cannot enable dp pclk %d\n", ret);
74 goto err_pclk;
75 }
76
77 ret = clk_prepare_enable(dp->core_clk);
78 if (ret < 0) {
79 - DRM_DEV_ERROR(dp->dev, "cannot enable core_clk %d\n", ret);
80 + DRM_DEV_ERROR(dev, "cannot enable core_clk %d\n", ret);
81 goto err_core_clk;
82 }
83
84 - ret = pm_runtime_get_sync(dp->dev);
85 + ret = pm_runtime_get_sync(dev);
86 if (ret < 0) {
87 - DRM_DEV_ERROR(dp->dev, "cannot get pm runtime %d\n", ret);
88 + DRM_DEV_ERROR(dev, "cannot get pm runtime %d\n", ret);
89 goto err_pm_runtime_get;
90 }
91
92 @@ -112,18 +113,18 @@ static int cdn_dp_clk_enable(struct cdn_
93
94 rate = clk_get_rate(dp->core_clk);
95 if (!rate) {
96 - DRM_DEV_ERROR(dp->dev, "get clk rate failed\n");
97 + DRM_DEV_ERROR(dev, "get clk rate failed\n");
98 ret = -EINVAL;
99 goto err_set_rate;
100 }
101
102 - cdn_dp_set_fw_clk(dp, rate);
103 - cdn_dp_clock_reset(dp);
104 + cdns_mhdp_set_fw_clk(&dp->mhdp, rate);
105 + cdns_mhdp_clock_reset(&dp->mhdp);
106
107 return 0;
108
109 err_set_rate:
110 - pm_runtime_put(dp->dev);
111 + pm_runtime_put(dev);
112 err_pm_runtime_get:
113 clk_disable_unprepare(dp->core_clk);
114 err_core_clk:
115 @@ -134,7 +135,7 @@ err_pclk:
116
117 static void cdn_dp_clk_disable(struct cdn_dp_device *dp)
118 {
119 - pm_runtime_put_sync(dp->dev);
120 + pm_runtime_put_sync(dp->mhdp.dev);
121 clk_disable_unprepare(dp->pclk);
122 clk_disable_unprepare(dp->core_clk);
123 }
124 @@ -167,7 +168,7 @@ static int cdn_dp_get_sink_count(struct
125 u8 value;
126
127 *sink_count = 0;
128 - ret = cdn_dp_dpcd_read(dp, DP_SINK_COUNT, &value, 1);
129 + ret = cdns_mhdp_dpcd_read(&dp->mhdp, DP_SINK_COUNT, &value, 1);
130 if (ret)
131 return ret;
132
133 @@ -191,12 +192,13 @@ static struct cdn_dp_port *cdn_dp_connec
134
135 static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)
136 {
137 + struct device *dev = dp->mhdp.dev;
138 unsigned long timeout = jiffies + msecs_to_jiffies(CDN_DPCD_TIMEOUT_MS);
139 struct cdn_dp_port *port;
140 u8 sink_count = 0;
141
142 if (dp->active_port < 0 || dp->active_port >= dp->ports) {
143 - DRM_DEV_ERROR(dp->dev, "active_port is wrong!\n");
144 + DRM_DEV_ERROR(dev, "active_port is wrong!\n");
145 return false;
146 }
147
148 @@ -218,7 +220,7 @@ static bool cdn_dp_check_sink_connection
149 usleep_range(5000, 10000);
150 }
151
152 - DRM_DEV_ERROR(dp->dev, "Get sink capability timed out\n");
153 + DRM_DEV_ERROR(dev, "Get sink capability timed out\n");
154 return false;
155 }
156
157 @@ -260,7 +262,8 @@ static int cdn_dp_connector_get_modes(st
158 mutex_lock(&dp->lock);
159 edid = dp->edid;
160 if (edid) {
161 - DRM_DEV_DEBUG_KMS(dp->dev, "got edid: width[%d] x height[%d]\n",
162 + DRM_DEV_DEBUG_KMS(dp->mhdp.dev,
163 + "got edid: width[%d] x height[%d]\n",
164 edid->width_cm, edid->height_cm);
165
166 dp->sink_has_audio = drm_detect_monitor_audio(edid);
167 @@ -278,7 +281,8 @@ static int cdn_dp_connector_mode_valid(s
168 struct drm_display_mode *mode)
169 {
170 struct cdn_dp_device *dp = connector_to_dp(connector);
171 - struct drm_display_info *display_info = &dp->connector.display_info;
172 + struct drm_display_info *display_info =
173 + &dp->mhdp.connector.display_info;
174 u32 requested, actual, rate, sink_max, source_max = 0;
175 u8 lanes, bpc;
176
177 @@ -304,7 +308,7 @@ static int cdn_dp_connector_mode_valid(s
178 sink_max = drm_dp_max_lane_count(dp->dpcd);
179 lanes = min(source_max, sink_max);
180
181 - source_max = drm_dp_bw_code_to_link_rate(CDN_DP_MAX_LINK_RATE);
182 + source_max = drm_dp_bw_code_to_link_rate(CDNS_DP_MAX_LINK_RATE);
183 sink_max = drm_dp_max_link_rate(dp->dpcd);
184 rate = min(source_max, sink_max);
185
186 @@ -314,7 +318,7 @@ static int cdn_dp_connector_mode_valid(s
187 actual = actual * 8 / 10;
188
189 if (requested > actual) {
190 - DRM_DEV_DEBUG_KMS(dp->dev,
191 + DRM_DEV_DEBUG_KMS(dp->mhdp.dev,
192 "requested=%d, actual=%d, clock=%d\n",
193 requested, actual, mode->clock);
194 return MODE_CLOCK_HIGH;
195 @@ -334,28 +338,29 @@ static int cdn_dp_firmware_init(struct c
196 const u32 *iram_data, *dram_data;
197 const struct firmware *fw = dp->fw;
198 const struct cdn_firmware_header *hdr;
199 + struct device *dev = dp->mhdp.dev;
200
201 hdr = (struct cdn_firmware_header *)fw->data;
202 if (fw->size != le32_to_cpu(hdr->size_bytes)) {
203 - DRM_DEV_ERROR(dp->dev, "firmware is invalid\n");
204 + DRM_DEV_ERROR(dev, "firmware is invalid\n");
205 return -EINVAL;
206 }
207
208 iram_data = (const u32 *)(fw->data + hdr->header_size);
209 dram_data = (const u32 *)(fw->data + hdr->header_size + hdr->iram_size);
210
211 - ret = cdn_dp_load_firmware(dp, iram_data, hdr->iram_size,
212 - dram_data, hdr->dram_size);
213 + ret = cdns_mhdp_load_firmware(&dp->mhdp, iram_data, hdr->iram_size,
214 + dram_data, hdr->dram_size);
215 if (ret)
216 return ret;
217
218 - ret = cdn_dp_set_firmware_active(dp, true);
219 + ret = cdns_mhdp_set_firmware_active(&dp->mhdp, true);
220 if (ret) {
221 - DRM_DEV_ERROR(dp->dev, "active ucpu failed: %d\n", ret);
222 + DRM_DEV_ERROR(dev, "active ucpu failed: %d\n", ret);
223 return ret;
224 }
225
226 - return cdn_dp_event_config(dp);
227 + return cdns_mhdp_event_config(&dp->mhdp);
228 }
229
230 static int cdn_dp_get_sink_capability(struct cdn_dp_device *dp)
231 @@ -365,28 +370,29 @@ static int cdn_dp_get_sink_capability(st
232 if (!cdn_dp_check_sink_connection(dp))
233 return -ENODEV;
234
235 - ret = cdn_dp_dpcd_read(dp, DP_DPCD_REV, dp->dpcd,
236 - DP_RECEIVER_CAP_SIZE);
237 + ret = cdns_mhdp_dpcd_read(&dp->mhdp, DP_DPCD_REV, dp->dpcd,
238 + DP_RECEIVER_CAP_SIZE);
239 if (ret) {
240 - DRM_DEV_ERROR(dp->dev, "Failed to get caps %d\n", ret);
241 + DRM_DEV_ERROR(dp->mhdp.dev, "Failed to get caps %d\n", ret);
242 return ret;
243 }
244
245 kfree(dp->edid);
246 - dp->edid = drm_do_get_edid(&dp->connector,
247 - cdn_dp_get_edid_block, dp);
248 + dp->edid = drm_do_get_edid(&dp->mhdp.connector,
249 + cdns_mhdp_get_edid_block, &dp->mhdp);
250 return 0;
251 }
252
253 static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
254 {
255 + struct device *dev = dp->mhdp.dev;
256 union extcon_property_value property;
257 int ret;
258
259 if (!port->phy_enabled) {
260 ret = phy_power_on(port->phy);
261 if (ret) {
262 - DRM_DEV_ERROR(dp->dev, "phy power on failed: %d\n",
263 + DRM_DEV_ERROR(dev, "phy power on failed: %d\n",
264 ret);
265 goto err_phy;
266 }
267 @@ -396,28 +402,28 @@ static int cdn_dp_enable_phy(struct cdn_
268 ret = cdn_dp_grf_write(dp, GRF_SOC_CON26,
269 DPTX_HPD_SEL_MASK | DPTX_HPD_SEL);
270 if (ret) {
271 - DRM_DEV_ERROR(dp->dev, "Failed to write HPD_SEL %d\n", ret);
272 + DRM_DEV_ERROR(dev, "Failed to write HPD_SEL %d\n", ret);
273 goto err_power_on;
274 }
275
276 - ret = cdn_dp_get_hpd_status(dp);
277 + ret = cdns_mhdp_get_hpd_status(&dp->mhdp);
278 if (ret <= 0) {
279 if (!ret)
280 - DRM_DEV_ERROR(dp->dev, "hpd does not exist\n");
281 + DRM_DEV_ERROR(dev, "hpd does not exist\n");
282 goto err_power_on;
283 }
284
285 ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
286 EXTCON_PROP_USB_TYPEC_POLARITY, &property);
287 if (ret) {
288 - DRM_DEV_ERROR(dp->dev, "get property failed\n");
289 + DRM_DEV_ERROR(dev, "get property failed\n");
290 goto err_power_on;
291 }
292
293 port->lanes = cdn_dp_get_port_lanes(port);
294 - ret = cdn_dp_set_host_cap(dp, port->lanes, property.intval);
295 + ret = cdns_mhdp_set_host_cap(&dp->mhdp, port->lanes, property.intval);
296 if (ret) {
297 - DRM_DEV_ERROR(dp->dev, "set host capabilities failed: %d\n",
298 + DRM_DEV_ERROR(dev, "set host capabilities failed: %d\n",
299 ret);
300 goto err_power_on;
301 }
302 @@ -427,7 +433,7 @@ static int cdn_dp_enable_phy(struct cdn_
303
304 err_power_on:
305 if (phy_power_off(port->phy))
306 - DRM_DEV_ERROR(dp->dev, "phy power off failed: %d", ret);
307 + DRM_DEV_ERROR(dev, "phy power off failed: %d", ret);
308 else
309 port->phy_enabled = false;
310
311 @@ -445,7 +451,8 @@ static int cdn_dp_disable_phy(struct cdn
312 if (port->phy_enabled) {
313 ret = phy_power_off(port->phy);
314 if (ret) {
315 - DRM_DEV_ERROR(dp->dev, "phy power off failed: %d", ret);
316 + DRM_DEV_ERROR(dp->mhdp.dev,
317 + "phy power off failed: %d", ret);
318 return ret;
319 }
320 }
321 @@ -469,16 +476,16 @@ static int cdn_dp_disable(struct cdn_dp_
322 ret = cdn_dp_grf_write(dp, GRF_SOC_CON26,
323 DPTX_HPD_SEL_MASK | DPTX_HPD_DEL);
324 if (ret) {
325 - DRM_DEV_ERROR(dp->dev, "Failed to clear hpd sel %d\n",
326 + DRM_DEV_ERROR(dp->mhdp.dev, "Failed to clear hpd sel %d\n",
327 ret);
328 return ret;
329 }
330
331 - cdn_dp_set_firmware_active(dp, false);
332 + cdns_mhdp_set_firmware_active(&dp->mhdp, false);
333 cdn_dp_clk_disable(dp);
334 dp->active = false;
335 - dp->link.rate = 0;
336 - dp->link.num_lanes = 0;
337 + dp->mhdp.link.rate = 0;
338 + dp->mhdp.link.num_lanes = 0;
339 if (!dp->connected) {
340 kfree(dp->edid);
341 dp->edid = NULL;
342 @@ -491,11 +498,11 @@ static int cdn_dp_enable(struct cdn_dp_d
343 {
344 int ret, i, lanes;
345 struct cdn_dp_port *port;
346 + struct device *dev = dp->mhdp.dev;
347
348 port = cdn_dp_connected_port(dp);
349 if (!port) {
350 - DRM_DEV_ERROR(dp->dev,
351 - "Can't enable without connection\n");
352 + DRM_DEV_ERROR(dev, "Can't enable without connection\n");
353 return -ENODEV;
354 }
355
356 @@ -508,7 +515,7 @@ static int cdn_dp_enable(struct cdn_dp_d
357
358 ret = cdn_dp_firmware_init(dp);
359 if (ret) {
360 - DRM_DEV_ERROR(dp->dev, "firmware init failed: %d", ret);
361 + DRM_DEV_ERROR(dp->mhdp.dev, "firmware init failed: %d", ret);
362 goto err_clk_disable;
363 }
364
365 @@ -542,8 +549,9 @@ static void cdn_dp_encoder_mode_set(stru
366 struct drm_display_mode *adjusted)
367 {
368 struct cdn_dp_device *dp = encoder_to_dp(encoder);
369 - struct drm_display_info *display_info = &dp->connector.display_info;
370 - struct video_info *video = &dp->video_info;
371 + struct drm_display_info *display_info =
372 + &dp->mhdp.connector.display_info;
373 + struct video_info *video = &dp->mhdp.video_info;
374
375 switch (display_info->bpc) {
376 case 10:
377 @@ -561,7 +569,7 @@ static void cdn_dp_encoder_mode_set(stru
378 video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC);
379 video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC);
380
381 - memcpy(&dp->mode, adjusted, sizeof(*mode));
382 + memcpy(&dp->mhdp.mode, adjusted, sizeof(*mode));
383 }
384
385 static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)
386 @@ -570,11 +578,11 @@ static bool cdn_dp_check_link_status(str
387 struct cdn_dp_port *port = cdn_dp_connected_port(dp);
388 u8 sink_lanes = drm_dp_max_lane_count(dp->dpcd);
389
390 - if (!port || !dp->link.rate || !dp->link.num_lanes)
391 + if (!port || !dp->mhdp.link.rate || !dp->mhdp.link.num_lanes)
392 return false;
393
394 - if (cdn_dp_dpcd_read(dp, DP_LANE0_1_STATUS, link_status,
395 - DP_LINK_STATUS_SIZE)) {
396 + if (cdns_mhdp_dpcd_read(&dp->mhdp, DP_LANE0_1_STATUS, link_status,
397 + DP_LINK_STATUS_SIZE)) {
398 DRM_ERROR("Failed to get link status\n");
399 return false;
400 }
401 @@ -586,15 +594,16 @@ static bool cdn_dp_check_link_status(str
402 static void cdn_dp_encoder_enable(struct drm_encoder *encoder)
403 {
404 struct cdn_dp_device *dp = encoder_to_dp(encoder);
405 + struct device *dev = dp->mhdp.dev;
406 int ret, val;
407
408 - ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder);
409 + ret = drm_of_encoder_active_endpoint_id(dev->of_node, encoder);
410 if (ret < 0) {
411 - DRM_DEV_ERROR(dp->dev, "Could not get vop id, %d", ret);
412 + DRM_DEV_ERROR(dev, "Could not get vop id, %d", ret);
413 return;
414 }
415
416 - DRM_DEV_DEBUG_KMS(dp->dev, "vop %s output to cdn-dp\n",
417 + DRM_DEV_DEBUG_KMS(dev, "vop %s output to cdn-dp\n",
418 (ret) ? "LIT" : "BIG");
419 if (ret)
420 val = DP_SEL_VOP_LIT | (DP_SEL_VOP_LIT << 16);
421 @@ -609,33 +618,33 @@ static void cdn_dp_encoder_enable(struct
422
423 ret = cdn_dp_enable(dp);
424 if (ret) {
425 - DRM_DEV_ERROR(dp->dev, "Failed to enable encoder %d\n",
426 + DRM_DEV_ERROR(dev, "Failed to enable encoder %d\n",
427 ret);
428 goto out;
429 }
430 if (!cdn_dp_check_link_status(dp)) {
431 - ret = cdn_dp_train_link(dp);
432 + ret = cdns_mhdp_train_link(&dp->mhdp);
433 if (ret) {
434 - DRM_DEV_ERROR(dp->dev, "Failed link train %d\n", ret);
435 + DRM_DEV_ERROR(dev, "Failed link train %d\n", ret);
436 goto out;
437 }
438 }
439
440 - ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_IDLE);
441 + ret = cdns_mhdp_set_video_status(&dp->mhdp, CONTROL_VIDEO_IDLE);
442 if (ret) {
443 - DRM_DEV_ERROR(dp->dev, "Failed to idle video %d\n", ret);
444 + DRM_DEV_ERROR(dev, "Failed to idle video %d\n", ret);
445 goto out;
446 }
447
448 - ret = cdn_dp_config_video(dp);
449 + ret = cdns_mhdp_config_video(&dp->mhdp);
450 if (ret) {
451 - DRM_DEV_ERROR(dp->dev, "Failed to config video %d\n", ret);
452 + DRM_DEV_ERROR(dev, "Failed to config video %d\n", ret);
453 goto out;
454 }
455
456 - ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_VALID);
457 + ret = cdns_mhdp_set_video_status(&dp->mhdp, CONTROL_VIDEO_VALID);
458 if (ret) {
459 - DRM_DEV_ERROR(dp->dev, "Failed to valid video %d\n", ret);
460 + DRM_DEV_ERROR(dev, "Failed to valid video %d\n", ret);
461 goto out;
462 }
463 out:
464 @@ -651,7 +660,8 @@ static void cdn_dp_encoder_disable(struc
465 if (dp->active) {
466 ret = cdn_dp_disable(dp);
467 if (ret) {
468 - DRM_DEV_ERROR(dp->dev, "Failed to disable encoder %d\n",
469 + DRM_DEV_ERROR(dp->mhdp.dev,
470 + "Failed to disable encoder %d\n",
471 ret);
472 }
473 }
474 @@ -695,7 +705,7 @@ static const struct drm_encoder_funcs cd
475
476 static int cdn_dp_parse_dt(struct cdn_dp_device *dp)
477 {
478 - struct device *dev = dp->dev;
479 + struct device *dev = dp->mhdp.dev;
480 struct device_node *np = dev->of_node;
481 struct platform_device *pdev = to_platform_device(dev);
482 struct resource *res;
483 @@ -707,10 +717,10 @@ static int cdn_dp_parse_dt(struct cdn_dp
484 }
485
486 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
487 - dp->regs = devm_ioremap_resource(dev, res);
488 - if (IS_ERR(dp->regs)) {
489 + dp->mhdp.regs = devm_ioremap_resource(dev, res);
490 + if (IS_ERR(dp->mhdp.regs)) {
491 DRM_DEV_ERROR(dev, "ioremap reg failed\n");
492 - return PTR_ERR(dp->regs);
493 + return PTR_ERR(dp->mhdp.regs);
494 }
495
496 dp->core_clk = devm_clk_get(dev, "core-clk");
497 @@ -725,10 +735,10 @@ static int cdn_dp_parse_dt(struct cdn_dp
498 return PTR_ERR(dp->pclk);
499 }
500
501 - dp->spdif_clk = devm_clk_get(dev, "spdif");
502 - if (IS_ERR(dp->spdif_clk)) {
503 + dp->mhdp.spdif_clk = devm_clk_get(dev, "spdif");
504 + if (IS_ERR(dp->mhdp.spdif_clk)) {
505 DRM_DEV_ERROR(dev, "cannot get spdif_clk\n");
506 - return PTR_ERR(dp->spdif_clk);
507 + return PTR_ERR(dp->mhdp.spdif_clk);
508 }
509
510 dp->grf_clk = devm_clk_get(dev, "grf");
511 @@ -737,10 +747,10 @@ static int cdn_dp_parse_dt(struct cdn_dp
512 return PTR_ERR(dp->grf_clk);
513 }
514
515 - dp->spdif_rst = devm_reset_control_get(dev, "spdif");
516 - if (IS_ERR(dp->spdif_rst)) {
517 + dp->mhdp.spdif_rst = devm_reset_control_get(dev, "spdif");
518 + if (IS_ERR(dp->mhdp.spdif_rst)) {
519 DRM_DEV_ERROR(dev, "no spdif reset control found\n");
520 - return PTR_ERR(dp->spdif_rst);
521 + return PTR_ERR(dp->mhdp.spdif_rst);
522 }
523
524 dp->dptx_rst = devm_reset_control_get(dev, "dptx");
525 @@ -795,7 +805,7 @@ static int cdn_dp_audio_hw_params(struct
526 goto out;
527 }
528
529 - ret = cdn_dp_audio_config(dp, &audio);
530 + ret = cdns_mhdp_audio_config(&dp->mhdp, &audio);
531 if (!ret)
532 dp->audio_info = audio;
533
534 @@ -813,7 +823,7 @@ static void cdn_dp_audio_shutdown(struct
535 if (!dp->active)
536 goto out;
537
538 - ret = cdn_dp_audio_stop(dp, &dp->audio_info);
539 + ret = cdns_mhdp_audio_stop(&dp->mhdp, &dp->audio_info);
540 if (!ret)
541 dp->audio_info.format = AFMT_UNUSED;
542 out:
543 @@ -832,7 +842,7 @@ static int cdn_dp_audio_digital_mute(str
544 goto out;
545 }
546
547 - ret = cdn_dp_audio_mute(dp, enable);
548 + ret = cdns_mhdp_audio_mute(&dp->mhdp, enable);
549
550 out:
551 mutex_unlock(&dp->lock);
552 @@ -844,7 +854,8 @@ static int cdn_dp_audio_get_eld(struct d
553 {
554 struct cdn_dp_device *dp = dev_get_drvdata(dev);
555
556 - memcpy(buf, dp->connector.eld, min(sizeof(dp->connector.eld), len));
557 + memcpy(buf, dp->mhdp.connector.eld,
558 + min(sizeof(dp->mhdp.connector.eld), len));
559
560 return 0;
561 }
562 @@ -878,6 +889,7 @@ static int cdn_dp_request_firmware(struc
563 int ret;
564 unsigned long timeout = jiffies + msecs_to_jiffies(CDN_FW_TIMEOUT_MS);
565 unsigned long sleep = 1000;
566 + struct device *dev = dp->mhdp.dev;
567
568 WARN_ON(!mutex_is_locked(&dp->lock));
569
570 @@ -888,13 +900,13 @@ static int cdn_dp_request_firmware(struc
571 mutex_unlock(&dp->lock);
572
573 while (time_before(jiffies, timeout)) {
574 - ret = request_firmware(&dp->fw, CDN_DP_FIRMWARE, dp->dev);
575 + ret = request_firmware(&dp->fw, CDN_DP_FIRMWARE, dev);
576 if (ret == -ENOENT) {
577 msleep(sleep);
578 sleep *= 2;
579 continue;
580 } else if (ret) {
581 - DRM_DEV_ERROR(dp->dev,
582 + DRM_DEV_ERROR(dev,
583 "failed to request firmware: %d\n", ret);
584 goto out;
585 }
586 @@ -904,7 +916,7 @@ static int cdn_dp_request_firmware(struc
587 goto out;
588 }
589
590 - DRM_DEV_ERROR(dp->dev, "Timed out trying to load firmware\n");
591 + DRM_DEV_ERROR(dev, "Timed out trying to load firmware\n");
592 ret = -ETIMEDOUT;
593 out:
594 mutex_lock(&dp->lock);
595 @@ -915,8 +927,9 @@ static void cdn_dp_pd_event_work(struct
596 {
597 struct cdn_dp_device *dp = container_of(work, struct cdn_dp_device,
598 event_work);
599 - struct drm_connector *connector = &dp->connector;
600 + struct drm_connector *connector = &dp->mhdp.connector;
601 enum drm_connector_status old_status;
602 + struct device *dev = dp->mhdp.dev;
603
604 int ret;
605
606 @@ -933,44 +946,45 @@ static void cdn_dp_pd_event_work(struct
607
608 /* Not connected, notify userspace to disable the block */
609 if (!cdn_dp_connected_port(dp)) {
610 - DRM_DEV_INFO(dp->dev, "Not connected. Disabling cdn\n");
611 + DRM_DEV_INFO(dev, "Not connected. Disabling cdn\n");
612 dp->connected = false;
613
614 /* Connected but not enabled, enable the block */
615 } else if (!dp->active) {
616 - DRM_DEV_INFO(dp->dev, "Connected, not enabled. Enabling cdn\n");
617 + DRM_DEV_INFO(dev, "Connected, not enabled. Enabling cdn\n");
618 ret = cdn_dp_enable(dp);
619 if (ret) {
620 - DRM_DEV_ERROR(dp->dev, "Enable dp failed %d\n", ret);
621 + DRM_DEV_ERROR(dev, "Enable dp failed %d\n", ret);
622 dp->connected = false;
623 }
624
625 /* Enabled and connected to a dongle without a sink, notify userspace */
626 } else if (!cdn_dp_check_sink_connection(dp)) {
627 - DRM_DEV_INFO(dp->dev, "Connected without sink. Assert hpd\n");
628 + DRM_DEV_INFO(dev, "Connected without sink. Assert hpd\n");
629 dp->connected = false;
630
631 /* Enabled and connected with a sink, re-train if requested */
632 } else if (!cdn_dp_check_link_status(dp)) {
633 - unsigned int rate = dp->link.rate;
634 - unsigned int lanes = dp->link.num_lanes;
635 - struct drm_display_mode *mode = &dp->mode;
636 + unsigned int rate = dp->mhdp.link.rate;
637 + unsigned int lanes = dp->mhdp.link.num_lanes;
638 + struct drm_display_mode *mode = &dp->mhdp.mode;
639
640 - DRM_DEV_INFO(dp->dev, "Connected with sink. Re-train link\n");
641 - ret = cdn_dp_train_link(dp);
642 + DRM_DEV_INFO(dev, "Connected with sink. Re-train link\n");
643 + ret = cdns_mhdp_train_link(&dp->mhdp);
644 if (ret) {
645 dp->connected = false;
646 - DRM_DEV_ERROR(dp->dev, "Train link failed %d\n", ret);
647 + DRM_DEV_ERROR(dev, "Train link failed %d\n", ret);
648 goto out;
649 }
650
651 /* If training result is changed, update the video config */
652 if (mode->clock &&
653 - (rate != dp->link.rate || lanes != dp->link.num_lanes)) {
654 - ret = cdn_dp_config_video(dp);
655 + (rate != dp->mhdp.link.rate ||
656 + lanes != dp->mhdp.link.num_lanes)) {
657 + ret = cdns_mhdp_config_video(&dp->mhdp);
658 if (ret) {
659 dp->connected = false;
660 - DRM_DEV_ERROR(dp->dev,
661 + DRM_DEV_ERROR(dev,
662 "Failed to config video %d\n",
663 ret);
664 }
665 @@ -1039,7 +1053,7 @@ static int cdn_dp_bind(struct device *de
666
667 drm_encoder_helper_add(encoder, &cdn_dp_encoder_helper_funcs);
668
669 - connector = &dp->connector;
670 + connector = &dp->mhdp.connector;
671 connector->polled = DRM_CONNECTOR_POLL_HPD;
672 connector->dpms = DRM_MODE_DPMS_OFF;
673
674 @@ -1063,7 +1077,7 @@ static int cdn_dp_bind(struct device *de
675 port = dp->port[i];
676
677 port->event_nb.notifier_call = cdn_dp_pd_event;
678 - ret = devm_extcon_register_notifier(dp->dev, port->extcon,
679 + ret = devm_extcon_register_notifier(dp->mhdp.dev, port->extcon,
680 EXTCON_DISP_DP,
681 &port->event_nb);
682 if (ret) {
683 @@ -1090,7 +1104,7 @@ static void cdn_dp_unbind(struct device
684 {
685 struct cdn_dp_device *dp = dev_get_drvdata(dev);
686 struct drm_encoder *encoder = &dp->encoder;
687 - struct drm_connector *connector = &dp->connector;
688 + struct drm_connector *connector = &dp->mhdp.connector;
689
690 cancel_work_sync(&dp->event_work);
691 cdn_dp_encoder_disable(encoder);
692 @@ -1150,7 +1164,7 @@ static int cdn_dp_probe(struct platform_
693 dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL);
694 if (!dp)
695 return -ENOMEM;
696 - dp->dev = dev;
697 + dp->mhdp.dev = dev;
698
699 match = of_match_node(cdn_dp_dt_ids, pdev->dev.of_node);
700 dp_data = (struct cdn_dp_data *)match->data;
701 @@ -1195,7 +1209,7 @@ static int cdn_dp_remove(struct platform
702 struct cdn_dp_device *dp = platform_get_drvdata(pdev);
703
704 platform_device_unregister(dp->audio_pdev);
705 - cdn_dp_suspend(dp->dev);
706 + cdn_dp_suspend(dp->mhdp.dev);
707 component_del(&pdev->dev, &cdn_dp_component_ops);
708
709 return 0;
710 @@ -1205,7 +1219,7 @@ static void cdn_dp_shutdown(struct platf
711 {
712 struct cdn_dp_device *dp = platform_get_drvdata(pdev);
713
714 - cdn_dp_suspend(dp->dev);
715 + cdn_dp_suspend(dp->mhdp.dev);
716 }
717
718 static const struct dev_pm_ops cdn_dp_pm_ops = {
719 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.h
720 +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.h
721 @@ -12,38 +12,10 @@
722 #include <drm/drm_probe_helper.h>
723
724 #include "rockchip_drm_drv.h"
725 +#include "cdn-dp-reg.h"
726
727 #define MAX_PHY 2
728
729 -enum audio_format {
730 - AFMT_I2S = 0,
731 - AFMT_SPDIF = 1,
732 - AFMT_UNUSED,
733 -};
734 -
735 -struct audio_info {
736 - enum audio_format format;
737 - int sample_rate;
738 - int channels;
739 - int sample_width;
740 -};
741 -
742 -enum vic_pxl_encoding_format {
743 - PXL_RGB = 0x1,
744 - YCBCR_4_4_4 = 0x2,
745 - YCBCR_4_2_2 = 0x4,
746 - YCBCR_4_2_0 = 0x8,
747 - Y_ONLY = 0x10,
748 -};
749 -
750 -struct video_info {
751 - bool h_sync_polarity;
752 - bool v_sync_polarity;
753 - bool interlaced;
754 - int color_depth;
755 - enum vic_pxl_encoding_format color_fmt;
756 -};
757 -
758 struct cdn_firmware_header {
759 u32 size_bytes; /* size of the entire header+image(s) in bytes */
760 u32 header_size; /* size of just the header in bytes */
761 @@ -62,11 +34,9 @@ struct cdn_dp_port {
762 };
763
764 struct cdn_dp_device {
765 - struct device *dev;
766 + struct cdns_mhdp_device mhdp;
767 struct drm_device *drm_dev;
768 - struct drm_connector connector;
769 struct drm_encoder encoder;
770 - struct drm_display_mode mode;
771 struct platform_device *audio_pdev;
772 struct work_struct event_work;
773 struct edid *edid;
774 @@ -77,22 +47,16 @@ struct cdn_dp_device {
775 bool suspended;
776
777 const struct firmware *fw; /* cdn dp firmware */
778 - unsigned int fw_version; /* cdn fw version */
779 bool fw_loaded;
780
781 - void __iomem *regs;
782 struct regmap *grf;
783 struct clk *core_clk;
784 struct clk *pclk;
785 - struct clk *spdif_clk;
786 struct clk *grf_clk;
787 - struct reset_control *spdif_rst;
788 struct reset_control *dptx_rst;
789 struct reset_control *apb_rst;
790 struct reset_control *core_rst;
791 struct audio_info audio_info;
792 - struct video_info video_info;
793 - struct drm_dp_link link;
794 struct cdn_dp_port *port[MAX_PHY];
795 u8 ports;
796 u8 lanes;
797 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c
798 +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c
799 @@ -14,19 +14,19 @@
800 #include "cdn-dp-core.h"
801 #include "cdn-dp-reg.h"
802
803 -#define CDN_DP_SPDIF_CLK 200000000
804 +#define CDNS_DP_SPDIF_CLK 200000000
805 #define FW_ALIVE_TIMEOUT_US 1000000
806 #define MAILBOX_RETRY_US 1000
807 #define MAILBOX_TIMEOUT_US 5000000
808 #define LINK_TRAINING_RETRY_MS 20
809 #define LINK_TRAINING_TIMEOUT_MS 500
810
811 -void cdn_dp_set_fw_clk(struct cdn_dp_device *dp, unsigned long clk)
812 +void cdns_mhdp_set_fw_clk(struct cdns_mhdp_device *mhdp, unsigned long clk)
813 {
814 - writel(clk / 1000000, dp->regs + SW_CLK_H);
815 + writel(clk / 1000000, mhdp->regs + SW_CLK_H);
816 }
817
818 -void cdn_dp_clock_reset(struct cdn_dp_device *dp)
819 +void cdns_mhdp_clock_reset(struct cdns_mhdp_device *mhdp)
820 {
821 u32 val;
822
823 @@ -42,16 +42,16 @@ void cdn_dp_clock_reset(struct cdn_dp_de
824 DPTX_SYS_CLK_EN |
825 CFG_DPTX_VIF_CLK_RSTN_EN |
826 CFG_DPTX_VIF_CLK_EN;
827 - writel(val, dp->regs + SOURCE_DPTX_CAR);
828 + writel(val, mhdp->regs + SOURCE_DPTX_CAR);
829
830 val = SOURCE_PHY_RSTN_EN | SOURCE_PHY_CLK_EN;
831 - writel(val, dp->regs + SOURCE_PHY_CAR);
832 + writel(val, mhdp->regs + SOURCE_PHY_CAR);
833
834 val = SOURCE_PKT_SYS_RSTN_EN |
835 SOURCE_PKT_SYS_CLK_EN |
836 SOURCE_PKT_DATA_RSTN_EN |
837 SOURCE_PKT_DATA_CLK_EN;
838 - writel(val, dp->regs + SOURCE_PKT_CAR);
839 + writel(val, mhdp->regs + SOURCE_PKT_CAR);
840
841 val = SPDIF_CDR_CLK_RSTN_EN |
842 SPDIF_CDR_CLK_EN |
843 @@ -59,53 +59,53 @@ void cdn_dp_clock_reset(struct cdn_dp_de
844 SOURCE_AIF_SYS_CLK_EN |
845 SOURCE_AIF_CLK_RSTN_EN |
846 SOURCE_AIF_CLK_EN;
847 - writel(val, dp->regs + SOURCE_AIF_CAR);
848 + writel(val, mhdp->regs + SOURCE_AIF_CAR);
849
850 val = SOURCE_CIPHER_SYSTEM_CLK_RSTN_EN |
851 SOURCE_CIPHER_SYS_CLK_EN |
852 SOURCE_CIPHER_CHAR_CLK_RSTN_EN |
853 SOURCE_CIPHER_CHAR_CLK_EN;
854 - writel(val, dp->regs + SOURCE_CIPHER_CAR);
855 + writel(val, mhdp->regs + SOURCE_CIPHER_CAR);
856
857 val = SOURCE_CRYPTO_SYS_CLK_RSTN_EN |
858 SOURCE_CRYPTO_SYS_CLK_EN;
859 - writel(val, dp->regs + SOURCE_CRYPTO_CAR);
860 + writel(val, mhdp->regs + SOURCE_CRYPTO_CAR);
861
862 /* enable Mailbox and PIF interrupt */
863 - writel(0, dp->regs + APB_INT_MASK);
864 + writel(0, mhdp->regs + APB_INT_MASK);
865 }
866
867 -static int cdn_dp_mailbox_read(struct cdn_dp_device *dp)
868 +static int cdns_mhdp_mailbox_read(struct cdns_mhdp_device *mhdp)
869 {
870 int val, ret;
871
872 - ret = readx_poll_timeout(readl, dp->regs + MAILBOX_EMPTY_ADDR,
873 + ret = readx_poll_timeout(readl, mhdp->regs + MAILBOX_EMPTY_ADDR,
874 val, !val, MAILBOX_RETRY_US,
875 MAILBOX_TIMEOUT_US);
876 if (ret < 0)
877 return ret;
878
879 - return readl(dp->regs + MAILBOX0_RD_DATA) & 0xff;
880 + return readl(mhdp->regs + MAILBOX0_RD_DATA) & 0xff;
881 }
882
883 -static int cdp_dp_mailbox_write(struct cdn_dp_device *dp, u8 val)
884 +static int cdp_dp_mailbox_write(struct cdns_mhdp_device *mhdp, u8 val)
885 {
886 int ret, full;
887
888 - ret = readx_poll_timeout(readl, dp->regs + MAILBOX_FULL_ADDR,
889 + ret = readx_poll_timeout(readl, mhdp->regs + MAILBOX_FULL_ADDR,
890 full, !full, MAILBOX_RETRY_US,
891 MAILBOX_TIMEOUT_US);
892 if (ret < 0)
893 return ret;
894
895 - writel(val, dp->regs + MAILBOX0_WR_DATA);
896 + writel(val, mhdp->regs + MAILBOX0_WR_DATA);
897
898 return 0;
899 }
900
901 -static int cdn_dp_mailbox_validate_receive(struct cdn_dp_device *dp,
902 - u8 module_id, u8 opcode,
903 - u16 req_size)
904 +static int cdns_mhdp_mailbox_validate_receive(struct cdns_mhdp_device *mhdp,
905 + u8 module_id, u8 opcode,
906 + u16 req_size)
907 {
908 u32 mbox_size, i;
909 u8 header[4];
910 @@ -113,7 +113,7 @@ static int cdn_dp_mailbox_validate_recei
911
912 /* read the header of the message */
913 for (i = 0; i < 4; i++) {
914 - ret = cdn_dp_mailbox_read(dp);
915 + ret = cdns_mhdp_mailbox_read(mhdp);
916 if (ret < 0)
917 return ret;
918
919 @@ -129,7 +129,7 @@ static int cdn_dp_mailbox_validate_recei
920 * clear the mailbox by reading its contents.
921 */
922 for (i = 0; i < mbox_size; i++)
923 - if (cdn_dp_mailbox_read(dp) < 0)
924 + if (cdns_mhdp_mailbox_read(mhdp) < 0)
925 break;
926
927 return -EINVAL;
928 @@ -138,14 +138,14 @@ static int cdn_dp_mailbox_validate_recei
929 return 0;
930 }
931
932 -static int cdn_dp_mailbox_read_receive(struct cdn_dp_device *dp,
933 - u8 *buff, u16 buff_size)
934 +static int cdns_mhdp_mailbox_read_receive(struct cdns_mhdp_device *mhdp,
935 + u8 *buff, u16 buff_size)
936 {
937 u32 i;
938 int ret;
939
940 for (i = 0; i < buff_size; i++) {
941 - ret = cdn_dp_mailbox_read(dp);
942 + ret = cdns_mhdp_mailbox_read(mhdp);
943 if (ret < 0)
944 return ret;
945
946 @@ -155,8 +155,8 @@ static int cdn_dp_mailbox_read_receive(s
947 return 0;
948 }
949
950 -static int cdn_dp_mailbox_send(struct cdn_dp_device *dp, u8 module_id,
951 - u8 opcode, u16 size, u8 *message)
952 +static int cdns_mhdp_mailbox_send(struct cdns_mhdp_device *mhdp, u8 module_id,
953 + u8 opcode, u16 size, u8 *message)
954 {
955 u8 header[4];
956 int ret, i;
957 @@ -167,13 +167,13 @@ static int cdn_dp_mailbox_send(struct cd
958 header[3] = size & 0xff;
959
960 for (i = 0; i < 4; i++) {
961 - ret = cdp_dp_mailbox_write(dp, header[i]);
962 + ret = cdp_dp_mailbox_write(mhdp, header[i]);
963 if (ret)
964 return ret;
965 }
966
967 for (i = 0; i < size; i++) {
968 - ret = cdp_dp_mailbox_write(dp, message[i]);
969 + ret = cdp_dp_mailbox_write(mhdp, message[i]);
970 if (ret)
971 return ret;
972 }
973 @@ -181,7 +181,7 @@ static int cdn_dp_mailbox_send(struct cd
974 return 0;
975 }
976
977 -static int cdn_dp_reg_write(struct cdn_dp_device *dp, u16 addr, u32 val)
978 +static int cdns_mhdp_reg_write(struct cdns_mhdp_device *mhdp, u16 addr, u32 val)
979 {
980 u8 msg[6];
981
982 @@ -191,12 +191,12 @@ static int cdn_dp_reg_write(struct cdn_d
983 msg[3] = (val >> 16) & 0xff;
984 msg[4] = (val >> 8) & 0xff;
985 msg[5] = val & 0xff;
986 - return cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_WRITE_REGISTER,
987 - sizeof(msg), msg);
988 + return cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
989 + DPTX_WRITE_REGISTER, sizeof(msg), msg);
990 }
991
992 -static int cdn_dp_reg_write_bit(struct cdn_dp_device *dp, u16 addr,
993 - u8 start_bit, u8 bits_no, u32 val)
994 +static int cdns_mhdp_reg_write_bit(struct cdns_mhdp_device *mhdp, u16 addr,
995 + u8 start_bit, u8 bits_no, u32 val)
996 {
997 u8 field[8];
998
999 @@ -209,11 +209,12 @@ static int cdn_dp_reg_write_bit(struct c
1000 field[6] = (val >> 8) & 0xff;
1001 field[7] = val & 0xff;
1002
1003 - return cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_WRITE_FIELD,
1004 - sizeof(field), field);
1005 + return cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1006 + DPTX_WRITE_FIELD, sizeof(field), field);
1007 }
1008
1009 -int cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len)
1010 +int cdns_mhdp_dpcd_read(struct cdns_mhdp_device *mhdp,
1011 + u32 addr, u8 *data, u16 len)
1012 {
1013 u8 msg[5], reg[5];
1014 int ret;
1015 @@ -223,28 +224,28 @@ int cdn_dp_dpcd_read(struct cdn_dp_devic
1016 msg[2] = (addr >> 16) & 0xff;
1017 msg[3] = (addr >> 8) & 0xff;
1018 msg[4] = addr & 0xff;
1019 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_READ_DPCD,
1020 - sizeof(msg), msg);
1021 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1022 + DPTX_READ_DPCD, sizeof(msg), msg);
1023 if (ret)
1024 goto err_dpcd_read;
1025
1026 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1027 - DPTX_READ_DPCD,
1028 - sizeof(reg) + len);
1029 + ret = cdns_mhdp_mailbox_validate_receive(mhdp, MB_MODULE_ID_DP_TX,
1030 + DPTX_READ_DPCD,
1031 + sizeof(reg) + len);
1032 if (ret)
1033 goto err_dpcd_read;
1034
1035 - ret = cdn_dp_mailbox_read_receive(dp, reg, sizeof(reg));
1036 + ret = cdns_mhdp_mailbox_read_receive(mhdp, reg, sizeof(reg));
1037 if (ret)
1038 goto err_dpcd_read;
1039
1040 - ret = cdn_dp_mailbox_read_receive(dp, data, len);
1041 + ret = cdns_mhdp_mailbox_read_receive(mhdp, data, len);
1042
1043 err_dpcd_read:
1044 return ret;
1045 }
1046
1047 -int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value)
1048 +int cdns_mhdp_dpcd_write(struct cdns_mhdp_device *mhdp, u32 addr, u8 value)
1049 {
1050 u8 msg[6], reg[5];
1051 int ret;
1052 @@ -255,17 +256,17 @@ int cdn_dp_dpcd_write(struct cdn_dp_devi
1053 msg[3] = (addr >> 8) & 0xff;
1054 msg[4] = addr & 0xff;
1055 msg[5] = value;
1056 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_WRITE_DPCD,
1057 - sizeof(msg), msg);
1058 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1059 + DPTX_WRITE_DPCD, sizeof(msg), msg);
1060 if (ret)
1061 goto err_dpcd_write;
1062
1063 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1064 - DPTX_WRITE_DPCD, sizeof(reg));
1065 + ret = cdns_mhdp_mailbox_validate_receive(mhdp, MB_MODULE_ID_DP_TX,
1066 + DPTX_WRITE_DPCD, sizeof(reg));
1067 if (ret)
1068 goto err_dpcd_write;
1069
1070 - ret = cdn_dp_mailbox_read_receive(dp, reg, sizeof(reg));
1071 + ret = cdns_mhdp_mailbox_read_receive(mhdp, reg, sizeof(reg));
1072 if (ret)
1073 goto err_dpcd_write;
1074
1075 @@ -274,53 +275,53 @@ int cdn_dp_dpcd_write(struct cdn_dp_devi
1076
1077 err_dpcd_write:
1078 if (ret)
1079 - DRM_DEV_ERROR(dp->dev, "dpcd write failed: %d\n", ret);
1080 + DRM_DEV_ERROR(mhdp->dev, "dpcd write failed: %d\n", ret);
1081 return ret;
1082 }
1083
1084 -int cdn_dp_load_firmware(struct cdn_dp_device *dp, const u32 *i_mem,
1085 - u32 i_size, const u32 *d_mem, u32 d_size)
1086 +int cdns_mhdp_load_firmware(struct cdns_mhdp_device *mhdp, const u32 *i_mem,
1087 + u32 i_size, const u32 *d_mem, u32 d_size)
1088 {
1089 u32 reg;
1090 int i, ret;
1091
1092 /* reset ucpu before load firmware*/
1093 writel(APB_IRAM_PATH | APB_DRAM_PATH | APB_XT_RESET,
1094 - dp->regs + APB_CTRL);
1095 + mhdp->regs + APB_CTRL);
1096
1097 for (i = 0; i < i_size; i += 4)
1098 - writel(*i_mem++, dp->regs + ADDR_IMEM + i);
1099 + writel(*i_mem++, mhdp->regs + ADDR_IMEM + i);
1100
1101 for (i = 0; i < d_size; i += 4)
1102 - writel(*d_mem++, dp->regs + ADDR_DMEM + i);
1103 + writel(*d_mem++, mhdp->regs + ADDR_DMEM + i);
1104
1105 /* un-reset ucpu */
1106 - writel(0, dp->regs + APB_CTRL);
1107 + writel(0, mhdp->regs + APB_CTRL);
1108
1109 /* check the keep alive register to make sure fw working */
1110 - ret = readx_poll_timeout(readl, dp->regs + KEEP_ALIVE,
1111 + ret = readx_poll_timeout(readl, mhdp->regs + KEEP_ALIVE,
1112 reg, reg, 2000, FW_ALIVE_TIMEOUT_US);
1113 if (ret < 0) {
1114 - DRM_DEV_ERROR(dp->dev, "failed to loaded the FW reg = %x\n",
1115 + DRM_DEV_ERROR(mhdp->dev, "failed to loaded the FW reg = %x\n",
1116 reg);
1117 return -EINVAL;
1118 }
1119
1120 - reg = readl(dp->regs + VER_L) & 0xff;
1121 - dp->fw_version = reg;
1122 - reg = readl(dp->regs + VER_H) & 0xff;
1123 - dp->fw_version |= reg << 8;
1124 - reg = readl(dp->regs + VER_LIB_L_ADDR) & 0xff;
1125 - dp->fw_version |= reg << 16;
1126 - reg = readl(dp->regs + VER_LIB_H_ADDR) & 0xff;
1127 - dp->fw_version |= reg << 24;
1128 + reg = readl(mhdp->regs + VER_L) & 0xff;
1129 + mhdp->fw_version = reg;
1130 + reg = readl(mhdp->regs + VER_H) & 0xff;
1131 + mhdp->fw_version |= reg << 8;
1132 + reg = readl(mhdp->regs + VER_LIB_L_ADDR) & 0xff;
1133 + mhdp->fw_version |= reg << 16;
1134 + reg = readl(mhdp->regs + VER_LIB_H_ADDR) & 0xff;
1135 + mhdp->fw_version |= reg << 24;
1136
1137 - DRM_DEV_DEBUG(dp->dev, "firmware version: %x\n", dp->fw_version);
1138 + DRM_DEV_DEBUG(mhdp->dev, "firmware version: %x\n", mhdp->fw_version);
1139
1140 return 0;
1141 }
1142
1143 -int cdn_dp_set_firmware_active(struct cdn_dp_device *dp, bool enable)
1144 +int cdns_mhdp_set_firmware_active(struct cdns_mhdp_device *mhdp, bool enable)
1145 {
1146 u8 msg[5];
1147 int ret, i;
1148 @@ -332,14 +333,14 @@ int cdn_dp_set_firmware_active(struct cd
1149 msg[4] = enable ? FW_ACTIVE : FW_STANDBY;
1150
1151 for (i = 0; i < sizeof(msg); i++) {
1152 - ret = cdp_dp_mailbox_write(dp, msg[i]);
1153 + ret = cdp_dp_mailbox_write(mhdp, msg[i]);
1154 if (ret)
1155 goto err_set_firmware_active;
1156 }
1157
1158 /* read the firmware state */
1159 for (i = 0; i < sizeof(msg); i++) {
1160 - ret = cdn_dp_mailbox_read(dp);
1161 + ret = cdns_mhdp_mailbox_read(mhdp);
1162 if (ret < 0)
1163 goto err_set_firmware_active;
1164
1165 @@ -350,16 +351,16 @@ int cdn_dp_set_firmware_active(struct cd
1166
1167 err_set_firmware_active:
1168 if (ret < 0)
1169 - DRM_DEV_ERROR(dp->dev, "set firmware active failed\n");
1170 + DRM_DEV_ERROR(mhdp->dev, "set firmware active failed\n");
1171 return ret;
1172 }
1173
1174 -int cdn_dp_set_host_cap(struct cdn_dp_device *dp, u8 lanes, bool flip)
1175 +int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, u8 lanes, bool flip)
1176 {
1177 u8 msg[8];
1178 int ret;
1179
1180 - msg[0] = CDN_DP_MAX_LINK_RATE;
1181 + msg[0] = CDNS_DP_MAX_LINK_RATE;
1182 msg[1] = lanes | SCRAMBLER_EN;
1183 msg[2] = VOLTAGE_LEVEL_2;
1184 msg[3] = PRE_EMPHASIS_LEVEL_3;
1185 @@ -368,22 +369,22 @@ int cdn_dp_set_host_cap(struct cdn_dp_de
1186 msg[6] = flip ? LANE_MAPPING_FLIPPED : LANE_MAPPING_NORMAL;
1187 msg[7] = ENHANCED;
1188
1189 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX,
1190 - DPTX_SET_HOST_CAPABILITIES,
1191 - sizeof(msg), msg);
1192 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1193 + DPTX_SET_HOST_CAPABILITIES,
1194 + sizeof(msg), msg);
1195 if (ret)
1196 goto err_set_host_cap;
1197
1198 - ret = cdn_dp_reg_write(dp, DP_AUX_SWAP_INVERSION_CONTROL,
1199 - AUX_HOST_INVERT);
1200 + ret = cdns_mhdp_reg_write(mhdp, DP_AUX_SWAP_INVERSION_CONTROL,
1201 + AUX_HOST_INVERT);
1202
1203 err_set_host_cap:
1204 if (ret)
1205 - DRM_DEV_ERROR(dp->dev, "set host cap failed: %d\n", ret);
1206 + DRM_DEV_ERROR(mhdp->dev, "set host cap failed: %d\n", ret);
1207 return ret;
1208 }
1209
1210 -int cdn_dp_event_config(struct cdn_dp_device *dp)
1211 +int cdns_mhdp_event_config(struct cdns_mhdp_device *mhdp)
1212 {
1213 u8 msg[5];
1214 int ret;
1215 @@ -392,49 +393,50 @@ int cdn_dp_event_config(struct cdn_dp_de
1216
1217 msg[0] = DPTX_EVENT_ENABLE_HPD | DPTX_EVENT_ENABLE_TRAINING;
1218
1219 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_ENABLE_EVENT,
1220 - sizeof(msg), msg);
1221 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1222 + DPTX_ENABLE_EVENT, sizeof(msg), msg);
1223 if (ret)
1224 - DRM_DEV_ERROR(dp->dev, "set event config failed: %d\n", ret);
1225 + DRM_DEV_ERROR(mhdp->dev, "set event config failed: %d\n", ret);
1226
1227 return ret;
1228 }
1229
1230 -u32 cdn_dp_get_event(struct cdn_dp_device *dp)
1231 +u32 cdns_mhdp_get_event(struct cdns_mhdp_device *mhdp)
1232 {
1233 - return readl(dp->regs + SW_EVENTS0);
1234 + return readl(mhdp->regs + SW_EVENTS0);
1235 }
1236
1237 -int cdn_dp_get_hpd_status(struct cdn_dp_device *dp)
1238 +int cdns_mhdp_get_hpd_status(struct cdns_mhdp_device *mhdp)
1239 {
1240 u8 status;
1241 int ret;
1242
1243 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_HPD_STATE,
1244 - 0, NULL);
1245 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1246 + DPTX_HPD_STATE, 0, NULL);
1247 if (ret)
1248 goto err_get_hpd;
1249
1250 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1251 - DPTX_HPD_STATE, sizeof(status));
1252 + ret = cdns_mhdp_mailbox_validate_receive(mhdp, MB_MODULE_ID_DP_TX,
1253 + DPTX_HPD_STATE,
1254 + sizeof(status));
1255 if (ret)
1256 goto err_get_hpd;
1257
1258 - ret = cdn_dp_mailbox_read_receive(dp, &status, sizeof(status));
1259 + ret = cdns_mhdp_mailbox_read_receive(mhdp, &status, sizeof(status));
1260 if (ret)
1261 goto err_get_hpd;
1262
1263 return status;
1264
1265 err_get_hpd:
1266 - DRM_DEV_ERROR(dp->dev, "get hpd status failed: %d\n", ret);
1267 + DRM_DEV_ERROR(mhdp->dev, "get hpd status failed: %d\n", ret);
1268 return ret;
1269 }
1270
1271 -int cdn_dp_get_edid_block(void *data, u8 *edid,
1272 +int cdns_mhdp_get_edid_block(void *data, u8 *edid,
1273 unsigned int block, size_t length)
1274 {
1275 - struct cdn_dp_device *dp = data;
1276 + struct cdns_mhdp_device *mhdp = data;
1277 u8 msg[2], reg[2], i;
1278 int ret;
1279
1280 @@ -442,22 +444,23 @@ int cdn_dp_get_edid_block(void *data, u8
1281 msg[0] = block / 2;
1282 msg[1] = block % 2;
1283
1284 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_GET_EDID,
1285 - sizeof(msg), msg);
1286 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1287 + DPTX_GET_EDID, sizeof(msg), msg);
1288 if (ret)
1289 continue;
1290
1291 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1292 - DPTX_GET_EDID,
1293 - sizeof(reg) + length);
1294 + ret = cdns_mhdp_mailbox_validate_receive(mhdp,
1295 + MB_MODULE_ID_DP_TX,
1296 + DPTX_GET_EDID,
1297 + sizeof(reg) + length);
1298 if (ret)
1299 continue;
1300
1301 - ret = cdn_dp_mailbox_read_receive(dp, reg, sizeof(reg));
1302 + ret = cdns_mhdp_mailbox_read_receive(mhdp, reg, sizeof(reg));
1303 if (ret)
1304 continue;
1305
1306 - ret = cdn_dp_mailbox_read_receive(dp, edid, length);
1307 + ret = cdns_mhdp_mailbox_read_receive(mhdp, edid, length);
1308 if (ret)
1309 continue;
1310
1311 @@ -466,13 +469,13 @@ int cdn_dp_get_edid_block(void *data, u8
1312 }
1313
1314 if (ret)
1315 - DRM_DEV_ERROR(dp->dev, "get block[%d] edid failed: %d\n", block,
1316 - ret);
1317 + DRM_DEV_ERROR(mhdp->dev, "get block[%d] edid failed: %d\n",
1318 + block, ret);
1319
1320 return ret;
1321 }
1322
1323 -static int cdn_dp_training_start(struct cdn_dp_device *dp)
1324 +static int cdns_mhdp_training_start(struct cdns_mhdp_device *mhdp)
1325 {
1326 unsigned long timeout;
1327 u8 msg, event[2];
1328 @@ -481,26 +484,28 @@ static int cdn_dp_training_start(struct
1329 msg = LINK_TRAINING_RUN;
1330
1331 /* start training */
1332 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_TRAINING_CONTROL,
1333 - sizeof(msg), &msg);
1334 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1335 + DPTX_TRAINING_CONTROL, sizeof(msg), &msg);
1336 if (ret)
1337 goto err_training_start;
1338
1339 timeout = jiffies + msecs_to_jiffies(LINK_TRAINING_TIMEOUT_MS);
1340 while (time_before(jiffies, timeout)) {
1341 msleep(LINK_TRAINING_RETRY_MS);
1342 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX,
1343 - DPTX_READ_EVENT, 0, NULL);
1344 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX,
1345 + DPTX_READ_EVENT, 0, NULL);
1346 if (ret)
1347 goto err_training_start;
1348
1349 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1350 - DPTX_READ_EVENT,
1351 - sizeof(event));
1352 + ret = cdns_mhdp_mailbox_validate_receive(mhdp,
1353 + MB_MODULE_ID_DP_TX,
1354 + DPTX_READ_EVENT,
1355 + sizeof(event));
1356 if (ret)
1357 goto err_training_start;
1358
1359 - ret = cdn_dp_mailbox_read_receive(dp, event, sizeof(event));
1360 + ret = cdns_mhdp_mailbox_read_receive(mhdp, event,
1361 + sizeof(event));
1362 if (ret)
1363 goto err_training_start;
1364
1365 @@ -511,76 +516,76 @@ static int cdn_dp_training_start(struct
1366 ret = -ETIMEDOUT;
1367
1368 err_training_start:
1369 - DRM_DEV_ERROR(dp->dev, "training failed: %d\n", ret);
1370 + DRM_DEV_ERROR(mhdp->dev, "training failed: %d\n", ret);
1371 return ret;
1372 }
1373
1374 -static int cdn_dp_get_training_status(struct cdn_dp_device *dp)
1375 +static int cdns_mhdp_get_training_status(struct cdns_mhdp_device *mhdp)
1376 {
1377 u8 status[10];
1378 int ret;
1379
1380 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_READ_LINK_STAT,
1381 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, DPTX_READ_LINK_STAT,
1382 0, NULL);
1383 if (ret)
1384 goto err_get_training_status;
1385
1386 - ret = cdn_dp_mailbox_validate_receive(dp, MB_MODULE_ID_DP_TX,
1387 + ret = cdns_mhdp_mailbox_validate_receive(mhdp, MB_MODULE_ID_DP_TX,
1388 DPTX_READ_LINK_STAT,
1389 sizeof(status));
1390 if (ret)
1391 goto err_get_training_status;
1392
1393 - ret = cdn_dp_mailbox_read_receive(dp, status, sizeof(status));
1394 + ret = cdns_mhdp_mailbox_read_receive(mhdp, status, sizeof(status));
1395 if (ret)
1396 goto err_get_training_status;
1397
1398 - dp->link.rate = drm_dp_bw_code_to_link_rate(status[0]);
1399 - dp->link.num_lanes = status[1];
1400 + mhdp->link.rate = drm_dp_bw_code_to_link_rate(status[0]);
1401 + mhdp->link.num_lanes = status[1];
1402
1403 err_get_training_status:
1404 if (ret)
1405 - DRM_DEV_ERROR(dp->dev, "get training status failed: %d\n", ret);
1406 + DRM_DEV_ERROR(mhdp->dev, "get training status failed: %d\n", ret);
1407 return ret;
1408 }
1409
1410 -int cdn_dp_train_link(struct cdn_dp_device *dp)
1411 +int cdns_mhdp_train_link(struct cdns_mhdp_device *mhdp)
1412 {
1413 int ret;
1414
1415 - ret = cdn_dp_training_start(dp);
1416 + ret = cdns_mhdp_training_start(mhdp);
1417 if (ret) {
1418 - DRM_DEV_ERROR(dp->dev, "Failed to start training %d\n", ret);
1419 + DRM_DEV_ERROR(mhdp->dev, "Failed to start training %d\n", ret);
1420 return ret;
1421 }
1422
1423 - ret = cdn_dp_get_training_status(dp);
1424 + ret = cdns_mhdp_get_training_status(mhdp);
1425 if (ret) {
1426 - DRM_DEV_ERROR(dp->dev, "Failed to get training stat %d\n", ret);
1427 + DRM_DEV_ERROR(mhdp->dev, "Failed to get training stat %d\n", ret);
1428 return ret;
1429 }
1430
1431 - DRM_DEV_DEBUG_KMS(dp->dev, "rate:0x%x, lanes:%d\n", dp->link.rate,
1432 - dp->link.num_lanes);
1433 + DRM_DEV_DEBUG_KMS(mhdp->dev, "rate:0x%x, lanes:%d\n", mhdp->link.rate,
1434 + mhdp->link.num_lanes);
1435 return ret;
1436 }
1437
1438 -int cdn_dp_set_video_status(struct cdn_dp_device *dp, int active)
1439 +int cdns_mhdp_set_video_status(struct cdns_mhdp_device *mhdp, int active)
1440 {
1441 u8 msg;
1442 int ret;
1443
1444 msg = !!active;
1445
1446 - ret = cdn_dp_mailbox_send(dp, MB_MODULE_ID_DP_TX, DPTX_SET_VIDEO,
1447 + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, DPTX_SET_VIDEO,
1448 sizeof(msg), &msg);
1449 if (ret)
1450 - DRM_DEV_ERROR(dp->dev, "set video status failed: %d\n", ret);
1451 + DRM_DEV_ERROR(mhdp->dev, "set video status failed: %d\n", ret);
1452
1453 return ret;
1454 }
1455
1456 -static int cdn_dp_get_msa_misc(struct video_info *video,
1457 +static int cdns_mhdp_get_msa_misc(struct video_info *video,
1458 struct drm_display_mode *mode)
1459 {
1460 u32 msa_misc;
1461 @@ -627,10 +632,10 @@ static int cdn_dp_get_msa_misc(struct vi
1462 return msa_misc;
1463 }
1464
1465 -int cdn_dp_config_video(struct cdn_dp_device *dp)
1466 +int cdns_mhdp_config_video(struct cdns_mhdp_device *mhdp)
1467 {
1468 - struct video_info *video = &dp->video_info;
1469 - struct drm_display_mode *mode = &dp->mode;
1470 + struct video_info *video = &mhdp->video_info;
1471 + struct drm_display_mode *mode = &mhdp->mode;
1472 u64 symbol;
1473 u32 val, link_rate, rem;
1474 u8 bit_per_pix, tu_size_reg = TU_SIZE;
1475 @@ -639,13 +644,13 @@ int cdn_dp_config_video(struct cdn_dp_de
1476 bit_per_pix = (video->color_fmt == YCBCR_4_2_2) ?
1477 (video->color_depth * 2) : (video->color_depth * 3);
1478
1479 - link_rate = dp->link.rate / 1000;
1480 + link_rate = mhdp->link.rate / 1000;
1481
1482 - ret = cdn_dp_reg_write(dp, BND_HSYNC2VSYNC, VIF_BYPASS_INTERLACE);
1483 + ret = cdns_mhdp_reg_write(mhdp, BND_HSYNC2VSYNC, VIF_BYPASS_INTERLACE);
1484 if (ret)
1485 goto err_config_video;
1486
1487 - ret = cdn_dp_reg_write(dp, HSYNC2VSYNC_POL_CTRL, 0);
1488 + ret = cdns_mhdp_reg_write(mhdp, HSYNC2VSYNC_POL_CTRL, 0);
1489 if (ret)
1490 goto err_config_video;
1491
1492 @@ -659,13 +664,13 @@ int cdn_dp_config_video(struct cdn_dp_de
1493 do {
1494 tu_size_reg += 2;
1495 symbol = tu_size_reg * mode->clock * bit_per_pix;
1496 - do_div(symbol, dp->link.num_lanes * link_rate * 8);
1497 + do_div(symbol, mhdp->link.num_lanes * link_rate * 8);
1498 rem = do_div(symbol, 1000);
1499 if (tu_size_reg > 64) {
1500 ret = -EINVAL;
1501 - DRM_DEV_ERROR(dp->dev,
1502 + DRM_DEV_ERROR(mhdp->dev,
1503 "tu error, clk:%d, lanes:%d, rate:%d\n",
1504 - mode->clock, dp->link.num_lanes,
1505 + mode->clock, mhdp->link.num_lanes,
1506 link_rate);
1507 goto err_config_video;
1508 }
1509 @@ -674,16 +679,16 @@ int cdn_dp_config_video(struct cdn_dp_de
1510
1511 val = symbol + (tu_size_reg << 8);
1512 val |= TU_CNT_RST_EN;
1513 - ret = cdn_dp_reg_write(dp, DP_FRAMER_TU, val);
1514 + ret = cdns_mhdp_reg_write(mhdp, DP_FRAMER_TU, val);
1515 if (ret)
1516 goto err_config_video;
1517
1518 /* set the FIFO Buffer size */
1519 val = div_u64(mode->clock * (symbol + 1), 1000) + link_rate;
1520 - val /= (dp->link.num_lanes * link_rate);
1521 + val /= (mhdp->link.num_lanes * link_rate);
1522 val = div_u64(8 * (symbol + 1), bit_per_pix) - val;
1523 val += 2;
1524 - ret = cdn_dp_reg_write(dp, DP_VC_TABLE(15), val);
1525 + ret = cdns_mhdp_reg_write(mhdp, DP_VC_TABLE(15), val);
1526
1527 switch (video->color_depth) {
1528 case 6:
1529 @@ -704,136 +709,137 @@ int cdn_dp_config_video(struct cdn_dp_de
1530 };
1531
1532 val += video->color_fmt << 8;
1533 - ret = cdn_dp_reg_write(dp, DP_FRAMER_PXL_REPR, val);
1534 + ret = cdns_mhdp_reg_write(mhdp, DP_FRAMER_PXL_REPR, val);
1535 if (ret)
1536 goto err_config_video;
1537
1538 val = video->h_sync_polarity ? DP_FRAMER_SP_HSP : 0;
1539 val |= video->v_sync_polarity ? DP_FRAMER_SP_VSP : 0;
1540 - ret = cdn_dp_reg_write(dp, DP_FRAMER_SP, val);
1541 + ret = cdns_mhdp_reg_write(mhdp, DP_FRAMER_SP, val);
1542 if (ret)
1543 goto err_config_video;
1544
1545 val = (mode->hsync_start - mode->hdisplay) << 16;
1546 val |= mode->htotal - mode->hsync_end;
1547 - ret = cdn_dp_reg_write(dp, DP_FRONT_BACK_PORCH, val);
1548 + ret = cdns_mhdp_reg_write(mhdp, DP_FRONT_BACK_PORCH, val);
1549 if (ret)
1550 goto err_config_video;
1551
1552 val = mode->hdisplay * bit_per_pix / 8;
1553 - ret = cdn_dp_reg_write(dp, DP_BYTE_COUNT, val);
1554 + ret = cdns_mhdp_reg_write(mhdp, DP_BYTE_COUNT, val);
1555 if (ret)
1556 goto err_config_video;
1557
1558 val = mode->htotal | ((mode->htotal - mode->hsync_start) << 16);
1559 - ret = cdn_dp_reg_write(dp, MSA_HORIZONTAL_0, val);
1560 + ret = cdns_mhdp_reg_write(mhdp, MSA_HORIZONTAL_0, val);
1561 if (ret)
1562 goto err_config_video;
1563
1564 val = mode->hsync_end - mode->hsync_start;
1565 val |= (mode->hdisplay << 16) | (video->h_sync_polarity << 15);
1566 - ret = cdn_dp_reg_write(dp, MSA_HORIZONTAL_1, val);
1567 + ret = cdns_mhdp_reg_write(mhdp, MSA_HORIZONTAL_1, val);
1568 if (ret)
1569 goto err_config_video;
1570
1571 val = mode->vtotal;
1572 val |= (mode->vtotal - mode->vsync_start) << 16;
1573 - ret = cdn_dp_reg_write(dp, MSA_VERTICAL_0, val);
1574 + ret = cdns_mhdp_reg_write(mhdp, MSA_VERTICAL_0, val);
1575 if (ret)
1576 goto err_config_video;
1577
1578 val = mode->vsync_end - mode->vsync_start;
1579 val |= (mode->vdisplay << 16) | (video->v_sync_polarity << 15);
1580 - ret = cdn_dp_reg_write(dp, MSA_VERTICAL_1, val);
1581 + ret = cdns_mhdp_reg_write(mhdp, MSA_VERTICAL_1, val);
1582 if (ret)
1583 goto err_config_video;
1584
1585 - val = cdn_dp_get_msa_misc(video, mode);
1586 - ret = cdn_dp_reg_write(dp, MSA_MISC, val);
1587 + val = cdns_mhdp_get_msa_misc(video, mode);
1588 + ret = cdns_mhdp_reg_write(mhdp, MSA_MISC, val);
1589 if (ret)
1590 goto err_config_video;
1591
1592 - ret = cdn_dp_reg_write(dp, STREAM_CONFIG, 1);
1593 + ret = cdns_mhdp_reg_write(mhdp, STREAM_CONFIG, 1);
1594 if (ret)
1595 goto err_config_video;
1596
1597 val = mode->hsync_end - mode->hsync_start;
1598 val |= mode->hdisplay << 16;
1599 - ret = cdn_dp_reg_write(dp, DP_HORIZONTAL, val);
1600 + ret = cdns_mhdp_reg_write(mhdp, DP_HORIZONTAL, val);
1601 if (ret)
1602 goto err_config_video;
1603
1604 val = mode->vdisplay;
1605 val |= (mode->vtotal - mode->vsync_start) << 16;
1606 - ret = cdn_dp_reg_write(dp, DP_VERTICAL_0, val);
1607 + ret = cdns_mhdp_reg_write(mhdp, DP_VERTICAL_0, val);
1608 if (ret)
1609 goto err_config_video;
1610
1611 val = mode->vtotal;
1612 - ret = cdn_dp_reg_write(dp, DP_VERTICAL_1, val);
1613 + ret = cdns_mhdp_reg_write(mhdp, DP_VERTICAL_1, val);
1614 if (ret)
1615 goto err_config_video;
1616
1617 - ret = cdn_dp_reg_write_bit(dp, DP_VB_ID, 2, 1, 0);
1618 + ret = cdns_mhdp_reg_write_bit(mhdp, DP_VB_ID, 2, 1, 0);
1619
1620 err_config_video:
1621 if (ret)
1622 - DRM_DEV_ERROR(dp->dev, "config video failed: %d\n", ret);
1623 + DRM_DEV_ERROR(mhdp->dev, "config video failed: %d\n", ret);
1624 return ret;
1625 }
1626
1627 -int cdn_dp_audio_stop(struct cdn_dp_device *dp, struct audio_info *audio)
1628 +int cdns_mhdp_audio_stop(struct cdns_mhdp_device *mhdp,
1629 + struct audio_info *audio)
1630 {
1631 int ret;
1632
1633 - ret = cdn_dp_reg_write(dp, AUDIO_PACK_CONTROL, 0);
1634 + ret = cdns_mhdp_reg_write(mhdp, AUDIO_PACK_CONTROL, 0);
1635 if (ret) {
1636 - DRM_DEV_ERROR(dp->dev, "audio stop failed: %d\n", ret);
1637 + DRM_DEV_ERROR(mhdp->dev, "audio stop failed: %d\n", ret);
1638 return ret;
1639 }
1640
1641 - writel(0, dp->regs + SPDIF_CTRL_ADDR);
1642 + writel(0, mhdp->regs + SPDIF_CTRL_ADDR);
1643
1644 /* clearn the audio config and reset */
1645 - writel(0, dp->regs + AUDIO_SRC_CNTL);
1646 - writel(0, dp->regs + AUDIO_SRC_CNFG);
1647 - writel(AUDIO_SW_RST, dp->regs + AUDIO_SRC_CNTL);
1648 - writel(0, dp->regs + AUDIO_SRC_CNTL);
1649 + writel(0, mhdp->regs + AUDIO_SRC_CNTL);
1650 + writel(0, mhdp->regs + AUDIO_SRC_CNFG);
1651 + writel(AUDIO_SW_RST, mhdp->regs + AUDIO_SRC_CNTL);
1652 + writel(0, mhdp->regs + AUDIO_SRC_CNTL);
1653
1654 /* reset smpl2pckt component */
1655 - writel(0, dp->regs + SMPL2PKT_CNTL);
1656 - writel(AUDIO_SW_RST, dp->regs + SMPL2PKT_CNTL);
1657 - writel(0, dp->regs + SMPL2PKT_CNTL);
1658 + writel(0, mhdp->regs + SMPL2PKT_CNTL);
1659 + writel(AUDIO_SW_RST, mhdp->regs + SMPL2PKT_CNTL);
1660 + writel(0, mhdp->regs + SMPL2PKT_CNTL);
1661
1662 /* reset FIFO */
1663 - writel(AUDIO_SW_RST, dp->regs + FIFO_CNTL);
1664 - writel(0, dp->regs + FIFO_CNTL);
1665 + writel(AUDIO_SW_RST, mhdp->regs + FIFO_CNTL);
1666 + writel(0, mhdp->regs + FIFO_CNTL);
1667
1668 if (audio->format == AFMT_SPDIF)
1669 - clk_disable_unprepare(dp->spdif_clk);
1670 + clk_disable_unprepare(mhdp->spdif_clk);
1671
1672 return 0;
1673 }
1674
1675 -int cdn_dp_audio_mute(struct cdn_dp_device *dp, bool enable)
1676 +int cdns_mhdp_audio_mute(struct cdns_mhdp_device *mhdp, bool enable)
1677 {
1678 int ret;
1679
1680 - ret = cdn_dp_reg_write_bit(dp, DP_VB_ID, 4, 1, enable);
1681 + ret = cdns_mhdp_reg_write_bit(mhdp, DP_VB_ID, 4, 1, enable);
1682 if (ret)
1683 - DRM_DEV_ERROR(dp->dev, "audio mute failed: %d\n", ret);
1684 + DRM_DEV_ERROR(mhdp->dev, "audio mute failed: %d\n", ret);
1685
1686 return ret;
1687 }
1688
1689 -static void cdn_dp_audio_config_i2s(struct cdn_dp_device *dp,
1690 - struct audio_info *audio)
1691 +static void cdns_mhdp_audio_config_i2s(struct cdns_mhdp_device *mhdp,
1692 + struct audio_info *audio)
1693 {
1694 int sub_pckt_num = 1, i2s_port_en_val = 0xf, i;
1695 u32 val;
1696
1697 if (audio->channels == 2) {
1698 - if (dp->link.num_lanes == 1)
1699 + if (mhdp->link.num_lanes == 1)
1700 sub_pckt_num = 2;
1701 else
1702 sub_pckt_num = 4;
1703 @@ -843,15 +849,15 @@ static void cdn_dp_audio_config_i2s(stru
1704 i2s_port_en_val = 3;
1705 }
1706
1707 - writel(0x0, dp->regs + SPDIF_CTRL_ADDR);
1708 + writel(0x0, mhdp->regs + SPDIF_CTRL_ADDR);
1709
1710 - writel(SYNC_WR_TO_CH_ZERO, dp->regs + FIFO_CNTL);
1711 + writel(SYNC_WR_TO_CH_ZERO, mhdp->regs + FIFO_CNTL);
1712
1713 val = MAX_NUM_CH(audio->channels);
1714 val |= NUM_OF_I2S_PORTS(audio->channels);
1715 val |= AUDIO_TYPE_LPCM;
1716 val |= CFG_SUB_PCKT_NUM(sub_pckt_num);
1717 - writel(val, dp->regs + SMPL2PKT_CNFG);
1718 + writel(val, mhdp->regs + SMPL2PKT_CNFG);
1719
1720 if (audio->sample_width == 16)
1721 val = 0;
1722 @@ -863,7 +869,7 @@ static void cdn_dp_audio_config_i2s(stru
1723 val |= AUDIO_CH_NUM(audio->channels);
1724 val |= I2S_DEC_PORT_EN(i2s_port_en_val);
1725 val |= TRANS_SMPL_WIDTH_32;
1726 - writel(val, dp->regs + AUDIO_SRC_CNFG);
1727 + writel(val, mhdp->regs + AUDIO_SRC_CNFG);
1728
1729 for (i = 0; i < (audio->channels + 1) / 2; i++) {
1730 if (audio->sample_width == 16)
1731 @@ -872,7 +878,7 @@ static void cdn_dp_audio_config_i2s(stru
1732 val = (0x0b << 8) | (0x0b << 20);
1733
1734 val |= ((2 * i) << 4) | ((2 * i + 1) << 16);
1735 - writel(val, dp->regs + STTS_BIT_CH(i));
1736 + writel(val, mhdp->regs + STTS_BIT_CH(i));
1737 }
1738
1739 switch (audio->sample_rate) {
1740 @@ -906,56 +912,57 @@ static void cdn_dp_audio_config_i2s(stru
1741 break;
1742 }
1743 val |= 4;
1744 - writel(val, dp->regs + COM_CH_STTS_BITS);
1745 + writel(val, mhdp->regs + COM_CH_STTS_BITS);
1746
1747 - writel(SMPL2PKT_EN, dp->regs + SMPL2PKT_CNTL);
1748 - writel(I2S_DEC_START, dp->regs + AUDIO_SRC_CNTL);
1749 + writel(SMPL2PKT_EN, mhdp->regs + SMPL2PKT_CNTL);
1750 + writel(I2S_DEC_START, mhdp->regs + AUDIO_SRC_CNTL);
1751 }
1752
1753 -static void cdn_dp_audio_config_spdif(struct cdn_dp_device *dp)
1754 +static void cdns_mhdp_audio_config_spdif(struct cdns_mhdp_device *mhdp)
1755 {
1756 u32 val;
1757
1758 - writel(SYNC_WR_TO_CH_ZERO, dp->regs + FIFO_CNTL);
1759 + writel(SYNC_WR_TO_CH_ZERO, mhdp->regs + FIFO_CNTL);
1760
1761 val = MAX_NUM_CH(2) | AUDIO_TYPE_LPCM | CFG_SUB_PCKT_NUM(4);
1762 - writel(val, dp->regs + SMPL2PKT_CNFG);
1763 - writel(SMPL2PKT_EN, dp->regs + SMPL2PKT_CNTL);
1764 + writel(val, mhdp->regs + SMPL2PKT_CNFG);
1765 + writel(SMPL2PKT_EN, mhdp->regs + SMPL2PKT_CNTL);
1766
1767 val = SPDIF_ENABLE | SPDIF_AVG_SEL | SPDIF_JITTER_BYPASS;
1768 - writel(val, dp->regs + SPDIF_CTRL_ADDR);
1769 + writel(val, mhdp->regs + SPDIF_CTRL_ADDR);
1770
1771 - clk_prepare_enable(dp->spdif_clk);
1772 - clk_set_rate(dp->spdif_clk, CDN_DP_SPDIF_CLK);
1773 + clk_prepare_enable(mhdp->spdif_clk);
1774 + clk_set_rate(mhdp->spdif_clk, CDNS_DP_SPDIF_CLK);
1775 }
1776
1777 -int cdn_dp_audio_config(struct cdn_dp_device *dp, struct audio_info *audio)
1778 +int cdns_mhdp_audio_config(struct cdns_mhdp_device *mhdp,
1779 + struct audio_info *audio)
1780 {
1781 int ret;
1782
1783 /* reset the spdif clk before config */
1784 if (audio->format == AFMT_SPDIF) {
1785 - reset_control_assert(dp->spdif_rst);
1786 - reset_control_deassert(dp->spdif_rst);
1787 + reset_control_assert(mhdp->spdif_rst);
1788 + reset_control_deassert(mhdp->spdif_rst);
1789 }
1790
1791 - ret = cdn_dp_reg_write(dp, CM_LANE_CTRL, LANE_REF_CYC);
1792 + ret = cdns_mhdp_reg_write(mhdp, CM_LANE_CTRL, LANE_REF_CYC);
1793 if (ret)
1794 goto err_audio_config;
1795
1796 - ret = cdn_dp_reg_write(dp, CM_CTRL, 0);
1797 + ret = cdns_mhdp_reg_write(mhdp, CM_CTRL, 0);
1798 if (ret)
1799 goto err_audio_config;
1800
1801 if (audio->format == AFMT_I2S)
1802 - cdn_dp_audio_config_i2s(dp, audio);
1803 + cdns_mhdp_audio_config_i2s(mhdp, audio);
1804 else if (audio->format == AFMT_SPDIF)
1805 - cdn_dp_audio_config_spdif(dp);
1806 + cdns_mhdp_audio_config_spdif(mhdp);
1807
1808 - ret = cdn_dp_reg_write(dp, AUDIO_PACK_CONTROL, AUDIO_PACK_EN);
1809 + ret = cdns_mhdp_reg_write(mhdp, AUDIO_PACK_CONTROL, AUDIO_PACK_EN);
1810
1811 err_audio_config:
1812 if (ret)
1813 - DRM_DEV_ERROR(dp->dev, "audio config failed: %d\n", ret);
1814 + DRM_DEV_ERROR(mhdp->dev, "audio config failed: %d\n", ret);
1815 return ret;
1816 }
1817 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.h
1818 +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.h
1819 @@ -387,7 +387,7 @@
1820 #define HDCP_TX_IS_RECEIVER_ID_VALID_EVENT BIT(7)
1821
1822 #define TU_SIZE 30
1823 -#define CDN_DP_MAX_LINK_RATE DP_LINK_BW_5_4
1824 +#define CDNS_DP_MAX_LINK_RATE DP_LINK_BW_5_4
1825
1826 /* audio */
1827 #define AUDIO_PACK_EN BIT(8)
1828 @@ -451,24 +451,96 @@ enum vic_bt_type {
1829 BT_709 = 0x1,
1830 };
1831
1832 -void cdn_dp_clock_reset(struct cdn_dp_device *dp);
1833 +enum audio_format {
1834 + AFMT_I2S = 0,
1835 + AFMT_SPDIF = 1,
1836 + AFMT_UNUSED,
1837 +};
1838 +
1839 +struct audio_info {
1840 + enum audio_format format;
1841 + int sample_rate;
1842 + int channels;
1843 + int sample_width;
1844 +};
1845 +
1846 +enum vic_pxl_encoding_format {
1847 + PXL_RGB = 0x1,
1848 + YCBCR_4_4_4 = 0x2,
1849 + YCBCR_4_2_2 = 0x4,
1850 + YCBCR_4_2_0 = 0x8,
1851 + Y_ONLY = 0x10,
1852 +};
1853 +
1854 +struct video_info {
1855 + bool h_sync_polarity;
1856 + bool v_sync_polarity;
1857 + bool interlaced;
1858 + int color_depth;
1859 + enum vic_pxl_encoding_format color_fmt;
1860 +};
1861 +
1862 +struct cdns_mhdp_host {
1863 + unsigned int link_rate;
1864 + u8 lanes_cnt;
1865 + u8 volt_swing;
1866 + u8 pre_emphasis;
1867 + u8 pattern_supp;
1868 + u8 fast_link;
1869 + u8 lane_mapping;
1870 + u8 enhanced;
1871 +};
1872 +
1873 +struct cdns_mhdp_sink {
1874 + unsigned int link_rate;
1875 + u8 lanes_cnt;
1876 + u8 pattern_supp;
1877 + u8 fast_link;
1878 + u8 enhanced;
1879 +};
1880 +
1881 +struct cdns_mhdp_device {
1882 + void __iomem *regs;
1883 +
1884 + struct device *dev;
1885 +
1886 + struct drm_dp_link link;
1887 + struct drm_connector connector;
1888 + struct clk *spdif_clk;
1889 + struct reset_control *spdif_rst;
1890 +
1891 + struct drm_dp_aux aux;
1892 + struct cdns_mhdp_host host;
1893 + struct cdns_mhdp_sink sink;
1894 + struct drm_bridge bridge;
1895 + struct phy *phy;
1896 + void __iomem *dbg_regs;
1897 +
1898 + struct video_info video_info;
1899 + struct drm_display_mode mode;
1900 + unsigned int fw_version;
1901 +};
1902
1903 -void cdn_dp_set_fw_clk(struct cdn_dp_device *dp, unsigned long clk);
1904 -int cdn_dp_load_firmware(struct cdn_dp_device *dp, const u32 *i_mem,
1905 - u32 i_size, const u32 *d_mem, u32 d_size);
1906 -int cdn_dp_set_firmware_active(struct cdn_dp_device *dp, bool enable);
1907 -int cdn_dp_set_host_cap(struct cdn_dp_device *dp, u8 lanes, bool flip);
1908 -int cdn_dp_event_config(struct cdn_dp_device *dp);
1909 -u32 cdn_dp_get_event(struct cdn_dp_device *dp);
1910 -int cdn_dp_get_hpd_status(struct cdn_dp_device *dp);
1911 -int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value);
1912 -int cdn_dp_dpcd_read(struct cdn_dp_device *dp, u32 addr, u8 *data, u16 len);
1913 -int cdn_dp_get_edid_block(void *dp, u8 *edid,
1914 - unsigned int block, size_t length);
1915 -int cdn_dp_train_link(struct cdn_dp_device *dp);
1916 -int cdn_dp_set_video_status(struct cdn_dp_device *dp, int active);
1917 -int cdn_dp_config_video(struct cdn_dp_device *dp);
1918 -int cdn_dp_audio_stop(struct cdn_dp_device *dp, struct audio_info *audio);
1919 -int cdn_dp_audio_mute(struct cdn_dp_device *dp, bool enable);
1920 -int cdn_dp_audio_config(struct cdn_dp_device *dp, struct audio_info *audio);
1921 +void cdns_mhdp_clock_reset(struct cdns_mhdp_device *mhdp);
1922 +void cdns_mhdp_set_fw_clk(struct cdns_mhdp_device *mhdp, unsigned long clk);
1923 +int cdns_mhdp_load_firmware(struct cdns_mhdp_device *mhdp, const u32 *i_mem,
1924 + u32 i_size, const u32 *d_mem, u32 d_size);
1925 +int cdns_mhdp_set_firmware_active(struct cdns_mhdp_device *mhdp, bool enable);
1926 +int cdns_mhdp_set_host_cap(struct cdns_mhdp_device *mhdp, u8 lanes, bool flip);
1927 +int cdns_mhdp_event_config(struct cdns_mhdp_device *mhdp);
1928 +u32 cdns_mhdp_get_event(struct cdns_mhdp_device *mhdp);
1929 +int cdns_mhdp_get_hpd_status(struct cdns_mhdp_device *mhdp);
1930 +int cdns_mhdp_dpcd_write(struct cdns_mhdp_device *mhdp, u32 addr, u8 value);
1931 +int cdns_mhdp_dpcd_read(struct cdns_mhdp_device *mhdp,
1932 + u32 addr, u8 *data, u16 len);
1933 +int cdns_mhdp_get_edid_block(void *mhdp, u8 *edid,
1934 + unsigned int block, size_t length);
1935 +int cdns_mhdp_train_link(struct cdns_mhdp_device *mhdp);
1936 +int cdns_mhdp_set_video_status(struct cdns_mhdp_device *mhdp, int active);
1937 +int cdns_mhdp_config_video(struct cdns_mhdp_device *mhdp);
1938 +int cdns_mhdp_audio_stop(struct cdns_mhdp_device *mhdp,
1939 + struct audio_info *audio);
1940 +int cdns_mhdp_audio_mute(struct cdns_mhdp_device *mhdp, bool enable);
1941 +int cdns_mhdp_audio_config(struct cdns_mhdp_device *mhdp,
1942 + struct audio_info *audio);
1943 #endif /* _CDN_DP_REG_H */