2 * pxa168 clock framework source file
4 * Copyright (C) 2012 Marvell
5 * Chao Xie <xiechao.mail@gmail.com>
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/clk.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/spinlock.h>
17 #include <linux/delay.h>
18 #include <linux/err.h>
23 #define APBC_TWSI0 0x2c
25 #define APBC_UART0 0x0
26 #define APBC_UART1 0x4
29 #define APBC_PWM1 0x10
30 #define APBC_PWM2 0x14
31 #define APBC_PWM3 0x18
32 #define APBC_SSP0 0x81c
33 #define APBC_SSP1 0x820
34 #define APBC_SSP2 0x84c
35 #define APBC_SSP3 0x858
36 #define APBC_SSP4 0x85c
37 #define APBC_TWSI1 0x6c
38 #define APBC_UART2 0x70
39 #define APMU_SDH0 0x54
40 #define APMU_SDH1 0x58
42 #define APMU_DISP0 0x4c
43 #define APMU_CCIC0 0x50
45 #define MPMU_UART_PLL 0x14
47 static DEFINE_SPINLOCK(clk_lock
);
49 static struct mmp_clk_factor_masks uart_factor_masks
= {
57 static struct mmp_clk_factor_tbl uart_factor_tbl
[] = {
58 {.num
= 8125, .den
= 1536}, /*14.745MHZ */
61 static const char *uart_parent
[] = {"pll1_3_16", "uart_pll"};
62 static const char *ssp_parent
[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
63 static const char *sdh_parent
[] = {"pll1_12", "pll1_13"};
64 static const char *disp_parent
[] = {"pll1_2", "pll1_12"};
65 static const char *ccic_parent
[] = {"pll1_2", "pll1_12"};
66 static const char *ccic_phy_parent
[] = {"pll1_6", "pll1_12"};
68 void __init
pxa168_clk_init(phys_addr_t mpmu_phys
, phys_addr_t apmu_phys
,
69 phys_addr_t apbc_phys
)
73 void __iomem
*mpmu_base
;
74 void __iomem
*apmu_base
;
75 void __iomem
*apbc_base
;
77 mpmu_base
= ioremap(mpmu_phys
, SZ_4K
);
78 if (mpmu_base
== NULL
) {
79 pr_err("error to ioremap MPMU base\n");
83 apmu_base
= ioremap(apmu_phys
, SZ_4K
);
84 if (apmu_base
== NULL
) {
85 pr_err("error to ioremap APMU base\n");
89 apbc_base
= ioremap(apbc_phys
, SZ_4K
);
90 if (apbc_base
== NULL
) {
91 pr_err("error to ioremap APBC base\n");
95 clk
= clk_register_fixed_rate(NULL
, "clk32", NULL
, 0, 3200);
96 clk_register_clkdev(clk
, "clk32", NULL
);
98 clk
= clk_register_fixed_rate(NULL
, "vctcxo", NULL
, 0, 26000000);
99 clk_register_clkdev(clk
, "vctcxo", NULL
);
101 clk
= clk_register_fixed_rate(NULL
, "pll1", NULL
, 0, 624000000);
102 clk_register_clkdev(clk
, "pll1", NULL
);
104 clk
= clk_register_fixed_factor(NULL
, "pll1_2", "pll1",
105 CLK_SET_RATE_PARENT
, 1, 2);
106 clk_register_clkdev(clk
, "pll1_2", NULL
);
108 clk
= clk_register_fixed_factor(NULL
, "pll1_4", "pll1_2",
109 CLK_SET_RATE_PARENT
, 1, 2);
110 clk_register_clkdev(clk
, "pll1_4", NULL
);
112 clk
= clk_register_fixed_factor(NULL
, "pll1_8", "pll1_4",
113 CLK_SET_RATE_PARENT
, 1, 2);
114 clk_register_clkdev(clk
, "pll1_8", NULL
);
116 clk
= clk_register_fixed_factor(NULL
, "pll1_16", "pll1_8",
117 CLK_SET_RATE_PARENT
, 1, 2);
118 clk_register_clkdev(clk
, "pll1_16", NULL
);
120 clk
= clk_register_fixed_factor(NULL
, "pll1_6", "pll1_2",
121 CLK_SET_RATE_PARENT
, 1, 3);
122 clk_register_clkdev(clk
, "pll1_6", NULL
);
124 clk
= clk_register_fixed_factor(NULL
, "pll1_12", "pll1_6",
125 CLK_SET_RATE_PARENT
, 1, 2);
126 clk_register_clkdev(clk
, "pll1_12", NULL
);
128 clk
= clk_register_fixed_factor(NULL
, "pll1_24", "pll1_12",
129 CLK_SET_RATE_PARENT
, 1, 2);
130 clk_register_clkdev(clk
, "pll1_24", NULL
);
132 clk
= clk_register_fixed_factor(NULL
, "pll1_48", "pll1_24",
133 CLK_SET_RATE_PARENT
, 1, 2);
134 clk_register_clkdev(clk
, "pll1_48", NULL
);
136 clk
= clk_register_fixed_factor(NULL
, "pll1_96", "pll1_48",
137 CLK_SET_RATE_PARENT
, 1, 2);
138 clk_register_clkdev(clk
, "pll1_96", NULL
);
140 clk
= clk_register_fixed_factor(NULL
, "pll1_13", "pll1",
141 CLK_SET_RATE_PARENT
, 1, 13);
142 clk_register_clkdev(clk
, "pll1_13", NULL
);
144 clk
= clk_register_fixed_factor(NULL
, "pll1_13_1_5", "pll1",
145 CLK_SET_RATE_PARENT
, 2, 3);
146 clk_register_clkdev(clk
, "pll1_13_1_5", NULL
);
148 clk
= clk_register_fixed_factor(NULL
, "pll1_2_1_5", "pll1",
149 CLK_SET_RATE_PARENT
, 2, 3);
150 clk_register_clkdev(clk
, "pll1_2_1_5", NULL
);
152 clk
= clk_register_fixed_factor(NULL
, "pll1_3_16", "pll1",
153 CLK_SET_RATE_PARENT
, 3, 16);
154 clk_register_clkdev(clk
, "pll1_3_16", NULL
);
156 uart_pll
= mmp_clk_register_factor("uart_pll", "pll1_4", 0,
157 mpmu_base
+ MPMU_UART_PLL
,
158 &uart_factor_masks
, uart_factor_tbl
,
159 ARRAY_SIZE(uart_factor_tbl
), &clk_lock
);
160 clk_set_rate(uart_pll
, 14745600);
161 clk_register_clkdev(uart_pll
, "uart_pll", NULL
);
163 clk
= mmp_clk_register_apbc("twsi0", "pll1_13_1_5",
164 apbc_base
+ APBC_TWSI0
, 10, 0, &clk_lock
);
165 clk_register_clkdev(clk
, NULL
, "pxa2xx-i2c.0");
167 clk
= mmp_clk_register_apbc("twsi1", "pll1_13_1_5",
168 apbc_base
+ APBC_TWSI1
, 10, 0, &clk_lock
);
169 clk_register_clkdev(clk
, NULL
, "pxa2xx-i2c.1");
171 clk
= mmp_clk_register_apbc("gpio", "vctcxo",
172 apbc_base
+ APBC_GPIO
, 10, 0, &clk_lock
);
173 clk_register_clkdev(clk
, NULL
, "mmp-gpio");
175 clk
= mmp_clk_register_apbc("kpc", "clk32",
176 apbc_base
+ APBC_KPC
, 10, 0, &clk_lock
);
177 clk_register_clkdev(clk
, NULL
, "pxa27x-keypad");
179 clk
= mmp_clk_register_apbc("rtc", "clk32",
180 apbc_base
+ APBC_RTC
, 10, 0, &clk_lock
);
181 clk_register_clkdev(clk
, NULL
, "sa1100-rtc");
183 clk
= mmp_clk_register_apbc("pwm0", "pll1_48",
184 apbc_base
+ APBC_PWM0
, 10, 0, &clk_lock
);
185 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.0");
187 clk
= mmp_clk_register_apbc("pwm1", "pll1_48",
188 apbc_base
+ APBC_PWM1
, 10, 0, &clk_lock
);
189 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.1");
191 clk
= mmp_clk_register_apbc("pwm2", "pll1_48",
192 apbc_base
+ APBC_PWM2
, 10, 0, &clk_lock
);
193 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.2");
195 clk
= mmp_clk_register_apbc("pwm3", "pll1_48",
196 apbc_base
+ APBC_PWM3
, 10, 0, &clk_lock
);
197 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.3");
199 clk
= clk_register_mux(NULL
, "uart0_mux", uart_parent
,
200 ARRAY_SIZE(uart_parent
),
201 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
202 apbc_base
+ APBC_UART0
, 4, 3, 0, &clk_lock
);
203 clk_set_parent(clk
, uart_pll
);
204 clk_register_clkdev(clk
, "uart_mux.0", NULL
);
206 clk
= mmp_clk_register_apbc("uart0", "uart0_mux",
207 apbc_base
+ APBC_UART0
, 10, 0, &clk_lock
);
208 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.0");
210 clk
= clk_register_mux(NULL
, "uart1_mux", uart_parent
,
211 ARRAY_SIZE(uart_parent
),
212 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
213 apbc_base
+ APBC_UART1
, 4, 3, 0, &clk_lock
);
214 clk_set_parent(clk
, uart_pll
);
215 clk_register_clkdev(clk
, "uart_mux.1", NULL
);
217 clk
= mmp_clk_register_apbc("uart1", "uart1_mux",
218 apbc_base
+ APBC_UART1
, 10, 0, &clk_lock
);
219 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.1");
221 clk
= clk_register_mux(NULL
, "uart2_mux", uart_parent
,
222 ARRAY_SIZE(uart_parent
),
223 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
224 apbc_base
+ APBC_UART2
, 4, 3, 0, &clk_lock
);
225 clk_set_parent(clk
, uart_pll
);
226 clk_register_clkdev(clk
, "uart_mux.2", NULL
);
228 clk
= mmp_clk_register_apbc("uart2", "uart2_mux",
229 apbc_base
+ APBC_UART2
, 10, 0, &clk_lock
);
230 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.2");
232 clk
= clk_register_mux(NULL
, "ssp0_mux", ssp_parent
,
233 ARRAY_SIZE(ssp_parent
),
234 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
235 apbc_base
+ APBC_SSP0
, 4, 3, 0, &clk_lock
);
236 clk_register_clkdev(clk
, "uart_mux.0", NULL
);
238 clk
= mmp_clk_register_apbc("ssp0", "ssp0_mux", apbc_base
+ APBC_SSP0
,
240 clk_register_clkdev(clk
, NULL
, "mmp-ssp.0");
242 clk
= clk_register_mux(NULL
, "ssp1_mux", ssp_parent
,
243 ARRAY_SIZE(ssp_parent
),
244 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
245 apbc_base
+ APBC_SSP1
, 4, 3, 0, &clk_lock
);
246 clk_register_clkdev(clk
, "ssp_mux.1", NULL
);
248 clk
= mmp_clk_register_apbc("ssp1", "ssp1_mux", apbc_base
+ APBC_SSP1
,
250 clk_register_clkdev(clk
, NULL
, "mmp-ssp.1");
252 clk
= clk_register_mux(NULL
, "ssp2_mux", ssp_parent
,
253 ARRAY_SIZE(ssp_parent
),
254 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
255 apbc_base
+ APBC_SSP2
, 4, 3, 0, &clk_lock
);
256 clk_register_clkdev(clk
, "ssp_mux.2", NULL
);
258 clk
= mmp_clk_register_apbc("ssp2", "ssp1_mux", apbc_base
+ APBC_SSP2
,
260 clk_register_clkdev(clk
, NULL
, "mmp-ssp.2");
262 clk
= clk_register_mux(NULL
, "ssp3_mux", ssp_parent
,
263 ARRAY_SIZE(ssp_parent
),
264 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
265 apbc_base
+ APBC_SSP3
, 4, 3, 0, &clk_lock
);
266 clk_register_clkdev(clk
, "ssp_mux.3", NULL
);
268 clk
= mmp_clk_register_apbc("ssp3", "ssp1_mux", apbc_base
+ APBC_SSP3
,
270 clk_register_clkdev(clk
, NULL
, "mmp-ssp.3");
272 clk
= clk_register_mux(NULL
, "ssp4_mux", ssp_parent
,
273 ARRAY_SIZE(ssp_parent
),
274 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
275 apbc_base
+ APBC_SSP4
, 4, 3, 0, &clk_lock
);
276 clk_register_clkdev(clk
, "ssp_mux.4", NULL
);
278 clk
= mmp_clk_register_apbc("ssp4", "ssp1_mux", apbc_base
+ APBC_SSP4
,
280 clk_register_clkdev(clk
, NULL
, "mmp-ssp.4");
282 clk
= mmp_clk_register_apmu("dfc", "pll1_4", apmu_base
+ APMU_DFC
,
284 clk_register_clkdev(clk
, NULL
, "pxa3xx-nand.0");
286 clk
= clk_register_mux(NULL
, "sdh0_mux", sdh_parent
,
287 ARRAY_SIZE(sdh_parent
),
288 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
289 apmu_base
+ APMU_SDH0
, 6, 1, 0, &clk_lock
);
290 clk_register_clkdev(clk
, "sdh0_mux", NULL
);
292 clk
= mmp_clk_register_apmu("sdh0", "sdh_mux", apmu_base
+ APMU_SDH0
,
294 clk_register_clkdev(clk
, NULL
, "sdhci-pxa.0");
296 clk
= clk_register_mux(NULL
, "sdh1_mux", sdh_parent
,
297 ARRAY_SIZE(sdh_parent
),
298 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
299 apmu_base
+ APMU_SDH1
, 6, 1, 0, &clk_lock
);
300 clk_register_clkdev(clk
, "sdh1_mux", NULL
);
302 clk
= mmp_clk_register_apmu("sdh1", "sdh1_mux", apmu_base
+ APMU_SDH1
,
304 clk_register_clkdev(clk
, NULL
, "sdhci-pxa.1");
306 clk
= mmp_clk_register_apmu("usb", "usb_pll", apmu_base
+ APMU_USB
,
308 clk_register_clkdev(clk
, "usb_clk", NULL
);
310 clk
= mmp_clk_register_apmu("sph", "usb_pll", apmu_base
+ APMU_USB
,
312 clk_register_clkdev(clk
, "sph_clk", NULL
);
314 clk
= clk_register_mux(NULL
, "disp0_mux", disp_parent
,
315 ARRAY_SIZE(disp_parent
),
316 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
317 apmu_base
+ APMU_DISP0
, 6, 1, 0, &clk_lock
);
318 clk_register_clkdev(clk
, "disp_mux.0", NULL
);
320 clk
= mmp_clk_register_apmu("disp0", "disp0_mux",
321 apmu_base
+ APMU_DISP0
, 0x1b, &clk_lock
);
322 clk_register_clkdev(clk
, "fnclk", "mmp-disp.0");
324 clk
= mmp_clk_register_apmu("disp0_hclk", "disp0_mux",
325 apmu_base
+ APMU_DISP0
, 0x24, &clk_lock
);
326 clk_register_clkdev(clk
, "hclk", "mmp-disp.0");
328 clk
= clk_register_mux(NULL
, "ccic0_mux", ccic_parent
,
329 ARRAY_SIZE(ccic_parent
),
330 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
331 apmu_base
+ APMU_CCIC0
, 6, 1, 0, &clk_lock
);
332 clk_register_clkdev(clk
, "ccic_mux.0", NULL
);
334 clk
= mmp_clk_register_apmu("ccic0", "ccic0_mux",
335 apmu_base
+ APMU_CCIC0
, 0x1b, &clk_lock
);
336 clk_register_clkdev(clk
, "fnclk", "mmp-ccic.0");
338 clk
= clk_register_mux(NULL
, "ccic0_phy_mux", ccic_phy_parent
,
339 ARRAY_SIZE(ccic_phy_parent
),
340 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
341 apmu_base
+ APMU_CCIC0
, 7, 1, 0, &clk_lock
);
342 clk_register_clkdev(clk
, "ccic_phy_mux.0", NULL
);
344 clk
= mmp_clk_register_apmu("ccic0_phy", "ccic0_phy_mux",
345 apmu_base
+ APMU_CCIC0
, 0x24, &clk_lock
);
346 clk_register_clkdev(clk
, "phyclk", "mmp-ccic.0");
348 clk
= clk_register_divider(NULL
, "ccic0_sphy_div", "ccic0_mux",
349 CLK_SET_RATE_PARENT
, apmu_base
+ APMU_CCIC0
,
350 10, 5, 0, &clk_lock
);
351 clk_register_clkdev(clk
, "sphyclk_div", NULL
);
353 clk
= mmp_clk_register_apmu("ccic0_sphy", "ccic0_sphy_div",
354 apmu_base
+ APMU_CCIC0
, 0x300, &clk_lock
);
355 clk_register_clkdev(clk
, "sphyclk", "mmp-ccic.0");