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