aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-09-17 08:26:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-09-17 17:10:00 -0400
commit87c5b10fd97937796dbf0769e8790a5f275b4a37 (patch)
treee533dc3d262b805c73bed9ffa9061327767c8562 /drivers/iio
parent587a51241c5d74a1e262d34e990f85dc4e5318c5 (diff)
iio: ad7476: Add support for the ad7091r
Add support for the ad7091r 12 bit ADC to the ad7476 driver. Although the ad7091r is not really related to any of the other devices supported by this driver, luckily for us there are not so many ways (which are not totally insane) how sampling a single channel ADC via SPI can be implemented and support for the ad7091r can be added to the driver with just a few adjustments. The ad7091r requires an external "conversion start" pulse to start a sample conversion. After the conversion has finished the result can be read via SPI. We depend on a IIO trigger to generate this signal, as a result only sampling in buffered mode and not in manual mode is available. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/ad7476.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index be2098d62b8b..7f2f45a0a48d 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -23,9 +23,12 @@
23 23
24#define RES_MASK(bits) ((1 << (bits)) - 1) 24#define RES_MASK(bits) ((1 << (bits)) - 1)
25 25
26struct ad7476_state;
27
26struct ad7476_chip_info { 28struct ad7476_chip_info {
27 unsigned int int_vref_uv; 29 unsigned int int_vref_uv;
28 struct iio_chan_spec channel[2]; 30 struct iio_chan_spec channel[2];
31 void (*reset)(struct ad7476_state *);
29}; 32};
30 33
31struct ad7476_state { 34struct ad7476_state {
@@ -45,6 +48,7 @@ struct ad7476_state {
45}; 48};
46 49
47enum ad7476_supported_device_ids { 50enum ad7476_supported_device_ids {
51 ID_AD7091R,
48 ID_AD7276, 52 ID_AD7276,
49 ID_AD7277, 53 ID_AD7277,
50 ID_AD7278, 54 ID_AD7278,
@@ -79,6 +83,12 @@ done:
79 return IRQ_HANDLED; 83 return IRQ_HANDLED;
80} 84}
81 85
86static void ad7091_reset(struct ad7476_state *st)
87{
88 /* Any transfers with 8 scl cycles will reset the device */
89 spi_read(st->spi, st->data, 1);
90}
91
82static int ad7476_scan_direct(struct ad7476_state *st) 92static int ad7476_scan_direct(struct ad7476_state *st)
83{ 93{
84 int ret; 94 int ret;
@@ -130,11 +140,11 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
130 return -EINVAL; 140 return -EINVAL;
131} 141}
132 142
133#define _AD7476_CHAN(bits, _shift) \ 143#define _AD7476_CHAN(bits, _shift, _info_mask) \
134 { \ 144 { \
135 .type = IIO_VOLTAGE, \ 145 .type = IIO_VOLTAGE, \
136 .indexed = 1, \ 146 .indexed = 1, \
137 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ 147 .info_mask = _info_mask | \
138 IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 148 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
139 .scan_type = { \ 149 .scan_type = { \
140 .sign = 'u', \ 150 .sign = 'u', \
@@ -145,10 +155,18 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
145 }, \ 155 }, \
146} 156}
147 157
148#define AD7476_CHAN(bits) _AD7476_CHAN((bits), 13 - (bits)) 158#define AD7476_CHAN(bits) _AD7476_CHAN((bits), 13 - (bits), \
149#define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits)) 159 IIO_CHAN_INFO_RAW_SEPARATE_BIT)
160#define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \
161 IIO_CHAN_INFO_RAW_SEPARATE_BIT)
162#define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0)
150 163
151static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { 164static const struct ad7476_chip_info ad7476_chip_info_tbl[] = {
165 [ID_AD7091R] = {
166 .channel[0] = AD7091R_CHAN(12),
167 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
168 .reset = ad7091_reset,
169 },
152 [ID_AD7276] = { 170 [ID_AD7276] = {
153 .channel[0] = AD7940_CHAN(12), 171 .channel[0] = AD7940_CHAN(12),
154 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 172 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
@@ -238,6 +256,9 @@ static int __devinit ad7476_probe(struct spi_device *spi)
238 if (ret) 256 if (ret)
239 goto error_disable_reg; 257 goto error_disable_reg;
240 258
259 if (st->chip_info->reset)
260 st->chip_info->reset(st);
261
241 ret = iio_device_register(indio_dev); 262 ret = iio_device_register(indio_dev);
242 if (ret) 263 if (ret)
243 goto error_ring_unregister; 264 goto error_ring_unregister;
@@ -271,6 +292,7 @@ static int __devexit ad7476_remove(struct spi_device *spi)
271} 292}
272 293
273static const struct spi_device_id ad7476_id[] = { 294static const struct spi_device_id ad7476_id[] = {
295 {"ad7091r", ID_AD7091R},
274 {"ad7273", ID_AD7277}, 296 {"ad7273", ID_AD7277},
275 {"ad7274", ID_AD7276}, 297 {"ad7274", ID_AD7276},
276 {"ad7276", ID_AD7276}, 298 {"ad7276", ID_AD7276},