13 #include <linux/kernel.h>
17 #include <asm/clock.h>
20 #define CPG2_FRQCR3 0xfe0a0018
22 static int frqcr3_divisors[] = { 1, 2, 3, 4, 6, 8, 16 };
23 static int frqcr3_values[] = { 0, 1, 2, 3, 4, 5, 6 };
25 static unsigned long emi_clk_recalc(
struct clk *
clk)
28 return clk->
parent->rate / frqcr3_divisors[
idx];
31 static inline int frqcr3_lookup(
struct clk *
clk,
unsigned long rate)
36 for (i = 0; i <
ARRAY_SIZE(frqcr3_divisors); i++)
37 if (frqcr3_divisors[i] == divisor)
38 return frqcr3_values[
i];
44 static struct sh_clk_ops sh4202_emi_clk_ops = {
45 .recalc = emi_clk_recalc,
48 static struct clk sh4202_emi_clk = {
50 .ops = &sh4202_emi_clk_ops,
53 static unsigned long femi_clk_recalc(
struct clk *clk)
56 return clk->
parent->rate / frqcr3_divisors[
idx];
59 static struct sh_clk_ops sh4202_femi_clk_ops = {
60 .recalc = femi_clk_recalc,
63 static struct clk sh4202_femi_clk = {
65 .ops = &sh4202_femi_clk_ops,
68 static void shoc_clk_init(
struct clk *clk)
81 for (i = 0; i <
ARRAY_SIZE(frqcr3_divisors); i++) {
82 int divisor = frqcr3_divisors[
i];
84 if (clk->
ops->set_rate(clk, clk->
parent->rate / divisor) == 0)
91 static unsigned long shoc_clk_recalc(
struct clk *clk)
94 return clk->
parent->rate / frqcr3_divisors[
idx];
97 static int shoc_clk_verify_rate(
struct clk *clk,
unsigned long rate)
104 if (rate > bclk_rate)
112 static int shoc_clk_set_rate(
struct clk *clk,
unsigned long rate)
114 unsigned long frqcr3;
118 if (shoc_clk_verify_rate(clk, rate) != 0)
121 tmp = frqcr3_lookup(clk, rate);
124 frqcr3 &= ~(0x0007 << 6);
133 static struct sh_clk_ops sh4202_shoc_clk_ops = {
134 .init = shoc_clk_init,
135 .recalc = shoc_clk_recalc,
136 .set_rate = shoc_clk_set_rate,
139 static struct clk sh4202_shoc_clk = {
141 .ops = &sh4202_shoc_clk_ops,
144 static struct clk *sh4202_onchip_clocks[] = {
165 for (i = 0; i <
ARRAY_SIZE(sh4202_onchip_clocks); i++) {
166 struct clk *clkp = sh4202_onchip_clocks[
i];