Skip to content

Commit 31c3af5

Browse files
lyakhpmundt
authored andcommitted
sh: support SIU sourcing from external clock on sh7722
Implement .set_rate() for all SH "div4 clocks," .enable(), .disable(), and .set_parent() for those, that support them. This allows, among other uses, reparenting of SIU clocks to the external source, and enabling and disabling of the IrDA clock on sh7722. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 14965f1 commit 31c3af5

3 files changed

Lines changed: 116 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ int sh_clk_mstp32_register(struct clk *clks, int nr);
148148

149149
int sh_clk_div4_register(struct clk *clks, int nr,
150150
struct clk_div_mult_table *table);
151+
int sh_clk_div4_enable_register(struct clk *clks, int nr,
152+
struct clk_div_mult_table *table);
153+
int sh_clk_div4_reparent_register(struct clk *clks, int nr,
154+
struct clk_div_mult_table *table);
151155

152156
#define SH_CLK_DIV6(_name, _parent, _reg, _flags) \
153157
{ \

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

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,81 @@ static unsigned long sh_clk_div4_recalc(struct clk *clk)
160160
return clk->freq_table[idx].frequency;
161161
}
162162

163+
static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
164+
{
165+
struct clk_div_mult_table *table = clk->priv;
166+
u32 value;
167+
int ret;
168+
169+
if (!strcmp("pll_clk", parent->name))
170+
value = __raw_readl(clk->enable_reg) & ~(1 << 7);
171+
else
172+
value = __raw_readl(clk->enable_reg) | (1 << 7);
173+
174+
ret = clk_reparent(clk, parent);
175+
if (ret < 0)
176+
return ret;
177+
178+
__raw_writel(value, clk->enable_reg);
179+
180+
/* Rebiuld the frequency table */
181+
clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
182+
table, &clk->arch_flags);
183+
184+
return 0;
185+
}
186+
187+
static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate, int algo_id)
188+
{
189+
unsigned long value;
190+
int idx = clk_rate_table_find(clk, clk->freq_table, rate);
191+
if (idx < 0)
192+
return idx;
193+
194+
value = __raw_readl(clk->enable_reg);
195+
value &= ~0xf;
196+
value |= idx;
197+
__raw_writel(value, clk->enable_reg);
198+
199+
return 0;
200+
}
201+
202+
static int sh_clk_div4_enable(struct clk *clk)
203+
{
204+
__raw_writel(__raw_readl(clk->enable_reg) & ~(1 << 8), clk->enable_reg);
205+
return 0;
206+
}
207+
208+
static void sh_clk_div4_disable(struct clk *clk)
209+
{
210+
__raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
211+
}
212+
163213
static struct clk_ops sh_clk_div4_clk_ops = {
164214
.recalc = sh_clk_div4_recalc,
215+
.set_rate = sh_clk_div4_set_rate,
165216
.round_rate = sh_clk_div_round_rate,
166217
};
167218

168-
int __init sh_clk_div4_register(struct clk *clks, int nr,
169-
struct clk_div_mult_table *table)
219+
static struct clk_ops sh_clk_div4_enable_clk_ops = {
220+
.recalc = sh_clk_div4_recalc,
221+
.set_rate = sh_clk_div4_set_rate,
222+
.round_rate = sh_clk_div_round_rate,
223+
.enable = sh_clk_div4_enable,
224+
.disable = sh_clk_div4_disable,
225+
};
226+
227+
static struct clk_ops sh_clk_div4_reparent_clk_ops = {
228+
.recalc = sh_clk_div4_recalc,
229+
.set_rate = sh_clk_div4_set_rate,
230+
.round_rate = sh_clk_div_round_rate,
231+
.enable = sh_clk_div4_enable,
232+
.disable = sh_clk_div4_disable,
233+
.set_parent = sh_clk_div4_set_parent,
234+
};
235+
236+
static int __init sh_clk_div4_register_ops(struct clk *clks, int nr,
237+
struct clk_div_mult_table *table, struct clk_ops *ops)
170238
{
171239
struct clk *clkp;
172240
void *freq_table;
@@ -185,7 +253,7 @@ int __init sh_clk_div4_register(struct clk *clks, int nr,
185253
for (k = 0; !ret && (k < nr); k++) {
186254
clkp = clks + k;
187255

188-
clkp->ops = &sh_clk_div4_clk_ops;
256+
clkp->ops = ops;
189257
clkp->id = -1;
190258
clkp->priv = table;
191259

@@ -198,6 +266,26 @@ int __init sh_clk_div4_register(struct clk *clks, int nr,
198266
return ret;
199267
}
200268

269+
int __init sh_clk_div4_register(struct clk *clks, int nr,
270+
struct clk_div_mult_table *table)
271+
{
272+
return sh_clk_div4_register_ops(clks, nr, table, &sh_clk_div4_clk_ops);
273+
}
274+
275+
int __init sh_clk_div4_enable_register(struct clk *clks, int nr,
276+
struct clk_div_mult_table *table)
277+
{
278+
return sh_clk_div4_register_ops(clks, nr, table,
279+
&sh_clk_div4_enable_clk_ops);
280+
}
281+
282+
int __init sh_clk_div4_reparent_register(struct clk *clks, int nr,
283+
struct clk_div_mult_table *table)
284+
{
285+
return sh_clk_div4_register_ops(clks, nr, table,
286+
&sh_clk_div4_reparent_clk_ops);
287+
}
288+
201289
#ifdef CONFIG_SH_CLK_CPG_LEGACY
202290
static struct clk master_clk = {
203291
.name = "master_clk",

‎arch/sh/kernel/cpu/sh4a/clock-sh7722.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,31 @@ static struct clk_div_mult_table div4_table = {
117117
.nr_multipliers = ARRAY_SIZE(multipliers),
118118
};
119119

120-
enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
121-
DIV4_SIUA, DIV4_SIUB, DIV4_IRDA, DIV4_NR };
122-
123120
#define DIV4(_str, _reg, _bit, _mask, _flags) \
124121
SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
125122

123+
enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };
124+
126125
struct clk div4_clks[DIV4_NR] = {
127126
[DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
128127
[DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
129128
[DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
130129
[DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
131130
[DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
132131
[DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
132+
};
133+
134+
enum { DIV4_IRDA, DIV4_ENABLE_NR };
135+
136+
struct clk div4_enable_clks[DIV4_ENABLE_NR] = {
137+
[DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x1fff, 0),
138+
};
139+
140+
enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };
141+
142+
struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {
133143
[DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
134144
[DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
135-
[DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x1fff, 0),
136145
};
137146

138147
struct clk div6_clks[] = {
@@ -188,6 +197,14 @@ int __init arch_clk_init(void)
188197
if (!ret)
189198
ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
190199

200+
if (!ret)
201+
ret = sh_clk_div4_enable_register(div4_enable_clks,
202+
DIV4_ENABLE_NR, &div4_table);
203+
204+
if (!ret)
205+
ret = sh_clk_div4_reparent_register(div4_reparent_clks,
206+
DIV4_REPARENT_NR, &div4_table);
207+
191208
if (!ret)
192209
ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
193210

0 commit comments

Comments
 (0)