aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel
diff options
context:
space:
mode:
authorJoachim Fenkes <fenkes@de.ibm.com>2007-09-26 05:45:21 -0400
committerPaul Mackerras <paulus@samba.org>2007-10-17 08:30:08 -0400
commit55347cc9962fbf2048a3cf78e92c3f52035ac524 (patch)
tree584f473e33bb68198a1cd8aa6f2b50e657aed321 /arch/powerpc/kernel
parenta988c0a627ee654b4d692570572567aec06c3e13 (diff)
[POWERPC] ibmebus: Add device creation and bus probing based on of_device
The devtree root is now searched for devices matching a built-in whitelist during boot, so these devices appear on the bus from the beginning. It is still possible to manually add/remove devices to/from the bus by using the probe/remove sysfs interface. Also, when a device driver registers itself, the devtree is matched against its matchlist. Signed-off-by: Joachim Fenkes <fenkes@de.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r--arch/powerpc/kernel/ibmebus.c100
1 files changed, 82 insertions, 18 deletions
diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index af21306e2ef9..d21658140b6e 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -51,6 +51,13 @@ static struct device ibmebus_bus_device = { /* fake "parent" device */
51 51
52struct bus_type ibmebus_bus_type; 52struct bus_type ibmebus_bus_type;
53 53
54/* These devices will automatically be added to the bus during init */
55static struct of_device_id builtin_matches[] = {
56 { .compatible = "IBM,lhca" },
57 { .compatible = "IBM,lhea" },
58 {},
59};
60
54static void *ibmebus_alloc_coherent(struct device *dev, 61static void *ibmebus_alloc_coherent(struct device *dev,
55 size_t size, 62 size_t size,
56 dma_addr_t *dma_handle, 63 dma_addr_t *dma_handle,
@@ -125,6 +132,67 @@ static struct dma_mapping_ops ibmebus_dma_ops = {
125 .dma_supported = ibmebus_dma_supported, 132 .dma_supported = ibmebus_dma_supported,
126}; 133};
127 134
135static int ibmebus_match_path(struct device *dev, void *data)
136{
137 struct device_node *dn = to_of_device(dev)->node;
138 return (dn->full_name &&
139 (strcasecmp((char *)data, dn->full_name) == 0));
140}
141
142static int ibmebus_match_node(struct device *dev, void *data)
143{
144 return to_of_device(dev)->node == data;
145}
146
147static int ibmebus_create_device(struct device_node *dn)
148{
149 struct of_device *dev;
150 int ret;
151
152 dev = of_device_alloc(dn, NULL, &ibmebus_bus_device);
153 if (!dev)
154 return -ENOMEM;
155
156 dev->dev.bus = &ibmebus_bus_type;
157 dev->dev.archdata.dma_ops = &ibmebus_dma_ops;
158
159 ret = of_device_register(dev);
160 if (ret) {
161 of_device_free(dev);
162 return ret;
163 }
164
165 return 0;
166}
167
168static int ibmebus_create_devices(const struct of_device_id *matches)
169{
170 struct device_node *root, *child;
171 int ret = 0;
172
173 root = of_find_node_by_path("/");
174
175 for (child = NULL; (child = of_get_next_child(root, child)); ) {
176 if (!of_match_node(matches, child))
177 continue;
178
179 if (bus_find_device(&ibmebus_bus_type, NULL, child,
180 ibmebus_match_node))
181 continue;
182
183 ret = ibmebus_create_device(child);
184 if (ret) {
185 printk(KERN_ERR "%s: failed to create device (%i)",
186 __FUNCTION__, ret);
187 of_node_put(child);
188 break;
189 }
190 }
191
192 of_node_put(root);
193 return ret;
194}
195
128int ibmebus_register_driver(struct ibmebus_driver *drv) 196int ibmebus_register_driver(struct ibmebus_driver *drv)
129{ 197{
130 return 0; 198 return 0;
@@ -173,18 +241,6 @@ static struct device_attribute ibmebus_dev_attrs[] = {
173 __ATTR_NULL 241 __ATTR_NULL
174}; 242};
175 243
176static int ibmebus_match_path(struct device *dev, void *data)
177{
178 int rc;
179 struct device_node *dn =
180 of_node_get(to_ibmebus_dev(dev)->ofdev.node);
181
182 rc = (dn->full_name && (strcasecmp((char*)data, dn->full_name) == 0));
183
184 of_node_put(dn);
185 return rc;
186}
187
188static char *ibmebus_chomp(const char *in, size_t count) 244static char *ibmebus_chomp(const char *in, size_t count)
189{ 245{
190 char *out = kmalloc(count + 1, GFP_KERNEL); 246 char *out = kmalloc(count + 1, GFP_KERNEL);
@@ -204,9 +260,8 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
204 const char *buf, size_t count) 260 const char *buf, size_t count)
205{ 261{
206 struct device_node *dn = NULL; 262 struct device_node *dn = NULL;
207 struct ibmebus_dev *dev;
208 char *path; 263 char *path;
209 ssize_t rc; 264 ssize_t rc = 0;
210 265
211 path = ibmebus_chomp(buf, count); 266 path = ibmebus_chomp(buf, count);
212 if (!path) 267 if (!path)
@@ -221,9 +276,8 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
221 } 276 }
222 277
223 if ((dn = of_find_node_by_path(path))) { 278 if ((dn = of_find_node_by_path(path))) {
224/* dev = ibmebus_register_device_node(dn); */ 279 rc = ibmebus_create_device(dn);
225 of_node_put(dn); 280 of_node_put(dn);
226 rc = IS_ERR(dev) ? PTR_ERR(dev) : count;
227 } else { 281 } else {
228 printk(KERN_WARNING "%s: no such device node: %s\n", 282 printk(KERN_WARNING "%s: no such device node: %s\n",
229 __FUNCTION__, path); 283 __FUNCTION__, path);
@@ -232,7 +286,9 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
232 286
233out: 287out:
234 kfree(path); 288 kfree(path);
235 return rc; 289 if (rc)
290 return rc;
291 return count;
236} 292}
237 293
238static ssize_t ibmebus_store_remove(struct bus_type *bus, 294static ssize_t ibmebus_store_remove(struct bus_type *bus,
@@ -247,7 +303,7 @@ static ssize_t ibmebus_store_remove(struct bus_type *bus,
247 303
248 if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path, 304 if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path,
249 ibmebus_match_path))) { 305 ibmebus_match_path))) {
250/* ibmebus_unregister_device(dev); */ 306 of_device_unregister(to_of_device(dev));
251 307
252 kfree(path); 308 kfree(path);
253 return count; 309 return count;
@@ -267,6 +323,7 @@ static struct bus_attribute ibmebus_bus_attrs[] = {
267}; 323};
268 324
269struct bus_type ibmebus_bus_type = { 325struct bus_type ibmebus_bus_type = {
326 .uevent = of_device_uevent,
270 .dev_attrs = ibmebus_dev_attrs, 327 .dev_attrs = ibmebus_dev_attrs,
271 .bus_attrs = ibmebus_bus_attrs 328 .bus_attrs = ibmebus_bus_attrs
272}; 329};
@@ -294,6 +351,13 @@ static int __init ibmebus_bus_init(void)
294 return err; 351 return err;
295 } 352 }
296 353
354 err = ibmebus_create_devices(builtin_matches);
355 if (err) {
356 device_unregister(&ibmebus_bus_device);
357 bus_unregister(&ibmebus_bus_type);
358 return err;
359 }
360
297 return 0; 361 return 0;
298} 362}
299postcore_initcall(ibmebus_bus_init); 363postcore_initcall(ibmebus_bus_init);