xref: /openbmc/linux/drivers/gpu/drm/sun4i/sun4i_tcon.c (revision 1469619d29d752759a2c9604a74091f92757830a)
19026e0d1SMaxime Ripard /*
29026e0d1SMaxime Ripard  * Copyright (C) 2015 Free Electrons
39026e0d1SMaxime Ripard  * Copyright (C) 2015 NextThing Co
49026e0d1SMaxime Ripard  *
59026e0d1SMaxime Ripard  * Maxime Ripard <maxime.ripard@free-electrons.com>
69026e0d1SMaxime Ripard  *
79026e0d1SMaxime Ripard  * This program is free software; you can redistribute it and/or
89026e0d1SMaxime Ripard  * modify it under the terms of the GNU General Public License as
99026e0d1SMaxime Ripard  * published by the Free Software Foundation; either version 2 of
109026e0d1SMaxime Ripard  * the License, or (at your option) any later version.
119026e0d1SMaxime Ripard  */
129026e0d1SMaxime Ripard 
139026e0d1SMaxime Ripard #include <drm/drmP.h>
149026e0d1SMaxime Ripard #include <drm/drm_atomic_helper.h>
159026e0d1SMaxime Ripard #include <drm/drm_crtc.h>
169026e0d1SMaxime Ripard #include <drm/drm_crtc_helper.h>
179026e0d1SMaxime Ripard #include <drm/drm_modes.h>
18ebc94461SRob Herring #include <drm/drm_of.h>
199026e0d1SMaxime Ripard 
209026e0d1SMaxime Ripard #include <linux/component.h>
219026e0d1SMaxime Ripard #include <linux/ioport.h>
229026e0d1SMaxime Ripard #include <linux/of_address.h>
2391ea2f29SChen-Yu Tsai #include <linux/of_device.h>
249026e0d1SMaxime Ripard #include <linux/of_irq.h>
259026e0d1SMaxime Ripard #include <linux/regmap.h>
269026e0d1SMaxime Ripard #include <linux/reset.h>
279026e0d1SMaxime Ripard 
289026e0d1SMaxime Ripard #include "sun4i_crtc.h"
299026e0d1SMaxime Ripard #include "sun4i_dotclock.h"
309026e0d1SMaxime Ripard #include "sun4i_drv.h"
3129e57fabSMaxime Ripard #include "sun4i_rgb.h"
329026e0d1SMaxime Ripard #include "sun4i_tcon.h"
3387969338SIcenowy Zheng #include "sunxi_engine.h"
349026e0d1SMaxime Ripard 
359026e0d1SMaxime Ripard void sun4i_tcon_disable(struct sun4i_tcon *tcon)
369026e0d1SMaxime Ripard {
379026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Disabling TCON\n");
389026e0d1SMaxime Ripard 
399026e0d1SMaxime Ripard 	/* Disable the TCON */
409026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
419026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_TCON_ENABLE, 0);
429026e0d1SMaxime Ripard }
439026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_disable);
449026e0d1SMaxime Ripard 
459026e0d1SMaxime Ripard void sun4i_tcon_enable(struct sun4i_tcon *tcon)
469026e0d1SMaxime Ripard {
479026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Enabling TCON\n");
489026e0d1SMaxime Ripard 
499026e0d1SMaxime Ripard 	/* Enable the TCON */
509026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
519026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_TCON_ENABLE,
529026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_TCON_ENABLE);
539026e0d1SMaxime Ripard }
549026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_enable);
559026e0d1SMaxime Ripard 
569026e0d1SMaxime Ripard void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel)
579026e0d1SMaxime Ripard {
581a075426SMaxime Ripard 	DRM_DEBUG_DRIVER("Disabling TCON channel %d\n", channel);
591a075426SMaxime Ripard 
609026e0d1SMaxime Ripard 	/* Disable the TCON's channel */
619026e0d1SMaxime Ripard 	if (channel == 0) {
629026e0d1SMaxime Ripard 		regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
639026e0d1SMaxime Ripard 				   SUN4I_TCON0_CTL_TCON_ENABLE, 0);
649026e0d1SMaxime Ripard 		clk_disable_unprepare(tcon->dclk);
658e924047SMaxime Ripard 		return;
668e924047SMaxime Ripard 	}
678e924047SMaxime Ripard 
6891ea2f29SChen-Yu Tsai 	WARN_ON(!tcon->quirks->has_channel_1);
699026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
709026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_TCON_ENABLE, 0);
719026e0d1SMaxime Ripard 	clk_disable_unprepare(tcon->sclk1);
729026e0d1SMaxime Ripard }
739026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_channel_disable);
749026e0d1SMaxime Ripard 
759026e0d1SMaxime Ripard void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel)
769026e0d1SMaxime Ripard {
771a075426SMaxime Ripard 	DRM_DEBUG_DRIVER("Enabling TCON channel %d\n", channel);
781a075426SMaxime Ripard 
799026e0d1SMaxime Ripard 	/* Enable the TCON's channel */
809026e0d1SMaxime Ripard 	if (channel == 0) {
819026e0d1SMaxime Ripard 		regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
829026e0d1SMaxime Ripard 				   SUN4I_TCON0_CTL_TCON_ENABLE,
839026e0d1SMaxime Ripard 				   SUN4I_TCON0_CTL_TCON_ENABLE);
849026e0d1SMaxime Ripard 		clk_prepare_enable(tcon->dclk);
858e924047SMaxime Ripard 		return;
868e924047SMaxime Ripard 	}
878e924047SMaxime Ripard 
8891ea2f29SChen-Yu Tsai 	WARN_ON(!tcon->quirks->has_channel_1);
899026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
909026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_TCON_ENABLE,
919026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_TCON_ENABLE);
929026e0d1SMaxime Ripard 	clk_prepare_enable(tcon->sclk1);
939026e0d1SMaxime Ripard }
949026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_channel_enable);
959026e0d1SMaxime Ripard 
969026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable)
979026e0d1SMaxime Ripard {
989026e0d1SMaxime Ripard 	u32 mask, val = 0;
999026e0d1SMaxime Ripard 
1009026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis");
1019026e0d1SMaxime Ripard 
1029026e0d1SMaxime Ripard 	mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) |
1039026e0d1SMaxime Ripard 	       SUN4I_TCON_GINT0_VBLANK_ENABLE(1);
1049026e0d1SMaxime Ripard 
1059026e0d1SMaxime Ripard 	if (enable)
1069026e0d1SMaxime Ripard 		val = mask;
1079026e0d1SMaxime Ripard 
1089026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val);
1099026e0d1SMaxime Ripard }
1109026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_enable_vblank);
1119026e0d1SMaxime Ripard 
112f8c73f4fSMaxime Ripard void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel,
113f8c73f4fSMaxime Ripard 			struct drm_encoder *encoder)
114f8c73f4fSMaxime Ripard {
115b7cb9b91SMaxime Ripard 	u32 val;
116b7cb9b91SMaxime Ripard 
117f8c73f4fSMaxime Ripard 	if (!tcon->quirks->has_unknown_mux)
118f8c73f4fSMaxime Ripard 		return;
119f8c73f4fSMaxime Ripard 
120f8c73f4fSMaxime Ripard 	if (channel != 1)
121f8c73f4fSMaxime Ripard 		return;
122f8c73f4fSMaxime Ripard 
123b7cb9b91SMaxime Ripard 	if (encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
124b7cb9b91SMaxime Ripard 		val = 1;
125b7cb9b91SMaxime Ripard 	else
126b7cb9b91SMaxime Ripard 		val = 0;
127b7cb9b91SMaxime Ripard 
128f8c73f4fSMaxime Ripard 	/*
129f8c73f4fSMaxime Ripard 	 * FIXME: Undocumented bits
130f8c73f4fSMaxime Ripard 	 */
131b7cb9b91SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, val);
132f8c73f4fSMaxime Ripard }
133f8c73f4fSMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_set_mux);
134f8c73f4fSMaxime Ripard 
1359026e0d1SMaxime Ripard static int sun4i_tcon_get_clk_delay(struct drm_display_mode *mode,
1369026e0d1SMaxime Ripard 				    int channel)
1379026e0d1SMaxime Ripard {
1389026e0d1SMaxime Ripard 	int delay = mode->vtotal - mode->vdisplay;
1399026e0d1SMaxime Ripard 
1409026e0d1SMaxime Ripard 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1419026e0d1SMaxime Ripard 		delay /= 2;
1429026e0d1SMaxime Ripard 
1439026e0d1SMaxime Ripard 	if (channel == 1)
1449026e0d1SMaxime Ripard 		delay -= 2;
1459026e0d1SMaxime Ripard 
1469026e0d1SMaxime Ripard 	delay = min(delay, 30);
1479026e0d1SMaxime Ripard 
1489026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay);
1499026e0d1SMaxime Ripard 
1509026e0d1SMaxime Ripard 	return delay;
1519026e0d1SMaxime Ripard }
1529026e0d1SMaxime Ripard 
1539026e0d1SMaxime Ripard void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
1549026e0d1SMaxime Ripard 			  struct drm_display_mode *mode)
1559026e0d1SMaxime Ripard {
1569026e0d1SMaxime Ripard 	unsigned int bp, hsync, vsync;
1579026e0d1SMaxime Ripard 	u8 clk_delay;
1589026e0d1SMaxime Ripard 	u32 val = 0;
1599026e0d1SMaxime Ripard 
16086cf6788SChen-Yu Tsai 	/* Configure the dot clock */
16186cf6788SChen-Yu Tsai 	clk_set_rate(tcon->dclk, mode->crtc_clock * 1000);
16286cf6788SChen-Yu Tsai 
1639026e0d1SMaxime Ripard 	/* Adjust clock delay */
1649026e0d1SMaxime Ripard 	clk_delay = sun4i_tcon_get_clk_delay(mode, 0);
1659026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
1669026e0d1SMaxime Ripard 			   SUN4I_TCON0_CTL_CLK_DELAY_MASK,
1679026e0d1SMaxime Ripard 			   SUN4I_TCON0_CTL_CLK_DELAY(clk_delay));
1689026e0d1SMaxime Ripard 
1699026e0d1SMaxime Ripard 	/* Set the resolution */
1709026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
1719026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
1729026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
1739026e0d1SMaxime Ripard 
1749026e0d1SMaxime Ripard 	/*
1759026e0d1SMaxime Ripard 	 * This is called a backporch in the register documentation,
17623a1cb11SChen-Yu Tsai 	 * but it really is the back porch + hsync
1779026e0d1SMaxime Ripard 	 */
1789026e0d1SMaxime Ripard 	bp = mode->crtc_htotal - mode->crtc_hsync_start;
1799026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
1809026e0d1SMaxime Ripard 			 mode->crtc_htotal, bp);
1819026e0d1SMaxime Ripard 
1829026e0d1SMaxime Ripard 	/* Set horizontal display timings */
1839026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG,
1849026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) |
1859026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC1_H_BACKPORCH(bp));
1869026e0d1SMaxime Ripard 
1879026e0d1SMaxime Ripard 	/*
1889026e0d1SMaxime Ripard 	 * This is called a backporch in the register documentation,
18923a1cb11SChen-Yu Tsai 	 * but it really is the back porch + hsync
1909026e0d1SMaxime Ripard 	 */
1919026e0d1SMaxime Ripard 	bp = mode->crtc_vtotal - mode->crtc_vsync_start;
1929026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
1939026e0d1SMaxime Ripard 			 mode->crtc_vtotal, bp);
1949026e0d1SMaxime Ripard 
1959026e0d1SMaxime Ripard 	/* Set vertical display timings */
1969026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG,
197a88cbbd4SMaxime Ripard 		     SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) |
1989026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC2_V_BACKPORCH(bp));
1999026e0d1SMaxime Ripard 
2009026e0d1SMaxime Ripard 	/* Set Hsync and Vsync length */
2019026e0d1SMaxime Ripard 	hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
2029026e0d1SMaxime Ripard 	vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
2039026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
2049026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG,
2059026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC3_V_SYNC(vsync) |
2069026e0d1SMaxime Ripard 		     SUN4I_TCON0_BASIC3_H_SYNC(hsync));
2079026e0d1SMaxime Ripard 
2089026e0d1SMaxime Ripard 	/* Setup the polarity of the various signals */
2099026e0d1SMaxime Ripard 	if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
2109026e0d1SMaxime Ripard 		val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
2119026e0d1SMaxime Ripard 
2129026e0d1SMaxime Ripard 	if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
2139026e0d1SMaxime Ripard 		val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
2149026e0d1SMaxime Ripard 
2159026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG,
2169026e0d1SMaxime Ripard 			   SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE,
2179026e0d1SMaxime Ripard 			   val);
2189026e0d1SMaxime Ripard 
2199026e0d1SMaxime Ripard 	/* Map output pins to channel 0 */
2209026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
2219026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_IOMAP_MASK,
2229026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_IOMAP_TCON0);
2239026e0d1SMaxime Ripard 
2249026e0d1SMaxime Ripard 	/* Enable the output on the pins */
2259026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0);
2269026e0d1SMaxime Ripard }
2279026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon0_mode_set);
2289026e0d1SMaxime Ripard 
2299026e0d1SMaxime Ripard void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
2309026e0d1SMaxime Ripard 			  struct drm_display_mode *mode)
2319026e0d1SMaxime Ripard {
232b8317a3dSMaxime Ripard 	unsigned int bp, hsync, vsync, vtotal;
2339026e0d1SMaxime Ripard 	u8 clk_delay;
2349026e0d1SMaxime Ripard 	u32 val;
2359026e0d1SMaxime Ripard 
23691ea2f29SChen-Yu Tsai 	WARN_ON(!tcon->quirks->has_channel_1);
2378e924047SMaxime Ripard 
23886cf6788SChen-Yu Tsai 	/* Configure the dot clock */
23986cf6788SChen-Yu Tsai 	clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000);
24086cf6788SChen-Yu Tsai 
2419026e0d1SMaxime Ripard 	/* Adjust clock delay */
2429026e0d1SMaxime Ripard 	clk_delay = sun4i_tcon_get_clk_delay(mode, 1);
2439026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
2449026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_CLK_DELAY_MASK,
2459026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_CLK_DELAY(clk_delay));
2469026e0d1SMaxime Ripard 
2479026e0d1SMaxime Ripard 	/* Set interlaced mode */
2489026e0d1SMaxime Ripard 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2499026e0d1SMaxime Ripard 		val = SUN4I_TCON1_CTL_INTERLACE_ENABLE;
2509026e0d1SMaxime Ripard 	else
2519026e0d1SMaxime Ripard 		val = 0;
2529026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
2539026e0d1SMaxime Ripard 			   SUN4I_TCON1_CTL_INTERLACE_ENABLE,
2549026e0d1SMaxime Ripard 			   val);
2559026e0d1SMaxime Ripard 
2569026e0d1SMaxime Ripard 	/* Set the input resolution */
2579026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG,
2589026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) |
2599026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay));
2609026e0d1SMaxime Ripard 
2619026e0d1SMaxime Ripard 	/* Set the upscaling resolution */
2629026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG,
2639026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) |
2649026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay));
2659026e0d1SMaxime Ripard 
2669026e0d1SMaxime Ripard 	/* Set the output resolution */
2679026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG,
2689026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) |
2699026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay));
2709026e0d1SMaxime Ripard 
2719026e0d1SMaxime Ripard 	/* Set horizontal display timings */
2723cb2f46bSMaxime Ripard 	bp = mode->crtc_htotal - mode->crtc_hsync_start;
2739026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
2749026e0d1SMaxime Ripard 			 mode->htotal, bp);
2759026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG,
2769026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) |
2779026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC3_H_BACKPORCH(bp));
2789026e0d1SMaxime Ripard 
2793cb2f46bSMaxime Ripard 	bp = mode->crtc_vtotal - mode->crtc_vsync_start;
2809026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
281b8317a3dSMaxime Ripard 			 mode->crtc_vtotal, bp);
282b8317a3dSMaxime Ripard 
283b8317a3dSMaxime Ripard 	/*
284b8317a3dSMaxime Ripard 	 * The vertical resolution needs to be doubled in all
285b8317a3dSMaxime Ripard 	 * cases. We could use crtc_vtotal and always multiply by two,
286b8317a3dSMaxime Ripard 	 * but that leads to a rounding error in interlace when vtotal
287b8317a3dSMaxime Ripard 	 * is odd.
288b8317a3dSMaxime Ripard 	 *
289b8317a3dSMaxime Ripard 	 * This happens with TV's PAL for example, where vtotal will
290b8317a3dSMaxime Ripard 	 * be 625, crtc_vtotal 312, and thus crtc_vtotal * 2 will be
291b8317a3dSMaxime Ripard 	 * 624, which apparently confuses the hardware.
292b8317a3dSMaxime Ripard 	 *
293b8317a3dSMaxime Ripard 	 * To work around this, we will always use vtotal, and
294b8317a3dSMaxime Ripard 	 * multiply by two only if we're not in interlace.
295b8317a3dSMaxime Ripard 	 */
296b8317a3dSMaxime Ripard 	vtotal = mode->vtotal;
297b8317a3dSMaxime Ripard 	if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
298b8317a3dSMaxime Ripard 		vtotal = vtotal * 2;
299b8317a3dSMaxime Ripard 
300b8317a3dSMaxime Ripard 	/* Set vertical display timings */
3019026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG,
302b8317a3dSMaxime Ripard 		     SUN4I_TCON1_BASIC4_V_TOTAL(vtotal) |
3039026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC4_V_BACKPORCH(bp));
3049026e0d1SMaxime Ripard 
3059026e0d1SMaxime Ripard 	/* Set Hsync and Vsync length */
3069026e0d1SMaxime Ripard 	hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
3079026e0d1SMaxime Ripard 	vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
3089026e0d1SMaxime Ripard 	DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
3099026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG,
3109026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC5_V_SYNC(vsync) |
3119026e0d1SMaxime Ripard 		     SUN4I_TCON1_BASIC5_H_SYNC(hsync));
3129026e0d1SMaxime Ripard 
3139026e0d1SMaxime Ripard 	/* Map output pins to channel 1 */
3149026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
3159026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_IOMAP_MASK,
3169026e0d1SMaxime Ripard 			   SUN4I_TCON_GCTL_IOMAP_TCON1);
3179026e0d1SMaxime Ripard }
3189026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon1_mode_set);
3199026e0d1SMaxime Ripard 
3209026e0d1SMaxime Ripard static void sun4i_tcon_finish_page_flip(struct drm_device *dev,
3219026e0d1SMaxime Ripard 					struct sun4i_crtc *scrtc)
3229026e0d1SMaxime Ripard {
3239026e0d1SMaxime Ripard 	unsigned long flags;
3249026e0d1SMaxime Ripard 
3259026e0d1SMaxime Ripard 	spin_lock_irqsave(&dev->event_lock, flags);
3269026e0d1SMaxime Ripard 	if (scrtc->event) {
3279026e0d1SMaxime Ripard 		drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event);
3289026e0d1SMaxime Ripard 		drm_crtc_vblank_put(&scrtc->crtc);
3299026e0d1SMaxime Ripard 		scrtc->event = NULL;
3309026e0d1SMaxime Ripard 	}
3319026e0d1SMaxime Ripard 	spin_unlock_irqrestore(&dev->event_lock, flags);
3329026e0d1SMaxime Ripard }
3339026e0d1SMaxime Ripard 
3349026e0d1SMaxime Ripard static irqreturn_t sun4i_tcon_handler(int irq, void *private)
3359026e0d1SMaxime Ripard {
3369026e0d1SMaxime Ripard 	struct sun4i_tcon *tcon = private;
3379026e0d1SMaxime Ripard 	struct drm_device *drm = tcon->drm;
33846cce6daSChen-Yu Tsai 	struct sun4i_crtc *scrtc = tcon->crtc;
3399026e0d1SMaxime Ripard 	unsigned int status;
3409026e0d1SMaxime Ripard 
3419026e0d1SMaxime Ripard 	regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status);
3429026e0d1SMaxime Ripard 
3439026e0d1SMaxime Ripard 	if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) |
3449026e0d1SMaxime Ripard 			SUN4I_TCON_GINT0_VBLANK_INT(1))))
3459026e0d1SMaxime Ripard 		return IRQ_NONE;
3469026e0d1SMaxime Ripard 
3479026e0d1SMaxime Ripard 	drm_crtc_handle_vblank(&scrtc->crtc);
3489026e0d1SMaxime Ripard 	sun4i_tcon_finish_page_flip(drm, scrtc);
3499026e0d1SMaxime Ripard 
3509026e0d1SMaxime Ripard 	/* Acknowledge the interrupt */
3519026e0d1SMaxime Ripard 	regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG,
3529026e0d1SMaxime Ripard 			   SUN4I_TCON_GINT0_VBLANK_INT(0) |
3539026e0d1SMaxime Ripard 			   SUN4I_TCON_GINT0_VBLANK_INT(1),
3549026e0d1SMaxime Ripard 			   0);
3559026e0d1SMaxime Ripard 
3569026e0d1SMaxime Ripard 	return IRQ_HANDLED;
3579026e0d1SMaxime Ripard }
3589026e0d1SMaxime Ripard 
3599026e0d1SMaxime Ripard static int sun4i_tcon_init_clocks(struct device *dev,
3609026e0d1SMaxime Ripard 				  struct sun4i_tcon *tcon)
3619026e0d1SMaxime Ripard {
3629026e0d1SMaxime Ripard 	tcon->clk = devm_clk_get(dev, "ahb");
3639026e0d1SMaxime Ripard 	if (IS_ERR(tcon->clk)) {
3649026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't get the TCON bus clock\n");
3659026e0d1SMaxime Ripard 		return PTR_ERR(tcon->clk);
3669026e0d1SMaxime Ripard 	}
3679026e0d1SMaxime Ripard 	clk_prepare_enable(tcon->clk);
3689026e0d1SMaxime Ripard 
3699026e0d1SMaxime Ripard 	tcon->sclk0 = devm_clk_get(dev, "tcon-ch0");
3709026e0d1SMaxime Ripard 	if (IS_ERR(tcon->sclk0)) {
3719026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
3729026e0d1SMaxime Ripard 		return PTR_ERR(tcon->sclk0);
3739026e0d1SMaxime Ripard 	}
3749026e0d1SMaxime Ripard 
37591ea2f29SChen-Yu Tsai 	if (tcon->quirks->has_channel_1) {
3769026e0d1SMaxime Ripard 		tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
3779026e0d1SMaxime Ripard 		if (IS_ERR(tcon->sclk1)) {
3789026e0d1SMaxime Ripard 			dev_err(dev, "Couldn't get the TCON channel 1 clock\n");
3799026e0d1SMaxime Ripard 			return PTR_ERR(tcon->sclk1);
3809026e0d1SMaxime Ripard 		}
3818e924047SMaxime Ripard 	}
3829026e0d1SMaxime Ripard 
3834c7f16d1SChen-Yu Tsai 	return 0;
3849026e0d1SMaxime Ripard }
3859026e0d1SMaxime Ripard 
3869026e0d1SMaxime Ripard static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
3879026e0d1SMaxime Ripard {
3889026e0d1SMaxime Ripard 	clk_disable_unprepare(tcon->clk);
3899026e0d1SMaxime Ripard }
3909026e0d1SMaxime Ripard 
3919026e0d1SMaxime Ripard static int sun4i_tcon_init_irq(struct device *dev,
3929026e0d1SMaxime Ripard 			       struct sun4i_tcon *tcon)
3939026e0d1SMaxime Ripard {
3949026e0d1SMaxime Ripard 	struct platform_device *pdev = to_platform_device(dev);
3959026e0d1SMaxime Ripard 	int irq, ret;
3969026e0d1SMaxime Ripard 
3979026e0d1SMaxime Ripard 	irq = platform_get_irq(pdev, 0);
3989026e0d1SMaxime Ripard 	if (irq < 0) {
3999026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't retrieve the TCON interrupt\n");
4009026e0d1SMaxime Ripard 		return irq;
4019026e0d1SMaxime Ripard 	}
4029026e0d1SMaxime Ripard 
4039026e0d1SMaxime Ripard 	ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0,
4049026e0d1SMaxime Ripard 			       dev_name(dev), tcon);
4059026e0d1SMaxime Ripard 	if (ret) {
4069026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't request the IRQ\n");
4079026e0d1SMaxime Ripard 		return ret;
4089026e0d1SMaxime Ripard 	}
4099026e0d1SMaxime Ripard 
4109026e0d1SMaxime Ripard 	return 0;
4119026e0d1SMaxime Ripard }
4129026e0d1SMaxime Ripard 
4139026e0d1SMaxime Ripard static struct regmap_config sun4i_tcon_regmap_config = {
4149026e0d1SMaxime Ripard 	.reg_bits	= 32,
4159026e0d1SMaxime Ripard 	.val_bits	= 32,
4169026e0d1SMaxime Ripard 	.reg_stride	= 4,
4179026e0d1SMaxime Ripard 	.max_register	= 0x800,
4189026e0d1SMaxime Ripard };
4199026e0d1SMaxime Ripard 
4209026e0d1SMaxime Ripard static int sun4i_tcon_init_regmap(struct device *dev,
4219026e0d1SMaxime Ripard 				  struct sun4i_tcon *tcon)
4229026e0d1SMaxime Ripard {
4239026e0d1SMaxime Ripard 	struct platform_device *pdev = to_platform_device(dev);
4249026e0d1SMaxime Ripard 	struct resource *res;
4259026e0d1SMaxime Ripard 	void __iomem *regs;
4269026e0d1SMaxime Ripard 
4279026e0d1SMaxime Ripard 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4289026e0d1SMaxime Ripard 	regs = devm_ioremap_resource(dev, res);
429af346f55SWei Yongjun 	if (IS_ERR(regs))
4309026e0d1SMaxime Ripard 		return PTR_ERR(regs);
4319026e0d1SMaxime Ripard 
4329026e0d1SMaxime Ripard 	tcon->regs = devm_regmap_init_mmio(dev, regs,
4339026e0d1SMaxime Ripard 					   &sun4i_tcon_regmap_config);
4349026e0d1SMaxime Ripard 	if (IS_ERR(tcon->regs)) {
4359026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't create the TCON regmap\n");
4369026e0d1SMaxime Ripard 		return PTR_ERR(tcon->regs);
4379026e0d1SMaxime Ripard 	}
4389026e0d1SMaxime Ripard 
4399026e0d1SMaxime Ripard 	/* Make sure the TCON is disabled and all IRQs are off */
4409026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0);
4419026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0);
4429026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0);
4439026e0d1SMaxime Ripard 
4449026e0d1SMaxime Ripard 	/* Disable IO lines and set them to tristate */
4459026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0);
4469026e0d1SMaxime Ripard 	regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0);
4479026e0d1SMaxime Ripard 
4489026e0d1SMaxime Ripard 	return 0;
4499026e0d1SMaxime Ripard }
4509026e0d1SMaxime Ripard 
451b317fa3bSChen-Yu Tsai /*
452b317fa3bSChen-Yu Tsai  * On SoCs with the old display pipeline design (Display Engine 1.0),
453b317fa3bSChen-Yu Tsai  * the TCON is always tied to just one backend. Hence we can traverse
454b317fa3bSChen-Yu Tsai  * the of_graph upwards to find the backend our tcon is connected to,
455b317fa3bSChen-Yu Tsai  * and take its ID as our own.
456b317fa3bSChen-Yu Tsai  *
457b317fa3bSChen-Yu Tsai  * We can either identify backends from their compatible strings, which
458b317fa3bSChen-Yu Tsai  * means maintaining a large list of them. Or, since the backend is
459b317fa3bSChen-Yu Tsai  * registered and binded before the TCON, we can just go through the
460b317fa3bSChen-Yu Tsai  * list of registered backends and compare the device node.
46187969338SIcenowy Zheng  *
46287969338SIcenowy Zheng  * As the structures now store engines instead of backends, here this
46387969338SIcenowy Zheng  * function in fact searches the corresponding engine, and the ID is
46487969338SIcenowy Zheng  * requested via the get_id function of the engine.
465b317fa3bSChen-Yu Tsai  */
46687969338SIcenowy Zheng static struct sunxi_engine *sun4i_tcon_find_engine(struct sun4i_drv *drv,
467b317fa3bSChen-Yu Tsai 						   struct device_node *node)
468b317fa3bSChen-Yu Tsai {
469b317fa3bSChen-Yu Tsai 	struct device_node *port, *ep, *remote;
47087969338SIcenowy Zheng 	struct sunxi_engine *engine;
471b317fa3bSChen-Yu Tsai 
472b317fa3bSChen-Yu Tsai 	port = of_graph_get_port_by_id(node, 0);
473b317fa3bSChen-Yu Tsai 	if (!port)
474b317fa3bSChen-Yu Tsai 		return ERR_PTR(-EINVAL);
475b317fa3bSChen-Yu Tsai 
476*1469619dSChen-Yu Tsai 	/*
477*1469619dSChen-Yu Tsai 	 * This only works if there is only one path from the TCON
478*1469619dSChen-Yu Tsai 	 * to any display engine. Otherwise the probe order of the
479*1469619dSChen-Yu Tsai 	 * TCONs and display engines is not guaranteed. They may
480*1469619dSChen-Yu Tsai 	 * either bind to the wrong one, or worse, bind to the same
481*1469619dSChen-Yu Tsai 	 * one if additional checks are not done.
482*1469619dSChen-Yu Tsai 	 *
483*1469619dSChen-Yu Tsai 	 * Bail out if there are multiple input connections.
484*1469619dSChen-Yu Tsai 	 */
485*1469619dSChen-Yu Tsai 	if (of_get_available_child_count(port) != 1) {
486*1469619dSChen-Yu Tsai 		of_node_put(port);
487*1469619dSChen-Yu Tsai 		return ERR_PTR(-EINVAL);
488*1469619dSChen-Yu Tsai 	}
489*1469619dSChen-Yu Tsai 
490b317fa3bSChen-Yu Tsai 	for_each_available_child_of_node(port, ep) {
491b317fa3bSChen-Yu Tsai 		remote = of_graph_get_remote_port_parent(ep);
492b317fa3bSChen-Yu Tsai 		if (!remote)
493b317fa3bSChen-Yu Tsai 			continue;
494b317fa3bSChen-Yu Tsai 
49587969338SIcenowy Zheng 		/* does this node match any registered engines? */
49687969338SIcenowy Zheng 		list_for_each_entry(engine, &drv->engine_list, list) {
49787969338SIcenowy Zheng 			if (remote == engine->node) {
498b317fa3bSChen-Yu Tsai 				of_node_put(remote);
499b317fa3bSChen-Yu Tsai 				of_node_put(port);
50087969338SIcenowy Zheng 				return engine;
501b317fa3bSChen-Yu Tsai 			}
502b317fa3bSChen-Yu Tsai 		}
503b317fa3bSChen-Yu Tsai 
504b317fa3bSChen-Yu Tsai 		/* keep looking through upstream ports */
50587969338SIcenowy Zheng 		engine = sun4i_tcon_find_engine(drv, remote);
50687969338SIcenowy Zheng 		if (!IS_ERR(engine)) {
507b317fa3bSChen-Yu Tsai 			of_node_put(remote);
508b317fa3bSChen-Yu Tsai 			of_node_put(port);
50987969338SIcenowy Zheng 			return engine;
510b317fa3bSChen-Yu Tsai 		}
511b317fa3bSChen-Yu Tsai 	}
512b317fa3bSChen-Yu Tsai 
513b317fa3bSChen-Yu Tsai 	return ERR_PTR(-EINVAL);
514b317fa3bSChen-Yu Tsai }
515b317fa3bSChen-Yu Tsai 
5169026e0d1SMaxime Ripard static int sun4i_tcon_bind(struct device *dev, struct device *master,
5179026e0d1SMaxime Ripard 			   void *data)
5189026e0d1SMaxime Ripard {
5199026e0d1SMaxime Ripard 	struct drm_device *drm = data;
5209026e0d1SMaxime Ripard 	struct sun4i_drv *drv = drm->dev_private;
52187969338SIcenowy Zheng 	struct sunxi_engine *engine;
5229026e0d1SMaxime Ripard 	struct sun4i_tcon *tcon;
5239026e0d1SMaxime Ripard 	int ret;
5249026e0d1SMaxime Ripard 
52587969338SIcenowy Zheng 	engine = sun4i_tcon_find_engine(drv, dev->of_node);
52687969338SIcenowy Zheng 	if (IS_ERR(engine)) {
52787969338SIcenowy Zheng 		dev_err(dev, "Couldn't find matching engine\n");
52880a58240SChen-Yu Tsai 		return -EPROBE_DEFER;
529b317fa3bSChen-Yu Tsai 	}
53080a58240SChen-Yu Tsai 
5319026e0d1SMaxime Ripard 	tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
5329026e0d1SMaxime Ripard 	if (!tcon)
5339026e0d1SMaxime Ripard 		return -ENOMEM;
5349026e0d1SMaxime Ripard 	dev_set_drvdata(dev, tcon);
5359026e0d1SMaxime Ripard 	tcon->drm = drm;
536ae558110SMaxime Ripard 	tcon->dev = dev;
53787969338SIcenowy Zheng 	tcon->id = engine->id;
53891ea2f29SChen-Yu Tsai 	tcon->quirks = of_device_get_match_data(dev);
5399026e0d1SMaxime Ripard 
5409026e0d1SMaxime Ripard 	tcon->lcd_rst = devm_reset_control_get(dev, "lcd");
5419026e0d1SMaxime Ripard 	if (IS_ERR(tcon->lcd_rst)) {
5429026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't get our reset line\n");
5439026e0d1SMaxime Ripard 		return PTR_ERR(tcon->lcd_rst);
5449026e0d1SMaxime Ripard 	}
5459026e0d1SMaxime Ripard 
5469026e0d1SMaxime Ripard 	/* Make sure our TCON is reset */
547d57294c1SChen-Yu Tsai 	ret = reset_control_reset(tcon->lcd_rst);
5489026e0d1SMaxime Ripard 	if (ret) {
5499026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't deassert our reset line\n");
5509026e0d1SMaxime Ripard 		return ret;
5519026e0d1SMaxime Ripard 	}
5529026e0d1SMaxime Ripard 
5539026e0d1SMaxime Ripard 	ret = sun4i_tcon_init_clocks(dev, tcon);
5549026e0d1SMaxime Ripard 	if (ret) {
5559026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't init our TCON clocks\n");
5569026e0d1SMaxime Ripard 		goto err_assert_reset;
5579026e0d1SMaxime Ripard 	}
5589026e0d1SMaxime Ripard 
5594c7f16d1SChen-Yu Tsai 	ret = sun4i_tcon_init_regmap(dev, tcon);
5609026e0d1SMaxime Ripard 	if (ret) {
5614c7f16d1SChen-Yu Tsai 		dev_err(dev, "Couldn't init our TCON regmap\n");
5629026e0d1SMaxime Ripard 		goto err_free_clocks;
5639026e0d1SMaxime Ripard 	}
5649026e0d1SMaxime Ripard 
5654c7f16d1SChen-Yu Tsai 	ret = sun4i_dclk_create(dev, tcon);
5664c7f16d1SChen-Yu Tsai 	if (ret) {
5674c7f16d1SChen-Yu Tsai 		dev_err(dev, "Couldn't create our TCON dot clock\n");
5684c7f16d1SChen-Yu Tsai 		goto err_free_clocks;
5694c7f16d1SChen-Yu Tsai 	}
5704c7f16d1SChen-Yu Tsai 
5719026e0d1SMaxime Ripard 	ret = sun4i_tcon_init_irq(dev, tcon);
5729026e0d1SMaxime Ripard 	if (ret) {
5739026e0d1SMaxime Ripard 		dev_err(dev, "Couldn't init our TCON interrupts\n");
5744c7f16d1SChen-Yu Tsai 		goto err_free_dotclock;
5759026e0d1SMaxime Ripard 	}
5769026e0d1SMaxime Ripard 
57787969338SIcenowy Zheng 	tcon->crtc = sun4i_crtc_init(drm, engine, tcon);
57846cce6daSChen-Yu Tsai 	if (IS_ERR(tcon->crtc)) {
57946cce6daSChen-Yu Tsai 		dev_err(dev, "Couldn't create our CRTC\n");
58046cce6daSChen-Yu Tsai 		ret = PTR_ERR(tcon->crtc);
58146cce6daSChen-Yu Tsai 		goto err_free_clocks;
58246cce6daSChen-Yu Tsai 	}
58346cce6daSChen-Yu Tsai 
584b9c8506cSChen-Yu Tsai 	ret = sun4i_rgb_init(drm, tcon);
58513fef095SChen-Yu Tsai 	if (ret < 0)
58613fef095SChen-Yu Tsai 		goto err_free_clocks;
58713fef095SChen-Yu Tsai 
58880a58240SChen-Yu Tsai 	list_add_tail(&tcon->list, &drv->tcon_list);
58980a58240SChen-Yu Tsai 
59013fef095SChen-Yu Tsai 	return 0;
5919026e0d1SMaxime Ripard 
5924c7f16d1SChen-Yu Tsai err_free_dotclock:
5934c7f16d1SChen-Yu Tsai 	sun4i_dclk_free(tcon);
5949026e0d1SMaxime Ripard err_free_clocks:
5959026e0d1SMaxime Ripard 	sun4i_tcon_free_clocks(tcon);
5969026e0d1SMaxime Ripard err_assert_reset:
5979026e0d1SMaxime Ripard 	reset_control_assert(tcon->lcd_rst);
5989026e0d1SMaxime Ripard 	return ret;
5999026e0d1SMaxime Ripard }
6009026e0d1SMaxime Ripard 
6019026e0d1SMaxime Ripard static void sun4i_tcon_unbind(struct device *dev, struct device *master,
6029026e0d1SMaxime Ripard 			      void *data)
6039026e0d1SMaxime Ripard {
6049026e0d1SMaxime Ripard 	struct sun4i_tcon *tcon = dev_get_drvdata(dev);
6059026e0d1SMaxime Ripard 
60680a58240SChen-Yu Tsai 	list_del(&tcon->list);
6074c7f16d1SChen-Yu Tsai 	sun4i_dclk_free(tcon);
6089026e0d1SMaxime Ripard 	sun4i_tcon_free_clocks(tcon);
6099026e0d1SMaxime Ripard }
6109026e0d1SMaxime Ripard 
611dfeb693dSJulia Lawall static const struct component_ops sun4i_tcon_ops = {
6129026e0d1SMaxime Ripard 	.bind	= sun4i_tcon_bind,
6139026e0d1SMaxime Ripard 	.unbind	= sun4i_tcon_unbind,
6149026e0d1SMaxime Ripard };
6159026e0d1SMaxime Ripard 
6169026e0d1SMaxime Ripard static int sun4i_tcon_probe(struct platform_device *pdev)
6179026e0d1SMaxime Ripard {
61829e57fabSMaxime Ripard 	struct device_node *node = pdev->dev.of_node;
619894f5a9fSMaxime Ripard 	struct drm_bridge *bridge;
62029e57fabSMaxime Ripard 	struct drm_panel *panel;
621ebc94461SRob Herring 	int ret;
62229e57fabSMaxime Ripard 
623ebc94461SRob Herring 	ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
624ebc94461SRob Herring 	if (ret == -EPROBE_DEFER)
625ebc94461SRob Herring 		return ret;
62629e57fabSMaxime Ripard 
6279026e0d1SMaxime Ripard 	return component_add(&pdev->dev, &sun4i_tcon_ops);
6289026e0d1SMaxime Ripard }
6299026e0d1SMaxime Ripard 
6309026e0d1SMaxime Ripard static int sun4i_tcon_remove(struct platform_device *pdev)
6319026e0d1SMaxime Ripard {
6329026e0d1SMaxime Ripard 	component_del(&pdev->dev, &sun4i_tcon_ops);
6339026e0d1SMaxime Ripard 
6349026e0d1SMaxime Ripard 	return 0;
6359026e0d1SMaxime Ripard }
6369026e0d1SMaxime Ripard 
63791ea2f29SChen-Yu Tsai static const struct sun4i_tcon_quirks sun5i_a13_quirks = {
63891ea2f29SChen-Yu Tsai 	.has_unknown_mux = true,
63991ea2f29SChen-Yu Tsai 	.has_channel_1	= true,
64091ea2f29SChen-Yu Tsai };
64191ea2f29SChen-Yu Tsai 
64293a5ec14SChen-Yu Tsai static const struct sun4i_tcon_quirks sun6i_a31_quirks = {
64393a5ec14SChen-Yu Tsai 	.has_channel_1	= true,
64493a5ec14SChen-Yu Tsai };
64593a5ec14SChen-Yu Tsai 
64693a5ec14SChen-Yu Tsai static const struct sun4i_tcon_quirks sun6i_a31s_quirks = {
64793a5ec14SChen-Yu Tsai 	.has_channel_1	= true,
64893a5ec14SChen-Yu Tsai };
64993a5ec14SChen-Yu Tsai 
65091ea2f29SChen-Yu Tsai static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
65191ea2f29SChen-Yu Tsai 	/* nothing is supported */
65291ea2f29SChen-Yu Tsai };
65391ea2f29SChen-Yu Tsai 
6541a0edb3fSIcenowy Zheng static const struct sun4i_tcon_quirks sun8i_v3s_quirks = {
6551a0edb3fSIcenowy Zheng 	/* nothing is supported */
6561a0edb3fSIcenowy Zheng };
6571a0edb3fSIcenowy Zheng 
6589026e0d1SMaxime Ripard static const struct of_device_id sun4i_tcon_of_table[] = {
65991ea2f29SChen-Yu Tsai 	{ .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
66093a5ec14SChen-Yu Tsai 	{ .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
66193a5ec14SChen-Yu Tsai 	{ .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
66291ea2f29SChen-Yu Tsai 	{ .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
6631a0edb3fSIcenowy Zheng 	{ .compatible = "allwinner,sun8i-v3s-tcon", .data = &sun8i_v3s_quirks },
6649026e0d1SMaxime Ripard 	{ }
6659026e0d1SMaxime Ripard };
6669026e0d1SMaxime Ripard MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table);
6679026e0d1SMaxime Ripard 
6689026e0d1SMaxime Ripard static struct platform_driver sun4i_tcon_platform_driver = {
6699026e0d1SMaxime Ripard 	.probe		= sun4i_tcon_probe,
6709026e0d1SMaxime Ripard 	.remove		= sun4i_tcon_remove,
6719026e0d1SMaxime Ripard 	.driver		= {
6729026e0d1SMaxime Ripard 		.name		= "sun4i-tcon",
6739026e0d1SMaxime Ripard 		.of_match_table	= sun4i_tcon_of_table,
6749026e0d1SMaxime Ripard 	},
6759026e0d1SMaxime Ripard };
6769026e0d1SMaxime Ripard module_platform_driver(sun4i_tcon_platform_driver);
6779026e0d1SMaxime Ripard 
6789026e0d1SMaxime Ripard MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
6799026e0d1SMaxime Ripard MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver");
6809026e0d1SMaxime Ripard MODULE_LICENSE("GPL");
681