dt-bindings: iio: adc: ti,ads1015: Add label property
Subsystems (2)
PATCH v3 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
@@ -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
PATCH v3 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.
---
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]/
drivers/iio/adc/ti-ads1015.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/iio/adc/ti-ads1015.c +30 -0
@@ -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;
Signature · 1 line
2.34.1
Re: [PATCH v3 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 +12
-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, or channel is not defined. +*/ +if (!name) + name = chan->datasheet_name;
Is the datasheet_name static? Can this rather be made only once at the probe time?
Quoted 2 lines
drivers/iio/adc/ti-ads1015.c +2
-0+return sysfs_emit (label,"%s\n" , name); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] iio: adc: ti-ads1015: Add support for label
Quoted 6 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.
...
Quoted 16 lines
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 +12
-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, or channel is not defined. +*/ +if (!name) + name = chan->datasheet_name;Is the
datasheet_namestatic? Can this rather be made only once at the probe time?
Good point. Yes it is static, so indeed I can move it to the probe function. Will send out a v4.
Best Regards,
Flaviu
Quoted 6 lines
Quoted 2 lines
drivers/iio/adc/ti-ads1015.c +2
-0+return sysfs_emit (label,"%s\n" , name); +}Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Flaviu Nistor
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.
You missed a cover letter.
Try next time
`git format-patch --cover-letter ...`
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 3 lines · Flaviu Nistor
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.
You missed a cover letter.
Try next time`git format-patch --cover-letter ...`
I will keep this in mind for future patch series.
Thanks,
Flaviu
Quoted 3 lines
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 1 line · Flaviu Nistor
Add support for an optional label property per channel similar to other adc
ADC
Quoted 2 lines
chips. This allows assigning distinct names for each channel which can match the schematic signal name.
Signature · 2 lines
With Best Regards, Andy Shevchenko