2 * arch/sh/kernel/cpu/sh4/clock-shx3.c
4 * SH-X3 support for the clock framework
6 * Copyright (C) 2006-2007 Renesas Technology Corp.
7 * Copyright (C) 2006-2007 Renesas Solutions Corp.
8 * Copyright (C) 2006-2007 Paul Mundt
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <asm/clock.h>
20 static int ifc_divisors[] = { 1, 2, 4 ,6 };
21 static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18, 24, 32, 36, 48 };
22 static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18, 24, 32, 36, 48 };
23 static int cfc_divisors[] = { 1, 1, 4, 6 };
26 #define IFC_MSK 0x0003
27 #define BFC_MSK 0x000f
28 #define PFC_MSK 0x000f
29 #define CFC_MSK 0x0003
34 static void master_clk_init(struct clk *clk)
36 clk->rate *= pfc_divisors[(ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK];
39 static struct clk_ops shx3_master_clk_ops = {
40 .init = master_clk_init,
43 static void module_clk_recalc(struct clk *clk)
45 int idx = ((ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK);
46 clk->rate = clk->parent->rate / pfc_divisors[idx];
49 static struct clk_ops shx3_module_clk_ops = {
50 .recalc = module_clk_recalc,
53 static void bus_clk_recalc(struct clk *clk)
55 int idx = ((ctrl_inl(FRQCR) >> BFC_POS) & BFC_MSK);
56 clk->rate = clk->parent->rate / bfc_divisors[idx];
59 static struct clk_ops shx3_bus_clk_ops = {
60 .recalc = bus_clk_recalc,
63 static void cpu_clk_recalc(struct clk *clk)
65 int idx = ((ctrl_inl(FRQCR) >> IFC_POS) & IFC_MSK);
66 clk->rate = clk->parent->rate / ifc_divisors[idx];
69 static struct clk_ops shx3_cpu_clk_ops = {
70 .recalc = cpu_clk_recalc,
73 static struct clk_ops *shx3_clk_ops[] = {
80 void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
82 if (idx < ARRAY_SIZE(shx3_clk_ops))
83 *ops = shx3_clk_ops[idx];
86 static void shyway_clk_recalc(struct clk *clk)
88 int idx = ((ctrl_inl(FRQCR) >> CFC_POS) & CFC_MSK);
89 clk->rate = clk->parent->rate / cfc_divisors[idx];
92 static struct clk_ops shx3_shyway_clk_ops = {
93 .recalc = shyway_clk_recalc,
96 static struct clk shx3_shyway_clk = {
98 .flags = CLK_ALWAYS_ENABLED,
99 .ops = &shx3_shyway_clk_ops,
103 * Additional SHx3-specific on-chip clocks that aren't already part of the
106 static struct clk *shx3_onchip_clocks[] = {
110 static int __init shx3_clk_init(void)
112 struct clk *clk = clk_get(NULL, "master_clk");
115 for (i = 0; i < ARRAY_SIZE(shx3_onchip_clocks); i++) {
116 struct clk *clkp = shx3_onchip_clocks[i];
124 * Now that we have the rest of the clocks registered, we need to
125 * force the parent clock to propagate so that these clocks will
126 * automatically figure out their rate. We cheat by handing the
127 * parent clock its current rate and forcing child propagation.
129 clk_set_rate(clk, clk_get_rate(clk));
135 arch_initcall(shx3_clk_init);