Skip to content

Commit 4ff29ff

Browse files
committed
sh: clkfwk: Consolidate the ALWAYS_ENABLED / NEEDS_INIT mess.
There is no real distinction here in behaviour, either a clock needs to be enabled on initialiation or not. The ALWAYS_ENABLED flag was always intended to only apply to clocks that were physically always on and could simply not be disabled at all from software. Unfortunately over time this was abused and the meaning became a bit blurry. So, we kill off both of all of those paths now, as well as the newer NEEDS_INIT flag, and consolidate on a CLK_ENABLE_ON_INIT. Clocks that need to be enabled on initialization can set this, and it will purposely enable them and bump the refcount up. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent b1f6cfe commit 4ff29ff

8 files changed

Lines changed: 44 additions & 75 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ struct clk {
3737
unsigned long arch_flags;
3838
};
3939

40-
#define CLK_ALWAYS_ENABLED (1 << 0)
41-
#define CLK_NEEDS_INIT (1 << 2)
40+
#define CLK_ENABLE_ON_INIT (1 << 0)
4241

4342
/* Should be defined by processor-specific code */
4443
void arch_init_clk_ops(struct clk_ops **, int type);

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

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ static DEFINE_MUTEX(clock_list_sem);
4343
*/
4444
static struct clk master_clk = {
4545
.name = "master_clk",
46-
.flags = CLK_ALWAYS_ENABLED,
46+
.flags = CLK_ENABLE_ON_INIT,
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,
53+
.flags = CLK_ENABLE_ON_INIT,
5454
};
5555

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

6262
static struct clk cpu_clk = {
6363
.name = "cpu_clk",
6464
.parent = &master_clk,
65-
.flags = CLK_ALWAYS_ENABLED,
65+
.flags = CLK_ENABLE_ON_INIT,
6666
};
6767

