summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-02-07 09:27:59 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2014-02-07 09:28:02 +0100
commit394edf6377ca604402293d74b31694b171923945 (patch)
tree10becc46a2620c580aa4c7a948c9053ac05a20a4 /drivers/base
parent4f2f9150b748f278a02c7874e9fc3fd026082581 (diff)
downloadbarebox-394edf6377ca604402293d74b31694b171923945.tar.gz
barebox-394edf6377ca604402293d74b31694b171923945.tar.xz
i2c/spi: match of_modaliases
i2c/spi devices in the devicetree often come with a "vendor,device" comaptible string. These do not match in barebox, so add a device_match_of_modalias function which does exactly that. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/bus.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b383d09c3e..c41e0b0438 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -71,3 +71,40 @@ int device_match(struct device_d *dev, struct driver_d *drv)
return -1;
}
+
+int device_match_of_modalias(struct device_d *dev, struct driver_d *drv)
+{
+ struct platform_device_id *id = drv->id_table;
+ const char *of_modalias = NULL, *p;
+ int cplen;
+ const char *compat;
+
+ if (!device_match(dev, drv))
+ return 0;
+
+ if (!id || !IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
+ return -1;
+
+ compat = of_get_property(dev->device_node, "compatible", &cplen);
+ if (!compat)
+ return -1;
+
+ p = strchr(compat, ',');
+ of_modalias = p ? p + 1 : compat;
+
+ while (id->name) {
+ if (!strcmp(id->name, dev->name)) {
+ dev->id_entry = id;
+ return 0;
+ }
+
+ if (of_modalias && !strcmp(id->name, of_modalias)) {
+ dev->id_entry = id;
+ return 0;
+ }
+
+ id++;
+ }
+
+ return -1;
+}