2 #include <linux/compiler.h>
3 #include <linux/bootmem.h>
7 static int sh_clk_mstp32_enable(struct clk *clk)
9 __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
14 static void sh_clk_mstp32_disable(struct clk *clk)
16 __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
20 static struct clk_ops sh_clk_mstp32_clk_ops = {
21 .enable = sh_clk_mstp32_enable,
22 .disable = sh_clk_mstp32_disable,
23 .recalc = followparent_recalc,
26 int __init sh_clk_mstp32_register(struct clk *clks, int nr)
32 for (k = 0; !ret && (k < nr); k++) {
34 clkp->ops = &sh_clk_mstp32_clk_ops;
35 ret |= clk_register(clkp);
41 static unsigned long sh_clk_div4_recalc(struct clk *clk)
43 struct clk_div_mult_table *table = clk->priv;
46 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
47 table, &clk->arch_flags);
49 idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
51 return clk->freq_table[idx].frequency;
54 static long sh_clk_div4_round_rate(struct clk *clk, unsigned long rate)
56 return clk_rate_table_round(clk, clk->freq_table, rate);
59 static struct clk_ops sh_clk_div4_clk_ops = {
60 .recalc = sh_clk_div4_recalc,
61 .round_rate = sh_clk_div4_round_rate,
64 int __init sh_clk_div4_register(struct clk *clks, int nr,
65 struct clk_div_mult_table *table)
69 int nr_divs = table->nr_divisors;
70 int freq_table_size = sizeof(struct cpufreq_frequency_table);
75 freq_table = alloc_bootmem(freq_table_size * nr * (nr_divs + 1));
79 for (k = 0; !ret && (k < nr); k++) {
82 clkp->ops = &sh_clk_div4_clk_ops;
86 clkp->freq_table = freq_table + (k * freq_table_size);
87 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
89 ret = clk_register(clkp);
95 #ifdef CONFIG_SH_CLK_CPG_LEGACY
96 static struct clk master_clk = {
98 .flags = CLK_ENABLE_ON_INIT,
99 .rate = CONFIG_SH_PCLK_FREQ,
102 static struct clk peripheral_clk = {
103 .name = "peripheral_clk",
104 .parent = &master_clk,
105 .flags = CLK_ENABLE_ON_INIT,
108 static struct clk bus_clk = {
110 .parent = &master_clk,
111 .flags = CLK_ENABLE_ON_INIT,
114 static struct clk cpu_clk = {
116 .parent = &master_clk,
117 .flags = CLK_ENABLE_ON_INIT,
121 * The ordering of these clocks matters, do not change it.
123 static struct clk *onchip_clocks[] = {
130 int __init __deprecated cpg_clk_init(void)
134 for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
135 struct clk *clk = onchip_clocks[i];
136 arch_init_clk_ops(&clk->ops, i);
138 ret |= clk_register(clk);
145 * Placeholder for compatability, until the lazy CPUs do this
148 int __init __weak arch_clk_init(void)
150 return cpg_clk_init();
152 #endif /* CONFIG_SH_CPG_CLK_LEGACY */