xref: /OK3568_Linux_fs/u-boot/arch/arm/include/asm/arch-sunxi/clock_sun9i.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * sun9i clock register definitions
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _SUNXI_CLOCK_SUN9I_H
10*4882a593Smuzhiyun #define _SUNXI_CLOCK_SUN9I_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun struct sunxi_ccm_reg {
13*4882a593Smuzhiyun 	u32 pll1_c0_cfg;	/* 0x00 c0cpu# pll configuration */
14*4882a593Smuzhiyun 	u32 pll2_c1_cfg;	/* 0x04 c1cpu# pll configuration */
15*4882a593Smuzhiyun 	u32 pll3_audio_cfg;	/* 0x08 audio pll configuration */
16*4882a593Smuzhiyun 	u32 pll4_periph0_cfg;	/* 0x0c peripheral0 pll configuration */
17*4882a593Smuzhiyun 	u32 pll5_ve_cfg;	/* 0x10 videoengine pll configuration */
18*4882a593Smuzhiyun 	u32 pll6_ddr_cfg;	/* 0x14 ddr pll configuration */
19*4882a593Smuzhiyun 	u32 pll7_video0_cfg;	/* 0x18 video0 pll configuration */
20*4882a593Smuzhiyun 	u32 pll8_video1_cfg;	/* 0x1c video1 pll configuration */
21*4882a593Smuzhiyun 	u32 pll9_gpu_cfg;	/* 0x20 gpu pll configuration */
22*4882a593Smuzhiyun 	u32 pll10_de_cfg;	/* 0x24 displayengine pll configuration */
23*4882a593Smuzhiyun 	u32 pll11_isp_cfg;	/* 0x28 isp pll6 ontrol */
24*4882a593Smuzhiyun 	u32 pll12_periph1_cfg;	/* 0x2c peripheral1 pll configuration */
25*4882a593Smuzhiyun 	u8 reserved1[0x20];	/* 0x30 */
26*4882a593Smuzhiyun 	u32 cpu_clk_source;	/* 0x50 cpu clk source configuration */
27*4882a593Smuzhiyun 	u32 c0_cfg;		/* 0x54 cpu cluster 0 clock configuration */
28*4882a593Smuzhiyun 	u32 c1_cfg;		/* 0x58 cpu cluster 1 clock configuration */
29*4882a593Smuzhiyun 	u32 gtbus_cfg;		/* 0x5c gtbus clock configuration */
30*4882a593Smuzhiyun 	u32 ahb0_cfg;		/* 0x60 ahb0 clock configuration */
31*4882a593Smuzhiyun 	u32 ahb1_cfg;		/* 0x64 ahb1 clock configuration */
32*4882a593Smuzhiyun 	u32 ahb2_cfg;		/* 0x68 ahb2 clock configuration */
33*4882a593Smuzhiyun 	u8 reserved2[0x04];	/* 0x6c */
34*4882a593Smuzhiyun 	u32 apb0_cfg;		/* 0x70 apb0 clock configuration */
35*4882a593Smuzhiyun 	u32 apb1_cfg;		/* 0x74 apb1 clock configuration */
36*4882a593Smuzhiyun 	u32 cci400_cfg;		/* 0x78 cci400 clock configuration */
37*4882a593Smuzhiyun 	u8 reserved3[0x04];	/* 0x7c */
38*4882a593Smuzhiyun 	u32 ats_cfg;		/* 0x80 ats clock configuration */
39*4882a593Smuzhiyun 	u32 trace_cfg;		/* 0x84 trace clock configuration */
40*4882a593Smuzhiyun 	u8 reserved4[0x14];     /* 0x88 */
41*4882a593Smuzhiyun 	u32 pll_stable_status;  /* 0x9c */
42*4882a593Smuzhiyun 	u8 reserved5[0xe0];	/* 0xa0 */
43*4882a593Smuzhiyun 	u32 clk_output_a;	/* 0x180 clk_output_a */
44*4882a593Smuzhiyun 	u32 clk_output_b;	/* 0x184 clk_output_a */
45*4882a593Smuzhiyun 	u8 reserved6[0x278];	/* 0x188 */
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	u32 nand0_clk_cfg;	/* 0x400 nand0 clock configuration0 */
48*4882a593Smuzhiyun 	u32 nand0_clk_cfg1;	/* 0x404 nand1 clock configuration */
49*4882a593Smuzhiyun 	u8 reserved7[0x08];	/* 0x408 */
50*4882a593Smuzhiyun 	u32 sd0_clk_cfg;	/* 0x410 sd0 clock configuration */
51*4882a593Smuzhiyun 	u32 sd1_clk_cfg;	/* 0x414 sd1 clock configuration */
52*4882a593Smuzhiyun 	u32 sd2_clk_cfg;	/* 0x418 sd2 clock configuration */
53*4882a593Smuzhiyun 	u32 sd3_clk_cfg;	/* 0x41c sd3 clock configuration */
54*4882a593Smuzhiyun 	u8 reserved8[0x08];	/* 0x420 */
55*4882a593Smuzhiyun 	u32 ts_clk_cfg;		/* 0x428 transport stream clock cfg */
56*4882a593Smuzhiyun 	u32 ss_clk_cfg;		/* 0x42c security system clock cfg */
57*4882a593Smuzhiyun 	u32 spi0_clk_cfg;	/* 0x430 spi0 clock configuration */
58*4882a593Smuzhiyun 	u32 spi1_clk_cfg;	/* 0x434 spi1 clock configuration */
59*4882a593Smuzhiyun 	u32 spi2_clk_cfg;	/* 0x438 spi2 clock configuration */
60*4882a593Smuzhiyun 	u32 spi3_clk_cfg;	/* 0x43c spi3 clock configuration */
61*4882a593Smuzhiyun 	u8 reserved9[0x44];	/* 0x440 */
62*4882a593Smuzhiyun 	u32 dram_clk_cfg;       /* 0x484 DRAM (controller) clock config */
63*4882a593Smuzhiyun 	u8 reserved10[0x8];     /* 0x488 */
64*4882a593Smuzhiyun 	u32 de_clk_cfg;		/* 0x490 display engine clock configuration */
65*4882a593Smuzhiyun 	u8 reserved11[0x04];	/* 0x494 */
66*4882a593Smuzhiyun 	u32 mp_clk_cfg;		/* 0x498 mp clock configuration */
67*4882a593Smuzhiyun 	u32 lcd0_clk_cfg;	/* 0x49c LCD0 module clock */
68*4882a593Smuzhiyun 	u32 lcd1_clk_cfg;	/* 0x4a0 LCD1 module clock */
69*4882a593Smuzhiyun 	u8 reserved12[0x1c];	/* 0x4a4 */
70*4882a593Smuzhiyun 	u32 csi_isp_clk_cfg;	/* 0x4c0 CSI ISP module clock */
71*4882a593Smuzhiyun 	u32 csi0_clk_cfg;	/* 0x4c4 CSI0 module clock */
72*4882a593Smuzhiyun 	u32 csi1_clk_cfg;	/* 0x4c8 CSI1 module clock */
73*4882a593Smuzhiyun 	u32 fd_clk_cfg;		/* 0x4cc FD module clock */
74*4882a593Smuzhiyun 	u32 ve_clk_cfg;		/* 0x4d0 VE module clock */
75*4882a593Smuzhiyun 	u32 avs_clk_cfg;	/* 0x4d4 AVS module clock */
76*4882a593Smuzhiyun 	u8 reserved13[0x18];	/* 0x4d8 */
77*4882a593Smuzhiyun 	u32 gpu_core_clk_cfg;	/* 0x4f0 GPU core clock config */
78*4882a593Smuzhiyun 	u32 gpu_mem_clk_cfg;	/* 0x4f4 GPU memory clock config */
79*4882a593Smuzhiyun 	u32 gpu_axi_clk_cfg;	/* 0x4f8 GPU AXI clock config */
80*4882a593Smuzhiyun 	u8 reserved14[0x10];	/* 0x4fc */
81*4882a593Smuzhiyun 	u32 gp_adc_clk_cfg;	/* 0x50c General Purpose ADC clk config */
82*4882a593Smuzhiyun 	u8 reserved15[0x70];	/* 0x510 */
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	u32 ahb_gate0;		/* 0x580 AHB0 Gating Register */
85*4882a593Smuzhiyun 	u32 ahb_gate1;		/* 0x584 AHB1 Gating Register */
86*4882a593Smuzhiyun 	u32 ahb_gate2;		/* 0x588 AHB2 Gating Register */
87*4882a593Smuzhiyun 	u8 reserved16[0x04];	/* 0x58c */
88*4882a593Smuzhiyun 	u32 apb0_gate;		/* 0x590 APB0 Clock Gating Register */
89*4882a593Smuzhiyun 	u32 apb1_gate;		/* 0x594 APB1 Clock Gating Register */
90*4882a593Smuzhiyun 	u8 reserved17[0x08];	/* 0x598 */
91*4882a593Smuzhiyun 	u32 ahb_reset0_cfg;	/* 0x5a0 AHB0 Software Reset Register */
92*4882a593Smuzhiyun 	u32 ahb_reset1_cfg;	/* 0x5a4 AHB1 Software Reset Register */
93*4882a593Smuzhiyun 	u32 ahb_reset2_cfg;	/* 0x5a8 AHB2 Software Reset Register */
94*4882a593Smuzhiyun 	u8 reserved18[0x04];	/* 0x5ac */
95*4882a593Smuzhiyun 	u32 apb0_reset_cfg;	/* 0x5b0 Bus Software Reset Register 3 */
96*4882a593Smuzhiyun 	u32 apb1_reset_cfg;	/* 0x5b4 Bus Software Reset Register 4 */
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun #define CCM_PLL4_CTRL_N_SHIFT		8
100*4882a593Smuzhiyun #define CCM_PLL4_CTRL_N_MASK		(0xff << CCM_PLL4_CTRL_N_SHIFT)
101*4882a593Smuzhiyun #define CCM_PLL4_CTRL_P_SHIFT		16
102*4882a593Smuzhiyun #define CCM_PLL4_CTRL_P_MASK		(0x1 << CCM_PLL4_CTRL_P_SHIFT)
103*4882a593Smuzhiyun #define CCM_PLL4_CTRL_M_SHIFT		18
104*4882a593Smuzhiyun #define CCM_PLL4_CTRL_M_MASK		(0x1 << CCM_PLL4_CTRL_M_SHIFT)
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* pllx_cfg bits */
107*4882a593Smuzhiyun #define CCM_PLL1_CTRL_N(n)		(((n) & 0xff) << 8)
108*4882a593Smuzhiyun #define CCM_PLL1_CTRL_P(n)		(((n) & 0x1) << 16)
109*4882a593Smuzhiyun #define CCM_PLL1_CTRL_EN		(1 << 31)
110*4882a593Smuzhiyun #define CCM_PLL1_CLOCK_TIME_2		(2 << 24)
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #define CCM_PLL2_CTRL_N(n)		(((n) & 0xff) << 8)
113*4882a593Smuzhiyun #define CCM_PLL2_CTRL_P(n)		(((n) & 0x1) << 16)
114*4882a593Smuzhiyun #define CCM_PLL2_CTRL_EN		(1 << 31)
115*4882a593Smuzhiyun #define CCM_PLL2_CLOCK_TIME_2		(2 << 24)
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define CCM_PLL4_CTRL_N(n)		(((n) & 0xff) << 8)
118*4882a593Smuzhiyun #define CCM_PLL4_CTRL_EN		(1 << 31)
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun #define CCM_PLL6_CTRL_N(n)		(((n) & 0xff) << 8)
121*4882a593Smuzhiyun #define CCM_PLL6_CTRL_P(p)		(((p) & 0x1) << 16)
122*4882a593Smuzhiyun #define CCM_PLL6_CTRL_EN		(1 << 31)
123*4882a593Smuzhiyun #define CCM_PLL6_CFG_UPDATE             (1 << 30)
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun #define CCM_PLL12_CTRL_N(n)		(((n) & 0xff) << 8)
126*4882a593Smuzhiyun #define CCM_PLL12_CTRL_EN		(1 << 31)
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #define PLL_C0CPUX_STATUS               (1 << 0)
129*4882a593Smuzhiyun #define PLL_C1CPUX_STATUS               (1 << 1)
130*4882a593Smuzhiyun #define PLL_DDR_STATUS                  (1 << 5)
131*4882a593Smuzhiyun #define PLL_PERIPH1_STATUS              (1 << 11)
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* cpu_clk_source bits */
134*4882a593Smuzhiyun #define C0_CPUX_CLK_SRC_SHIFT           0
135*4882a593Smuzhiyun #define C1_CPUX_CLK_SRC_SHIFT           8
136*4882a593Smuzhiyun #define C0_CPUX_CLK_SRC_MASK            (1 << C0_CPUX_CLK_SRC_SHIFT)
137*4882a593Smuzhiyun #define C1_CPUX_CLK_SRC_MASK            (1 << C1_CPUX_CLK_SRC_SHIFT)
138*4882a593Smuzhiyun #define C0_CPUX_CLK_SRC_OSC24M		(0 << C0_CPUX_CLK_SRC_SHIFT)
139*4882a593Smuzhiyun #define C0_CPUX_CLK_SRC_PLL1		(1 << C0_CPUX_CLK_SRC_SHIFT)
140*4882a593Smuzhiyun #define C1_CPUX_CLK_SRC_OSC24M		(0 << C1_CPUX_CLK_SRC_SHIFT)
141*4882a593Smuzhiyun #define C1_CPUX_CLK_SRC_PLL2		(1 << C1_CPUX_CLK_SRC_SHIFT)
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun /* c0_cfg */
144*4882a593Smuzhiyun #define C0_CFG_AXI0_CLK_DIV_RATIO(n)    (((n - 1) & 0x3) << 0)
145*4882a593Smuzhiyun #define C0_CFG_APB0_CLK_DIV_RATIO(n)    (((n - 1) & 0x3) << 8)
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun /* ahbx_cfg */
148*4882a593Smuzhiyun #define AHBx_SRC_CLK_SELECT_SHIFT       24
149*4882a593Smuzhiyun #define AHBx_SRC_MASK                   (0x3 << AHBx_SRC_CLK_SELECT_SHIFT)
150*4882a593Smuzhiyun #define AHB0_SRC_GTBUS_CLK              (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
151*4882a593Smuzhiyun #define AHB1_SRC_GTBUS_CLK              (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
152*4882a593Smuzhiyun #define AHB2_SRC_OSC24M                 (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
153*4882a593Smuzhiyun #define AHBx_SRC_PLL_PERIPH0            (0x1 << AHBx_SRC_CLK_SELECT_SHIFT)
154*4882a593Smuzhiyun #define AHBx_SRC_PLL_PERIPH1            (0x2 << AHBx_SRC_CLK_SELECT_SHIFT)
155*4882a593Smuzhiyun #define AHBx_CLK_DIV_RATIO(n)           (((ffs(n) - 1) & 0x3) << 0)
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /* apb0_cfg */
158*4882a593Smuzhiyun #define APB0_SRC_CLK_SELECT_SHIFT       24
159*4882a593Smuzhiyun #define APB0_SRC_MASK                   (0x1 << APB0_SRC_CLK_SELECT_SHIFT)
160*4882a593Smuzhiyun #define APB0_SRC_OSC24M                 (0x0 << APB0_SRC_CLK_SELECT_SHIFT)
161*4882a593Smuzhiyun #define APB0_SRC_PLL_PERIPH0            (0x1 << APB0_SRC_CLK_SELECT_SHIFT)
162*4882a593Smuzhiyun #define APB0_CLK_DIV_RATIO(n)           (((ffs(n) - 1) & 0x3) << 0)
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /* gtbus_clk_cfg */
165*4882a593Smuzhiyun #define GTBUS_SRC_CLK_SELECT_SHIFT      24
166*4882a593Smuzhiyun #define GTBUS_SRC_MASK                  (0x3 << GTBUS_SRC_CLK_SELECT_SHIFT)
167*4882a593Smuzhiyun #define GTBUS_SRC_OSC24M                (0x0 << GTBUS_SRC_CLK_SELECT_SHIFT)
168*4882a593Smuzhiyun #define GTBUS_SRC_PLL_PERIPH0           (0x1 << GTBUS_SRC_CLK_SELECT_SHIFT)
169*4882a593Smuzhiyun #define GTBUS_SRC_PLL_PERIPH1           (0x2 << GTBUS_SRC_CLK_SELECT_SHIFT)
170*4882a593Smuzhiyun #define GTBUS_CLK_DIV_RATIO(n)          (((n - 1) & 0x3) << 0)
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun /* cci400_clk_cfg */
173*4882a593Smuzhiyun #define CCI400_SRC_CLK_SELECT_SHIFT     24
174*4882a593Smuzhiyun #define CCI400_SRC_MASK                 (0x3 << CCI400_SRC_CLK_SELECT_SHIFT)
175*4882a593Smuzhiyun #define CCI400_SRC_OSC24M               (0x0 << CCI400_SRC_CLK_SELECT_SHIFT)
176*4882a593Smuzhiyun #define CCI400_SRC_PLL_PERIPH0          (0x1 << CCI400_SRC_CLK_SELECT_SHIFT)
177*4882a593Smuzhiyun #define CCI400_SRC_PLL_PERIPH1          (0x2 << CCI400_SRC_CLK_SELECT_SHIFT)
178*4882a593Smuzhiyun #define CCI400_CLK_DIV_RATIO(n)         (((n - 1) & 0x3) << 0)
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun /* sd#_clk_cfg fields */
181*4882a593Smuzhiyun #define CCM_MMC_CTRL_M(x)		((x) - 1)
182*4882a593Smuzhiyun #define CCM_MMC_CTRL_OCLK_DLY(x)	((x) << 8)
183*4882a593Smuzhiyun #define CCM_MMC_CTRL_N(x)		((x) << 16)
184*4882a593Smuzhiyun #define CCM_MMC_CTRL_SCLK_DLY(x)	((x) << 20)
185*4882a593Smuzhiyun #define CCM_MMC_CTRL_OSCM24		(0 << 24)
186*4882a593Smuzhiyun #define CCM_MMC_CTRL_PLL_PERIPH0	(1 << 24)
187*4882a593Smuzhiyun #define CCM_MMC_CTRL_ENABLE		(1 << 31)
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /* ahb_gate0 fields */
190*4882a593Smuzhiyun #define AHB_GATE_OFFSET_MCTL		14
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /* On sun9i all sdc-s share their ahb gate, so ignore (x) */
193*4882a593Smuzhiyun #define AHB_GATE_OFFSET_NAND0		13
194*4882a593Smuzhiyun #define AHB_GATE_OFFSET_MMC(x)		8
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun /* ahb gate1 field */
197*4882a593Smuzhiyun #define AHB_GATE_OFFSET_DMA		24
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun /* apb1_gate fields */
200*4882a593Smuzhiyun #define APB1_GATE_UART_SHIFT		16
201*4882a593Smuzhiyun #define APB1_GATE_UART_MASK		(0xff << APB1_GATE_UART_SHIFT)
202*4882a593Smuzhiyun #define APB1_GATE_TWI_SHIFT		0
203*4882a593Smuzhiyun #define APB1_GATE_TWI_MASK		(0xf << APB1_GATE_TWI_SHIFT)
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun /* ahb_reset0_cfg fields */
206*4882a593Smuzhiyun #define AHB_RESET_OFFSET_MCTL		14
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun /* On sun9i all sdc-s share their ahb reset, so ignore (x) */
209*4882a593Smuzhiyun #define AHB_RESET_OFFSET_MMC(x)		8
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun /* apb1_reset_cfg fields */
212*4882a593Smuzhiyun #define APB1_RESET_UART_SHIFT		16
213*4882a593Smuzhiyun #define APB1_RESET_UART_MASK		(0xff << APB1_RESET_UART_SHIFT)
214*4882a593Smuzhiyun #define APB1_RESET_TWI_SHIFT		0
215*4882a593Smuzhiyun #define APB1_RESET_TWI_MASK		(0xf << APB1_RESET_TWI_SHIFT)
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun #ifndef __ASSEMBLY__
219*4882a593Smuzhiyun void clock_set_pll1(unsigned int clk);
220*4882a593Smuzhiyun void clock_set_pll2(unsigned int clk);
221*4882a593Smuzhiyun void clock_set_pll4(unsigned int clk);
222*4882a593Smuzhiyun void clock_set_pll6(unsigned int clk);
223*4882a593Smuzhiyun void clock_set_pll12(unsigned int clk);
224*4882a593Smuzhiyun unsigned int clock_get_pll4_periph0(void);
225*4882a593Smuzhiyun #endif
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun #endif /* _SUNXI_CLOCK_SUN9I_H */
228