2 * linux/arch/arm/mach-pxa/clock-pxa3xx.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
13 #include <linux/syscore_ops.h>
15 #include <mach/smemc.h>
16 #include <mach/pxa3xx-regs.h>
20 /* Crystal clock: 13MHz */
21 #define BASE_CLK 13000000
23 /* Ring Oscillator Clock: 60MHz */
24 #define RO_CLK 60000000
26 #define ACCR_D0CS (1 << 26)
27 #define ACCR_PCCE (1 << 11)
29 /* crystal frequency to HSIO bus frequency multiplier (HSS) */
30 static unsigned char hss_mult[4] = { 8, 12, 16, 24 };
33 * Get the clock frequency as reflected by CCSR and the turbo flag.
34 * We assume these values have been applied via a fcs.
35 * If info is not 0 we also display the current settings.
37 unsigned int pxa3xx_get_clk_frequency_khz(int info)
39 unsigned long acsr, xclkcfg;
40 unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
42 /* Read XCLKCFG register turbo bit */
43 __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
49 xn = (acsr >> 8) & 0x7;
50 hss = (acsr >> 14) & 0x3;
55 ro = acsr & ACCR_D0CS;
57 CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
58 HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
61 pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
62 RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
64 pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
65 XL / 1000000, (XL % 1000000) / 10000, xl);
66 pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
67 XN / 1000000, (XN % 1000000) / 10000, xn,
69 pr_info("HSIO bus clock: %d.%02dMHz\n",
70 HSS / 1000000, (HSS % 1000000) / 10000);
77 * Return the current AC97 clock frequency.
79 static unsigned long clk_pxa3xx_ac97_getrate(struct clk *clk)
81 unsigned long rate = 312000000;
82 unsigned long ac97_div;
86 /* This may loose precision for some rates but won't for the
89 rate /= (ac97_div >> 12) & 0x7fff;
90 rate *= (ac97_div & 0xfff);
96 * Return the current HSIO bus clock frequency
98 static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
101 unsigned int hss, hsio_clk;
105 hss = (acsr >> 14) & 0x3;
106 hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
111 /* crystal frequency to static memory controller multiplier (SMCFS) */
112 static unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
113 static unsigned int df_clkdiv[4] = { 1, 2, 4, 1 };
115 static unsigned long clk_pxa3xx_smemc_getrate(struct clk *clk)
117 unsigned long acsr = ACSR;
118 unsigned long memclkcfg = __raw_readl(MEMCLKCFG);
120 return BASE_CLK * smcfs_mult[(acsr >> 23) & 0x7] /
121 df_clkdiv[(memclkcfg >> 16) & 0x3];
124 void clk_pxa3xx_cken_enable(struct clk *clk)
126 unsigned long mask = 1ul << (clk->cken & 0x1f);
130 else if (clk->cken < 64)
136 void clk_pxa3xx_cken_disable(struct clk *clk)
138 unsigned long mask = 1ul << (clk->cken & 0x1f);
142 else if (clk->cken < 64)
148 const struct clkops clk_pxa3xx_cken_ops = {
149 .enable = clk_pxa3xx_cken_enable,
150 .disable = clk_pxa3xx_cken_disable,
153 const struct clkops clk_pxa3xx_hsio_ops = {
154 .enable = clk_pxa3xx_cken_enable,
155 .disable = clk_pxa3xx_cken_disable,
156 .getrate = clk_pxa3xx_hsio_getrate,
159 const struct clkops clk_pxa3xx_ac97_ops = {
160 .enable = clk_pxa3xx_cken_enable,
161 .disable = clk_pxa3xx_cken_disable,
162 .getrate = clk_pxa3xx_ac97_getrate,
165 const struct clkops clk_pxa3xx_smemc_ops = {
166 .enable = clk_pxa3xx_cken_enable,
167 .disable = clk_pxa3xx_cken_disable,
168 .getrate = clk_pxa3xx_smemc_getrate,
171 static void clk_pout_enable(struct clk *clk)
176 static void clk_pout_disable(struct clk *clk)
181 const struct clkops clk_pxa3xx_pout_ops = {
182 .enable = clk_pout_enable,
183 .disable = clk_pout_disable,
187 static uint32_t cken[2];
188 static uint32_t accr;
190 static int pxa3xx_clock_suspend(void)
198 static void pxa3xx_clock_resume(void)
205 #define pxa3xx_clock_suspend NULL
206 #define pxa3xx_clock_resume NULL
209 struct syscore_ops pxa3xx_clock_syscore_ops = {
210 .suspend = pxa3xx_clock_suspend,
211 .resume = pxa3xx_clock_resume,