diff options
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/adc/ad7476.c | 30 |
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 | ||
26 | struct ad7476_state; | ||
27 | |||
26 | struct ad7476_chip_info { | 28 | struct 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 | ||
31 | struct ad7476_state { | 34 | struct ad7476_state { |
@@ -45,6 +48,7 @@ struct ad7476_state { | |||
45 | }; | 48 | }; |
46 | 49 | ||
47 | enum ad7476_supported_device_ids { | 50 | enum 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 | ||
86 | static 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 | |||
82 | static int ad7476_scan_direct(struct ad7476_state *st) | 92 | static 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 | ||
151 | static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { | 164 | static 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 | ||
273 | static const struct spi_device_id ad7476_id[] = { | 294 | static 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}, |