1 /* linux/arch/arm/mach-s5pv210/clock.c
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
6 * S5PV210 - Clock support
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/errno.h>
18 #include <linux/err.h>
19 #include <linux/clk.h>
20 #include <linux/sysdev.h>
25 #include <plat/cpu-freq.h>
26 #include <mach/regs-clock.h>
27 #include <plat/clock.h>
30 #include <plat/s5p-clock.h>
31 #include <plat/clock-clksrc.h>
32 #include <plat/s5pv210.h>
34 static struct clksrc_clk clk_mout_apll = {
39 .sources = &clk_src_apll,
40 .reg_src = { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
43 static struct clksrc_clk clk_mout_epll = {
48 .sources = &clk_src_epll,
49 .reg_src = { .reg = S5P_CLK_SRC0, .shift = 8, .size = 1 },
52 static struct clksrc_clk clk_mout_mpll = {
57 .sources = &clk_src_mpll,
58 .reg_src = { .reg = S5P_CLK_SRC0, .shift = 4, .size = 1 },
61 static struct clk *clkset_armclk_list[] = {
62 [0] = &clk_mout_apll.clk,
63 [1] = &clk_mout_mpll.clk,
66 static struct clksrc_sources clkset_armclk = {
67 .sources = clkset_armclk_list,
68 .nr_sources = ARRAY_SIZE(clkset_armclk_list),
71 static struct clksrc_clk clk_armclk = {
76 .sources = &clkset_armclk,
77 .reg_src = { .reg = S5P_CLK_SRC0, .shift = 16, .size = 1 },
78 .reg_div = { .reg = S5P_CLK_DIV0, .shift = 0, .size = 3 },
81 static int s5pv210_clk_ip0_ctrl(struct clk *clk, int enable)
83 return s5p_gatectrl(S5P_CLKGATE_IP0, clk, enable);
86 static int s5pv210_clk_ip1_ctrl(struct clk *clk, int enable)
88 return s5p_gatectrl(S5P_CLKGATE_IP1, clk, enable);
91 static int s5pv210_clk_ip2_ctrl(struct clk *clk, int enable)
93 return s5p_gatectrl(S5P_CLKGATE_IP2, clk, enable);
96 static int s5pv210_clk_ip3_ctrl(struct clk *clk, int enable)
98 return s5p_gatectrl(S5P_CLKGATE_IP3, clk, enable);
101 static struct clk clk_h200 = {
106 static struct clk clk_h100 = {
111 static struct clk clk_h166 = {
116 static struct clk clk_h133 = {
121 static struct clk clk_p100 = {
126 static struct clk clk_p83 = {
131 static struct clk clk_p66 = {
136 static struct clk *sys_clks[] = {
146 static struct clk init_clocks_disable[] = {
151 .enable = s5pv210_clk_ip0_ctrl,
157 .enable = s5pv210_clk_ip1_ctrl,
163 .enable = s5pv210_clk_ip1_ctrl,
169 .enable = s5pv210_clk_ip1_ctrl,
175 .enable = s5pv210_clk_ip1_ctrl,
181 .enable = s5pv210_clk_ip2_ctrl,
187 .enable = s5pv210_clk_ip2_ctrl,
193 .enable = s5pv210_clk_ip2_ctrl,
199 .enable = s5pv210_clk_ip2_ctrl,
205 .enable = s5pv210_clk_ip3_ctrl,
211 .enable = s5pv210_clk_ip3_ctrl,
217 .enable = s5pv210_clk_ip3_ctrl,
223 .enable = s5pv210_clk_ip3_ctrl,
229 .enable = s5pv210_clk_ip3_ctrl,
235 .enable = s5pv210_clk_ip3_ctrl,
241 .enable = s5pv210_clk_ip3_ctrl,
247 .enable = s5pv210_clk_ip3_ctrl,
253 .enable = s5pv210_clk_ip3_ctrl,
259 .enable = s5pv210_clk_ip3_ctrl,
265 .enable = s5pv210_clk_ip3_ctrl,
271 .enable = s5pv210_clk_ip3_ctrl,
277 .enable = s5pv210_clk_ip3_ctrl,
283 .enable = s5pv210_clk_ip3_ctrl,
289 .enable = s5pv210_clk_ip3_ctrl,
294 static struct clk init_clocks[] = {
299 .enable = s5pv210_clk_ip3_ctrl,
305 .enable = s5pv210_clk_ip3_ctrl,
311 .enable = s5pv210_clk_ip3_ctrl,
317 .enable = s5pv210_clk_ip3_ctrl,
322 static struct clk *clkset_uart_list[] = {
323 [6] = &clk_mout_mpll.clk,
324 [7] = &clk_mout_epll.clk,
327 static struct clksrc_sources clkset_uart = {
328 .sources = clkset_uart_list,
329 .nr_sources = ARRAY_SIZE(clkset_uart_list),
332 static struct clksrc_clk clksrcs[] = {
338 .enable = s5pv210_clk_ip3_ctrl,
340 .sources = &clkset_uart,
341 .reg_src = { .reg = S5P_CLK_SRC4, .shift = 16, .size = 4 },
342 .reg_div = { .reg = S5P_CLK_DIV4, .shift = 16, .size = 4 },
346 /* Clock initialisation code */
347 static struct clksrc_clk *sysclks[] = {
354 #define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
356 void __init_or_cpufreq s5pv210_setup_clocks(void)
358 struct clk *xtal_clk;
360 unsigned long armclk;
361 unsigned long hclk200;
362 unsigned long hclk166;
363 unsigned long hclk133;
364 unsigned long pclk100;
365 unsigned long pclk83;
366 unsigned long pclk66;
371 u32 clkdiv0, clkdiv1;
373 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
375 clkdiv0 = __raw_readl(S5P_CLK_DIV0);
376 clkdiv1 = __raw_readl(S5P_CLK_DIV1);
378 printk(KERN_DEBUG "%s: clkdiv0 = %08x, clkdiv1 = %08x\n",
379 __func__, clkdiv0, clkdiv1);
381 xtal_clk = clk_get(NULL, "xtal");
382 BUG_ON(IS_ERR(xtal_clk));
384 xtal = clk_get_rate(xtal_clk);
387 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
389 apll = s5p_get_pll45xx(xtal, __raw_readl(S5P_APLL_CON), pll_4508);
390 mpll = s5p_get_pll45xx(xtal, __raw_readl(S5P_MPLL_CON), pll_4502);
391 epll = s5p_get_pll45xx(xtal, __raw_readl(S5P_EPLL_CON), pll_4500);
393 clk_fout_apll.rate = apll;
394 clk_fout_mpll.rate = mpll;
395 clk_fout_epll.rate = epll;
397 printk(KERN_INFO "S5PV210: PLL settings, A=%ld, M=%ld, E=%ld",
400 armclk = clk_get_rate(&clk_armclk.clk);
401 if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX200_MASK)
402 hclk200 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK200);
404 hclk200 = armclk / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK200);
406 if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX166_MASK) {
407 hclk166 = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_A2M);
408 hclk166 = hclk166 / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK166);
410 hclk166 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK166);
412 if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX133_MASK) {
413 hclk133 = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_A2M);
414 hclk133 = hclk133 / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK133);
416 hclk133 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK133);
418 pclk100 = hclk200 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK100);
419 pclk83 = hclk166 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK83);
420 pclk66 = hclk133 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK66);
422 printk(KERN_INFO "S5PV210: ARMCLK=%ld, HCLKM=%ld, HCLKD=%ld, \
423 HCLKP=%ld, PCLKM=%ld, PCLKD=%ld, PCLKP=%ld\n",
424 armclk, hclk200, hclk166, hclk133, pclk100, pclk83, pclk66);
427 clk_h.rate = hclk133;
429 clk_p66.rate = pclk66;
430 clk_p83.rate = pclk83;
431 clk_h133.rate = hclk133;
432 clk_h166.rate = hclk166;
433 clk_h200.rate = hclk200;
435 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
436 s3c_set_clksrc(&clksrcs[ptr], true);
439 static struct clk *clks[] __initdata = {
442 void __init s5pv210_register_clocks(void)
448 ret = s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
450 printk(KERN_ERR "Failed to register %u clocks\n", ret);
452 for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
453 s3c_register_clksrc(sysclks[ptr], 1);
455 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
456 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
458 ret = s3c24xx_register_clocks(sys_clks, ARRAY_SIZE(sys_clks));
460 printk(KERN_ERR "Failed to register system clocks\n");
462 clkp = init_clocks_disable;
463 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
464 ret = s3c24xx_register_clock(clkp);
466 printk(KERN_ERR "Failed to register clock %s (%d)\n",
469 (clkp->enable)(clkp, 0);