Message ID | 1306359073-16274-3-git-send-email-robherring2@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wednesday 25 May 2011, Rob Herring wrote: > > From: Rob Herring <rob.herring@calxeda.com> > > Add support to the platform bus scanning to call custom device creation > functions. This enables creation of non-platform devices like amba_bus. > > Cc: Jeremy Kerr <jeremy.kerr@canonical.com> > Cc: Grant Likely <grant.likely@secretlab.ca> > Cc: linux@arm.linux.org.uk > Cc: arnd@arndb.de > Cc: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: Rob Herring <rob.herring@calxeda.com> This creates a confusing mix of match table entries: Normally, all entries in the match table are meant to identify child buses, but if I read your patch correctly, you now also need to match on the amba devices themselves, including the creation of platform devices for each child device node under an amba device. I don't think that was the intention. Maybe we need to pass two match tables into of_platform_bus_probe() instead: one to identify the buses, and another one that is used to create the actual devices. Arnd
Arnd, On 05/26/2011 08:11 AM, Arnd Bergmann wrote: > On Wednesday 25 May 2011, Rob Herring wrote: >> >> From: Rob Herring<rob.herring@calxeda.com> >> >> Add support to the platform bus scanning to call custom device creation >> functions. This enables creation of non-platform devices like amba_bus. >> >> Cc: Jeremy Kerr<jeremy.kerr@canonical.com> >> Cc: Grant Likely<grant.likely@secretlab.ca> >> Cc: linux@arm.linux.org.uk >> Cc: arnd@arndb.de >> Cc: Linus Walleij<linus.walleij@linaro.org> >> Signed-off-by: Rob Herring<rob.herring@calxeda.com> > > This creates a confusing mix of match table entries: Normally, > all entries in the match table are meant to identify child buses, > but if I read your patch correctly, you now also need to match > on the amba devices themselves, including the creation of > platform devices for each child device node under an amba > device. > We should only create devices for each matching bus and the immediate children of each bus. A child device of an amba device would be something like an i2c bus which we don't want to create devices for. Or am I missing something? > I don't think that was the intention. Maybe we need to pass > two match tables into of_platform_bus_probe() instead: > one to identify the buses, and another one that is used > to create the actual devices. > That was my original thinking too, but some reason I had concluded 1 could get by with just 1 table. After more thought, I think you are right. In fact, I broke platform device creation with this patch. I need to be able to tell if no match means create a platform device (child of bus) or not (child of a device). Here's an updated version with just the interesting hunk. I've tested it with a made up bus structure that looks something like this: soc bus -plat dev -amba dev -sub-bus -plat dev -amba dev -plat dev As of_platform_bus_probe is not recommended to be used by Grant, I only plan to add 2 match tables to of_platform_bus_populate. @@ -234,18 +237,32 @@ static int of_platform_bus_create(struct device_node *bus, return 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) { - pr_debug(" create child: %s\n", child->full_name); - rc = of_platform_bus_create(child, matches, &dev->dev, strict); - if (rc) { - of_node_put(child); - break; + id = of_match_node(bus_matches, bus); + if (id) { + dev = of_platform_device_create(bus, NULL, parent); + if (!dev) + return 0; + for_each_child_of_node(bus, child) { + pr_debug(" create child: %s\n", child->full_name); + rc = of_platform_bus_create(child, bus_matches, + dev_matches, dev, strict); + if (rc) { + of_node_put(child); + break; + } } + return rc; } + + id = of_match_node(dev_matches, bus); + mdata = id ? id->data : NULL; + if (id && mdata && mdata->dev_create) + dev = mdata->dev_create(bus, parent); + else + dev = of_platform_device_create(bus, NULL, parent); + if (!dev) + return 0; + return rc; } Rob
On Thursday 26 May 2011, Rob Herring wrote: > On 05/26/2011 08:11 AM, Arnd Bergmann wrote: > > On Wednesday 25 May 2011, Rob Herring wrote: > > This creates a confusing mix of match table entries: Normally, > > all entries in the match table are meant to identify child buses, > > but if I read your patch correctly, you now also need to match > > on the amba devices themselves, including the creation of > > platform devices for each child device node under an amba > > device. > > > We should only create devices for each matching bus and the immediate > children of each bus. A child device of an amba device would be > something like an i2c bus which we don't want to create devices for. Or > am I missing something? Exactly, that was my point. > > I don't think that was the intention. Maybe we need to pass > > two match tables into of_platform_bus_probe() instead: > > one to identify the buses, and another one that is used > > to create the actual devices. > > > That was my original thinking too, but some reason I had concluded 1 > could get by with just 1 table. After more thought, I think you are > right. In fact, I broke platform device creation with this patch. I need > to be able to tell if no match means create a platform device (child of > bus) or not (child of a device). Ok. > @@ -234,18 +237,32 @@ static int of_platform_bus_create(struct > device_node *bus, > return 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) { > - pr_debug(" create child: %s\n", child->full_name); > - rc = of_platform_bus_create(child, matches, &dev->dev, strict); > - if (rc) { > - of_node_put(child); > - break; > + id = of_match_node(bus_matches, bus); > + if (id) { > + dev = of_platform_device_create(bus, NULL, parent); > + if (!dev) > + return 0; > + for_each_child_of_node(bus, child) { > + pr_debug(" create child: %s\n", child->full_name); > + rc = of_platform_bus_create(child, bus_matches, > + dev_matches, dev, strict); > + if (rc) { > + of_node_put(child); > + break; > + } > } > + return rc; > } > + > + id = of_match_node(dev_matches, bus); > + mdata = id ? id->data : NULL; > + if (id && mdata && mdata->dev_create) > + dev = mdata->dev_create(bus, parent); > + else > + dev = of_platform_device_create(bus, NULL, parent); > + if (!dev) > + return 0; > + Yes, that looks like it should work. It still feels a bit strange, because it's not exactly how we normally probe devices: In all other cases, we bind a device to a driver when we find it, and that driver in turn scans it, and potentially creates child devices that it finds. What we do here is to let the platform decide how to interpret the data that is coming in. To make the probing more well-behaved, another approach would be: * Bind a platform_driver to compatible="arm,amba" (or whatever we had in the binding). * In that driver, do nothing except register an amba_device as a child. This would create a somewhat deeper device hierarchy, but be still completely logical: you have a device that cannot be probed (identified simply by its register space), which can be probed internally because the registers actually have a meaning. Arnd
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 9b785be..8c0f43400 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -176,9 +176,9 @@ EXPORT_SYMBOL(of_device_alloc); * Returns pointer to created platform device, or NULL if a device was not * registered. Unavailable devices will not get registered. */ -struct platform_device *of_platform_device_create(struct device_node *np, - const char *bus_id, - struct device *parent) +struct device *of_platform_device_create(struct device_node *np, + const char *bus_id, + struct device *parent) { struct platform_device *dev; @@ -205,7 +205,7 @@ struct platform_device *of_platform_device_create(struct device_node *np, return NULL; } - return dev; + return &dev->dev; } EXPORT_SYMBOL(of_platform_device_create); @@ -224,7 +224,9 @@ static int of_platform_bus_create(struct device_node *bus, struct device *parent, bool strict) { struct device_node *child; - struct platform_device *dev; + struct device *dev; + struct of_device_id *id; + struct of_platform_match_data *mdata; int rc = 0; /* Make sure it has a compatible property */ @@ -234,13 +236,22 @@ static int of_platform_bus_create(struct device_node *bus, return 0; } - dev = of_platform_device_create(bus, NULL, parent); - if (!dev || !of_match_node(matches, bus)) + id = of_match_node(matches, bus); + if (!id) + return 0; + + /* Found a matching node, so create the device */ + mdata = id->data; + if (mdata && mdata->dev_create) + dev = mdata->dev_create(bus, parent); + else + dev = of_platform_device_create(bus, NULL, parent); + if (!dev) 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->dev, strict); + rc = of_platform_bus_create(child, matches, dev, strict); if (rc) { of_node_put(child); break; diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 43c723d..f59d25e 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -40,6 +40,11 @@ struct of_platform_driver #define to_of_platform_driver(drv) \ container_of(drv,struct of_platform_driver, driver) +struct of_platform_match_data { + struct device * (*dev_create)(struct device_node *node, + struct device *parent); +}; + /* Platform drivers register/unregister */ extern struct platform_device *of_device_alloc(struct device_node *np, const char *bus_id, @@ -48,9 +53,9 @@ extern struct platform_device *of_find_device_by_node(struct device_node *np); #if !defined(CONFIG_SPARC) /* SPARC has its own device registration method */ /* Platform devices and busses creation */ -extern struct platform_device *of_platform_device_create(struct device_node *np, - const char *bus_id, - struct device *parent); +extern struct device *of_platform_device_create(struct device_node *np, + const char *bus_id, + struct device *parent); extern int of_platform_bus_probe(struct device_node *root, const struct of_device_id *matches,