12 #include <linux/compiler.h>
13 #include <linux/slab.h>
17 #define CPG_CKSTP_BIT BIT(8)
19 static unsigned int sh_clk_read(
struct clk *
clk)
29 static void sh_clk_write(
int value,
struct clk *
clk)
39 static int sh_clk_mstp_enable(
struct clk *clk)
41 sh_clk_write(sh_clk_read(clk) & ~(1 << clk->
enable_bit), clk);
45 static void sh_clk_mstp_disable(
struct clk *clk)
47 sh_clk_write(sh_clk_read(clk) | (1 << clk->
enable_bit), clk);
50 static struct sh_clk_ops sh_clk_mstp_clk_ops = {
51 .enable = sh_clk_mstp_enable,
52 .disable = sh_clk_mstp_disable,
62 for (k = 0; !ret && (k <
nr); k++) {
64 clkp->
ops = &sh_clk_mstp_clk_ops;
74 static inline struct clk_div_table *clk_to_div_table(
struct clk *clk)
81 return clk_to_div_table(clk)->div_mult_table;
87 static long sh_clk_div_round_rate(
struct clk *clk,
unsigned long rate)
92 static unsigned long sh_clk_div_recalc(
struct clk *clk)
105 static int sh_clk_div_set_rate(
struct clk *clk,
unsigned long rate)
115 value = sh_clk_read(clk);
118 sh_clk_write(value, clk);
127 static int sh_clk_div_enable(
struct clk *clk)
133 static void sh_clk_div_disable(
struct clk *clk)
137 val = sh_clk_read(clk);
148 sh_clk_write(val, clk);
151 static struct sh_clk_ops sh_clk_div_clk_ops = {
152 .recalc = sh_clk_div_recalc,
153 .set_rate = sh_clk_div_set_rate,
154 .round_rate = sh_clk_div_round_rate,
157 static struct sh_clk_ops sh_clk_div_enable_clk_ops = {
158 .recalc = sh_clk_div_recalc,
159 .set_rate = sh_clk_div_set_rate,
160 .round_rate = sh_clk_div_round_rate,
161 .enable = sh_clk_div_enable,
162 .disable = sh_clk_div_disable,
165 static int __init sh_clk_init_parent(
struct clk *clk)
176 pr_err(
"sh_clk_init_parent: cannot select parent clock\n");
180 val = (sh_clk_read(clk) >> clk->
src_shift);
184 pr_err(
"sh_clk_init_parent: parent table size failed\n");
190 pr_err(
"sh_clk_init_parent: unable to set parent");
197 static int __init sh_clk_div_register_ops(
struct clk *clks,
int nr,
207 freq_table_size *= (nr_divs + 1);
208 freq_table = kzalloc(freq_table_size * nr,
GFP_KERNEL);
210 pr_err(
"%s: unable to alloc memory\n", __func__);
214 for (k = 0; !ret && (k <
nr); k++) {
220 clkp->
freq_table = freq_table + (k * freq_table_size);
225 ret = sh_clk_init_parent(clkp);
234 static int sh_clk_div6_divisors[64] = {
235 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
236 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
237 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
238 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
242 .divisors = sh_clk_div6_divisors,
243 .nr_divisors =
ARRAY_SIZE(sh_clk_div6_divisors),
247 .div_mult_table = &div6_div_mult_table,
250 static int sh_clk_div6_set_parent(
struct clk *clk,
struct clk *parent)
271 value = sh_clk_read(clk) &
274 sh_clk_write(value | (i << clk->
src_shift), clk);
283 static struct sh_clk_ops sh_clk_div6_reparent_clk_ops = {
284 .recalc = sh_clk_div_recalc,
285 .round_rate = sh_clk_div_round_rate,
286 .set_rate = sh_clk_div_set_rate,
287 .enable = sh_clk_div_enable,
288 .disable = sh_clk_div_disable,
289 .set_parent = sh_clk_div6_set_parent,
294 return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table,
295 &sh_clk_div_enable_clk_ops);
300 return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table,
301 &sh_clk_div6_reparent_clk_ops);
307 static int sh_clk_div4_set_parent(
struct clk *clk,
struct clk *parent)
319 value = sh_clk_read(clk) & ~(1 << 7);
321 value = sh_clk_read(clk) | (1 << 7);
327 sh_clk_write(value, clk);
336 static struct sh_clk_ops sh_clk_div4_reparent_clk_ops = {
337 .recalc = sh_clk_div_recalc,
338 .set_rate = sh_clk_div_set_rate,
339 .round_rate = sh_clk_div_round_rate,
340 .enable = sh_clk_div_enable,
341 .disable = sh_clk_div_disable,
342 .set_parent = sh_clk_div4_set_parent,
348 return sh_clk_div_register_ops(clks, nr, table, &sh_clk_div_clk_ops);
354 return sh_clk_div_register_ops(clks, nr, table,
355 &sh_clk_div_enable_clk_ops);
361 return sh_clk_div_register_ops(clks, nr, table,
362 &sh_clk_div4_reparent_clk_ops);