* [PATCH v3 0/2] hwmon: Add "label" attribute v3
@ 2022-01-10 18:22 Paul Cercueil
2022-01-10 18:22 ` [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
2022-01-10 18:22 ` [PATCH v3 2/2] hwmon: Add "label" attribute Paul Cercueil
0 siblings, 2 replies; 5+ messages in thread
From: Paul Cercueil @ 2022-01-10 18:22 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Jonathan Corbet
Cc: linux-hwmon, linux-kernel, linux-doc, list, Paul Cercueil
Hi Jean, Guenter,
A V3 of my patchset which allows specifying a hwmon device's label from
Device Tree. When the "label" device property is present, its value is
exported to the userspace via the "label" sysfs attribute.
This is useful for userspace to be able to identify an individual device
when multiple individual chips are present in the system.
Note that this mechanism already exists in IIO.
Patch [1/2] documents the ABI change.
Patch [2/2] adds the change to the core drivers/hwmon/hwmon.c file.
Changes from v2:
- Move the code setting the label around in the probe function to fix
error handling issue.
Cheers,
-Paul
Paul Cercueil (2):
ABI: hwmon: Document "label" sysfs attribute
hwmon: Add "label" attribute
Documentation/ABI/testing/sysfs-class-hwmon | 8 +++++
Documentation/hwmon/sysfs-interface.rst | 4 +++
drivers/hwmon/hwmon.c | 34 +++++++++++++++++++--
3 files changed, 43 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute
2022-01-10 18:22 [PATCH v3 0/2] hwmon: Add "label" attribute v3 Paul Cercueil
@ 2022-01-10 18:22 ` Paul Cercueil
2022-01-14 16:41 ` Guenter Roeck
2022-01-10 18:22 ` [PATCH v3 2/2] hwmon: Add "label" attribute Paul Cercueil
1 sibling, 1 reply; 5+ messages in thread
From: Paul Cercueil @ 2022-01-10 18:22 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Jonathan Corbet
Cc: linux-hwmon, linux-kernel, linux-doc, list, Paul Cercueil
Add the "label" sysfs attribute, which can contain a descriptive label
that allows to uniquely identify a device within the system.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
Notes:
v2: New patch
v3: No change
Documentation/ABI/testing/sysfs-class-hwmon | 8 ++++++++
Documentation/hwmon/sysfs-interface.rst | 4 ++++
2 files changed, 12 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-hwmon b/Documentation/ABI/testing/sysfs-class-hwmon
index 1f20687def44..653d4c75eddb 100644
--- a/Documentation/ABI/testing/sysfs-class-hwmon
+++ b/Documentation/ABI/testing/sysfs-class-hwmon
@@ -9,6 +9,14 @@ Description:
RO
+What: /sys/class/hwmon/hwmonX/label
+Description:
+ A descriptive label that allows to uniquely identify a
+ device within the system.
+ The contents of the label are free-form.
+
+ RO
+
What: /sys/class/hwmon/hwmonX/update_interval
Description:
The interval at which the chip will update readings.
diff --git a/Documentation/hwmon/sysfs-interface.rst b/Documentation/hwmon/sysfs-interface.rst
index 85652a6aaa3e..209626fb2405 100644
--- a/Documentation/hwmon/sysfs-interface.rst
+++ b/Documentation/hwmon/sysfs-interface.rst
@@ -99,6 +99,10 @@ Global attributes
`name`
The chip name.
+`label`
+ A descriptive label that allows to uniquely identify a device
+ within the system.
+
`update_interval`
The interval at which the chip will update readings.
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] hwmon: Add "label" attribute
2022-01-10 18:22 [PATCH v3 0/2] hwmon: Add "label" attribute v3 Paul Cercueil
2022-01-10 18:22 ` [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
@ 2022-01-10 18:22 ` Paul Cercueil
2022-01-14 16:41 ` Guenter Roeck
1 sibling, 1 reply; 5+ messages in thread
From: Paul Cercueil @ 2022-01-10 18:22 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Jonathan Corbet
Cc: linux-hwmon, linux-kernel, linux-doc, list, Paul Cercueil,
Cosmin Tanislav
If a label is defined in the device tree for this device add that
to the device specific attributes. This is useful for userspace to
be able to identify an individual device when multiple identical
chips are present in the system.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Tested-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
---
Notes:
v2: - Cache label into hwmon_device
- Rename hwmon_dev_name_is_visible() to hwmon_dev_attr_is_visible()
v3: Move the code setting the label around in the probe function to fix
error handling issue.
drivers/hwmon/hwmon.c | 34 +++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 3501a3ead4ba..8d787dba3e38 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -18,6 +18,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/pci.h>
+#include <linux/property.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/thermal.h>
@@ -30,6 +31,7 @@
struct hwmon_device {
const char *name;
+ const char *label;
struct device dev;
const struct hwmon_chip_info *chip;
struct list_head tzdata;
@@ -71,17 +73,29 @@ name_show(struct device *dev, struct device_attribute *attr, char *buf)
}
static DEVICE_ATTR_RO(name);
+static ssize_t
+label_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->label);
+}
+static DEVICE_ATTR_RO(label);
+
static struct attribute *hwmon_dev_attrs[] = {
&dev_attr_name.attr,
+ &dev_attr_label.attr,
NULL
};
-static umode_t hwmon_dev_name_is_visible(struct kobject *kobj,
+static umode_t hwmon_dev_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int n)
{
struct device *dev = kobj_to_dev(kobj);
+ struct hwmon_device *hdev = to_hwmon_device(dev);
- if (to_hwmon_device(dev)->name == NULL)
+ if (attr == &dev_attr_name.attr && hdev->name == NULL)
+ return 0;
+
+ if (attr == &dev_attr_label.attr && hdev->label == NULL)
return 0;
return attr->mode;
@@ -89,7 +103,7 @@ static umode_t hwmon_dev_name_is_visible(struct kobject *kobj,
static const struct attribute_group hwmon_dev_attr_group = {
.attrs = hwmon_dev_attrs,
- .is_visible = hwmon_dev_name_is_visible,
+ .is_visible = hwmon_dev_attr_is_visible,
};
static const struct attribute_group *hwmon_dev_attr_groups[] = {
@@ -117,6 +131,7 @@ static void hwmon_dev_release(struct device *dev)
if (hwdev->group.attrs)
hwmon_free_attrs(hwdev->group.attrs);
kfree(hwdev->groups);
+ kfree(hwdev->label);
kfree(hwdev);
}
@@ -733,6 +748,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
const struct attribute_group **groups)
{
struct hwmon_device *hwdev;
+ const char *label;
struct device *hdev;
int i, err, id;
@@ -788,6 +804,18 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
hdev->groups = groups;
}
+ if (device_property_present(dev, "label")) {
+ err = device_property_read_string(dev, "label", &label);
+ if (err < 0)
+ goto free_hwmon;
+
+ hwdev->label = kstrdup(label, GFP_KERNEL);
+ if (hwdev->label == NULL) {
+ err = -ENOMEM;
+ goto free_hwmon;
+ }
+ }
+
hwdev->name = name;
hdev->class = &hwmon_class;
hdev->parent = dev;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute
2022-01-10 18:22 ` [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
@ 2022-01-14 16:41 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2022-01-14 16:41 UTC (permalink / raw)
To: Paul Cercueil
Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-kernel,
linux-doc, list
On Mon, Jan 10, 2022 at 06:22:55PM +0000, Paul Cercueil wrote:
> Add the "label" sysfs attribute, which can contain a descriptive label
> that allows to uniquely identify a device within the system.
>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Applied to hwmon-next.
Thanks,
Guenter
> ---
>
> Notes:
> v2: New patch
> v3: No change
>
> Documentation/ABI/testing/sysfs-class-hwmon | 8 ++++++++
> Documentation/hwmon/sysfs-interface.rst | 4 ++++
> 2 files changed, 12 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-class-hwmon b/Documentation/ABI/testing/sysfs-class-hwmon
> index 1f20687def44..653d4c75eddb 100644
> --- a/Documentation/ABI/testing/sysfs-class-hwmon
> +++ b/Documentation/ABI/testing/sysfs-class-hwmon
> @@ -9,6 +9,14 @@ Description:
>
> RO
>
> +What: /sys/class/hwmon/hwmonX/label
> +Description:
> + A descriptive label that allows to uniquely identify a
> + device within the system.
> + The contents of the label are free-form.
> +
> + RO
> +
> What: /sys/class/hwmon/hwmonX/update_interval
> Description:
> The interval at which the chip will update readings.
> diff --git a/Documentation/hwmon/sysfs-interface.rst b/Documentation/hwmon/sysfs-interface.rst
> index 85652a6aaa3e..209626fb2405 100644
> --- a/Documentation/hwmon/sysfs-interface.rst
> +++ b/Documentation/hwmon/sysfs-interface.rst
> @@ -99,6 +99,10 @@ Global attributes
> `name`
> The chip name.
>
> +`label`
> + A descriptive label that allows to uniquely identify a device
> + within the system.
> +
> `update_interval`
> The interval at which the chip will update readings.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] hwmon: Add "label" attribute
2022-01-10 18:22 ` [PATCH v3 2/2] hwmon: Add "label" attribute Paul Cercueil
@ 2022-01-14 16:41 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2022-01-14 16:41 UTC (permalink / raw)
To: Paul Cercueil
Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-kernel,
linux-doc, list, Cosmin Tanislav
On Mon, Jan 10, 2022 at 06:22:56PM +0000, Paul Cercueil wrote:
> If a label is defined in the device tree for this device add that
> to the device specific attributes. This is useful for userspace to
> be able to identify an individual device when multiple identical
> chips are present in the system.
>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> Tested-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
Applied to hwmon-next.
Thanks,
Guenter
> ---
>
> Notes:
> v2: - Cache label into hwmon_device
> - Rename hwmon_dev_name_is_visible() to hwmon_dev_attr_is_visible()
> v3: Move the code setting the label around in the probe function to fix
> error handling issue.
>
> drivers/hwmon/hwmon.c | 34 +++++++++++++++++++++++++++++++---
> 1 file changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 3501a3ead4ba..8d787dba3e38 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -18,6 +18,7 @@
> #include <linux/list.h>
> #include <linux/module.h>
> #include <linux/pci.h>
> +#include <linux/property.h>
> #include <linux/slab.h>
> #include <linux/string.h>
> #include <linux/thermal.h>
> @@ -30,6 +31,7 @@
>
> struct hwmon_device {
> const char *name;
> + const char *label;
> struct device dev;
> const struct hwmon_chip_info *chip;
> struct list_head tzdata;
> @@ -71,17 +73,29 @@ name_show(struct device *dev, struct device_attribute *attr, char *buf)
> }
> static DEVICE_ATTR_RO(name);
>
> +static ssize_t
> +label_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->label);
> +}
> +static DEVICE_ATTR_RO(label);
> +
> static struct attribute *hwmon_dev_attrs[] = {
> &dev_attr_name.attr,
> + &dev_attr_label.attr,
> NULL
> };
>
> -static umode_t hwmon_dev_name_is_visible(struct kobject *kobj,
> +static umode_t hwmon_dev_attr_is_visible(struct kobject *kobj,
> struct attribute *attr, int n)
> {
> struct device *dev = kobj_to_dev(kobj);
> + struct hwmon_device *hdev = to_hwmon_device(dev);
>
> - if (to_hwmon_device(dev)->name == NULL)
> + if (attr == &dev_attr_name.attr && hdev->name == NULL)
> + return 0;
> +
> + if (attr == &dev_attr_label.attr && hdev->label == NULL)
> return 0;
>
> return attr->mode;
> @@ -89,7 +103,7 @@ static umode_t hwmon_dev_name_is_visible(struct kobject *kobj,
>
> static const struct attribute_group hwmon_dev_attr_group = {
> .attrs = hwmon_dev_attrs,
> - .is_visible = hwmon_dev_name_is_visible,
> + .is_visible = hwmon_dev_attr_is_visible,
> };
>
> static const struct attribute_group *hwmon_dev_attr_groups[] = {
> @@ -117,6 +131,7 @@ static void hwmon_dev_release(struct device *dev)
> if (hwdev->group.attrs)
> hwmon_free_attrs(hwdev->group.attrs);
> kfree(hwdev->groups);
> + kfree(hwdev->label);
> kfree(hwdev);
> }
>
> @@ -733,6 +748,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> const struct attribute_group **groups)
> {
> struct hwmon_device *hwdev;
> + const char *label;
> struct device *hdev;
> int i, err, id;
>
> @@ -788,6 +804,18 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> hdev->groups = groups;
> }
>
> + if (device_property_present(dev, "label")) {
> + err = device_property_read_string(dev, "label", &label);
> + if (err < 0)
> + goto free_hwmon;
> +
> + hwdev->label = kstrdup(label, GFP_KERNEL);
> + if (hwdev->label == NULL) {
> + err = -ENOMEM;
> + goto free_hwmon;
> + }
> + }
> +
> hwdev->name = name;
> hdev->class = &hwmon_class;
> hdev->parent = dev;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-14 16:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 18:22 [PATCH v3 0/2] hwmon: Add "label" attribute v3 Paul Cercueil
2022-01-10 18:22 ` [PATCH v3 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
2022-01-14 16:41 ` Guenter Roeck
2022-01-10 18:22 ` [PATCH v3 2/2] hwmon: Add "label" attribute Paul Cercueil
2022-01-14 16:41 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.