docbook: fix fatal rapidio yet again (and more to come)
[linux/fpc-iii.git] / arch / sh / kernel / cpu / sh4a / clock-sh7343.c
blob7adc4f16e95ae4f3fd66a8ea384e6244ad16c095
1 /*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7343.c
4 * SH7343/SH7722 support for the clock framework
6 * Copyright (C) 2006 Paul Mundt
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/io.h>
15 #include <asm/clock.h>
16 #include <asm/freq.h>
19 * SH7343/SH7722 uses a common set of multipliers and divisors, so this
20 * is quite simple..
22 static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
23 static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
25 #define pll_calc() (((ctrl_inl(FRQCR) >> 24) & 0x1f) + 1)
27 static void master_clk_init(struct clk *clk)
29 clk->parent = clk_get(NULL, "cpu_clk");
32 static void master_clk_recalc(struct clk *clk)
34 int idx = (ctrl_inl(FRQCR) & 0x000f);
35 clk->rate *= clk->parent->rate * multipliers[idx] / divisors[idx];
38 static struct clk_ops sh7343_master_clk_ops = {
39 .init = master_clk_init,
40 .recalc = master_clk_recalc,
43 static void module_clk_init(struct clk *clk)
45 clk->parent = NULL;
46 clk->rate = CONFIG_SH_PCLK_FREQ;
49 static struct clk_ops sh7343_module_clk_ops = {
50 .init = module_clk_init,
53 static void bus_clk_init(struct clk *clk)
55 clk->parent = clk_get(NULL, "cpu_clk");
58 static void bus_clk_recalc(struct clk *clk)
60 int idx = (ctrl_inl(FRQCR) >> 8) & 0x000f;
61 clk->rate = clk->parent->rate * multipliers[idx] / divisors[idx];
64 static struct clk_ops sh7343_bus_clk_ops = {
65 .init = bus_clk_init,
66 .recalc = bus_clk_recalc,
69 static void cpu_clk_init(struct clk *clk)
71 clk->parent = clk_get(NULL, "module_clk");
72 clk->flags |= CLK_RATE_PROPAGATES;
73 clk_set_rate(clk, clk_get_rate(clk));
76 static void cpu_clk_recalc(struct clk *clk)
78 int idx = (ctrl_inl(FRQCR) >> 20) & 0x000f;
79 clk->rate = clk->parent->rate * pll_calc() *
80 multipliers[idx] / divisors[idx];
83 static struct clk_ops sh7343_cpu_clk_ops = {
84 .init = cpu_clk_init,
85 .recalc = cpu_clk_recalc,
88 static struct clk_ops *sh7343_clk_ops[] = {
89 &sh7343_master_clk_ops,
90 &sh7343_module_clk_ops,
91 &sh7343_bus_clk_ops,
92 &sh7343_cpu_clk_ops,
95 void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
97 if (idx < ARRAY_SIZE(sh7343_clk_ops))
98 *ops = sh7343_clk_ops[idx];