Skip to content

Commit b1f6cfe

Browse files
committed
sh: clkfwk: refactor rate propagation.
This resyncs the rate propagation strategy with the scheme used by the OMAP clock framework. Child clocks are tracked on a list under each parent and propagation happens there specifically rather than constantly iterating over the global clock list. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent a02cb23 commit b1f6cfe

3 files changed

Lines changed: 85 additions & 52 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ struct clk {
2727
struct clk *parent;
2828
struct clk_ops *ops;
2929

30+
struct list_head children;
31+
struct list_head sibling; /* node for children */
32+
3033
int usecount;
3134

3235
unsigned long rate;
@@ -35,7 +38,6 @@ struct clk {
3538
};
3639

3740
#define CLK_ALWAYS_ENABLED (1 << 0)
38-
#define CLK_RATE_PROPAGATES (1 << 1)
3941
#define CLK_NEEDS_INIT (1 << 2)
4042

4143
/* Should be defined by processor-specific code */
@@ -44,9 +46,10 @@ int __init arch_clk_init(void);
4446

4547
/* arch/sh/kernel/cpu/clock.c */
4648
int clk_init(void);
47-
unsigned long followparent_recalc(struct clk *clk);
49+
unsigned long followparent_recalc(struct clk *);
50+
void recalculate_root_clocks(void);
51+
void propagate_rate(struct clk *);
4852
void clk_recalc_rate(struct clk *);
49-
5053
int clk_register(struct clk *);
5154
void clk_unregister(struct clk *);
5255

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

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* arch/sh/kernel/cpu/clock.c - SuperH clock framework
33
*
4-
* Copyright (C) 2005, 2006, 2007 Paul Mundt
4+
* Copyright (C) 2005 - 2009 Paul Mundt
55
*
66
* This clock framework is derived from the OMAP version by:
77
*
8-
* Copyright (C) 2004 - 2005 Nokia Corporation
8+
* Copyright (C) 2004 - 2008 Nokia Corporation
99
* Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
1010
*
1111
* Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
@@ -43,20 +43,20 @@ static DEFINE_MUTEX(clock_list_sem);
4343
*/
4444
static struct clk master_clk = {
4545
.name = "master_clk",
46-
.flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
46+
.flags = CLK_ALWAYS_ENABLED,
4747
.rate = CONFIG_SH_PCLK_FREQ,
4848
};
4949

5050
static struct clk module_clk = {
5151
.name = "module_clk",
5252
.parent = &master_clk,
53-
.flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
53+
.flags = CLK_ALWAYS_ENABLED,
5454
};
5555

5656
static struct clk bus_clk = {
5757
.name = "bus_clk",
5858
.parent = &master_clk,
59-
.flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
59+
.flags = CLK_ALWAYS_ENABLED,
6060
};
6161

6262
static struct clk cpu_clk = {
@@ -75,27 +75,24 @@ static struct clk *onchip_clocks[] = {
7575
&cpu_clk,
7676
};
7777

78+
/* Used for clocks that always have same value as the parent clock */
79+
unsigned long followparent_recalc(struct clk *clk)
80+
{
81+
return clk->parent->rate;
82+
}
83+
7884
/* Propagate rate to children */
79-
static void propagate_rate(struct clk *clk)
85+
void propagate_rate(struct clk *tclk)
8086
{
8187
struct clk *clkp;
8288

83-
list_for_each_entry(clkp, &clock_list, node) {
84-
if (likely(clkp->parent != clk))
85-
continue;
86-
if (likely(clkp->ops && clkp->ops->recalc))
89+
list_for_each_entry(clkp, &tclk->children, sibling) {
90+
if (clkp->ops->recalc)
8791
clkp->rate = clkp->ops->recalc(clkp);
88-
if (unlikely(clkp->flags & CLK_RATE_PROPAGATES))
89-
propagate_rate(clkp);
92+
propagate_rate(clkp);
9093
}
9194
}
9295

93-
/* Used for clocks that always have same value as the parent clock */
94-
unsigned long followparent_recalc(struct clk *clk)
95-
{
96-
return clk->parent->rate;
97-
}
98-
9996
static void __clk_init(struct clk *clk)
10097
{
10198
/*
@@ -180,10 +177,46 @@ void clk_disable(struct clk *clk)
180177
}
181178
EXPORT_SYMBOL_GPL(clk_disable);
182179

180+
static LIST_HEAD(root_clks);
181+
182+
/**
183+
* recalculate_root_clocks - recalculate and propagate all root clocks
184+
*
185+
* Recalculates all root clocks (clocks with no parent), which if the
186+
* clock's .recalc is set correctly, should also propagate their rates.
187+
* Called at init.
188+
*/
189+
void recalculate_root_clocks(void)
190+
{
191+
struct clk *clkp;
192+
193+
list_for_each_entry(clkp, &root_clks, sibling) {
194+
if (clkp->ops->recalc)
195+
clkp->rate = clkp->ops->recalc(clkp);
196+
propagate_rate(clkp);
197+
}
198+
}
199+
183200
int clk_register(struct clk *clk)
184201
{
202+
if (clk == NULL || IS_ERR(clk))
203+
return -EINVAL;
204+
205+
/*
206+
* trap out already registered clocks
207+
*/
208+
if (clk->node.next || clk->node.prev)
209+
return 0;
210+
185211
mutex_lock(&clock_list_sem);
186212

213+
INIT_LIST_HEAD(&clk->children);
214+
215+
if (clk->parent)
216+
list_add(&clk->sibling, &clk->parent->children);
217+
else
218+
list_add(&clk->sibling, &root_clks);
219+
187220
list_add(&clk->node, &clock_list);
188221
clk->usecount = 0;
189222
clk->flags |= CLK_NEEDS_INIT;
@@ -205,6 +238,7 @@ EXPORT_SYMBOL_GPL(clk_register);
205238
void clk_unregister(struct clk *clk)
206239
{
207240
mutex_lock(&clock_list_sem);
241+
list_del(&clk->sibling);
208242
list_del(&clk->node);
209243
mutex_unlock(&clock_list_sem);
210244
}
@@ -231,50 +265,53 @@ int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)
231265

232266
spin_lock_irqsave(&clock_lock, flags);
233267
ret = clk->ops->set_rate(clk, rate, algo_id);
268+
if (ret == 0) {
269+
if (clk->ops->recalc)
270+
clk->rate = clk->ops->recalc(clk);
271+
propagate_rate(clk);
272+
}
234273
spin_unlock_irqrestore(&clock_lock, flags);
235274
}
236275

237-
if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
238-
propagate_rate(clk);
239-
240276
return ret;
241277
}
242278
EXPORT_SYMBOL_GPL(clk_set_rate_ex);
243279

244280
void clk_recalc_rate(struct clk *clk)
245281
{
246-
if (likely(clk->ops && clk->ops->recalc)) {
247-
unsigned long flags;
282+
unsigned long flags;
248283

249-
spin_lock_irqsave(&clock_lock, flags);
250-
clk->rate = clk->ops->recalc(clk);
251-
spin_unlock_irqrestore(&clock_lock, flags);
252-
}
284+
if (!clk->ops->recalc)
285+
return;
253286

254-
if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
255-
propagate_rate(clk);
287+
spin_lock_irqsave(&clock_lock, flags);
288+
clk->rate = clk->ops->recalc(clk);
289+
propagate_rate(clk);
290+
spin_unlock_irqrestore(&clock_lock, flags);
256291
}
257292
EXPORT_SYMBOL_GPL(clk_recalc_rate);
258293

259294
int clk_set_parent(struct clk *clk, struct clk *parent)
260295
{
296+
unsigned long flags;
261297
int ret = -EINVAL;
262-
struct clk *old;
263298

264299
if (!parent || !clk)
265300
return ret;
266301

267-
old = clk->parent;
268-
if (likely(clk->ops && clk->ops->set_parent)) {
269-
unsigned long flags;
270-
spin_lock_irqsave(&clock_lock, flags);
271-
ret = clk->ops->set_parent(clk, parent);
272-
spin_unlock_irqrestore(&clock_lock, flags);
273-
clk->parent = (ret ? old : parent);
274-
}
302+
spin_lock_irqsave(&clock_lock, flags);
303+
if (clk->usecount == 0) {
304+
if (clk->ops->set_parent)
305+
ret = clk->ops->set_parent(clk, parent);
306+
if (ret == 0) {
307+
if (clk->ops->recalc)
308+
clk->rate = clk->ops->recalc(clk);
309+
propagate_rate(clk);
310+
}
311+
} else
312+
ret = -EBUSY;
313+
spin_unlock_irqrestore(&clock_lock, flags);
275314

276-
if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
277-
propagate_rate(clk);
278315
return ret;
279316
}
280317
EXPORT_SYMBOL_GPL(clk_set_parent);
@@ -457,8 +494,7 @@ int __init clk_init(void)
457494
ret |= arch_clk_init();
458495

459496
/* Kick the child clocks.. */
460-
propagate_rate(&master_clk);
461-
propagate_rate(&bus_clk);
497+
recalculate_root_clocks();
462498

463499
return ret;
464500
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ static unsigned long master_clk_recalc(struct clk *clk)
161161
static void master_clk_init(struct clk *clk)
162162
{
163163
clk->parent = NULL;
164-
clk->flags |= CLK_RATE_PROPAGATES;
165-
clk->rate = CONFIG_SH_PCLK_FREQ;
166-
master_clk_recalc(clk);
164+
clk->rate = master_clk_recalc(clk);
167165
}
168166

169167
static unsigned long module_clk_recalc(struct clk *clk)
@@ -541,19 +539,16 @@ static struct clk_ops sh7722_video_clk_ops = {
541539
static struct clk sh7722_umem_clock = {
542540
.name = "umem_clk",
543541
.ops = &sh7722_frqcr_clk_ops,
544-
.flags = CLK_RATE_PROPAGATES,
545542
};
546543

547544
static struct clk sh7722_sh_clock = {
548545
.name = "sh_clk",
549546
.ops = &sh7722_frqcr_clk_ops,
550-
.flags = CLK_RATE_PROPAGATES,
551547
};
552548

553549
static struct clk sh7722_peripheral_clock = {
554550
.name = "peripheral_clk",
555551
.ops = &sh7722_frqcr_clk_ops,
556-
.flags = CLK_RATE_PROPAGATES,
557552
};
558553

559554
static struct clk sh7722_sdram_clock = {
@@ -564,7 +559,6 @@ static struct clk sh7722_sdram_clock = {
564559
static struct clk sh7722_r_clock = {
565560
.name = "r_clk",
566561
.rate = 32768,
567-
.flags = CLK_RATE_PROPAGATES,
568562
};
569563

570564
#if !defined(CONFIG_CPU_SUBTYPE_SH7343) &&\

0 commit comments

Comments
 (0)