[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220817150542.483291-7-nipun.gupta@amd.com>
Date: Wed, 17 Aug 2022 20:35:42 +0530
From: Nipun Gupta <nipun.gupta@....com>
To: <robh+dt@...nel.org>, <krzysztof.kozlowski+dt@...aro.org>,
<gregkh@...uxfoundation.org>, <rafael@...nel.org>,
<eric.auger@...hat.com>, <alex.williamson@...hat.com>,
<cohuck@...hat.com>, <puneet.gupta@....com>,
<song.bao.hua@...ilicon.com>, <mchehab+huawei@...nel.org>,
<maz@...nel.org>, <f.fainelli@...il.com>,
<jeffrey.l.hugo@...il.com>, <saravanak@...gle.com>,
<Michael.Srba@...nam.cz>, <mani@...nel.org>, <yishaih@...dia.com>,
<jgg@...pe.ca>, <linux-kernel@...r.kernel.org>,
<devicetree@...r.kernel.org>, <kvm@...r.kernel.org>
CC: <okaya@...nel.org>, <harpreet.anand@....com>,
<nikhil.agarwal@....com>, <michal.simek@....com>, <git@....com>,
Nipun Gupta <nipun.gupta@....com>
Subject: [RFC PATCH v2 6/6] driver core: add compatible string in sysfs for platform devices
This change adds compatible string for the platform based
devices.
Signed-off-by: Nipun Gupta <nipun.gupta@....com>
---
Documentation/ABI/testing/sysfs-bus-platform | 8 +++++++
drivers/base/platform.c | 23 ++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
index c4dfe7355c2d..d95ff83d768c 100644
--- a/Documentation/ABI/testing/sysfs-bus-platform
+++ b/Documentation/ABI/testing/sysfs-bus-platform
@@ -54,3 +54,11 @@ Description:
Other platform devices use, instead:
- platform:`driver name`
+
+What: /sys/bus/platform/devices/.../compatible
+Date: August 2022
+Contact: Nipun Gupta <nipun.gupta@....com>
+Description:
+ compatible string associated with the device. This is
+ a read only and is visible if the device have "compatible"
+ property associated with it.
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 51bb2289865c..94c33efaa9b8 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1289,10 +1289,25 @@ static ssize_t driver_override_store(struct device *dev,
}
static DEVICE_ATTR_RW(driver_override);
+static ssize_t compatible_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ const char *compat;
+ int ret;
+
+ ret = device_property_read_string(dev, "compatible", &compat);
+ if (ret != 0)
+ return 0;
+
+ return sysfs_emit(buf, "%s", compat);
+}
+static DEVICE_ATTR_RO(compatible);
+
static struct attribute *platform_dev_attrs[] = {
&dev_attr_modalias.attr,
&dev_attr_numa_node.attr,
&dev_attr_driver_override.attr,
+ &dev_attr_compatible.attr,
NULL,
};
@@ -1300,11 +1315,19 @@ static umode_t platform_dev_attrs_visible(struct kobject *kobj, struct attribute
int n)
{
struct device *dev = container_of(kobj, typeof(*dev), kobj);
+ const char *compat;
+ int ret;
if (a == &dev_attr_numa_node.attr &&
dev_to_node(dev) == NUMA_NO_NODE)
return 0;
+ if (a == &dev_attr_compatible.attr) {
+ ret = device_property_read_string(dev, "compatible", &compat);
+ if (ret != 0)
+ return 0;
+ }
+
return a->mode;
}
--
2.25.1
Powered by blists - more mailing lists