2 * arch/sh/kernel/cpu/sh4a/clock-sh7785.c
4 * SH7785 support for the clock framework
6 * Copyright (C) 2007 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
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <asm/clock.h>
18 static int ifc_divisors
[] = { 1, 2, 4, 6 };
19 static int ufc_divisors
[] = { 1, 1, 4, 6 };
20 static int sfc_divisors
[] = { 1, 1, 4, 6 };
21 static int bfc_divisors
[] = { 1, 1, 1, 1, 1, 12, 16, 18,
22 24, 32, 36, 48, 1, 1, 1, 1 };
23 static int mfc_divisors
[] = { 1, 1, 4, 6 };
24 static int pfc_divisors
[] = { 1, 1, 1, 1, 1, 1, 1, 18,
25 24, 32, 36, 48, 1, 1, 1, 1 };
27 static void master_clk_init(struct clk
*clk
)
32 static struct clk_ops sh7785_master_clk_ops
= {
33 .init
= master_clk_init
,
36 static void module_clk_recalc(struct clk
*clk
)
38 int idx
= (ctrl_inl(FRQMR1
) & 0x000f);
39 clk
->rate
= clk
->parent
->rate
/ pfc_divisors
[idx
];
42 static struct clk_ops sh7785_module_clk_ops
= {
43 .recalc
= module_clk_recalc
,
46 static void bus_clk_recalc(struct clk
*clk
)
48 int idx
= ((ctrl_inl(FRQMR1
) >> 16) & 0x000f);
49 clk
->rate
= clk
->parent
->rate
/ bfc_divisors
[idx
];
52 static struct clk_ops sh7785_bus_clk_ops
= {
53 .recalc
= bus_clk_recalc
,
56 static void cpu_clk_recalc(struct clk
*clk
)
58 int idx
= ((ctrl_inl(FRQMR1
) >> 28) & 0x0003);
59 clk
->rate
= clk
->parent
->rate
/ ifc_divisors
[idx
];
62 static struct clk_ops sh7785_cpu_clk_ops
= {
63 .recalc
= cpu_clk_recalc
,
66 static struct clk_ops
*sh7785_clk_ops
[] = {
67 &sh7785_master_clk_ops
,
68 &sh7785_module_clk_ops
,
73 void __init
arch_init_clk_ops(struct clk_ops
**ops
, int idx
)
75 if (idx
< ARRAY_SIZE(sh7785_clk_ops
))
76 *ops
= sh7785_clk_ops
[idx
];
79 static void shyway_clk_recalc(struct clk
*clk
)
81 int idx
= ((ctrl_inl(FRQMR1
) >> 20) & 0x0003);
82 clk
->rate
= clk
->parent
->rate
/ sfc_divisors
[idx
];
85 static struct clk_ops sh7785_shyway_clk_ops
= {
86 .recalc
= shyway_clk_recalc
,
89 static struct clk sh7785_shyway_clk
= {
91 .flags
= CLK_ALWAYS_ENABLED
,
92 .ops
= &sh7785_shyway_clk_ops
,
95 static void ddr_clk_recalc(struct clk
*clk
)
97 int idx
= ((ctrl_inl(FRQMR1
) >> 12) & 0x0003);
98 clk
->rate
= clk
->parent
->rate
/ mfc_divisors
[idx
];
101 static struct clk_ops sh7785_ddr_clk_ops
= {
102 .recalc
= ddr_clk_recalc
,
105 static struct clk sh7785_ddr_clk
= {
107 .flags
= CLK_ALWAYS_ENABLED
,
108 .ops
= &sh7785_ddr_clk_ops
,
111 static void ram_clk_recalc(struct clk
*clk
)
113 int idx
= ((ctrl_inl(FRQMR1
) >> 24) & 0x0003);
114 clk
->rate
= clk
->parent
->rate
/ ufc_divisors
[idx
];
117 static struct clk_ops sh7785_ram_clk_ops
= {
118 .recalc
= ram_clk_recalc
,
121 static struct clk sh7785_ram_clk
= {
123 .flags
= CLK_ALWAYS_ENABLED
,
124 .ops
= &sh7785_ram_clk_ops
,
128 * Additional SH7785-specific on-chip clocks that aren't already part of the
131 static struct clk
*sh7785_onchip_clocks
[] = {
137 static int __init
sh7785_clk_init(void)
139 struct clk
*clk
= clk_get(NULL
, "master_clk");
142 for (i
= 0; i
< ARRAY_SIZE(sh7785_onchip_clocks
); i
++) {
143 struct clk
*clkp
= sh7785_onchip_clocks
[i
];
151 * Now that we have the rest of the clocks registered, we need to
152 * force the parent clock to propagate so that these clocks will
153 * automatically figure out their rate. We cheat by handing the
154 * parent clock its current rate and forcing child propagation.
156 clk_set_rate(clk
, clk_get_rate(clk
));
162 arch_initcall(sh7785_clk_init
);