9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
17 #include <linux/module.h>
25 #define AD7298_V_CHAN(index) \
27 .type = IIO_VOLTAGE, \
30 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
31 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
33 .scan_index = index, \
67 static int ad7298_scan_direct(
struct ad7298_state *
st,
unsigned ch)
88 ret = spi_write(st->
spi, (
u8 *)&buf, 2);
94 ret = spi_write(st->
spi, (
u8 *)&buf, 2);
100 ret = spi_read(st->
spi, (
u8 *)&buf, 2);
112 tmp = (4096 -
tmp) * 250;
124 static int ad7298_read_raw(
struct iio_dev *indio_dev,
132 unsigned int scale_uv;
141 ret = ad7298_scan_temp(st, val);
143 ret = ad7298_scan_direct(st, chan->
address);
155 switch (chan->
type) {
158 *val = scale_uv / 1000;
159 *val2 = (scale_uv % 1000) * 1000;
172 static const struct iio_info ad7298_info = {
173 .read_raw = &ad7298_read_raw,
185 if (indio_dev ==
NULL)
188 st = iio_priv(indio_dev);
191 if (!IS_ERR(st->
reg)) {
197 spi_set_drvdata(spi, indio_dev);
202 indio_dev->
dev.parent = &spi->
dev;
204 indio_dev->
channels = ad7298_channels;
206 indio_dev->
info = &ad7298_info;
233 goto error_disable_reg;
237 goto error_cleanup_ring;
244 if (!IS_ERR(st->
reg))
247 if (!IS_ERR(st->
reg))
256 struct iio_dev *indio_dev = spi_get_drvdata(spi);
261 if (!IS_ERR(st->
reg)) {
281 .probe = ad7298_probe,
283 .id_table = ad7298_id,