diff --git a/drivers/base/bus.c b/drivers/base/bus.c index b383d09c3..c41e0b043 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; +} diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 3b9f601f6..d77410500 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -467,7 +467,7 @@ static void i2c_remove(struct device_d *dev) struct bus_type i2c_bus = { .name = "i2c", - .match = device_match, + .match = device_match_of_modalias, .probe = i2c_probe, .remove = i2c_remove, }; diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ad65884fd..8bddd98cf 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -316,7 +316,7 @@ static void spi_remove(struct device_d *dev) struct bus_type spi_bus = { .name = "spi", - .match = device_match, + .match = device_match_of_modalias, .probe = spi_probe, .remove = spi_remove, }; diff --git a/include/driver.h b/include/driver.h index bbe789b51..cbb040170 100644 --- a/include/driver.h +++ b/include/driver.h @@ -496,5 +496,6 @@ int devfs_del_partition(const char *name); int dev_get_drvdata(struct device_d *dev, unsigned long *data); -#endif /* DRIVER_H */ +int device_match_of_modalias(struct device_d *dev, struct driver_d *drv); +#endif /* DRIVER_H */