blob: 1c2c088aa2e8dc9c6d743d54a9f655e33e25a9d6 [file] [log] [blame]
Ben Dookse4d06e32007-02-16 12:12:31 +01001/* linux/arch/arm/mach-s3c2443/clock.c
2 *
Ben Dooks4bed36b2010-01-30 10:25:49 +02003 * Copyright (c) 2007, 2010 Simtec Electronics
Ben Dookse4d06e32007-02-16 12:12:31 +01004 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * S3C2443 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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#include <linux/init.h>
Ben Dooksaf337f32010-04-28 18:03:57 +090024
Ben Dookse4d06e32007-02-16 12:12:31 +010025#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/list.h>
28#include <linux/errno.h>
29#include <linux/err.h>
30#include <linux/sysdev.h>
31#include <linux/clk.h>
32#include <linux/mutex.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010033#include <linux/serial_core.h>
Russell Kingfced80c2008-09-06 12:10:45 +010034#include <linux/io.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010035
36#include <asm/mach/map.h>
37
Russell Kinga09e64f2008-08-05 16:14:15 +010038#include <mach/hardware.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010039
Russell Kinga09e64f2008-08-05 16:14:15 +010040#include <mach/regs-s3c2443-clock.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010041
Ben Dookse4253822008-10-21 14:06:38 +010042#include <plat/cpu-freq.h>
43
Ben Dooksa2b7ba92008-10-07 22:26:09 +010044#include <plat/s3c2443.h>
Ben Dooksd5120ae2008-10-07 23:09:51 +010045#include <plat/clock.h>
Ben Dooks9aa753c2010-01-30 09:19:59 +020046#include <plat/clock-clksrc.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010047#include <plat/cpu.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010048
49/* We currently have to assume that the system is running
50 * from the XTPll input, and that all ***REFCLKs are being
51 * fed from it, as we cannot read the state of OM[4] from
52 * software.
53 *
54 * It would be possible for each board initialisation to
55 * set the correct muxing at initialisation
56*/
57
Ben Dookse4d06e32007-02-16 12:12:31 +010058/* clock selections */
59
Ben Dooksba7622a2008-07-07 18:12:39 +010060/* armdiv
61 *
62 * this clock is sourced from msysclk and can have a number of
63 * divider values applied to it to then be fed into armclk.
Heiko St?bneraab08ee2011-10-14 15:08:56 +090064 * The real clock definition is done in s3c2443-clock.c,
65 * only the armdiv divisor table must be defined here.
Ben Dooksba7622a2008-07-07 18:12:39 +010066*/
67
Ben Dooks41f23a02010-01-30 11:14:14 +020068static unsigned int armdiv[16] = {
69 [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
70 [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
71 [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
72 [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
73 [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
74 [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
75 [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
76 [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
77};
78
Ben Dookse4d06e32007-02-16 12:12:31 +010079/* hsspi
80 *
81 * high-speed spi clock, sourced from esysclk
82*/
83
Ben Dooks9aa753c2010-01-30 09:19:59 +020084static struct clksrc_clk clk_hsspi = {
85 .clk = {
Heiko Stuebner8b069b72011-09-27 08:45:23 +090086 .name = "hsspi-if",
Ben Dooks4bed36b2010-01-30 10:25:49 +020087 .parent = &clk_esysclk.clk,
Ben Dooks9aa753c2010-01-30 09:19:59 +020088 .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
89 .enable = s3c2443_clkcon_enable_s,
Ben Dooksb3bf41b2009-12-01 01:24:37 +000090 },
Ben Dooks9aa753c2010-01-30 09:19:59 +020091 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
Ben Dookse4d06e32007-02-16 12:12:31 +010092};
93
Ben Dookse4d06e32007-02-16 12:12:31 +010094
95/* clk_hsmcc_div
96 *
97 * this clock is sourced from epll, and is fed through a divider,
98 * to a mux controlled by sclkcon where either it or a extclk can
99 * be fed to the hsmmc block
100*/
101
Ben Dooks9aa753c2010-01-30 09:19:59 +0200102static struct clksrc_clk clk_hsmmc_div = {
103 .clk = {
104 .name = "hsmmc-div",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900105 .devname = "s3c-sdhci.1",
Ben Dooks4bed36b2010-01-30 10:25:49 +0200106 .parent = &clk_esysclk.clk,
Ben Dooksb3bf41b2009-12-01 01:24:37 +0000107 },
Ben Dooks9aa753c2010-01-30 09:19:59 +0200108 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
Ben Dookse4d06e32007-02-16 12:12:31 +0100109};
110
111static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
112{
113 unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
114
115 clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
116 S3C2443_SCLKCON_HSMMCCLK_EPLL);
117
118 if (parent == &clk_epll)
119 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
120 else if (parent == &clk_ext)
121 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
122 else
123 return -EINVAL;
124
125 if (clk->usage > 0) {
126 __raw_writel(clksrc, S3C2443_SCLKCON);
127 }
128
129 clk->parent = parent;
130 return 0;
131}
132
133static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
134{
135 return s3c2443_setparent_hsmmc(clk, clk->parent);
136}
137
138static struct clk clk_hsmmc = {
139 .name = "hsmmc-if",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900140 .devname = "s3c-sdhci.1",
Ben Dooks9aa753c2010-01-30 09:19:59 +0200141 .parent = &clk_hsmmc_div.clk,
Ben Dookse4d06e32007-02-16 12:12:31 +0100142 .enable = s3c2443_enable_hsmmc,
Ben Dooksb3bf41b2009-12-01 01:24:37 +0000143 .ops = &(struct clk_ops) {
144 .set_parent = s3c2443_setparent_hsmmc,
145 },
Ben Dookse4d06e32007-02-16 12:12:31 +0100146};
147
Ben Dookse4d06e32007-02-16 12:12:31 +0100148/* standard clock definitions */
149
Ben Dooks4e046912010-04-28 12:58:13 +0900150static struct clk init_clocks_off[] = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100151 {
Ben Dookse4d06e32007-02-16 12:12:31 +0100152 .name = "sdi",
Ben Dookse4d06e32007-02-16 12:12:31 +0100153 .parent = &clk_p,
154 .enable = s3c2443_clkcon_enable_p,
155 .ctrlbit = S3C2443_PCLKCON_SDI,
156 }, {
Ben Dookse4d06e32007-02-16 12:12:31 +0100157 .name = "spi",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900158 .devname = "s3c2410-spi.0",
Ben Dookse4d06e32007-02-16 12:12:31 +0100159 .parent = &clk_p,
160 .enable = s3c2443_clkcon_enable_p,
161 .ctrlbit = S3C2443_PCLKCON_SPI0,
162 }, {
163 .name = "spi",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900164 .devname = "s3c2410-spi.1",
Ben Dookse4d06e32007-02-16 12:12:31 +0100165 .parent = &clk_p,
166 .enable = s3c2443_clkcon_enable_p,
167 .ctrlbit = S3C2443_PCLKCON_SPI1,
168 }
169};
170
Ben Dookse4d06e32007-02-16 12:12:31 +0100171/* clocks to add straight away */
172
Ben Dooks9aa753c2010-01-30 09:19:59 +0200173static struct clksrc_clk *clksrcs[] __initdata = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100174 &clk_hsspi,
175 &clk_hsmmc_div,
Ben Dooks9aa753c2010-01-30 09:19:59 +0200176};
177
178static struct clk *clks[] __initdata = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100179 &clk_hsmmc,
180};
181
Ben Dookse4253822008-10-21 14:06:38 +0100182void __init_or_cpufreq s3c2443_setup_clocks(void)
Ben Dookse4d06e32007-02-16 12:12:31 +0100183{
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900184 s3c2443_common_setup_clocks(s3c2443_get_mpll);
Ben Dookse4253822008-10-21 14:06:38 +0100185}
186
187void __init s3c2443_init_clocks(int xtal)
188{
Ben Dookse4253822008-10-21 14:06:38 +0100189 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
Ben Dookse4253822008-10-21 14:06:38 +0100190 int ptr;
191
Ben Dooksaf337f32010-04-28 18:03:57 +0900192 clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
193 clk_epll.parent = &clk_epllref.clk;
Ben Dookse4253822008-10-21 14:06:38 +0100194
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900195 s3c2443_common_init_clocks(xtal, s3c2443_get_mpll,
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900196 armdiv, ARRAY_SIZE(armdiv),
197 S3C2443_CLKDIV0_ARMDIV_MASK);
Ben Dooksaf337f32010-04-28 18:03:57 +0900198
Ben Dookse4253822008-10-21 14:06:38 +0100199 s3c2443_setup_clocks();
Ben Dookse4d06e32007-02-16 12:12:31 +0100200
Ben Dooks4e046912010-04-28 12:58:13 +0900201 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
Ben Dookse4d06e32007-02-16 12:12:31 +0100202
Ben Dooks9aa753c2010-01-30 09:19:59 +0200203 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
204 s3c_register_clksrc(clksrcs[ptr], 1);
205
Ben Dookse4d06e32007-02-16 12:12:31 +0100206 /* We must be careful disabling the clocks we are not intending to
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200207 * be using at boot time, as subsystems such as the LCD which do
Ben Dookse4d06e32007-02-16 12:12:31 +0100208 * their own DMA requests to the bus can cause the system to lockup
209 * if they where in the middle of requesting bus access.
210 *
211 * Disabling the LCD clock if the LCD is active is very dangerous,
212 * and therefore the bootloader should be careful to not enable
213 * the LCD clock if it is not needed.
214 */
215
216 /* install (and disable) the clocks we do not need immediately */
217
Ben Dooks4e046912010-04-28 12:58:13 +0900218 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
219 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Ben Dooks9d325f22008-11-21 10:36:05 +0000220
221 s3c_pwmclk_init();
Ben Dookse4d06e32007-02-16 12:12:31 +0100222}