Skip to content

Commit

Permalink
iio: adc: nau7802: Expose possible gains in sysfs
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Quentin Schulz authored and Jonathan Cameron committed May 21, 2016
1 parent 9a47894 commit 44072b2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/iio/adc/nau7802.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 44072b2

Please sign in to comment.