platform.c (02e2407858fd62053bf60349c0e72cd1c7a4a60e) platform.c (38e9e21dac33082f0440d24aefb3466bb18bfed6)
1/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org>
4 * and Arnd Bergmann, IBM Corp.
5 * Merged from powerpc/kernel/of_platform.c and
6 * sparc{,64}/kernel/of_device.c by Stephen Rothwell
7 *
8 * This program is free software; you can redistribute it and/or

--- 196 unchanged lines hidden (view full) ---

205 return NULL;
206 }
207
208 return dev;
209}
210EXPORT_SYMBOL(of_platform_device_create);
211
212/**
1/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org>
4 * and Arnd Bergmann, IBM Corp.
5 * Merged from powerpc/kernel/of_platform.c and
6 * sparc{,64}/kernel/of_device.c by Stephen Rothwell
7 *
8 * This program is free software; you can redistribute it and/or

--- 196 unchanged lines hidden (view full) ---

205 return NULL;
206 }
207
208 return dev;
209}
210EXPORT_SYMBOL(of_platform_device_create);
211
212/**
213 * of_platform_bus_create - Create an OF device for a bus node and all its
214 * children. Optionally recursively instantiate matching busses.
213 * of_platform_bus_create() - Create a device for a node and its children.
215 * @bus: device node of the bus to instantiate
216 * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
214 * @bus: device node of the bus to instantiate
215 * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
217 * disallow recursive creation of child busses
216 * disallow recursive creation of child buses
217 * @parent: parent for new device, or NULL for top level.
218 *
219 * Creates a platform_device for the provided device_node, and optionally
220 * recursively create devices for all the child nodes.
218 */
221 */
219static int of_platform_bus_create(const struct device_node *bus,
222static int of_platform_bus_create(struct device_node *bus,
220 const struct of_device_id *matches,
221 struct device *parent)
222{
223 struct device_node *child;
224 struct platform_device *dev;
225 int rc = 0;
226
223 const struct of_device_id *matches,
224 struct device *parent)
225{
226 struct device_node *child;
227 struct platform_device *dev;
228 int rc = 0;
229
230 dev = of_platform_device_create(bus, NULL, parent);
231 if (!dev || !of_match_node(matches, bus))
232 return 0;
233
227 for_each_child_of_node(bus, child) {
228 pr_debug(" create child: %s\n", child->full_name);
234 for_each_child_of_node(bus, child) {
235 pr_debug(" create child: %s\n", child->full_name);
229 dev = of_platform_device_create(child, NULL, parent);
230 if (dev == NULL)
231 continue;
232
233 if (!of_match_node(matches, child))
234 continue;
235 if (rc == 0) {
236 pr_debug(" and sub busses\n");
237 rc = of_platform_bus_create(child, matches, &dev->dev);
238 }
236 rc = of_platform_bus_create(child, matches, &dev->dev);
239 if (rc) {
240 of_node_put(child);
241 break;
242 }
243 }
244 return rc;
245}
246
247/**
237 if (rc) {
238 of_node_put(child);
239 break;
240 }
241 }
242 return rc;
243}
244
245/**
248 * of_platform_bus_probe - Probe the device-tree for platform busses
246 * of_platform_bus_probe() - Probe the device-tree for platform buses
249 * @root: parent of the first level to probe or NULL for the root of the tree
250 * @matches: match table, NULL to use the default
251 * @parent: parent to hook devices from, NULL for toplevel
252 *
253 * Note that children of the provided root are not instantiated as devices
254 * unless the specified root itself matches the bus list and is not NULL.
255 */
256int of_platform_bus_probe(struct device_node *root,
257 const struct of_device_id *matches,
258 struct device *parent)
259{
260 struct device_node *child;
247 * @root: parent of the first level to probe or NULL for the root of the tree
248 * @matches: match table, NULL to use the default
249 * @parent: parent to hook devices from, NULL for toplevel
250 *
251 * Note that children of the provided root are not instantiated as devices
252 * unless the specified root itself matches the bus list and is not NULL.
253 */
254int of_platform_bus_probe(struct device_node *root,
255 const struct of_device_id *matches,
256 struct device *parent)
257{
258 struct device_node *child;
261 struct platform_device *dev;
262 int rc = 0;
263
264 if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
265 return -EINVAL;
266 if (root == NULL)
267 root = of_find_node_by_path("/");
268 else
269 of_node_get(root);
270 if (root == NULL)
271 return -EINVAL;
272
273 pr_debug("of_platform_bus_probe()\n");
274 pr_debug(" starting at: %s\n", root->full_name);
275
276 /* Do a self check of bus type, if there's a match, create
277 * children
278 */
279 if (of_match_node(matches, root)) {
259 int rc = 0;
260
261 if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
262 return -EINVAL;
263 if (root == NULL)
264 root = of_find_node_by_path("/");
265 else
266 of_node_get(root);
267 if (root == NULL)
268 return -EINVAL;
269
270 pr_debug("of_platform_bus_probe()\n");
271 pr_debug(" starting at: %s\n", root->full_name);
272
273 /* Do a self check of bus type, if there's a match, create
274 * children
275 */
276 if (of_match_node(matches, root)) {
280 pr_debug(" root match, create all sub devices\n");
281 dev = of_platform_device_create(root, NULL, parent);
282 if (dev == NULL)
283 goto bail;
284
285 pr_debug(" create all sub busses\n");
286 rc = of_platform_bus_create(root, matches, &dev->dev);
287 goto bail;
288 }
289 for_each_child_of_node(root, child) {
277 rc = of_platform_bus_create(root, matches, parent);
278 } else for_each_child_of_node(root, child) {
290 if (!of_match_node(matches, child))
291 continue;
279 if (!of_match_node(matches, child))
280 continue;
292
293 pr_debug(" match: %s\n", child->full_name);
294 dev = of_platform_device_create(child, NULL, parent);
295 if (dev == NULL)
296 continue;
297
298 rc = of_platform_bus_create(child, matches, &dev->dev);
299 if (rc) {
300 of_node_put(child);
281 rc = of_platform_bus_create(child, matches, parent);
282 if (rc)
301 break;
283 break;
302 }
303 }
284 }
304 bail:
285
305 of_node_put(root);
306 return rc;
307}
308EXPORT_SYMBOL(of_platform_bus_probe);
309#endif /* !CONFIG_SPARC */
286 of_node_put(root);
287 return rc;
288}
289EXPORT_SYMBOL(of_platform_bus_probe);
290#endif /* !CONFIG_SPARC */