int of_platform_bus_probe(struct device_node *root, struct of_device_id *matches, struct device *parent) { struct device_node *child; struct of_device *dev; int rc = 0; if (matches == NULL) matches = of_default_bus_ids; if (matches == OF_NO_DEEP_PROBE) return -EINVAL; if (root == NULL) root = of_find_node_by_path("/"); else of_node_get(root); pr_debug("of_platform_bus_probe()\n"); pr_debug(" starting at: %s\n", root->full_name); /* Do a self check of bus type, if there's a match, create * children */ if (of_match_node(matches, root)) { pr_debug(" root match, create all sub devices\n"); dev = of_platform_device_create(root, NULL, parent); if (dev == NULL) { rc = -ENOMEM; goto bail; } pr_debug(" create all sub busses\n"); rc = of_platform_bus_create(root, matches, &dev->dev); goto bail; } for (child = NULL; (child = of_get_next_child(root, child)); ) { if (!of_match_node(matches, child)) continue; pr_debug(" match: %s\n", child->full_name); dev = of_platform_device_create(child, NULL, parent); if (dev == NULL) rc = -ENOMEM; else rc = of_platform_bus_create(child, matches, &dev->dev); if (rc) { of_node_put(child); break; } } bail: of_node_put(root); return rc; }
/** * of_platform_bus_create - Create an OF device for a bus node and all its * children. Optionally recursively instanciate matching busses. * @bus: device node of the bus to instanciate * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to * disallow recursive creation of child busses */ static int of_platform_bus_create(struct device_node *bus, struct of_device_id *matches, struct device *parent) { struct device_node *child; struct of_device *dev; int rc = 0; for (child = NULL; (child = of_get_next_child(bus, child)); ) { pr_debug(" create child: %s\n", child->full_name); dev = of_platform_device_create(child, NULL, parent); if (dev == NULL) rc = -ENOMEM; else if (!of_match_node(matches, child)) continue; if (rc == 0) { pr_debug(" and sub busses\n"); rc = of_platform_bus_create(child, matches, &dev->dev); } if (rc) { of_node_put(child); break; } } return rc; }
/** * of_platform_bus_create() - Create a device for a node and its children. * @bus: device node of the bus to instantiate * @matches: match table for bus nodes * @parent: parent for new device, or NULL for top level. * * Creates a platform_device for the provided device_node, and optionally * recursively create devices for all the child nodes. */ static int of_platform_bus_create(struct device_node *bus, const struct of_device_id *matches, struct device_d *parent) { struct device_node *child; struct device_d *dev; int rc = 0; /* Make sure it has a compatible property */ if (!of_get_property(bus, "compatible", NULL)) { pr_debug("%s() - skipping %s, no compatible prop\n", __func__, bus->full_name); return 0; } if (of_device_is_compatible(bus, "arm,primecell")) { of_amba_device_create(bus); return 0; } dev = of_platform_device_create(bus, parent); if (!dev || !of_match_node(matches, bus)) return 0; for_each_child_of_node(bus, child) { pr_debug(" create child: %s\n", child->full_name); rc = of_platform_bus_create(child, matches, dev); if (rc) break; }
/** * of_platform_bus_create - Create an OF device for a bus node and all its * children. Optionally recursively instantiate matching busses. * @bus: device node of the bus to instantiate * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to * disallow recursive creation of child busses */ static int of_platform_bus_create(const struct device_node *bus, const struct of_device_id *matches, struct device *parent) { struct device_node *child; struct platform_device *dev; int rc = 0; for_each_child_of_node(bus, child) { pr_debug(" create child: %s\n", child->full_name); dev = of_platform_device_create(child, NULL, parent); if (dev == NULL) continue; if (!of_match_node(matches, child)) continue; if (rc == 0) { pr_debug(" and sub busses\n"); rc = of_platform_bus_create(child, matches, &dev->dev); } if (rc) { of_node_put(child); break; } }
/** * of_platform_bus_create() - Create a device for a node and its children. * @bus: device node of the bus to instantiate * @matches: match table for bus nodes * @lookup: auxdata table for matching id and platform_data with device nodes * @parent: parent for new device, or NULL for top level. * @strict: require compatible property * * Creates a platform_device for the provided device_node, and optionally * recursively create devices for all the child nodes. */ static int of_platform_bus_create(struct device_node *bus, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent, bool strict) { const struct of_dev_auxdata *auxdata; struct device_node *child; struct platform_device *dev; const char *bus_id = NULL; void *platform_data = NULL; int rc = 0; /* Make sure it has a compatible property */ if (strict && (!of_get_property(bus, "compatible", NULL))) { pr_debug("%s() - skipping %s, no compatible prop\n", __func__, bus->full_name); return 0; } if (of_node_check_flag(bus, OF_POPULATED_BUS)) { pr_debug("%s() - skipping %s, already populated\n", __func__, bus->full_name); return 0; } auxdata = of_dev_lookup(lookup, bus); if (auxdata) { bus_id = auxdata->name; platform_data = auxdata->platform_data; } if (of_device_is_compatible(bus, "arm,primecell")) { /* * Don't return an error here to keep compatibility with older * device tree files. */ of_amba_device_create(bus, bus_id, platform_data, parent); return 0; } dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent); if (!dev || !of_match_node(matches, bus)) return 0; for_each_child_of_node(bus, child) { pr_debug(" create child: %s\n", child->full_name); rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict); if (rc) { of_node_put(child); break; } }
static int of_platform_bus_create(struct device_node *bus, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent, bool strict) { const struct of_dev_auxdata *auxdata; struct device_node *child; struct platform_device *dev; const char *bus_id = NULL; void *platform_data = NULL; int rc = 0; if (strict && (!of_get_property(bus, "compatible", NULL))) { pr_debug("%s() - skipping %s, no compatible prop\n", __func__, bus->full_name); return 0; } auxdata = of_dev_lookup(lookup, bus); if (auxdata) { bus_id = auxdata->name; platform_data = auxdata->platform_data; } if (of_device_is_compatible(bus, "arm,primecell")) { of_amba_device_create(bus, bus_id, platform_data, parent); return 0; } dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent); if (!dev || !of_match_node(matches, bus)) return 0; for_each_child_of_node(bus, child) { pr_debug(" create child: %s\n", child->full_name); rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict); if (rc) { of_node_put(child); break; } }