diff mbox series

[v3,4/5] meson saradc: add channel labels

Message ID 20230627224017.1724097-5-gnstark@sberdevices.ru (mailing list archive)
State Superseded
Headers show
Series meson saradc: add iio channels to read channel 7 mux inputs | expand

Commit Message

George Stark June 27, 2023, 10:37 p.m. UTC
Add attribute 'label' to all iio channels.

Signed-off-by: George Stark <GNStark@sberdevices.ru>
---
 drivers/iio/adc/meson_saradc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Jonathan Cameron July 2, 2023, 9:16 a.m. UTC | #1
On Wed, 28 Jun 2023 01:37:17 +0300
George Stark <gnstark@sberdevices.ru> wrote:

> Add attribute 'label' to all iio channels.

Why?  Reasoning is more useful here than a simple statement of 'what'.

> 
> Signed-off-by: George Stark <GNStark@sberdevices.ru>
> ---
>  drivers/iio/adc/meson_saradc.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
> index b87f05dfb322..85970fe852af 100644
> --- a/drivers/iio/adc/meson_saradc.c
> +++ b/drivers/iio/adc/meson_saradc.c
> @@ -1058,8 +1058,20 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> +static int read_label(struct iio_dev *indio_dev,
> +		      struct iio_chan_spec const *chan,
> +		      char *label)
> +{
> +	if (chan->type == IIO_TEMP)
> +		return sprintf(label, "%s\n", "temp-sensor");
> +	if (chan->type == IIO_VOLTAGE)
> +		return sprintf(label, "channel-%d\n", chan->channel);
> +	return 0;
> +}
> +
>  static const struct iio_info meson_sar_adc_iio_info = {
>  	.read_raw = meson_sar_adc_iio_info_read_raw,
> +	.read_label = read_label,
>  };
>  
>  static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {
George Stark July 4, 2023, 1:32 a.m. UTC | #2
On 7/2/23 12:16, Jonathan Cameron wrote:
> On Wed, 28 Jun 2023 01:37:17 +0300
> George Stark <gnstark@sberdevices.ru> wrote:
>
>> Add attribute 'label' to all iio channels.
> Why?  Reasoning is more useful here than a simple statement of 'what'.
Adding labels make sense only for newly-added channels,
base channels' default node names are close enough to datasheet names.
Ack for extending the commit message.
>> Signed-off-by: George Stark <GNStark@sberdevices.ru>
>> ---
>>   drivers/iio/adc/meson_saradc.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
>> index b87f05dfb322..85970fe852af 100644
>> --- a/drivers/iio/adc/meson_saradc.c
>> +++ b/drivers/iio/adc/meson_saradc.c
>> @@ -1058,8 +1058,20 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev)
>>   	return ret;
>>   }
>>   
>> +static int read_label(struct iio_dev *indio_dev,
>> +		      struct iio_chan_spec const *chan,
>> +		      char *label)
>> +{
>> +	if (chan->type == IIO_TEMP)
>> +		return sprintf(label, "%s\n", "temp-sensor");
>> +	if (chan->type == IIO_VOLTAGE)
>> +		return sprintf(label, "channel-%d\n", chan->channel);
>> +	return 0;
>> +}
>> +
>>   static const struct iio_info meson_sar_adc_iio_info = {
>>   	.read_raw = meson_sar_adc_iio_info_read_raw,
>> +	.read_label = read_label,
>>   };
>>   
>>   static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {
diff mbox series

Patch

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index b87f05dfb322..85970fe852af 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -1058,8 +1058,20 @@  static int meson_sar_adc_calib(struct iio_dev *indio_dev)
 	return ret;
 }
 
+static int read_label(struct iio_dev *indio_dev,
+		      struct iio_chan_spec const *chan,
+		      char *label)
+{
+	if (chan->type == IIO_TEMP)
+		return sprintf(label, "%s\n", "temp-sensor");
+	if (chan->type == IIO_VOLTAGE)
+		return sprintf(label, "channel-%d\n", chan->channel);
+	return 0;
+}
+
 static const struct iio_info meson_sar_adc_iio_info = {
 	.read_raw = meson_sar_adc_iio_info_read_raw,
+	.read_label = read_label,
 };
 
 static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {