Lines Matching +full:e +full:- +full:ddc
1 // SPDX-License-Identifier: GPL-2.0+
3 * i.MX drm driver - Television Encoder (TVEv2)
8 #include <linux/clk-provider.h>
18 #include <video/imx-ipu-v3.h>
26 #include "imx-drm.h"
117 struct i2c_adapter *ddc; member
126 return container_of(c, struct imx_tve_encoder, connector)->tve; in con_to_tve()
129 static inline struct imx_tve *enc_to_tve(struct drm_encoder *e) in enc_to_tve() argument
131 return container_of(e, struct imx_tve_encoder, encoder)->tve; in enc_to_tve()
136 clk_prepare_enable(tve->clk); in tve_enable()
137 regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, TVE_EN); in tve_enable()
140 regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff); in tve_enable()
143 if (tve->mode == TVE_MODE_VGA) in tve_enable()
144 regmap_write(tve->regmap, TVE_INT_CONT_REG, 0); in tve_enable()
146 regmap_write(tve->regmap, TVE_INT_CONT_REG, in tve_enable()
154 regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0); in tve_disable()
155 clk_disable_unprepare(tve->clk); in tve_disable()
160 return -ENOTSUPP; in tve_setup_tvout()
169 /* set gain to (1 + 10/128) to provide 0.7V peak-to-peak amplitude */ in tve_setup_vga()
170 ret = regmap_update_bits(tve->regmap, TVE_TVDAC0_CONT_REG, in tve_setup_vga()
175 ret = regmap_update_bits(tve->regmap, TVE_TVDAC1_CONT_REG, in tve_setup_vga()
180 ret = regmap_update_bits(tve->regmap, TVE_TVDAC2_CONT_REG, in tve_setup_vga()
192 ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, mask, val); in tve_setup_vga()
197 return regmap_update_bits(tve->regmap, TVE_TST_MODE_REG, in tve_setup_vga()
207 if (!tve->ddc) in imx_tve_connector_get_modes()
210 drm_edid = drm_edid_read_ddc(connector, tve->ddc); in imx_tve_connector_get_modes()
226 rate = clk_round_rate(tve->clk, 2000UL * mode->clock) / 2000; in imx_tve_connector_mode_valid()
227 if (rate == mode->clock) in imx_tve_connector_mode_valid()
231 rate = clk_round_rate(tve->clk, 1000UL * mode->clock) / 1000; in imx_tve_connector_mode_valid()
232 if (rate == mode->clock) in imx_tve_connector_mode_valid()
235 dev_warn(tve->dev, "ignoring mode %dx%d\n", in imx_tve_connector_mode_valid()
236 mode->hdisplay, mode->vdisplay); in imx_tve_connector_mode_valid()
253 * we should try 4k * mode->clock first, in imx_tve_encoder_mode_set()
256 rate = 2000UL * mode->clock; in imx_tve_encoder_mode_set()
257 clk_set_rate(tve->clk, rate); in imx_tve_encoder_mode_set()
258 rounded_rate = clk_get_rate(tve->clk); in imx_tve_encoder_mode_set()
261 clk_set_rate(tve->di_clk, rounded_rate / div); in imx_tve_encoder_mode_set()
263 ret = clk_set_parent(tve->di_sel_clk, tve->di_clk); in imx_tve_encoder_mode_set()
265 dev_err(tve->dev, "failed to set di_sel parent to tve_di: %d\n", in imx_tve_encoder_mode_set()
269 regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, in imx_tve_encoder_mode_set()
272 if (tve->mode == TVE_MODE_VGA) in imx_tve_encoder_mode_set()
277 dev_err(tve->dev, "failed to set configuration: %d\n", ret); in imx_tve_encoder_mode_set()
301 imx_crtc_state->bus_format = MEDIA_BUS_FMT_GBR888_1X24; in imx_tve_atomic_check()
302 imx_crtc_state->di_hsync_pin = tve->di_hsync_pin; in imx_tve_atomic_check()
303 imx_crtc_state->di_vsync_pin = tve->di_vsync_pin; in imx_tve_atomic_check()
333 regmap_read(tve->regmap, TVE_STAT_REG, &val); in imx_tve_irq_handler()
336 regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff); in imx_tve_irq_handler()
348 ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); in clk_tve_di_recalc_rate()
394 ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, in clk_tve_di_set_rate()
398 dev_err(tve->dev, "failed to set divider: %d\n", ret); in clk_tve_di_set_rate()
421 tve_di_parent[0] = __clk_get_name(tve->clk); in tve_clk_init()
424 tve->clk_hw_di.init = &init; in tve_clk_init()
425 tve->di_clk = devm_clk_register(tve->dev, &tve->clk_hw_di); in tve_clk_init()
426 if (IS_ERR(tve->di_clk)) { in tve_clk_init()
427 dev_err(tve->dev, "failed to register TVE output clock: %ld\n", in tve_clk_init()
428 PTR_ERR(tve->di_clk)); in tve_clk_init()
429 return PTR_ERR(tve->di_clk); in tve_clk_init()
439 regulator_disable(tve->dac_reg); in imx_tve_disable_regulator()
469 ret = of_property_read_string(np, "fsl,tve-mode", &bm); in of_get_tve_mode()
477 return -EINVAL; in of_get_tve_mode()
490 encoder_type = tve->mode == TVE_MODE_VGA ? in imx_tve_bind()
498 tvee->tve = tve; in imx_tve_bind()
499 encoder = &tvee->encoder; in imx_tve_bind()
500 connector = &tvee->connector; in imx_tve_bind()
502 ret = imx_drm_encoder_parse_of(drm, encoder, tve->dev->of_node); in imx_tve_bind()
511 DRM_MODE_CONNECTOR_VGA, tve->ddc); in imx_tve_bind()
524 struct device *dev = &pdev->dev; in imx_tve_probe()
525 struct device_node *np = dev->of_node; in imx_tve_probe()
535 return -ENOMEM; in imx_tve_probe()
537 tve->dev = dev; in imx_tve_probe()
539 ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); in imx_tve_probe()
541 tve->ddc = of_find_i2c_adapter_by_node(ddc_node); in imx_tve_probe()
545 tve->mode = of_get_tve_mode(np); in imx_tve_probe()
546 if (tve->mode != TVE_MODE_VGA) { in imx_tve_probe()
548 return -EINVAL; in imx_tve_probe()
551 if (tve->mode == TVE_MODE_VGA) { in imx_tve_probe()
552 ret = of_property_read_u32(np, "fsl,hsync-pin", in imx_tve_probe()
553 &tve->di_hsync_pin); in imx_tve_probe()
560 ret = of_property_read_u32(np, "fsl,vsync-pin", in imx_tve_probe()
561 &tve->di_vsync_pin); in imx_tve_probe()
574 tve->regmap = devm_regmap_init_mmio_clk(dev, "tve", base, in imx_tve_probe()
576 if (IS_ERR(tve->regmap)) { in imx_tve_probe()
578 PTR_ERR(tve->regmap)); in imx_tve_probe()
579 return PTR_ERR(tve->regmap); in imx_tve_probe()
588 "imx-tve", tve); in imx_tve_probe()
594 tve->dac_reg = devm_regulator_get(dev, "dac"); in imx_tve_probe()
595 if (!IS_ERR(tve->dac_reg)) { in imx_tve_probe()
596 if (regulator_get_voltage(tve->dac_reg) != IMX_TVE_DAC_VOLTAGE) in imx_tve_probe()
598 ret = regulator_enable(tve->dac_reg); in imx_tve_probe()
606 tve->clk = devm_clk_get(dev, "tve"); in imx_tve_probe()
607 if (IS_ERR(tve->clk)) { in imx_tve_probe()
609 PTR_ERR(tve->clk)); in imx_tve_probe()
610 return PTR_ERR(tve->clk); in imx_tve_probe()
614 tve->di_sel_clk = devm_clk_get(dev, "di_sel"); in imx_tve_probe()
615 if (IS_ERR(tve->di_sel_clk)) { in imx_tve_probe()
617 PTR_ERR(tve->di_sel_clk)); in imx_tve_probe()
618 return PTR_ERR(tve->di_sel_clk); in imx_tve_probe()
625 ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); in imx_tve_probe()
633 return -ENODEV; in imx_tve_probe()
637 ret = regmap_write(tve->regmap, TVE_CD_CONT_REG, 0); in imx_tve_probe()
648 component_del(&pdev->dev, &imx_tve_ops); in imx_tve_remove()
652 { .compatible = "fsl,imx53-tve", },
662 .name = "imx-tve",
671 MODULE_ALIAS("platform:imx-tve");