Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * AD7466/7/8 AD7476/5/7/8 (A) SPI ADC driver |
| 3 | * |
| 4 | * Copyright 2010 Analog Devices Inc. |
| 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
| 7 | */ |
| 8 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 9 | #include <linux/device.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/sysfs.h> |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 13 | #include <linux/spi/spi.h> |
| 14 | #include <linux/regulator/consumer.h> |
| 15 | #include <linux/err.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 17 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 18 | #include <linux/iio/iio.h> |
| 19 | #include <linux/iio/sysfs.h> |
| 20 | #include <linux/iio/buffer.h> |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 21 | #include <linux/iio/trigger_consumer.h> |
| 22 | #include <linux/iio/triggered_buffer.h> |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 23 | |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 24 | #define RES_MASK(bits) ((1 << (bits)) - 1) |
| 25 | |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 26 | struct ad7476_state; |
| 27 | |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 28 | struct ad7476_chip_info { |
| 29 | unsigned int int_vref_uv; |
| 30 | struct iio_chan_spec channel[2]; |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 31 | void (*reset)(struct ad7476_state *); |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct ad7476_state { |
| 35 | struct spi_device *spi; |
| 36 | const struct ad7476_chip_info *chip_info; |
| 37 | struct regulator *reg; |
| 38 | struct spi_transfer xfer; |
| 39 | struct spi_message msg; |
| 40 | /* |
| 41 | * DMA (thus cache coherency maintenance) requires the |
| 42 | * transfer buffers to live in their own cache lines. |
| 43 | * Make the buffer large enough for one 16 bit sample and one 64 bit |
| 44 | * aligned 64 bit timestamp. |
| 45 | */ |
| 46 | unsigned char data[ALIGN(2, sizeof(s64)) + sizeof(s64)] |
| 47 | ____cacheline_aligned; |
| 48 | }; |
| 49 | |
| 50 | enum ad7476_supported_device_ids { |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 51 | ID_AD7091R, |
Lars-Peter Clausen | c26cc89 | 2012-09-10 10:33:00 +0100 | [diff] [blame] | 52 | ID_AD7276, |
| 53 | ID_AD7277, |
| 54 | ID_AD7278, |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 55 | ID_AD7466, |
| 56 | ID_AD7467, |
| 57 | ID_AD7468, |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 58 | ID_AD7495, |
| 59 | ID_AD7940, |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static irqreturn_t ad7476_trigger_handler(int irq, void *p) |
| 63 | { |
| 64 | struct iio_poll_func *pf = p; |
| 65 | struct iio_dev *indio_dev = pf->indio_dev; |
| 66 | struct ad7476_state *st = iio_priv(indio_dev); |
| 67 | s64 time_ns; |
| 68 | int b_sent; |
| 69 | |
| 70 | b_sent = spi_sync(st->spi, &st->msg); |
| 71 | if (b_sent < 0) |
| 72 | goto done; |
| 73 | |
| 74 | time_ns = iio_get_time_ns(); |
| 75 | |
| 76 | if (indio_dev->scan_timestamp) |
| 77 | ((s64 *)st->data)[1] = time_ns; |
| 78 | |
Jonathan Cameron | 84b36ce | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 79 | iio_push_to_buffers(indio_dev, st->data); |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 80 | done: |
| 81 | iio_trigger_notify_done(indio_dev->trig); |
| 82 | |
| 83 | return IRQ_HANDLED; |
| 84 | } |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 85 | |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 86 | static void ad7091_reset(struct ad7476_state *st) |
| 87 | { |
| 88 | /* Any transfers with 8 scl cycles will reset the device */ |
| 89 | spi_read(st->spi, st->data, 1); |
| 90 | } |
| 91 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 92 | static int ad7476_scan_direct(struct ad7476_state *st) |
| 93 | { |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 94 | int ret; |
| 95 | |
Michael Hennerich | 668413e | 2010-10-11 18:05:56 +0200 | [diff] [blame] | 96 | ret = spi_sync(st->spi, &st->msg); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 97 | if (ret) |
| 98 | return ret; |
| 99 | |
Lars-Peter Clausen | 610a407 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 100 | return be16_to_cpup((__be16 *)st->data); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 103 | static int ad7476_read_raw(struct iio_dev *indio_dev, |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 104 | struct iio_chan_spec const *chan, |
| 105 | int *val, |
| 106 | int *val2, |
| 107 | long m) |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 108 | { |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 109 | int ret; |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 110 | struct ad7476_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 111 | int scale_uv; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 112 | |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 113 | switch (m) { |
Jonathan Cameron | b11f98f | 2012-04-15 17:41:18 +0100 | [diff] [blame] | 114 | case IIO_CHAN_INFO_RAW: |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 115 | mutex_lock(&indio_dev->mlock); |
| 116 | if (iio_buffer_enabled(indio_dev)) |
Jonathan Cameron | 78c32ed | 2011-12-05 22:18:20 +0000 | [diff] [blame] | 117 | ret = -EBUSY; |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 118 | else |
| 119 | ret = ad7476_scan_direct(st); |
Jonathan Cameron | 84f79ec | 2011-10-06 17:14:37 +0100 | [diff] [blame] | 120 | mutex_unlock(&indio_dev->mlock); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 121 | |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | *val = (ret >> st->chip_info->channel[0].scan_type.shift) & |
| 125 | RES_MASK(st->chip_info->channel[0].scan_type.realbits); |
| 126 | return IIO_VAL_INT; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 127 | case IIO_CHAN_INFO_SCALE: |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 128 | if (!st->chip_info->int_vref_uv) { |
| 129 | scale_uv = regulator_get_voltage(st->reg); |
| 130 | if (scale_uv < 0) |
| 131 | return scale_uv; |
| 132 | } else { |
| 133 | scale_uv = st->chip_info->int_vref_uv; |
| 134 | } |
| 135 | scale_uv >>= chan->scan_type.realbits; |
| 136 | *val = scale_uv / 1000; |
| 137 | *val2 = (scale_uv % 1000) * 1000; |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 138 | return IIO_VAL_INT_PLUS_MICRO; |
| 139 | } |
| 140 | return -EINVAL; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 141 | } |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 142 | |
Jonathan Cameron | 8c1033f | 2013-02-27 19:05:34 +0000 | [diff] [blame] | 143 | #define _AD7476_CHAN(bits, _shift, _info_mask_sep) \ |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 144 | { \ |
| 145 | .type = IIO_VOLTAGE, \ |
| 146 | .indexed = 1, \ |
Jonathan Cameron | 8c1033f | 2013-02-27 19:05:34 +0000 | [diff] [blame] | 147 | .info_mask_separate = _info_mask_sep, \ |
| 148 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 149 | .scan_type = { \ |
| 150 | .sign = 'u', \ |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 151 | .realbits = (bits), \ |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 152 | .storagebits = 16, \ |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 153 | .shift = (_shift), \ |
| 154 | .endianness = IIO_BE, \ |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 155 | }, \ |
| 156 | } |
| 157 | |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 158 | #define AD7476_CHAN(bits) _AD7476_CHAN((bits), 13 - (bits), \ |
Jonathan Cameron | 8c1033f | 2013-02-27 19:05:34 +0000 | [diff] [blame] | 159 | BIT(IIO_CHAN_INFO_RAW)) |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 160 | #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \ |
Jonathan Cameron | 8c1033f | 2013-02-27 19:05:34 +0000 | [diff] [blame] | 161 | BIT(IIO_CHAN_INFO_RAW)) |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 162 | #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0) |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 163 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 164 | static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 165 | [ID_AD7091R] = { |
| 166 | .channel[0] = AD7091R_CHAN(12), |
| 167 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
| 168 | .reset = ad7091_reset, |
| 169 | }, |
Lars-Peter Clausen | c26cc89 | 2012-09-10 10:33:00 +0100 | [diff] [blame] | 170 | [ID_AD7276] = { |
| 171 | .channel[0] = AD7940_CHAN(12), |
| 172 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
| 173 | }, |
| 174 | [ID_AD7277] = { |
| 175 | .channel[0] = AD7940_CHAN(10), |
| 176 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
| 177 | }, |
| 178 | [ID_AD7278] = { |
| 179 | .channel[0] = AD7940_CHAN(8), |
| 180 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
| 181 | }, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 182 | [ID_AD7466] = { |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 183 | .channel[0] = AD7476_CHAN(12), |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 184 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 185 | }, |
| 186 | [ID_AD7467] = { |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 187 | .channel[0] = AD7476_CHAN(10), |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 188 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 189 | }, |
| 190 | [ID_AD7468] = { |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 191 | .channel[0] = AD7476_CHAN(8), |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 192 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 193 | }, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 194 | [ID_AD7495] = { |
Jonathan Cameron | 85871cd | 2012-04-13 10:42:55 +0100 | [diff] [blame] | 195 | .channel[0] = AD7476_CHAN(12), |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 196 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 197 | .int_vref_uv = 2500000, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 198 | }, |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 199 | [ID_AD7940] = { |
| 200 | .channel[0] = AD7940_CHAN(14), |
| 201 | .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), |
| 202 | }, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 203 | }; |
| 204 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 205 | static const struct iio_info ad7476_info = { |
| 206 | .driver_module = THIS_MODULE, |
| 207 | .read_raw = &ad7476_read_raw, |
| 208 | }; |
| 209 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 210 | static int ad7476_probe(struct spi_device *spi) |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 211 | { |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 212 | struct ad7476_state *st; |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 213 | struct iio_dev *indio_dev; |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 214 | int ret; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 215 | |
Sachin Kamat | 4ea454d | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 216 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
| 217 | if (!indio_dev) |
| 218 | return -ENOMEM; |
| 219 | |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 220 | st = iio_priv(indio_dev); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 221 | st->chip_info = |
| 222 | &ad7476_chip_info_tbl[spi_get_device_id(spi)->driver_data]; |
| 223 | |
Sachin Kamat | 4ea454d | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 224 | st->reg = devm_regulator_get(&spi->dev, "vcc"); |
| 225 | if (IS_ERR(st->reg)) |
| 226 | return PTR_ERR(st->reg); |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 227 | |
| 228 | ret = regulator_enable(st->reg); |
| 229 | if (ret) |
Sachin Kamat | 4ea454d | 2013-07-23 09:58:00 +0100 | [diff] [blame] | 230 | return ret; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 231 | |
Jonathan Cameron | 38f71aa | 2011-07-13 13:42:47 +0100 | [diff] [blame] | 232 | spi_set_drvdata(spi, indio_dev); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 233 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 234 | st->spi = spi; |
| 235 | |
Roland Stigge | ae63983 | 2011-01-29 16:27:17 +0100 | [diff] [blame] | 236 | /* Establish that the iio_dev is a child of the spi device */ |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 237 | indio_dev->dev.parent = &spi->dev; |
| 238 | indio_dev->name = spi_get_device_id(spi)->name; |
| 239 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 240 | indio_dev->channels = st->chip_info->channel; |
| 241 | indio_dev->num_channels = 2; |
| 242 | indio_dev->info = &ad7476_info; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 243 | /* Setup default message */ |
| 244 | |
| 245 | st->xfer.rx_buf = &st->data; |
Jonathan Cameron | c5e0819 | 2011-05-18 14:41:24 +0100 | [diff] [blame] | 246 | st->xfer.len = st->chip_info->channel[0].scan_type.storagebits / 8; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 247 | |
| 248 | spi_message_init(&st->msg); |
| 249 | spi_message_add_tail(&st->xfer, &st->msg); |
| 250 | |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 251 | ret = iio_triggered_buffer_setup(indio_dev, NULL, |
| 252 | &ad7476_trigger_handler, NULL); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 253 | if (ret) |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 254 | goto error_disable_reg; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 255 | |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 256 | if (st->chip_info->reset) |
| 257 | st->chip_info->reset(st); |
| 258 | |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 259 | ret = iio_device_register(indio_dev); |
| 260 | if (ret) |
| 261 | goto error_ring_unregister; |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 262 | return 0; |
| 263 | |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 264 | error_ring_unregister: |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 265 | iio_triggered_buffer_cleanup(indio_dev); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 266 | error_disable_reg: |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 267 | regulator_disable(st->reg); |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 268 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 269 | return ret; |
| 270 | } |
| 271 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 272 | static int ad7476_remove(struct spi_device *spi) |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 273 | { |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 274 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
| 275 | struct ad7476_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 276 | |
Jonathan Cameron | d2fffd6 | 2011-10-14 14:46:58 +0100 | [diff] [blame] | 277 | iio_device_unregister(indio_dev); |
Lars-Peter Clausen | 7a28fe3 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 278 | iio_triggered_buffer_cleanup(indio_dev); |
Lars-Peter Clausen | cb093e4 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 279 | regulator_disable(st->reg); |
Jonathan Cameron | 6768810 | 2011-06-27 13:07:18 +0100 | [diff] [blame] | 280 | |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static const struct spi_device_id ad7476_id[] = { |
Lars-Peter Clausen | 87c5b10 | 2012-09-17 13:26:00 +0100 | [diff] [blame] | 285 | {"ad7091r", ID_AD7091R}, |
Lars-Peter Clausen | c26cc89 | 2012-09-10 10:33:00 +0100 | [diff] [blame] | 286 | {"ad7273", ID_AD7277}, |
| 287 | {"ad7274", ID_AD7276}, |
| 288 | {"ad7276", ID_AD7276}, |
| 289 | {"ad7277", ID_AD7277}, |
| 290 | {"ad7278", ID_AD7278}, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 291 | {"ad7466", ID_AD7466}, |
| 292 | {"ad7467", ID_AD7467}, |
| 293 | {"ad7468", ID_AD7468}, |
Lars-Peter Clausen | fcc7800 | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 294 | {"ad7475", ID_AD7466}, |
| 295 | {"ad7476", ID_AD7466}, |
| 296 | {"ad7476a", ID_AD7466}, |
| 297 | {"ad7477", ID_AD7467}, |
| 298 | {"ad7477a", ID_AD7467}, |
| 299 | {"ad7478", ID_AD7468}, |
| 300 | {"ad7478a", ID_AD7468}, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 301 | {"ad7495", ID_AD7495}, |
Lars-Peter Clausen | ac5332b | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 302 | {"ad7910", ID_AD7467}, |
| 303 | {"ad7920", ID_AD7466}, |
Lars-Peter Clausen | 4c337de | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 304 | {"ad7940", ID_AD7940}, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 305 | {} |
| 306 | }; |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 307 | MODULE_DEVICE_TABLE(spi, ad7476_id); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 308 | |
| 309 | static struct spi_driver ad7476_driver = { |
| 310 | .driver = { |
| 311 | .name = "ad7476", |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 312 | .owner = THIS_MODULE, |
| 313 | }, |
| 314 | .probe = ad7476_probe, |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 315 | .remove = ad7476_remove, |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 316 | .id_table = ad7476_id, |
| 317 | }; |
Lars-Peter Clausen | ae6ae6f | 2011-11-16 10:13:39 +0100 | [diff] [blame] | 318 | module_spi_driver(ad7476_driver); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 319 | |
| 320 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
Lars-Peter Clausen | ac5332b | 2012-09-10 09:34:00 +0100 | [diff] [blame] | 321 | MODULE_DESCRIPTION("Analog Devices AD7476 and similar 1-channel ADCs"); |
Michael Hennerich | 349282d | 2010-10-11 18:05:37 +0200 | [diff] [blame] | 322 | MODULE_LICENSE("GPL v2"); |