All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: nau7802: Expose possible gains in sysfs
@ 2016-05-18 15:16 Quentin Schulz
  2016-05-18 15:24 ` Daniel Baluta
  2016-05-19 10:01 ` Alexandre Belloni
  0 siblings, 2 replies; 4+ messages in thread
From: Quentin Schulz @ 2016-05-18 15:16 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: Quentin Schulz, linux-iio, maxime.ripard, alexandre.belloni,
	antoine.tenart

The Nuvoton NAU7802 ADC is able to adjust its gain but prior knowledge of
its possible values was required to adjust it. Users had to guess the
possible gain values based on the ADC datasheet or on this driver's code.

This exposes the possible values in the in_voltage_scale_available file of
each nau7802 ADC device. The gain is set for the whole ADC and is therefore
not configurable by channel. Thus, there exists only one
in_voltage_scale_available file for each nau7802 ADC device even if it has
two separate channels.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
---

There exists two files to set the gain: in_voltageX_scale_available and
in_voltage-voltage_scale_available. What are the differences between those
two? What are the use cases for each? Which one should I have used?

 drivers/iio/adc/nau7802.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
index e525aa6..57365c5 100644
--- a/drivers/iio/adc/nau7802.c
+++ b/drivers/iio/adc/nau7802.c
@@ -79,10 +79,29 @@ static const struct iio_chan_spec nau7802_chan_array[] = {
 static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80,
 						10, 10, 10, 320};
 
+static ssize_t nau7802_show_scales(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));
+	int i, len = 0;
+
+	for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
+		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09d ",
+				 st->scale_avail[i]);
+
+	buf[len-1] = '\n';
+
+	return len;
+}
+
 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320");
 
+static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, nau7802_show_scales,
+		       NULL, 0);
+
 static struct attribute *nau7802_attributes[] = {
 	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
 	NULL
 };
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: nau7802: Expose possible gains in sysfs
  2016-05-18 15:16 [PATCH] iio: adc: nau7802: Expose possible gains in sysfs Quentin Schulz
@ 2016-05-18 15:24 ` Daniel Baluta
  2016-05-19 10:01 ` Alexandre Belloni
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Baluta @ 2016-05-18 15:24 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, maxime.ripard,
	alexandre.belloni, antoine.tenart

On Wed, May 18, 2016 at 6:16 PM, Quentin Schulz
<quentin.schulz@free-electrons.com> wrote:
> The Nuvoton NAU7802 ADC is able to adjust its gain but prior knowledge of
> its possible values was required to adjust it. Users had to guess the
> possible gain values based on the ADC datasheet or on this driver's code.
>
> This exposes the possible values in the in_voltage_scale_available file of
> each nau7802 ADC device. The gain is set for the whole ADC and is therefore
> not configurable by channel. Thus, there exists only one
> in_voltage_scale_available file for each nau7802 ADC device even if it has
> two separate channels.
>
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> ---
>
> There exists two files to set the gain: in_voltageX_scale_available and
> in_voltage-voltage_scale_available. What are the differences between those
> two? What are the use cases for each? Which one should I have used?

First is for single channels while the latter is for differential channels.
In this case it's correct to use in in_voltageX_scale_available as you did.

thanks,
Daniel.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: nau7802: Expose possible gains in sysfs
  2016-05-18 15:16 [PATCH] iio: adc: nau7802: Expose possible gains in sysfs Quentin Schulz
  2016-05-18 15:24 ` Daniel Baluta
@ 2016-05-19 10:01 ` Alexandre Belloni
  2016-05-21 19:17   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Belloni @ 2016-05-19 10:01 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: jic23, knaack.h, lars, pmeerw, linux-iio, maxime.ripard, antoine.tenart

