Thomas Gleixner | fda8d26 | 2019-05-28 09:57:06 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 2 | /* |
| 3 | * AD7887 SPI ADC driver |
| 4 | * |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 5 | * Copyright 2010-2011 Analog Devices Inc. |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 8 | #include <linux/device.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/sysfs.h> |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 12 | #include <linux/spi/spi.h> |
| 13 | #include <linux/regulator/consumer.h> |
| 14 | #include <linux/err.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Peter Meerwald | 09a1737 | 2014-12-06 06:00:00 +0000 | [diff] [blame] | 17 | #include <linux/bitops.h> |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 18 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 19 | #include <linux/iio/iio.h> |
| 20 | #include <linux/iio/sysfs.h> |
| 21 | #include <linux/iio/buffer.h> |
Jonathan Cameron | cdf3870 | 2011-08-12 17:08:43 +0100 | [diff] [blame] | 22 | |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 23 | #include <linux/iio/trigger_consumer.h> |
| 24 | #include <linux/iio/triggered_buffer.h> |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 25 | |
Lars-Peter Clausen | 4eb3ccf | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 26 | #include <linux/platform_data/ad7887.h> |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 27 | |
Peter Meerwald | 09a1737 | 2014-12-06 06:00:00 +0000 | [diff] [blame] | 28 | #define AD7887_REF_DIS BIT(5) /* on-chip reference disable */ |
| 29 | #define AD7887_DUAL BIT(4) /* dual-channel mode */ |
| 30 | #define AD7887_CH_AIN1 BIT(3) /* convert on channel 1, DUAL=1 */ |
| 31 | #define AD7887_CH_AIN0 0 /* convert on channel 0, DUAL=0,1 */ |
| 32 | #define AD7887_PM_MODE1 0 /* CS based shutdown */ |
| 33 | #define AD7887_PM_MODE2 1 /* full on */ |
| 34 | #define AD7887_PM_MODE3 2 /* auto shutdown after conversion */ |
| 35 | #define AD7887_PM_MODE4 3 /* standby mode */ |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 36 | |
| 37 | enum ad7887_channels { |
| 38 | AD7887_CH0, |
| 39 | AD7887_CH0_CH1, |
| 40 | AD7887_CH1, |
| 41 | }; |
| 42 | |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 43 | /** |
| 44 | * struct ad7887_chip_info - chip specifc information |
| 45 | * @int_vref_mv: the internal reference voltage |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 46 | * @channels: channels specification |
| 47 | * @num_channels: number of channels |
| 48 | * @dual_channels: channels specification in dual mode |
| 49 | * @num_dual_channels: number of channels in dual mode |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 50 | */ |
| 51 | struct ad7887_chip_info { |
| 52 | u16 int_vref_mv; |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 53 | const struct iio_chan_spec *channels; |
| 54 | unsigned int num_channels; |
| 55 | const struct iio_chan_spec *dual_channels; |
| 56 | unsigned int num_dual_channels; |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct ad7887_state { |
| 60 | struct spi_device *spi; |
| 61 | const struct ad7887_chip_info *chip_info; |
| 62 | struct regulator *reg; |
| 63 | struct spi_transfer xfer[4]; |
| 64 | struct spi_message msg[3]; |
| 65 | struct spi_message *ring_msg; |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 66 | unsigned char tx_cmd_buf[4]; |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * DMA (thus cache coherency maintenance) requires the |
| 70 | * transfer buffers to live in their own cache lines. |
| 71 | * Buffer needs to be large enough to hold two 16 bit samples and a |
| 72 | * 64 bit aligned 64 bit timestamp. |
| 73 | */ |
| 74 | unsigned char data[ALIGN(4, sizeof(s64)) + sizeof(s64)] |
| 75 | ____cacheline_aligned; |
| 76 | }; |
| 77 | |
| 78 | enum ad7887_supported_device_ids { |
| 79 | ID_AD7887 |
| 80 | }; |
| 81 | |
| 82 | static int ad7887_ring_preenable(struct iio_dev *indio_dev) |
| 83 | { |
| 84 | struct ad7887_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 85 | |
| 86 | /* We know this is a single long so can 'cheat' */ |
| 87 | switch (*indio_dev->active_scan_mask) { |
| 88 | case (1 << 0): |
| 89 | st->ring_msg = &st->msg[AD7887_CH0]; |
| 90 | break; |
| 91 | case (1 << 1): |
| 92 | st->ring_msg = &st->msg[AD7887_CH1]; |
| 93 | /* Dummy read: push CH1 setting down to hardware */ |
| 94 | spi_sync(st->spi, st->ring_msg); |
| 95 | break; |
| 96 | case ((1 << 1) | (1 << 0)): |
| 97 | st->ring_msg = &st->msg[AD7887_CH0_CH1]; |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int ad7887_ring_postdisable(struct iio_dev *indio_dev) |
| 105 | { |
| 106 | struct ad7887_state *st = iio_priv(indio_dev); |
| 107 | |
| 108 | /* dummy read: restore default CH0 settin */ |
| 109 | return spi_sync(st->spi, &st->msg[AD7887_CH0]); |
| 110 | } |
| 111 | |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 112 | static irqreturn_t ad7887_trigger_handler(int irq, void *p) |
| 113 | { |
| 114 | struct iio_poll_func *pf = p; |
| 115 | struct iio_dev *indio_dev = pf->indio_dev; |
| 116 | struct ad7887_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 117 | int b_sent; |
| 118 | |
| 119 | b_sent = spi_sync(st->spi, st->ring_msg); |
| 120 | if (b_sent) |
| 121 | goto done; |
| 122 | |
Lars-Peter Clausen | 5afd602 | 2013-09-19 13:59:00 +0100 | [diff] [blame] | 123 | iio_push_to_buffers_with_timestamp(indio_dev, st->data, |
Gregor Boirie | bc2b7da | 2016-03-09 19:05:49 +0100 | [diff] [blame] | 124 | iio_get_time_ns(indio_dev)); |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 125 | done: |
| 126 | iio_trigger_notify_done(indio_dev->trig); |
| 127 | |
| 128 | return IRQ_HANDLED; |
| 129 | } |
| 130 | |
| 131 | static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = { |
| 132 | .preenable = &ad7887_ring_preenable, |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 133 | .postdisable = &ad7887_ring_postdisable, |
| 134 | }; |
| 135 | |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 136 | static int ad7887_scan_direct(struct ad7887_state *st, unsigned ch) |
| 137 | { |
| 138 | int ret = spi_sync(st->spi, &st->msg[ch]); |
| 139 | if (ret) |
| 140 | return ret; |
| 141 | |
| 142 | return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1]; |
| 143 | } |
| 144 | |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 145 | static int ad7887_read_raw(struct iio_dev *indio_dev, |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 146 | struct iio_chan_spec const *chan, |
| 147 | int *val, |
| 148 | int *val2, |
| 149 | long m) |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 150 | { |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 151 | int ret; |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 152 | struct ad7887_state *st = iio_priv(indio_dev); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 153 | |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 154 | switch (m) { |
Jonathan Cameron | b11f98f | 2012-04-15 17:41:18 +0100 | [diff] [blame] | 155 | case IIO_CHAN_INFO_RAW: |
Alison Schofield | 6fea8a4 | 2016-05-24 12:18:43 -0700 | [diff] [blame] | 156 | ret = iio_device_claim_direct_mode(indio_dev); |
| 157 | if (ret) |
| 158 | return ret; |
| 159 | ret = ad7887_scan_direct(st, chan->address); |
| 160 | iio_device_release_direct_mode(indio_dev); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 161 | |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 162 | if (ret < 0) |
| 163 | return ret; |
Lars-Peter Clausen | 98efb70 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 164 | *val = ret >> chan->scan_type.shift; |
Peter Meerwald | 09a1737 | 2014-12-06 06:00:00 +0000 | [diff] [blame] | 165 | *val &= GENMASK(chan->scan_type.realbits - 1, 0); |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 166 | return IIO_VAL_INT; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 167 | case IIO_CHAN_INFO_SCALE: |
Lars-Peter Clausen | bf5d261 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 168 | if (st->reg) { |
| 169 | *val = regulator_get_voltage(st->reg); |
| 170 | if (*val < 0) |
| 171 | return *val; |
| 172 | *val /= 1000; |
| 173 | } else { |
| 174 | *val = st->chip_info->int_vref_mv; |
| 175 | } |
| 176 | |
Lars-Peter Clausen | 98efb70 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 177 | *val2 = chan->scan_type.realbits; |
Lars-Peter Clausen | bf5d261 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 178 | |
| 179 | return IIO_VAL_FRACTIONAL_LOG2; |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 180 | } |
| 181 | return -EINVAL; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 184 | #define AD7887_CHANNEL(x) { \ |
| 185 | .type = IIO_VOLTAGE, \ |
| 186 | .indexed = 1, \ |
| 187 | .channel = (x), \ |
| 188 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 189 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
| 190 | .address = (x), \ |
| 191 | .scan_index = (x), \ |
| 192 | .scan_type = { \ |
| 193 | .sign = 'u', \ |
| 194 | .realbits = 12, \ |
| 195 | .storagebits = 16, \ |
| 196 | .shift = 0, \ |
| 197 | .endianness = IIO_BE, \ |
| 198 | }, \ |
| 199 | } |
| 200 | |
| 201 | static const struct iio_chan_spec ad7887_channels[] = { |
| 202 | AD7887_CHANNEL(0), |
| 203 | IIO_CHAN_SOFT_TIMESTAMP(1), |
| 204 | }; |
| 205 | |
| 206 | static const struct iio_chan_spec ad7887_dual_channels[] = { |
| 207 | AD7887_CHANNEL(0), |
| 208 | AD7887_CHANNEL(1), |
| 209 | IIO_CHAN_SOFT_TIMESTAMP(2), |
| 210 | }; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 211 | |
| 212 | static const struct ad7887_chip_info ad7887_chip_info_tbl[] = { |
| 213 | /* |
| 214 | * More devices added in future |
| 215 | */ |
| 216 | [ID_AD7887] = { |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 217 | .channels = ad7887_channels, |
| 218 | .num_channels = ARRAY_SIZE(ad7887_channels), |
| 219 | .dual_channels = ad7887_dual_channels, |
| 220 | .num_dual_channels = ARRAY_SIZE(ad7887_dual_channels), |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 221 | .int_vref_mv = 2500, |
| 222 | }, |
| 223 | }; |
| 224 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 225 | static const struct iio_info ad7887_info = { |
| 226 | .read_raw = &ad7887_read_raw, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 227 | }; |
| 228 | |
Alexandru Ardelean | 24b2849 | 2020-11-13 11:16:48 +0200 | [diff] [blame] | 229 | static void ad7887_reg_disable(void *data) |
| 230 | { |
| 231 | struct regulator *reg = data; |
| 232 | |
| 233 | regulator_disable(reg); |
| 234 | } |
| 235 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 236 | static int ad7887_probe(struct spi_device *spi) |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 237 | { |
| 238 | struct ad7887_platform_data *pdata = spi->dev.platform_data; |
| 239 | struct ad7887_state *st; |
Sachin Kamat | 82429e0 | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 240 | struct iio_dev *indio_dev; |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 241 | uint8_t mode; |
Lars-Peter Clausen | bf5d261 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 242 | int ret; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 243 | |
Sachin Kamat | 82429e0 | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 244 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
Michael Hennerich | f39e086 | 2011-05-18 14:41:51 +0100 | [diff] [blame] | 245 | if (indio_dev == NULL) |
| 246 | return -ENOMEM; |
| 247 | |
| 248 | st = iio_priv(indio_dev); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 249 | |
Alexandru Ardelean | 5483b8d | 2020-10-02 11:27:23 +0300 | [diff] [blame] | 250 | st->reg = devm_regulator_get_optional(&spi->dev, "vref"); |
| 251 | if (IS_ERR(st->reg)) { |
| 252 | if (PTR_ERR(st->reg) != -ENODEV) |
Sachin Kamat | 82429e0 | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 253 | return PTR_ERR(st->reg); |
Lars-Peter Clausen | bf5d261 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 254 | |
Alexandru Ardelean | 5483b8d | 2020-10-02 11:27:23 +0300 | [diff] [blame] | 255 | st->reg = NULL; |
| 256 | } |
| 257 | |
| 258 | if (st->reg) { |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 259 | ret = regulator_enable(st->reg); |
| 260 | if (ret) |
Sachin Kamat | 82429e0 | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 261 | return ret; |
Alexandru Ardelean | 24b2849 | 2020-11-13 11:16:48 +0200 | [diff] [blame] | 262 | |
| 263 | ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg); |
| 264 | if (ret) |
| 265 | return ret; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | st->chip_info = |
| 269 | &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; |
| 270 | |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 271 | st->spi = spi; |
| 272 | |
Michael Hennerich | f39e086 | 2011-05-18 14:41:51 +0100 | [diff] [blame] | 273 | indio_dev->name = spi_get_device_id(spi)->name; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 274 | indio_dev->info = &ad7887_info; |
Michael Hennerich | f39e086 | 2011-05-18 14:41:51 +0100 | [diff] [blame] | 275 | indio_dev->modes = INDIO_DIRECT_MODE; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 276 | |
| 277 | /* Setup default message */ |
| 278 | |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 279 | mode = AD7887_PM_MODE4; |
Alexandru Ardelean | 5483b8d | 2020-10-02 11:27:23 +0300 | [diff] [blame] | 280 | if (!st->reg) |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 281 | mode |= AD7887_REF_DIS; |
| 282 | if (pdata && pdata->en_dual) |
| 283 | mode |= AD7887_DUAL; |
| 284 | |
| 285 | st->tx_cmd_buf[0] = AD7887_CH_AIN0 | mode; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 286 | |
| 287 | st->xfer[0].rx_buf = &st->data[0]; |
| 288 | st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; |
| 289 | st->xfer[0].len = 2; |
| 290 | |
| 291 | spi_message_init(&st->msg[AD7887_CH0]); |
| 292 | spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); |
| 293 | |
| 294 | if (pdata && pdata->en_dual) { |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 295 | st->tx_cmd_buf[2] = AD7887_CH_AIN1 | mode; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 296 | |
| 297 | st->xfer[1].rx_buf = &st->data[0]; |
| 298 | st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; |
| 299 | st->xfer[1].len = 2; |
| 300 | |
| 301 | st->xfer[2].rx_buf = &st->data[2]; |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 302 | st->xfer[2].tx_buf = &st->tx_cmd_buf[0]; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 303 | st->xfer[2].len = 2; |
| 304 | |
| 305 | spi_message_init(&st->msg[AD7887_CH0_CH1]); |
| 306 | spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); |
| 307 | spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); |
| 308 | |
Lars-Peter Clausen | fce7c3e | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 309 | st->xfer[3].rx_buf = &st->data[2]; |
| 310 | st->xfer[3].tx_buf = &st->tx_cmd_buf[2]; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 311 | st->xfer[3].len = 2; |
| 312 | |
| 313 | spi_message_init(&st->msg[AD7887_CH1]); |
| 314 | spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); |
| 315 | |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 316 | indio_dev->channels = st->chip_info->dual_channels; |
| 317 | indio_dev->num_channels = st->chip_info->num_dual_channels; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 318 | } else { |
Beniamin Bia | b0ec7a4 | 2019-11-25 15:21:37 +0200 | [diff] [blame] | 319 | indio_dev->channels = st->chip_info->channels; |
| 320 | indio_dev->num_channels = st->chip_info->num_channels; |
Michael Hennerich | 596d060 | 2011-05-18 14:41:50 +0100 | [diff] [blame] | 321 | } |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 322 | |
Alexandru Ardelean | 24b2849 | 2020-11-13 11:16:48 +0200 | [diff] [blame] | 323 | ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, |
| 324 | &iio_pollfunc_store_time, |
Lars-Peter Clausen | 65dd3d3 | 2012-11-05 09:56:00 +0000 | [diff] [blame] | 325 | &ad7887_trigger_handler, &ad7887_ring_setup_ops); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 326 | if (ret) |
Alexandru Ardelean | 24b2849 | 2020-11-13 11:16:48 +0200 | [diff] [blame] | 327 | return ret; |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 328 | |
Alexandru Ardelean | 24b2849 | 2020-11-13 11:16:48 +0200 | [diff] [blame] | 329 | return devm_iio_device_register(&spi->dev, indio_dev); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static const struct spi_device_id ad7887_id[] = { |
| 333 | {"ad7887", ID_AD7887}, |
| 334 | {} |
| 335 | }; |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 336 | MODULE_DEVICE_TABLE(spi, ad7887_id); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 337 | |
| 338 | static struct spi_driver ad7887_driver = { |
| 339 | .driver = { |
| 340 | .name = "ad7887", |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 341 | }, |
| 342 | .probe = ad7887_probe, |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 343 | .id_table = ad7887_id, |
| 344 | }; |
Lars-Peter Clausen | ae6ae6f | 2011-11-16 10:13:39 +0100 | [diff] [blame] | 345 | module_spi_driver(ad7887_driver); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 346 | |
Michael Hennerich | 9920ed2 | 2018-08-14 13:23:17 +0200 | [diff] [blame] | 347 | MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); |
Michael Hennerich | 2b4756a | 2010-11-22 14:35:32 +0100 | [diff] [blame] | 348 | MODULE_DESCRIPTION("Analog Devices AD7887 ADC"); |
| 349 | MODULE_LICENSE("GPL v2"); |