1 From fe1824851dd6f7d3ee6d5411edba4102dacea873 Mon Sep 17 00:00:00 2001
2 From: Sandor Yu <Sandor.yu@nxp.com>
3 Date: Wed, 11 Sep 2019 17:16:47 +0800
4 Subject: [PATCH] drm: bridge: cadence: move struct imx_mhdp_device to drm/imx
6 move struct imx_mhdp_device to drm/imx folder.
7 change the base address name from regs to regs_base.
8 add mhdp bus access function.
11 Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
13 drivers/gpu/drm/bridge/cadence/cdns-dp-core.c | 188 ++++++++++-----------
14 drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c | 190 ++++++++++------------
15 drivers/gpu/drm/bridge/cadence/cdns-mhdp-audio.c | 1 -
16 drivers/gpu/drm/bridge/cadence/cdns-mhdp-cec.c | 2 +-
17 drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c | 43 ++---
18 drivers/gpu/drm/bridge/cadence/cdns-mhdp-hdmi.c | 1 -
19 include/drm/bridge/cdns-mhdp-common.h | 67 +++++++-
20 include/drm/bridge/cdns-mhdp-imx.h | 121 --------------
21 8 files changed, 258 insertions(+), 355 deletions(-)
22 delete mode 100644 include/drm/bridge/cdns-mhdp-imx.h
24 --- a/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c
25 +++ b/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c
27 * (at your option) any later version.
31 -#include <drm/bridge/cdns-mhdp-imx.h>
32 +#include <drm/bridge/cdns-mhdp-common.h>
33 #include <drm/drm_atomic_helper.h>
34 #include <drm/drm_crtc_helper.h>
35 #include <drm/drm_edid.h>
37 #include <linux/mutex.h>
38 #include <linux/of_device.h>
40 -#define aux_to_hdp(x) container_of(x, struct imx_mhdp_device, aux)
43 * This function only implements native DPDC reads and writes
45 @@ -111,24 +108,24 @@ static void dp_pixel_clk_reset(struct cd
46 cdns_mhdp_reg_write(mhdp, SOURCE_HDTX_CAR, val);
49 -static void cdns_dp_mode_set(struct imx_mhdp_device *dp,
50 +static void cdns_dp_mode_set(struct cdns_mhdp_device *mhdp,
51 const struct drm_display_mode *mode)
53 struct drm_dp_link link;
54 - struct cdns_mhdp_device *mhdp = &dp->mhdp;
55 u32 lane_mapping = mhdp->lane_mapping;
59 memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
61 - dp->dual_mode = video_is_dual_mode(mode);
63 +// mhdp->dual_mode = video_is_dual_mode(mode);
65 dp_pixel_clk_reset(mhdp);
67 - hdp_plat_call(dp, pclock_change);
68 + cdns_mhdp_plat_call(mhdp, pclk_rate);
70 - hdp_plat_call(dp, phy_init);
71 + cdns_mhdp_plat_call(mhdp, phy_set);
73 ret = drm_dp_downstream_id(&mhdp->dp.aux, linkid);
75 @@ -168,7 +165,7 @@ static void cdns_dp_mode_set(struct imx_
76 /* initialize phy if lanes or link rate differnt */
77 if (mhdp->dp.link.num_lanes != mhdp->dp.num_lanes ||
78 mhdp->dp.link.rate != mhdp->dp.link_rate)
79 - hdp_plat_call(dp, phy_init);
80 + cdns_mhdp_plat_call(mhdp, phy_set);
83 ret = cdns_mhdp_set_video_status(mhdp, CONTROL_VIDEO_IDLE);
84 @@ -215,11 +212,11 @@ static void cdns_dp_mode_set(struct imx_
85 static enum drm_connector_status
86 cdns_dp_connector_detect(struct drm_connector *connector, bool force)
88 - struct imx_mhdp_device *dp = container_of(connector,
89 - struct imx_mhdp_device, mhdp.connector.base);
90 + struct cdns_mhdp_device *mhdp = container_of(connector,
91 + struct cdns_mhdp_device, connector.base);
94 - hpd = cdns_mhdp_read_hpd(&dp->mhdp);
95 + hpd = cdns_mhdp_read_hpd(mhdp);
98 return connector_status_connected;
99 @@ -235,15 +232,15 @@ cdns_dp_connector_detect(struct drm_conn
101 static int cdns_dp_connector_get_modes(struct drm_connector *connector)
103 - struct imx_mhdp_device *dp = container_of(connector,
104 - struct imx_mhdp_device, mhdp.connector.base);
105 + struct cdns_mhdp_device *mhdp = container_of(connector,
106 + struct cdns_mhdp_device, connector.base);
110 - edid = drm_do_get_edid(&dp->mhdp.connector.base,
111 - cdns_mhdp_get_edid_block, &dp->mhdp);
112 + edid = drm_do_get_edid(&mhdp->connector.base,
113 + cdns_mhdp_get_edid_block, mhdp);
115 - dev_info(dp->mhdp.dev, "%x,%x,%x,%x,%x,%x,%x,%x\n",
116 + dev_info(mhdp->dev, "%x,%x,%x,%x,%x,%x,%x,%x\n",
117 edid->header[0], edid->header[1],
118 edid->header[2], edid->header[3],
119 edid->header[4], edid->header[5],
120 @@ -273,9 +270,9 @@ static const struct drm_connector_helper
122 static int cdns_dp_bridge_attach(struct drm_bridge *bridge)
124 - struct imx_mhdp_device *dp = bridge->driver_private;
125 + struct cdns_mhdp_device *mhdp = bridge->driver_private;
126 struct drm_encoder *encoder = bridge->encoder;
127 - struct drm_connector *connector = &dp->mhdp.connector.base;
128 + struct drm_connector *connector = &mhdp->connector.base;
130 connector->interlace_allowed = 1;
131 connector->polled = DRM_CONNECTOR_POLL_HPD;
132 @@ -319,9 +316,9 @@ static void cdns_dp_bridge_mode_set(stru
133 const struct drm_display_mode *orig_mode,
134 const struct drm_display_mode *mode)
136 - struct imx_mhdp_device *dp = bridge->driver_private;
137 - struct drm_display_info *display_info = &dp->mhdp.connector.base.display_info;
138 - struct video_info *video = &dp->mhdp.video_info;
139 + struct cdns_mhdp_device *mhdp = bridge->driver_private;
140 + struct drm_display_info *display_info = &mhdp->connector.base.display_info;
141 + struct video_info *video = &mhdp->video_info;
143 switch (display_info->bpc) {
145 @@ -341,11 +338,11 @@ static void cdns_dp_bridge_mode_set(stru
147 DRM_INFO("Mode: %dx%dp%d\n", mode->hdisplay, mode->vdisplay, mode->clock);
149 - mutex_lock(&dp->lock);
150 + mutex_lock(&mhdp->lock);
152 - cdns_dp_mode_set(dp, mode);
153 + cdns_dp_mode_set(mhdp, mode);
155 - mutex_unlock(&dp->lock);
156 + mutex_unlock(&mhdp->lock);
159 static void cdn_hdp_bridge_enable(struct drm_bridge *bridge)
160 @@ -354,8 +351,7 @@ static void cdn_hdp_bridge_enable(struct
162 static void cdn_hdp_bridge_disable(struct drm_bridge *bridge)
164 - struct imx_mhdp_device *dp = bridge->driver_private;
165 - struct cdns_mhdp_device *mhdp = &dp->mhdp;
166 + struct cdns_mhdp_device *mhdp = bridge->driver_private;
168 cdns_mhdp_set_video_status(mhdp, CONTROL_VIDEO_IDLE);
169 drm_dp_link_power_down(&mhdp->dp.aux, &mhdp->dp.link);
170 @@ -371,29 +367,29 @@ static const struct drm_bridge_funcs cdn
172 static void hotplug_work_func(struct work_struct *work)
174 - struct imx_mhdp_device *dp = container_of(work,
175 - struct imx_mhdp_device, hotplug_work.work);
176 - struct drm_connector *connector = &dp->mhdp.connector.base;
177 + struct cdns_mhdp_device *mhdp = container_of(work,
178 + struct cdns_mhdp_device, hotplug_work.work);
179 + struct drm_connector *connector = &mhdp->connector.base;
181 drm_helper_hpd_irq_event(connector->dev);
183 if (connector->status == connector_status_connected) {
184 DRM_INFO("HDMI/DP Cable Plug In\n");
185 - enable_irq(dp->irq[IRQ_OUT]);
186 + enable_irq(mhdp->irq[IRQ_OUT]);
187 } else if (connector->status == connector_status_disconnected) {
188 /* Cable Disconnedted */
189 DRM_INFO("HDMI/DP Cable Plug Out\n");
190 - enable_irq(dp->irq[IRQ_IN]);
191 + enable_irq(mhdp->irq[IRQ_IN]);
195 static irqreturn_t cdns_dp_irq_thread(int irq, void *data)
197 - struct imx_mhdp_device *dp = data;
198 + struct cdns_mhdp_device *mhdp = data;
200 disable_irq_nosync(irq);
202 - mod_delayed_work(system_wq, &dp->hotplug_work,
203 + mod_delayed_work(system_wq, &mhdp->hotplug_work,
204 msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
207 @@ -430,111 +426,92 @@ static void cdns_dp_parse_dt(struct cdns
208 mhdp->dp.link.rate= mhdp->dp.link_rate;
211 -static struct imx_mhdp_device *
212 -__cdns_dp_probe(struct platform_device *pdev,
213 - const struct cdn_plat_data *plat_data)
214 +static int __cdns_dp_probe(struct platform_device *pdev,
215 + struct cdns_mhdp_device *mhdp)
217 struct device *dev = &pdev->dev;
218 - struct imx_mhdp_device *dp;
219 struct resource *iores = NULL;
222 - dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL);
224 - return ERR_PTR(-ENOMEM);
226 - dp->plat_data = plat_data;
227 - dp->mhdp.dev = dev;
229 - mutex_init(&dp->lock);
230 - mutex_init(&dp->audio_mutex);
231 - spin_lock_init(&dp->audio_lock);
232 + mutex_init(&mhdp->lock);
234 - INIT_DELAYED_WORK(&dp->hotplug_work, hotplug_work_func);
235 + INIT_DELAYED_WORK(&mhdp->hotplug_work, hotplug_work_func);
237 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
238 - dp->mhdp.regs = devm_ioremap(dev, iores->start, resource_size(iores));
239 - if (IS_ERR(dp->mhdp.regs)) {
240 - ret = PTR_ERR(dp->mhdp.regs);
243 + mhdp->regs_base = devm_ioremap(dev, iores->start, resource_size(iores));
244 + if (IS_ERR(mhdp->regs_base))
248 iores = platform_get_resource(pdev, IORESOURCE_MEM, 1);
249 - dp->regs_ss = devm_ioremap(dev, iores->start, resource_size(iores));
250 - if (IS_ERR(dp->regs_ss)) {
251 - ret = PTR_ERR(dp->regs_ss);
255 + mhdp->regs_sec = devm_ioremap(dev, iores->start, resource_size(iores));
256 + if (IS_ERR(mhdp->regs_sec))
259 - dp->irq[IRQ_IN] = platform_get_irq_byname(pdev, "plug_in");
260 - if (dp->irq[IRQ_IN] < 0)
261 + mhdp->irq[IRQ_IN] = platform_get_irq_byname(pdev, "plug_in");
262 + if (mhdp->irq[IRQ_IN] < 0)
263 dev_info(dev, "No plug_in irq number\n");
265 - dp->irq[IRQ_OUT] = platform_get_irq_byname(pdev, "plug_out");
266 - if (dp->irq[IRQ_OUT] < 0)
267 + mhdp->irq[IRQ_OUT] = platform_get_irq_byname(pdev, "plug_out");
268 + if (mhdp->irq[IRQ_OUT] < 0)
269 dev_info(dev, "No plug_out irq number\n");
271 - cdns_dp_parse_dt(&dp->mhdp);
272 + cdns_dp_parse_dt(mhdp);
274 - dp->dual_mode = false;
275 - hdp_plat_call(dp, fw_init);
276 +// mhdp->dual_mode = false;
277 + cdns_mhdp_plat_call(mhdp, firmware_init);
279 /* DP FW alive check */
280 - ret = cdns_mhdp_check_alive(&dp->mhdp);
281 + ret = cdns_mhdp_check_alive(mhdp);
283 DRM_ERROR("NO dp FW running\n");
284 - return ERR_PTR(-ENXIO);
288 /* DP PHY init before AUX init */
289 - hdp_plat_call(dp, phy_init);
290 + cdns_mhdp_plat_call(mhdp, phy_set);
292 /* Enable Hotplug Detect IRQ thread */
293 - irq_set_status_flags(dp->irq[IRQ_IN], IRQ_NOAUTOEN);
294 - ret = devm_request_threaded_irq(dev, dp->irq[IRQ_IN],
295 + irq_set_status_flags(mhdp->irq[IRQ_IN], IRQ_NOAUTOEN);
296 + ret = devm_request_threaded_irq(dev, mhdp->irq[IRQ_IN],
297 NULL, cdns_dp_irq_thread,
298 IRQF_ONESHOT, dev_name(dev),
302 dev_err(dev, "can't claim irq %d\n",
305 + mhdp->irq[IRQ_IN]);
309 - irq_set_status_flags(dp->irq[IRQ_OUT], IRQ_NOAUTOEN);
310 - ret = devm_request_threaded_irq(dev, dp->irq[IRQ_OUT],
311 + irq_set_status_flags(mhdp->irq[IRQ_OUT], IRQ_NOAUTOEN);
312 + ret = devm_request_threaded_irq(dev, mhdp->irq[IRQ_OUT],
313 NULL, cdns_dp_irq_thread,
314 IRQF_ONESHOT, dev_name(dev),
318 dev_err(dev, "can't claim irq %d\n",
321 + mhdp->irq[IRQ_OUT]);
324 - if (cdns_mhdp_read_hpd(&dp->mhdp))
325 - enable_irq(dp->irq[IRQ_OUT]);
327 + if (cdns_mhdp_read_hpd(mhdp))
328 + enable_irq(mhdp->irq[IRQ_OUT]);
330 - enable_irq(dp->irq[IRQ_IN]);
331 + enable_irq(mhdp->irq[IRQ_IN]);
333 - dp->mhdp.bridge.base.driver_private = dp;
334 - dp->mhdp.bridge.base.funcs = &cdns_dp_bridge_funcs;
335 + mhdp->bridge.base.driver_private = mhdp;
336 + mhdp->bridge.base.funcs = &cdns_dp_bridge_funcs;
338 - dp->mhdp.bridge.base.of_node = dev->of_node;
339 + mhdp->bridge.base.of_node = dev->of_node;
342 - dev_set_drvdata(dev, &dp->mhdp);
343 + dev_set_drvdata(dev, mhdp);
345 /* register audio driver */
346 cdns_mhdp_register_audio_driver(dev);
348 - dp_aux_init(&dp->mhdp, dev);
351 + dp_aux_init(mhdp, dev);
354 - return ERR_PTR(ret);
358 static void __cdns_dp_remove(struct cdns_mhdp_device *mhdp)
359 @@ -547,15 +524,15 @@ static void __cdns_dp_remove(struct cdns
360 * Probe/remove API, used from platforms based on the DRM bridge API.
362 int cdns_dp_probe(struct platform_device *pdev,
363 - const struct cdn_plat_data *plat_data)
364 + struct cdns_mhdp_device *mhdp)
366 - struct imx_mhdp_device *dp;
369 - dp = __cdns_dp_probe(pdev, plat_data);
371 - return PTR_ERR(dp);
372 + ret = __cdns_dp_probe(pdev, mhdp);
376 - drm_bridge_add(&dp->mhdp.bridge.base);
377 + drm_bridge_add(&mhdp->bridge.base);
381 @@ -575,16 +552,15 @@ EXPORT_SYMBOL_GPL(cdns_dp_remove);
382 * Bind/unbind API, used from platforms based on the component framework.
384 int cdns_dp_bind(struct platform_device *pdev, struct drm_encoder *encoder,
385 - const struct cdn_plat_data *plat_data)
386 + struct cdns_mhdp_device *mhdp)
388 - struct imx_mhdp_device *dp;
391 - dp = __cdns_dp_probe(pdev, plat_data);
393 - return PTR_ERR(dp);
394 + ret = __cdns_dp_probe(pdev, mhdp);
398 - ret = drm_bridge_attach(encoder, &dp->mhdp.bridge.base, NULL);
399 + ret = drm_bridge_attach(encoder, &mhdp->bridge.base, NULL);
401 cdns_dp_remove(pdev);
402 DRM_ERROR("Failed to initialize bridge with drm\n");
403 --- a/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c
404 +++ b/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c
406 * (at your option) any later version.
409 -#include <drm/bridge/cdns-mhdp-imx.h>
410 +#include <drm/bridge/cdns-mhdp-common.h>
411 #include <drm/drm_atomic_helper.h>
412 #include <drm/drm_crtc_helper.h>
413 #include <drm/drm_edid.h>
414 @@ -60,8 +60,6 @@ static int hdmi_sink_config(struct cdns_
415 static void hdmi_lanes_config(struct cdns_mhdp_device *mhdp)
418 - /* For imx8qm lane_mapping = 0x93
419 - * For imx8mq lane_mapping = 0xe4*/
420 cdns_mhdp_reg_write(mhdp, LANES_CONFIG, 0x00400000 | mhdp->lane_mapping);
423 @@ -216,12 +214,12 @@ void cdns_hdmi_mode_set(struct cdns_mhdp
424 static enum drm_connector_status
425 cdns_hdmi_connector_detect(struct drm_connector *connector, bool force)
427 - struct imx_mhdp_device *hdmi =
428 - container_of(connector, struct imx_mhdp_device, mhdp.connector.base);
429 + struct cdns_mhdp_device *mhdp =
430 + container_of(connector, struct cdns_mhdp_device, connector.base);
434 - hpd = cdns_mhdp_read_hpd(&hdmi->mhdp);
435 + hpd = cdns_mhdp_read_hpd(mhdp);
438 /* Cable Connected */
439 @@ -238,15 +236,15 @@ cdns_hdmi_connector_detect(struct drm_co
441 static int cdns_hdmi_connector_get_modes(struct drm_connector *connector)
443 - struct imx_mhdp_device *hdmi = container_of(connector, struct imx_mhdp_device,
444 - mhdp.connector.base);
445 + struct cdns_mhdp_device *mhdp =
446 + container_of(connector, struct cdns_mhdp_device, connector.base);
450 - edid = drm_do_get_edid(&hdmi->mhdp.connector.base,
451 - cdns_hdmi_get_edid_block, &hdmi->mhdp);
452 + edid = drm_do_get_edid(&mhdp->connector.base,
453 + cdns_hdmi_get_edid_block, mhdp);
455 - dev_info(hdmi->mhdp.dev, "%x,%x,%x,%x,%x,%x,%x,%x\n",
456 + dev_info(mhdp->dev, "%x,%x,%x,%x,%x,%x,%x,%x\n",
457 edid->header[0], edid->header[1],
458 edid->header[2], edid->header[3],
459 edid->header[4], edid->header[5],
460 @@ -276,9 +274,9 @@ static const struct drm_connector_helper
462 static int cdns_hdmi_bridge_attach(struct drm_bridge *bridge)
464 - struct imx_mhdp_device *hdmi = bridge->driver_private;
465 + struct cdns_mhdp_device *mhdp = bridge->driver_private;
466 struct drm_encoder *encoder = bridge->encoder;
467 - struct drm_connector *connector = &hdmi->mhdp.connector.base;
468 + struct drm_connector *connector = &mhdp->connector.base;
470 connector->interlace_allowed = 1;
471 connector->polled = DRM_CONNECTOR_POLL_HPD;
472 @@ -319,9 +317,9 @@ static void cdns_hdmi_bridge_mode_set(st
473 const struct drm_display_mode *orig_mode,
474 const struct drm_display_mode *mode)
476 - struct imx_mhdp_device *hdmi = bridge->driver_private;
477 - struct drm_display_info *display_info = &hdmi->mhdp.connector.base.display_info;
478 - struct video_info *video = &hdmi->mhdp.video_info;
479 + struct cdns_mhdp_device *mhdp = bridge->driver_private;
480 + struct drm_display_info *display_info = &mhdp->connector.base.display_info;
481 + struct video_info *video = &mhdp->video_info;
483 switch (display_info->bpc) {
485 @@ -339,23 +337,24 @@ static void cdns_hdmi_bridge_mode_set(st
486 video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC);
487 video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC);
489 - mutex_lock(&hdmi->lock);
490 + mutex_lock(&mhdp->lock);
492 DRM_INFO("Mode: %dx%dp%d\n", mode->hdisplay, mode->vdisplay, mode->clock);
494 - memcpy(&hdmi->mhdp.mode, mode, sizeof(struct drm_display_mode));
495 + memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
497 - hdmi->dual_mode = video_is_dual_mode(mode);
499 +// hdmi->dual_mode = video_is_dual_mode(mode);
501 - hdmi_lanes_config(&hdmi->mhdp);
502 + hdmi_lanes_config(mhdp);
504 - hdp_plat_call(hdmi, pclock_change);
505 + cdns_mhdp_plat_call(mhdp, pclk_rate);
507 - hdp_plat_call(hdmi, phy_init);
508 + cdns_mhdp_plat_call(mhdp, phy_set);
510 - cdns_hdmi_mode_set(&hdmi->mhdp);
511 + cdns_hdmi_mode_set(mhdp);
513 - mutex_unlock(&hdmi->lock);
514 + mutex_unlock(&mhdp->lock);
517 static const struct drm_bridge_funcs cdns_hdmi_bridge_funcs = {
518 @@ -366,30 +365,30 @@ static const struct drm_bridge_funcs cdn
520 static void hotplug_work_func(struct work_struct *work)
522 - struct imx_mhdp_device *hdmi = container_of(work,
523 - struct imx_mhdp_device, hotplug_work.work);
524 - struct drm_connector *connector = &hdmi->mhdp.connector.base;
525 + struct cdns_mhdp_device *mhdp = container_of(work,
526 + struct cdns_mhdp_device, hotplug_work.work);
527 + struct drm_connector *connector = &mhdp->connector.base;
529 drm_helper_hpd_irq_event(connector->dev);
531 if (connector->status == connector_status_connected) {
532 /* Cable Connected */
533 DRM_INFO("HDMI Cable Plug In\n");
534 - enable_irq(hdmi->irq[IRQ_OUT]);
535 + enable_irq(mhdp->irq[IRQ_OUT]);
536 } else if (connector->status == connector_status_disconnected) {
537 /* Cable Disconnedted */
538 DRM_INFO("HDMI Cable Plug Out\n");
539 - enable_irq(hdmi->irq[IRQ_IN]);
540 + enable_irq(mhdp->irq[IRQ_IN]);
544 static irqreturn_t cdns_hdmi_irq_thread(int irq, void *data)
546 - struct imx_mhdp_device *hdmi = data;
547 + struct cdns_mhdp_device *mhdp = data;
549 disable_irq_nosync(irq);
551 - mod_delayed_work(system_wq, &hdmi->hotplug_work,
552 + mod_delayed_work(system_wq, &mhdp->hotplug_work,
553 msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
556 @@ -408,109 +407,99 @@ static void cdns_hdmi_parse_dt(struct cd
557 dev_info(mhdp->dev, "lane-mapping 0x%02x\n", mhdp->lane_mapping);
560 -static struct imx_mhdp_device *
561 -__cdns_hdmi_probe(struct platform_device *pdev,
562 - const struct cdn_plat_data *plat_data)
563 +static int __cdns_hdmi_probe(struct platform_device *pdev,
564 + struct cdns_mhdp_device *mhdp)
566 struct device *dev = &pdev->dev;
567 - struct device_node *np = dev->of_node;
568 struct platform_device_info pdevinfo;
569 - struct imx_mhdp_device *hdmi;
570 struct resource *iores = NULL;
573 - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
575 - return ERR_PTR(-ENOMEM);
577 - hdmi->plat_data = plat_data;
578 - hdmi->mhdp.dev = dev;
580 - mutex_init(&hdmi->lock);
581 - mutex_init(&hdmi->audio_mutex);
582 - spin_lock_init(&hdmi->audio_lock);
583 + mutex_init(&mhdp->lock);
585 - INIT_DELAYED_WORK(&hdmi->hotplug_work, hotplug_work_func);
586 + INIT_DELAYED_WORK(&mhdp->hotplug_work, hotplug_work_func);
588 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
589 - hdmi->mhdp.regs = devm_ioremap(dev, iores->start, resource_size(iores));
590 - if (IS_ERR(hdmi->mhdp.regs)) {
591 - ret = PTR_ERR(hdmi->mhdp.regs);
593 + mhdp->regs_base = devm_ioremap(dev, iores->start, resource_size(iores));
594 + if (IS_ERR(mhdp->regs_base)) {
595 + dev_err(dev, "No regs_base memory\n");
599 + /* sec register base */
600 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 1);
601 + mhdp->regs_sec = devm_ioremap(dev, iores->start, resource_size(iores));
602 + if (IS_ERR(mhdp->regs_sec)) {
603 + dev_err(dev, "No regs_sec memory\n");
607 - /* csr register base */
608 - hdmi->regmap_csr = syscon_regmap_lookup_by_phandle(np, "csr");
609 - if (IS_ERR(hdmi->regmap_csr)) {
610 - dev_info(dev, "No csr regmap\n");
613 - hdmi->irq[IRQ_IN] = platform_get_irq_byname(pdev, "plug_in");
614 - if (hdmi->irq[IRQ_IN] < 0) {
615 + mhdp->irq[IRQ_IN] = platform_get_irq_byname(pdev, "plug_in");
616 + if (mhdp->irq[IRQ_IN] < 0) {
617 dev_info(dev, "No plug_in irq number\n");
618 - return ERR_PTR(-EPROBE_DEFER);
619 + return -EPROBE_DEFER;
622 - hdmi->irq[IRQ_OUT] = platform_get_irq_byname(pdev, "plug_out");
623 - if (hdmi->irq[IRQ_OUT] < 0) {
624 + mhdp->irq[IRQ_OUT] = platform_get_irq_byname(pdev, "plug_out");
625 + if (mhdp->irq[IRQ_OUT] < 0) {
626 dev_info(dev, "No plug_out irq number\n");
627 - return ERR_PTR(-EPROBE_DEFER);
628 + return -EPROBE_DEFER;
631 /* Initialize dual_mode to false */
632 - hdmi->dual_mode = false;
633 +// hdmi->dual_mode = false;
636 - hdp_plat_call(hdmi, fw_init);
637 + cdns_mhdp_plat_call(mhdp, firmware_init);
639 /* HDMI FW alive check */
640 - ret = cdns_mhdp_check_alive(&hdmi->mhdp);
641 + ret = cdns_mhdp_check_alive(mhdp);
643 - DRM_ERROR("NO HDMI FW running\n");
644 - return ERR_PTR(-ENXIO);
645 + dev_err(dev, "NO HDMI FW running\n");
649 /* Enable Hotplug Detect thread */
650 - irq_set_status_flags(hdmi->irq[IRQ_IN], IRQ_NOAUTOEN);
651 - ret = devm_request_threaded_irq(dev, hdmi->irq[IRQ_IN],
652 + irq_set_status_flags(mhdp->irq[IRQ_IN], IRQ_NOAUTOEN);
653 + ret = devm_request_threaded_irq(dev, mhdp->irq[IRQ_IN],
654 NULL, cdns_hdmi_irq_thread,
655 IRQF_ONESHOT, dev_name(dev),
660 dev_err(dev, "can't claim irq %d\n",
661 - hdmi->irq[IRQ_IN]);
663 + mhdp->irq[IRQ_IN]);
667 - irq_set_status_flags(hdmi->irq[IRQ_OUT], IRQ_NOAUTOEN);
668 - ret = devm_request_threaded_irq(dev, hdmi->irq[IRQ_OUT],
669 + irq_set_status_flags(mhdp->irq[IRQ_OUT], IRQ_NOAUTOEN);
670 + ret = devm_request_threaded_irq(dev, mhdp->irq[IRQ_OUT],
671 NULL, cdns_hdmi_irq_thread,
672 IRQF_ONESHOT, dev_name(dev),
677 dev_err(dev, "can't claim irq %d\n",
678 - hdmi->irq[IRQ_OUT]);
680 + mhdp->irq[IRQ_OUT]);
684 - cdns_hdmi_parse_dt(&hdmi->mhdp);
685 + cdns_hdmi_parse_dt(mhdp);
687 - if (cdns_mhdp_read_hpd(&hdmi->mhdp))
688 - enable_irq(hdmi->irq[IRQ_OUT]);
689 + if (cdns_mhdp_read_hpd(mhdp))
690 + enable_irq(mhdp->irq[IRQ_OUT]);
692 - enable_irq(hdmi->irq[IRQ_IN]);
693 + enable_irq(mhdp->irq[IRQ_IN]);
695 - hdmi->mhdp.bridge.base.driver_private = hdmi;
696 - hdmi->mhdp.bridge.base.funcs = &cdns_hdmi_bridge_funcs;
697 + mhdp->bridge.base.driver_private = mhdp;
698 + mhdp->bridge.base.funcs = &cdns_hdmi_bridge_funcs;
700 - hdmi->mhdp.bridge.base.of_node = dev->of_node;
701 + mhdp->bridge.base.of_node = dev->of_node;
704 memset(&pdevinfo, 0, sizeof(pdevinfo));
705 pdevinfo.parent = dev;
706 pdevinfo.id = PLATFORM_DEVID_AUTO;
708 - dev_set_drvdata(dev, &hdmi->mhdp);
709 + dev_set_drvdata(dev, mhdp);
711 /* register audio driver */
712 cdns_mhdp_register_audio_driver(dev);
713 @@ -520,11 +509,7 @@ __cdns_hdmi_probe(struct platform_device
714 cdns_mhdp_register_cec_driver(dev);
721 - return ERR_PTR(ret);
725 static void __cdns_hdmi_remove(struct cdns_mhdp_device *mhdp)
726 @@ -540,15 +525,15 @@ static void __cdns_hdmi_remove(struct cd
727 * Probe/remove API, used from platforms based on the DRM bridge API.
729 int cdns_hdmi_probe(struct platform_device *pdev,
730 - const struct cdn_plat_data *plat_data)
731 + struct cdns_mhdp_device *mhdp)
733 - struct imx_mhdp_device *hdmi;
736 - hdmi = __cdns_hdmi_probe(pdev, plat_data);
738 - return PTR_ERR(hdmi);
739 + ret = __cdns_hdmi_probe(pdev, mhdp);
743 - drm_bridge_add(&hdmi->mhdp.bridge.base);
744 + drm_bridge_add(&mhdp->bridge.base);
748 @@ -568,16 +553,15 @@ EXPORT_SYMBOL_GPL(cdns_hdmi_remove);
749 * Bind/unbind API, used from platforms based on the component framework.
751 int cdns_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
752 - const struct cdn_plat_data *plat_data)
753 + struct cdns_mhdp_device *mhdp)
755 - struct imx_mhdp_device *hdmi;
758 - hdmi = __cdns_hdmi_probe(pdev, plat_data);
760 - return PTR_ERR(hdmi);
761 + ret = __cdns_hdmi_probe(pdev, mhdp);
765 - ret = drm_bridge_attach(encoder, &hdmi->mhdp.bridge.base, NULL);
766 + ret = drm_bridge_attach(encoder, &mhdp->bridge.base, NULL);
768 cdns_hdmi_remove(pdev);
769 DRM_ERROR("Failed to initialize bridge with drm\n");
770 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-audio.c
771 +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-audio.c
773 #include <linux/reset.h>
774 #include <drm/bridge/cdns-mhdp-common.h>
775 #include <sound/hdmi-codec.h>
776 -#include <drm/bridge/cdns-mhdp-imx.h>
777 #include <drm/drm_of.h>
778 #include <drm/drmP.h>
780 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-cec.c
781 +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-cec.c
782 @@ -344,4 +344,4 @@ int cdns_mhdp_unregister_cec_driver(stru
784 MODULE_AUTHOR("Sandor.Yu@NXP.com");
785 MODULE_LICENSE("GPL");
786 -MODULE_DESCRIPTION("NXP CDNS MHDP CEC driver");
787 +MODULE_DESCRIPTION("NXP CDNS MHDP HDMI CEC driver");
788 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c
789 +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-common.c
791 #include <asm/unaligned.h>
793 #include <drm/bridge/cdns-mhdp-common.h>
794 -#include <drm/bridge/cdns-mhdp-imx.h>
795 #include <drm/drm_modes.h>
796 #include <drm/drm_print.h>
797 #include <linux/regmap.h>
798 @@ -74,18 +73,20 @@ static inline void put_unaligned_be24(u3
800 u32 cdns_mhdp_bus_read(struct cdns_mhdp_device *mhdp, u32 offset)
802 - struct imx_mhdp_device *hdmi = container_of(mhdp, struct imx_mhdp_device, mhdp);
806 - if (offset >= 0x1000 && hdmi->regmap_csr) {
807 + if (mhdp->bus_type == BUS_TYPE_LOW4K_SAPB) {
808 + /* Remap address to low 4K SAPB bus */
809 + writel(offset >> 12, mhdp->regs_sec + 0xc);
810 + val = readl((offset & 0xfff) + mhdp->regs_base);
811 + } else if (mhdp->bus_type == BUS_TYPE_LOW4K_APB) {
812 /* Remap address to low 4K memory */
813 - regmap_write(hdmi->regmap_csr, hdmi->csr_ctrl0_reg, offset >> 12);
814 - val = readl((offset & 0xfff) + mhdp->regs);
815 - /* Restore address mapping */
816 - regmap_write(hdmi->regmap_csr, hdmi->csr_ctrl0_reg, 0);
818 - val = readl(mhdp->regs + offset);
819 + writel(offset >> 12, mhdp->regs_sec + 8);
820 + val = readl((offset & 0xfff) + mhdp->regs_base);
821 + } else if (mhdp->bus_type == BUS_TYPE_NORMAL_SAPB)
822 + val = readl(mhdp->regs_sec + offset);
824 + val = readl(mhdp->regs_base + offset);
828 @@ -93,18 +94,18 @@ EXPORT_SYMBOL(cdns_mhdp_bus_read);
830 void cdns_mhdp_bus_write(u32 val, struct cdns_mhdp_device *mhdp, u32 offset)
832 - struct imx_mhdp_device *hdmi = container_of(mhdp, struct imx_mhdp_device, mhdp);
835 - if (offset >= 0x1000 && hdmi->regmap_csr) {
836 + if (mhdp->bus_type == BUS_TYPE_LOW4K_SAPB) {
837 + /* Remap address to low 4K SAPB bus */
838 + writel(offset >> 12, mhdp->regs_sec + 0xc);
839 + writel(val, (offset & 0xfff) + mhdp->regs_base);
840 + } else if (mhdp->bus_type == BUS_TYPE_LOW4K_APB) {
841 /* Remap address to low 4K memory */
842 - regmap_write(hdmi->regmap_csr, hdmi->csr_ctrl0_reg, offset >> 12);
843 - writel(val, (offset & 0xfff) + mhdp->regs);
844 - /* Restore address mapping */
845 - regmap_write(hdmi->regmap_csr, hdmi->csr_ctrl0_reg, 0);
848 - writel(val, mhdp->regs + offset);
849 + writel(offset >> 12, mhdp->regs_sec + 8);
850 + writel(val, (offset & 0xfff) + mhdp->regs_base);
851 + } else if (mhdp->bus_type == BUS_TYPE_NORMAL_SAPB)
852 + writel(val, mhdp->regs_sec + offset);
854 + writel(val, mhdp->regs_base + offset);
856 EXPORT_SYMBOL(cdns_mhdp_bus_write);
858 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-hdmi.c
859 +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-hdmi.c
861 #include <drm/drmP.h>
862 #include <linux/io.h>
863 #include <drm/bridge/cdns-mhdp-common.h>
864 -#include <drm/bridge/cdns-mhdp-imx.h>
865 #include <linux/regmap.h>
867 void cdns_mhdp_infoframe_set(struct cdns_mhdp_device *mhdp,
868 --- a/include/drm/bridge/cdns-mhdp-common.h
869 +++ b/include/drm/bridge/cdns-mhdp-common.h
872 #define HOTPLUG_DEBOUNCE_MS 200
878 +#define cdns_mhdp_plat_call(mhdp, operation) \
879 + (!(mhdp) ? -ENODEV : (((mhdp)->plat_data && (mhdp)->plat_data->operation) ? \
880 + (mhdp)->plat_data->operation(mhdp) : ENOIOCTLCMD))
882 +/* bus access type */
884 + BUS_TYPE_NORMAL_APB = 0,
885 + BUS_TYPE_NORMAL_SAPB = 1,
886 + BUS_TYPE_LOW4K_APB = 2,
887 + BUS_TYPE_LOW4K_SAPB = 3,
890 enum voltage_swing_level {
893 @@ -616,8 +632,33 @@ struct cdns_mhdp_cec {
897 +struct cdns_plat_data {
898 + /* Vendor PHY support */
899 + int (*bind)(struct platform_device *pdev,
900 + struct drm_encoder *encoder,
901 + struct cdns_mhdp_device *mhdp);
902 + void (*unbind)(struct device *dev);
904 + void (*plat_init)(struct cdns_mhdp_device *mhdp);
905 + void (*plat_deinit)(struct cdns_mhdp_device *mhdp);
907 + int (*phy_set)(struct cdns_mhdp_device *mhdp);
908 + int (*firmware_init)(struct cdns_mhdp_device *mhdp);
909 + void (*pclk_rate)(struct cdns_mhdp_device *mhdp);
911 + int (*power_on)(struct cdns_mhdp_device *mhdp);
912 + int (*power_off)(struct cdns_mhdp_device *mhdp);
919 struct cdns_mhdp_device {
920 - void __iomem *regs;
921 + void __iomem *regs_base;
922 + void __iomem *regs_sec;
928 @@ -642,6 +683,9 @@ struct cdns_mhdp_device {
938 @@ -663,6 +707,8 @@ struct cdns_mhdp_device {
942 + const struct cdns_plat_data *plat_data;
946 u32 cdns_mhdp_bus_read(struct cdns_mhdp_device *mhdp, u32 offset);
947 @@ -727,6 +773,25 @@ int cdns_hdmi_disable_gcp(struct cdns_mh
948 int cdns_hdmi_enable_gcp(struct cdns_mhdp_device *mhdp);
950 bool cdns_mhdp_check_alive(struct cdns_mhdp_device *mhdp);
953 +int cdns_hdmi_probe(struct platform_device *pdev,
954 + struct cdns_mhdp_device *mhdp);
955 +void cdns_hdmi_remove(struct platform_device *pdev);
956 +void cdns_hdmi_unbind(struct device *dev);
957 +int cdns_hdmi_bind(struct platform_device *pdev,
958 + struct drm_encoder *encoder, struct cdns_mhdp_device *mhdp);
959 +void cdns_hdmi_set_sample_rate(struct cdns_mhdp_device *mhdp, unsigned int rate);
960 +void cdns_hdmi_audio_enable(struct cdns_mhdp_device *mhdp);
961 +void cdns_hdmi_audio_disable(struct cdns_mhdp_device *mhdp);
963 +int cdns_dp_probe(struct platform_device *pdev,
964 + struct cdns_mhdp_device *mhdp);
965 +void cdns_dp_remove(struct platform_device *pdev);
966 +void cdns_dp_unbind(struct device *dev);
967 +int cdns_dp_bind(struct platform_device *pdev,
968 + struct drm_encoder *encoder, struct cdns_mhdp_device *mhdp);
971 #ifdef CONFIG_DRM_CDNS_HDMI_CEC
972 int cdns_mhdp_register_cec_driver(struct device *dev);
973 --- a/include/drm/bridge/cdns-mhdp-imx.h
977 - * Cadence High-Definition Multimedia Interface (HDMI) driver
979 - * Copyright (C) 2019 NXP Semiconductor, Inc.
981 - * This program is free software; you can redistribute it and/or modify
982 - * it under the terms of the GNU General Public License as published by
983 - * the Free Software Foundation; either version 2 of the License, or
984 - * (at your option) any later version.
987 -#ifndef CDNS_MHDP_IMX_H_
988 -#define CDNS_MHDP_IMX_H_
990 -#include <drm/bridge/cdns-mhdp-common.h>
996 -#define hdp_plat_call(hdp, operation) \
997 - (!(hdp) ? -ENODEV : (((hdp)->plat_data && (hdp)->plat_data->operation) ? \
998 - (hdp)->plat_data->operation(hdp) : ENOIOCTLCMD))
1000 -#define HDP_DUAL_MODE_MIN_PCLK_RATE 300000 /* KHz */
1001 -#define HDP_SINGLE_MODE_MAX_WIDTH 1920
1003 -static inline bool video_is_dual_mode(const struct drm_display_mode *mode)
1005 - return (mode->clock > HDP_DUAL_MODE_MIN_PCLK_RATE ||
1006 - mode->hdisplay > HDP_SINGLE_MODE_MAX_WIDTH) ? true : false;
1009 -struct imx_mhdp_device;
1011 -struct imx_hdp_clks {
1012 - struct clk *av_pll;
1013 - struct clk *dig_pll;
1014 - struct clk *clk_ipg;
1015 - struct clk *clk_core;
1016 - struct clk *clk_pxl;
1017 - struct clk *clk_pxl_mux;
1018 - struct clk *clk_pxl_link;
1020 - struct clk *lpcg_hdp;
1021 - struct clk *lpcg_msi;
1022 - struct clk *lpcg_pxl;
1023 - struct clk *lpcg_vif;
1024 - struct clk *lpcg_lis;
1025 - struct clk *lpcg_apb;
1026 - struct clk *lpcg_apb_csr;
1027 - struct clk *lpcg_apb_ctrl;
1029 - struct clk *lpcg_i2s;
1030 - struct clk *clk_i2s_bypass;
1033 -struct cdn_plat_data {
1034 - /* Vendor PHY support */
1035 - int (*phy_init)(struct imx_mhdp_device *hdmi);
1036 - int (*bind)(struct platform_device *pdev,
1037 - struct drm_encoder *encoder,
1038 - const struct cdn_plat_data *plat_data);
1039 - void (*unbind)(struct device *dev);
1040 - int (*fw_init)(struct imx_mhdp_device *hdp);
1041 - void (*pclock_change)(struct imx_mhdp_device *hdp);
1045 -struct imx_mhdp_device {
1046 - struct cdns_mhdp_device mhdp;
1048 - struct mutex lock;
1049 - struct mutex audio_mutex;
1050 - spinlock_t audio_lock;
1054 - struct imx_hdp_clks clks;
1056 - const struct cdn_plat_data *plat_data;
1059 - struct delayed_work hotplug_work;
1060 - //void __iomem *regmap_csr;
1061 - struct regmap *regmap_csr;
1062 - u32 csr_pxl_mux_reg;
1063 - u32 csr_ctrl0_reg;
1064 - u32 csr_ctrl0_sec;
1066 - struct audio_info audio_info;
1067 - bool sink_has_audio;
1070 - struct device *pd_mhdp_dev;
1071 - struct device *pd_pll0_dev;
1072 - struct device *pd_pll1_dev;
1073 - struct device_link *pd_mhdp_link;
1074 - struct device_link *pd_pll0_link;
1075 - struct device_link *pd_pll1_link;
1080 -int cdns_hdmi_probe(struct platform_device *pdev,
1081 - const struct cdn_plat_data *plat_data);
1082 -void cdns_hdmi_remove(struct platform_device *pdev);
1083 -void cdns_hdmi_unbind(struct device *dev);
1084 -int cdns_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
1085 - const struct cdn_plat_data *plat_data);
1086 -void cdns_hdmi_set_sample_rate(struct imx_mhdp_device *hdmi, unsigned int rate);
1087 -void cdns_hdmi_audio_enable(struct imx_mhdp_device *hdmi);
1088 -void cdns_hdmi_audio_disable(struct imx_mhdp_device *hdmi);
1089 -int cdns_dp_probe(struct platform_device *pdev,
1090 - const struct cdn_plat_data *plat_data);
1091 -void cdns_dp_remove(struct platform_device *pdev);
1092 -void cdns_dp_unbind(struct device *dev);
1093 -int cdns_dp_bind(struct platform_device *pdev, struct drm_encoder *encoder,
1094 - const struct cdn_plat_data *plat_data);
1096 -#endif /* CDNS_MHDP_IMX_H_ */