aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/adc/ad7780.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-09-21 14:29:00 +0100
committerJonathan Cameron <jic23@kernel.org>2012-09-22 10:25:32 +0100
commit7aecec986e043f02738705328d85f97375ca6f41 (patch)
tree25b884d95c7a6817705c655cda80aea9ff6f5ae6 /drivers/staging/iio/adc/ad7780.c
parentstaging:iio:ad7780: Make powerdown GPIO optional (diff)
downloadlinux-dev-7aecec986e043f02738705328d85f97375ca6f41.tar.xz
linux-dev-7aecec986e043f02738705328d85f97375ca6f41.zip
staging:iio:ad7780: Add support for the ad7170/ad7171
The ad7170/ad7171 have a software interface similar to the ad7780. They do not have an external pin which allows to change the internal gain and the what is used for the gain bit in the ad7780/ad7781 becomes part of the check pattern. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio/adc/ad7780.c')
-rw-r--r--drivers/staging/iio/adc/ad7780.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 1dd7cdb1dbc8..0a1328b8657f 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -1,5 +1,5 @@
/*
- * AD7780/AD7781 SPI ADC driver
+ * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver
*
* Copyright 2011 Analog Devices Inc.
*
@@ -34,7 +34,9 @@
#define AD7780_PAT0 (1 << 0)
struct ad7780_chip_info {
- struct iio_chan_spec channel;
+ struct iio_chan_spec channel;
+ unsigned int pattern_mask;
+ unsigned int pattern;
};
struct ad7780_state {
@@ -48,6 +50,8 @@ struct ad7780_state {
};
enum ad7780_supported_device_ids {
+ ID_AD7170,
+ ID_AD7171,
ID_AD7780,
ID_AD7781,
};
@@ -109,9 +113,10 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta,
unsigned int raw_sample)
{
struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
+ const struct ad7780_chip_info *chip_info = st->chip_info;
if ((raw_sample & AD7780_ERR) ||
- !((raw_sample & AD7780_PAT0) && !(raw_sample & AD7780_PAT1)))
+ ((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
return -EIO;
if (raw_sample & AD7780_GAIN)
@@ -128,12 +133,29 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = {
.has_registers = false,
};
+#define AD7780_CHANNEL(bits, wordsize) \
+ AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits)
+
static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
+ [ID_AD7170] = {
+ .channel = AD7780_CHANNEL(12, 24),
+ .pattern = 0x5,
+ .pattern_mask = 0x7,
+ },
+ [ID_AD7171] = {
+ .channel = AD7780_CHANNEL(16, 24),
+ .pattern = 0x5,
+ .pattern_mask = 0x7,
+ },
[ID_AD7780] = {
- .channel = AD_SD_CHANNEL(1, 0, 0, 24, 32, 8),
+ .channel = AD7780_CHANNEL(24, 32),
+ .pattern = 0x1,
+ .pattern_mask = 0x3,
},
[ID_AD7781] = {
- .channel = AD_SD_CHANNEL(1, 0, 0, 20, 32, 12),
+ .channel = AD7780_CHANNEL(20, 32),
+ .pattern = 0x1,
+ .pattern_mask = 0x3,
},
};
@@ -247,6 +269,8 @@ static int __devexit ad7780_remove(struct spi_device *spi)
}
static const struct spi_device_id ad7780_id[] = {
+ {"ad7170", ID_AD7170},
+ {"ad7171", ID_AD7171},
{"ad7780", ID_AD7780},
{"ad7781", ID_AD7781},
{}
@@ -265,5 +289,5 @@ static struct spi_driver ad7780_driver = {
module_spi_driver(ad7780_driver);
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
-MODULE_DESCRIPTION("Analog Devices AD7780/1 ADC");
+MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs");
MODULE_LICENSE("GPL v2");