Lines Matching +full:dual +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0+
3 * i.MX drm driver - LVDS display bridge
11 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
31 #include "imx-drm.h"
33 #define DRIVER_NAME "imx-ldb"
90 struct imx_ldb_channel channel[2]; member
102 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_ch_set_bus_format()
103 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_ch_set_bus_format() local
109 if (imx_ldb_ch->chno == 0 || dual) in imx_ldb_ch_set_bus_format()
110 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; in imx_ldb_ch_set_bus_format()
111 if (imx_ldb_ch->chno == 1 || dual) in imx_ldb_ch_set_bus_format()
112 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; in imx_ldb_ch_set_bus_format()
115 if (imx_ldb_ch->chno == 0 || dual) in imx_ldb_ch_set_bus_format()
116 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | in imx_ldb_ch_set_bus_format()
118 if (imx_ldb_ch->chno == 1 || dual) in imx_ldb_ch_set_bus_format()
119 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | in imx_ldb_ch_set_bus_format()
130 num_modes = drm_panel_get_modes(imx_ldb_ch->panel, connector); in imx_ldb_connector_get_modes()
134 if (!imx_ldb_ch->edid && imx_ldb_ch->ddc) in imx_ldb_connector_get_modes()
135 imx_ldb_ch->edid = drm_get_edid(connector, imx_ldb_ch->ddc); in imx_ldb_connector_get_modes()
137 if (imx_ldb_ch->edid) { in imx_ldb_connector_get_modes()
139 imx_ldb_ch->edid); in imx_ldb_connector_get_modes()
140 num_modes = drm_add_edid_modes(connector, imx_ldb_ch->edid); in imx_ldb_connector_get_modes()
143 if (imx_ldb_ch->mode_valid) { in imx_ldb_connector_get_modes()
146 mode = drm_mode_create(connector->dev); in imx_ldb_connector_get_modes()
148 return -EINVAL; in imx_ldb_connector_get_modes()
149 drm_mode_copy(mode, &imx_ldb_ch->mode); in imx_ldb_connector_get_modes()
150 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; in imx_ldb_connector_get_modes()
163 dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__, in imx_ldb_set_clock()
164 clk_get_rate(ldb->clk_pll[chno]), serial_clk); in imx_ldb_set_clock()
165 clk_set_rate(ldb->clk_pll[chno], serial_clk); in imx_ldb_set_clock()
167 dev_dbg(ldb->dev, "%s after: %ld\n", __func__, in imx_ldb_set_clock()
168 clk_get_rate(ldb->clk_pll[chno])); in imx_ldb_set_clock()
170 dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__, in imx_ldb_set_clock()
171 clk_get_rate(ldb->clk[chno]), in imx_ldb_set_clock()
173 clk_set_rate(ldb->clk[chno], di_clk); in imx_ldb_set_clock()
175 dev_dbg(ldb->dev, "%s after: %ld\n", __func__, in imx_ldb_set_clock()
176 clk_get_rate(ldb->clk[chno])); in imx_ldb_set_clock()
179 ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk[chno]); in imx_ldb_set_clock()
181 dev_err(ldb->dev, in imx_ldb_set_clock()
189 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_enable()
190 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_enable() local
191 int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); in imx_ldb_encoder_enable()
193 drm_panel_prepare(imx_ldb_ch->panel); in imx_ldb_encoder_enable()
195 if (dual) { in imx_ldb_encoder_enable()
196 clk_set_parent(ldb->clk_sel[mux], ldb->clk[0]); in imx_ldb_encoder_enable()
197 clk_set_parent(ldb->clk_sel[mux], ldb->clk[1]); in imx_ldb_encoder_enable()
199 clk_prepare_enable(ldb->clk[0]); in imx_ldb_encoder_enable()
200 clk_prepare_enable(ldb->clk[1]); in imx_ldb_encoder_enable()
202 clk_set_parent(ldb->clk_sel[mux], ldb->clk[imx_ldb_ch->chno]); in imx_ldb_encoder_enable()
205 if (imx_ldb_ch == &ldb->channel[0] || dual) { in imx_ldb_encoder_enable()
206 ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK; in imx_ldb_encoder_enable()
207 if (mux == 0 || ldb->lvds_mux) in imx_ldb_encoder_enable()
208 ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI0; in imx_ldb_encoder_enable()
210 ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI1; in imx_ldb_encoder_enable()
212 if (imx_ldb_ch == &ldb->channel[1] || dual) { in imx_ldb_encoder_enable()
213 ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK; in imx_ldb_encoder_enable()
214 if (mux == 1 || ldb->lvds_mux) in imx_ldb_encoder_enable()
215 ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI1; in imx_ldb_encoder_enable()
217 ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI0; in imx_ldb_encoder_enable()
220 if (ldb->lvds_mux) { in imx_ldb_encoder_enable()
223 if (imx_ldb_ch == &ldb->channel[0]) in imx_ldb_encoder_enable()
224 lvds_mux = &ldb->lvds_mux[0]; in imx_ldb_encoder_enable()
225 else if (imx_ldb_ch == &ldb->channel[1]) in imx_ldb_encoder_enable()
226 lvds_mux = &ldb->lvds_mux[1]; in imx_ldb_encoder_enable()
228 regmap_update_bits(ldb->regmap, lvds_mux->reg, lvds_mux->mask, in imx_ldb_encoder_enable()
229 mux << lvds_mux->shift); in imx_ldb_encoder_enable()
232 regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl); in imx_ldb_encoder_enable()
234 drm_panel_enable(imx_ldb_ch->panel); in imx_ldb_encoder_enable()
243 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in imx_ldb_encoder_atomic_mode_set()
244 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_atomic_mode_set()
245 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_atomic_mode_set() local
247 unsigned long di_clk = mode->clock * 1000; in imx_ldb_encoder_atomic_mode_set()
248 int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); in imx_ldb_encoder_atomic_mode_set()
249 u32 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_mode_set()
251 if (mode->clock > 170000) { in imx_ldb_encoder_atomic_mode_set()
252 dev_warn(ldb->dev, in imx_ldb_encoder_atomic_mode_set()
255 if (mode->clock > 85000 && !dual) { in imx_ldb_encoder_atomic_mode_set()
256 dev_warn(ldb->dev, in imx_ldb_encoder_atomic_mode_set()
260 if (dual) { in imx_ldb_encoder_atomic_mode_set()
261 serial_clk = 3500UL * mode->clock; in imx_ldb_encoder_atomic_mode_set()
265 serial_clk = 7000UL * mode->clock; in imx_ldb_encoder_atomic_mode_set()
266 imx_ldb_set_clock(ldb, mux, imx_ldb_ch->chno, serial_clk, in imx_ldb_encoder_atomic_mode_set()
270 /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */ in imx_ldb_encoder_atomic_mode_set()
271 if (imx_ldb_ch == &ldb->channel[0] || dual) { in imx_ldb_encoder_atomic_mode_set()
272 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in imx_ldb_encoder_atomic_mode_set()
273 ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
274 else if (mode->flags & DRM_MODE_FLAG_PVSYNC) in imx_ldb_encoder_atomic_mode_set()
275 ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
277 if (imx_ldb_ch == &ldb->channel[1] || dual) { in imx_ldb_encoder_atomic_mode_set()
278 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in imx_ldb_encoder_atomic_mode_set()
279 ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
280 else if (mode->flags & DRM_MODE_FLAG_PVSYNC) in imx_ldb_encoder_atomic_mode_set()
281 ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
285 struct drm_connector *connector = connector_state->connector; in imx_ldb_encoder_atomic_mode_set()
286 struct drm_display_info *di = &connector->display_info; in imx_ldb_encoder_atomic_mode_set()
288 if (di->num_bus_formats) in imx_ldb_encoder_atomic_mode_set()
289 bus_format = di->bus_formats[0]; in imx_ldb_encoder_atomic_mode_set()
297 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_disable()
298 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_disable() local
301 drm_panel_disable(imx_ldb_ch->panel); in imx_ldb_encoder_disable()
303 if (imx_ldb_ch == &ldb->channel[0] || dual) in imx_ldb_encoder_disable()
304 ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK; in imx_ldb_encoder_disable()
305 if (imx_ldb_ch == &ldb->channel[1] || dual) in imx_ldb_encoder_disable()
306 ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK; in imx_ldb_encoder_disable()
308 regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl); in imx_ldb_encoder_disable()
310 if (dual) { in imx_ldb_encoder_disable()
311 clk_disable_unprepare(ldb->clk[0]); in imx_ldb_encoder_disable()
312 clk_disable_unprepare(ldb->clk[1]); in imx_ldb_encoder_disable()
315 if (ldb->lvds_mux) { in imx_ldb_encoder_disable()
318 if (imx_ldb_ch == &ldb->channel[0]) in imx_ldb_encoder_disable()
319 lvds_mux = &ldb->lvds_mux[0]; in imx_ldb_encoder_disable()
320 else if (imx_ldb_ch == &ldb->channel[1]) in imx_ldb_encoder_disable()
321 lvds_mux = &ldb->lvds_mux[1]; in imx_ldb_encoder_disable()
323 regmap_read(ldb->regmap, lvds_mux->reg, &mux); in imx_ldb_encoder_disable()
324 mux &= lvds_mux->mask; in imx_ldb_encoder_disable()
325 mux >>= lvds_mux->shift; in imx_ldb_encoder_disable()
327 mux = (imx_ldb_ch == &ldb->channel[0]) ? 0 : 1; in imx_ldb_encoder_disable()
331 ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk_parent[mux]); in imx_ldb_encoder_disable()
333 dev_err(ldb->dev, in imx_ldb_encoder_disable()
337 drm_panel_unprepare(imx_ldb_ch->panel); in imx_ldb_encoder_disable()
346 struct drm_display_info *di = &conn_state->connector->display_info; in imx_ldb_encoder_atomic_check()
347 u32 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_check()
350 if (!bus_format && di->num_bus_formats) { in imx_ldb_encoder_atomic_check()
351 bus_format = di->bus_formats[0]; in imx_ldb_encoder_atomic_check()
352 imx_crtc_state->bus_flags = di->bus_flags; in imx_ldb_encoder_atomic_check()
354 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_check()
355 imx_crtc_state->bus_flags = imx_ldb_ch->bus_flags; in imx_ldb_encoder_atomic_check()
359 imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB666_1X18; in imx_ldb_encoder_atomic_check()
363 imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24; in imx_ldb_encoder_atomic_check()
366 return -EINVAL; in imx_ldb_encoder_atomic_check()
369 imx_crtc_state->di_hsync_pin = 2; in imx_ldb_encoder_atomic_check()
370 imx_crtc_state->di_vsync_pin = 3; in imx_ldb_encoder_atomic_check()
400 ldb->clk[chno] = devm_clk_get(ldb->dev, clkname); in imx_ldb_get_clk()
401 if (IS_ERR(ldb->clk[chno])) in imx_ldb_get_clk()
402 return PTR_ERR(ldb->clk[chno]); in imx_ldb_get_clk()
405 ldb->clk_pll[chno] = devm_clk_get(ldb->dev, clkname); in imx_ldb_get_clk()
407 return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]); in imx_ldb_get_clk()
413 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_register()
414 struct drm_encoder *encoder = &imx_ldb_ch->encoder; in imx_ldb_register()
417 ret = imx_drm_encoder_parse_of(drm, encoder, imx_ldb_ch->child); in imx_ldb_register()
421 ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno); in imx_ldb_register()
425 if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) { in imx_ldb_register()
434 if (imx_ldb_ch->bridge) { in imx_ldb_register()
435 ret = drm_bridge_attach(&imx_ldb_ch->encoder, in imx_ldb_register()
436 imx_ldb_ch->bridge, NULL, 0); in imx_ldb_register()
448 drm_connector_helper_add(&imx_ldb_ch->connector, in imx_ldb_register()
450 drm_connector_init_with_ddc(drm, &imx_ldb_ch->connector, in imx_ldb_register()
453 imx_ldb_ch->ddc); in imx_ldb_register()
454 drm_connector_attach_encoder(&imx_ldb_ch->connector, encoder); in imx_ldb_register()
478 ret = of_property_read_string(np, "fsl,data-mapping", &bm); in of_get_bus_format()
482 of_property_read_u32(np, "fsl,data-width", &datawidth); in of_get_bus_format()
490 dev_err(dev, "invalid data mapping: %d-bit \"%s\"\n", datawidth, bm); in of_get_bus_format()
492 return -ENOENT; in of_get_bus_format()
508 * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
511 * entries (in this case fsl,imx53-ldb) need to be ordered last.
514 { .compatible = "fsl,imx6q-ldb", .data = imx6q_lvds_mux, },
515 { .compatible = "fsl,imx53-ldb", .data = NULL, },
521 struct imx_ldb_channel *channel, struct device_node *child) in imx_ldb_panel_ddc() argument
527 ddc_node = of_parse_phandle(child, "ddc-i2c-bus", 0); in imx_ldb_panel_ddc()
529 channel->ddc = of_find_i2c_adapter_by_node(ddc_node); in imx_ldb_panel_ddc()
531 if (!channel->ddc) { in imx_ldb_panel_ddc()
533 return -EPROBE_DEFER; in imx_ldb_panel_ddc()
537 if (!channel->ddc) { in imx_ldb_panel_ddc()
545 channel->edid = kmemdup(edidp, edid_len, GFP_KERNEL); in imx_ldb_panel_ddc()
546 } else if (!channel->panel) { in imx_ldb_panel_ddc()
547 /* fallback to display-timings node */ in imx_ldb_panel_ddc()
549 &channel->mode, in imx_ldb_panel_ddc()
550 &channel->bus_flags, in imx_ldb_panel_ddc()
553 channel->mode_valid = 1; in imx_ldb_panel_ddc()
562 struct device_node *np = dev->of_node; in imx_ldb_bind()
567 int dual; in imx_ldb_bind() local
574 imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr"); in imx_ldb_bind()
575 if (IS_ERR(imx_ldb->regmap)) { in imx_ldb_bind()
577 return PTR_ERR(imx_ldb->regmap); in imx_ldb_bind()
581 regmap_write(imx_ldb->regmap, IOMUXC_GPR2, 0); in imx_ldb_bind()
583 imx_ldb->dev = dev; in imx_ldb_bind()
586 imx_ldb->lvds_mux = of_id->data; in imx_ldb_bind()
588 dual = of_property_read_bool(np, "fsl,dual-channel"); in imx_ldb_bind()
589 if (dual) in imx_ldb_bind()
590 imx_ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN; in imx_ldb_bind()
603 imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname); in imx_ldb_bind()
604 if (IS_ERR(imx_ldb->clk_sel[i])) { in imx_ldb_bind()
605 ret = PTR_ERR(imx_ldb->clk_sel[i]); in imx_ldb_bind()
606 imx_ldb->clk_sel[i] = NULL; in imx_ldb_bind()
610 imx_ldb->clk_parent[i] = clk_get_parent(imx_ldb->clk_sel[i]); in imx_ldb_bind()
616 struct imx_ldb_channel *channel; in imx_ldb_bind() local
621 ret = -EINVAL; in imx_ldb_bind()
628 if (dual && i > 0) { in imx_ldb_bind()
629 dev_warn(dev, "dual-channel mode, ignoring second output\n"); in imx_ldb_bind()
633 channel = &imx_ldb->channel[i]; in imx_ldb_bind()
634 channel->ldb = imx_ldb; in imx_ldb_bind()
635 channel->chno = i; in imx_ldb_bind()
638 * The output port is port@4 with an external 4-port mux or in imx_ldb_bind()
639 * port@2 with the internal 2-port mux. in imx_ldb_bind()
642 imx_ldb->lvds_mux ? 4 : 2, 0, in imx_ldb_bind()
643 &channel->panel, &channel->bridge); in imx_ldb_bind()
644 if (ret && ret != -ENODEV) in imx_ldb_bind()
648 if (!channel->bridge) { in imx_ldb_bind()
649 ret = imx_ldb_panel_ddc(dev, channel, child); in imx_ldb_bind()
655 if (bus_format == -EINVAL) { in imx_ldb_bind()
660 if (channel->panel && channel->panel->funcs && in imx_ldb_bind()
661 channel->panel->funcs->get_modes) in imx_ldb_bind()
670 channel->bus_format = bus_format; in imx_ldb_bind()
671 channel->child = child; in imx_ldb_bind()
673 ret = imx_ldb_register(drm, channel); in imx_ldb_bind()
675 channel->child = NULL; in imx_ldb_bind()
694 struct imx_ldb_channel *channel = &imx_ldb->channel[i]; in imx_ldb_unbind() local
696 kfree(channel->edid); in imx_ldb_unbind()
697 i2c_put_adapter(channel->ddc); in imx_ldb_unbind()
710 imx_ldb = devm_kzalloc(&pdev->dev, sizeof(*imx_ldb), GFP_KERNEL); in imx_ldb_probe()
712 return -ENOMEM; in imx_ldb_probe()
716 return component_add(&pdev->dev, &imx_ldb_ops); in imx_ldb_probe()
721 component_del(&pdev->dev, &imx_ldb_ops); in imx_ldb_remove()