xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-sunxi/clock_sun4i.h (revision fd42e1b589b5ae7e89dc327a70e5852999a23aeb)
1643cf0eaSIan Campbell /*
2643cf0eaSIan Campbell  * sun4i, sun5i and sun7i clock register definitions
3643cf0eaSIan Campbell  *
4643cf0eaSIan Campbell  * (C) Copyright 2007-2011
5643cf0eaSIan Campbell  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6643cf0eaSIan Campbell  * Tom Cubie <tangliang@allwinnertech.com>
7643cf0eaSIan Campbell  *
8643cf0eaSIan Campbell  * SPDX-License-Identifier:	GPL-2.0+
9643cf0eaSIan Campbell  */
10643cf0eaSIan Campbell 
11643cf0eaSIan Campbell #ifndef _SUNXI_CLOCK_SUN4I_H
12643cf0eaSIan Campbell #define _SUNXI_CLOCK_SUN4I_H
13643cf0eaSIan Campbell 
14643cf0eaSIan Campbell struct sunxi_ccm_reg {
15643cf0eaSIan Campbell 	u32 pll1_cfg;		/* 0x00 pll1 control */
16643cf0eaSIan Campbell 	u32 pll1_tun;		/* 0x04 pll1 tuning */
17643cf0eaSIan Campbell 	u32 pll2_cfg;		/* 0x08 pll2 control */
18643cf0eaSIan Campbell 	u32 pll2_tun;		/* 0x0c pll2 tuning */
19643cf0eaSIan Campbell 	u32 pll3_cfg;		/* 0x10 pll3 control */
20643cf0eaSIan Campbell 	u8 res0[0x4];
21643cf0eaSIan Campbell 	u32 pll4_cfg;		/* 0x18 pll4 control */
22643cf0eaSIan Campbell 	u8 res1[0x4];
23643cf0eaSIan Campbell 	u32 pll5_cfg;		/* 0x20 pll5 control */
24643cf0eaSIan Campbell 	u32 pll5_tun;		/* 0x24 pll5 tuning */
25643cf0eaSIan Campbell 	u32 pll6_cfg;		/* 0x28 pll6 control */
26643cf0eaSIan Campbell 	u32 pll6_tun;		/* 0x2c pll6 tuning */
27643cf0eaSIan Campbell 	u32 pll7_cfg;		/* 0x30 pll7 control */
28643cf0eaSIan Campbell 	u32 pll1_tun2;		/* 0x34 pll5 tuning2 */
29643cf0eaSIan Campbell 	u8 res2[0x4];
30643cf0eaSIan Campbell 	u32 pll5_tun2;		/* 0x3c pll5 tuning2 */
31643cf0eaSIan Campbell 	u8 res3[0xc];
32643cf0eaSIan Campbell 	u32 pll_lock_dbg;	/* 0x4c pll lock time debug */
33643cf0eaSIan Campbell 	u32 osc24m_cfg;		/* 0x50 osc24m control */
34643cf0eaSIan Campbell 	u32 cpu_ahb_apb0_cfg;	/* 0x54 cpu,ahb and apb0 divide ratio */
35643cf0eaSIan Campbell 	u32 apb1_clk_div_cfg;	/* 0x58 apb1 clock dividor */
36643cf0eaSIan Campbell 	u32 axi_gate;		/* 0x5c axi module clock gating */
37643cf0eaSIan Campbell 	u32 ahb_gate0;		/* 0x60 ahb module clock gating 0 */
38643cf0eaSIan Campbell 	u32 ahb_gate1;		/* 0x64 ahb module clock gating 1 */
39643cf0eaSIan Campbell 	u32 apb0_gate;		/* 0x68 apb0 module clock gating */
40643cf0eaSIan Campbell 	u32 apb1_gate;		/* 0x6c apb1 module clock gating */
41643cf0eaSIan Campbell 	u8 res4[0x10];
42d0f42003SRoy Spliet 	u32 nand0_clk_cfg;	/* 0x80 nand sub clock control */
43643cf0eaSIan Campbell 	u32 ms_sclk_cfg;	/* 0x84 memory stick sub clock control */
44643cf0eaSIan Campbell 	u32 sd0_clk_cfg;	/* 0x88 sd0 clock control */
45643cf0eaSIan Campbell 	u32 sd1_clk_cfg;	/* 0x8c sd1 clock control */
46643cf0eaSIan Campbell 	u32 sd2_clk_cfg;	/* 0x90 sd2 clock control */
47643cf0eaSIan Campbell 	u32 sd3_clk_cfg;	/* 0x94 sd3 clock control */
48643cf0eaSIan Campbell 	u32 ts_clk_cfg;		/* 0x98 transport stream clock control */
49643cf0eaSIan Campbell 	u32 ss_clk_cfg;		/* 0x9c */
50643cf0eaSIan Campbell 	u32 spi0_clk_cfg;	/* 0xa0 */
51643cf0eaSIan Campbell 	u32 spi1_clk_cfg;	/* 0xa4 */
52643cf0eaSIan Campbell 	u32 spi2_clk_cfg;	/* 0xa8 */
53643cf0eaSIan Campbell 	u32 pata_clk_cfg;	/* 0xac */
54643cf0eaSIan Campbell 	u32 ir0_clk_cfg;	/* 0xb0 */
55643cf0eaSIan Campbell 	u32 ir1_clk_cfg;	/* 0xb4 */
56643cf0eaSIan Campbell 	u32 iis_clk_cfg;	/* 0xb8 */
57643cf0eaSIan Campbell 	u32 ac97_clk_cfg;	/* 0xbc */
58643cf0eaSIan Campbell 	u32 spdif_clk_cfg;	/* 0xc0 */
59643cf0eaSIan Campbell 	u32 keypad_clk_cfg;	/* 0xc4 */
60643cf0eaSIan Campbell 	u32 sata_clk_cfg;	/* 0xc8 */
61643cf0eaSIan Campbell 	u32 usb_clk_cfg;	/* 0xcc */
62643cf0eaSIan Campbell 	u32 gps_clk_cfg;	/* 0xd0 */
63643cf0eaSIan Campbell 	u32 spi3_clk_cfg;	/* 0xd4 */
64643cf0eaSIan Campbell 	u8 res5[0x28];
659d4b7d0bSHans de Goede 	u32 dram_clk_gate;	/* 0x100 */
66643cf0eaSIan Campbell 	u32 be0_clk_cfg;	/* 0x104 */
67643cf0eaSIan Campbell 	u32 be1_clk_cfg;	/* 0x108 */
68643cf0eaSIan Campbell 	u32 fe0_clk_cfg;	/* 0x10c */
69643cf0eaSIan Campbell 	u32 fe1_clk_cfg;	/* 0x110 */
70643cf0eaSIan Campbell 	u32 mp_clk_cfg;		/* 0x114 */
71643cf0eaSIan Campbell 	u32 lcd0_ch0_clk_cfg;	/* 0x118 */
72643cf0eaSIan Campbell 	u32 lcd1_ch0_clk_cfg;	/* 0x11c */
73643cf0eaSIan Campbell 	u32 csi_isp_clk_cfg;	/* 0x120 */
74643cf0eaSIan Campbell 	u8 res6[0x4];
75643cf0eaSIan Campbell 	u32 tvd_clk_reg;	/* 0x128 */
76643cf0eaSIan Campbell 	u32 lcd0_ch1_clk_cfg;	/* 0x12c */
77643cf0eaSIan Campbell 	u32 lcd1_ch1_clk_cfg;	/* 0x130 */
78643cf0eaSIan Campbell 	u32 csi0_clk_cfg;	/* 0x134 */
79643cf0eaSIan Campbell 	u32 csi1_clk_cfg;	/* 0x138 */
80643cf0eaSIan Campbell 	u32 ve_clk_cfg;		/* 0x13c */
81643cf0eaSIan Campbell 	u32 audio_codec_clk_cfg;	/* 0x140 */
82643cf0eaSIan Campbell 	u32 avs_clk_cfg;	/* 0x144 */
83643cf0eaSIan Campbell 	u32 ace_clk_cfg;	/* 0x148 */
84643cf0eaSIan Campbell 	u32 lvds_clk_cfg;	/* 0x14c */
85643cf0eaSIan Campbell 	u32 hdmi_clk_cfg;	/* 0x150 */
86643cf0eaSIan Campbell 	u32 mali_clk_cfg;	/* 0x154 */
87643cf0eaSIan Campbell 	u8 res7[0x4];
88643cf0eaSIan Campbell 	u32 mbus_clk_cfg;	/* 0x15c */
89643cf0eaSIan Campbell 	u8 res8[0x4];
90643cf0eaSIan Campbell 	u32 gmac_clk_cfg;	/* 0x164 */
91643cf0eaSIan Campbell };
92643cf0eaSIan Campbell 
93643cf0eaSIan Campbell /* apb1 bit field */
94643cf0eaSIan Campbell #define APB1_CLK_SRC_OSC24M		(0x0 << 24)
95643cf0eaSIan Campbell #define APB1_CLK_SRC_PLL6		(0x1 << 24)
96643cf0eaSIan Campbell #define APB1_CLK_SRC_LOSC		(0x2 << 24)
97643cf0eaSIan Campbell #define APB1_CLK_SRC_MASK		(0x3 << 24)
98643cf0eaSIan Campbell #define APB1_CLK_RATE_N_1		(0x0 << 16)
99643cf0eaSIan Campbell #define APB1_CLK_RATE_N_2		(0x1 << 16)
100643cf0eaSIan Campbell #define APB1_CLK_RATE_N_4		(0x2 << 16)
101643cf0eaSIan Campbell #define APB1_CLK_RATE_N_8		(0x3 << 16)
102643cf0eaSIan Campbell #define APB1_CLK_RATE_N_MASK		(3 << 16)
103643cf0eaSIan Campbell #define APB1_CLK_RATE_M(m)		(((m)-1) << 0)
104643cf0eaSIan Campbell #define APB1_CLK_RATE_M_MASK            (0x1f << 0)
105643cf0eaSIan Campbell 
106643cf0eaSIan Campbell /* apb1 gate field */
107643cf0eaSIan Campbell #define APB1_GATE_UART_SHIFT	(16)
108643cf0eaSIan Campbell #define APB1_GATE_UART_MASK		(0xff << APB1_GATE_UART_SHIFT)
109643cf0eaSIan Campbell #define APB1_GATE_TWI_SHIFT	(0)
110643cf0eaSIan Campbell #define APB1_GATE_TWI_MASK		(0xf << APB1_GATE_TWI_SHIFT)
111643cf0eaSIan Campbell 
112643cf0eaSIan Campbell /* clock divide */
113643cf0eaSIan Campbell #define AXI_DIV_SHIFT		(0)
114643cf0eaSIan Campbell #define AXI_DIV_1			0
115643cf0eaSIan Campbell #define AXI_DIV_2			1
116643cf0eaSIan Campbell #define AXI_DIV_3			2
117643cf0eaSIan Campbell #define AXI_DIV_4			3
118643cf0eaSIan Campbell #define AHB_DIV_SHIFT		(4)
119643cf0eaSIan Campbell #define AHB_DIV_1			0
120643cf0eaSIan Campbell #define AHB_DIV_2			1
121643cf0eaSIan Campbell #define AHB_DIV_4			2
122643cf0eaSIan Campbell #define AHB_DIV_8			3
123643cf0eaSIan Campbell #define APB0_DIV_SHIFT		(8)
124643cf0eaSIan Campbell #define APB0_DIV_1			0
125643cf0eaSIan Campbell #define APB0_DIV_2			1
126643cf0eaSIan Campbell #define APB0_DIV_4			2
127643cf0eaSIan Campbell #define APB0_DIV_8			3
128643cf0eaSIan Campbell #define CPU_CLK_SRC_SHIFT	(16)
129643cf0eaSIan Campbell #define CPU_CLK_SRC_OSC24M		1
130643cf0eaSIan Campbell #define CPU_CLK_SRC_PLL1		2
131643cf0eaSIan Campbell 
132643cf0eaSIan Campbell #define CCM_PLL1_CFG_ENABLE_SHIFT		31
133643cf0eaSIan Campbell #define CCM_PLL1_CFG_VCO_RST_SHIFT		30
134643cf0eaSIan Campbell #define CCM_PLL1_CFG_VCO_BIAS_SHIFT		26
135643cf0eaSIan Campbell #define CCM_PLL1_CFG_PLL4_EXCH_SHIFT		25
136643cf0eaSIan Campbell #define CCM_PLL1_CFG_BIAS_CUR_SHIFT		20
137643cf0eaSIan Campbell #define CCM_PLL1_CFG_DIVP_SHIFT			16
138643cf0eaSIan Campbell #define CCM_PLL1_CFG_LCK_TMR_SHIFT		13
139643cf0eaSIan Campbell #define CCM_PLL1_CFG_FACTOR_N_SHIFT		8
140643cf0eaSIan Campbell #define CCM_PLL1_CFG_FACTOR_K_SHIFT		4
141643cf0eaSIan Campbell #define CCM_PLL1_CFG_SIG_DELT_PAT_IN_SHIFT	3
142643cf0eaSIan Campbell #define CCM_PLL1_CFG_SIG_DELT_PAT_EN_SHIFT	2
143643cf0eaSIan Campbell #define CCM_PLL1_CFG_FACTOR_M_SHIFT		0
144643cf0eaSIan Campbell 
145643cf0eaSIan Campbell #define PLL1_CFG_DEFAULT	0xa1005000
146643cf0eaSIan Campbell 
147f388a26dSHans de Goede #if defined CONFIG_OLD_SUNXI_KERNEL_COMPAT && defined CONFIG_MACH_SUN5I
148f388a26dSHans de Goede /*
149f388a26dSHans de Goede  * Older linux-sunxi-3.4 kernels override our PLL6 setting with 300 MHz,
150f388a26dSHans de Goede  * halving the mbus frequency, so set it to 300 MHz ourselves and base the
151f388a26dSHans de Goede  * mbus divider on that.
152f388a26dSHans de Goede  */
153f388a26dSHans de Goede #define PLL6_CFG_DEFAULT	0xa1009900
154f388a26dSHans de Goede #else
155643cf0eaSIan Campbell #define PLL6_CFG_DEFAULT	0xa1009911
156f388a26dSHans de Goede #endif
157643cf0eaSIan Campbell 
158643cf0eaSIan Campbell /* nand clock */
159643cf0eaSIan Campbell #define NAND_CLK_SRC_OSC24		0
160643cf0eaSIan Campbell #define NAND_CLK_DIV_N			0
161643cf0eaSIan Campbell #define NAND_CLK_DIV_M			0
162643cf0eaSIan Campbell 
163643cf0eaSIan Campbell /* gps clock */
164643cf0eaSIan Campbell #define GPS_SCLK_GATING_OFF		0
165643cf0eaSIan Campbell #define GPS_RESET			0
166643cf0eaSIan Campbell 
167643cf0eaSIan Campbell /* ahb clock gate bit offset */
168643cf0eaSIan Campbell #define AHB_GATE_OFFSET_GPS		26
169643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SATA		25
170643cf0eaSIan Campbell #define AHB_GATE_OFFSET_PATA		24
171643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SPI3		23
172643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SPI2		22
173643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SPI1		21
174643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SPI0		20
175643cf0eaSIan Campbell #define AHB_GATE_OFFSET_TS0		18
176643cf0eaSIan Campbell #define AHB_GATE_OFFSET_EMAC		17
177643cf0eaSIan Campbell #define AHB_GATE_OFFSET_ACE		16
178643cf0eaSIan Campbell #define AHB_GATE_OFFSET_DLL		15
179643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SDRAM		14
180d0f42003SRoy Spliet #define AHB_GATE_OFFSET_NAND0		13
181643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MS		12
182643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MMC3		11
183643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MMC2		10
184643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MMC1		9
185643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MMC0		8
186643cf0eaSIan Campbell #define AHB_GATE_OFFSET_MMC(n)		(AHB_GATE_OFFSET_MMC0 + (n))
187643cf0eaSIan Campbell #define AHB_GATE_OFFSET_BIST		7
188643cf0eaSIan Campbell #define AHB_GATE_OFFSET_DMA		6
189643cf0eaSIan Campbell #define AHB_GATE_OFFSET_SS		5
190643cf0eaSIan Campbell #define AHB_GATE_OFFSET_USB_OHCI1	4
191643cf0eaSIan Campbell #define AHB_GATE_OFFSET_USB_EHCI1	3
192643cf0eaSIan Campbell #define AHB_GATE_OFFSET_USB_OHCI0	2
193643cf0eaSIan Campbell #define AHB_GATE_OFFSET_USB_EHCI0	1
1940eccec4eSHans de Goede #define AHB_GATE_OFFSET_USB0		0
195643cf0eaSIan Campbell 
196643cf0eaSIan Campbell /* ahb clock gate bit offset (second register) */
197643cf0eaSIan Campbell #define AHB_GATE_OFFSET_GMAC		17
1987cd6f92dSHans de Goede #define AHB_GATE_OFFSET_DE_FE0		14
1990bd51251SHans de Goede #define AHB_GATE_OFFSET_DE_BE0		12
2000bd51251SHans de Goede #define AHB_GATE_OFFSET_HDMI		11
2010bd51251SHans de Goede #define AHB_GATE_OFFSET_LCD1		5
2020bd51251SHans de Goede #define AHB_GATE_OFFSET_LCD0		4
203d9786d23SHans de Goede #define AHB_GATE_OFFSET_TVE1		3
204d9786d23SHans de Goede #define AHB_GATE_OFFSET_TVE0		2
205643cf0eaSIan Campbell 
206643cf0eaSIan Campbell #define CCM_AHB_GATE_GPS (0x1 << 26)
207643cf0eaSIan Campbell #define CCM_AHB_GATE_SDRAM (0x1 << 14)
208643cf0eaSIan Campbell #define CCM_AHB_GATE_DLL (0x1 << 15)
209643cf0eaSIan Campbell #define CCM_AHB_GATE_ACE (0x1 << 16)
210643cf0eaSIan Campbell 
21149043cbaSHans de Goede #define CCM_PLL3_CTRL_M_SHIFT		0
21249043cbaSHans de Goede #define CCM_PLL3_CTRL_M_MASK		(0x7f << CCM_PLL3_CTRL_M_SHIFT)
2130bd51251SHans de Goede #define CCM_PLL3_CTRL_M(n)		(((n) & 0x7f) << 0)
2140bd51251SHans de Goede #define CCM_PLL3_CTRL_INTEGER_MODE	(0x1 << 15)
2150bd51251SHans de Goede #define CCM_PLL3_CTRL_EN		(0x1 << 31)
2160bd51251SHans de Goede 
217643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M(n) (((n) & 0x3) << 0)
218643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M_MASK CCM_PLL5_CTRL_M(0x3)
219643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M_X(n) ((n) - 1)
220643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M1(n) (((n) & 0x3) << 2)
221643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M1_MASK CCM_PLL5_CTRL_M1(0x3)
222643cf0eaSIan Campbell #define CCM_PLL5_CTRL_M1_X(n) ((n) - 1)
223643cf0eaSIan Campbell #define CCM_PLL5_CTRL_K(n) (((n) & 0x3) << 4)
2249e54f6eeSHans de Goede #define CCM_PLL5_CTRL_K_SHIFT 4
225643cf0eaSIan Campbell #define CCM_PLL5_CTRL_K_MASK CCM_PLL5_CTRL_K(0x3)
226643cf0eaSIan Campbell #define CCM_PLL5_CTRL_K_X(n) ((n) - 1)
227643cf0eaSIan Campbell #define CCM_PLL5_CTRL_LDO (0x1 << 7)
228643cf0eaSIan Campbell #define CCM_PLL5_CTRL_N(n) (((n) & 0x1f) << 8)
2299e54f6eeSHans de Goede #define CCM_PLL5_CTRL_N_SHIFT 8
230643cf0eaSIan Campbell #define CCM_PLL5_CTRL_N_MASK CCM_PLL5_CTRL_N(0x1f)
231643cf0eaSIan Campbell #define CCM_PLL5_CTRL_N_X(n) (n)
232643cf0eaSIan Campbell #define CCM_PLL5_CTRL_P(n) (((n) & 0x3) << 16)
2339e54f6eeSHans de Goede #define CCM_PLL5_CTRL_P_SHIFT 16
234643cf0eaSIan Campbell #define CCM_PLL5_CTRL_P_MASK CCM_PLL5_CTRL_P(0x3)
235643cf0eaSIan Campbell #define CCM_PLL5_CTRL_P_X(n) ((n) - 1)
236643cf0eaSIan Campbell #define CCM_PLL5_CTRL_BW (0x1 << 18)
237643cf0eaSIan Campbell #define CCM_PLL5_CTRL_VCO_GAIN (0x1 << 19)
238643cf0eaSIan Campbell #define CCM_PLL5_CTRL_BIAS(n) (((n) & 0x1f) << 20)
239643cf0eaSIan Campbell #define CCM_PLL5_CTRL_BIAS_MASK CCM_PLL5_CTRL_BIAS(0x1f)
240643cf0eaSIan Campbell #define CCM_PLL5_CTRL_BIAS_X(n) ((n) - 1)
241643cf0eaSIan Campbell #define CCM_PLL5_CTRL_VCO_BIAS (0x1 << 25)
242643cf0eaSIan Campbell #define CCM_PLL5_CTRL_DDR_CLK (0x1 << 29)
243643cf0eaSIan Campbell #define CCM_PLL5_CTRL_BYPASS (0x1 << 30)
244643cf0eaSIan Campbell #define CCM_PLL5_CTRL_EN (0x1 << 31)
245643cf0eaSIan Campbell 
246a6e50a88SIan Campbell #define CCM_PLL6_CTRL_EN		31
247a6e50a88SIan Campbell #define CCM_PLL6_CTRL_BYPASS_EN		30
248a6e50a88SIan Campbell #define CCM_PLL6_CTRL_SATA_EN_SHIFT	14
249643cf0eaSIan Campbell #define CCM_PLL6_CTRL_N_SHIFT		8
250643cf0eaSIan Campbell #define CCM_PLL6_CTRL_N_MASK		(0x1f << CCM_PLL6_CTRL_N_SHIFT)
251643cf0eaSIan Campbell #define CCM_PLL6_CTRL_K_SHIFT		4
252643cf0eaSIan Campbell #define CCM_PLL6_CTRL_K_MASK		(0x3 << CCM_PLL6_CTRL_K_SHIFT)
253643cf0eaSIan Campbell 
254643cf0eaSIan Campbell #define CCM_GPS_CTRL_RESET (0x1 << 0)
255643cf0eaSIan Campbell #define CCM_GPS_CTRL_GATE (0x1 << 1)
256643cf0eaSIan Campbell 
257643cf0eaSIan Campbell #define CCM_DRAM_CTRL_DCLK_OUT (0x1 << 15)
258643cf0eaSIan Campbell 
259643cf0eaSIan Campbell #define CCM_MBUS_CTRL_M(n) (((n) & 0xf) << 0)
260643cf0eaSIan Campbell #define CCM_MBUS_CTRL_M_MASK CCM_MBUS_CTRL_M(0xf)
261643cf0eaSIan Campbell #define CCM_MBUS_CTRL_M_X(n) ((n) - 1)
262643cf0eaSIan Campbell #define CCM_MBUS_CTRL_N(n) (((n) & 0xf) << 16)
263643cf0eaSIan Campbell #define CCM_MBUS_CTRL_N_MASK CCM_MBUS_CTRL_N(0xf)
264643cf0eaSIan Campbell #define CCM_MBUS_CTRL_N_X(n) (((n) >> 3) ? 3 : (((n) >> 2) ? 2 : (((n) >> 1) ? 1 : 0)))
265643cf0eaSIan Campbell #define CCM_MBUS_CTRL_CLK_SRC(n) (((n) & 0x3) << 24)
266643cf0eaSIan Campbell #define CCM_MBUS_CTRL_CLK_SRC_MASK CCM_MBUS_CTRL_CLK_SRC(0x3)
267643cf0eaSIan Campbell #define CCM_MBUS_CTRL_CLK_SRC_HOSC 0x0
268643cf0eaSIan Campbell #define CCM_MBUS_CTRL_CLK_SRC_PLL6 0x1
269643cf0eaSIan Campbell #define CCM_MBUS_CTRL_CLK_SRC_PLL5 0x2
270643cf0eaSIan Campbell #define CCM_MBUS_CTRL_GATE (0x1 << 31)
271643cf0eaSIan Campbell 
272*8df375b4SBoris Brezillon #define CCM_NAND_CTRL_M(x)		((x) - 1)
273*8df375b4SBoris Brezillon #define CCM_NAND_CTRL_N(x)		((x) << 16)
274*8df375b4SBoris Brezillon #define CCM_NAND_CTRL_OSCM24		(0x0 << 24)
275*8df375b4SBoris Brezillon #define CCM_NAND_CTRL_PLL6		(0x1 << 24)
276*8df375b4SBoris Brezillon #define CCM_NAND_CTRL_PLL5		(0x2 << 24)
277ad008299SKarol Gugala #define CCM_NAND_CTRL_ENABLE		(0x1 << 31)
278ad008299SKarol Gugala 
279fc3a8325SHans de Goede #define CCM_MMC_CTRL_M(x)		((x) - 1)
280fc3a8325SHans de Goede #define CCM_MMC_CTRL_OCLK_DLY(x)	((x) << 8)
281fc3a8325SHans de Goede #define CCM_MMC_CTRL_N(x)		((x) << 16)
282fc3a8325SHans de Goede #define CCM_MMC_CTRL_SCLK_DLY(x)	((x) << 20)
283643cf0eaSIan Campbell #define CCM_MMC_CTRL_OSCM24		(0x0 << 24)
284643cf0eaSIan Campbell #define CCM_MMC_CTRL_PLL6		(0x1 << 24)
285643cf0eaSIan Campbell #define CCM_MMC_CTRL_PLL5		(0x2 << 24)
286643cf0eaSIan Campbell #define CCM_MMC_CTRL_ENABLE		(0x1 << 31)
287643cf0eaSIan Campbell 
2887cd6f92dSHans de Goede #define CCM_DRAM_GATE_OFFSET_DE_FE1	24 /* Note the order of FE1 and */
2897cd6f92dSHans de Goede #define CCM_DRAM_GATE_OFFSET_DE_FE0	25 /* FE0 is swapped ! */
2900bd51251SHans de Goede #define CCM_DRAM_GATE_OFFSET_DE_BE0	26
2917cd6f92dSHans de Goede #define CCM_DRAM_GATE_OFFSET_DE_BE1	27
2920bd51251SHans de Goede 
2930bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_PLL3		(0 << 24)
2940bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_PLL7		(1 << 24)
2950bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_PLL3_2X	(2 << 24)
2960bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_PLL7_2X	(3 << 24)
29755ea98d8SHans de Goede #define CCM_LCD_CH0_CTRL_MIPI_PLL	0 /* No mipi pll on sun4i/5i/7i */
298d8d07996SHans de Goede #ifdef CONFIG_MACH_SUN5I
299d8d07996SHans de Goede #define CCM_LCD_CH0_CTRL_TVE_RST	(0x1 << 29)
300d8d07996SHans de Goede #else
301d8d07996SHans de Goede #define CCM_LCD_CH0_CTRL_TVE_RST	0 /* No separate tve-rst on sun4i/7i */
302d8d07996SHans de Goede #endif
3030bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_RST		(0x1 << 30)
3040bd51251SHans de Goede #define CCM_LCD_CH0_CTRL_GATE		(0x1 << 31)
3050bd51251SHans de Goede 
3060bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_M(n)		((((n) - 1) & 0xf) << 0)
3070ecb43a8SHans de Goede #define CCM_LCD_CH1_CTRL_HALF_SCLK1	(1 << 11)
3080bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_PLL3		(0 << 24)
3090bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_PLL7		(1 << 24)
3100bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_PLL3_2X	(2 << 24)
3110bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_PLL7_2X	(3 << 24)
3120bd51251SHans de Goede /* Enable / disable both ch1 sclk1 and sclk2 at the same time */
3130bd51251SHans de Goede #define CCM_LCD_CH1_CTRL_GATE		(0x1 << 31 | 0x1 << 15)
3140bd51251SHans de Goede 
315213480e1SHans de Goede #define CCM_LVDS_CTRL_RST		(1 << 0)
316213480e1SHans de Goede 
3170bd51251SHans de Goede #define CCM_HDMI_CTRL_M(n)		((((n) - 1) & 0xf) << 0)
3180bd51251SHans de Goede #define CCM_HDMI_CTRL_PLL_MASK		(3 << 24)
3190bd51251SHans de Goede #define CCM_HDMI_CTRL_PLL3		(0 << 24)
3200bd51251SHans de Goede #define CCM_HDMI_CTRL_PLL7		(1 << 24)
3210bd51251SHans de Goede #define CCM_HDMI_CTRL_PLL3_2X		(2 << 24)
3220bd51251SHans de Goede #define CCM_HDMI_CTRL_PLL7_2X		(3 << 24)
3230bd51251SHans de Goede /* No separate ddc gate on sun4i, sun5i and sun7i */
3240bd51251SHans de Goede #define CCM_HDMI_CTRL_DDC_GATE		0
3250bd51251SHans de Goede #define CCM_HDMI_CTRL_GATE		(0x1 << 31)
3260bd51251SHans de Goede 
327643cf0eaSIan Campbell #define CCM_GMAC_CTRL_TX_CLK_SRC_MII 0x0
328643cf0eaSIan Campbell #define CCM_GMAC_CTRL_TX_CLK_SRC_EXT_RGMII 0x1
329643cf0eaSIan Campbell #define CCM_GMAC_CTRL_TX_CLK_SRC_INT_RGMII 0x2
330643cf0eaSIan Campbell #define CCM_GMAC_CTRL_GPIT_MII (0x0 << 2)
331643cf0eaSIan Campbell #define CCM_GMAC_CTRL_GPIT_RGMII (0x1 << 2)
332c13f60d9SHans de Goede #define CCM_GMAC_CTRL_RX_CLK_DELAY(x)	((x) << 5)
333c13f60d9SHans de Goede #define CCM_GMAC_CTRL_TX_CLK_DELAY(x)	((x) << 10)
334643cf0eaSIan Campbell 
3354458b7a6SHans de Goede #define CCM_USB_CTRL_PHY0_RST (0x1 << 0)
33606cdd940SRoman Byshko #define CCM_USB_CTRL_PHY1_RST (0x1 << 1)
33706cdd940SRoman Byshko #define CCM_USB_CTRL_PHY2_RST (0x1 << 2)
3386a72e804SHans de Goede #define CCM_USB_CTRL_OHCI0_CLK (0x1 << 6)
3396a72e804SHans de Goede #define CCM_USB_CTRL_OHCI1_CLK (0x1 << 7)
34006cdd940SRoman Byshko #define CCM_USB_CTRL_PHYGATE (0x1 << 8)
3414458b7a6SHans de Goede /* These 3 are sun6i only, define them as 0 on sun4i */
3424458b7a6SHans de Goede #define CCM_USB_CTRL_PHY0_CLK 0
34376946dfeSHans de Goede #define CCM_USB_CTRL_PHY1_CLK 0
34476946dfeSHans de Goede #define CCM_USB_CTRL_PHY2_CLK 0
34506cdd940SRoman Byshko 
3460bd51251SHans de Goede /* CCM bits common to all Display Engine (and IEP) clock ctrl regs */
3470bd51251SHans de Goede #define CCM_DE_CTRL_M(n)		((((n) - 1) & 0xf) << 0)
3480bd51251SHans de Goede #define CCM_DE_CTRL_PLL_MASK		(3 << 24)
3490bd51251SHans de Goede #define CCM_DE_CTRL_PLL3		(0 << 24)
3500bd51251SHans de Goede #define CCM_DE_CTRL_PLL7		(1 << 24)
3510bd51251SHans de Goede #define CCM_DE_CTRL_PLL5P		(2 << 24)
3520bd51251SHans de Goede #define CCM_DE_CTRL_RST			(1 << 30)
3530bd51251SHans de Goede #define CCM_DE_CTRL_GATE		(1 << 31)
3540bd51251SHans de Goede 
355cc67a0b6SHans de Goede #ifndef __ASSEMBLY__
356cc67a0b6SHans de Goede void clock_set_pll1(unsigned int hz);
357cc67a0b6SHans de Goede void clock_set_pll3(unsigned int hz);
35849043cbaSHans de Goede unsigned int clock_get_pll3(void);
359cc67a0b6SHans de Goede unsigned int clock_get_pll5p(void);
360cc67a0b6SHans de Goede unsigned int clock_get_pll6(void);
361cc67a0b6SHans de Goede #endif
362cc67a0b6SHans de Goede 
363643cf0eaSIan Campbell #endif /* _SUNXI_CLOCK_SUN4I_H */
364