9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
16 #include <linux/module.h>
33 static int ad8366_write(
struct iio_dev *indio_dev,
34 unsigned char ch_a,
char unsigned ch_b)
39 ch_a = bitrev8(ch_a & 0x3F);
40 ch_b = bitrev8(ch_b & 0x3F);
42 st->data[0] = ch_b >> 4;
43 st->data[1] = (ch_b << 4) | (ch_a >> 2);
47 dev_err(&indio_dev->
dev,
"write failed (%d)", ret);
52 static int ad8366_read_raw(
struct iio_dev *indio_dev,
68 code = code * 253 + 4500;
70 *val2 = (code % 1000) * 1000;
82 static int ad8366_write_raw(
struct iio_dev *indio_dev,
92 if (val < 0 || val2 < 0)
96 code = (((
u8)val * 1000) + ((
u32)val2 / 1000));
98 if (code > 20500 || code < 4500)
101 code = (code - 4500) / 253;
107 ret = ad8366_write(indio_dev, st->
ch[0], st->
ch[1]);
117 static const struct iio_info ad8366_info = {
118 .read_raw = &ad8366_read_raw,
119 .write_raw = &ad8366_write_raw,
123 #define AD8366_CHAN(_channel) { \
124 .type = IIO_VOLTAGE, \
127 .channel = _channel, \
128 .info_mask = IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT,\
143 if (indio_dev ==
NULL)
146 st = iio_priv(indio_dev);
149 if (!IS_ERR(st->
reg)) {
155 spi_set_drvdata(spi, indio_dev);
158 indio_dev->
dev.parent = &spi->
dev;
160 indio_dev->
info = &ad8366_info;
162 indio_dev->
channels = ad8366_channels;
167 goto error_disable_reg;
169 ad8366_write(indio_dev, 0 , 0);
174 if (!IS_ERR(st->
reg))
177 if (!IS_ERR(st->
reg))
187 struct iio_dev *indio_dev = spi_get_drvdata(spi);
210 .name = KBUILD_MODNAME,
213 .probe = ad8366_probe,
215 .id_table = ad8366_id,