Add labels from IIO channels to our channels. This allows userspace to
display more meaningful names instead of "in0" or "temp5".
Although lm-sensors gracefully handles errors when reading channel
labels, the ABI says the label attribute
Should only be created if the driver has hints about what this voltage
channel is being used for, and user-space doesn't.
Therefore, we test to see if the channel has a label before
creating the attribute.
Signed-off-by: Sean Anderson <sean.anderson@xxxxxxxxx>
---
Changes in v2:
- Check if the label exists before creating the attribute
drivers/hwmon/iio_hwmon.c | 45 ++++++++++++++++++++++++++++++++++-----
1 file changed, 40 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 4c8a80847891..5722cb9d81f9 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -33,6 +33,17 @@ struct iio_hwmon_state {
struct attribute **attrs;
};
+static ssize_t iio_hwmon_read_label(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+ struct iio_hwmon_state *state = dev_get_drvdata(dev);
+ struct iio_channel *chan = &state->channels[sattr->index];
+
+ return iio_read_channel_label(chan, buf);
+}
+