[PATCH v3 2/2] iio: adc: ti-ads1015: Add support for label

From: Flaviu Nistor

Date: Mon Sep 07 2026 - 11:27:12 EST


Add support for label sysfs attribute similar to other adc devices. This is
particularly useful because the label can match the schematic signal name,
identifying channel voltages easier if label is defined via device tree.

Signed-off-by: Flaviu Nistor <flaviu.nistor@xxxxxxxxx>
---
Changes in v3:
- Return datasheet_name of the channel in user space if label is not present in dts.
- Link to v2: https://lore.kernel.org/all/20260902172230.5234-2-flaviu.nistor@xxxxxxxxx/
Changes in v2:
- Implement changes suggested by Andy Shevchenko.
- Link to v1: https://lore.kernel.org/all/20260901184302.8127-2-flaviu.nistor@xxxxxxxxx/

drivers/iio/adc/ti-ads1015.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 0fbfa4e499aa..7ad03fa2253d 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -233,6 +233,7 @@ static const struct iio_event_spec ads1015_events[] = {
struct ads1015_channel_data {
unsigned int pga;
unsigned int data_rate;
+ const char *label;
};

struct ads1015_thresh_data {
@@ -586,6 +587,22 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
}
}

+static int ads1015_read_label(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, char *label)
+{
+ struct ads1015_data *data = iio_priv(indio_dev);
+ const char *name = data->channel_data[chan->address].label;
+
+ /*
+ * Avoid printing "(null)" in the console in case label property
+ * is missing for the channel, or channel is not defined.
+ */
+ if (!name)
+ name = chan->datasheet_name;
+
+ return sysfs_emit(label, "%s\n", name);
+}
+
static int ads1015_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val,
int val2, long mask)
@@ -843,6 +860,7 @@ static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
static const struct iio_info ads1015_info = {
.read_avail = ads1015_read_avail,
.read_raw = ads1015_read_raw,
+ .read_label = ads1015_read_label,
.write_raw = ads1015_write_raw,
.read_event_value = ads1015_read_event,
.write_event_value = ads1015_write_event,
@@ -853,6 +871,7 @@ static const struct iio_info ads1015_info = {
static const struct iio_info tla2024_info = {
.read_avail = ads1015_read_avail,
.read_raw = ads1015_read_raw,
+ .read_label = ads1015_read_label,
.write_raw = ads1015_write_raw,
};

@@ -861,7 +880,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct ads1015_data *data = iio_priv(indio_dev);
struct device *dev = &client->dev;
+ const char *label;
int i = -1;
+ int ret;

device_for_each_child_node_scoped(dev, node) {
u32 pval;
@@ -897,6 +918,15 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
}
}

+ if (fwnode_property_present(node, "label")) {
+ ret = fwnode_property_read_string(node, "label", &label);
+ if (ret) {
+ dev_err(dev, "invalid label on %pfw\n", node);
+ return ret;
+ }
+ data->channel_data[channel].label = label;
+ }
+
data->channel_data[channel].pga = pga;
data->channel_data[channel].data_rate = data_rate;

--
2.34.1