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>
This commit is contained in:
parent
4f2f9150b7
commit
394edf6377
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue