Skip to content

Commit 44072b2

Browse files
QSchulzjic23
authored andcommitted
iio: adc: nau7802: Expose possible gains in sysfs
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 <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 9a47894 commit 44072b2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/iio/adc/nau7802.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,29 @@ static const struct iio_chan_spec nau7802_chan_array[] = {
7979
static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80,
8080
10, 10, 10, 320};
8181

82+
static ssize_t nau7802_show_scales(struct device *dev,
83+
struct device_attribute *attr, char *buf)
84+
{
85+
struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));
86+
int i, len = 0;
87+
88+
for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
89+
len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09d ",
90+
st->scale_avail[i]);
91+
92+
buf[len-1] = '\n';
93+
94+
return len;
95+
}
96+
8297
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320");
8398

99+
static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, nau7802_show_scales,
100+
NULL, 0);
101+
84102
static struct attribute *nau7802_attributes[] = {
85103
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
104+
&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
86105
NULL
87106
};
88107

0 commit comments

Comments
 (0)