13 #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
15 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/string.h>
24 #include <mach/hardware.h>
26 #include <asm/div64.h>
43 static unsigned long get_uart_rate(
struct clk *
clk);
45 static int set_keytchclk_rate(
struct clk *
clk,
unsigned long rate);
46 static int set_div_rate(
struct clk *
clk,
unsigned long rate);
47 static int set_i2s_sclk_rate(
struct clk *
clk,
unsigned long rate);
48 static int set_i2s_lrclk_rate(
struct clk *
clk,
unsigned long rate);
50 static struct clk clk_xtali = {
53 static struct clk clk_uart1 = {
58 .get_rate = get_uart_rate,
60 static struct clk clk_uart2 = {
65 .get_rate = get_uart_rate,
67 static struct clk clk_uart3 = {
72 .get_rate = get_uart_rate,
74 static struct clk clk_pll1 = {
77 static struct clk clk_f = {
80 static struct clk clk_h = {
83 static struct clk clk_p = {
86 static struct clk clk_pll2 = {
89 static struct clk clk_usb_host = {
94 static struct clk clk_keypad = {
99 .set_rate = set_keytchclk_rate,
101 static struct clk clk_spi = {
102 .parent = &clk_xtali,
105 static struct clk clk_pwm = {
106 .parent = &clk_xtali,
110 static struct clk clk_video = {
114 .set_rate = set_div_rate,
117 static struct clk clk_i2s_mclk = {
121 .set_rate = set_div_rate,
124 static struct clk clk_i2s_sclk = {
126 .parent = &clk_i2s_mclk,
129 .set_rate = set_i2s_sclk_rate,
132 static struct clk clk_i2s_lrclk = {
134 .parent = &clk_i2s_sclk,
137 .set_rate = set_i2s_lrclk_rate,
141 static struct clk clk_m2p0 = {
146 static struct clk clk_m2p1 = {
151 static struct clk clk_m2p2 = {
156 static struct clk clk_m2p3 = {
161 static struct clk clk_m2p4 = {
166 static struct clk clk_m2p5 = {
171 static struct clk clk_m2p6 = {
176 static struct clk clk_m2p7 = {
181 static struct clk clk_m2p8 = {
186 static struct clk clk_m2p9 = {
191 static struct clk clk_m2m0 = {
196 static struct clk clk_m2m1 = {
202 #define INIT_CK(dev,con,ck) \
203 { .dev_id = dev, .con_id = con, .clk = ck }
219 INIT_CK(
"ep93xx-i2s",
"mclk", &clk_i2s_mclk),
220 INIT_CK(
"ep93xx-i2s",
"sclk", &clk_i2s_sclk),
221 INIT_CK(
"ep93xx-i2s",
"lrclk", &clk_i2s_lrclk),
267 spin_unlock_irqrestore(&clk_lock, flags);
301 spin_unlock_irqrestore(&clk_lock, flags);
305 static unsigned long get_uart_rate(
struct clk *clk)
326 static int set_keytchclk_rate(
struct clk *clk,
unsigned long rate)
354 static int calc_clk_div(
struct clk *clk,
unsigned long rate,
355 int *psel,
int *esel,
int *pdiv,
int *
div)
358 unsigned long max_rate, actual_rate, mclk_rate, rate_err = -1;
359 int i, found = 0, __div = 0, __pdiv = 0;
363 rate =
min(rate, max_rate);
374 for (i = 0; i < 3; i++) {
381 mclk_rate = mclk->
rate * 2;
384 for (__pdiv = 4; __pdiv <= 6; __pdiv++) {
385 __div = mclk_rate / (rate * __pdiv);
386 if (__div < 2 || __div > 127)
389 actual_rate = mclk_rate / (__pdiv * __div);
391 if (!found ||
abs(actual_rate - rate) < rate_err) {
397 clk->
rate = actual_rate;
398 rate_err =
abs(actual_rate - rate);
410 static int set_div_rate(
struct clk *clk,
unsigned long rate)
412 int err, psel = 0, esel = 0, pdiv = 0, div = 0;
415 err = calc_clk_div(clk, rate, &psel, &esel, &pdiv, &div);
431 static int set_i2s_sclk_rate(
struct clk *clk,
unsigned long rate)
435 if (rate == clk_i2s_mclk.
rate / 2)
438 else if (rate == clk_i2s_mclk.
rate / 4)
448 static int set_i2s_lrclk_rate(
struct clk *clk,
unsigned long rate)
453 if (rate == clk_i2s_sclk.
rate / 32)
456 else if (rate == clk_i2s_sclk.
rate / 64)
459 else if (rate == clk_i2s_sclk.
rate / 128)
479 static char fclk_divisors[] = { 1, 2, 4, 8, 16, 1, 1, 1 };
480 static char hclk_divisors[] = { 1, 2, 4, 5, 6, 8, 16, 32 };
481 static char pclk_divisors[] = { 1, 2, 4, 8 };
486 static unsigned long calc_pll_rate(
u32 config_word)
488 unsigned long long rate;
491 rate = clk_xtali.
rate;
492 rate *= ((config_word >> 11) & 0x1f) + 1;
493 rate *= ((config_word >> 5) & 0x3f) + 1;
494 do_div(rate, (config_word & 0x1f) + 1);
495 for (i = 0; i < ((config_word >> 16) & 3); i++)
498 return (
unsigned long)
rate;
501 static void __init ep93xx_dma_clock_init(
void)
517 static int __init ep93xx_clock_init(
void)
526 clk_pll1.
rate = calc_pll_rate(value);
529 clk_f.
rate = clk_pll1.
rate / fclk_divisors[(value >> 25) & 0x7];
530 clk_h.
rate = clk_pll1.
rate / hclk_divisors[(value >> 20) & 0x7];
531 clk_p.
rate = clk_h.
rate / pclk_divisors[(value >> 18) & 0x3];
532 ep93xx_dma_clock_init();
539 clk_pll2.
rate = calc_pll_rate(value);
544 clk_usb_host.
rate = clk_pll2.
rate / (((value >> 28) & 0xf) + 1);
554 pr_info(
"PLL1 running at %ld MHz, PLL2 at %ld MHz\n",
555 clk_pll1.
rate / 1000000, clk_pll2.
rate / 1000000);
556 pr_info(
"FCLK %ld MHz, HCLK %ld MHz, PCLK %ld MHz\n",
557 clk_f.
rate / 1000000, clk_h.
rate / 1000000,
558 clk_p.
rate / 1000000);