On 18/05/2016 at 17:16:18 +0200, Quentin Schulz wrote :
>
> The Nuvoton NAU7802 ADC is able to adjust its gain but prior knowledge of
> its possible values was required to adjust it. Users had to guess the
> possible gain values based on the ADC datasheet or on this driver's code.
> 
> This exposes the possible values in the in_voltage_scale_available file of
> each nau7802 ADC device. The gain is set for the whole ADC and is therefore
> not configurable by channel. Thus, there exists only one
> in_voltage_scale_available file for each nau7802 ADC device even if it has
> two separate channels.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
> 
> There exists two files to set the gain: in_voltageX_scale_available and
> in_voltage-voltage_scale_available. What are the differences between those
> two? What are the use cases for each? Which one should I have used?
> 
>  drivers/iio/adc/nau7802.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
> index e525aa6..57365c5 100644
> --- a/drivers/iio/adc/nau7802.c
> +++ b/drivers/iio/adc/nau7802.c
> @@ -79,10 +79,29 @@ static const struct iio_chan_spec nau7802_chan_array[] = {
>  static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80,
>  						10, 10, 10, 320};
>  
> +static ssize_t nau7802_show_scales(struct device *dev,
> +				   struct device_attribute *attr, char *buf)
> +{
> +	struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));
> +	int i, len = 0;
> +
> +	for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
> +		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09d ",
> +				 st->scale_avail[i]);
> +
> +	buf[len-1] = '\n';
> +
> +	return len;
> +}
> +
>  static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320");
>  
> +static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, nau7802_show_scales,
> +		       NULL, 0);
> +
>  static struct attribute *nau7802_attributes[] = {
>  	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
>  	NULL
>  };
>  
> -- 
> 2.5.0
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: nau7802: Expose possible gains in sysfs
  2016-05-19 10:01 ` Alexandre Belloni
@ 2016-05-21 19:17   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2016-05-21 19:17 UTC (permalink / raw)
  To: Alexandre Belloni, Quentin Schulz
  Cc: knaack.h, lars, pmeerw, linux-iio, maxime.ripard, antoine.tenart

On 19/05/16 11:01, Alexandre Belloni wrote:
> On 18/05/2016 at 17:16:18 +0200, Quentin Schulz wrote :
>>
>> The Nuvoton NAU7802 ADC is able to adjust its gain but prior knowledge of
>> its possible values was required to adjust it. Users had to guess the
>> possible gain values based on the ADC datasheet or on this driver's code.
>>
>> This exposes the possible values in the in_voltage_scale_available file of
>> each nau7802 ADC device. The gain is set for the whole ADC and is therefore
>> not configurable by channel. Thus, there exists only one
>> in_voltage_scale_available file for each nau7802 ADC device even if it has
>> two separate channels.
>>
>> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan
> 
>> ---
>>
>> There exists two files to set the gain: in_voltageX_scale_available and
>> in_voltage-voltage_scale_available. What are the differences between those
>> two? What are the use cases for each? Which one should I have used?
>>
>>  drivers/iio/adc/nau7802.c | 19 +++++++++++++++++++
>>  1 file changed, 19 insertions(+)
>>
>> diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
>> index e525aa6..57365c5 100644
>> --- a/drivers/iio/adc/nau7802.c
>> +++ b/drivers/iio/adc/nau7802.c
>> @@ -79,10 +79,29 @@ static const struct iio_chan_spec nau7802_chan_array[] = {
>>  static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80,
>>  						10, 10, 10, 320};
>>  
>> +static ssize_t nau7802_show_scales(struct device *dev,
>> +				   struct device_attribute *attr, char *buf)
>> +{
>> +	struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));
>> +	int i, len = 0;
>> +
>> +	for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
>> +		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09d ",
>> +				 st->scale_avail[i]);
>> +
>> +	buf[len-1] = '\n';
>> +
>> +	return len;
>> +}
>> +
>>  static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320");
>>  
>> +static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, nau7802_show_scales,
>> +		       NULL, 0);
>> +
>>  static struct attribute *nau7802_attributes[] = {
>>  	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
>> +	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
>>  	NULL
>>  };
>>  
>> -- 
>> 2.5.0
>>
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-21 19:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-18 15:16 [PATCH] iio: adc: nau7802: Expose possible gains in sysfs Quentin Schulz
2016-05-18 15:24 ` Daniel Baluta
2016-05-19 10:01 ` Alexandre Belloni
2016-05-21 19:17   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.