blob: 76cd31f7804e45e35d01c6c9f191fc06051c9d07 [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>
Kay Sieversedbaa602011-12-21 16:26:03 -080030#include <linux/device.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010031#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 Dooksd5120ae2008-10-07 23:09:51 +010044#include <plat/clock.h>
Ben Dooks9aa753c2010-01-30 09:19:59 +020045#include <plat/clock-clksrc.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010046#include <plat/cpu.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010047
48/* We currently have to assume that the system is running
49 * from the XTPll input, and that all ***REFCLKs are being
50 * fed from it, as we cannot read the state of OM[4] from
51 * software.
52 *
53 * It would be possible for each board initialisation to
54 * set the correct muxing at initialisation
55*/
56
Ben Dookse4d06e32007-02-16 12:12:31 +010057/* clock selections */
58
Ben Dooksba7622a2008-07-07 18:12:39 +010059/* armdiv
60 *
61 * this clock is sourced from msysclk and can have a number of
62 * divider values applied to it to then be fed into armclk.
Heiko St?bneraab08ee2011-10-14 15:08:56 +090063 * The real clock definition is done in s3c2443-clock.c,
64 * only the armdiv divisor table must be defined here.
Ben Dooksba7622a2008-07-07 18:12:39 +010065*/
66
Ben Dooks41f23a02010-01-30 11:14:14 +020067static unsigned int armdiv[16] = {
68 [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
69 [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
70 [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
71 [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
72 [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
73 [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
74 [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
75 [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
76};
77
Ben Dookse4d06e32007-02-16 12:12:31 +010078/* hsspi
79 *
80 * high-speed spi clock, sourced from esysclk
81*/
82
Ben Dooks9aa753c2010-01-30 09:19:59 +020083static struct clksrc_clk clk_hsspi = {
84 .clk = {
Heiko Stuebner8b069b72011-09-27 08:45:23 +090085 .name = "hsspi-if",
Ben Dooks4bed36b2010-01-30 10:25:49 +020086 .parent = &clk_esysclk.clk,
Ben Dooks9aa753c2010-01-30 09:19:59 +020087 .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
88 .enable = s3c2443_clkcon_enable_s,
Ben Dooksb3bf41b2009-12-01 01:24:37 +000089 },
Ben Dooks9aa753c2010-01-30 09:19:59 +020090 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
Ben Dookse4d06e32007-02-16 12:12:31 +010091};
92
Ben Dookse4d06e32007-02-16 12:12:31 +010093
94/* clk_hsmcc_div
95 *
96 * this clock is sourced from epll, and is fed through a divider,
97 * to a mux controlled by sclkcon where either it or a extclk can
98 * be fed to the hsmmc block
99*/
100
Ben Dooks9aa753c2010-01-30 09:19:59 +0200101static struct clksrc_clk clk_hsmmc_div = {
102 .clk = {
103 .name = "hsmmc-div",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900104 .devname = "s3c-sdhci.1",
Ben Dooks4bed36b2010-01-30 10:25:49 +0200105 .parent = &clk_esysclk.clk,
Ben Dooksb3bf41b2009-12-01 01:24:37 +0000106 },
Ben Dooks9aa753c2010-01-30 09:19:59 +0200107 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
Ben Dookse4d06e32007-02-16 12:12:31 +0100108};
109
110static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
111{
112 unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
113
114 clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
115 S3C2443_SCLKCON_HSMMCCLK_EPLL);
116
117 if (parent == &clk_epll)
118 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
119 else if (parent == &clk_ext)
120 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
121 else
122 return -EINVAL;
123
124 if (clk->usage > 0) {
125 __raw_writel(clksrc, S3C2443_SCLKCON);
126 }
127
128 clk->parent = parent;
129 return 0;
130}
131
132static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
133{
134 return s3c2443_setparent_hsmmc(clk, clk->parent);
135}
136
137static struct clk clk_hsmmc = {
138 .name = "hsmmc-if",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900139 .devname = "s3c-sdhci.1",
Ben Dooks9aa753c2010-01-30 09:19:59 +0200140 .parent = &clk_hsmmc_div.clk,
Ben Dookse4d06e32007-02-16 12:12:31 +0100141 .enable = s3c2443_enable_hsmmc,
Ben Dooksb3bf41b2009-12-01 01:24:37 +0000142 .ops = &(struct clk_ops) {
143 .set_parent = s3c2443_setparent_hsmmc,
144 },
Ben Dookse4d06e32007-02-16 12:12:31 +0100145};
146
Ben Dookse4d06e32007-02-16 12:12:31 +0100147/* standard clock definitions */
148
Ben Dooks4e046912010-04-28 12:58:13 +0900149static struct clk init_clocks_off[] = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100150 {
Ben Dookse4d06e32007-02-16 12:12:31 +0100151 .name = "sdi",
Ben Dookse4d06e32007-02-16 12:12:31 +0100152 .parent = &clk_p,
153 .enable = s3c2443_clkcon_enable_p,
154 .ctrlbit = S3C2443_PCLKCON_SDI,
155 }, {
Ben Dookse4d06e32007-02-16 12:12:31 +0100156 .name = "spi",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900157 .devname = "s3c2410-spi.0",
Ben Dookse4d06e32007-02-16 12:12:31 +0100158 .parent = &clk_p,
159 .enable = s3c2443_clkcon_enable_p,
Ben Dookse4d06e32007-02-16 12:12:31 +0100160 .ctrlbit = S3C2443_PCLKCON_SPI1,
161 }
162};
163
Ben Dookse4d06e32007-02-16 12:12:31 +0100164/* clocks to add straight away */
165
Ben Dooks9aa753c2010-01-30 09:19:59 +0200166static struct clksrc_clk *clksrcs[] __initdata = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100167 &clk_hsspi,
168 &clk_hsmmc_div,
Ben Dooks9aa753c2010-01-30 09:19:59 +0200169};
170
171static struct clk *clks[] __initdata = {
Ben Dookse4d06e32007-02-16 12:12:31 +0100172 &clk_hsmmc,
173};
174
Heiko Stuebnerd25a8f92012-04-24 18:06:49 -0700175static struct clk_lookup s3c2443_clk_lookup[] = {
176 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &clk_hsmmc),
Thomas Abrahama5238e32012-07-13 07:15:14 +0900177 CLKDEV_INIT("s3c2443-spi.0", "spi_busclk2", &clk_hsspi.clk),
Heiko Stuebnerd25a8f92012-04-24 18:06:49 -0700178};
179
Ben Dookse4253822008-10-21 14:06:38 +0100180void __init s3c2443_init_clocks(int xtal)
181{
Ben Dookse4253822008-10-21 14:06:38 +0100182 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
Ben Dookse4253822008-10-21 14:06:38 +0100183 int ptr;
184
Ben Dooksaf337f32010-04-28 18:03:57 +0900185 clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
186 clk_epll.parent = &clk_epllref.clk;
Ben Dookse4253822008-10-21 14:06:38 +0100187
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900188 s3c2443_common_init_clocks(xtal, s3c2443_get_mpll,
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900189 armdiv, ARRAY_SIZE(armdiv),
190 S3C2443_CLKDIV0_ARMDIV_MASK);
Ben Dooksaf337f32010-04-28 18:03:57 +0900191
Ben Dooks4e046912010-04-28 12:58:13 +0900192 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
Ben Dookse4d06e32007-02-16 12:12:31 +0100193
Ben Dooks9aa753c2010-01-30 09:19:59 +0200194 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
195 s3c_register_clksrc(clksrcs[ptr], 1);
196
Ben Dookse4d06e32007-02-16 12:12:31 +0100197 /* We must be careful disabling the clocks we are not intending to
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200198 * be using at boot time, as subsystems such as the LCD which do
Ben Dookse4d06e32007-02-16 12:12:31 +0100199 * their own DMA requests to the bus can cause the system to lockup
200 * if they where in the middle of requesting bus access.
201 *
202 * Disabling the LCD clock if the LCD is active is very dangerous,
203 * and therefore the bootloader should be careful to not enable
204 * the LCD clock if it is not needed.
205 */
206
207 /* install (and disable) the clocks we do not need immediately */
208
Ben Dooks4e046912010-04-28 12:58:13 +0900209 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
210 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Heiko Stuebnerd25a8f92012-04-24 18:06:49 -0700211 clkdev_add_table(s3c2443_clk_lookup, ARRAY_SIZE(s3c2443_clk_lookup));
Ben Dookse4d06e32007-02-16 12:12:31 +0100212}