1 /* linux/arch/arm/mach-s5p64x0/clock-s5p6440.c
3 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * S5P6440 - 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/device.h>
23 #include <mach/hardware.h>
25 #include <mach/regs-clock.h>
26 #include <mach/s5p64x0-clock.h>
28 #include <plat/cpu-freq.h>
29 #include <plat/clock.h>
32 #include <plat/s5p-clock.h>
33 #include <plat/clock-clksrc.h>
37 static u32 epll_div
[][5] = {
38 { 36000000, 0, 48, 1, 4 },
39 { 48000000, 0, 32, 1, 3 },
40 { 60000000, 0, 40, 1, 3 },
41 { 72000000, 0, 48, 1, 3 },
42 { 84000000, 0, 28, 1, 2 },
43 { 96000000, 0, 32, 1, 2 },
44 { 32768000, 45264, 43, 1, 4 },
45 { 45158000, 6903, 30, 1, 3 },
46 { 49152000, 50332, 32, 1, 3 },
47 { 67738000, 10398, 45, 1, 3 },
48 { 73728000, 9961, 49, 1, 3 }
51 static int s5p6440_epll_set_rate(struct clk
*clk
, unsigned long rate
)
53 unsigned int epll_con
, epll_con_k
;
56 if (clk
->rate
== rate
) /* Return if nothing changed */
59 epll_con
= __raw_readl(S5P64X0_EPLL_CON
);
60 epll_con_k
= __raw_readl(S5P64X0_EPLL_CON_K
);
62 epll_con_k
&= ~(PLL90XX_KDIV_MASK
);
63 epll_con
&= ~(PLL90XX_MDIV_MASK
| PLL90XX_PDIV_MASK
| PLL90XX_SDIV_MASK
);
65 for (i
= 0; i
< ARRAY_SIZE(epll_div
); i
++) {
66 if (epll_div
[i
][0] == rate
) {
67 epll_con_k
|= (epll_div
[i
][1] << PLL90XX_KDIV_SHIFT
);
68 epll_con
|= (epll_div
[i
][2] << PLL90XX_MDIV_SHIFT
) |
69 (epll_div
[i
][3] << PLL90XX_PDIV_SHIFT
) |
70 (epll_div
[i
][4] << PLL90XX_SDIV_SHIFT
);
75 if (i
== ARRAY_SIZE(epll_div
)) {
76 printk(KERN_ERR
"%s: Invalid Clock EPLL Frequency\n", __func__
);
80 __raw_writel(epll_con
, S5P64X0_EPLL_CON
);
81 __raw_writel(epll_con_k
, S5P64X0_EPLL_CON_K
);
83 printk(KERN_WARNING
"EPLL Rate changes from %lu to %lu\n",
91 static struct clk_ops s5p6440_epll_ops
= {
92 .get_rate
= s5p_epll_get_rate
,
93 .set_rate
= s5p6440_epll_set_rate
,
96 static struct clksrc_clk clk_hclk
= {
99 .parent
= &clk_armclk
.clk
,
101 .reg_div
= { .reg
= S5P64X0_CLK_DIV0
, .shift
= 8, .size
= 4 },
104 static struct clksrc_clk clk_pclk
= {
107 .parent
= &clk_hclk
.clk
,
109 .reg_div
= { .reg
= S5P64X0_CLK_DIV0
, .shift
= 12, .size
= 4 },
111 static struct clksrc_clk clk_hclk_low
= {
113 .name
= "clk_hclk_low",
115 .sources
= &clkset_hclk_low
,
116 .reg_src
= { .reg
= S5P64X0_SYS_OTHERS
, .shift
= 6, .size
= 1 },
117 .reg_div
= { .reg
= S5P64X0_CLK_DIV3
, .shift
= 8, .size
= 4 },
120 static struct clksrc_clk clk_pclk_low
= {
122 .name
= "clk_pclk_low",
123 .parent
= &clk_hclk_low
.clk
,
125 .reg_div
= { .reg
= S5P64X0_CLK_DIV3
, .shift
= 12, .size
= 4 },
129 * The following clocks will be disabled during clock initialization. It is
130 * recommended to keep the following clocks disabled until the driver requests
131 * for enabling the clock.
133 static struct clk init_clocks_off
[] = {
136 .parent
= &clk_hclk
.clk
,
137 .enable
= s5p64x0_mem_ctrl
,
141 .parent
= &clk_hclk_low
.clk
,
142 .enable
= s5p64x0_hclk0_ctrl
,
146 .parent
= &clk_hclk
.clk
,
147 .enable
= s5p64x0_hclk0_ctrl
,
151 .devname
= "dma-pl330",
152 .parent
= &clk_hclk_low
.clk
,
153 .enable
= s5p64x0_hclk0_ctrl
,
154 .ctrlbit
= (1 << 12),
157 .devname
= "s3c-sdhci.0",
158 .parent
= &clk_hclk_low
.clk
,
159 .enable
= s5p64x0_hclk0_ctrl
,
160 .ctrlbit
= (1 << 17),
163 .devname
= "s3c-sdhci.1",
164 .parent
= &clk_hclk_low
.clk
,
165 .enable
= s5p64x0_hclk0_ctrl
,
166 .ctrlbit
= (1 << 18),
169 .devname
= "s3c-sdhci.2",
170 .parent
= &clk_hclk_low
.clk
,
171 .enable
= s5p64x0_hclk0_ctrl
,
172 .ctrlbit
= (1 << 19),
175 .parent
= &clk_hclk_low
.clk
,
176 .enable
= s5p64x0_hclk0_ctrl
,
180 .parent
= &clk_hclk
.clk
,
181 .enable
= s5p64x0_hclk0_ctrl
,
182 .ctrlbit
= (1 << 25),
185 .parent
= &clk_hclk_low
.clk
,
186 .enable
= s5p64x0_hclk1_ctrl
,
189 .name
= "hclk_fimgvg",
190 .parent
= &clk_hclk
.clk
,
191 .enable
= s5p64x0_hclk1_ctrl
,
195 .parent
= &clk_hclk_low
.clk
,
196 .enable
= s5p64x0_hclk1_ctrl
,
200 .parent
= &clk_pclk_low
.clk
,
201 .enable
= s5p64x0_pclk_ctrl
,
205 .parent
= &clk_pclk_low
.clk
,
206 .enable
= s5p64x0_pclk_ctrl
,
210 .parent
= &clk_pclk_low
.clk
,
211 .enable
= s5p64x0_pclk_ctrl
,
215 .parent
= &clk_pclk_low
.clk
,
216 .enable
= s5p64x0_pclk_ctrl
,
220 .parent
= &clk_pclk_low
.clk
,
221 .enable
= s5p64x0_pclk_ctrl
,
222 .ctrlbit
= (1 << 12),
225 .parent
= &clk_pclk_low
.clk
,
226 .enable
= s5p64x0_pclk_ctrl
,
227 .ctrlbit
= (1 << 17),
230 .devname
= "s5p64x0-spi.0",
231 .parent
= &clk_pclk_low
.clk
,
232 .enable
= s5p64x0_pclk_ctrl
,
233 .ctrlbit
= (1 << 21),
236 .devname
= "s5p64x0-spi.1",
237 .parent
= &clk_pclk_low
.clk
,
238 .enable
= s5p64x0_pclk_ctrl
,
239 .ctrlbit
= (1 << 22),
242 .parent
= &clk_pclk_low
.clk
,
243 .enable
= s5p64x0_pclk_ctrl
,
244 .ctrlbit
= (1 << 25),
247 .parent
= &clk_pclk_low
.clk
,
248 .enable
= s5p64x0_pclk_ctrl
,
249 .ctrlbit
= (1 << 28),
252 .parent
= &clk_pclk
.clk
,
253 .enable
= s5p64x0_pclk_ctrl
,
254 .ctrlbit
= (1 << 29),
257 .parent
= &clk_pclk
.clk
,
258 .enable
= s5p64x0_pclk_ctrl
,
259 .ctrlbit
= (1 << 30),
261 .name
= "pclk_fimgvg",
262 .parent
= &clk_pclk
.clk
,
263 .enable
= s5p64x0_pclk_ctrl
,
264 .ctrlbit
= (1 << 31),
267 .devname
= "s3c-sdhci.0",
269 .enable
= s5p64x0_sclk_ctrl
,
270 .ctrlbit
= (1 << 27),
273 .devname
= "s3c-sdhci.1",
275 .enable
= s5p64x0_sclk_ctrl
,
276 .ctrlbit
= (1 << 28),
279 .devname
= "s3c-sdhci.2",
281 .enable
= s5p64x0_sclk_ctrl
,
282 .ctrlbit
= (1 << 29),
287 * The following clocks will be enabled during clock initialization.
289 static struct clk init_clocks
[] = {
292 .parent
= &clk_hclk
.clk
,
293 .enable
= s5p64x0_hclk0_ctrl
,
297 .parent
= &clk_hclk
.clk
,
298 .enable
= s5p64x0_hclk0_ctrl
,
299 .ctrlbit
= (1 << 21),
302 .devname
= "s3c6400-uart.0",
303 .parent
= &clk_pclk_low
.clk
,
304 .enable
= s5p64x0_pclk_ctrl
,
308 .devname
= "s3c6400-uart.1",
309 .parent
= &clk_pclk_low
.clk
,
310 .enable
= s5p64x0_pclk_ctrl
,
314 .devname
= "s3c6400-uart.2",
315 .parent
= &clk_pclk_low
.clk
,
316 .enable
= s5p64x0_pclk_ctrl
,
320 .devname
= "s3c6400-uart.3",
321 .parent
= &clk_pclk_low
.clk
,
322 .enable
= s5p64x0_pclk_ctrl
,
326 .parent
= &clk_pclk_low
.clk
,
327 .enable
= s5p64x0_pclk_ctrl
,
328 .ctrlbit
= (1 << 18),
332 static struct clk clk_iis_cd_v40
= {
333 .name
= "iis_cdclk_v40",
336 static struct clk clk_pcm_cd
= {
340 static struct clk
*clkset_group1_list
[] = {
346 static struct clksrc_sources clkset_group1
= {
347 .sources
= clkset_group1_list
,
348 .nr_sources
= ARRAY_SIZE(clkset_group1_list
),
351 static struct clk
*clkset_uart_list
[] = {
356 static struct clksrc_sources clkset_uart
= {
357 .sources
= clkset_uart_list
,
358 .nr_sources
= ARRAY_SIZE(clkset_uart_list
),
361 static struct clk
*clkset_audio_list
[] = {
369 static struct clksrc_sources clkset_audio
= {
370 .sources
= clkset_audio_list
,
371 .nr_sources
= ARRAY_SIZE(clkset_audio_list
),
374 static struct clksrc_clk clksrcs
[] = {
378 .ctrlbit
= (1 << 10),
379 .enable
= s5p64x0_sclk_ctrl
,
381 .sources
= &clkset_group1
,
382 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 26, .size
= 2 },
383 .reg_div
= { .reg
= S5P64X0_CLK_DIV1
, .shift
= 12, .size
= 4 },
386 .name
= "sclk_dispcon",
388 .enable
= s5p64x0_sclk1_ctrl
,
390 .sources
= &clkset_group1
,
391 .reg_src
= { .reg
= S5P64X0_CLK_SRC1
, .shift
= 4, .size
= 2 },
392 .reg_div
= { .reg
= S5P64X0_CLK_DIV3
, .shift
= 0, .size
= 4 },
395 .name
= "sclk_fimgvg",
397 .enable
= s5p64x0_sclk1_ctrl
,
399 .sources
= &clkset_group1
,
400 .reg_src
= { .reg
= S5P64X0_CLK_SRC1
, .shift
= 8, .size
= 2 },
401 .reg_div
= { .reg
= S5P64X0_CLK_DIV3
, .shift
= 4, .size
= 4 },
405 static struct clksrc_clk clk_sclk_mmc0
= {
408 .devname
= "s3c-sdhci.0",
409 .ctrlbit
= (1 << 24),
410 .enable
= s5p64x0_sclk_ctrl
,
412 .sources
= &clkset_group1
,
413 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 18, .size
= 2 },
414 .reg_div
= { .reg
= S5P64X0_CLK_DIV1
, .shift
= 0, .size
= 4 },
417 static struct clksrc_clk clk_sclk_mmc1
= {
420 .devname
= "s3c-sdhci.1",
421 .ctrlbit
= (1 << 25),
422 .enable
= s5p64x0_sclk_ctrl
,
424 .sources
= &clkset_group1
,
425 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 20, .size
= 2 },
426 .reg_div
= { .reg
= S5P64X0_CLK_DIV1
, .shift
= 4, .size
= 4 },
429 static struct clksrc_clk clk_sclk_mmc2
= {
432 .devname
= "s3c-sdhci.2",
433 .ctrlbit
= (1 << 26),
434 .enable
= s5p64x0_sclk_ctrl
,
436 .sources
= &clkset_group1
,
437 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 22, .size
= 2 },
438 .reg_div
= { .reg
= S5P64X0_CLK_DIV1
, .shift
= 8, .size
= 4 },
441 static struct clksrc_clk clk_sclk_uclk
= {
445 .enable
= s5p64x0_sclk_ctrl
,
447 .sources
= &clkset_uart
,
448 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 13, .size
= 1 },
449 .reg_div
= { .reg
= S5P64X0_CLK_DIV2
, .shift
= 16, .size
= 4 },
452 static struct clk clk_i2s0
= {
454 .devname
= "samsung-i2s.0",
455 .parent
= &clk_pclk_low
.clk
,
456 .enable
= s5p64x0_pclk_ctrl
,
457 .ctrlbit
= (1 << 26),
460 static struct clksrc_clk clk_audio_bus2
= {
462 .name
= "sclk_audio2",
463 .devname
= "samsung-i2s.0",
464 .ctrlbit
= (1 << 11),
465 .enable
= s5p64x0_sclk_ctrl
,
467 .sources
= &clkset_audio
,
468 .reg_src
= { .reg
= S5P64X0_CLK_SRC1
, .shift
= 0, .size
= 3 },
469 .reg_div
= { .reg
= S5P64X0_CLK_DIV2
, .shift
= 24, .size
= 4 },
472 static struct clksrc_clk clk_sclk_spi0
= {
475 .devname
= "s5p64x0-spi.0",
476 .ctrlbit
= (1 << 20),
477 .enable
= s5p64x0_sclk_ctrl
,
479 .sources
= &clkset_group1
,
480 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 14, .size
= 2 },
481 .reg_div
= { .reg
= S5P64X0_CLK_DIV2
, .shift
= 0, .size
= 4 },
484 static struct clksrc_clk clk_sclk_spi1
= {
487 .devname
= "s5p64x0-spi.1",
488 .ctrlbit
= (1 << 21),
489 .enable
= s5p64x0_sclk_ctrl
,
491 .sources
= &clkset_group1
,
492 .reg_src
= { .reg
= S5P64X0_CLK_SRC0
, .shift
= 16, .size
= 2 },
493 .reg_div
= { .reg
= S5P64X0_CLK_DIV2
, .shift
= 4, .size
= 4 },
496 /* Clock initialization code */
497 static struct clksrc_clk
*sysclks
[] = {
509 static struct clk dummy_apb_pclk
= {
514 static struct clk
*clk_cdev
[] = {
518 static struct clksrc_clk
*clksrc_cdev
[] = {
528 static struct clk_lookup s5p6440_clk_lookup
[] = {
529 CLKDEV_INIT(NULL
, "clk_uart_baud2", &clk_pclk_low
.clk
),
530 CLKDEV_INIT(NULL
, "clk_uart_baud3", &clk_sclk_uclk
.clk
),
531 CLKDEV_INIT(NULL
, "spi_busclk0", &clk_p
),
532 CLKDEV_INIT("s5p64x0-spi.0", "spi_busclk1", &clk_sclk_spi0
.clk
),
533 CLKDEV_INIT("s5p64x0-spi.1", "spi_busclk1", &clk_sclk_spi1
.clk
),
534 CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.2", &clk_sclk_mmc0
.clk
),
535 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &clk_sclk_mmc1
.clk
),
536 CLKDEV_INIT("s3c-sdhci.2", "mmc_busclk.2", &clk_sclk_mmc2
.clk
),
537 CLKDEV_INIT("samsung-i2s.0", "i2s_opclk0", &clk_i2s0
),
538 CLKDEV_INIT("samsung-i2s.0", "i2s_opclk1", &clk_audio_bus2
.clk
),
541 void __init_or_cpufreq
s5p6440_setup_clocks(void)
543 struct clk
*xtal_clk
;
548 unsigned long hclk_low
;
550 unsigned long pclk_low
;
557 /* Set S5P6440 functions for clk_fout_epll */
559 clk_fout_epll
.enable
= s5p_epll_enable
;
560 clk_fout_epll
.ops
= &s5p6440_epll_ops
;
562 clk_48m
.enable
= s5p64x0_clk48m_ctrl
;
564 xtal_clk
= clk_get(NULL
, "ext_xtal");
565 BUG_ON(IS_ERR(xtal_clk
));
567 xtal
= clk_get_rate(xtal_clk
);
570 apll
= s5p_get_pll45xx(xtal
, __raw_readl(S5P64X0_APLL_CON
), pll_4502
);
571 mpll
= s5p_get_pll45xx(xtal
, __raw_readl(S5P64X0_MPLL_CON
), pll_4502
);
572 epll
= s5p_get_pll90xx(xtal
, __raw_readl(S5P64X0_EPLL_CON
),
573 __raw_readl(S5P64X0_EPLL_CON_K
));
575 clk_fout_apll
.rate
= apll
;
576 clk_fout_mpll
.rate
= mpll
;
577 clk_fout_epll
.rate
= epll
;
579 printk(KERN_INFO
"S5P6440: PLL settings, A=%ld.%ldMHz, M=%ld.%ldMHz," \
581 print_mhz(apll
), print_mhz(mpll
), print_mhz(epll
));
583 fclk
= clk_get_rate(&clk_armclk
.clk
);
584 hclk
= clk_get_rate(&clk_hclk
.clk
);
585 pclk
= clk_get_rate(&clk_pclk
.clk
);
586 hclk_low
= clk_get_rate(&clk_hclk_low
.clk
);
587 pclk_low
= clk_get_rate(&clk_pclk_low
.clk
);
589 printk(KERN_INFO
"S5P6440: HCLK=%ld.%ldMHz, HCLK_LOW=%ld.%ldMHz," \
590 " PCLK=%ld.%ldMHz, PCLK_LOW=%ld.%ldMHz\n",
591 print_mhz(hclk
), print_mhz(hclk_low
),
592 print_mhz(pclk
), print_mhz(pclk_low
));
598 for (ptr
= 0; ptr
< ARRAY_SIZE(clksrcs
); ptr
++)
599 s3c_set_clksrc(&clksrcs
[ptr
], true);
602 static struct clk
*clks
[] __initdata
= {
608 void __init
s5p6440_register_clocks(void)
613 s3c24xx_register_clocks(clks
, ARRAY_SIZE(clks
));
615 for (ptr
= 0; ptr
< ARRAY_SIZE(sysclks
); ptr
++)
616 s3c_register_clksrc(sysclks
[ptr
], 1);
618 s3c24xx_register_clocks(clk_cdev
, ARRAY_SIZE(clk_cdev
));
619 for (cnt
= 0; cnt
< ARRAY_SIZE(clk_cdev
); cnt
++)
620 s3c_disable_clocks(clk_cdev
[cnt
], 1);
622 s3c_register_clksrc(clksrcs
, ARRAY_SIZE(clksrcs
));
623 s3c_register_clocks(init_clocks
, ARRAY_SIZE(init_clocks
));
624 for (ptr
= 0; ptr
< ARRAY_SIZE(clksrc_cdev
); ptr
++)
625 s3c_register_clksrc(clksrc_cdev
[ptr
], 1);
627 s3c_register_clocks(init_clocks_off
, ARRAY_SIZE(init_clocks_off
));
628 s3c_disable_clocks(init_clocks_off
, ARRAY_SIZE(init_clocks_off
));
629 clkdev_add_table(s5p6440_clk_lookup
, ARRAY_SIZE(s5p6440_clk_lookup
));
631 s3c24xx_register_clock(&dummy_apb_pclk
);