aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2012-05-02 04:30:32 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2012-05-02 04:30:32 -0400
commite9d7f4065408e92338a41b809e437c6e043da090 (patch)
treed89c702ecd99fc606c9d5265278cabb6d3744607 /drivers/clk
parent67b508715a61962f9b5b3ef3432e045a9cba4f1e (diff)
CLKDEV: provide helpers for common clock framework
The common clock framework allocates clocks dynamically. Provide a set of helpers to streamline the clkdev registration of the clock lookups to avoid repetitive code sequences. Reviewed-by: Viresh Kumar <viresh.kumar@st.com> Tested-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/clkdev.c84
1 files changed, 78 insertions, 6 deletions
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index d4a59931e75e..c535cf8c5770 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -166,8 +166,9 @@ struct clk_lookup_alloc {
166 char con_id[MAX_CON_ID]; 166 char con_id[MAX_CON_ID];
167}; 167};
168 168
169struct clk_lookup * __init_refok 169static struct clk_lookup * __init_refok
170clkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt, ...) 170vclkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt,
171 va_list ap)
171{ 172{
172 struct clk_lookup_alloc *cla; 173 struct clk_lookup_alloc *cla;
173 174
@@ -182,16 +183,25 @@ clkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt, ...)
182 } 183 }
183 184
184 if (dev_fmt) { 185 if (dev_fmt) {
185 va_list ap;
186
187 va_start(ap, dev_fmt);
188 vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap); 186 vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
189 cla->cl.dev_id = cla->dev_id; 187 cla->cl.dev_id = cla->dev_id;
190 va_end(ap);
191 } 188 }
192 189
193 return &cla->cl; 190 return &cla->cl;
194} 191}
192
193struct clk_lookup * __init_refok
194clkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt, ...)
195{
196 struct clk_lookup *cl;
197 va_list ap;
198
199 va_start(ap, dev_fmt);
200 cl = vclkdev_alloc(clk, con_id, dev_fmt, ap);
201 va_end(ap);
202
203 return cl;
204}
195EXPORT_SYMBOL(clkdev_alloc); 205EXPORT_SYMBOL(clkdev_alloc);
196 206
197int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, 207int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
@@ -223,3 +233,65 @@ void clkdev_drop(struct clk_lookup *cl)
223 kfree(cl); 233 kfree(cl);
224} 234}
225EXPORT_SYMBOL(clkdev_drop); 235EXPORT_SYMBOL(clkdev_drop);
236
237/**
238 * clk_register_clkdev - register one clock lookup for a struct clk
239 * @clk: struct clk to associate with all clk_lookups
240 * @con_id: connection ID string on device
241 * @dev_id: format string describing device name
242 *
243 * con_id or dev_id may be NULL as a wildcard, just as in the rest of
244 * clkdev.
245 *
246 * To make things easier for mass registration, we detect error clks
247 * from a previous clk_register() call, and return the error code for
248 * those. This is to permit this function to be called immediately
249 * after clk_register().
250 */
251int clk_register_clkdev(struct clk *clk, const char *con_id,
252 const char *dev_fmt, ...)
253{
254 struct clk_lookup *cl;
255 va_list ap;
256
257 if (IS_ERR(clk))
258 return PTR_ERR(clk);
259
260 va_start(ap, dev_fmt);
261 cl = vclkdev_alloc(clk, con_id, dev_fmt, ap);
262 va_end(ap);
263
264 if (!cl)
265 return -ENOMEM;
266
267 clkdev_add(cl);
268
269 return 0;
270}
271
272/**
273 * clk_register_clkdevs - register a set of clk_lookup for a struct clk
274 * @clk: struct clk to associate with all clk_lookups
275 * @cl: array of clk_lookup structures with con_id and dev_id pre-initialized
276 * @num: number of clk_lookup structures to register
277 *
278 * To make things easier for mass registration, we detect error clks
279 * from a previous clk_register() call, and return the error code for
280 * those. This is to permit this function to be called immediately
281 * after clk_register().
282 */
283int clk_register_clkdevs(struct clk *clk, struct clk_lookup *cl, size_t num)
284{
285 unsigned i;
286
287 if (IS_ERR(clk))
288 return PTR_ERR(clk);
289
290 for (i = 0; i < num; i++, cl++) {
291 cl->clk = clk;
292 clkdev_add(cl);
293 }
294
295 return 0;
296}
297EXPORT_SYMBOL(clk_register_clkdevs);