dt: Refactor of_platform_bus_probe()
The current implementation uses three copies of of basically identical code. This patch consolidates them to make the code simpler. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
Родитель
4bbba111d9
Коммит
38e9e21dac
|
@ -210,13 +210,16 @@ struct platform_device *of_platform_device_create(struct device_node *np,
|
||||||
EXPORT_SYMBOL(of_platform_device_create);
|
EXPORT_SYMBOL(of_platform_device_create);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_platform_bus_create - Create an OF device for a bus node and all its
|
* of_platform_bus_create() - Create a device for a node and its children.
|
||||||
* children. Optionally recursively instantiate matching busses.
|
|
||||||
* @bus: device node of the bus to instantiate
|
* @bus: device node of the bus to instantiate
|
||||||
* @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
|
* @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
|
||||||
* disallow recursive creation of child busses
|
* disallow recursive creation of child buses
|
||||||
|
* @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(const struct device_node *bus,
|
static int of_platform_bus_create(struct device_node *bus,
|
||||||
const struct of_device_id *matches,
|
const struct of_device_id *matches,
|
||||||
struct device *parent)
|
struct device *parent)
|
||||||
{
|
{
|
||||||
|
@ -224,18 +227,13 @@ static int of_platform_bus_create(const struct device_node *bus,
|
||||||
struct platform_device *dev;
|
struct platform_device *dev;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
dev = of_platform_device_create(bus, NULL, parent);
|
||||||
|
if (!dev || !of_match_node(matches, bus))
|
||||||
|
return 0;
|
||||||
|
|
||||||
for_each_child_of_node(bus, child) {
|
for_each_child_of_node(bus, child) {
|
||||||
pr_debug(" create child: %s\n", child->full_name);
|
pr_debug(" create child: %s\n", child->full_name);
|
||||||
dev = of_platform_device_create(child, NULL, parent);
|
rc = of_platform_bus_create(child, matches, &dev->dev);
|
||||||
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) {
|
if (rc) {
|
||||||
of_node_put(child);
|
of_node_put(child);
|
||||||
break;
|
break;
|
||||||
|
@ -245,7 +243,7 @@ static int of_platform_bus_create(const struct device_node *bus,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_platform_bus_probe - Probe the device-tree for platform busses
|
* of_platform_bus_probe() - Probe the device-tree for platform buses
|
||||||
* @root: parent of the first level to probe or NULL for the root of the tree
|
* @root: parent of the first level to probe or NULL for the root of the tree
|
||||||
* @matches: match table, NULL to use the default
|
* @matches: match table, NULL to use the default
|
||||||
* @parent: parent to hook devices from, NULL for toplevel
|
* @parent: parent to hook devices from, NULL for toplevel
|
||||||
|
@ -258,7 +256,6 @@ int of_platform_bus_probe(struct device_node *root,
|
||||||
struct device *parent)
|
struct device *parent)
|
||||||
{
|
{
|
||||||
struct device_node *child;
|
struct device_node *child;
|
||||||
struct platform_device *dev;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
|
if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
|
||||||
|
@ -277,31 +274,15 @@ int of_platform_bus_probe(struct device_node *root,
|
||||||
* children
|
* children
|
||||||
*/
|
*/
|
||||||
if (of_match_node(matches, root)) {
|
if (of_match_node(matches, root)) {
|
||||||
pr_debug(" root match, create all sub devices\n");
|
rc = of_platform_bus_create(root, matches, parent);
|
||||||
dev = of_platform_device_create(root, NULL, parent);
|
} else for_each_child_of_node(root, child) {
|
||||||
if (dev == NULL)
|
|
||||||
goto bail;
|
|
||||||
|
|
||||||
pr_debug(" create all sub busses\n");
|
|
||||||
rc = of_platform_bus_create(root, matches, &dev->dev);
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
for_each_child_of_node(root, child) {
|
|
||||||
if (!of_match_node(matches, child))
|
if (!of_match_node(matches, child))
|
||||||
continue;
|
continue;
|
||||||
|
rc = of_platform_bus_create(child, matches, parent);
|
||||||
pr_debug(" match: %s\n", child->full_name);
|
if (rc)
|
||||||
dev = of_platform_device_create(child, NULL, parent);
|
|
||||||
if (dev == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
rc = of_platform_bus_create(child, matches, &dev->dev);
|
|
||||||
if (rc) {
|
|
||||||
of_node_put(child);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bail:
|
|
||||||
of_node_put(root);
|
of_node_put(root);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче