diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-06-26 08:35:09 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-06-26 09:21:36 +0200 |
commit | 75aed480a5a1e9d80234b7a99537dbfbfdcbccc2 (patch) | |
tree | ff39c0385f85fbc32a052ba35d4d4aeba49ba76b /drivers/base | |
parent | 39ca74057d186dfd9e12cd7d78d1da4b598c4bc6 (diff) | |
download | barebox-75aed480a5a1e9d80234b7a99537dbfbfdcbccc2.tar.gz barebox-75aed480a5a1e9d80234b7a99537dbfbfdcbccc2.tar.xz |
driver: detect: detect parent devices aswell
Let device_detect_by_name detect parent devices aswell. We
separate the devname strings by colons and call device_detect()
for each component. This makes it possible for example to
detect nand0.root.ubi.root
With the above detect will be called for nand0, nand0.root, nand0.root.ubi
and nand0.root.ubi.root. The nand0.root detection step will detect the
UBI volume and attach it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/driver.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 24cb5bc62b..338bea1280 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -113,14 +113,29 @@ int device_detect(struct device_d *dev) return dev->detect(dev); } -int device_detect_by_name(const char *devname) +int device_detect_by_name(const char *__devname) { - struct device_d *dev = get_device_by_name(devname); + char *devname = xstrdup(__devname); + char *str = devname; + struct device_d *dev; + int ret = -ENODEV; + + while (1) { + strsep(&str, "."); + + dev = get_device_by_name(devname); + if (dev) + ret = device_detect(dev); - if (!dev) - return -ENODEV; + if (!str) + break; + else + *(str - 1) = '.'; + } - return device_detect(dev); + free(devname); + + return ret; } static int match(struct driver_d *drv, struct device_d *dev) |