[PATCH v3 3/6] of: of_device_get_match_compatible() helper
Oleksij Rempel
o.rempel at pengutronix.de
Thu Aug 13 08:55:11 EDT 2020
Some times we need to know, against which compatible did the driver
was registered. So, instead of coding it in the driver, add generic
helper for all drivers.
Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
drivers/of/device.c | 12 ++++++++++++
include/of_device.h | 6 ++++++
2 files changed, 18 insertions(+)
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 67a67bd565..b3f522e1fa 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -31,3 +31,15 @@ const void *of_device_get_match_data(const struct device_d *dev)
return match->data;
}
EXPORT_SYMBOL(of_device_get_match_data);
+
+const char *of_device_get_match_compatible(const struct device_d *dev)
+{
+ const struct of_device_id *match;
+
+ match = of_match_device(dev->driver->of_compatible, dev);
+ if (!match)
+ return NULL;
+
+ return match->compatible;
+}
+EXPORT_SYMBOL(of_device_get_match_compatible);
diff --git a/include/of_device.h b/include/of_device.h
index 244f5fcbbb..cef6d5b5cc 100644
--- a/include/of_device.h
+++ b/include/of_device.h
@@ -22,6 +22,7 @@ static inline int of_driver_match_device(struct device_d *dev,
}
extern const void *of_device_get_match_data(const struct device_d *dev);
+extern const char *of_device_get_match_compatible(const struct device_d *dev);
#else /* CONFIG_OFTREE */
@@ -36,6 +37,11 @@ static inline const void *of_device_get_match_data(const struct device_d *dev)
return NULL;
}
+static inline const char *of_device_get_match_compatible(const struct device_d *dev)
+{
+ return NULL;
+}
+
static inline const struct of_device_id *__of_match_device(
const struct of_device_id *matches, const struct device_d *dev)
{
--
2.28.0
More information about the barebox
mailing list