Pull button into test branch
[linux-drm-fsl-dcu.git] / arch / sh / kernel / cpu / sh3 / clock-sh7709.c
1 /*
2  * arch/sh/kernel/cpu/sh3/clock-sh7709.c
3  *
4  * SH7709 support for the clock framework
5  *
6  *  Copyright (C) 2005  Andriy Skulysh
7  *
8  * Based on arch/sh/kernel/cpu/sh3/clock-sh7705.c
9  *  Copyright (C) 2005  Paul Mundt
10  *
11  * This file is subject to the terms and conditions of the GNU General Public
12  * License.  See the file "COPYING" in the main directory of this archive
13  * for more details.
14  */
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <asm/clock.h>
18 #include <asm/freq.h>
19 #include <asm/io.h>
20
21 static int stc_multipliers[] = { 1, 2, 4, 8, 3, 6, 1, 1 };
22 static int ifc_divisors[]    = { 1, 2, 4, 1, 3, 1, 1, 1 };
23 static int pfc_divisors[]    = { 1, 2, 4, 1, 3, 6, 1, 1 };
24
25 static void set_bus_parent(struct clk *clk)
26 {
27         struct clk *bus_clk = clk_get(NULL, "bus_clk");
28         clk->parent = bus_clk;
29         clk_put(bus_clk);
30 }
31
32 static void master_clk_init(struct clk *clk)
33 {
34         int frqcr = ctrl_inw(FRQCR);
35         int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
36
37         clk->rate *= pfc_divisors[idx];
38 }
39
40 static struct clk_ops sh7709_master_clk_ops = {
41         .init           = master_clk_init,
42 };
43
44 static void module_clk_recalc(struct clk *clk)
45 {
46         int frqcr = ctrl_inw(FRQCR);
47         int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
48
49         clk->rate = clk->parent->rate / pfc_divisors[idx];
50 }
51
52 static struct clk_ops sh7709_module_clk_ops = {
53 #ifdef CLOCK_MODE_0_1_2_7
54         .init           = set_bus_parent,
55 #endif
56         .recalc         = module_clk_recalc,
57 };
58
59 static void bus_clk_recalc(struct clk *clk)
60 {
61         int frqcr = ctrl_inw(FRQCR);
62         int idx = (frqcr & 0x0080) ?
63                 ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1;
64
65         clk->rate = clk->parent->rate * stc_multipliers[idx];
66 }
67
68 static struct clk_ops sh7709_bus_clk_ops = {
69         .recalc         = bus_clk_recalc,
70 };
71
72 static void cpu_clk_recalc(struct clk *clk)
73 {
74         int frqcr = ctrl_inw(FRQCR);
75         int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
76
77         clk->rate = clk->parent->rate / ifc_divisors[idx];
78 }
79
80 static struct clk_ops sh7709_cpu_clk_ops = {
81         .init           = set_bus_parent,
82         .recalc         = cpu_clk_recalc,
83 };
84
85 static struct clk_ops *sh7709_clk_ops[] = {
86         &sh7709_master_clk_ops,
87         &sh7709_module_clk_ops,
88         &sh7709_bus_clk_ops,
89         &sh7709_cpu_clk_ops,
90 };
91
92 void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
93 {
94         if (idx < ARRAY_SIZE(sh7709_clk_ops))
95                 *ops = sh7709_clk_ops[idx];
96 }