1 /* linux/arch/arm/plat-s3c64xx/s3c6400-clock.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * S3C6400 based common clock support
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/list.h>
19 #include <linux/errno.h>
20 #include <linux/err.h>
21 #include <linux/clk.h>
22 #include <linux/sysdev.h>
25 #include <mach/hardware.h>
28 #include <plat/cpu-freq.h>
30 #include <plat/regs-clock.h>
31 #include <plat/clock.h>
32 #include <plat/clock-clksrc.h>
36 /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
37 * ext_xtal_mux for want of an actual name from the manual.
40 static struct clk clk_ext_xtal_mux = {
45 #define clk_fin_apll clk_ext_xtal_mux
46 #define clk_fin_mpll clk_ext_xtal_mux
47 #define clk_fin_epll clk_ext_xtal_mux
49 #define clk_fout_mpll clk_mpll
50 #define clk_fout_epll clk_epll
52 static struct clk clk_fout_apll = {
57 static struct clk *clk_src_apll_list[] = {
62 static struct clksrc_sources clk_src_apll = {
63 .sources = clk_src_apll_list,
64 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
67 static struct clksrc_clk clk_mout_apll = {
72 .reg_src = { .reg = S3C_CLK_SRC, .shift = 0, .size = 1 },
73 .sources = &clk_src_apll,
76 static struct clk *clk_src_epll_list[] = {
81 static struct clksrc_sources clk_src_epll = {
82 .sources = clk_src_epll_list,
83 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
86 static struct clksrc_clk clk_mout_epll = {
91 .reg_src = { .reg = S3C_CLK_SRC, .shift = 2, .size = 1 },
92 .sources = &clk_src_epll,
95 static struct clk *clk_src_mpll_list[] = {
100 static struct clksrc_sources clk_src_mpll = {
101 .sources = clk_src_mpll_list,
102 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
105 static struct clksrc_clk clk_mout_mpll = {
110 .reg_src = { .reg = S3C_CLK_SRC, .shift = 1, .size = 1 },
111 .sources = &clk_src_mpll,
114 static unsigned int armclk_mask;
116 static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
118 unsigned long rate = clk_get_rate(clk->parent);
121 /* divisor mask starts at bit0, so no need to shift */
122 clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
124 return rate / (clkdiv + 1);
127 static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
130 unsigned long parent = clk_get_rate(clk->parent);
136 div = (parent / rate) - 1;
137 if (div > armclk_mask)
140 return parent / (div + 1);
143 static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
145 unsigned long parent = clk_get_rate(clk->parent);
149 if (rate < parent / (armclk_mask + 1))
152 rate = clk_round_rate(clk, rate);
153 div = clk_get_rate(clk->parent) / rate;
155 val = __raw_readl(S3C_CLK_DIV0);
158 __raw_writel(val, S3C_CLK_DIV0);
164 static struct clk clk_arm = {
167 .parent = &clk_mout_apll.clk,
168 .ops = &(struct clk_ops) {
169 .get_rate = s3c64xx_clk_arm_get_rate,
170 .set_rate = s3c64xx_clk_arm_set_rate,
171 .round_rate = s3c64xx_clk_arm_round_rate,
175 static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
177 unsigned long rate = clk_get_rate(clk->parent);
179 printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
181 if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
187 static struct clk_ops clk_dout_ops = {
188 .get_rate = s3c64xx_clk_doutmpll_get_rate,
191 static struct clk clk_dout_mpll = {
194 .parent = &clk_mout_mpll.clk,
195 .ops = &clk_dout_ops,
198 static struct clk *clkset_spi_mmc_list[] = {
205 static struct clksrc_sources clkset_spi_mmc = {
206 .sources = clkset_spi_mmc_list,
207 .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
210 static struct clk *clkset_irda_list[] = {
217 static struct clksrc_sources clkset_irda = {
218 .sources = clkset_irda_list,
219 .nr_sources = ARRAY_SIZE(clkset_irda_list),
222 static struct clk *clkset_uart_list[] = {
229 static struct clksrc_sources clkset_uart = {
230 .sources = clkset_uart_list,
231 .nr_sources = ARRAY_SIZE(clkset_uart_list),
234 static struct clk *clkset_uhost_list[] = {
241 static struct clksrc_sources clkset_uhost = {
242 .sources = clkset_uhost_list,
243 .nr_sources = ARRAY_SIZE(clkset_uhost_list),
246 /* The peripheral clocks are all controlled via clocksource followed
247 * by an optional divider and gate stage. We currently roll this into
248 * one clock which hides the intermediate clock from the mux.
250 * Note, the JPEG clock can only be an even divider...
252 * The scaler and LCD clocks depend on the S3C64XX version, and also
253 * have a common parent divisor so are not included here.
256 /* clocks that feed other parts of the clock source tree */
258 static struct clk clk_iis_cd0 = {
259 .name = "iis_cdclk0",
263 static struct clk clk_iis_cd1 = {
264 .name = "iis_cdclk1",
268 static struct clk clk_pcm_cd = {
273 static struct clk *clkset_audio0_list[] = {
274 [0] = &clk_mout_epll.clk,
275 [1] = &clk_dout_mpll,
281 static struct clksrc_sources clkset_audio0 = {
282 .sources = clkset_audio0_list,
283 .nr_sources = ARRAY_SIZE(clkset_audio0_list),
286 static struct clk *clkset_audio1_list[] = {
287 [0] = &clk_mout_epll.clk,
288 [1] = &clk_dout_mpll,
294 static struct clksrc_sources clkset_audio1 = {
295 .sources = clkset_audio1_list,
296 .nr_sources = ARRAY_SIZE(clkset_audio1_list),
299 static struct clk *clkset_camif_list[] = {
303 static struct clksrc_sources clkset_camif = {
304 .sources = clkset_camif_list,
305 .nr_sources = ARRAY_SIZE(clkset_camif_list),
308 static struct clksrc_clk clksrcs[] = {
313 .ctrlbit = S3C_CLKCON_SCLK_MMC0,
314 .enable = s3c64xx_sclk_ctrl,
316 .reg_src = { .reg = S3C_CLK_SRC, .shift = 18, .size = 2 },
317 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 0, .size = 4 },
318 .sources = &clkset_spi_mmc,
323 .ctrlbit = S3C_CLKCON_SCLK_MMC1,
324 .enable = s3c64xx_sclk_ctrl,
326 .reg_src = { .reg = S3C_CLK_SRC, .shift = 20, .size = 2 },
327 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 4, .size = 4 },
328 .sources = &clkset_spi_mmc,
333 .ctrlbit = S3C_CLKCON_SCLK_MMC2,
334 .enable = s3c64xx_sclk_ctrl,
336 .reg_src = { .reg = S3C_CLK_SRC, .shift = 22, .size = 2 },
337 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 8, .size = 4 },
338 .sources = &clkset_spi_mmc,
341 .name = "usb-bus-host",
343 .ctrlbit = S3C_CLKCON_SCLK_UHOST,
344 .enable = s3c64xx_sclk_ctrl,
346 .reg_src = { .reg = S3C_CLK_SRC, .shift = 5, .size = 2 },
347 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 20, .size = 4 },
348 .sources = &clkset_uhost,
353 .ctrlbit = S3C_CLKCON_SCLK_UART,
354 .enable = s3c64xx_sclk_ctrl,
356 .reg_src = { .reg = S3C_CLK_SRC, .shift = 13, .size = 1 },
357 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 16, .size = 4 },
358 .sources = &clkset_uart,
360 /* Where does UCLK0 come from? */
364 .ctrlbit = S3C_CLKCON_SCLK_SPI0,
365 .enable = s3c64xx_sclk_ctrl,
367 .reg_src = { .reg = S3C_CLK_SRC, .shift = 14, .size = 2 },
368 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 0, .size = 4 },
369 .sources = &clkset_spi_mmc,
374 .ctrlbit = S3C_CLKCON_SCLK_SPI1,
375 .enable = s3c64xx_sclk_ctrl,
377 .reg_src = { .reg = S3C_CLK_SRC, .shift = 16, .size = 2 },
378 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 4, .size = 4 },
379 .sources = &clkset_spi_mmc,
384 .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
385 .enable = s3c64xx_sclk_ctrl,
387 .reg_src = { .reg = S3C_CLK_SRC, .shift = 7, .size = 3 },
388 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 8, .size = 4 },
389 .sources = &clkset_audio0,
394 .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
395 .enable = s3c64xx_sclk_ctrl,
397 .reg_src = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3 },
398 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4 },
399 .sources = &clkset_audio1,
404 .ctrlbit = S3C_CLKCON_SCLK_IRDA,
405 .enable = s3c64xx_sclk_ctrl,
407 .reg_src = { .reg = S3C_CLK_SRC, .shift = 24, .size = 2 },
408 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 20, .size = 4 },
409 .sources = &clkset_irda,
414 .ctrlbit = S3C_CLKCON_SCLK_CAM,
415 .enable = s3c64xx_sclk_ctrl,
417 .reg_div = { .reg = S3C_CLK_DIV0, .shift = 20, .size = 4 },
418 .reg_src = { .reg = NULL, .shift = 0, .size = 0 },
419 .sources = &clkset_camif,
423 /* Clock initialisation code */
425 static struct clksrc_clk *init_parents[] = {
431 #define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
433 void __init_or_cpufreq s3c6400_setup_clocks(void)
435 struct clk *xtal_clk;
447 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
449 clkdiv0 = __raw_readl(S3C_CLK_DIV0);
450 printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
452 xtal_clk = clk_get(NULL, "xtal");
453 BUG_ON(IS_ERR(xtal_clk));
455 xtal = clk_get_rate(xtal_clk);
458 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
460 /* For now assume the mux always selects the crystal */
461 clk_ext_xtal_mux.parent = xtal_clk;
463 epll = s3c6400_get_epll(xtal);
464 mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
465 apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
469 printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
472 hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
473 hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
474 pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
476 printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
479 clk_fout_mpll.rate = mpll;
480 clk_fout_epll.rate = epll;
481 clk_fout_apll.rate = apll;
488 for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
489 s3c_set_clksrc(init_parents[ptr], true);
491 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
492 s3c_set_clksrc(&clksrcs[ptr], true);
495 static struct clk *clks[] __initdata = {
507 * s3c6400_register_clocks - register clocks for s3c6400 and above
508 * @armclk_divlimit: Divisor mask for ARMCLK
510 * Register the clocks for the S3C6400 and above SoC range, such
511 * as ARMCLK and the clocks which have divider chains attached.
513 * This call does not setup the clocks, which is left to the
514 * s3c6400_setup_clocks() call which may be needed by the cpufreq
515 * or resume code to re-set the clocks if the bootloader has changed
518 void __init s3c6400_register_clocks(unsigned armclk_divlimit)
524 armclk_mask = armclk_divlimit;
526 for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
528 ret = s3c24xx_register_clock(clkp);
530 printk(KERN_ERR "Failed to register clock %s (%d)\n",
535 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));