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/module.h>
13 #include <linux/kernel.h>
14 #include <linux/spinlock.h>
16 #include <linux/delay.h>
17 #include <linux/err.h>
19 #include <mach/addr-map.h>
24 #define APBC_TWSI0 0x2c
26 #define APBC_UART0 0x0
27 #define APBC_UART1 0x4
30 #define APBC_PWM1 0x10
31 #define APBC_PWM2 0x14
32 #define APBC_PWM3 0x18
33 #define APBC_SSP0 0x81c
34 #define APBC_SSP1 0x820
35 #define APBC_SSP2 0x84c
36 #define APBC_SSP3 0x858
37 #define APBC_SSP4 0x85c
38 #define APBC_TWSI1 0x6c
39 #define APBC_UART2 0x70
40 #define APMU_SDH0 0x54
41 #define APMU_SDH1 0x58
43 #define APMU_DISP0 0x4c
44 #define APMU_CCIC0 0x50
46 #define MPMU_UART_PLL 0x14
48 static DEFINE_SPINLOCK(clk_lock
);
50 static struct clk_factor_masks uart_factor_masks
= {
58 static struct clk_factor_tbl uart_factor_tbl
[] = {
59 {.num
= 8125, .den
= 1536}, /*14.745MHZ */
62 static const char *uart_parent
[] = {"pll1_3_16", "uart_pll"};
63 static const char *ssp_parent
[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
64 static const char *sdh_parent
[] = {"pll1_12", "pll1_13"};
65 static const char *disp_parent
[] = {"pll1_2", "pll1_12"};
66 static const char *ccic_parent
[] = {"pll1_2", "pll1_12"};
67 static const char *ccic_phy_parent
[] = {"pll1_6", "pll1_12"};
69 void __init
pxa168_clk_init(void)
73 void __iomem
*mpmu_base
;
74 void __iomem
*apmu_base
;
75 void __iomem
*apbc_base
;
77 mpmu_base
= ioremap(APB_PHYS_BASE
+ 0x50000, SZ_4K
);
78 if (mpmu_base
== NULL
) {
79 pr_err("error to ioremap MPMU base\n");
83 apmu_base
= ioremap(AXI_PHYS_BASE
+ 0x82800, SZ_4K
);
84 if (apmu_base
== NULL
) {
85 pr_err("error to ioremap APMU base\n");
89 apbc_base
= ioremap(APB_PHYS_BASE
+ 0x15000, 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
, CLK_IS_ROOT
, 3200);
96 clk_register_clkdev(clk
, "clk32", NULL
);
98 clk
= clk_register_fixed_rate(NULL
, "vctcxo", NULL
, CLK_IS_ROOT
,
100 clk_register_clkdev(clk
, "vctcxo", NULL
);
102 clk
= clk_register_fixed_rate(NULL
, "pll1", NULL
, CLK_IS_ROOT
,
104 clk_register_clkdev(clk
, "pll1", NULL
);
106 clk
= clk_register_fixed_factor(NULL
, "pll1_2", "pll1",
107 CLK_SET_RATE_PARENT
, 1, 2);
108 clk_register_clkdev(clk
, "pll1_2", NULL
);
110 clk
= clk_register_fixed_factor(NULL
, "pll1_4", "pll1_2",
111 CLK_SET_RATE_PARENT
, 1, 2);
112 clk_register_clkdev(clk
, "pll1_4", NULL
);
114 clk
= clk_register_fixed_factor(NULL
, "pll1_8", "pll1_4",
115 CLK_SET_RATE_PARENT
, 1, 2);
116 clk_register_clkdev(clk
, "pll1_8", NULL
);
118 clk
= clk_register_fixed_factor(NULL
, "pll1_16", "pll1_8",
119 CLK_SET_RATE_PARENT
, 1, 2);
120 clk_register_clkdev(clk
, "pll1_16", NULL
);
122 clk
= clk_register_fixed_factor(NULL
, "pll1_6", "pll1_2",
123 CLK_SET_RATE_PARENT
, 1, 3);
124 clk_register_clkdev(clk
, "pll1_6", NULL
);
126 clk
= clk_register_fixed_factor(NULL
, "pll1_12", "pll1_6",
127 CLK_SET_RATE_PARENT
, 1, 2);
128 clk_register_clkdev(clk
, "pll1_12", NULL
);
130 clk
= clk_register_fixed_factor(NULL
, "pll1_24", "pll1_12",
131 CLK_SET_RATE_PARENT
, 1, 2);
132 clk_register_clkdev(clk
, "pll1_24", NULL
);
134 clk
= clk_register_fixed_factor(NULL
, "pll1_48", "pll1_24",
135 CLK_SET_RATE_PARENT
, 1, 2);
136 clk_register_clkdev(clk
, "pll1_48", NULL
);
138 clk
= clk_register_fixed_factor(NULL
, "pll1_96", "pll1_48",
139 CLK_SET_RATE_PARENT
, 1, 2);
140 clk_register_clkdev(clk
, "pll1_96", NULL
);
142 clk
= clk_register_fixed_factor(NULL
, "pll1_13", "pll1",
143 CLK_SET_RATE_PARENT
, 1, 13);
144 clk_register_clkdev(clk
, "pll1_13", NULL
);
146 clk
= clk_register_fixed_factor(NULL
, "pll1_13_1_5", "pll1",
147 CLK_SET_RATE_PARENT
, 2, 3);
148 clk_register_clkdev(clk
, "pll1_13_1_5", NULL
);
150 clk
= clk_register_fixed_factor(NULL
, "pll1_2_1_5", "pll1",
151 CLK_SET_RATE_PARENT
, 2, 3);
152 clk_register_clkdev(clk
, "pll1_2_1_5", NULL
);
154 clk
= clk_register_fixed_factor(NULL
, "pll1_3_16", "pll1",
155 CLK_SET_RATE_PARENT
, 3, 16);
156 clk_register_clkdev(clk
, "pll1_3_16", NULL
);
158 uart_pll
= mmp_clk_register_factor("uart_pll", "pll1_4", 0,
159 mpmu_base
+ MPMU_UART_PLL
,
160 &uart_factor_masks
, uart_factor_tbl
,
161 ARRAY_SIZE(uart_factor_tbl
));
162 clk_set_rate(uart_pll
, 14745600);
163 clk_register_clkdev(uart_pll
, "uart_pll", NULL
);
165 clk
= mmp_clk_register_apbc("twsi0", "pll1_13_1_5",
166 apbc_base
+ APBC_TWSI0
, 10, 0, &clk_lock
);
167 clk_register_clkdev(clk
, NULL
, "pxa2xx-i2c.0");
169 clk
= mmp_clk_register_apbc("twsi1", "pll1_13_1_5",
170 apbc_base
+ APBC_TWSI1
, 10, 0, &clk_lock
);
171 clk_register_clkdev(clk
, NULL
, "pxa2xx-i2c.1");
173 clk
= mmp_clk_register_apbc("gpio", "vctcxo",
174 apbc_base
+ APBC_GPIO
, 10, 0, &clk_lock
);
175 clk_register_clkdev(clk
, NULL
, "mmp-gpio");
177 clk
= mmp_clk_register_apbc("kpc", "clk32",
178 apbc_base
+ APBC_KPC
, 10, 0, &clk_lock
);
179 clk_register_clkdev(clk
, NULL
, "pxa27x-keypad");
181 clk
= mmp_clk_register_apbc("rtc", "clk32",
182 apbc_base
+ APBC_RTC
, 10, 0, &clk_lock
);
183 clk_register_clkdev(clk
, NULL
, "sa1100-rtc");
185 clk
= mmp_clk_register_apbc("pwm0", "pll1_48",
186 apbc_base
+ APBC_PWM0
, 10, 0, &clk_lock
);
187 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.0");
189 clk
= mmp_clk_register_apbc("pwm1", "pll1_48",
190 apbc_base
+ APBC_PWM1
, 10, 0, &clk_lock
);
191 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.1");
193 clk
= mmp_clk_register_apbc("pwm2", "pll1_48",
194 apbc_base
+ APBC_PWM2
, 10, 0, &clk_lock
);
195 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.2");
197 clk
= mmp_clk_register_apbc("pwm3", "pll1_48",
198 apbc_base
+ APBC_PWM3
, 10, 0, &clk_lock
);
199 clk_register_clkdev(clk
, NULL
, "pxa168-pwm.3");
201 clk
= clk_register_mux(NULL
, "uart0_mux", uart_parent
,
202 ARRAY_SIZE(uart_parent
),
203 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
204 apbc_base
+ APBC_UART0
, 4, 3, 0, &clk_lock
);
205 clk_set_parent(clk
, uart_pll
);
206 clk_register_clkdev(clk
, "uart_mux.0", NULL
);
208 clk
= mmp_clk_register_apbc("uart0", "uart0_mux",
209 apbc_base
+ APBC_UART0
, 10, 0, &clk_lock
);
210 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.0");
212 clk
= clk_register_mux(NULL
, "uart1_mux", uart_parent
,
213 ARRAY_SIZE(uart_parent
),
214 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
215 apbc_base
+ APBC_UART1
, 4, 3, 0, &clk_lock
);
216 clk_set_parent(clk
, uart_pll
);
217 clk_register_clkdev(clk
, "uart_mux.1", NULL
);
219 clk
= mmp_clk_register_apbc("uart1", "uart1_mux",
220 apbc_base
+ APBC_UART1
, 10, 0, &clk_lock
);
221 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.1");
223 clk
= clk_register_mux(NULL
, "uart2_mux", uart_parent
,
224 ARRAY_SIZE(uart_parent
),
225 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
226 apbc_base
+ APBC_UART2
, 4, 3, 0, &clk_lock
);
227 clk_set_parent(clk
, uart_pll
);
228 clk_register_clkdev(clk
, "uart_mux.2", NULL
);
230 clk
= mmp_clk_register_apbc("uart2", "uart2_mux",
231 apbc_base
+ APBC_UART2
, 10, 0, &clk_lock
);
232 clk_register_clkdev(clk
, NULL
, "pxa2xx-uart.2");
234 clk
= clk_register_mux(NULL
, "ssp0_mux", ssp_parent
,
235 ARRAY_SIZE(ssp_parent
),
236 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
237 apbc_base
+ APBC_SSP0
, 4, 3, 0, &clk_lock
);
238 clk_register_clkdev(clk
, "uart_mux.0", NULL
);
240 clk
= mmp_clk_register_apbc("ssp0", "ssp0_mux", apbc_base
+ APBC_SSP0
,
242 clk_register_clkdev(clk
, NULL
, "mmp-ssp.0");
244 clk
= clk_register_mux(NULL
, "ssp1_mux", ssp_parent
,
245 ARRAY_SIZE(ssp_parent
),
246 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
247 apbc_base
+ APBC_SSP1
, 4, 3, 0, &clk_lock
);
248 clk_register_clkdev(clk
, "ssp_mux.1", NULL
);
250 clk
= mmp_clk_register_apbc("ssp1", "ssp1_mux", apbc_base
+ APBC_SSP1
,
252 clk_register_clkdev(clk
, NULL
, "mmp-ssp.1");
254 clk
= clk_register_mux(NULL
, "ssp2_mux", ssp_parent
,
255 ARRAY_SIZE(ssp_parent
),
256 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
257 apbc_base
+ APBC_SSP2
, 4, 3, 0, &clk_lock
);
258 clk_register_clkdev(clk
, "ssp_mux.2", NULL
);
260 clk
= mmp_clk_register_apbc("ssp2", "ssp1_mux", apbc_base
+ APBC_SSP2
,
262 clk_register_clkdev(clk
, NULL
, "mmp-ssp.2");
264 clk
= clk_register_mux(NULL
, "ssp3_mux", ssp_parent
,
265 ARRAY_SIZE(ssp_parent
),
266 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
267 apbc_base
+ APBC_SSP3
, 4, 3, 0, &clk_lock
);
268 clk_register_clkdev(clk
, "ssp_mux.3", NULL
);
270 clk
= mmp_clk_register_apbc("ssp3", "ssp1_mux", apbc_base
+ APBC_SSP3
,
272 clk_register_clkdev(clk
, NULL
, "mmp-ssp.3");
274 clk
= clk_register_mux(NULL
, "ssp4_mux", ssp_parent
,
275 ARRAY_SIZE(ssp_parent
),
276 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
277 apbc_base
+ APBC_SSP4
, 4, 3, 0, &clk_lock
);
278 clk_register_clkdev(clk
, "ssp_mux.4", NULL
);
280 clk
= mmp_clk_register_apbc("ssp4", "ssp1_mux", apbc_base
+ APBC_SSP4
,
282 clk_register_clkdev(clk
, NULL
, "mmp-ssp.4");
284 clk
= mmp_clk_register_apmu("dfc", "pll1_4", apmu_base
+ APMU_DFC
,
286 clk_register_clkdev(clk
, NULL
, "pxa3xx-nand.0");
288 clk
= clk_register_mux(NULL
, "sdh0_mux", sdh_parent
,
289 ARRAY_SIZE(sdh_parent
),
290 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
291 apmu_base
+ APMU_SDH0
, 6, 1, 0, &clk_lock
);
292 clk_register_clkdev(clk
, "sdh0_mux", NULL
);
294 clk
= mmp_clk_register_apmu("sdh0", "sdh_mux", apmu_base
+ APMU_SDH0
,
296 clk_register_clkdev(clk
, NULL
, "sdhci-pxa.0");
298 clk
= clk_register_mux(NULL
, "sdh1_mux", sdh_parent
,
299 ARRAY_SIZE(sdh_parent
),
300 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
301 apmu_base
+ APMU_SDH1
, 6, 1, 0, &clk_lock
);
302 clk_register_clkdev(clk
, "sdh1_mux", NULL
);
304 clk
= mmp_clk_register_apmu("sdh1", "sdh1_mux", apmu_base
+ APMU_SDH1
,
306 clk_register_clkdev(clk
, NULL
, "sdhci-pxa.1");
308 clk
= mmp_clk_register_apmu("usb", "usb_pll", apmu_base
+ APMU_USB
,
310 clk_register_clkdev(clk
, "usb_clk", NULL
);
312 clk
= mmp_clk_register_apmu("sph", "usb_pll", apmu_base
+ APMU_USB
,
314 clk_register_clkdev(clk
, "sph_clk", NULL
);
316 clk
= clk_register_mux(NULL
, "disp0_mux", disp_parent
,
317 ARRAY_SIZE(disp_parent
),
318 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
319 apmu_base
+ APMU_DISP0
, 6, 1, 0, &clk_lock
);
320 clk_register_clkdev(clk
, "disp_mux.0", NULL
);
322 clk
= mmp_clk_register_apmu("disp0", "disp0_mux",
323 apmu_base
+ APMU_DISP0
, 0x1b, &clk_lock
);
324 clk_register_clkdev(clk
, "fnclk", "mmp-disp.0");
326 clk
= mmp_clk_register_apmu("disp0_hclk", "disp0_mux",
327 apmu_base
+ APMU_DISP0
, 0x24, &clk_lock
);
328 clk_register_clkdev(clk
, "hclk", "mmp-disp.0");
330 clk
= clk_register_mux(NULL
, "ccic0_mux", ccic_parent
,
331 ARRAY_SIZE(ccic_parent
),
332 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
333 apmu_base
+ APMU_CCIC0
, 6, 1, 0, &clk_lock
);
334 clk_register_clkdev(clk
, "ccic_mux.0", NULL
);
336 clk
= mmp_clk_register_apmu("ccic0", "ccic0_mux",
337 apmu_base
+ APMU_CCIC0
, 0x1b, &clk_lock
);
338 clk_register_clkdev(clk
, "fnclk", "mmp-ccic.0");
340 clk
= clk_register_mux(NULL
, "ccic0_phy_mux", ccic_phy_parent
,
341 ARRAY_SIZE(ccic_phy_parent
),
342 CLK_SET_RATE_PARENT
| CLK_SET_RATE_NO_REPARENT
,
343 apmu_base
+ APMU_CCIC0
, 7, 1, 0, &clk_lock
);
344 clk_register_clkdev(clk
, "ccic_phy_mux.0", NULL
);
346 clk
= mmp_clk_register_apmu("ccic0_phy", "ccic0_phy_mux",
347 apmu_base
+ APMU_CCIC0
, 0x24, &clk_lock
);
348 clk_register_clkdev(clk
, "phyclk", "mmp-ccic.0");
350 clk
= clk_register_divider(NULL
, "ccic0_sphy_div", "ccic0_mux",
351 CLK_SET_RATE_PARENT
, apmu_base
+ APMU_CCIC0
,
352 10, 5, 0, &clk_lock
);
353 clk_register_clkdev(clk
, "sphyclk_div", NULL
);
355 clk
= mmp_clk_register_apmu("ccic0_sphy", "ccic0_sphy_div",
356 apmu_base
+ APMU_CCIC0
, 0x300, &clk_lock
);
357 clk_register_clkdev(clk
, "sphyclk", "mmp-ccic.0");