Lines Matching +full:e +full:- +full:ddc
1 // SPDX-License-Identifier: GPL-2.0+
3 * i.MX drm driver - LVDS display bridge
11 #include <linux/media-bus-format.h>
13 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
36 #include "imx-drm.h"
38 #define DRIVER_NAME "imx-ldb"
73 struct i2c_adapter *ddc; member
84 return container_of(c, struct imx_ldb_encoder, connector)->channel; in con_to_imx_ldb_ch()
87 static inline struct imx_ldb_channel *enc_to_imx_ldb_ch(struct drm_encoder *e) in enc_to_imx_ldb_ch() argument
89 return container_of(e, struct imx_ldb_encoder, encoder)->channel; in enc_to_imx_ldb_ch()
113 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_ch_set_bus_format()
114 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_ch_set_bus_format()
120 if (imx_ldb_ch->chno == 0 || dual) in imx_ldb_ch_set_bus_format()
121 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; in imx_ldb_ch_set_bus_format()
122 if (imx_ldb_ch->chno == 1 || dual) in imx_ldb_ch_set_bus_format()
123 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; in imx_ldb_ch_set_bus_format()
126 if (imx_ldb_ch->chno == 0 || dual) in imx_ldb_ch_set_bus_format()
127 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | in imx_ldb_ch_set_bus_format()
129 if (imx_ldb_ch->chno == 1 || dual) in imx_ldb_ch_set_bus_format()
130 ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | in imx_ldb_ch_set_bus_format()
141 num_modes = drm_panel_get_modes(imx_ldb_ch->panel, connector); in imx_ldb_connector_get_modes()
145 if (!imx_ldb_ch->drm_edid && imx_ldb_ch->ddc) { in imx_ldb_connector_get_modes()
146 imx_ldb_ch->drm_edid = drm_edid_read_ddc(connector, in imx_ldb_connector_get_modes()
147 imx_ldb_ch->ddc); in imx_ldb_connector_get_modes()
148 drm_edid_connector_update(connector, imx_ldb_ch->drm_edid); in imx_ldb_connector_get_modes()
151 if (imx_ldb_ch->drm_edid) in imx_ldb_connector_get_modes()
154 if (imx_ldb_ch->mode_valid) { in imx_ldb_connector_get_modes()
157 mode = drm_mode_duplicate(connector->dev, &imx_ldb_ch->mode); in imx_ldb_connector_get_modes()
159 return -EINVAL; in imx_ldb_connector_get_modes()
160 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; in imx_ldb_connector_get_modes()
173 dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__, in imx_ldb_set_clock()
174 clk_get_rate(ldb->clk_pll[chno]), serial_clk); in imx_ldb_set_clock()
175 clk_set_rate(ldb->clk_pll[chno], serial_clk); in imx_ldb_set_clock()
177 dev_dbg(ldb->dev, "%s after: %ld\n", __func__, in imx_ldb_set_clock()
178 clk_get_rate(ldb->clk_pll[chno])); in imx_ldb_set_clock()
180 dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__, in imx_ldb_set_clock()
181 clk_get_rate(ldb->clk[chno]), in imx_ldb_set_clock()
183 clk_set_rate(ldb->clk[chno], di_clk); in imx_ldb_set_clock()
185 dev_dbg(ldb->dev, "%s after: %ld\n", __func__, in imx_ldb_set_clock()
186 clk_get_rate(ldb->clk[chno])); in imx_ldb_set_clock()
189 ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk[chno]); in imx_ldb_set_clock()
191 dev_err(ldb->dev, in imx_ldb_set_clock()
199 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_enable()
200 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_enable()
201 int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); in imx_ldb_encoder_enable()
203 if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { in imx_ldb_encoder_enable()
204 dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux); in imx_ldb_encoder_enable()
208 drm_panel_prepare(imx_ldb_ch->panel); in imx_ldb_encoder_enable()
211 clk_set_parent(ldb->clk_sel[mux], ldb->clk[0]); in imx_ldb_encoder_enable()
212 clk_set_parent(ldb->clk_sel[mux], ldb->clk[1]); in imx_ldb_encoder_enable()
214 clk_prepare_enable(ldb->clk[0]); in imx_ldb_encoder_enable()
215 clk_prepare_enable(ldb->clk[1]); in imx_ldb_encoder_enable()
217 clk_set_parent(ldb->clk_sel[mux], ldb->clk[imx_ldb_ch->chno]); in imx_ldb_encoder_enable()
220 if (imx_ldb_ch == &ldb->channel[0] || dual) { in imx_ldb_encoder_enable()
221 ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK; in imx_ldb_encoder_enable()
222 if (mux == 0 || ldb->lvds_mux) in imx_ldb_encoder_enable()
223 ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI0; in imx_ldb_encoder_enable()
225 ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI1; in imx_ldb_encoder_enable()
227 if (imx_ldb_ch == &ldb->channel[1] || dual) { in imx_ldb_encoder_enable()
228 ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK; in imx_ldb_encoder_enable()
229 if (mux == 1 || ldb->lvds_mux) in imx_ldb_encoder_enable()
230 ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI1; in imx_ldb_encoder_enable()
232 ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI0; in imx_ldb_encoder_enable()
235 if (ldb->lvds_mux) { in imx_ldb_encoder_enable()
238 if (imx_ldb_ch == &ldb->channel[0]) in imx_ldb_encoder_enable()
239 lvds_mux = &ldb->lvds_mux[0]; in imx_ldb_encoder_enable()
240 else if (imx_ldb_ch == &ldb->channel[1]) in imx_ldb_encoder_enable()
241 lvds_mux = &ldb->lvds_mux[1]; in imx_ldb_encoder_enable()
243 regmap_update_bits(ldb->regmap, lvds_mux->reg, lvds_mux->mask, in imx_ldb_encoder_enable()
244 mux << lvds_mux->shift); in imx_ldb_encoder_enable()
247 regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl); in imx_ldb_encoder_enable()
249 drm_panel_enable(imx_ldb_ch->panel); in imx_ldb_encoder_enable()
258 struct drm_display_mode *mode = &crtc_state->adjusted_mode; in imx_ldb_encoder_atomic_mode_set()
259 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_atomic_mode_set()
260 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_atomic_mode_set()
262 unsigned long di_clk = mode->clock * 1000; in imx_ldb_encoder_atomic_mode_set()
263 int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); in imx_ldb_encoder_atomic_mode_set()
264 u32 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_mode_set()
266 if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { in imx_ldb_encoder_atomic_mode_set()
267 dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux); in imx_ldb_encoder_atomic_mode_set()
271 if (mode->clock > 170000) { in imx_ldb_encoder_atomic_mode_set()
272 dev_warn(ldb->dev, in imx_ldb_encoder_atomic_mode_set()
275 if (mode->clock > 85000 && !dual) { in imx_ldb_encoder_atomic_mode_set()
276 dev_warn(ldb->dev, in imx_ldb_encoder_atomic_mode_set()
280 if (!IS_ALIGNED(mode->hdisplay, 8)) { in imx_ldb_encoder_atomic_mode_set()
281 dev_warn(ldb->dev, in imx_ldb_encoder_atomic_mode_set()
286 serial_clk = 3500UL * mode->clock; in imx_ldb_encoder_atomic_mode_set()
290 serial_clk = 7000UL * mode->clock; in imx_ldb_encoder_atomic_mode_set()
291 imx_ldb_set_clock(ldb, mux, imx_ldb_ch->chno, serial_clk, in imx_ldb_encoder_atomic_mode_set()
295 /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */ in imx_ldb_encoder_atomic_mode_set()
296 if (imx_ldb_ch == &ldb->channel[0] || dual) { in imx_ldb_encoder_atomic_mode_set()
297 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in imx_ldb_encoder_atomic_mode_set()
298 ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
299 else if (mode->flags & DRM_MODE_FLAG_PVSYNC) in imx_ldb_encoder_atomic_mode_set()
300 ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
302 if (imx_ldb_ch == &ldb->channel[1] || dual) { in imx_ldb_encoder_atomic_mode_set()
303 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in imx_ldb_encoder_atomic_mode_set()
304 ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
305 else if (mode->flags & DRM_MODE_FLAG_PVSYNC) in imx_ldb_encoder_atomic_mode_set()
306 ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW; in imx_ldb_encoder_atomic_mode_set()
310 struct drm_connector *connector = connector_state->connector; in imx_ldb_encoder_atomic_mode_set()
311 struct drm_display_info *di = &connector->display_info; in imx_ldb_encoder_atomic_mode_set()
313 if (di->num_bus_formats) in imx_ldb_encoder_atomic_mode_set()
314 bus_format = di->bus_formats[0]; in imx_ldb_encoder_atomic_mode_set()
322 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_encoder_disable()
323 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; in imx_ldb_encoder_disable()
326 drm_panel_disable(imx_ldb_ch->panel); in imx_ldb_encoder_disable()
328 if (imx_ldb_ch == &ldb->channel[0] || dual) in imx_ldb_encoder_disable()
329 ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK; in imx_ldb_encoder_disable()
330 if (imx_ldb_ch == &ldb->channel[1] || dual) in imx_ldb_encoder_disable()
331 ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK; in imx_ldb_encoder_disable()
333 regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl); in imx_ldb_encoder_disable()
336 clk_disable_unprepare(ldb->clk[0]); in imx_ldb_encoder_disable()
337 clk_disable_unprepare(ldb->clk[1]); in imx_ldb_encoder_disable()
340 if (ldb->lvds_mux) { in imx_ldb_encoder_disable()
343 if (imx_ldb_ch == &ldb->channel[0]) in imx_ldb_encoder_disable()
344 lvds_mux = &ldb->lvds_mux[0]; in imx_ldb_encoder_disable()
345 else if (imx_ldb_ch == &ldb->channel[1]) in imx_ldb_encoder_disable()
346 lvds_mux = &ldb->lvds_mux[1]; in imx_ldb_encoder_disable()
348 regmap_read(ldb->regmap, lvds_mux->reg, &mux); in imx_ldb_encoder_disable()
349 mux &= lvds_mux->mask; in imx_ldb_encoder_disable()
350 mux >>= lvds_mux->shift; in imx_ldb_encoder_disable()
352 mux = (imx_ldb_ch == &ldb->channel[0]) ? 0 : 1; in imx_ldb_encoder_disable()
356 ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk_parent[mux]); in imx_ldb_encoder_disable()
358 dev_err(ldb->dev, in imx_ldb_encoder_disable()
362 drm_panel_unprepare(imx_ldb_ch->panel); in imx_ldb_encoder_disable()
371 struct drm_display_info *di = &conn_state->connector->display_info; in imx_ldb_encoder_atomic_check()
372 u32 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_check()
375 if (!bus_format && di->num_bus_formats) { in imx_ldb_encoder_atomic_check()
376 bus_format = di->bus_formats[0]; in imx_ldb_encoder_atomic_check()
377 imx_crtc_state->bus_flags = di->bus_flags; in imx_ldb_encoder_atomic_check()
379 bus_format = imx_ldb_ch->bus_format; in imx_ldb_encoder_atomic_check()
380 imx_crtc_state->bus_flags = imx_ldb_ch->bus_flags; in imx_ldb_encoder_atomic_check()
384 imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB666_1X18; in imx_ldb_encoder_atomic_check()
388 imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24; in imx_ldb_encoder_atomic_check()
391 return -EINVAL; in imx_ldb_encoder_atomic_check()
394 imx_crtc_state->di_hsync_pin = 2; in imx_ldb_encoder_atomic_check()
395 imx_crtc_state->di_vsync_pin = 3; in imx_ldb_encoder_atomic_check()
425 ldb->clk[chno] = devm_clk_get(ldb->dev, clkname); in imx_ldb_get_clk()
426 if (IS_ERR(ldb->clk[chno])) in imx_ldb_get_clk()
427 return PTR_ERR(ldb->clk[chno]); in imx_ldb_get_clk()
430 ldb->clk_pll[chno] = devm_clk_get(ldb->dev, clkname); in imx_ldb_get_clk()
432 return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]); in imx_ldb_get_clk()
438 struct imx_ldb *ldb = imx_ldb_ch->ldb; in imx_ldb_register()
449 ldb_encoder->channel = imx_ldb_ch; in imx_ldb_register()
450 connector = &ldb_encoder->connector; in imx_ldb_register()
451 encoder = &ldb_encoder->encoder; in imx_ldb_register()
453 ret = imx_drm_encoder_parse_of(drm, encoder, imx_ldb_ch->child); in imx_ldb_register()
457 ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno); in imx_ldb_register()
461 if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) { in imx_ldb_register()
469 if (imx_ldb_ch->bridge) { in imx_ldb_register()
470 ret = drm_bridge_attach(encoder, imx_ldb_ch->bridge, NULL, 0); in imx_ldb_register()
485 imx_ldb_ch->ddc); in imx_ldb_register()
510 ret = of_property_read_string(np, "fsl,data-mapping", &bm); in of_get_bus_format()
514 of_property_read_u32(np, "fsl,data-width", &datawidth); in of_get_bus_format()
522 dev_err(dev, "invalid data mapping: %d-bit \"%s\"\n", datawidth, bm); in of_get_bus_format()
524 return -ENOENT; in of_get_bus_format()
540 * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
543 * entries (in this case fsl,imx53-ldb) need to be ordered last.
546 { .compatible = "fsl,imx6q-ldb", .data = imx6q_lvds_mux, },
547 { .compatible = "fsl,imx53-ldb", .data = NULL, },
558 ddc_node = of_parse_phandle(child, "ddc-i2c-bus", 0); in imx_ldb_panel_ddc()
560 channel->ddc = of_find_i2c_adapter_by_node(ddc_node); in imx_ldb_panel_ddc()
562 if (!channel->ddc) { in imx_ldb_panel_ddc()
563 dev_warn(dev, "failed to get ddc i2c adapter\n"); in imx_ldb_panel_ddc()
564 return -EPROBE_DEFER; in imx_ldb_panel_ddc()
568 if (!channel->ddc) { in imx_ldb_panel_ddc()
572 /* if no DDC available, fallback to hardcoded EDID */ in imx_ldb_panel_ddc()
573 dev_dbg(dev, "no ddc available\n"); in imx_ldb_panel_ddc()
577 channel->drm_edid = drm_edid_alloc(edidp, edid_len); in imx_ldb_panel_ddc()
578 if (!channel->drm_edid) in imx_ldb_panel_ddc()
579 return -ENOMEM; in imx_ldb_panel_ddc()
580 } else if (!channel->panel) { in imx_ldb_panel_ddc()
581 /* fallback to display-timings node */ in imx_ldb_panel_ddc()
583 &channel->mode, in imx_ldb_panel_ddc()
584 &channel->bus_flags, in imx_ldb_panel_ddc()
587 channel->mode_valid = 1; in imx_ldb_panel_ddc()
601 struct imx_ldb_channel *channel = &imx_ldb->channel[i]; in imx_ldb_bind()
603 if (!channel->ldb) in imx_ldb_bind()
620 struct device *dev = &pdev->dev; in imx_ldb_probe()
621 struct device_node *np = dev->of_node; in imx_ldb_probe()
630 return -ENOMEM; in imx_ldb_probe()
632 imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr"); in imx_ldb_probe()
633 if (IS_ERR(imx_ldb->regmap)) { in imx_ldb_probe()
635 return PTR_ERR(imx_ldb->regmap); in imx_ldb_probe()
639 regmap_write(imx_ldb->regmap, IOMUXC_GPR2, 0); in imx_ldb_probe()
641 imx_ldb->dev = dev; in imx_ldb_probe()
642 imx_ldb->lvds_mux = device_get_match_data(dev); in imx_ldb_probe()
644 dual = of_property_read_bool(np, "fsl,dual-channel"); in imx_ldb_probe()
646 imx_ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN; in imx_ldb_probe()
659 imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname); in imx_ldb_probe()
660 if (IS_ERR(imx_ldb->clk_sel[i])) { in imx_ldb_probe()
661 ret = PTR_ERR(imx_ldb->clk_sel[i]); in imx_ldb_probe()
662 imx_ldb->clk_sel[i] = NULL; in imx_ldb_probe()
666 imx_ldb->clk_parent[i] = clk_get_parent(imx_ldb->clk_sel[i]); in imx_ldb_probe()
677 ret = -EINVAL; in imx_ldb_probe()
685 dev_warn(dev, "dual-channel mode, ignoring second output\n"); in imx_ldb_probe()
689 channel = &imx_ldb->channel[i]; in imx_ldb_probe()
690 channel->ldb = imx_ldb; in imx_ldb_probe()
691 channel->chno = i; in imx_ldb_probe()
694 * The output port is port@4 with an external 4-port mux or in imx_ldb_probe()
695 * port@2 with the internal 2-port mux. in imx_ldb_probe()
698 imx_ldb->lvds_mux ? 4 : 2, 0, in imx_ldb_probe()
699 &channel->panel, &channel->bridge); in imx_ldb_probe()
700 if (ret && ret != -ENODEV) in imx_ldb_probe()
703 /* panel ddc only if there is no bridge */ in imx_ldb_probe()
704 if (!channel->bridge) { in imx_ldb_probe()
711 if (bus_format == -EINVAL) { in imx_ldb_probe()
716 if (channel->panel && channel->panel->funcs && in imx_ldb_probe()
717 channel->panel->funcs->get_modes) in imx_ldb_probe()
726 channel->bus_format = bus_format; in imx_ldb_probe()
727 channel->child = child; in imx_ldb_probe()
732 return component_add(&pdev->dev, &imx_ldb_ops); in imx_ldb_probe()
745 struct imx_ldb_channel *channel = &imx_ldb->channel[i]; in imx_ldb_remove()
747 drm_edid_free(channel->drm_edid); in imx_ldb_remove()
748 i2c_put_adapter(channel->ddc); in imx_ldb_remove()
751 component_del(&pdev->dev, &imx_ldb_ops); in imx_ldb_remove()