2 * i.MX drm driver - LVDS display bridge
4 * Copyright (C) 2012 Sascha Hauer, Pengutronix
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/clk.h>
18 #include <linux/component.h>
20 #include <drm/drm_atomic.h>
21 #include <drm/drm_atomic_helper.h>
22 #include <drm/drm_fb_helper.h>
23 #include <drm/drm_crtc_helper.h>
24 #include <drm/drm_of.h>
25 #include <drm/drm_panel.h>
26 #include <linux/mfd/syscon.h>
27 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
28 #include <linux/of_device.h>
29 #include <linux/of_graph.h>
30 #include <video/of_display_timing.h>
31 #include <video/of_videomode.h>
32 #include <linux/regmap.h>
33 #include <linux/videodev2.h>
37 #define DRIVER_NAME "imx-ldb"
39 #define LDB_CH0_MODE_EN_TO_DI0 (1 << 0)
40 #define LDB_CH0_MODE_EN_TO_DI1 (3 << 0)
41 #define LDB_CH0_MODE_EN_MASK (3 << 0)
42 #define LDB_CH1_MODE_EN_TO_DI0 (1 << 2)
43 #define LDB_CH1_MODE_EN_TO_DI1 (3 << 2)
44 #define LDB_CH1_MODE_EN_MASK (3 << 2)
45 #define LDB_SPLIT_MODE_EN (1 << 4)
46 #define LDB_DATA_WIDTH_CH0_24 (1 << 5)
47 #define LDB_BIT_MAP_CH0_JEIDA (1 << 6)
48 #define LDB_DATA_WIDTH_CH1_24 (1 << 7)
49 #define LDB_BIT_MAP_CH1_JEIDA (1 << 8)
50 #define LDB_DI0_VS_POL_ACT_LOW (1 << 9)
51 #define LDB_DI1_VS_POL_ACT_LOW (1 << 10)
52 #define LDB_BGREF_RMODE_INT (1 << 15)
56 struct imx_ldb_channel
{
58 struct drm_connector connector
;
59 struct drm_encoder encoder
;
61 /* Defines what is connected to the ldb, only one at a time */
62 struct drm_panel
*panel
;
63 struct drm_bridge
*bridge
;
65 struct device_node
*child
;
66 struct i2c_adapter
*ddc
;
70 struct drm_display_mode mode
;
76 static inline struct imx_ldb_channel
*con_to_imx_ldb_ch(struct drm_connector
*c
)
78 return container_of(c
, struct imx_ldb_channel
, connector
);
81 static inline struct imx_ldb_channel
*enc_to_imx_ldb_ch(struct drm_encoder
*e
)
83 return container_of(e
, struct imx_ldb_channel
, encoder
);
93 struct regmap
*regmap
;
95 struct imx_ldb_channel channel
[2];
96 struct clk
*clk
[2]; /* our own clock */
97 struct clk
*clk_sel
[4]; /* parent of display clock */
98 struct clk
*clk_parent
[4]; /* original parent of clk_sel */
99 struct clk
*clk_pll
[2]; /* upstream clock we can adjust */
101 const struct bus_mux
*lvds_mux
;
104 static enum drm_connector_status
imx_ldb_connector_detect(
105 struct drm_connector
*connector
, bool force
)
107 return connector_status_connected
;
110 static void imx_ldb_ch_set_bus_format(struct imx_ldb_channel
*imx_ldb_ch
,
113 struct imx_ldb
*ldb
= imx_ldb_ch
->ldb
;
114 int dual
= ldb
->ldb_ctrl
& LDB_SPLIT_MODE_EN
;
116 switch (bus_format
) {
117 case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG
:
119 case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG
:
120 if (imx_ldb_ch
->chno
== 0 || dual
)
121 ldb
->ldb_ctrl
|= LDB_DATA_WIDTH_CH0_24
;
122 if (imx_ldb_ch
->chno
== 1 || dual
)
123 ldb
->ldb_ctrl
|= LDB_DATA_WIDTH_CH1_24
;
125 case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA
:
126 if (imx_ldb_ch
->chno
== 0 || dual
)
127 ldb
->ldb_ctrl
|= LDB_DATA_WIDTH_CH0_24
|
128 LDB_BIT_MAP_CH0_JEIDA
;
129 if (imx_ldb_ch
->chno
== 1 || dual
)
130 ldb
->ldb_ctrl
|= LDB_DATA_WIDTH_CH1_24
|
131 LDB_BIT_MAP_CH1_JEIDA
;
136 static int imx_ldb_connector_get_modes(struct drm_connector
*connector
)
138 struct imx_ldb_channel
*imx_ldb_ch
= con_to_imx_ldb_ch(connector
);
141 if (imx_ldb_ch
->panel
&& imx_ldb_ch
->panel
->funcs
&&
142 imx_ldb_ch
->panel
->funcs
->get_modes
) {
143 num_modes
= imx_ldb_ch
->panel
->funcs
->get_modes(imx_ldb_ch
->panel
);
148 if (!imx_ldb_ch
->edid
&& imx_ldb_ch
->ddc
)
149 imx_ldb_ch
->edid
= drm_get_edid(connector
, imx_ldb_ch
->ddc
);
151 if (imx_ldb_ch
->edid
) {
152 drm_mode_connector_update_edid_property(connector
,
154 num_modes
= drm_add_edid_modes(connector
, imx_ldb_ch
->edid
);
157 if (imx_ldb_ch
->mode_valid
) {
158 struct drm_display_mode
*mode
;
160 mode
= drm_mode_create(connector
->dev
);
163 drm_mode_copy(mode
, &imx_ldb_ch
->mode
);
164 mode
->type
|= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
165 drm_mode_probed_add(connector
, mode
);
172 static struct drm_encoder
*imx_ldb_connector_best_encoder(
173 struct drm_connector
*connector
)
175 struct imx_ldb_channel
*imx_ldb_ch
= con_to_imx_ldb_ch(connector
);
177 return &imx_ldb_ch
->encoder
;
180 static void imx_ldb_set_clock(struct imx_ldb
*ldb
, int mux
, int chno
,
181 unsigned long serial_clk
, unsigned long di_clk
)
185 dev_dbg(ldb
->dev
, "%s: now: %ld want: %ld\n", __func__
,
186 clk_get_rate(ldb
->clk_pll
[chno
]), serial_clk
);
187 clk_set_rate(ldb
->clk_pll
[chno
], serial_clk
);
189 dev_dbg(ldb
->dev
, "%s after: %ld\n", __func__
,
190 clk_get_rate(ldb
->clk_pll
[chno
]));
192 dev_dbg(ldb
->dev
, "%s: now: %ld want: %ld\n", __func__
,
193 clk_get_rate(ldb
->clk
[chno
]),
195 clk_set_rate(ldb
->clk
[chno
], di_clk
);
197 dev_dbg(ldb
->dev
, "%s after: %ld\n", __func__
,
198 clk_get_rate(ldb
->clk
[chno
]));
200 /* set display clock mux to LDB input clock */
201 ret
= clk_set_parent(ldb
->clk_sel
[mux
], ldb
->clk
[chno
]);
204 "unable to set di%d parent clock to ldb_di%d\n", mux
,
208 static void imx_ldb_encoder_enable(struct drm_encoder
*encoder
)
210 struct imx_ldb_channel
*imx_ldb_ch
= enc_to_imx_ldb_ch(encoder
);
211 struct imx_ldb
*ldb
= imx_ldb_ch
->ldb
;
212 int dual
= ldb
->ldb_ctrl
& LDB_SPLIT_MODE_EN
;
213 int mux
= drm_of_encoder_active_port_id(imx_ldb_ch
->child
, encoder
);
215 drm_panel_prepare(imx_ldb_ch
->panel
);
218 clk_set_parent(ldb
->clk_sel
[mux
], ldb
->clk
[0]);
219 clk_set_parent(ldb
->clk_sel
[mux
], ldb
->clk
[1]);
221 clk_prepare_enable(ldb
->clk
[0]);
222 clk_prepare_enable(ldb
->clk
[1]);
224 clk_set_parent(ldb
->clk_sel
[mux
], ldb
->clk
[imx_ldb_ch
->chno
]);
227 if (imx_ldb_ch
== &ldb
->channel
[0] || dual
) {
228 ldb
->ldb_ctrl
&= ~LDB_CH0_MODE_EN_MASK
;
229 if (mux
== 0 || ldb
->lvds_mux
)
230 ldb
->ldb_ctrl
|= LDB_CH0_MODE_EN_TO_DI0
;
232 ldb
->ldb_ctrl
|= LDB_CH0_MODE_EN_TO_DI1
;
234 if (imx_ldb_ch
== &ldb
->channel
[1] || dual
) {
235 ldb
->ldb_ctrl
&= ~LDB_CH1_MODE_EN_MASK
;
236 if (mux
== 1 || ldb
->lvds_mux
)
237 ldb
->ldb_ctrl
|= LDB_CH1_MODE_EN_TO_DI1
;
239 ldb
->ldb_ctrl
|= LDB_CH1_MODE_EN_TO_DI0
;
243 const struct bus_mux
*lvds_mux
= NULL
;
245 if (imx_ldb_ch
== &ldb
->channel
[0])
246 lvds_mux
= &ldb
->lvds_mux
[0];
247 else if (imx_ldb_ch
== &ldb
->channel
[1])
248 lvds_mux
= &ldb
->lvds_mux
[1];
250 regmap_update_bits(ldb
->regmap
, lvds_mux
->reg
, lvds_mux
->mask
,
251 mux
<< lvds_mux
->shift
);
254 regmap_write(ldb
->regmap
, IOMUXC_GPR2
, ldb
->ldb_ctrl
);
256 drm_panel_enable(imx_ldb_ch
->panel
);
260 imx_ldb_encoder_atomic_mode_set(struct drm_encoder
*encoder
,
261 struct drm_crtc_state
*crtc_state
,
262 struct drm_connector_state
*connector_state
)
264 struct imx_ldb_channel
*imx_ldb_ch
= enc_to_imx_ldb_ch(encoder
);
265 struct drm_display_mode
*mode
= &crtc_state
->adjusted_mode
;
266 struct imx_ldb
*ldb
= imx_ldb_ch
->ldb
;
267 int dual
= ldb
->ldb_ctrl
& LDB_SPLIT_MODE_EN
;
268 unsigned long serial_clk
;
269 unsigned long di_clk
= mode
->clock
* 1000;
270 int mux
= drm_of_encoder_active_port_id(imx_ldb_ch
->child
, encoder
);
271 u32 bus_format
= imx_ldb_ch
->bus_format
;
273 if (mode
->clock
> 170000) {
275 "%s: mode exceeds 170 MHz pixel clock\n", __func__
);
277 if (mode
->clock
> 85000 && !dual
) {
279 "%s: mode exceeds 85 MHz pixel clock\n", __func__
);
283 serial_clk
= 3500UL * mode
->clock
;
284 imx_ldb_set_clock(ldb
, mux
, 0, serial_clk
, di_clk
);
285 imx_ldb_set_clock(ldb
, mux
, 1, serial_clk
, di_clk
);
287 serial_clk
= 7000UL * mode
->clock
;
288 imx_ldb_set_clock(ldb
, mux
, imx_ldb_ch
->chno
, serial_clk
,
292 /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */
293 if (imx_ldb_ch
== &ldb
->channel
[0] || dual
) {
294 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
295 ldb
->ldb_ctrl
|= LDB_DI0_VS_POL_ACT_LOW
;
296 else if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
297 ldb
->ldb_ctrl
&= ~LDB_DI0_VS_POL_ACT_LOW
;
299 if (imx_ldb_ch
== &ldb
->channel
[1] || dual
) {
300 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
301 ldb
->ldb_ctrl
|= LDB_DI1_VS_POL_ACT_LOW
;
302 else if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
303 ldb
->ldb_ctrl
&= ~LDB_DI1_VS_POL_ACT_LOW
;
307 struct drm_connector
*connector
= connector_state
->connector
;
308 struct drm_display_info
*di
= &connector
->display_info
;
310 if (di
->num_bus_formats
)
311 bus_format
= di
->bus_formats
[0];
313 imx_ldb_ch_set_bus_format(imx_ldb_ch
, bus_format
);
316 static void imx_ldb_encoder_disable(struct drm_encoder
*encoder
)
318 struct imx_ldb_channel
*imx_ldb_ch
= enc_to_imx_ldb_ch(encoder
);
319 struct imx_ldb
*ldb
= imx_ldb_ch
->ldb
;
323 * imx_ldb_encoder_disable is called by
324 * drm_helper_disable_unused_functions without
325 * the encoder being enabled before.
327 if (imx_ldb_ch
== &ldb
->channel
[0] &&
328 (ldb
->ldb_ctrl
& LDB_CH0_MODE_EN_MASK
) == 0)
330 else if (imx_ldb_ch
== &ldb
->channel
[1] &&
331 (ldb
->ldb_ctrl
& LDB_CH1_MODE_EN_MASK
) == 0)
334 drm_panel_disable(imx_ldb_ch
->panel
);
336 if (imx_ldb_ch
== &ldb
->channel
[0])
337 ldb
->ldb_ctrl
&= ~LDB_CH0_MODE_EN_MASK
;
338 else if (imx_ldb_ch
== &ldb
->channel
[1])
339 ldb
->ldb_ctrl
&= ~LDB_CH1_MODE_EN_MASK
;
341 regmap_write(ldb
->regmap
, IOMUXC_GPR2
, ldb
->ldb_ctrl
);
343 if (ldb
->ldb_ctrl
& LDB_SPLIT_MODE_EN
) {
344 clk_disable_unprepare(ldb
->clk
[0]);
345 clk_disable_unprepare(ldb
->clk
[1]);
349 const struct bus_mux
*lvds_mux
= NULL
;
351 if (imx_ldb_ch
== &ldb
->channel
[0])
352 lvds_mux
= &ldb
->lvds_mux
[0];
353 else if (imx_ldb_ch
== &ldb
->channel
[1])
354 lvds_mux
= &ldb
->lvds_mux
[1];
356 regmap_read(ldb
->regmap
, lvds_mux
->reg
, &mux
);
357 mux
&= lvds_mux
->mask
;
358 mux
>>= lvds_mux
->shift
;
360 mux
= (imx_ldb_ch
== &ldb
->channel
[0]) ? 0 : 1;
363 /* set display clock mux back to original input clock */
364 ret
= clk_set_parent(ldb
->clk_sel
[mux
], ldb
->clk_parent
[mux
]);
367 "unable to set di%d parent clock to original parent\n",
370 drm_panel_unprepare(imx_ldb_ch
->panel
);
373 static int imx_ldb_encoder_atomic_check(struct drm_encoder
*encoder
,
374 struct drm_crtc_state
*crtc_state
,
375 struct drm_connector_state
*conn_state
)
377 struct imx_crtc_state
*imx_crtc_state
= to_imx_crtc_state(crtc_state
);
378 struct imx_ldb_channel
*imx_ldb_ch
= enc_to_imx_ldb_ch(encoder
);
379 struct drm_display_info
*di
= &conn_state
->connector
->display_info
;
380 u32 bus_format
= imx_ldb_ch
->bus_format
;
382 /* Bus format description in DT overrides connector display info. */
383 if (!bus_format
&& di
->num_bus_formats
) {
384 bus_format
= di
->bus_formats
[0];
385 imx_crtc_state
->bus_flags
= di
->bus_flags
;
387 bus_format
= imx_ldb_ch
->bus_format
;
388 imx_crtc_state
->bus_flags
= imx_ldb_ch
->bus_flags
;
390 switch (bus_format
) {
391 case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG
:
392 imx_crtc_state
->bus_format
= MEDIA_BUS_FMT_RGB666_1X18
;
394 case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG
:
395 case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA
:
396 imx_crtc_state
->bus_format
= MEDIA_BUS_FMT_RGB888_1X24
;
402 imx_crtc_state
->di_hsync_pin
= 2;
403 imx_crtc_state
->di_vsync_pin
= 3;
409 static const struct drm_connector_funcs imx_ldb_connector_funcs
= {
410 .dpms
= drm_atomic_helper_connector_dpms
,
411 .fill_modes
= drm_helper_probe_single_connector_modes
,
412 .detect
= imx_ldb_connector_detect
,
413 .destroy
= imx_drm_connector_destroy
,
414 .reset
= drm_atomic_helper_connector_reset
,
415 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
416 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
419 static const struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs
= {
420 .get_modes
= imx_ldb_connector_get_modes
,
421 .best_encoder
= imx_ldb_connector_best_encoder
,
424 static const struct drm_encoder_funcs imx_ldb_encoder_funcs
= {
425 .destroy
= imx_drm_encoder_destroy
,
428 static const struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs
= {
429 .atomic_mode_set
= imx_ldb_encoder_atomic_mode_set
,
430 .enable
= imx_ldb_encoder_enable
,
431 .disable
= imx_ldb_encoder_disable
,
432 .atomic_check
= imx_ldb_encoder_atomic_check
,
435 static int imx_ldb_get_clk(struct imx_ldb
*ldb
, int chno
)
439 snprintf(clkname
, sizeof(clkname
), "di%d", chno
);
440 ldb
->clk
[chno
] = devm_clk_get(ldb
->dev
, clkname
);
441 if (IS_ERR(ldb
->clk
[chno
]))
442 return PTR_ERR(ldb
->clk
[chno
]);
444 snprintf(clkname
, sizeof(clkname
), "di%d_pll", chno
);
445 ldb
->clk_pll
[chno
] = devm_clk_get(ldb
->dev
, clkname
);
447 return PTR_ERR_OR_ZERO(ldb
->clk_pll
[chno
]);
450 static int imx_ldb_register(struct drm_device
*drm
,
451 struct imx_ldb_channel
*imx_ldb_ch
)
453 struct imx_ldb
*ldb
= imx_ldb_ch
->ldb
;
454 struct drm_encoder
*encoder
= &imx_ldb_ch
->encoder
;
457 ret
= imx_drm_encoder_parse_of(drm
, encoder
, imx_ldb_ch
->child
);
461 ret
= imx_ldb_get_clk(ldb
, imx_ldb_ch
->chno
);
465 if (ldb
->ldb_ctrl
& LDB_SPLIT_MODE_EN
) {
466 ret
= imx_ldb_get_clk(ldb
, 1);
471 drm_encoder_helper_add(encoder
, &imx_ldb_encoder_helper_funcs
);
472 drm_encoder_init(drm
, encoder
, &imx_ldb_encoder_funcs
,
473 DRM_MODE_ENCODER_LVDS
, NULL
);
475 if (imx_ldb_ch
->bridge
) {
476 imx_ldb_ch
->bridge
->encoder
= encoder
;
478 imx_ldb_ch
->encoder
.bridge
= imx_ldb_ch
->bridge
;
479 ret
= drm_bridge_attach(drm
, imx_ldb_ch
->bridge
);
481 DRM_ERROR("Failed to initialize bridge with drm\n");
486 * We want to add the connector whenever there is no bridge
487 * that brings its own, not only when there is a panel. For
488 * historical reasons, the ldb driver can also work without
491 drm_connector_helper_add(&imx_ldb_ch
->connector
,
492 &imx_ldb_connector_helper_funcs
);
493 drm_connector_init(drm
, &imx_ldb_ch
->connector
,
494 &imx_ldb_connector_funcs
,
495 DRM_MODE_CONNECTOR_LVDS
);
496 drm_mode_connector_attach_encoder(&imx_ldb_ch
->connector
,
500 if (imx_ldb_ch
->panel
) {
501 ret
= drm_panel_attach(imx_ldb_ch
->panel
,
502 &imx_ldb_ch
->connector
);
515 struct imx_ldb_bit_mapping
{
518 const char * const mapping
;
521 static const struct imx_ldb_bit_mapping imx_ldb_bit_mappings
[] = {
522 { MEDIA_BUS_FMT_RGB666_1X7X3_SPWG
, 18, "spwg" },
523 { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG
, 24, "spwg" },
524 { MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA
, 24, "jeida" },
527 static u32
of_get_bus_format(struct device
*dev
, struct device_node
*np
)
533 ret
= of_property_read_string(np
, "fsl,data-mapping", &bm
);
537 of_property_read_u32(np
, "fsl,data-width", &datawidth
);
539 for (i
= 0; i
< ARRAY_SIZE(imx_ldb_bit_mappings
); i
++) {
540 if (!strcasecmp(bm
, imx_ldb_bit_mappings
[i
].mapping
) &&
541 datawidth
== imx_ldb_bit_mappings
[i
].datawidth
)
542 return imx_ldb_bit_mappings
[i
].bus_format
;
545 dev_err(dev
, "invalid data mapping: %d-bit \"%s\"\n", datawidth
, bm
);
550 static struct bus_mux imx6q_lvds_mux
[2] = {
554 .mask
= IMX6Q_GPR3_LVDS0_MUX_CTL_MASK
,
558 .mask
= IMX6Q_GPR3_LVDS1_MUX_CTL_MASK
,
563 * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
564 * of_match_device will walk through this list and take the first entry
565 * matching any of its compatible values. Therefore, the more generic
566 * entries (in this case fsl,imx53-ldb) need to be ordered last.
568 static const struct of_device_id imx_ldb_dt_ids
[] = {
569 { .compatible
= "fsl,imx6q-ldb", .data
= imx6q_lvds_mux
, },
570 { .compatible
= "fsl,imx53-ldb", .data
= NULL
, },
573 MODULE_DEVICE_TABLE(of
, imx_ldb_dt_ids
);
575 static int imx_ldb_panel_ddc(struct device
*dev
,
576 struct imx_ldb_channel
*channel
, struct device_node
*child
)
578 struct device_node
*ddc_node
;
582 ddc_node
= of_parse_phandle(child
, "ddc-i2c-bus", 0);
584 channel
->ddc
= of_find_i2c_adapter_by_node(ddc_node
);
585 of_node_put(ddc_node
);
587 dev_warn(dev
, "failed to get ddc i2c adapter\n");
588 return -EPROBE_DEFER
;
593 /* if no DDC available, fallback to hardcoded EDID */
594 dev_dbg(dev
, "no ddc available\n");
596 edidp
= of_get_property(child
, "edid",
599 channel
->edid
= kmemdup(edidp
,
602 } else if (!channel
->panel
) {
603 /* fallback to display-timings node */
604 ret
= of_get_drm_display_mode(child
,
609 channel
->mode_valid
= 1;
615 static int imx_ldb_bind(struct device
*dev
, struct device
*master
, void *data
)
617 struct drm_device
*drm
= data
;
618 struct device_node
*np
= dev
->of_node
;
619 const struct of_device_id
*of_id
=
620 of_match_device(imx_ldb_dt_ids
, dev
);
621 struct device_node
*child
;
622 struct imx_ldb
*imx_ldb
;
627 imx_ldb
= devm_kzalloc(dev
, sizeof(*imx_ldb
), GFP_KERNEL
);
631 imx_ldb
->regmap
= syscon_regmap_lookup_by_phandle(np
, "gpr");
632 if (IS_ERR(imx_ldb
->regmap
)) {
633 dev_err(dev
, "failed to get parent regmap\n");
634 return PTR_ERR(imx_ldb
->regmap
);
637 /* disable LDB by resetting the control register to POR default */
638 regmap_write(imx_ldb
->regmap
, IOMUXC_GPR2
, 0);
643 imx_ldb
->lvds_mux
= of_id
->data
;
645 dual
= of_property_read_bool(np
, "fsl,dual-channel");
647 imx_ldb
->ldb_ctrl
|= LDB_SPLIT_MODE_EN
;
650 * There are three different possible clock mux configurations:
651 * i.MX53: ipu1_di0_sel, ipu1_di1_sel
652 * i.MX6q: ipu1_di0_sel, ipu1_di1_sel, ipu2_di0_sel, ipu2_di1_sel
653 * i.MX6dl: ipu1_di0_sel, ipu1_di1_sel, lcdif_sel
654 * Map them all to di0_sel...di3_sel.
656 for (i
= 0; i
< 4; i
++) {
659 sprintf(clkname
, "di%d_sel", i
);
660 imx_ldb
->clk_sel
[i
] = devm_clk_get(imx_ldb
->dev
, clkname
);
661 if (IS_ERR(imx_ldb
->clk_sel
[i
])) {
662 ret
= PTR_ERR(imx_ldb
->clk_sel
[i
]);
663 imx_ldb
->clk_sel
[i
] = NULL
;
667 imx_ldb
->clk_parent
[i
] = clk_get_parent(imx_ldb
->clk_sel
[i
]);
672 for_each_child_of_node(np
, child
) {
673 struct imx_ldb_channel
*channel
;
674 struct device_node
*ep
;
677 ret
= of_property_read_u32(child
, "reg", &i
);
678 if (ret
|| i
< 0 || i
> 1)
681 if (!of_device_is_available(child
))
685 dev_warn(dev
, "dual-channel mode, ignoring second output\n");
689 channel
= &imx_ldb
->channel
[i
];
690 channel
->ldb
= imx_ldb
;
692 channel
->child
= child
;
695 * The output port is port@4 with an external 4-port mux or
696 * port@2 with the internal 2-port mux.
698 ep
= of_graph_get_endpoint_by_regs(child
,
699 imx_ldb
->lvds_mux
? 4 : 2,
702 struct device_node
*remote
;
704 remote
= of_graph_get_remote_port_parent(ep
);
707 channel
->panel
= of_drm_find_panel(remote
);
708 channel
->bridge
= of_drm_find_bridge(remote
);
710 return -EPROBE_DEFER
;
713 if (!channel
->panel
&& !channel
->bridge
) {
714 dev_err(dev
, "panel/bridge not found: %s\n",
716 return -EPROBE_DEFER
;
720 /* panel ddc only if there is no bridge */
721 if (!channel
->bridge
) {
722 ret
= imx_ldb_panel_ddc(dev
, channel
, child
);
727 bus_format
= of_get_bus_format(dev
, child
);
728 if (bus_format
== -EINVAL
) {
730 * If no bus format was specified in the device tree,
731 * we can still get it from the connected panel later.
733 if (channel
->panel
&& channel
->panel
->funcs
&&
734 channel
->panel
->funcs
->get_modes
)
737 if (bus_format
< 0) {
738 dev_err(dev
, "could not determine data mapping: %d\n",
742 channel
->bus_format
= bus_format
;
744 ret
= imx_ldb_register(drm
, channel
);
749 dev_set_drvdata(dev
, imx_ldb
);
754 static void imx_ldb_unbind(struct device
*dev
, struct device
*master
,
757 struct imx_ldb
*imx_ldb
= dev_get_drvdata(dev
);
760 for (i
= 0; i
< 2; i
++) {
761 struct imx_ldb_channel
*channel
= &imx_ldb
->channel
[i
];
764 drm_bridge_detach(channel
->bridge
);
766 drm_panel_detach(channel
->panel
);
768 kfree(channel
->edid
);
769 i2c_put_adapter(channel
->ddc
);
773 static const struct component_ops imx_ldb_ops
= {
774 .bind
= imx_ldb_bind
,
775 .unbind
= imx_ldb_unbind
,
778 static int imx_ldb_probe(struct platform_device
*pdev
)
780 return component_add(&pdev
->dev
, &imx_ldb_ops
);
783 static int imx_ldb_remove(struct platform_device
*pdev
)
785 component_del(&pdev
->dev
, &imx_ldb_ops
);
789 static struct platform_driver imx_ldb_driver
= {
790 .probe
= imx_ldb_probe
,
791 .remove
= imx_ldb_remove
,
793 .of_match_table
= imx_ldb_dt_ids
,
798 module_platform_driver(imx_ldb_driver
);
800 MODULE_DESCRIPTION("i.MX LVDS driver");
801 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
802 MODULE_LICENSE("GPL");
803 MODULE_ALIAS("platform:" DRIVER_NAME
);