xref: /openbmc/linux/drivers/gpu/drm/sun4i/sun4i_tcon.h (revision a88cbbd469b05548f499e4320758f0364beada08)
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>
2080a58240SChen-Yu Tsai #include <linux/list.h>
219026e0d1SMaxime Ripard #include <linux/reset.h>
229026e0d1SMaxime Ripard 
239026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_REG			0x0
249026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_TCON_ENABLE			BIT(31)
259026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_MASK			BIT(0)
269026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON1			(1 << 0)
279026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON0			(0 << 0)
289026e0d1SMaxime Ripard 
299026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_REG			0x4
309026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe)		BIT(31 - (pipe))
319026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_INT(pipe)		BIT(15 - (pipe))
329026e0d1SMaxime Ripard 
339026e0d1SMaxime Ripard #define SUN4I_TCON_GINT1_REG			0x8
349026e0d1SMaxime Ripard #define SUN4I_TCON_FRM_CTL_REG			0x10
359026e0d1SMaxime Ripard 
369026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_REG			0x40
379026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_TCON_ENABLE			BIT(31)
389026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY_MASK			GENMASK(8, 4)
399026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY(delay)		((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK)
409026e0d1SMaxime Ripard 
419026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_REG			0x44
429026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_GATE_BIT			(31)
439026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_SHIFT			(0)
449026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_WIDTH			(7)
459026e0d1SMaxime Ripard 
469026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_REG			0x48
479026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_X(width)			((((width) - 1) & 0xfff) << 16)
489026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_Y(height)			(((height) - 1) & 0xfff)
499026e0d1SMaxime Ripard 
509026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_REG			0x4c
519026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_TOTAL(total)		((((total) - 1) & 0x1fff) << 16)
529026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
539026e0d1SMaxime Ripard 
549026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_REG			0x50
55*a88cbbd4SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_TOTAL(total)		(((total) & 0x1fff) << 16)
569026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
579026e0d1SMaxime Ripard 
589026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_REG			0x54
599026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_H_SYNC(width)		((((width) - 1) & 0x7ff) << 16)
609026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_V_SYNC(height)		(((height) - 1) & 0x7ff)
619026e0d1SMaxime Ripard 
629026e0d1SMaxime Ripard #define SUN4I_TCON0_HV_IF_REG			0x58
639026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_IF_REG			0x60
649026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_WR_REG			0x64
659026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RD0_REG			0x68
669026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RDA_REG			0x6c
679026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL0_REG			0x70
689026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL1_REG			0x74
699026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL2_REG			0x78
709026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL3_REG			0x7c
719026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL4_REG			0x80
729026e0d1SMaxime Ripard #define SUN4I_TCON0_LVDS_IF_REG			0x84
739026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_REG			0x88
749026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase)		((phase & 3) << 28)
759026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE		BIT(25)
769026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE		BIT(24)
779026e0d1SMaxime Ripard 
789026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_REG			0x8c
799026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE		BIT(25)
809026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE		BIT(24)
819026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins)	GENMASK(pins, 0)
829026e0d1SMaxime Ripard 
839026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_REG			0x90
849026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_TCON_ENABLE			BIT(31)
859026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_INTERLACE_ENABLE		BIT(20)
869026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY_MASK			GENMASK(8, 4)
879026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY(delay)		((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK)
889026e0d1SMaxime Ripard 
899026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_REG			0x94
909026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_X(width)			((((width) - 1) & 0xfff) << 16)
919026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_Y(height)			(((height) - 1) & 0xfff)
929026e0d1SMaxime Ripard 
939026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_REG			0x98
949026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_X(width)			((((width) - 1) & 0xfff) << 16)
959026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_Y(height)			(((height) - 1) & 0xfff)
969026e0d1SMaxime Ripard 
979026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_REG			0x9c
989026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_X(width)			((((width) - 1) & 0xfff) << 16)
999026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_Y(height)			(((height) - 1) & 0xfff)
1009026e0d1SMaxime Ripard 
1019026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_REG			0xa0
1029026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_TOTAL(total)		((((total) - 1) & 0x1fff) << 16)
1039026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
1049026e0d1SMaxime Ripard 
1059026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_REG			0xa4
1069026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_TOTAL(total)		(((total) & 0x1fff) << 16)
1079026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp)		(((bp) - 1) & 0xfff)
1089026e0d1SMaxime Ripard 
1099026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_REG			0xa8
1109026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_H_SYNC(width)		((((width) - 1) & 0x3ff) << 16)
1119026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_V_SYNC(height)		(((height) - 1) & 0x3ff)
1129026e0d1SMaxime Ripard 
1139026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_POL_REG			0xf0
1149026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_TRI_REG			0xf4
1159026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_CTL_REG			0x100
1169026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RR_REG		0x110
1179026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RG_REG		0x114
1189026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RB_REG		0x118
1199026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_RC_REG		0x11c
1209026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GR_REG		0x120
1219026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GG_REG		0x124
1229026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GB_REG		0x128
1239026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_GC_REG		0x12c
1249026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BR_REG		0x130
1259026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BG_REG		0x134
1269026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BB_REG		0x138
1279026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_BC_REG		0x13c
1289026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_R_REG		0x140
1299026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_G_REG		0x144
1309026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_B_REG		0x148
1319026e0d1SMaxime Ripard #define SUN4I_TCON_MUX_CTRL_REG			0x200
1329026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_CTL_REG		0x300
1339026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG0_REG		0x304
1349026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END0_REG		0x308
1359026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA0_REG		0x30c
1369026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG1_REG		0x310
1379026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END1_REG		0x314
1389026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA1_REG		0x318
1399026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG2_REG		0x31c
1409026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END2_REG		0x320
1419026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA2_REG		0x324
1429026e0d1SMaxime Ripard #define SUN4I_TCON1_GAMMA_TABLE_REG		0x400
1439026e0d1SMaxime Ripard 
1449026e0d1SMaxime Ripard #define SUN4I_TCON_MAX_CHANNELS		2
1459026e0d1SMaxime Ripard 
14691ea2f29SChen-Yu Tsai struct sun4i_tcon_quirks {
14791ea2f29SChen-Yu Tsai 	bool	has_unknown_mux; /* sun5i has undocumented mux */
14891ea2f29SChen-Yu Tsai 	bool	has_channel_1;	/* a33 does not have channel 1 */
14991ea2f29SChen-Yu Tsai };
15091ea2f29SChen-Yu Tsai 
1519026e0d1SMaxime Ripard struct sun4i_tcon {
152ae558110SMaxime Ripard 	struct device			*dev;
1539026e0d1SMaxime Ripard 	struct drm_device		*drm;
1549026e0d1SMaxime Ripard 	struct regmap			*regs;
1559026e0d1SMaxime Ripard 
1569026e0d1SMaxime Ripard 	/* Main bus clock */
1579026e0d1SMaxime Ripard 	struct clk			*clk;
1589026e0d1SMaxime Ripard 
1599026e0d1SMaxime Ripard 	/* Clocks for the TCON channels */
1609026e0d1SMaxime Ripard 	struct clk			*sclk0;
1619026e0d1SMaxime Ripard 	struct clk			*sclk1;
1629026e0d1SMaxime Ripard 
1639026e0d1SMaxime Ripard 	/* Pixel clock */
1649026e0d1SMaxime Ripard 	struct clk			*dclk;
1659026e0d1SMaxime Ripard 
1669026e0d1SMaxime Ripard 	/* Reset control */
1679026e0d1SMaxime Ripard 	struct reset_control		*lcd_rst;
1689026e0d1SMaxime Ripard 
16929e57fabSMaxime Ripard 	struct drm_panel		*panel;
1708e924047SMaxime Ripard 
17191ea2f29SChen-Yu Tsai 	/* Platform adjustments */
17291ea2f29SChen-Yu Tsai 	const struct sun4i_tcon_quirks	*quirks;
17346cce6daSChen-Yu Tsai 
17446cce6daSChen-Yu Tsai 	/* Associated crtc */
17546cce6daSChen-Yu Tsai 	struct sun4i_crtc		*crtc;
17680a58240SChen-Yu Tsai 
177d281c862SChen-Yu Tsai 	int				id;
178d281c862SChen-Yu Tsai 
17980a58240SChen-Yu Tsai 	/* TCON list management */
18080a58240SChen-Yu Tsai 	struct list_head		list;
1819026e0d1SMaxime Ripard };
1829026e0d1SMaxime Ripard 
183894f5a9fSMaxime Ripard struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);
184a8444c7eSMaxime Ripard struct drm_panel *sun4i_tcon_find_panel(struct device_node *node);
185a8444c7eSMaxime Ripard 
1869026e0d1SMaxime Ripard /* Global Control */
1879026e0d1SMaxime Ripard void sun4i_tcon_disable(struct sun4i_tcon *tcon);
1889026e0d1SMaxime Ripard void sun4i_tcon_enable(struct sun4i_tcon *tcon);
1899026e0d1SMaxime Ripard 
1909026e0d1SMaxime Ripard /* Channel Control */
1919026e0d1SMaxime Ripard void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel);
1929026e0d1SMaxime Ripard void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel);
1939026e0d1SMaxime Ripard 
1949026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable);
1959026e0d1SMaxime Ripard 
1969026e0d1SMaxime Ripard /* Mode Related Controls */
1979026e0d1SMaxime Ripard void sun4i_tcon_switch_interlace(struct sun4i_tcon *tcon,
1989026e0d1SMaxime Ripard 				 bool enable);
199f8c73f4fSMaxime Ripard void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel,
200f8c73f4fSMaxime Ripard 			struct drm_encoder *encoder);
2019026e0d1SMaxime Ripard void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
2029026e0d1SMaxime Ripard 			  struct drm_display_mode *mode);
2039026e0d1SMaxime Ripard void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
2049026e0d1SMaxime Ripard 			  struct drm_display_mode *mode);
2059026e0d1SMaxime Ripard 
2069026e0d1SMaxime Ripard #endif /* __SUN4I_TCON_H__ */
207