1 /*
2  * Sunxi A31 Power Management Unit register definition.
3  *
4  * (C) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl>
5  * http://linux-sunxi.org
6  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
7  * Berg Xing <bergxing@allwinnertech.com>
8  * Tom Cubie <tangliang@allwinnertech.com>
9  *
10  * SPDX-License-Identifier:	GPL-2.0+
11  */
12 
13 #ifndef _SUNXI_PRCM_H
14 #define _SUNXI_PRCM_H
15 
16 #define __PRCM_CPUS_CFG_PRE(n) (((n) & 0x3) << 4)
17 #define PRCM_CPUS_CFG_PRE_MASK __PRCM_CPUS_CFG_PRE(0x3)
18 #define __PRCM_CPUS_CFG_PRE_DIV(n) (((n) >> 1) - 1)
19 #define PRCM_CPUS_CFG_PRE_DIV(n) \
20 	__PRCM_CPUS_CFG_PRE(__PRCM_CPUS_CFG_CLK_PRE(n))
21 #define __PRCM_CPUS_CFG_POST(n) (((n) & 0x1f) << 8)
22 #define PRCM_CPUS_CFG_POST_MASK __PRCM_CPUS_CFG_POST(0x1f)
23 #define __PRCM_CPUS_CFG_POST_DIV(n) ((n) - 1)
24 #define PRCM_CPUS_CFG_POST_DIV(n) \
25 	__PRCM_CPUS_CFG_POST_DIV(__PRCM_CPUS_CFG_POST_DIV(n))
26 #define __PRCM_CPUS_CFG_CLK_SRC(n) (((n) & 0x3) << 16)
27 #define PRCM_CPUS_CFG_CLK_SRC_MASK __PRCM_CPUS_CFG_CLK_SRC(0x3)
28 #define __PRCM_CPUS_CFG_CLK_SRC_LOSC 0x0
29 #define __PRCM_CPUS_CFG_CLK_SRC_HOSC 0x1
30 #define __PRCM_CPUS_CFG_CLK_SRC_PLL6 0x2
31 #define __PRCM_CPUS_CFG_CLK_SRC_PDIV 0x3
32 #define PRCM_CPUS_CFG_CLK_SRC_LOSC \
33 	__PRCM_CPUS_CFG_CLK_SRC(__PRCM_CPUS_CFG_CLK_SRC_LOSC)
34 #define PRCM_CPUS_CFG_CLK_SRC_HOSC \
35 	__PRCM_CPUS_CFG_CLK_SRC(__PRCM_CPUS_CFG_CLK_SRC_HOSC)
36 #define PRCM_CPUS_CFG_CLK_SRC_PLL6 \
37 	__PRCM_CPUS_CFG_CLK_SRC(__PRCM_CPUS_CFG_CLK_SRC_PLL6)
38 #define PRCM_CPUS_CFG_CLK_SRC_PDIV \
39 	__PRCM_CPUS_CFG_CLK_SRC(__PRCM_CPUS_CFG_CLK_SRC_PDIV)
40 
41 #define __PRCM_APB0_RATIO(n) (((n) & 0x3) << 0)
42 #define PRCM_APB0_RATIO_DIV_MASK __PRCM_APB0_RATIO_DIV(0x3)
43 #define __PRCM_APB0_RATIO_DIV(n) (((n) >> 1) - 1)
44 #define PRCM_APB0_RATIO_DIV(n) \
45 	__PRCM_APB0_RATIO(__PRCM_APB0_RATIO_DIV(n))
46 
47 #define PRCM_CPU_CFG_NEON_CLK_EN (0x1 << 0)
48 #define PRCM_CPU_CFG_CPU_CLK_EN (0x1 << 1)
49 
50 #define PRCM_APB0_GATE_PIO (0x1 << 0)
51 #define PRCM_APB0_GATE_IR (0x1 << 1)
52 #define PRCM_APB0_GATE_TIMER01 (0x1 << 2)
53 #define PRCM_APB0_GATE_P2WI (0x1 << 3)
54 #define PRCM_APB0_GATE_UART (0x1 << 4)
55 #define PRCM_APB0_GATE_1WIRE (0x1 << 5)
56 #define PRCM_APB0_GATE_I2C (0x1 << 6)
57 
58 #define PRCM_APB0_RESET_PIO (0x1 << 0)
59 #define PRCM_APB0_RESET_IR (0x1 << 1)
60 #define PRCM_APB0_RESET_TIMER01 (0x1 << 2)
61 #define PRCM_APB0_RESET_P2WI (0x1 << 3)
62 #define PRCM_APB0_RESET_UART (0x1 << 4)
63 #define PRCM_APB0_RESET_1WIRE (0x1 << 5)
64 #define PRCM_APB0_RESET_I2C (0x1 << 6)
65 
66 #define PRCM_PLL_CTRL_PLL_BIAS (0x1 << 0)
67 #define PRCM_PLL_CTRL_HOSC_GAIN_ENH (0x1 << 1)
68 #define __PRCM_PLL_CTRL_USB_CLK_SRC(n) (((n) & 0x3) << 4)
69 #define PRCM_PLL_CTRL_USB_CLK_SRC_MASK \
70 	__PRCM_PLL_CTRL_USB_CLK_SRC(0x3)
71 #define __PRCM_PLL_CTRL_USB_CLK_0 0x0
72 #define __PRCM_PLL_CTRL_USB_CLK_1 0x1
73 #define __PRCM_PLL_CTRL_USB_CLK_2 0x2
74 #define __PRCM_PLL_CTRL_USB_CLK_3 0x3
75 #define PRCM_PLL_CTRL_USB_CLK_0 \
76 	__PRCM_PLL_CTRL_USB_CLK_SRC(__PRCM_PLL_CTRL_USB_CLK_0)
77 #define PRCM_PLL_CTRL_USB_CLK_1 \
78 	__PRCM_PLL_CTRL_USB_CLK_SRC(__PRCM_PLL_CTRL_USB_CLK_1)
79 #define PRCM_PLL_CTRL_USB_CLK_2 \
80 	__PRCM_PLL_CTRL_USB_CLK_SRC(__PRCM_PLL_CTRL_USB_CLK_2)
81 #define PRCM_PLL_CTRL_USB_CLK_3 \
82 	__PRCM_PLL_CTRL_USB_CLK_SRC(__PRCM_PLL_CTRL_USB_CLK_3)
83 #define __PRCM_PLL_CTRL_INT_PLL_IN_SEL(n) (((n) & 0x3) << 12)
84 #define PRCM_PLL_CTRL_INT_PLL_IN_SEL_MASK \
85 	__PRCM_PLL_CTRL_INT_PLL_IN_SEL(0x3)
86 #define PRCM_PLL_CTRL_INT_PLL_IN_SEL(n) \
87 	__PRCM_PLL_CTRL_INT_PLL_IN_SEL(n)
88 #define __PRCM_PLL_CTRL_HOSC_CLK_SEL(n) (((n) & 0x3) << 20)
89 #define PRCM_PLL_CTRL_HOSC_CLK_SEL_MASK \
90 	__PRCM_PLL_CTRL_HOSC_CLK_SEL(0x3)
91 #define __PRCM_PLL_CTRL_HOSC_CLK_0 0x0
92 #define __PRCM_PLL_CTRL_HOSC_CLK_1 0x1
93 #define __PRCM_PLL_CTRL_HOSC_CLK_2 0x2
94 #define __PRCM_PLL_CTRL_HOSC_CLK_3 0x3
95 #define PRCM_PLL_CTRL_HOSC_CLK_0 \
96 	__PRCM_PLL_CTRL_HOSC_CLK_SEL(__PRCM_PLL_CTRL_HOSC_CLK_0)
97 #define PRCM_PLL_CTRL_HOSC_CLK_1 \
98 	__PRCM_PLL_CTRL_HOSC_CLK_SEL(__PRCM_PLL_CTRL_HOSC_CLK_1)
99 #define PRCM_PLL_CTRL_HOSC_CLK_2 \
100 	__PRCM_PLL_CTRL_HOSC_CLK_SEL(__PRCM_PLL_CTRL_HOSC_CLK_2)
101 #define PRCM_PLL_CTRL_HOSC_CLK_3 \
102 	__PRCM_PLL_CTRL_HOSC_CLK_SEL(__PRCM_PLL_CTRL_HOSC_CLK_3)
103 #define PRCM_PLL_CTRL_PLL_TST_SRC_EXT (0x1 << 24)
104 #define PRCM_PLL_CTRL_LDO_DIGITAL_EN (0x1 << 0)
105 #define PRCM_PLL_CTRL_LDO_ANALOG_EN (0x1 << 1)
106 #define PRCM_PLL_CTRL_EXT_OSC_EN (0x1 << 2)
107 #define PRCM_PLL_CTRL_CLK_TST_EN (0x1 << 3)
108 #define PRCM_PLL_CTRL_IN_PWR_HIGH (0x1 << 15) /* 3.3 for hi 2.5 for lo */
109 #define __PRCM_PLL_CTRL_VDD_LDO_OUT(n) (((n) & 0x7) << 16)
110 #define PRCM_PLL_CTRL_LDO_OUT_MASK \
111 	__PRCM_PLL_CTRL_LDO_OUT(0x7)
112 /* When using the low voltage 20 mV steps, and high voltage 30 mV steps */
113 #define PRCM_PLL_CTRL_LDO_OUT_L(n) \
114 	__PRCM_PLL_CTRL_VDD_LDO_OUT((((n) - 1000) / 20) & 0x7)
115 #define PRCM_PLL_CTRL_LDO_OUT_H(n) \
116 	__PRCM_PLL_CTRL_VDD_LDO_OUT((((n) - 1160) / 30) & 0x7)
117 #define PRCM_PLL_CTRL_LDO_OUT_LV(n) \
118 	__PRCM_PLL_CTRL_VDD_LDO_OUT((((n) & 0x7) * 20) + 1000)
119 #define PRCM_PLL_CTRL_LDO_OUT_HV(n) \
120 	__PRCM_PLL_CTRL_VDD_LDO_OUT((((n) & 0x7) * 30) + 1160)
121 #define PRCM_PLL_CTRL_LDO_KEY (0xa7 << 24)
122 #define PRCM_PLL_CTRL_LDO_KEY_MASK (0xff << 24)
123 
124 #define PRCM_CLK_1WIRE_GATE (0x1 << 31)
125 
126 #define __PRCM_CLK_MOD0_M(n) (((n) & 0xf) << 0)
127 #define PRCM_CLK_MOD0_M_MASK __PRCM_CLK_MOD0_M(0xf)
128 #define __PRCM_CLK_MOD0_M_X(n) (n - 1)
129 #define PRCM_CLK_MOD0_M(n) __PRCM_CLK_MOD0_M(__PRCM_CLK_MOD0_M_X(n))
130 #define PRCM_CLK_MOD0_OUT_PHASE(n) (((n) & 0x7) << 8)
131 #define PRCM_CLK_MOD0_OUT_PHASE_MASK(n) PRCM_CLK_MOD0_OUT_PHASE(0x7)
132 #define _PRCM_CLK_MOD0_N(n) (((n) & 0x3) << 16)
133 #define PRCM_CLK_MOD0_N_MASK __PRCM_CLK_MOD_N(0x3)
134 #define __PRCM_CLK_MOD0_N_X(n) (((n) >> 1) - 1)
135 #define PRCM_CLK_MOD0_N(n) __PRCM_CLK_MOD0_N(__PRCM_CLK_MOD0_N_X(n))
136 #define PRCM_CLK_MOD0_SMPL_PHASE(n) (((n) & 0x7) << 20)
137 #define PRCM_CLK_MOD0_SMPL_PHASE_MASK PRCM_CLK_MOD0_SMPL_PHASE(0x7)
138 #define PRCM_CLK_MOD0_SRC_SEL(n) (((n) & 0x7) << 24)
139 #define PRCM_CLK_MOD0_SRC_SEL_MASK PRCM_CLK_MOD0_SRC_SEL(0x7)
140 #define PRCM_CLK_MOD0_GATE_EN (0x1 << 31)
141 
142 #define PRCM_APB0_RESET_PIO (0x1 << 0)
143 #define PRCM_APB0_RESET_IR (0x1 << 1)
144 #define PRCM_APB0_RESET_TIMER01 (0x1 << 2)
145 #define PRCM_APB0_RESET_P2WI (0x1 << 3)
146 #define PRCM_APB0_RESET_UART (0x1 << 4)
147 #define PRCM_APB0_RESET_1WIRE (0x1 << 5)
148 #define PRCM_APB0_RESET_I2C (0x1 << 6)
149 
150 #define __PRCM_CLK_OUTD_M(n) (((n) & 0x7) << 8)
151 #define PRCM_CLK_OUTD_M_MASK __PRCM_CLK_OUTD_M(0x7)
152 #define __PRCM_CLK_OUTD_M_X() ((n) - 1)
153 #define PRCM_CLK_OUTD_M(n) __PRCM_CLK_OUTD_M(__PRCM_CLK_OUTD_M_X(n))
154 #define __PRCM_CLK_OUTD_N(n) (((n) & 0x7) << 20)
155 #define PRCM_CLK_OUTD_N_MASK __PRCM_CLK_OUTD_N(0x7)
156 #define __PRCM_CLK_OUTD_N_X(n) (((n) >> 1) - 1)
157 #define PRCM_CLK_OUTD_N(n) __PRCM_CLK_OUTD_N(__PRCM_CLK_OUTD_N_X(n)
158 #define __PRCM_CLK_OUTD_SRC_SEL(n) (((n) & 0x3) << 24)
159 #define PRCM_CLK_OUTD_SRC_SEL_MASK __PRCM_CLK_OUTD_SRC_SEL(0x3)
160 #define __PRCM_CLK_OUTD_SRC_LOSC2 0x0
161 #define __PRCM_CLK_OUTD_SRC_LOSC 0x1
162 #define __PRCM_CLK_OUTD_SRC_HOSC 0x2
163 #define __PRCM_CLK_OUTD_SRC_ERR 0x3
164 #define PRCM_CLK_OUTD_SRC_LOSC2 \
165 #deifne __PRCM_CLK_OUTD_SRC_SEL(__PRCM_CLK_OUTD_SRC_LOSC2)
166 #define PRCM_CLK_OUTD_SRC_LOSC \
167 #deifne __PRCM_CLK_OUTD_SRC_SEL(__PRCM_CLK_OUTD_SRC_LOSC)
168 #define PRCM_CLK_OUTD_SRC_HOSC \
169 #deifne __PRCM_CLK_OUTD_SRC_SEL(__PRCM_CLK_OUTD_SRC_HOSC)
170 #define PRCM_CLK_OUTD_SRC_ERR \
171 #deifne __PRCM_CLK_OUTD_SRC_SEL(__PRCM_CLK_OUTD_SRC_ERR)
172 #define PRCM_CLK_OUTD_EN (0x1 << 31)
173 
174 #define PRCM_CPU0_PWROFF (0x1 << 0)
175 #define PRCM_CPU1_PWROFF (0x1 << 1)
176 #define PRCM_CPU2_PWROFF (0x1 << 2)
177 #define PRCM_CPU3_PWROFF (0x1 << 3)
178 #define PRCM_CPU_ALL_PWROFF (0xf << 0)
179 
180 #define PRCM_VDD_SYS_DRAM_CH0_PAD_HOLD_PWROFF (0x1 << 0)
181 #define PRCM_VDD_SYS_DRAM_CH1_PAD_HOLD_PWROFF (0x1 << 1)
182 #define PRCM_VDD_SYS_AVCC_A_PWROFF (0x1 << 2)
183 #define PRCM_VDD_SYS_CPU0_VDD_PWROFF (0x1 << 3)
184 
185 #define PRCM_VDD_GPU_PWROFF (0x1 << 0)
186 
187 #define PRCM_VDD_SYS_RESET (0x1 << 0)
188 
189 #define PRCM_CPU1_PWR_CLAMP(n) (((n) & 0xff) << 0)
190 #define PRCM_CPU1_PWR_CLAMP_MASK PRCM_CPU1_PWR_CLAMP(0xff)
191 
192 #define PRCM_CPU2_PWR_CLAMP(n) (((n) & 0xff) << 0)
193 #define PRCM_CPU2_PWR_CLAMP_MASK PRCM_CPU2_PWR_CLAMP(0xff)
194 
195 #define PRCM_CPU3_PWR_CLAMP(n) (((n) & 0xff) << 0)
196 #define PRCM_CPU3_PWR_CLAMP_MASK PRCM_CPU3_PWR_CLAMP(0xff)
197 
198 #ifndef __ASSEMBLY__
199 struct sunxi_prcm_reg {
200 	u32 cpus_cfg;		/* 0x000 */
201 	u8 res0[0x8];		/* 0x004 */
202 	u32 apb0_ratio;		/* 0x00c */
203 	u32 cpu0_cfg;		/* 0x010 */
204 	u32 cpu1_cfg;		/* 0x014 */
205 	u32 cpu2_cfg;		/* 0x018 */
206 	u32 cpu3_cfg;		/* 0x01c */
207 	u8 res1[0x8];		/* 0x020 */
208 	u32 apb0_gate;		/* 0x028 */
209 	u8 res2[0x14];		/* 0x02c */
210 	u32 pll_ctrl0;		/* 0x040 */
211 	u32 pll_ctrl1;		/* 0x044 */
212 	u8 res3[0x8];		/* 0x048 */
213 	u32 clk_1wire;		/* 0x050 */
214 	u32 clk_ir;		/* 0x054 */
215 	u8 res4[0x58];		/* 0x058 */
216 	u32 apb0_reset;		/* 0x0b0 */
217 	u8 res5[0x3c];		/* 0x0b4 */
218 	u32 clk_outd;		/* 0x0f0 */
219 	u8 res6[0xc];		/* 0x0f4 */
220 	u32 cpu_pwroff;		/* 0x100 */
221 	u8 res7[0xc];		/* 0x104 */
222 	u32 vdd_sys_pwroff;	/* 0x110 */
223 	u8 res8[0x4];		/* 0x114 */
224 	u32 gpu_pwroff;		/* 0x118 */
225 	u8 res9[0x4];		/* 0x11c */
226 	u32 vdd_pwr_reset;	/* 0x120 */
227 	u8 res10[0x20];		/* 0x124 */
228 	u32 cpu1_pwr_clamp;	/* 0x144 */
229 	u32 cpu2_pwr_clamp;	/* 0x148 */
230 	u32 cpu3_pwr_clamp;	/* 0x14c */
231 	u8 res11[0x30];		/* 0x150 */
232 	u32 dram_pwr;		/* 0x180 */
233 	u8 res12[0xc];		/* 0x184 */
234 	u32 dram_tst;		/* 0x190 */
235 };
236 
237 void prcm_apb0_enable(u32 flags);
238 #endif /* __ASSEMBLY__ */
239 #endif /* _PRCM_H */
240