aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2005-10-13 01:16:25 -0400
committerStephen Rothwell <sfr@canb.auug.org.au>2005-10-13 01:16:25 -0400
commiteec5ef909888cd9d25a61f904cd8f0db50ea0455 (patch)
tree1104668ef4480c9e0659e72afaa0a730aed63e49 /arch
parentae2752050d21f5aef811c362d3a47dce4694068d (diff)
ppc64: use powerpc of_device.c
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/kernel/Makefile3
-rw-r--r--arch/ppc64/kernel/Makefile1
-rw-r--r--arch/ppc64/kernel/of_device.c274
3 files changed, 2 insertions, 276 deletions
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index adac749a1a8..bce253969e4 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -14,6 +14,7 @@ obj-y := semaphore.o cputable.o
14obj-$(CONFIG_PPC64) += binfmt_elf32.o 14obj-$(CONFIG_PPC64) += binfmt_elf32.o
15obj-$(CONFIG_ALTIVEC) += vecemu.o vector.o 15obj-$(CONFIG_ALTIVEC) += vecemu.o vector.o
16obj-$(CONFIG_POWER4) += idle_power4.o 16obj-$(CONFIG_POWER4) += idle_power4.o
17obj-$(CONFIG_PPC_OF) += of_device.o
17 18
18ifeq ($(CONFIG_PPC_MERGE),y) 19ifeq ($(CONFIG_PPC_MERGE),y)
19 20
@@ -32,7 +33,7 @@ obj-y += process.o init_task.o \
32 prom.o systbl.o traps.o 33 prom.o systbl.o traps.o
33obj-$(CONFIG_PPC32) += entry_32.o setup_32.o misc_32.o 34obj-$(CONFIG_PPC32) += entry_32.o setup_32.o misc_32.o
34obj-$(CONFIG_PPC64) += setup_64.o misc_64.o 35obj-$(CONFIG_PPC64) += setup_64.o misc_64.o
35obj-$(CONFIG_PPC_OF) += prom_init.o of_device.o 36obj-$(CONFIG_PPC_OF) += prom_init.o
36obj-$(CONFIG_MODULES) += ppc_ksyms.o 37obj-$(CONFIG_MODULES) += ppc_ksyms.o
37obj-$(CONFIG_BOOTX_TEXT) += btext.o 38obj-$(CONFIG_BOOTX_TEXT) += btext.o
38 39
diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile
index 615484b09f9..1a8f3532885 100644
--- a/arch/ppc64/kernel/Makefile
+++ b/arch/ppc64/kernel/Makefile
@@ -8,7 +8,6 @@ EXTRA_CFLAGS += -mno-minimal-toc
8extra-y := head.o vmlinux.lds 8extra-y := head.o vmlinux.lds
9 9
10obj-y := setup.o entry.o misc.o prom.o 10obj-y := setup.o entry.o misc.o prom.o
11obj-$(CONFIG_PPC_OF) += of_device.o
12 11
13endif 12endif
14 13
diff --git a/arch/ppc64/kernel/of_device.c b/arch/ppc64/kernel/of_device.c
deleted file mode 100644
index 9f200f0f2ad..00000000000
--- a/arch/ppc64/kernel/of_device.c
+++ /dev/null
@@ -1,274 +0,0 @@
1#include <linux/config.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
4#include <linux/init.h>
5#include <linux/module.h>
6#include <linux/mod_devicetable.h>
7#include <asm/errno.h>
8#include <asm/of_device.h>
9
10/**
11 * of_match_device - Tell if an of_device structure has a matching
12 * of_match structure
13 * @ids: array of of device match structures to search in
14 * @dev: the of device structure to match against
15 *
16 * Used by a driver to check whether an of_device present in the
17 * system is in its list of supported devices.
18 */
19const struct of_device_id *of_match_device(const struct of_device_id *matches,
20 const struct of_device *dev)
21{
22 if (!dev->node)
23 return NULL;
24 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
25 int match = 1;
26 if (matches->name[0])
27 match &= dev->node->name
28 && !strcmp(matches->name, dev->node->name);
29 if (matches->type[0])
30 match &= dev->node->type
31 && !strcmp(matches->type, dev->node->type);
32 if (matches->compatible[0])
33 match &= device_is_compatible(dev->node,
34 matches->compatible);
35 if (match)
36 return matches;
37 matches++;
38 }
39 return NULL;
40}
41
42static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
43{
44 struct of_device * of_dev = to_of_device(dev);
45 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
46 const struct of_device_id * matches = of_drv->match_table;
47
48 if (!matches)
49 return 0;
50
51 return of_match_device(matches, of_dev) != NULL;
52}
53
54struct of_device *of_dev_get(struct of_device *dev)
55{
56 struct device *tmp;
57
58 if (!dev)
59 return NULL;
60 tmp = get_device(&dev->dev);
61 if (tmp)
62 return to_of_device(tmp);
63 else
64 return NULL;
65}
66
67void of_dev_put(struct of_device *dev)
68{
69 if (dev)
70 put_device(&dev->dev);
71}
72
73
74static int of_device_probe(struct device *dev)
75{
76 int error = -ENODEV;
77 struct of_platform_driver *drv;
78 struct of_device *of_dev;
79 const struct of_device_id *match;
80
81 drv = to_of_platform_driver(dev->driver);
82 of_dev = to_of_device(dev);
83
84 if (!drv->probe)
85 return error;
86
87 of_dev_get(of_dev);
88
89 match = of_match_device(drv->match_table, of_dev);
90 if (match)
91 error = drv->probe(of_dev, match);
92 if (error)
93 of_dev_put(of_dev);
94
95 return error;
96}
97
98static int of_device_remove(struct device *dev)
99{
100 struct of_device * of_dev = to_of_device(dev);
101 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
102
103 if (dev->driver && drv->remove)
104 drv->remove(of_dev);
105 return 0;
106}
107
108static int of_device_suspend(struct device *dev, pm_message_t state)
109{
110 struct of_device * of_dev = to_of_device(dev);
111 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
112 int error = 0;
113
114 if (dev->driver && drv->suspend)
115 error = drv->suspend(of_dev, state);
116 return error;
117}
118
119static int of_device_resume(struct device * dev)
120{
121 struct of_device * of_dev = to_of_device(dev);
122 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
123 int error = 0;
124
125 if (dev->driver && drv->resume)
126 error = drv->resume(of_dev);
127 return error;
128}
129
130struct bus_type of_platform_bus_type = {
131 .name = "of_platform",
132 .match = of_platform_bus_match,
133 .suspend = of_device_suspend,
134 .resume = of_device_resume,
135};
136
137static int __init of_bus_driver_init(void)
138{
139 return bus_register(&of_platform_bus_type);
140}
141
142postcore_initcall(of_bus_driver_init);
143
144int of_register_driver(struct of_platform_driver *drv)
145{
146 int count = 0;
147
148 /* initialize common driver fields */
149 drv->driver.name = drv->name;
150 drv->driver.bus = &of_platform_bus_type;
151 drv->driver.probe = of_device_probe;
152 drv->driver.remove = of_device_remove;
153
154 /* register with core */
155 count = driver_register(&drv->driver);
156 return count ? count : 1;
157}
158
159void of_unregister_driver(struct of_platform_driver *drv)
160{
161 driver_unregister(&drv->driver);
162}
163
164
165static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
166{
167 struct of_device *ofdev;
168
169 ofdev = to_of_device(dev);
170 return sprintf(buf, "%s", ofdev->node->full_name);
171}
172
173static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
174
175/**
176 * of_release_dev - free an of device structure when all users of it are finished.
177 * @dev: device that's been disconnected
178 *
179 * Will be called only by the device core when all users of this of device are
180 * done.
181 */
182void of_release_dev(struct device *dev)
183{
184 struct of_device *ofdev;
185
186 ofdev = to_of_device(dev);
187 kfree(ofdev);
188}
189
190int of_device_register(struct of_device *ofdev)
191{
192 int rc;
193 struct of_device **odprop;
194
195 BUG_ON(ofdev->node == NULL);
196
197 odprop = (struct of_device **)get_property(ofdev->node, "linux,device", NULL);
198 if (!odprop) {
199 struct property *new_prop;
200
201 new_prop = kmalloc(sizeof(struct property) + sizeof(struct of_device *),
202 GFP_KERNEL);
203 if (new_prop == NULL)
204 return -ENOMEM;
205 new_prop->name = "linux,device";
206 new_prop->length = sizeof(sizeof(struct of_device *));
207 new_prop->value = (unsigned char *)&new_prop[1];
208 odprop = (struct of_device **)new_prop->value;
209 *odprop = NULL;
210 prom_add_property(ofdev->node, new_prop);
211 }
212 *odprop = ofdev;
213
214 rc = device_register(&ofdev->dev);
215 if (rc)
216 return rc;
217
218 device_create_file(&ofdev->dev, &dev_attr_devspec);
219
220 return 0;
221}
222
223void of_device_unregister(struct of_device *ofdev)
224{
225 struct of_device **odprop;
226
227 device_remove_file(&ofdev->dev, &dev_attr_devspec);
228
229 odprop = (struct of_device **)get_property(ofdev->node, "linux,device", NULL);
230 if (odprop)
231 *odprop = NULL;
232
233 device_unregister(&ofdev->dev);
234}
235
236struct of_device* of_platform_device_create(struct device_node *np,
237 const char *bus_id,
238 struct device *parent)
239{
240 struct of_device *dev;
241
242 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
243 if (!dev)
244 return NULL;
245 memset(dev, 0, sizeof(*dev));
246
247 dev->node = np;
248 dev->dma_mask = 0xffffffffUL;
249 dev->dev.dma_mask = &dev->dma_mask;
250 dev->dev.parent = parent;
251 dev->dev.bus = &of_platform_bus_type;
252 dev->dev.release = of_release_dev;
253
254 strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
255
256 if (of_device_register(dev) != 0) {
257 kfree(dev);
258 return NULL;
259 }
260
261 return dev;
262}
263
264
265EXPORT_SYMBOL(of_match_device);
266EXPORT_SYMBOL(of_platform_bus_type);
267EXPORT_SYMBOL(of_register_driver);
268EXPORT_SYMBOL(of_unregister_driver);
269EXPORT_SYMBOL(of_device_register);
270EXPORT_SYMBOL(of_device_unregister);
271EXPORT_SYMBOL(of_dev_get);
272EXPORT_SYMBOL(of_dev_put);
273EXPORT_SYMBOL(of_platform_device_create);
274EXPORT_SYMBOL(of_release_dev);