xref: /openbmc/linux/drivers/gpu/drm/sun4i/sun4i_tcon.h (revision ae558110e51737b3596f400505ee598acbbf6713)
19026e0d1SMaxime Ripard /*
29026e0d1SMaxime Ripard  * Copyright (C) 2015 Free Electrons
39026e0d1SMaxime Ripard  * Copyright (C) 2015 NextThing Co
49026e0d1SMaxime Ripard  *
59026e0d1SMaxime Ripard  * Boris Brezillon <boris.brezillon@free-electrons.com>
69026e0d1SMaxime Ripard  * Maxime Ripard <maxime.ripard@free-electrons.com>
79026e0d1SMaxime Ripard  *
89026e0d1SMaxime Ripard  * This program is free software; you can redistribute it and/or
99026e0d1SMaxime Ripard  * modify it under the terms of the GNU General Public License as
109026e0d1SMaxime Ripard  * published by the Free Software Foundation; either version 2 of
119026e0d1SMaxime Ripard  * the License, or (at your option) any later version.
129026e0d1SMaxime Ripard  */
139026e0d1SMaxime Ripard 
149026e0d1SMaxime Ripard #ifndef __SUN4I_TCON_H__
159026e0d1SMaxime Ripard #define __SUN4I_TCON_H__
169026e0d1SMaxime Ripard 
179026e0d1SMaxime Ripard #include <drm/drm_crtc.h>
189026e0d1SMaxime Ripard 
199026e0d1SMaxime Ripard #include <linux/kernel.h>
209026e0d1SMaxime Ripard #include <linux/reset.h>
219026e0d1SMaxime Ripard 
229026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_REG			0x0
239026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_TCON_ENABLE			BIT(31)
249026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_MASK			BIT(0)
259026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON1			(1 << 0)
269026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON0			(0 << 0)
279026e0d1SMaxime Ripard 
289026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_REG			0x4
299026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe)		BIT(31 - (pipe))
309026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_INT(pipe)		BIT(15 - (pipe))
319026e0d1SMaxime Ripard 
329026e0d1SMaxime Ripard #define SUN4I_TCON_GINT1_REG			0x8
339026e0d1SMaxime Ripard #define SUN4I_TCON_FRM_CTL_REG			0x10
349026e0d1SMaxime Ripard 
359026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_REG			0x40
369026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_TCON_ENABLE			BIT(31)
379026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY_MASK			GENMASK(8, 4)
389026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY(delay)		((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK)
399026e0d1SMaxime Ripard 
409026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_REG			0x44
419026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_GATE_BIT			(31)
429026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_SHIFT			(0)
439026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_WIDTH			(7)
449026e0d1SMaxime Ripard 
459026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_REG			0x48
469026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_X(width)			((((width) - 1) & 0xfff) << 16)
479026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_Y(height)			(((height) - 1) & 0xfff)
489026e0d1SMaxime Ripard 
499026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_REG			0x4c
509026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_TOTAL(total)		((((total) - 1) & 0x1fff) << 16)
519026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
529026e0d1SMaxime Ripard 
539026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_REG			0x50
549026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_TOTAL(total)		((((total) * 2) & 0x1fff) << 16)
559026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
569026e0d1SMaxime Ripard 
579026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_REG			0x54
589026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_H_SYNC(width)		((((width) - 1) & 0x7ff) << 16)
599026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_V_SYNC(height)		(((height) - 1) & 0x7ff)
609026e0d1SMaxime Ripard 
619026e0d1SMaxime Ripard #define SUN4I_TCON0_HV_IF_REG			0x58
629026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_IF_REG			0x60
639026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_WR_REG			0x64
649026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RD0_REG			0x68
659026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RDA_REG			0x6c
669026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL0_REG			0x70
679026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL1_REG			0x74
689026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL2_REG			0x78
699026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL3_REG			0x7c
709026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL4_REG			0x80
719026e0d1SMaxime Ripard #define SUN4I_TCON0_LVDS_IF_REG			0x84
729026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_REG			0x88
739026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase)		((phase & 3) << 28)
749026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE		BIT(25)
759026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE		BIT(24)
769026e0d1SMaxime Ripard 
779026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_REG			0x8c
789026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE		BIT(25)
799026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE		BIT(24)
809026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins)	GENMASK(pins, 0)
819026e0d1SMaxime Ripard 
829026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_REG			0x90
839026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_TCON_ENABLE			BIT(31)
849026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_INTERLACE_ENABLE		BIT(20)
859026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY_MASK			GENMASK(8, 4)
869026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY(delay)		((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK)
879026e0d1SMaxime Ripard 
889026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_REG			0x94
899026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_X(width)			((((width) - 1) & 0xfff) << 16)
909026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_Y(height)			(((height) - 1) & 0xfff)
919026e0d1SMaxime Ripard 
929026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_REG			0x98
939026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_X(width)			((((width) - 1) & 0xfff) << 16)
949026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_Y(height)			(((height) - 1) & 0xfff)
959026e0d1SMaxime Ripard 
969026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_REG			0x9c
979026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_X(width)			((((width) - 1) & 0xfff) << 16)
989026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_Y(height)			(((height) - 1) & 0xfff)
999026e0d1SMaxime Ripard 
1009026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_REG			0xa0
1019026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_TOTAL(total)		((((total) - 1) & 0x1fff) << 16)
1029026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
1039026e0d1SMaxime Ripard 
1049026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_REG			0xa4
1059026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_TOTAL(total)		(((total) & 0x1fff) << 16)
1069026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
1079026e0d1SMaxime Ripard 
1089026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_REG			0xa8
1099026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_H_SYNC(width)		((((width) - 1) & 0x3ff) << 16)
1109026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_V_SYNC(height)		(((height) - 1) & 0x3ff)
1119026e0d1SMaxime Ripard 
1129026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_POL_REG			0xf0
1139026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_TRI_REG			0xf4
1149026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_CTL_REG			0x100
1159026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RR_REG		0x110
1169026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RG_REG		0x114
1179026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RB_REG		0x118
1189026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_RC_REG		0x11c
1199026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GR_REG		0x120
1209026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GG_REG		0x124
1219026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GB_REG		0x128
1229026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_GC_REG		0x12c
1239026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BR_REG		0x130
1249026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BG_REG		0x134
1259026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BB_REG		0x138
1269026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_BC_REG		0x13c
1279026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_R_REG		0x140
1289026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_G_REG		0x144
1299026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_B_REG		0x148
1309026e0d1SMaxime Ripard #define SUN4I_TCON_MUX_CTRL_REG			0x200
1319026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_CTL_REG		0x300
1329026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG0_REG		0x304
1339026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END0_REG		0x308
1349026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA0_REG		0x30c
1359026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG1_REG		0x310
1369026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END1_REG		0x314
1379026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA1_REG		0x318
1389026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG2_REG		0x31c
1399026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END2_REG		0x320
1409026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA2_REG		0x324
1419026e0d1SMaxime Ripard #define SUN4I_TCON1_GAMMA_TABLE_REG		0x400
1429026e0d1SMaxime Ripard 
1439026e0d1SMaxime Ripard #define SUN4I_TCON_MAX_CHANNELS		2
1449026e0d1SMaxime Ripard 
1459026e0d1SMaxime Ripard struct sun4i_tcon {
146*ae558110SMaxime Ripard 	struct device			*dev;
1479026e0d1SMaxime Ripard 	struct drm_device		*drm;
1489026e0d1SMaxime Ripard 	struct regmap			*regs;
1499026e0d1SMaxime Ripard 
1509026e0d1SMaxime Ripard 	/* Main bus clock */
1519026e0d1SMaxime Ripard 	struct clk			*clk;
1529026e0d1SMaxime Ripard 
1539026e0d1SMaxime Ripard 	/* Clocks for the TCON channels */
1549026e0d1SMaxime Ripard 	struct clk			*sclk0;
1559026e0d1SMaxime Ripard 	struct clk			*sclk1;
1569026e0d1SMaxime Ripard 
1579026e0d1SMaxime Ripard 	/* Pixel clock */
1589026e0d1SMaxime Ripard 	struct clk			*dclk;
1599026e0d1SMaxime Ripard 
1609026e0d1SMaxime Ripard 	/* Reset control */
1619026e0d1SMaxime Ripard 	struct reset_control		*lcd_rst;
1629026e0d1SMaxime Ripard 
1639026e0d1SMaxime Ripard 	/* Platform adjustments */
1649026e0d1SMaxime Ripard 	bool				has_mux;
16529e57fabSMaxime Ripard 
16629e57fabSMaxime Ripard 	struct drm_panel		*panel;
1679026e0d1SMaxime Ripard };
1689026e0d1SMaxime Ripard 
1699026e0d1SMaxime Ripard /* Global Control */
1709026e0d1SMaxime Ripard void sun4i_tcon_disable(struct sun4i_tcon *tcon);
1719026e0d1SMaxime Ripard void sun4i_tcon_enable(struct sun4i_tcon *tcon);
1729026e0d1SMaxime Ripard 
1739026e0d1SMaxime Ripard /* Channel Control */
1749026e0d1SMaxime Ripard void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel);
1759026e0d1SMaxime Ripard void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel);
1769026e0d1SMaxime Ripard 
1779026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable);
1789026e0d1SMaxime Ripard 
1799026e0d1SMaxime Ripard /* Mode Related Controls */
1809026e0d1SMaxime Ripard void sun4i_tcon_switch_interlace(struct sun4i_tcon *tcon,
1819026e0d1SMaxime Ripard 				 bool enable);
1829026e0d1SMaxime Ripard void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
1839026e0d1SMaxime Ripard 			  struct drm_display_mode *mode);
1849026e0d1SMaxime Ripard void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
1859026e0d1SMaxime Ripard 			  struct drm_display_mode *mode);
1869026e0d1SMaxime Ripard 
1879026e0d1SMaxime Ripard #endif /* __SUN4I_TCON_H__ */
188