Skip to content

Commit a1153e2

Browse files
Magnus Dammpmundt
authored andcommitted
sh: shared div4 clock code
Add shared code for 4-bit divisor clocks. Processor specific code can use SH_CLK_DIV4() to initialize div4 clocks, and then use sh_clk_div4_register() for registration. Signed-off-by: Magnus Damm <damm@igel.co.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent e89d53e commit a1153e2

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎arch/sh/include/asm/clock.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/list.h>
55
#include <linux/seq_file.h>
6+
#include <linux/cpufreq.h>
67
#include <linux/clk.h>
78
#include <linux/err.h>
89

@@ -41,6 +42,7 @@ struct clk {
4142
unsigned long arch_flags;
4243
void *priv;
4344
struct dentry *dentry;
45+
struct cpufreq_frequency_table *freq_table;
4446
};
4547

4648
struct clk_lookup {
@@ -130,4 +132,17 @@ long clk_rate_table_round(struct clk *clk,
130132

131133
int sh_clk_mstp32_register(struct clk *clks, int nr);
132134

135+
#define SH_CLK_DIV4(_name, _parent, _reg, _shift, _div_bitmap, _flags) \
136+
{ \
137+
.name = _name, \
138+
.parent = _parent, \
139+
.enable_reg = (void __iomem *)_reg, \
140+
.enable_bit = _shift, \
141+
.arch_flags = _div_bitmap, \
142+
.flags = _flags, \
143+
}
144+
145+
int sh_clk_div4_register(struct clk *clks, int nr,
146+
struct clk_div_mult_table *table);
147+
133148
#endif /* __ASM_SH_CLOCK_H */

‎arch/sh/kernel/cpu/clock-cpg.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <linux/clk.h>
22
#include <linux/compiler.h>
3+
#include <linux/bootmem.h>
34
#include <linux/io.h>
45
#include <asm/clock.h>
56

@@ -37,6 +38,60 @@ int __init sh_clk_mstp32_register(struct clk *clks, int nr)
3738
return ret;
3839
}
3940

41+
static unsigned long sh_clk_div4_recalc(struct clk *clk)
42+
{
43+
struct clk_div_mult_table *table = clk->priv;
44+
unsigned int idx;
45+
46+
clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
47+
table, &clk->arch_flags);
48+
49+
idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
50+
51+
return clk->freq_table[idx].frequency;
52+
}
53+
54+
static long sh_clk_div4_round_rate(struct clk *clk, unsigned long rate)
55+
{
56+
return clk_rate_table_round(clk, clk->freq_table, rate);
57+
}
58+
59+
static struct clk_ops sh_clk_div4_clk_ops = {
60+
.recalc = sh_clk_div4_recalc,
61+
.round_rate = sh_clk_div4_round_rate,
62+
};
63+
64+
int __init sh_clk_div4_register(struct clk *clks, int nr,
65+
struct clk_div_mult_table *table)
66+
{
67+
struct clk *clkp;
68+
void *freq_table;
69+
int nr_divs = table->nr_divisors;
70+
int freq_table_size = sizeof(struct cpufreq_frequency_table);
71+
int ret = 0;
72+
int k;
73+
74+
k = nr_divs + 1;
75+
freq_table = alloc_bootmem(freq_table_size * nr * (nr_divs + 1));
76+
if (!freq_table)
77+
return -ENOMEM;
78+
79+
for (k = 0; !ret && (k < nr); k++) {
80+
clkp = clks + k;
81+
82+
clkp->ops = &sh_clk_div4_clk_ops;
83+
clkp->id = -1;
84+
clkp->priv = table;
85+
86+
clkp->freq_table = freq_table + (k * freq_table_size);
87+
clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
88+
89+
ret = clk_register(clkp);
90+
}
91+
92+
return ret;
93+
}
94+
4095
#ifdef CONFIG_SH_CLK_CPG_LEGACY
4196
static struct clk master_clk = {
4297
.name = "master_clk",

0 commit comments

Comments
 (0)