9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
16 #include <linux/module.h>
24 #define RES_MASK(bits) ((1 << (bits)) - 1)
62 static irqreturn_t ad7476_trigger_handler(
int irq,
void *
p)
74 time_ns = iio_get_time_ns();
77 ((
s64 *)st->data)[1] = time_ns;
89 spi_read(st->
spi, st->data, 1);
103 static int ad7476_read_raw(
struct iio_dev *indio_dev,
116 if (iio_buffer_enabled(indio_dev))
119 ret = ad7476_scan_direct(st);
124 *val = (ret >> st->
chip_info->channel[0].scan_type.shift) &
136 *val = scale_uv / 1000;
137 *val2 = (scale_uv % 1000) * 1000;
143 #define _AD7476_CHAN(bits, _shift, _info_mask) \
145 .type = IIO_VOLTAGE, \
147 .info_mask = _info_mask | \
148 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
151 .realbits = (bits), \
154 .endianness = IIO_BE, \
158 #define AD7476_CHAN(bits) _AD7476_CHAN((bits), 13 - (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)
168 .reset = ad7091_reset,
197 .int_vref_uv = 2500000,
205 static const struct iio_info ad7476_info = {
207 .read_raw = &ad7476_read_raw,
217 if (indio_dev ==
NULL) {
221 st = iio_priv(indio_dev);
226 if (IS_ERR(st->
reg)) {
227 ret = PTR_ERR(st->
reg);
235 spi_set_drvdata(spi, indio_dev);
240 indio_dev->
dev.parent = &spi->
dev;
245 indio_dev->
info = &ad7476_info;
248 st->
xfer.rx_buf = &st->data;
249 st->
xfer.len = st->
chip_info->channel[0].scan_type.storagebits / 8;
251 spi_message_init(&st->
msg);
252 spi_message_add_tail(&st->
xfer, &st->
msg);
255 &ad7476_trigger_handler,
NULL);
257 goto error_disable_reg;
264 goto error_ring_unregister;
267 error_ring_unregister:
282 struct iio_dev *indio_dev = spi_get_drvdata(spi);
324 .probe = ad7476_probe,
326 .id_table = ad7476_id,