xref: /linux/drivers/gpu/drm/imx/ipuv3/imx-tve.c (revision 4b6cb2b67da883bc5095ee6d77f951f1cd7a1c24)
1*4b6cb2b6SLucas Stach // SPDX-License-Identifier: GPL-2.0+
2*4b6cb2b6SLucas Stach /*
3*4b6cb2b6SLucas Stach  * i.MX drm driver - Television Encoder (TVEv2)
4*4b6cb2b6SLucas Stach  *
5*4b6cb2b6SLucas Stach  * Copyright (C) 2013 Philipp Zabel, Pengutronix
6*4b6cb2b6SLucas Stach  */
7*4b6cb2b6SLucas Stach 
8*4b6cb2b6SLucas Stach #include <linux/clk-provider.h>
9*4b6cb2b6SLucas Stach #include <linux/clk.h>
10*4b6cb2b6SLucas Stach #include <linux/component.h>
11*4b6cb2b6SLucas Stach #include <linux/i2c.h>
12*4b6cb2b6SLucas Stach #include <linux/module.h>
13*4b6cb2b6SLucas Stach #include <linux/platform_device.h>
14*4b6cb2b6SLucas Stach #include <linux/regmap.h>
15*4b6cb2b6SLucas Stach #include <linux/regulator/consumer.h>
16*4b6cb2b6SLucas Stach #include <linux/videodev2.h>
17*4b6cb2b6SLucas Stach 
18*4b6cb2b6SLucas Stach #include <video/imx-ipu-v3.h>
19*4b6cb2b6SLucas Stach 
20*4b6cb2b6SLucas Stach #include <drm/drm_atomic_helper.h>
21*4b6cb2b6SLucas Stach #include <drm/drm_edid.h>
22*4b6cb2b6SLucas Stach #include <drm/drm_managed.h>
23*4b6cb2b6SLucas Stach #include <drm/drm_probe_helper.h>
24*4b6cb2b6SLucas Stach #include <drm/drm_simple_kms_helper.h>
25*4b6cb2b6SLucas Stach 
26*4b6cb2b6SLucas Stach #include "imx-drm.h"
27*4b6cb2b6SLucas Stach 
28*4b6cb2b6SLucas Stach #define TVE_COM_CONF_REG	0x00
29*4b6cb2b6SLucas Stach #define TVE_TVDAC0_CONT_REG	0x28
30*4b6cb2b6SLucas Stach #define TVE_TVDAC1_CONT_REG	0x2c
31*4b6cb2b6SLucas Stach #define TVE_TVDAC2_CONT_REG	0x30
32*4b6cb2b6SLucas Stach #define TVE_CD_CONT_REG		0x34
33*4b6cb2b6SLucas Stach #define TVE_INT_CONT_REG	0x64
34*4b6cb2b6SLucas Stach #define TVE_STAT_REG		0x68
35*4b6cb2b6SLucas Stach #define TVE_TST_MODE_REG	0x6c
36*4b6cb2b6SLucas Stach #define TVE_MV_CONT_REG		0xdc
37*4b6cb2b6SLucas Stach 
38*4b6cb2b6SLucas Stach /* TVE_COM_CONF_REG */
39*4b6cb2b6SLucas Stach #define TVE_SYNC_CH_2_EN	BIT(22)
40*4b6cb2b6SLucas Stach #define TVE_SYNC_CH_1_EN	BIT(21)
41*4b6cb2b6SLucas Stach #define TVE_SYNC_CH_0_EN	BIT(20)
42*4b6cb2b6SLucas Stach #define TVE_TV_OUT_MODE_MASK	(0x7 << 12)
43*4b6cb2b6SLucas Stach #define TVE_TV_OUT_DISABLE	(0x0 << 12)
44*4b6cb2b6SLucas Stach #define TVE_TV_OUT_CVBS_0	(0x1 << 12)
45*4b6cb2b6SLucas Stach #define TVE_TV_OUT_CVBS_2	(0x2 << 12)
46*4b6cb2b6SLucas Stach #define TVE_TV_OUT_CVBS_0_2	(0x3 << 12)
47*4b6cb2b6SLucas Stach #define TVE_TV_OUT_SVIDEO_0_1	(0x4 << 12)
48*4b6cb2b6SLucas Stach #define TVE_TV_OUT_SVIDEO_0_1_CVBS2_2	(0x5 << 12)
49*4b6cb2b6SLucas Stach #define TVE_TV_OUT_YPBPR	(0x6 << 12)
50*4b6cb2b6SLucas Stach #define TVE_TV_OUT_RGB		(0x7 << 12)
51*4b6cb2b6SLucas Stach #define TVE_TV_STAND_MASK	(0xf << 8)
52*4b6cb2b6SLucas Stach #define TVE_TV_STAND_HD_1080P30	(0xc << 8)
53*4b6cb2b6SLucas Stach #define TVE_P2I_CONV_EN		BIT(7)
54*4b6cb2b6SLucas Stach #define TVE_INP_VIDEO_FORM	BIT(6)
55*4b6cb2b6SLucas Stach #define TVE_INP_YCBCR_422	(0x0 << 6)
56*4b6cb2b6SLucas Stach #define TVE_INP_YCBCR_444	(0x1 << 6)
57*4b6cb2b6SLucas Stach #define TVE_DATA_SOURCE_MASK	(0x3 << 4)
58*4b6cb2b6SLucas Stach #define TVE_DATA_SOURCE_BUS1	(0x0 << 4)
59*4b6cb2b6SLucas Stach #define TVE_DATA_SOURCE_BUS2	(0x1 << 4)
60*4b6cb2b6SLucas Stach #define TVE_DATA_SOURCE_EXT	(0x2 << 4)
61*4b6cb2b6SLucas Stach #define TVE_DATA_SOURCE_TESTGEN	(0x3 << 4)
62*4b6cb2b6SLucas Stach #define TVE_IPU_CLK_EN_OFS	3
63*4b6cb2b6SLucas Stach #define TVE_IPU_CLK_EN		BIT(3)
64*4b6cb2b6SLucas Stach #define TVE_DAC_SAMP_RATE_OFS	1
65*4b6cb2b6SLucas Stach #define TVE_DAC_SAMP_RATE_WIDTH	2
66*4b6cb2b6SLucas Stach #define TVE_DAC_SAMP_RATE_MASK	(0x3 << 1)
67*4b6cb2b6SLucas Stach #define TVE_DAC_FULL_RATE	(0x0 << 1)
68*4b6cb2b6SLucas Stach #define TVE_DAC_DIV2_RATE	(0x1 << 1)
69*4b6cb2b6SLucas Stach #define TVE_DAC_DIV4_RATE	(0x2 << 1)
70*4b6cb2b6SLucas Stach #define TVE_EN			BIT(0)
71*4b6cb2b6SLucas Stach 
72*4b6cb2b6SLucas Stach /* TVE_TVDACx_CONT_REG */
73*4b6cb2b6SLucas Stach #define TVE_TVDAC_GAIN_MASK	(0x3f << 0)
74*4b6cb2b6SLucas Stach 
75*4b6cb2b6SLucas Stach /* TVE_CD_CONT_REG */
76*4b6cb2b6SLucas Stach #define TVE_CD_CH_2_SM_EN	BIT(22)
77*4b6cb2b6SLucas Stach #define TVE_CD_CH_1_SM_EN	BIT(21)
78*4b6cb2b6SLucas Stach #define TVE_CD_CH_0_SM_EN	BIT(20)
79*4b6cb2b6SLucas Stach #define TVE_CD_CH_2_LM_EN	BIT(18)
80*4b6cb2b6SLucas Stach #define TVE_CD_CH_1_LM_EN	BIT(17)
81*4b6cb2b6SLucas Stach #define TVE_CD_CH_0_LM_EN	BIT(16)
82*4b6cb2b6SLucas Stach #define TVE_CD_CH_2_REF_LVL	BIT(10)
83*4b6cb2b6SLucas Stach #define TVE_CD_CH_1_REF_LVL	BIT(9)
84*4b6cb2b6SLucas Stach #define TVE_CD_CH_0_REF_LVL	BIT(8)
85*4b6cb2b6SLucas Stach #define TVE_CD_EN		BIT(0)
86*4b6cb2b6SLucas Stach 
87*4b6cb2b6SLucas Stach /* TVE_INT_CONT_REG */
88*4b6cb2b6SLucas Stach #define TVE_FRAME_END_IEN	BIT(13)
89*4b6cb2b6SLucas Stach #define TVE_CD_MON_END_IEN	BIT(2)
90*4b6cb2b6SLucas Stach #define TVE_CD_SM_IEN		BIT(1)
91*4b6cb2b6SLucas Stach #define TVE_CD_LM_IEN		BIT(0)
92*4b6cb2b6SLucas Stach 
93*4b6cb2b6SLucas Stach /* TVE_TST_MODE_REG */
94*4b6cb2b6SLucas Stach #define TVE_TVDAC_TEST_MODE_MASK	(0x7 << 0)
95*4b6cb2b6SLucas Stach 
96*4b6cb2b6SLucas Stach #define IMX_TVE_DAC_VOLTAGE	2750000
97*4b6cb2b6SLucas Stach 
98*4b6cb2b6SLucas Stach enum {
99*4b6cb2b6SLucas Stach 	TVE_MODE_TVOUT,
100*4b6cb2b6SLucas Stach 	TVE_MODE_VGA,
101*4b6cb2b6SLucas Stach };
102*4b6cb2b6SLucas Stach 
103*4b6cb2b6SLucas Stach struct imx_tve_encoder {
104*4b6cb2b6SLucas Stach 	struct drm_connector connector;
105*4b6cb2b6SLucas Stach 	struct drm_encoder encoder;
106*4b6cb2b6SLucas Stach 	struct imx_tve *tve;
107*4b6cb2b6SLucas Stach };
108*4b6cb2b6SLucas Stach 
109*4b6cb2b6SLucas Stach struct imx_tve {
110*4b6cb2b6SLucas Stach 	struct device *dev;
111*4b6cb2b6SLucas Stach 	int mode;
112*4b6cb2b6SLucas Stach 	int di_hsync_pin;
113*4b6cb2b6SLucas Stach 	int di_vsync_pin;
114*4b6cb2b6SLucas Stach 
115*4b6cb2b6SLucas Stach 	struct regmap *regmap;
116*4b6cb2b6SLucas Stach 	struct regulator *dac_reg;
117*4b6cb2b6SLucas Stach 	struct i2c_adapter *ddc;
118*4b6cb2b6SLucas Stach 	struct clk *clk;
119*4b6cb2b6SLucas Stach 	struct clk *di_sel_clk;
120*4b6cb2b6SLucas Stach 	struct clk_hw clk_hw_di;
121*4b6cb2b6SLucas Stach 	struct clk *di_clk;
122*4b6cb2b6SLucas Stach };
123*4b6cb2b6SLucas Stach 
124*4b6cb2b6SLucas Stach static inline struct imx_tve *con_to_tve(struct drm_connector *c)
125*4b6cb2b6SLucas Stach {
126*4b6cb2b6SLucas Stach 	return container_of(c, struct imx_tve_encoder, connector)->tve;
127*4b6cb2b6SLucas Stach }
128*4b6cb2b6SLucas Stach 
129*4b6cb2b6SLucas Stach static inline struct imx_tve *enc_to_tve(struct drm_encoder *e)
130*4b6cb2b6SLucas Stach {
131*4b6cb2b6SLucas Stach 	return container_of(e, struct imx_tve_encoder, encoder)->tve;
132*4b6cb2b6SLucas Stach }
133*4b6cb2b6SLucas Stach 
134*4b6cb2b6SLucas Stach static void tve_enable(struct imx_tve *tve)
135*4b6cb2b6SLucas Stach {
136*4b6cb2b6SLucas Stach 	clk_prepare_enable(tve->clk);
137*4b6cb2b6SLucas Stach 	regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, TVE_EN);
138*4b6cb2b6SLucas Stach 
139*4b6cb2b6SLucas Stach 	/* clear interrupt status register */
140*4b6cb2b6SLucas Stach 	regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff);
141*4b6cb2b6SLucas Stach 
142*4b6cb2b6SLucas Stach 	/* cable detection irq disabled in VGA mode, enabled in TVOUT mode */
143*4b6cb2b6SLucas Stach 	if (tve->mode == TVE_MODE_VGA)
144*4b6cb2b6SLucas Stach 		regmap_write(tve->regmap, TVE_INT_CONT_REG, 0);
145*4b6cb2b6SLucas Stach 	else
146*4b6cb2b6SLucas Stach 		regmap_write(tve->regmap, TVE_INT_CONT_REG,
147*4b6cb2b6SLucas Stach 			     TVE_CD_SM_IEN |
148*4b6cb2b6SLucas Stach 			     TVE_CD_LM_IEN |
149*4b6cb2b6SLucas Stach 			     TVE_CD_MON_END_IEN);
150*4b6cb2b6SLucas Stach }
151*4b6cb2b6SLucas Stach 
152*4b6cb2b6SLucas Stach static void tve_disable(struct imx_tve *tve)
153*4b6cb2b6SLucas Stach {
154*4b6cb2b6SLucas Stach 	regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0);
155*4b6cb2b6SLucas Stach 	clk_disable_unprepare(tve->clk);
156*4b6cb2b6SLucas Stach }
157*4b6cb2b6SLucas Stach 
158*4b6cb2b6SLucas Stach static int tve_setup_tvout(struct imx_tve *tve)
159*4b6cb2b6SLucas Stach {
160*4b6cb2b6SLucas Stach 	return -ENOTSUPP;
161*4b6cb2b6SLucas Stach }
162*4b6cb2b6SLucas Stach 
163*4b6cb2b6SLucas Stach static int tve_setup_vga(struct imx_tve *tve)
164*4b6cb2b6SLucas Stach {
165*4b6cb2b6SLucas Stach 	unsigned int mask;
166*4b6cb2b6SLucas Stach 	unsigned int val;
167*4b6cb2b6SLucas Stach 	int ret;
168*4b6cb2b6SLucas Stach 
169*4b6cb2b6SLucas Stach 	/* set gain to (1 + 10/128) to provide 0.7V peak-to-peak amplitude */
170*4b6cb2b6SLucas Stach 	ret = regmap_update_bits(tve->regmap, TVE_TVDAC0_CONT_REG,
171*4b6cb2b6SLucas Stach 				 TVE_TVDAC_GAIN_MASK, 0x0a);
172*4b6cb2b6SLucas Stach 	if (ret)
173*4b6cb2b6SLucas Stach 		return ret;
174*4b6cb2b6SLucas Stach 
175*4b6cb2b6SLucas Stach 	ret = regmap_update_bits(tve->regmap, TVE_TVDAC1_CONT_REG,
176*4b6cb2b6SLucas Stach 				 TVE_TVDAC_GAIN_MASK, 0x0a);
177*4b6cb2b6SLucas Stach 	if (ret)
178*4b6cb2b6SLucas Stach 		return ret;
179*4b6cb2b6SLucas Stach 
180*4b6cb2b6SLucas Stach 	ret = regmap_update_bits(tve->regmap, TVE_TVDAC2_CONT_REG,
181*4b6cb2b6SLucas Stach 				 TVE_TVDAC_GAIN_MASK, 0x0a);
182*4b6cb2b6SLucas Stach 	if (ret)
183*4b6cb2b6SLucas Stach 		return ret;
184*4b6cb2b6SLucas Stach 
185*4b6cb2b6SLucas Stach 	/* set configuration register */
186*4b6cb2b6SLucas Stach 	mask = TVE_DATA_SOURCE_MASK | TVE_INP_VIDEO_FORM;
187*4b6cb2b6SLucas Stach 	val  = TVE_DATA_SOURCE_BUS2 | TVE_INP_YCBCR_444;
188*4b6cb2b6SLucas Stach 	mask |= TVE_TV_STAND_MASK       | TVE_P2I_CONV_EN;
189*4b6cb2b6SLucas Stach 	val  |= TVE_TV_STAND_HD_1080P30 | 0;
190*4b6cb2b6SLucas Stach 	mask |= TVE_TV_OUT_MODE_MASK | TVE_SYNC_CH_0_EN;
191*4b6cb2b6SLucas Stach 	val  |= TVE_TV_OUT_RGB       | TVE_SYNC_CH_0_EN;
192*4b6cb2b6SLucas Stach 	ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, mask, val);
193*4b6cb2b6SLucas Stach 	if (ret)
194*4b6cb2b6SLucas Stach 		return ret;
195*4b6cb2b6SLucas Stach 
196*4b6cb2b6SLucas Stach 	/* set test mode (as documented) */
197*4b6cb2b6SLucas Stach 	return regmap_update_bits(tve->regmap, TVE_TST_MODE_REG,
198*4b6cb2b6SLucas Stach 				 TVE_TVDAC_TEST_MODE_MASK, 1);
199*4b6cb2b6SLucas Stach }
200*4b6cb2b6SLucas Stach 
201*4b6cb2b6SLucas Stach static int imx_tve_connector_get_modes(struct drm_connector *connector)
202*4b6cb2b6SLucas Stach {
203*4b6cb2b6SLucas Stach 	struct imx_tve *tve = con_to_tve(connector);
204*4b6cb2b6SLucas Stach 	struct edid *edid;
205*4b6cb2b6SLucas Stach 	int ret = 0;
206*4b6cb2b6SLucas Stach 
207*4b6cb2b6SLucas Stach 	if (!tve->ddc)
208*4b6cb2b6SLucas Stach 		return 0;
209*4b6cb2b6SLucas Stach 
210*4b6cb2b6SLucas Stach 	edid = drm_get_edid(connector, tve->ddc);
211*4b6cb2b6SLucas Stach 	if (edid) {
212*4b6cb2b6SLucas Stach 		drm_connector_update_edid_property(connector, edid);
213*4b6cb2b6SLucas Stach 		ret = drm_add_edid_modes(connector, edid);
214*4b6cb2b6SLucas Stach 		kfree(edid);
215*4b6cb2b6SLucas Stach 	}
216*4b6cb2b6SLucas Stach 
217*4b6cb2b6SLucas Stach 	return ret;
218*4b6cb2b6SLucas Stach }
219*4b6cb2b6SLucas Stach 
220*4b6cb2b6SLucas Stach static enum drm_mode_status
221*4b6cb2b6SLucas Stach imx_tve_connector_mode_valid(struct drm_connector *connector,
222*4b6cb2b6SLucas Stach 			     struct drm_display_mode *mode)
223*4b6cb2b6SLucas Stach {
224*4b6cb2b6SLucas Stach 	struct imx_tve *tve = con_to_tve(connector);
225*4b6cb2b6SLucas Stach 	unsigned long rate;
226*4b6cb2b6SLucas Stach 
227*4b6cb2b6SLucas Stach 	/* pixel clock with 2x oversampling */
228*4b6cb2b6SLucas Stach 	rate = clk_round_rate(tve->clk, 2000UL * mode->clock) / 2000;
229*4b6cb2b6SLucas Stach 	if (rate == mode->clock)
230*4b6cb2b6SLucas Stach 		return MODE_OK;
231*4b6cb2b6SLucas Stach 
232*4b6cb2b6SLucas Stach 	/* pixel clock without oversampling */
233*4b6cb2b6SLucas Stach 	rate = clk_round_rate(tve->clk, 1000UL * mode->clock) / 1000;
234*4b6cb2b6SLucas Stach 	if (rate == mode->clock)
235*4b6cb2b6SLucas Stach 		return MODE_OK;
236*4b6cb2b6SLucas Stach 
237*4b6cb2b6SLucas Stach 	dev_warn(tve->dev, "ignoring mode %dx%d\n",
238*4b6cb2b6SLucas Stach 		 mode->hdisplay, mode->vdisplay);
239*4b6cb2b6SLucas Stach 
240*4b6cb2b6SLucas Stach 	return MODE_BAD;
241*4b6cb2b6SLucas Stach }
242*4b6cb2b6SLucas Stach 
243*4b6cb2b6SLucas Stach static void imx_tve_encoder_mode_set(struct drm_encoder *encoder,
244*4b6cb2b6SLucas Stach 				     struct drm_display_mode *orig_mode,
245*4b6cb2b6SLucas Stach 				     struct drm_display_mode *mode)
246*4b6cb2b6SLucas Stach {
247*4b6cb2b6SLucas Stach 	struct imx_tve *tve = enc_to_tve(encoder);
248*4b6cb2b6SLucas Stach 	unsigned long rounded_rate;
249*4b6cb2b6SLucas Stach 	unsigned long rate;
250*4b6cb2b6SLucas Stach 	int div = 1;
251*4b6cb2b6SLucas Stach 	int ret;
252*4b6cb2b6SLucas Stach 
253*4b6cb2b6SLucas Stach 	/*
254*4b6cb2b6SLucas Stach 	 * FIXME
255*4b6cb2b6SLucas Stach 	 * we should try 4k * mode->clock first,
256*4b6cb2b6SLucas Stach 	 * and enable 4x oversampling for lower resolutions
257*4b6cb2b6SLucas Stach 	 */
258*4b6cb2b6SLucas Stach 	rate = 2000UL * mode->clock;
259*4b6cb2b6SLucas Stach 	clk_set_rate(tve->clk, rate);
260*4b6cb2b6SLucas Stach 	rounded_rate = clk_get_rate(tve->clk);
261*4b6cb2b6SLucas Stach 	if (rounded_rate >= rate)
262*4b6cb2b6SLucas Stach 		div = 2;
263*4b6cb2b6SLucas Stach 	clk_set_rate(tve->di_clk, rounded_rate / div);
264*4b6cb2b6SLucas Stach 
265*4b6cb2b6SLucas Stach 	ret = clk_set_parent(tve->di_sel_clk, tve->di_clk);
266*4b6cb2b6SLucas Stach 	if (ret < 0) {
267*4b6cb2b6SLucas Stach 		dev_err(tve->dev, "failed to set di_sel parent to tve_di: %d\n",
268*4b6cb2b6SLucas Stach 			ret);
269*4b6cb2b6SLucas Stach 	}
270*4b6cb2b6SLucas Stach 
271*4b6cb2b6SLucas Stach 	regmap_update_bits(tve->regmap, TVE_COM_CONF_REG,
272*4b6cb2b6SLucas Stach 			   TVE_IPU_CLK_EN, TVE_IPU_CLK_EN);
273*4b6cb2b6SLucas Stach 
274*4b6cb2b6SLucas Stach 	if (tve->mode == TVE_MODE_VGA)
275*4b6cb2b6SLucas Stach 		ret = tve_setup_vga(tve);
276*4b6cb2b6SLucas Stach 	else
277*4b6cb2b6SLucas Stach 		ret = tve_setup_tvout(tve);
278*4b6cb2b6SLucas Stach 	if (ret)
279*4b6cb2b6SLucas Stach 		dev_err(tve->dev, "failed to set configuration: %d\n", ret);
280*4b6cb2b6SLucas Stach }
281*4b6cb2b6SLucas Stach 
282*4b6cb2b6SLucas Stach static void imx_tve_encoder_enable(struct drm_encoder *encoder)
283*4b6cb2b6SLucas Stach {
284*4b6cb2b6SLucas Stach 	struct imx_tve *tve = enc_to_tve(encoder);
285*4b6cb2b6SLucas Stach 
286*4b6cb2b6SLucas Stach 	tve_enable(tve);
287*4b6cb2b6SLucas Stach }
288*4b6cb2b6SLucas Stach 
289*4b6cb2b6SLucas Stach static void imx_tve_encoder_disable(struct drm_encoder *encoder)
290*4b6cb2b6SLucas Stach {
291*4b6cb2b6SLucas Stach 	struct imx_tve *tve = enc_to_tve(encoder);
292*4b6cb2b6SLucas Stach 
293*4b6cb2b6SLucas Stach 	tve_disable(tve);
294*4b6cb2b6SLucas Stach }
295*4b6cb2b6SLucas Stach 
296*4b6cb2b6SLucas Stach static int imx_tve_atomic_check(struct drm_encoder *encoder,
297*4b6cb2b6SLucas Stach 				struct drm_crtc_state *crtc_state,
298*4b6cb2b6SLucas Stach 				struct drm_connector_state *conn_state)
299*4b6cb2b6SLucas Stach {
300*4b6cb2b6SLucas Stach 	struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
301*4b6cb2b6SLucas Stach 	struct imx_tve *tve = enc_to_tve(encoder);
302*4b6cb2b6SLucas Stach 
303*4b6cb2b6SLucas Stach 	imx_crtc_state->bus_format = MEDIA_BUS_FMT_GBR888_1X24;
304*4b6cb2b6SLucas Stach 	imx_crtc_state->di_hsync_pin = tve->di_hsync_pin;
305*4b6cb2b6SLucas Stach 	imx_crtc_state->di_vsync_pin = tve->di_vsync_pin;
306*4b6cb2b6SLucas Stach 
307*4b6cb2b6SLucas Stach 	return 0;
308*4b6cb2b6SLucas Stach }
309*4b6cb2b6SLucas Stach 
310*4b6cb2b6SLucas Stach static const struct drm_connector_funcs imx_tve_connector_funcs = {
311*4b6cb2b6SLucas Stach 	.fill_modes = drm_helper_probe_single_connector_modes,
312*4b6cb2b6SLucas Stach 	.destroy = imx_drm_connector_destroy,
313*4b6cb2b6SLucas Stach 	.reset = drm_atomic_helper_connector_reset,
314*4b6cb2b6SLucas Stach 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
315*4b6cb2b6SLucas Stach 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
316*4b6cb2b6SLucas Stach };
317*4b6cb2b6SLucas Stach 
318*4b6cb2b6SLucas Stach static const struct drm_connector_helper_funcs imx_tve_connector_helper_funcs = {
319*4b6cb2b6SLucas Stach 	.get_modes = imx_tve_connector_get_modes,
320*4b6cb2b6SLucas Stach 	.mode_valid = imx_tve_connector_mode_valid,
321*4b6cb2b6SLucas Stach };
322*4b6cb2b6SLucas Stach 
323*4b6cb2b6SLucas Stach static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = {
324*4b6cb2b6SLucas Stach 	.mode_set = imx_tve_encoder_mode_set,
325*4b6cb2b6SLucas Stach 	.enable = imx_tve_encoder_enable,
326*4b6cb2b6SLucas Stach 	.disable = imx_tve_encoder_disable,
327*4b6cb2b6SLucas Stach 	.atomic_check = imx_tve_atomic_check,
328*4b6cb2b6SLucas Stach };
329*4b6cb2b6SLucas Stach 
330*4b6cb2b6SLucas Stach static irqreturn_t imx_tve_irq_handler(int irq, void *data)
331*4b6cb2b6SLucas Stach {
332*4b6cb2b6SLucas Stach 	struct imx_tve *tve = data;
333*4b6cb2b6SLucas Stach 	unsigned int val;
334*4b6cb2b6SLucas Stach 
335*4b6cb2b6SLucas Stach 	regmap_read(tve->regmap, TVE_STAT_REG, &val);
336*4b6cb2b6SLucas Stach 
337*4b6cb2b6SLucas Stach 	/* clear interrupt status register */
338*4b6cb2b6SLucas Stach 	regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff);
339*4b6cb2b6SLucas Stach 
340*4b6cb2b6SLucas Stach 	return IRQ_HANDLED;
341*4b6cb2b6SLucas Stach }
342*4b6cb2b6SLucas Stach 
343*4b6cb2b6SLucas Stach static unsigned long clk_tve_di_recalc_rate(struct clk_hw *hw,
344*4b6cb2b6SLucas Stach 					    unsigned long parent_rate)
345*4b6cb2b6SLucas Stach {
346*4b6cb2b6SLucas Stach 	struct imx_tve *tve = container_of(hw, struct imx_tve, clk_hw_di);
347*4b6cb2b6SLucas Stach 	unsigned int val;
348*4b6cb2b6SLucas Stach 	int ret;
349*4b6cb2b6SLucas Stach 
350*4b6cb2b6SLucas Stach 	ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val);
351*4b6cb2b6SLucas Stach 	if (ret < 0)
352*4b6cb2b6SLucas Stach 		return 0;
353*4b6cb2b6SLucas Stach 
354*4b6cb2b6SLucas Stach 	switch (val & TVE_DAC_SAMP_RATE_MASK) {
355*4b6cb2b6SLucas Stach 	case TVE_DAC_DIV4_RATE:
356*4b6cb2b6SLucas Stach 		return parent_rate / 4;
357*4b6cb2b6SLucas Stach 	case TVE_DAC_DIV2_RATE:
358*4b6cb2b6SLucas Stach 		return parent_rate / 2;
359*4b6cb2b6SLucas Stach 	case TVE_DAC_FULL_RATE:
360*4b6cb2b6SLucas Stach 	default:
361*4b6cb2b6SLucas Stach 		return parent_rate;
362*4b6cb2b6SLucas Stach 	}
363*4b6cb2b6SLucas Stach 
364*4b6cb2b6SLucas Stach 	return 0;
365*4b6cb2b6SLucas Stach }
366*4b6cb2b6SLucas Stach 
367*4b6cb2b6SLucas Stach static long clk_tve_di_round_rate(struct clk_hw *hw, unsigned long rate,
368*4b6cb2b6SLucas Stach 				  unsigned long *prate)
369*4b6cb2b6SLucas Stach {
370*4b6cb2b6SLucas Stach 	unsigned long div;
371*4b6cb2b6SLucas Stach 
372*4b6cb2b6SLucas Stach 	div = *prate / rate;
373*4b6cb2b6SLucas Stach 	if (div >= 4)
374*4b6cb2b6SLucas Stach 		return *prate / 4;
375*4b6cb2b6SLucas Stach 	else if (div >= 2)
376*4b6cb2b6SLucas Stach 		return *prate / 2;
377*4b6cb2b6SLucas Stach 	return *prate;
378*4b6cb2b6SLucas Stach }
379*4b6cb2b6SLucas Stach 
380*4b6cb2b6SLucas Stach static int clk_tve_di_set_rate(struct clk_hw *hw, unsigned long rate,
381*4b6cb2b6SLucas Stach 			       unsigned long parent_rate)
382*4b6cb2b6SLucas Stach {
383*4b6cb2b6SLucas Stach 	struct imx_tve *tve = container_of(hw, struct imx_tve, clk_hw_di);
384*4b6cb2b6SLucas Stach 	unsigned long div;
385*4b6cb2b6SLucas Stach 	u32 val;
386*4b6cb2b6SLucas Stach 	int ret;
387*4b6cb2b6SLucas Stach 
388*4b6cb2b6SLucas Stach 	div = parent_rate / rate;
389*4b6cb2b6SLucas Stach 	if (div >= 4)
390*4b6cb2b6SLucas Stach 		val = TVE_DAC_DIV4_RATE;
391*4b6cb2b6SLucas Stach 	else if (div >= 2)
392*4b6cb2b6SLucas Stach 		val = TVE_DAC_DIV2_RATE;
393*4b6cb2b6SLucas Stach 	else
394*4b6cb2b6SLucas Stach 		val = TVE_DAC_FULL_RATE;
395*4b6cb2b6SLucas Stach 
396*4b6cb2b6SLucas Stach 	ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG,
397*4b6cb2b6SLucas Stach 				 TVE_DAC_SAMP_RATE_MASK, val);
398*4b6cb2b6SLucas Stach 
399*4b6cb2b6SLucas Stach 	if (ret < 0) {
400*4b6cb2b6SLucas Stach 		dev_err(tve->dev, "failed to set divider: %d\n", ret);
401*4b6cb2b6SLucas Stach 		return ret;
402*4b6cb2b6SLucas Stach 	}
403*4b6cb2b6SLucas Stach 
404*4b6cb2b6SLucas Stach 	return 0;
405*4b6cb2b6SLucas Stach }
406*4b6cb2b6SLucas Stach 
407*4b6cb2b6SLucas Stach static const struct clk_ops clk_tve_di_ops = {
408*4b6cb2b6SLucas Stach 	.round_rate = clk_tve_di_round_rate,
409*4b6cb2b6SLucas Stach 	.set_rate = clk_tve_di_set_rate,
410*4b6cb2b6SLucas Stach 	.recalc_rate = clk_tve_di_recalc_rate,
411*4b6cb2b6SLucas Stach };
412*4b6cb2b6SLucas Stach 
413*4b6cb2b6SLucas Stach static int tve_clk_init(struct imx_tve *tve, void __iomem *base)
414*4b6cb2b6SLucas Stach {
415*4b6cb2b6SLucas Stach 	const char *tve_di_parent[1];
416*4b6cb2b6SLucas Stach 	struct clk_init_data init = {
417*4b6cb2b6SLucas Stach 		.name = "tve_di",
418*4b6cb2b6SLucas Stach 		.ops = &clk_tve_di_ops,
419*4b6cb2b6SLucas Stach 		.num_parents = 1,
420*4b6cb2b6SLucas Stach 		.flags = 0,
421*4b6cb2b6SLucas Stach 	};
422*4b6cb2b6SLucas Stach 
423*4b6cb2b6SLucas Stach 	tve_di_parent[0] = __clk_get_name(tve->clk);
424*4b6cb2b6SLucas Stach 	init.parent_names = (const char **)&tve_di_parent;
425*4b6cb2b6SLucas Stach 
426*4b6cb2b6SLucas Stach 	tve->clk_hw_di.init = &init;
427*4b6cb2b6SLucas Stach 	tve->di_clk = devm_clk_register(tve->dev, &tve->clk_hw_di);
428*4b6cb2b6SLucas Stach 	if (IS_ERR(tve->di_clk)) {
429*4b6cb2b6SLucas Stach 		dev_err(tve->dev, "failed to register TVE output clock: %ld\n",
430*4b6cb2b6SLucas Stach 			PTR_ERR(tve->di_clk));
431*4b6cb2b6SLucas Stach 		return PTR_ERR(tve->di_clk);
432*4b6cb2b6SLucas Stach 	}
433*4b6cb2b6SLucas Stach 
434*4b6cb2b6SLucas Stach 	return 0;
435*4b6cb2b6SLucas Stach }
436*4b6cb2b6SLucas Stach 
437*4b6cb2b6SLucas Stach static void imx_tve_disable_regulator(void *data)
438*4b6cb2b6SLucas Stach {
439*4b6cb2b6SLucas Stach 	struct imx_tve *tve = data;
440*4b6cb2b6SLucas Stach 
441*4b6cb2b6SLucas Stach 	regulator_disable(tve->dac_reg);
442*4b6cb2b6SLucas Stach }
443*4b6cb2b6SLucas Stach 
444*4b6cb2b6SLucas Stach static bool imx_tve_readable_reg(struct device *dev, unsigned int reg)
445*4b6cb2b6SLucas Stach {
446*4b6cb2b6SLucas Stach 	return (reg % 4 == 0) && (reg <= 0xdc);
447*4b6cb2b6SLucas Stach }
448*4b6cb2b6SLucas Stach 
449*4b6cb2b6SLucas Stach static struct regmap_config tve_regmap_config = {
450*4b6cb2b6SLucas Stach 	.reg_bits = 32,
451*4b6cb2b6SLucas Stach 	.val_bits = 32,
452*4b6cb2b6SLucas Stach 	.reg_stride = 4,
453*4b6cb2b6SLucas Stach 
454*4b6cb2b6SLucas Stach 	.readable_reg = imx_tve_readable_reg,
455*4b6cb2b6SLucas Stach 
456*4b6cb2b6SLucas Stach 	.fast_io = true,
457*4b6cb2b6SLucas Stach 
458*4b6cb2b6SLucas Stach 	.max_register = 0xdc,
459*4b6cb2b6SLucas Stach };
460*4b6cb2b6SLucas Stach 
461*4b6cb2b6SLucas Stach static const char * const imx_tve_modes[] = {
462*4b6cb2b6SLucas Stach 	[TVE_MODE_TVOUT]  = "tvout",
463*4b6cb2b6SLucas Stach 	[TVE_MODE_VGA] = "vga",
464*4b6cb2b6SLucas Stach };
465*4b6cb2b6SLucas Stach 
466*4b6cb2b6SLucas Stach static int of_get_tve_mode(struct device_node *np)
467*4b6cb2b6SLucas Stach {
468*4b6cb2b6SLucas Stach 	const char *bm;
469*4b6cb2b6SLucas Stach 	int ret, i;
470*4b6cb2b6SLucas Stach 
471*4b6cb2b6SLucas Stach 	ret = of_property_read_string(np, "fsl,tve-mode", &bm);
472*4b6cb2b6SLucas Stach 	if (ret < 0)
473*4b6cb2b6SLucas Stach 		return ret;
474*4b6cb2b6SLucas Stach 
475*4b6cb2b6SLucas Stach 	for (i = 0; i < ARRAY_SIZE(imx_tve_modes); i++)
476*4b6cb2b6SLucas Stach 		if (!strcasecmp(bm, imx_tve_modes[i]))
477*4b6cb2b6SLucas Stach 			return i;
478*4b6cb2b6SLucas Stach 
479*4b6cb2b6SLucas Stach 	return -EINVAL;
480*4b6cb2b6SLucas Stach }
481*4b6cb2b6SLucas Stach 
482*4b6cb2b6SLucas Stach static int imx_tve_bind(struct device *dev, struct device *master, void *data)
483*4b6cb2b6SLucas Stach {
484*4b6cb2b6SLucas Stach 	struct drm_device *drm = data;
485*4b6cb2b6SLucas Stach 	struct imx_tve *tve = dev_get_drvdata(dev);
486*4b6cb2b6SLucas Stach 	struct imx_tve_encoder *tvee;
487*4b6cb2b6SLucas Stach 	struct drm_encoder *encoder;
488*4b6cb2b6SLucas Stach 	struct drm_connector *connector;
489*4b6cb2b6SLucas Stach 	int encoder_type;
490*4b6cb2b6SLucas Stach 	int ret;
491*4b6cb2b6SLucas Stach 
492*4b6cb2b6SLucas Stach 	encoder_type = tve->mode == TVE_MODE_VGA ?
493*4b6cb2b6SLucas Stach 		       DRM_MODE_ENCODER_DAC : DRM_MODE_ENCODER_TVDAC;
494*4b6cb2b6SLucas Stach 
495*4b6cb2b6SLucas Stach 	tvee = drmm_simple_encoder_alloc(drm, struct imx_tve_encoder, encoder,
496*4b6cb2b6SLucas Stach 					 encoder_type);
497*4b6cb2b6SLucas Stach 	if (IS_ERR(tvee))
498*4b6cb2b6SLucas Stach 		return PTR_ERR(tvee);
499*4b6cb2b6SLucas Stach 
500*4b6cb2b6SLucas Stach 	tvee->tve = tve;
501*4b6cb2b6SLucas Stach 	encoder = &tvee->encoder;
502*4b6cb2b6SLucas Stach 	connector = &tvee->connector;
503*4b6cb2b6SLucas Stach 
504*4b6cb2b6SLucas Stach 	ret = imx_drm_encoder_parse_of(drm, encoder, tve->dev->of_node);
505*4b6cb2b6SLucas Stach 	if (ret)
506*4b6cb2b6SLucas Stach 		return ret;
507*4b6cb2b6SLucas Stach 
508*4b6cb2b6SLucas Stach 	drm_encoder_helper_add(encoder, &imx_tve_encoder_helper_funcs);
509*4b6cb2b6SLucas Stach 
510*4b6cb2b6SLucas Stach 	drm_connector_helper_add(connector, &imx_tve_connector_helper_funcs);
511*4b6cb2b6SLucas Stach 	ret = drm_connector_init_with_ddc(drm, connector,
512*4b6cb2b6SLucas Stach 					  &imx_tve_connector_funcs,
513*4b6cb2b6SLucas Stach 					  DRM_MODE_CONNECTOR_VGA, tve->ddc);
514*4b6cb2b6SLucas Stach 	if (ret)
515*4b6cb2b6SLucas Stach 		return ret;
516*4b6cb2b6SLucas Stach 
517*4b6cb2b6SLucas Stach 	return drm_connector_attach_encoder(connector, encoder);
518*4b6cb2b6SLucas Stach }
519*4b6cb2b6SLucas Stach 
520*4b6cb2b6SLucas Stach static const struct component_ops imx_tve_ops = {
521*4b6cb2b6SLucas Stach 	.bind	= imx_tve_bind,
522*4b6cb2b6SLucas Stach };
523*4b6cb2b6SLucas Stach 
524*4b6cb2b6SLucas Stach static int imx_tve_probe(struct platform_device *pdev)
525*4b6cb2b6SLucas Stach {
526*4b6cb2b6SLucas Stach 	struct device *dev = &pdev->dev;
527*4b6cb2b6SLucas Stach 	struct device_node *np = dev->of_node;
528*4b6cb2b6SLucas Stach 	struct device_node *ddc_node;
529*4b6cb2b6SLucas Stach 	struct imx_tve *tve;
530*4b6cb2b6SLucas Stach 	void __iomem *base;
531*4b6cb2b6SLucas Stach 	unsigned int val;
532*4b6cb2b6SLucas Stach 	int irq;
533*4b6cb2b6SLucas Stach 	int ret;
534*4b6cb2b6SLucas Stach 
535*4b6cb2b6SLucas Stach 	tve = devm_kzalloc(dev, sizeof(*tve), GFP_KERNEL);
536*4b6cb2b6SLucas Stach 	if (!tve)
537*4b6cb2b6SLucas Stach 		return -ENOMEM;
538*4b6cb2b6SLucas Stach 
539*4b6cb2b6SLucas Stach 	tve->dev = dev;
540*4b6cb2b6SLucas Stach 
541*4b6cb2b6SLucas Stach 	ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0);
542*4b6cb2b6SLucas Stach 	if (ddc_node) {
543*4b6cb2b6SLucas Stach 		tve->ddc = of_find_i2c_adapter_by_node(ddc_node);
544*4b6cb2b6SLucas Stach 		of_node_put(ddc_node);
545*4b6cb2b6SLucas Stach 	}
546*4b6cb2b6SLucas Stach 
547*4b6cb2b6SLucas Stach 	tve->mode = of_get_tve_mode(np);
548*4b6cb2b6SLucas Stach 	if (tve->mode != TVE_MODE_VGA) {
549*4b6cb2b6SLucas Stach 		dev_err(dev, "only VGA mode supported, currently\n");
550*4b6cb2b6SLucas Stach 		return -EINVAL;
551*4b6cb2b6SLucas Stach 	}
552*4b6cb2b6SLucas Stach 
553*4b6cb2b6SLucas Stach 	if (tve->mode == TVE_MODE_VGA) {
554*4b6cb2b6SLucas Stach 		ret = of_property_read_u32(np, "fsl,hsync-pin",
555*4b6cb2b6SLucas Stach 					   &tve->di_hsync_pin);
556*4b6cb2b6SLucas Stach 
557*4b6cb2b6SLucas Stach 		if (ret < 0) {
558*4b6cb2b6SLucas Stach 			dev_err(dev, "failed to get hsync pin\n");
559*4b6cb2b6SLucas Stach 			return ret;
560*4b6cb2b6SLucas Stach 		}
561*4b6cb2b6SLucas Stach 
562*4b6cb2b6SLucas Stach 		ret = of_property_read_u32(np, "fsl,vsync-pin",
563*4b6cb2b6SLucas Stach 					   &tve->di_vsync_pin);
564*4b6cb2b6SLucas Stach 
565*4b6cb2b6SLucas Stach 		if (ret < 0) {
566*4b6cb2b6SLucas Stach 			dev_err(dev, "failed to get vsync pin\n");
567*4b6cb2b6SLucas Stach 			return ret;
568*4b6cb2b6SLucas Stach 		}
569*4b6cb2b6SLucas Stach 	}
570*4b6cb2b6SLucas Stach 
571*4b6cb2b6SLucas Stach 	base = devm_platform_ioremap_resource(pdev, 0);
572*4b6cb2b6SLucas Stach 	if (IS_ERR(base))
573*4b6cb2b6SLucas Stach 		return PTR_ERR(base);
574*4b6cb2b6SLucas Stach 
575*4b6cb2b6SLucas Stach 	tve_regmap_config.lock_arg = tve;
576*4b6cb2b6SLucas Stach 	tve->regmap = devm_regmap_init_mmio_clk(dev, "tve", base,
577*4b6cb2b6SLucas Stach 						&tve_regmap_config);
578*4b6cb2b6SLucas Stach 	if (IS_ERR(tve->regmap)) {
579*4b6cb2b6SLucas Stach 		dev_err(dev, "failed to init regmap: %ld\n",
580*4b6cb2b6SLucas Stach 			PTR_ERR(tve->regmap));
581*4b6cb2b6SLucas Stach 		return PTR_ERR(tve->regmap);
582*4b6cb2b6SLucas Stach 	}
583*4b6cb2b6SLucas Stach 
584*4b6cb2b6SLucas Stach 	irq = platform_get_irq(pdev, 0);
585*4b6cb2b6SLucas Stach 	if (irq < 0)
586*4b6cb2b6SLucas Stach 		return irq;
587*4b6cb2b6SLucas Stach 
588*4b6cb2b6SLucas Stach 	ret = devm_request_threaded_irq(dev, irq, NULL,
589*4b6cb2b6SLucas Stach 					imx_tve_irq_handler, IRQF_ONESHOT,
590*4b6cb2b6SLucas Stach 					"imx-tve", tve);
591*4b6cb2b6SLucas Stach 	if (ret < 0) {
592*4b6cb2b6SLucas Stach 		dev_err(dev, "failed to request irq: %d\n", ret);
593*4b6cb2b6SLucas Stach 		return ret;
594*4b6cb2b6SLucas Stach 	}
595*4b6cb2b6SLucas Stach 
596*4b6cb2b6SLucas Stach 	tve->dac_reg = devm_regulator_get(dev, "dac");
597*4b6cb2b6SLucas Stach 	if (!IS_ERR(tve->dac_reg)) {
598*4b6cb2b6SLucas Stach 		if (regulator_get_voltage(tve->dac_reg) != IMX_TVE_DAC_VOLTAGE)
599*4b6cb2b6SLucas Stach 			dev_warn(dev, "dac voltage is not %d uV\n", IMX_TVE_DAC_VOLTAGE);
600*4b6cb2b6SLucas Stach 		ret = regulator_enable(tve->dac_reg);
601*4b6cb2b6SLucas Stach 		if (ret)
602*4b6cb2b6SLucas Stach 			return ret;
603*4b6cb2b6SLucas Stach 		ret = devm_add_action_or_reset(dev, imx_tve_disable_regulator, tve);
604*4b6cb2b6SLucas Stach 		if (ret)
605*4b6cb2b6SLucas Stach 			return ret;
606*4b6cb2b6SLucas Stach 	}
607*4b6cb2b6SLucas Stach 
608*4b6cb2b6SLucas Stach 	tve->clk = devm_clk_get(dev, "tve");
609*4b6cb2b6SLucas Stach 	if (IS_ERR(tve->clk)) {
610*4b6cb2b6SLucas Stach 		dev_err(dev, "failed to get high speed tve clock: %ld\n",
611*4b6cb2b6SLucas Stach 			PTR_ERR(tve->clk));
612*4b6cb2b6SLucas Stach 		return PTR_ERR(tve->clk);
613*4b6cb2b6SLucas Stach 	}
614*4b6cb2b6SLucas Stach 
615*4b6cb2b6SLucas Stach 	/* this is the IPU DI clock input selector, can be parented to tve_di */
616*4b6cb2b6SLucas Stach 	tve->di_sel_clk = devm_clk_get(dev, "di_sel");
617*4b6cb2b6SLucas Stach 	if (IS_ERR(tve->di_sel_clk)) {
618*4b6cb2b6SLucas Stach 		dev_err(dev, "failed to get ipu di mux clock: %ld\n",
619*4b6cb2b6SLucas Stach 			PTR_ERR(tve->di_sel_clk));
620*4b6cb2b6SLucas Stach 		return PTR_ERR(tve->di_sel_clk);
621*4b6cb2b6SLucas Stach 	}
622*4b6cb2b6SLucas Stach 
623*4b6cb2b6SLucas Stach 	ret = tve_clk_init(tve, base);
624*4b6cb2b6SLucas Stach 	if (ret < 0)
625*4b6cb2b6SLucas Stach 		return ret;
626*4b6cb2b6SLucas Stach 
627*4b6cb2b6SLucas Stach 	ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val);
628*4b6cb2b6SLucas Stach 	if (ret < 0) {
629*4b6cb2b6SLucas Stach 		dev_err(dev, "failed to read configuration register: %d\n",
630*4b6cb2b6SLucas Stach 			ret);
631*4b6cb2b6SLucas Stach 		return ret;
632*4b6cb2b6SLucas Stach 	}
633*4b6cb2b6SLucas Stach 	if (val != 0x00100000) {
634*4b6cb2b6SLucas Stach 		dev_err(dev, "configuration register default value indicates this is not a TVEv2\n");
635*4b6cb2b6SLucas Stach 		return -ENODEV;
636*4b6cb2b6SLucas Stach 	}
637*4b6cb2b6SLucas Stach 
638*4b6cb2b6SLucas Stach 	/* disable cable detection for VGA mode */
639*4b6cb2b6SLucas Stach 	ret = regmap_write(tve->regmap, TVE_CD_CONT_REG, 0);
640*4b6cb2b6SLucas Stach 	if (ret)
641*4b6cb2b6SLucas Stach 		return ret;
642*4b6cb2b6SLucas Stach 
643*4b6cb2b6SLucas Stach 	platform_set_drvdata(pdev, tve);
644*4b6cb2b6SLucas Stach 
645*4b6cb2b6SLucas Stach 	return component_add(dev, &imx_tve_ops);
646*4b6cb2b6SLucas Stach }
647*4b6cb2b6SLucas Stach 
648*4b6cb2b6SLucas Stach static int imx_tve_remove(struct platform_device *pdev)
649*4b6cb2b6SLucas Stach {
650*4b6cb2b6SLucas Stach 	component_del(&pdev->dev, &imx_tve_ops);
651*4b6cb2b6SLucas Stach 	return 0;
652*4b6cb2b6SLucas Stach }
653*4b6cb2b6SLucas Stach 
654*4b6cb2b6SLucas Stach static const struct of_device_id imx_tve_dt_ids[] = {
655*4b6cb2b6SLucas Stach 	{ .compatible = "fsl,imx53-tve", },
656*4b6cb2b6SLucas Stach 	{ /* sentinel */ }
657*4b6cb2b6SLucas Stach };
658*4b6cb2b6SLucas Stach MODULE_DEVICE_TABLE(of, imx_tve_dt_ids);
659*4b6cb2b6SLucas Stach 
660*4b6cb2b6SLucas Stach static struct platform_driver imx_tve_driver = {
661*4b6cb2b6SLucas Stach 	.probe		= imx_tve_probe,
662*4b6cb2b6SLucas Stach 	.remove		= imx_tve_remove,
663*4b6cb2b6SLucas Stach 	.driver		= {
664*4b6cb2b6SLucas Stach 		.of_match_table = imx_tve_dt_ids,
665*4b6cb2b6SLucas Stach 		.name	= "imx-tve",
666*4b6cb2b6SLucas Stach 	},
667*4b6cb2b6SLucas Stach };
668*4b6cb2b6SLucas Stach 
669*4b6cb2b6SLucas Stach module_platform_driver(imx_tve_driver);
670*4b6cb2b6SLucas Stach 
671*4b6cb2b6SLucas Stach MODULE_DESCRIPTION("i.MX Television Encoder driver");
672*4b6cb2b6SLucas Stach MODULE_AUTHOR("Philipp Zabel, Pengutronix");
673*4b6cb2b6SLucas Stach MODULE_LICENSE("GPL");
674*4b6cb2b6SLucas Stach MODULE_ALIAS("platform:imx-tve");
675