GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / sh / kernel / clkdev.c
blobbefc255830a4c1b30874ed44034d81680e13fbfd
1 /*
2 * arch/sh/kernel/clkdev.c
4 * Cloned from arch/arm/common/clkdev.c:
6 * Copyright (C) 2008 Russell King.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Helper for the clk API to assist looking up a struct clk.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/device.h>
17 #include <linux/list.h>
18 #include <linux/errno.h>
19 #include <linux/err.h>
20 #include <linux/string.h>
21 #include <linux/mutex.h>
22 #include <linux/clk.h>
23 #include <linux/slab.h>
24 #include <linux/bootmem.h>
25 #include <linux/mm.h>
26 #include <asm/clock.h>
27 #include <asm/clkdev.h>
29 static LIST_HEAD(clocks);
30 static DEFINE_MUTEX(clocks_mutex);
33 * Find the correct struct clk for the device and connection ID.
34 * We do slightly fuzzy matching here:
35 * An entry with a NULL ID is assumed to be a wildcard.
36 * If an entry has a device ID, it must match
37 * If an entry has a connection ID, it must match
38 * Then we take the most specific entry - with the following
39 * order of precedence: dev+con > dev only > con only.
41 static struct clk *clk_find(const char *dev_id, const char *con_id)
43 struct clk_lookup *p;
44 struct clk *clk = NULL;
45 int match, best = 0;
47 list_for_each_entry(p, &clocks, node) {
48 match = 0;
49 if (p->dev_id) {
50 if (!dev_id || strcmp(p->dev_id, dev_id))
51 continue;
52 match += 2;
54 if (p->con_id) {
55 if (!con_id || strcmp(p->con_id, con_id))
56 continue;
57 match += 1;
59 if (match == 0)
60 continue;
62 if (match > best) {
63 clk = p->clk;
64 best = match;
67 return clk;
70 struct clk *clk_get_sys(const char *dev_id, const char *con_id)
72 struct clk *clk;
74 mutex_lock(&clocks_mutex);
75 clk = clk_find(dev_id, con_id);
76 mutex_unlock(&clocks_mutex);
78 return clk ? clk : ERR_PTR(-ENOENT);
80 EXPORT_SYMBOL(clk_get_sys);
82 void clkdev_add(struct clk_lookup *cl)
84 mutex_lock(&clocks_mutex);
85 list_add_tail(&cl->node, &clocks);
86 mutex_unlock(&clocks_mutex);
88 EXPORT_SYMBOL(clkdev_add);
90 void __init clkdev_add_table(struct clk_lookup *cl, size_t num)
92 mutex_lock(&clocks_mutex);
93 while (num--) {
94 list_add_tail(&cl->node, &clocks);
95 cl++;
97 mutex_unlock(&clocks_mutex);
100 #define MAX_DEV_ID 20
101 #define MAX_CON_ID 16
103 struct clk_lookup_alloc {
104 struct clk_lookup cl;
105 char dev_id[MAX_DEV_ID];
106 char con_id[MAX_CON_ID];
109 struct clk_lookup * __init_refok
110 clkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt, ...)
112 struct clk_lookup_alloc *cla;
114 if (!slab_is_available())
115 cla = alloc_bootmem_low_pages(sizeof(*cla));
116 else
117 cla = kzalloc(sizeof(*cla), GFP_KERNEL);
119 if (!cla)
120 return NULL;
122 cla->cl.clk = clk;
123 if (con_id) {
124 strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
125 cla->cl.con_id = cla->con_id;
128 if (dev_fmt) {
129 va_list ap;
131 va_start(ap, dev_fmt);
132 vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
133 cla->cl.dev_id = cla->dev_id;
134 va_end(ap);
137 return &cla->cl;
139 EXPORT_SYMBOL(clkdev_alloc);
141 int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
142 struct device *dev)
144 struct clk *r = clk_get(dev, id);
145 struct clk_lookup *l;
147 if (IS_ERR(r))
148 return PTR_ERR(r);
150 l = clkdev_alloc(r, alias, alias_dev_name);
151 clk_put(r);
152 if (!l)
153 return -ENODEV;
154 clkdev_add(l);
155 return 0;
157 EXPORT_SYMBOL(clk_add_alias);
160 * clkdev_drop - remove a clock dynamically allocated
162 void clkdev_drop(struct clk_lookup *cl)
164 mutex_lock(&clocks_mutex);
165 list_del(&cl->node);
166 mutex_unlock(&clocks_mutex);
167 kfree(cl);
169 EXPORT_SYMBOL(clkdev_drop);