blob: 196fb37f4b19750b71c11ad2132c7324da5db330 [file] [log] [blame]
Ben Dooks8d6f8652010-04-30 11:12:58 +09001/* linux/arch/arm/mach-s3c2416/clock.c
2 *
3 * Copyright (c) 2010 Simtec Electronics
4 * Copyright (c) 2010 Ben Dooks <ben-linux@fluff.org>
5 *
6 * S3C2416 Clock control support
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/init.h>
15#include <linux/clk.h>
16
17#include <plat/s3c2416.h>
18#include <plat/s3c2443.h>
19#include <plat/clock.h>
20#include <plat/clock-clksrc.h>
21#include <plat/cpu.h>
22
23#include <plat/cpu-freq.h>
24#include <plat/pll6553x.h>
25#include <plat/pll.h>
26
27#include <asm/mach/map.h>
28
29#include <mach/regs-clock.h>
30#include <mach/regs-s3c2443-clock.h>
31
32static unsigned int armdiv[8] = {
33 [0] = 1,
34 [1] = 2,
35 [2] = 3,
36 [3] = 4,
37 [5] = 6,
38 [7] = 8,
39};
40
Heiko Stuebner4a43c662011-09-27 08:45:09 +090041static struct clksrc_clk hsspi_eplldiv = {
42 .clk = {
43 .name = "hsspi-eplldiv",
44 .parent = &clk_esysclk.clk,
45 .ctrlbit = (1 << 14),
46 .enable = s3c2443_clkcon_enable_s,
47 },
48 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 24 },
49};
50
51static struct clk *hsspi_sources[] = {
52 [0] = &hsspi_eplldiv.clk,
53 [1] = NULL, /* to fix */
54};
55
56static struct clksrc_clk hsspi_mux = {
57 .clk = {
58 .name = "hsspi-if",
59 },
60 .sources = &(struct clksrc_sources) {
61 .sources = hsspi_sources,
62 .nr_sources = ARRAY_SIZE(hsspi_sources),
63 },
64 .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 18 },
65};
66
Ben Dooks8d6f8652010-04-30 11:12:58 +090067static struct clksrc_clk hsmmc_div[] = {
68 [0] = {
69 .clk = {
70 .name = "hsmmc-div",
Thomas Abrahame83626f2011-06-14 19:12:26 +090071 .devname = "s3c-sdhci.0",
Ben Dooks8d6f8652010-04-30 11:12:58 +090072 .parent = &clk_esysclk.clk,
73 },
74 .reg_div = { .reg = S3C2416_CLKDIV2, .size = 2, .shift = 6 },
75 },
76 [1] = {
77 .clk = {
78 .name = "hsmmc-div",
Thomas Abrahame83626f2011-06-14 19:12:26 +090079 .devname = "s3c-sdhci.1",
Ben Dooks8d6f8652010-04-30 11:12:58 +090080 .parent = &clk_esysclk.clk,
81 },
82 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
83 },
84};
85
86static struct clksrc_clk hsmmc_mux[] = {
87 [0] = {
88 .clk = {
Ben Dooks8d6f8652010-04-30 11:12:58 +090089 .name = "hsmmc-if",
Thomas Abrahame83626f2011-06-14 19:12:26 +090090 .devname = "s3c-sdhci.0",
Ben Dooks8d6f8652010-04-30 11:12:58 +090091 .ctrlbit = (1 << 6),
92 .enable = s3c2443_clkcon_enable_s,
93 },
94 .sources = &(struct clksrc_sources) {
95 .nr_sources = 2,
96 .sources = (struct clk *[]) {
97 [0] = &hsmmc_div[0].clk,
98 [1] = NULL, /* to fix */
99 },
100 },
101 .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 16 },
102 },
103 [1] = {
104 .clk = {
Ben Dooks8d6f8652010-04-30 11:12:58 +0900105 .name = "hsmmc-if",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900106 .devname = "s3c-sdhci.1",
Ben Dooks8d6f8652010-04-30 11:12:58 +0900107 .ctrlbit = (1 << 12),
108 .enable = s3c2443_clkcon_enable_s,
109 },
110 .sources = &(struct clksrc_sources) {
111 .nr_sources = 2,
112 .sources = (struct clk *[]) {
113 [0] = &hsmmc_div[1].clk,
114 [1] = NULL, /* to fix */
115 },
116 },
117 .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 17 },
118 },
119};
120
Yauhen Kharuzhy95d67912011-01-06 13:04:33 +0900121static struct clk hsmmc0_clk = {
122 .name = "hsmmc",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900123 .devname = "s3c-sdhci.0",
Yauhen Kharuzhy95d67912011-01-06 13:04:33 +0900124 .parent = &clk_h,
125 .enable = s3c2443_clkcon_enable_h,
126 .ctrlbit = S3C2416_HCLKCON_HSMMC0,
127};
Ben Dooks8d6f8652010-04-30 11:12:58 +0900128
129static inline unsigned int s3c2416_fclk_div(unsigned long clkcon0)
130{
131 clkcon0 &= 7 << S3C2443_CLKDIV0_ARMDIV_SHIFT;
132
133 return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
134}
135
136void __init_or_cpufreq s3c2416_setup_clocks(void)
137{
138 s3c2443_common_setup_clocks(s3c2416_get_pll, s3c2416_fclk_div);
139}
140
141
142static struct clksrc_clk *clksrcs[] __initdata = {
Heiko Stuebner4a43c662011-09-27 08:45:09 +0900143 &hsspi_eplldiv,
144 &hsspi_mux,
Ben Dooks8d6f8652010-04-30 11:12:58 +0900145 &hsmmc_div[0],
146 &hsmmc_div[1],
147 &hsmmc_mux[0],
148 &hsmmc_mux[1],
149};
150
151void __init s3c2416_init_clocks(int xtal)
152{
153 u32 epllcon = __raw_readl(S3C2443_EPLLCON);
154 u32 epllcon1 = __raw_readl(S3C2443_EPLLCON+4);
155 int ptr;
156
157 /* s3c2416 EPLL compatible with s3c64xx */
158 clk_epll.rate = s3c_get_pll6553x(xtal, epllcon, epllcon1);
159
160 clk_epll.parent = &clk_epllref.clk;
161
162 s3c2443_common_init_clocks(xtal, s3c2416_get_pll, s3c2416_fclk_div);
163
164 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
165 s3c_register_clksrc(clksrcs[ptr], 1);
166
Yauhen Kharuzhy95d67912011-01-06 13:04:33 +0900167 s3c24xx_register_clock(&hsmmc0_clk);
168
Ben Dooks8d6f8652010-04-30 11:12:58 +0900169 s3c_pwmclk_init();
170
171}