From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Add software_node_device_modalias() API to return the MODALIAS string for
swnode based on the swnode's compatible property.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
drivers/base/swnode.c | 13 +++++++++++++
include/linux/property.h | 1 +
2 files changed, 14 insertions(+)
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index c33e09300e5f..a9fa19a27dc6 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -401,6 +401,19 @@ int software_node_device_uevent(const struct device *dev, struct kobj_uevent_env
}
EXPORT_SYMBOL_GPL(software_node_device_uevent);
+ssize_t software_node_device_modalias(struct device *dev, char *str, ssize_t len)
+{
+ const char *compatible;
+ int ret;
+
+ ret = device_property_read_string(dev, "compatible", &compatible);
+ if (ret)
+ return ret;
+
+ return sysfs_emit(str, "%s\n", compatible);
+}
+EXPORT_SYMBOL_GPL(software_node_device_modalias);
+
/* -------------------------------------------------------------------------- */
/* fwnode operations */
diff --git a/include/linux/property.h b/include/linux/property.h
index 14f85fd66bfc..94ea02ae1675 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -600,6 +600,7 @@ void software_node_unregister(const struct software_node *node);
bool software_node_match_device(struct device *dev, const struct device_driver *drv);
int software_node_device_uevent(const struct device *dev, struct kobj_uevent_env *env);
+ssize_t software_node_device_modalias(struct device *dev, char *str, ssize_t len);
struct fwnode_handle *
fwnode_create_software_node(const struct property_entry *properties,
--
2.48.1