9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
16 #include <linux/module.h>
25 static int ad7887_scan_direct(
struct ad7887_state *
st,
unsigned ch)
31 return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1];
34 static int ad7887_read_raw(
struct iio_dev *indio_dev,
42 unsigned int scale_uv;
47 if (iio_buffer_enabled(indio_dev))
50 ret = ad7887_scan_direct(st, chan->
address);
55 *val = (ret >> st->
chip_info->channel[0].scan_type.shift) &
60 >> st->
chip_info->channel[0].scan_type.realbits;
62 *val2 = (scale_uv%1000)*1000;
82 .scan_type =
IIO_ST(
'u', 12, 16, 0),
92 .scan_type =
IIO_ST(
'u', 12, 16, 0),
99 static const struct iio_info ad7887_info = {
100 .read_raw = &ad7887_read_raw,
108 int ret, voltage_uv = 0;
111 if (indio_dev ==
NULL)
114 st = iio_priv(indio_dev);
117 if (!IS_ERR(st->
reg)) {
128 spi_set_drvdata(spi, indio_dev);
132 indio_dev->
dev.parent = &spi->
dev;
134 indio_dev->
info = &ad7887_info;
143 st->
xfer[0].rx_buf = &st->data[0];
160 st->
xfer[1].rx_buf = &st->data[0];
164 st->
xfer[2].rx_buf = &st->data[2];
172 st->
xfer[3].rx_buf = &st->data[0];
184 dev_warn(&spi->
dev,
"reference voltage unspecified\n");
194 dev_warn(&spi->
dev,
"reference voltage unspecified\n");
202 goto error_disable_reg;
206 goto error_unregister_ring;
209 error_unregister_ring:
212 if (!IS_ERR(st->
reg))
215 if (!IS_ERR(st->
reg))
224 struct iio_dev *indio_dev = spi_get_drvdata(spi);
229 if (!IS_ERR(st->
reg)) {
249 .probe = ad7887_probe,
251 .id_table = ad7887_id,