6868
/*
@@ -93,39 +93,11 @@ void propagate_rate(struct clk *tclk)
9393
}
9494
}
9595

96-
static void __clk_init(struct clk *clk)
97-
{
98-
/*
99-
* See if this is the first time we're enabling the clock, some
100-
* clocks that are always enabled still require "special"
101-
* initialization. This is especially true if the clock mode
102-
* changes and the clock needs to hunt for the proper set of
103-
* divisors to use before it can effectively recalc.
104-
*/
105-
106-
if (clk->flags & CLK_NEEDS_INIT) {
107-
if (clk->ops && clk->ops->init)
108-
clk->ops->init(clk);
109-
110-
clk->flags &= ~CLK_NEEDS_INIT;
111-
}
112-
}
113-
11496
static int __clk_enable(struct clk *clk)
11597
{
116-
if (!clk)
117-
return -EINVAL;
118-
119-
clk->usecount++;
120-
121-
/* nothing to do if always enabled */
122-
if (clk->flags & CLK_ALWAYS_ENABLED)
123-
return 0;
124-
125-
if (clk->usecount == 1) {
126-
__clk_init(clk);
127-
128-
__clk_enable(clk->parent);
98+
if (clk->usecount++ == 0) {
99+
if (clk->parent)
100+
__clk_enable(clk->parent);
129101

130102
if (clk->ops && clk->ops->enable)
131103
clk->ops->enable(clk);
@@ -139,6 +111,9 @@ int clk_enable(struct clk *clk)
139111
unsigned long flags;
140112
int ret;
141113

114+
if (!clk)
115+
return -EINVAL;
116+
142117
spin_lock_irqsave(&clock_lock, flags);
143118
ret = __clk_enable(clk);
144119
spin_unlock_irqrestore(&clock_lock, flags);
@@ -149,28 +124,21 @@ EXPORT_SYMBOL_GPL(clk_enable);
149124

150125
static void __clk_disable(struct clk *clk)
151126
{
152-
if (!clk)
153-
return;
154-
155-
clk->usecount--;
156-
157-
WARN_ON(clk->usecount < 0);
158-
159-
if (clk->flags & CLK_ALWAYS_ENABLED)
160-
return;
161-
162-
if (clk->usecount == 0) {
127+
if (clk->usecount > 0 && !(--clk->usecount)) {
163128
if (likely(clk->ops && clk->ops->disable))
164129
clk->ops->disable(clk);
165-
166-
__clk_disable(clk->parent);
130+
if (likely(clk->parent))
131+
__clk_disable(clk->parent);
167132
}
168133
}
169134

170135
void clk_disable(struct clk *clk)
171136
{
172137
unsigned long flags;
173138

139+
if (!clk)
140+
return;
141+
174142
spin_lock_irqsave(&clock_lock, flags);
175143
__clk_disable(clk);
176144
spin_unlock_irqrestore(&clock_lock, flags);
@@ -211,26 +179,18 @@ int clk_register(struct clk *clk)
211179
mutex_lock(&clock_list_sem);
212180

213181
INIT_LIST_HEAD(&clk->children);
182+
clk->usecount = 0;
214183

215184
if (clk->parent)
216185
list_add(&clk->sibling, &clk->parent->children);
217186
else
218187
list_add(&clk->sibling, &root_clks);
219188

220189
list_add(&clk->node, &clock_list);
221-
clk->usecount = 0;
222-
clk->flags |= CLK_NEEDS_INIT;
223-
190+
if (clk->ops->init)
191+
clk->ops->init(clk);
224192
mutex_unlock(&clock_list_sem);
225193

226-
if (clk->flags & CLK_ALWAYS_ENABLED) {
227-
__clk_init(clk);
228-
pr_debug( "Clock '%s' is ALWAYS_ENABLED\n", clk->name);
229-
if (clk->ops && clk->ops->enable)
230-
clk->ops->enable(clk);
231-
pr_debug( "Enabled.");
232-
}
233-
234194
return 0;
235195
}
236196
EXPORT_SYMBOL_GPL(clk_register);
@@ -244,6 +204,15 @@ void clk_unregister(struct clk *clk)
244204
}
245205
EXPORT_SYMBOL_GPL(clk_unregister);
246206

207+
static void clk_enable_init_clocks(void)
208+
{
209+
struct clk *clkp;
210+
211+
list_for_each_entry(clkp, &clock_list, node)
212+
if (clkp->flags & CLK_ENABLE_ON_INIT)
213+
clk_enable(clkp);
214+
}
215+
247216
unsigned long clk_get_rate(struct clk *clk)
248217
{
249218
return clk->rate;
@@ -404,9 +373,7 @@ static int show_clocks(char *buf, char **start, off_t off,
404373

405374
p += sprintf(p, "%-12s\t: %ld.%02ldMHz\t%s\n", clk->name,
406375
rate / 1000000, (rate % 1000000) / 10000,
407-
((clk->flags & CLK_ALWAYS_ENABLED) ||
408-
clk->usecount > 0) ?
409-
"enabled" : "disabled");
376+
(clk->usecount > 0) ? "enabled" : "disabled");
410377
}
411378

412379
return p - buf;
@@ -496,6 +463,9 @@ int __init clk_init(void)
496463
/* Kick the child clocks.. */
497464
recalculate_root_clocks();
498465

466+
/* Enable the necessary init clocks */
467+
clk_enable_init_clocks();
468+
499469
return ret;
500470
}
501471

‎arch/sh/kernel/cpu/sh4/clock-sh4-202.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static struct clk_ops sh4202_emi_clk_ops = {
4646

4747
static struct clk sh4202_emi_clk = {
4848
.name = "emi_clk",
49-
.flags = CLK_ALWAYS_ENABLED,
49+
.flags = CLK_ENABLE_ON_INIT,
5050
.ops = &sh4202_emi_clk_ops,
5151
};
5252

@@ -62,7 +62,7 @@ static struct clk_ops sh4202_femi_clk_ops = {
6262

6363
static struct clk sh4202_femi_clk = {
6464
.name = "femi_clk",
65-
.flags = CLK_ALWAYS_ENABLED,
65+
.flags = CLK_ENABLE_ON_INIT,
6666
.ops = &sh4202_femi_clk_ops,
6767
};
6868

@@ -140,7 +140,7 @@ static struct clk_ops sh4202_shoc_clk_ops = {
140140

141141
static struct clk sh4202_shoc_clk = {
142142
.name = "shoc_clk",
143-
.flags = CLK_ALWAYS_ENABLED,
143+
.flags = CLK_ENABLE_ON_INIT,
144144
.ops = &sh4202_shoc_clk_ops,
145145
};
146146

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static struct clk_ops sh7763_shyway_clk_ops = {
7878

7979
static struct clk sh7763_shyway_clk = {
8080
.name = "shyway_clk",
81-
.flags = CLK_ALWAYS_ENABLED,
81+
.flags = CLK_ENABLE_ON_INIT,
8282
.ops = &sh7763_shyway_clk_ops,
8383
};
8484

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static struct clk_ops sh7780_shyway_clk_ops = {
8484

8585
static struct clk sh7780_shyway_clk = {
8686
.name = "shyway_clk",
87-
.flags = CLK_ALWAYS_ENABLED,
87+
.flags = CLK_ENABLE_ON_INIT,
8888
.ops = &sh7780_shyway_clk_ops,
8989
};
9090

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static struct clk_ops sh7785_shyway_clk_ops = {
8888

8989
static struct clk sh7785_shyway_clk = {
9090
.name = "shyway_clk",
91-
.flags = CLK_ALWAYS_ENABLED,
91+
.flags = CLK_ENABLE_ON_INIT,
9292
.ops = &sh7785_shyway_clk_ops,
9393
};
9494

@@ -104,7 +104,7 @@ static struct clk_ops sh7785_ddr_clk_ops = {
104104

105105
static struct clk sh7785_ddr_clk = {
106106
.name = "ddr_clk",
107-
.flags = CLK_ALWAYS_ENABLED,
107+
.flags = CLK_ENABLE_ON_INIT,
108108
.ops = &sh7785_ddr_clk_ops,
109109
};
110110

@@ -120,7 +120,7 @@ static struct clk_ops sh7785_ram_clk_ops = {
120120

121121
static struct clk sh7785_ram_clk = {
122122
.name = "ram_clk",
123-
.flags = CLK_ALWAYS_ENABLED,
123+
.flags = CLK_ENABLE_ON_INIT,
124124
.ops = &sh7785_ram_clk_ops,
125125
};
126126

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static struct clk_ops sh7786_shyway_clk_ops = {
9191

9292
static struct clk sh7786_shyway_clk = {
9393
.name = "shyway_clk",
94-
.flags = CLK_ALWAYS_ENABLED,
94+
.flags = CLK_ENABLE_ON_INIT,
9595
.ops = &sh7786_shyway_clk_ops,
9696
};
9797

@@ -107,7 +107,7 @@ static struct clk_ops sh7786_ddr_clk_ops = {
107107

108108
static struct clk sh7786_ddr_clk = {
109109
.name = "ddr_clk",
110-
.flags = CLK_ALWAYS_ENABLED,
110+
.flags = CLK_ENABLE_ON_INIT,
111111
.ops = &sh7786_ddr_clk_ops,
112112
};
113113

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static struct clk_ops shx3_shyway_clk_ops = {
9595

9696
static struct clk shx3_shyway_clk = {
9797
.name = "shyway_clk",
98-
.flags = CLK_ALWAYS_ENABLED,
98+
.flags = CLK_ENABLE_ON_INIT,
9999
.ops = &shx3_shyway_clk_ops,
100100
};
101101

0 commit comments

Comments
 (0)