10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
17 #include <linux/sched.h>
19 #include <linux/module.h>
27 #define AD7780_RDY (1 << 7)
28 #define AD7780_FILTER (1 << 6)
29 #define AD7780_ERR (1 << 5)
30 #define AD7780_ID1 (1 << 4)
31 #define AD7780_ID0 (1 << 3)
32 #define AD7780_GAIN (1 << 2)
33 #define AD7780_PAT1 (1 << 1)
34 #define AD7780_PAT0 (1 << 0)
86 static int ad7780_read_raw(
struct iio_dev *indio_dev,
93 unsigned long scale_uv;
101 *val = scale_uv / 100000;
102 *val2 = (scale_uv % 100000) * 10;
105 *val -= (1 << (chan->
scan_type.realbits - 1));
112 static int ad7780_postprocess_sample(
struct ad_sigma_delta *sigma_delta,
113 unsigned int raw_sample)
115 struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
131 .set_mode = ad7780_set_mode,
132 .postprocess_sample = ad7780_postprocess_sample,
133 .has_registers =
false,
136 #define AD7780_CHANNEL(bits, wordsize) \
137 AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits)
162 static const struct iio_info ad7780_info = {
163 .read_raw = &ad7780_read_raw,
172 int ret, voltage_uv = 0;
175 if (indio_dev ==
NULL)
178 st = iio_priv(indio_dev);
181 ad_sd_init(&st->
sd, indio_dev, spi, &ad7780_sigma_delta_info);
184 if (!IS_ERR(st->
reg)) {
200 dev_warn(&spi->
dev,
"reference voltage unspecified\n");
202 spi_set_drvdata(spi, indio_dev);
204 indio_dev->
dev.parent = &spi->
dev;
209 indio_dev->
info = &ad7780_info;
211 if (pdata && gpio_is_valid(pdata->
gpio_pdrst)) {
216 dev_err(&spi->
dev,
"failed to request GPIO PDRST\n");
217 goto error_disable_reg;
226 goto error_free_gpio;
230 goto error_cleanup_buffer_and_trigger;
234 error_cleanup_buffer_and_trigger:
237 if (pdata && gpio_is_valid(pdata->
gpio_pdrst))
240 if (!IS_ERR(st->
reg))
243 if (!IS_ERR(st->
reg))
253 struct iio_dev *indio_dev = spi_get_drvdata(spi);
262 if (!IS_ERR(st->
reg)) {
285 .probe = ad7780_probe,
287 .id_table = ad7780_id,