Skip to contentSkip to conversation

dt-bindings: iio: adc: ti,ads1015: Add label property

PATCH Superseded Flaviu Nistor 2 participants 3 messages Sep 1 – Sep 2

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 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
#1 lore raw

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

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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/iio/adc/ti-ads1015.c +23 -0
index 0fbfa4e499aa..399a3322732d 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,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.
+	 */
+	if (!name)
+		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,
 };
 
@@ -862,6 +881,7 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
 	struct ads1015_data *data = iio_priv(indio_dev);
 	struct device *dev = &client->dev;
 	int i = -1;
+	const char *label;
 
 	device_for_each_child_node_scoped(dev, node) {
 		u32 pval;
@@ -897,6 +917,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
 			}
 		}
 
+		if (!fwnode_property_read_string(node, "label", &label))
+			data->channel_data[channel].label = label;
+
 		data->channel_data[channel].pga = pga;
 		data->channel_data[channel].data_rate = data_rate;
 
Signature · 1 line
2.34.1
#2 lore raw

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

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.

...

drivers/iio/adc/ti-ads1015.c static int ads1015_read_raw(struct iio_dev *indio_dev, · line 601

Quoted 12 lines
drivers/iio/adc/ti-ads1015.c +11 -0
+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.
+	 */
+	if (!name)
+		name = "";

No need, you can assign below whatever you want for the default case.

Quoted 2 lines
drivers/iio/adc/ti-ads1015.c +2 -0
+	return sysfs_emit(label, "%s\n", name);
+}

...

drivers/iio/adc/ti-ads1015.c static int ads1015_client_get_channels_config(struct i2c_client *client) · line 884

Quoted 6 lines

static int ads1015_client_get_channels_config(struct i2c_client *client)

drivers/iio/adc/ti-ads1015.c +1 -0
 	struct ads1015_data *data = iio_priv(indio_dev);
 	struct device *dev = &client->dev;
 	int i = -1;
+	const char *label;

Keep reversed xmas tree order.

...

drivers/iio/adc/ti-ads1015.c static int ads1015_client_get_channels_config(struct i2c_client *client) · line 921

Quoted 2 lines
drivers/iio/adc/ti-ads1015.c +2 -0
+		if (!fwnode_property_read_string(node, "label", &label))
+			data->channel_data[channel].label = label;

We want something like

		if (fwnode_property_present(...)) {
			ret = fwnode_property_read_string(...);
			if (ret)
				return ret;

			...use label...
		} else {
			...assign default...
		}
Signature · 2 lines
With Best Regards,
Andy Shevchenko