summaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/adc/ad7606.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/iio/adc/ad7606.c')
-rw-r--r--drivers/staging/iio/adc/ad7606.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index b7810b1aad07..048c205b979e 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -26,9 +26,12 @@
#include "ad7606.h"
-/* Scales are computed as 2.5/2**16 and 5/2**16 respectively */
+/*
+ * Scales are computed as 5000/32768 and 10000/32768 respectively,
+ * so that when applied to the raw values they provide mV values
+ */
static const unsigned int scale_avail[2][2] = {
- {0, 38147}, {0, 76294}
+ {0, 152588}, {0, 305176}
};
static int ad7606_reset(struct ad7606_state *st)
@@ -271,7 +274,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
.attrs = ad7606_attributes_range,
};
-#define AD7606_CHANNEL(num) \
+#define AD760X_CHANNEL(num, mask) \
{ \
.type = IIO_VOLTAGE, \
.indexed = 1, \
@@ -279,8 +282,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
.address = num, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
- .info_mask_shared_by_all = \
- BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ .info_mask_shared_by_all = mask, \
.scan_index = num, \
.scan_type = { \
.sign = 's', \
@@ -290,6 +292,20 @@ static const struct attribute_group ad7606_attribute_group_range = {
}, \
}
+#define AD7605_CHANNEL(num) \
+ AD760X_CHANNEL(num, 0)
+
+#define AD7606_CHANNEL(num) \
+ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
+
+static const struct iio_chan_spec ad7605_channels[] = {
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ AD7605_CHANNEL(0),
+ AD7605_CHANNEL(1),
+ AD7605_CHANNEL(2),
+ AD7605_CHANNEL(3),
+};
+
static const struct iio_chan_spec ad7606_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(8),
AD7606_CHANNEL(0),
@@ -306,17 +322,24 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
/*
* More devices added in future
*/
+ [ID_AD7605_4] = {
+ .channels = ad7605_channels,
+ .num_channels = 5,
+ },
[ID_AD7606_8] = {
.channels = ad7606_channels,
.num_channels = 9,
+ .has_oversampling = true,
},
[ID_AD7606_6] = {
.channels = ad7606_channels,
.num_channels = 7,
+ .has_oversampling = true,
},
[ID_AD7606_4] = {
.channels = ad7606_channels,
.num_channels = 5,
+ .has_oversampling = true,
},
};
@@ -347,6 +370,9 @@ static int ad7606_request_gpios(struct ad7606_state *st)
if (IS_ERR(st->gpio_frstdata))
return PTR_ERR(st->gpio_frstdata);
+ if (!st->chip_info->has_oversampling)
+ return 0;
+
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os);
@@ -425,12 +451,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return ret;
}
+ st->chip_info = &ad7606_chip_info_tbl[id];
+
ret = ad7606_request_gpios(st);
if (ret)
goto error_disable_reg;
- st->chip_info = &ad7606_chip_info_tbl[id];
-
indio_dev->dev.parent = dev;
if (st->gpio_os) {
if (st->gpio_range)
@@ -532,6 +558,6 @@ EXPORT_SYMBOL_GPL(ad7606_pm_ops);
#endif
-MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
MODULE_LICENSE("GPL v2");