Skip to content

Commit 4f5ecaa

Browse files
Magnus Dammpmundt
authored andcommitted
sh: clock framework update, fix count and kill off kref
This patch updates the clock framework use count code. With this patch the enable() and disable() callbacks only get called when counting from and to zero. While at it the kref stuff gets replaced with an int. Signed-off-by: Magnus Damm <damm@igel.co.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 7d170b1 commit 4f5ecaa

2 files changed

Lines changed: 39 additions & 34 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef __ASM_SH_CLOCK_H
22
#define __ASM_SH_CLOCK_H
33

4-
#include <linux/kref.h>
54
#include <linux/list.h>
65
#include <linux/seq_file.h>
76
#include <linux/clk.h>
@@ -28,7 +27,7 @@ struct clk {
2827
struct clk *parent;
2928
struct clk_ops *ops;
3029

31-
struct kref kref;
30+
int usecount;
3231

3332
unsigned long rate;
3433
unsigned long flags;
@@ -37,6 +36,7 @@ struct clk {
3736

3837
#define CLK_ALWAYS_ENABLED (1 << 0)
3938
#define CLK_RATE_PROPAGATES (1 << 1)
39+
#define CLK_NEEDS_INIT (1 << 2)
4040

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

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

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/module.h>
2020
#include <linux/mutex.h>
2121
#include <linux/list.h>
22-
#include <linux/kref.h>
2322
#include <linux/kobject.h>
2423
#include <linux/sysdev.h>
2524
#include <linux/seq_file.h>
@@ -90,7 +89,7 @@ static void propagate_rate(struct clk *clk)
9089
}
9190
}
9291

93-
static int __clk_enable(struct clk *clk)
92+
static void __clk_init(struct clk *clk)
9493
{
9594
/*
9695
* See if this is the first time we're enabling the clock, some
@@ -100,19 +99,33 @@ static int __clk_enable(struct clk *clk)
10099
* divisors to use before it can effectively recalc.
101100
*/
102101

103-
if (clk->flags & CLK_ALWAYS_ENABLED) {
104-
kref_get(&clk->kref);
105-
return 0;
106-
}
107-
108-
if (unlikely(atomic_read(&clk->kref.refcount) == 1))
102+
if (clk->flags & CLK_NEEDS_INIT) {
109103
if (clk->ops && clk->ops->init)
110104
clk->ops->init(clk);
111105

112-
kref_get(&clk->kref);
106+
clk->flags &= ~CLK_NEEDS_INIT;
107+
}
108+
}
109+
110+
static int __clk_enable(struct clk *clk)
111+
{
112+
if (!clk)
113+
return -EINVAL;
114+
115+
clk->usecount++;
116+
117+
/* nothing to do if always enabled */
118+
if (clk->flags & CLK_ALWAYS_ENABLED)
119+
return 0;
120+
121+
if (clk->usecount == 1) {
122+
__clk_init(clk);
113123

114-
if (likely(clk->ops && clk->ops->enable))
115-
clk->ops->enable(clk);
124+
__clk_enable(clk->parent);
125+
126+
if (clk->ops && clk->ops->enable)
127+
clk->ops->enable(clk);
128+
}
116129

117130
return 0;
118131
}
@@ -122,11 +135,6 @@ int clk_enable(struct clk *clk)
122135
unsigned long flags;
123136
int ret;
124137

125-
if (!clk)
126-
return -EINVAL;
127-
128-
clk_enable(clk->parent);
129-
130138
spin_lock_irqsave(&clock_lock, flags);
131139
ret = __clk_enable(clk);
132140
spin_unlock_irqrestore(&clock_lock, flags);
@@ -135,36 +143,33 @@ int clk_enable(struct clk *clk)
135143
}
136144
EXPORT_SYMBOL_GPL(clk_enable);
137145

138-
static void clk_kref_release(struct kref *kref)
139-
{
140-
/* Nothing to do */
141-
}
142-
143146
static void __clk_disable(struct clk *clk)
144147
{
145-
int count = kref_put(&clk->kref, clk_kref_release);
148+
if (!clk)
149+
return;
150+
151+
clk->usecount--;
152+
153+
WARN_ON(clk->usecount < 0);
146154

147155
if (clk->flags & CLK_ALWAYS_ENABLED)
148156
return;
149157

150-
if (!count) { /* count reaches zero, disable the clock */
158+
if (clk->usecount == 0) {
151159
if (likely(clk->ops && clk->ops->disable))
152160
clk->ops->disable(clk);
161+
162+
__clk_disable(clk->parent);
153163
}
154164
}
155165

156166
void clk_disable(struct clk *clk)
157167
{
158168
unsigned long flags;
159169

160-
if (!clk)
161-
return;
162-
163170
spin_lock_irqsave(&clock_lock, flags);
164171
__clk_disable(clk);
165172
spin_unlock_irqrestore(&clock_lock, flags);
166-
167-
clk_disable(clk->parent);
168173
}
169174
EXPORT_SYMBOL_GPL(clk_disable);
170175

@@ -173,14 +178,14 @@ int clk_register(struct clk *clk)
173178
mutex_lock(&clock_list_sem);
174179

175180
list_add(&clk->node, &clock_list);
176-
kref_init(&clk->kref);
181+
clk->usecount = 0;
182+
clk->flags |= CLK_NEEDS_INIT;
177183

178184
mutex_unlock(&clock_list_sem);
179185

180186
if (clk->flags & CLK_ALWAYS_ENABLED) {
187+
__clk_init(clk);
181188
pr_debug( "Clock '%s' is ALWAYS_ENABLED\n", clk->name);
182-
if (clk->ops && clk->ops->init)
183-
clk->ops->init(clk);
184189
if (clk->ops && clk->ops->enable)
185190
clk->ops->enable(clk);
186191
pr_debug( "Enabled.");
@@ -356,7 +361,7 @@ static int show_clocks(char *buf, char **start, off_t off,
356361
p += sprintf(p, "%-12s\t: %ld.%02ldMHz\t%s\n", clk->name,
357362
rate / 1000000, (rate % 1000000) / 10000,
358363
((clk->flags & CLK_ALWAYS_ENABLED) ||
359-
(atomic_read(&clk->kref.refcount) != 1)) ?
364+
clk->usecount > 0) ?
360365
"enabled" : "disabled");
361366
}
362367

0 commit comments

Comments
 (0)