Skip to contentSkip to conversation

iio: adc: ti-ads1015: Add support for label

PATCH In review Flaviu Nistor 3 participants 6 messages Sep 8 – Sep 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover iio: adc: ti-ads1015: Add support for label

This patch series intention is to add support for label sysfs attribute similar to other ADC devices for ti-ads1015. The patch series adds label property in the dt-binding and the needed functionality in the driver.

Changes in v4:
- Added this cover letter
- Use Uper Case letters for "ADC" instead of "adc" in both commit messages and move static label assignment to probe as suggested by Andy Shevchenko.
- Link to v3: https://lore.kernel.org/all/[email protected]/
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/[email protected]/
Changes in v2:
- Implement changes suggested by Andy Shevchenko.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Flaviu Nistor (2):
iio: adc: ti-ads1015: Add support for label
dt-bindings: iio: adc: ti,ads1015: Add label property

 .../bindings/iio/adc/ti,ads1015.yaml          |  6 ++++
 drivers/iio/adc/ti-ads1015.c                  | 30 +++++++++++++++++++
 2 files changed, 36 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/2 dt-bindings: iio: adc: ti,ads1015: Add label property

Add support for an optional label property per channel similar to other ADC chips. This allows assigning distinct names for each channel which can match the schematic signal name.

---
 Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml +6 -0
index 718f633c6e04..777a75c21d7f 100644
@@ -66,6 +66,11 @@ patternProperties:
           - minimum: 0
             maximum: 7
 
+      label:
+        $ref: /schemas/types.yaml#/definitions/string
+        description:
+          A descriptive name for this channel, like "vcc_ram" or "CH3".
+
       ti,gain:
         $ref: /schemas/types.yaml#/definitions/uint32
         minimum: 0
@@ -125,6 +130,7 @@ examples:
                 reg = <4>;
                 ti,gain = <3>;
                 ti,datarate = <5>;
+                label = "CH3";
             };
         };
     };
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/2 iio: adc: ti-ads1015: Add support for label

In reply to Flaviu Nistor

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.

---
 drivers/iio/adc/ti-ads1015.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/iio/adc/ti-ads1015.c +30 -0
index 0fbfa4e499aa..0f9244107c6d 100644
@@ -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,15 @@ 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);
+
+	return sysfs_emit(label, "%s\n",
+			  data->channel_data[chan->address].label);
+}
+
 static int ads1015_write_raw(struct iio_dev *indio_dev,
 			     struct iio_chan_spec const *chan, int val,
 			     int val2, long mask)
@@ -843,6 +853,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 +864,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 +873,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 +911,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;
 
@@ -985,6 +1008,13 @@ static int ads1015_probe(struct i2c_client *client)
 	/* we need to keep this ABI the same as used by hwmon ADS1015 driver */
 	ads1015_get_channels_config(client);
 
+	/* Channels without a label property fall back to the datasheet name */
+	for (i = 0; i < ADS1015_CHANNELS; i++) {
+		if (!data->channel_data[i].label)
+			data->channel_data[i].label =
+				indio_dev->channels[i].datasheet_name;
+	}
+
 	data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ?
 					    &ads1015_regmap_config :
 					    &tla2024_regmap_config);
Signature · 1 line
2.34.1
Reviewed-by on v4 2/2
#3 lore raw
Quoted 3 lines · Flaviu Nistor

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Flaviu Nistor

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.

Thanks,
Flaviu

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

maintainer
#5 lore raw
In reply to Flaviu Nistor
Quoted 4 lines · On Tue, 8 Sep 2026 22:20:34 +0300 Flaviu Nistor <[email protected]>…

This patch series intention is to add support for label sysfs attribute similar to other ADC devices for ti-ads1015. The patch series adds label property in the dt-binding and the needed functionality in the driver.

Quoted 12 lines

Changes in v4:
- Added this cover letter
- Use Uper Case letters for "ADC" instead of "adc" in both commit messages and move static label assignment to probe as suggested by Andy Shevchenko.
- Link to v3: https://lore.kernel.org/all/[email protected]/
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/[email protected]/
Changes in v2:
- Implement changes suggested by Andy Shevchenko.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Applied to the testing branch of iio.git where the bots can have a first look at it before I push out as a tree I'd rather not rebase! (that normally happens after a few days to 1 week).

Thanks,

Jonathan

Quoted 9 lines

Flaviu Nistor (2):
iio: adc: ti-ads1015: Add support for label
dt-bindings: iio: adc: ti,ads1015: Add label property

 .../bindings/iio/adc/ti,ads1015.yaml          |  6 ++++
 drivers/iio/adc/ti-ads1015.c                  | 30 +++++++++++++++++++
 2 files changed, 36 insertions(+)