Skip to content

Commit d277ce2

Browse files
akemnadeTero Kristo
authored andcommitted
clk: ti: add a usecount for autoidle
Multiple users might deny autoidle on a clock. So we should have some counting here, also according to the comment in _setup_iclk_autoidle(). Also setting autoidle regs is not atomic, so there is another reason for locking. Signed-off-by: Andreas Kemnade <andreas@kemnade.info> Acked-by: Tony Lindgren <tony@atomide.com> Tested-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Tero Kristo <t-kristo@ti.com>
1 parent ead4782 commit d277ce2

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎drivers/clk/ti/autoidle.c‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,41 @@ struct clk_ti_autoidle {
3636

3737
static LIST_HEAD(autoidle_clks);
3838

39+
/*
40+
* we have some non-atomic read/write
41+
* operations behind it, so lets
42+
* take one lock for handling autoidle
43+
* of all clocks
44+
*/
45+
static DEFINE_SPINLOCK(autoidle_spinlock);
46+
3947
static int _omap2_clk_deny_idle(struct clk_hw_omap *clk)
4048
{
41-
if (clk->ops && clk->ops->deny_idle)
42-
clk->ops->deny_idle(clk);
49+
if (clk->ops && clk->ops->deny_idle) {
50+
unsigned long irqflags;
51+
52+
spin_lock_irqsave(&autoidle_spinlock, irqflags);
53+
clk->autoidle_count++;
54+
if (clk->autoidle_count == 1)
55+
clk->ops->deny_idle(clk);
56+
57+
spin_unlock_irqrestore(&autoidle_spinlock, irqflags);
58+
}
4359
return 0;
4460
}
4561

4662
static int _omap2_clk_allow_idle(struct clk_hw_omap *clk)
4763
{
48-
if (clk->ops && clk->ops->allow_idle)
49-
clk->ops->allow_idle(clk);
64+
if (clk->ops && clk->ops->allow_idle) {
65+
unsigned long irqflags;
66+
67+
spin_lock_irqsave(&autoidle_spinlock, irqflags);
68+
clk->autoidle_count--;
69+
if (clk->autoidle_count == 0)
70+
clk->ops->allow_idle(clk);
71+
72+
spin_unlock_irqrestore(&autoidle_spinlock, irqflags);
73+
}
5074
return 0;
5175
}
5276

‎include/linux/clk/ti.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct clk_hw_omap {
160160
struct clockdomain *clkdm;
161161
const struct clk_hw_omap_ops *ops;
162162
u32 context;
163+
int autoidle_count;
163164
};
164165

165166
/*

0 commit comments

Comments
 (0)