2 * arch/sh/kernel/cpu/sh4/clock-sh7757.c
4 * SH7757 support for the clock framework
6 * Copyright (C) 2009 Renesas Solutions Corp.
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>
15 #include <asm/clkdev.h>
16 #include <asm/clock.h>
19 static int ifc_divisors
[] = { 2, 1, 4, 1, 1, 8, 1, 1,
20 16, 1, 1, 32, 1, 1, 1, 1 };
21 static int sfc_divisors
[] = { 2, 1, 4, 1, 1, 8, 1, 1,
22 16, 1, 1, 32, 1, 1, 1, 1 };
23 static int bfc_divisors
[] = { 2, 1, 4, 1, 1, 8, 1, 1,
24 16, 1, 1, 32, 1, 1, 1, 1 };
25 static int p1fc_divisors
[] = { 2, 1, 4, 1, 1, 8, 1, 1,
26 16, 1, 1, 32, 1, 1, 1, 1 };
28 static void master_clk_init(struct clk
*clk
)
30 clk
->rate
= CONFIG_SH_PCLK_FREQ
* 16;
33 static struct clk_ops sh7757_master_clk_ops
= {
34 .init
= master_clk_init
,
37 static void module_clk_recalc(struct clk
*clk
)
39 int idx
= __raw_readl(FRQCR
) & 0x0000000f;
40 clk
->rate
= clk
->parent
->rate
/ p1fc_divisors
[idx
];
43 static struct clk_ops sh7757_module_clk_ops
= {
44 .recalc
= module_clk_recalc
,
47 static void bus_clk_recalc(struct clk
*clk
)
49 int idx
= (__raw_readl(FRQCR
) >> 8) & 0x0000000f;
50 clk
->rate
= clk
->parent
->rate
/ bfc_divisors
[idx
];
53 static struct clk_ops sh7757_bus_clk_ops
= {
54 .recalc
= bus_clk_recalc
,
57 static void cpu_clk_recalc(struct clk
*clk
)
59 int idx
= (__raw_readl(FRQCR
) >> 20) & 0x0000000f;
60 clk
->rate
= clk
->parent
->rate
/ ifc_divisors
[idx
];
63 static struct clk_ops sh7757_cpu_clk_ops
= {
64 .recalc
= cpu_clk_recalc
,
67 static struct clk_ops
*sh7757_clk_ops
[] = {
68 &sh7757_master_clk_ops
,
69 &sh7757_module_clk_ops
,
74 void __init
arch_init_clk_ops(struct clk_ops
**ops
, int idx
)
76 if (idx
< ARRAY_SIZE(sh7757_clk_ops
))
77 *ops
= sh7757_clk_ops
[idx
];
80 static void shyway_clk_recalc(struct clk
*clk
)
82 int idx
= (__raw_readl(FRQCR
) >> 12) & 0x0000000f;
83 clk
->rate
= clk
->parent
->rate
/ sfc_divisors
[idx
];
86 static struct clk_ops sh7757_shyway_clk_ops
= {
87 .recalc
= shyway_clk_recalc
,
90 static struct clk sh7757_shyway_clk
= {
91 .flags
= CLK_ENABLE_ON_INIT
,
92 .ops
= &sh7757_shyway_clk_ops
,
96 * Additional sh7757-specific on-chip clocks that aren't already part of the
99 static struct clk
*sh7757_onchip_clocks
[] = {
103 #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
105 static struct clk_lookup lookups
[] = {
107 CLKDEV_CON_ID("shyway_clk", &sh7757_shyway_clk
),
110 static int __init
sh7757_clk_init(void)
112 struct clk
*clk
= clk_get(NULL
, "master_clk");
115 for (i
= 0; i
< ARRAY_SIZE(sh7757_onchip_clocks
); i
++) {
116 struct clk
*clkp
= sh7757_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
));
133 clkdev_add_table(lookups
, ARRAY_SIZE(lookups
));
138 arch_initcall(sh7757_clk_init
);