blob: 605eb5e7e8291215e65f3d54b811e7b23cae44b1 [file] [log] [blame]
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +02001/*
2 * AD7266/65 SPI ADC driver
3 *
4 * Copyright 2012 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/device.h>
10#include <linux/kernel.h>
11#include <linux/slab.h>
12#include <linux/spi/spi.h>
13#include <linux/regulator/consumer.h>
14#include <linux/err.h>
15#include <linux/gpio.h>
16#include <linux/module.h>
17
18#include <linux/interrupt.h>
19
20#include <linux/iio/iio.h>
21#include <linux/iio/buffer.h>
22#include <linux/iio/trigger_consumer.h>
23#include <linux/iio/triggered_buffer.h>
24
25#include <linux/platform_data/ad7266.h>
26
27struct ad7266_state {
28 struct spi_device *spi;
29 struct regulator *reg;
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +010030 unsigned long vref_mv;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020031
32 struct spi_transfer single_xfer[3];
33 struct spi_message single_msg;
34
35 enum ad7266_range range;
36 enum ad7266_mode mode;
37 bool fixed_addr;
38 struct gpio gpios[3];
39
40 /*
41 * DMA (thus cache coherency maintenance) requires the
42 * transfer buffers to live in their own cache lines.
43 * The buffer needs to be large enough to hold two samples (4 bytes) and
44 * the naturally aligned timestamp (8 bytes).
45 */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +000046 struct {
47 __be16 sample[2];
48 s64 timestamp;
49 } data ____cacheline_aligned;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020050};
51
52static int ad7266_wakeup(struct ad7266_state *st)
53{
54 /* Any read with >= 2 bytes will wake the device */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +000055 return spi_read(st->spi, &st->data.sample[0], 2);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020056}
57
58static int ad7266_powerdown(struct ad7266_state *st)
59{
60 /* Any read with < 2 bytes will powerdown the device */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +000061 return spi_read(st->spi, &st->data.sample[0], 1);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020062}
63
64static int ad7266_preenable(struct iio_dev *indio_dev)
65{
66 struct ad7266_state *st = iio_priv(indio_dev);
Lars-Peter Clausen06e1b542013-10-14 17:49:00 +010067 return ad7266_wakeup(st);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020068}
69
70static int ad7266_postdisable(struct iio_dev *indio_dev)
71{
72 struct ad7266_state *st = iio_priv(indio_dev);
73 return ad7266_powerdown(st);
74}
75
76static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
77 .preenable = &ad7266_preenable,
78 .postenable = &iio_triggered_buffer_postenable,
79 .predisable = &iio_triggered_buffer_predisable,
80 .postdisable = &ad7266_postdisable,
81};
82
83static irqreturn_t ad7266_trigger_handler(int irq, void *p)
84{
85 struct iio_poll_func *pf = p;
86 struct iio_dev *indio_dev = pf->indio_dev;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020087 struct ad7266_state *st = iio_priv(indio_dev);
88 int ret;
89
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +000090 ret = spi_read(st->spi, st->data.sample, 4);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020091 if (ret == 0) {
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +000092 iio_push_to_buffers_with_timestamp(indio_dev, &st->data,
Lars-Peter Clausenfce8abf2013-09-19 13:59:00 +010093 pf->timestamp);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +020094 }
95
96 iio_trigger_notify_done(indio_dev->trig);
97
98 return IRQ_HANDLED;
99}
100
101static void ad7266_select_input(struct ad7266_state *st, unsigned int nr)
102{
103 unsigned int i;
104
105 if (st->fixed_addr)
106 return;
107
108 switch (st->mode) {
109 case AD7266_MODE_SINGLE_ENDED:
110 nr >>= 1;
111 break;
112 case AD7266_MODE_PSEUDO_DIFF:
113 nr |= 1;
114 break;
115 case AD7266_MODE_DIFF:
116 nr &= ~1;
117 break;
118 }
119
120 for (i = 0; i < 3; ++i)
121 gpio_set_value(st->gpios[i].gpio, (bool)(nr & BIT(i)));
122}
123
124static int ad7266_update_scan_mode(struct iio_dev *indio_dev,
125 const unsigned long *scan_mask)
126{
127 struct ad7266_state *st = iio_priv(indio_dev);
128 unsigned int nr = find_first_bit(scan_mask, indio_dev->masklength);
129
130 ad7266_select_input(st, nr);
131
132 return 0;
133}
134
135static int ad7266_read_single(struct ad7266_state *st, int *val,
136 unsigned int address)
137{
138 int ret;
139
140 ad7266_select_input(st, address);
141
142 ret = spi_sync(st->spi, &st->single_msg);
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +0000143 *val = be16_to_cpu(st->data.sample[address % 2]);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200144
145 return ret;
146}
147
148static int ad7266_read_raw(struct iio_dev *indio_dev,
149 struct iio_chan_spec const *chan, int *val, int *val2, long m)
150{
151 struct ad7266_state *st = iio_priv(indio_dev);
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100152 unsigned long scale_mv;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200153 int ret;
154
155 switch (m) {
156 case IIO_CHAN_INFO_RAW:
Alison Schofieldc70df202016-05-24 12:16:23 -0700157 ret = iio_device_claim_direct_mode(indio_dev);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200158 if (ret)
159 return ret;
Alison Schofieldc70df202016-05-24 12:16:23 -0700160 ret = ad7266_read_single(st, val, chan->address);
161 iio_device_release_direct_mode(indio_dev);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200162
163 *val = (*val >> 2) & 0xfff;
164 if (chan->scan_type.sign == 's')
165 *val = sign_extend32(*val, 11);
166
167 return IIO_VAL_INT;
168 case IIO_CHAN_INFO_SCALE:
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100169 scale_mv = st->vref_mv;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200170 if (st->mode == AD7266_MODE_DIFF)
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100171 scale_mv *= 2;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200172 if (st->range == AD7266_RANGE_2VREF)
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100173 scale_mv *= 2;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200174
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100175 *val = scale_mv;
176 *val2 = chan->scan_type.realbits;
177 return IIO_VAL_FRACTIONAL_LOG2;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200178 case IIO_CHAN_INFO_OFFSET:
179 if (st->range == AD7266_RANGE_2VREF &&
180 st->mode != AD7266_MODE_DIFF)
181 *val = 2048;
182 else
183 *val = 0;
184 return IIO_VAL_INT;
185 }
186 return -EINVAL;
187}
188
189#define AD7266_CHAN(_chan, _sign) { \
190 .type = IIO_VOLTAGE, \
191 .indexed = 1, \
192 .channel = (_chan), \
193 .address = (_chan), \
Jonathan Cameron3234ac72013-02-27 19:04:03 +0000194 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
195 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
196 | BIT(IIO_CHAN_INFO_OFFSET), \
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200197 .scan_index = (_chan), \
198 .scan_type = { \
199 .sign = (_sign), \
200 .realbits = 12, \
201 .storagebits = 16, \
202 .shift = 2, \
203 .endianness = IIO_BE, \
204 }, \
205}
206
207#define AD7266_DECLARE_SINGLE_ENDED_CHANNELS(_name, _sign) \
208const struct iio_chan_spec ad7266_channels_##_name[] = { \
209 AD7266_CHAN(0, (_sign)), \
210 AD7266_CHAN(1, (_sign)), \
211 AD7266_CHAN(2, (_sign)), \
212 AD7266_CHAN(3, (_sign)), \
213 AD7266_CHAN(4, (_sign)), \
214 AD7266_CHAN(5, (_sign)), \
215 AD7266_CHAN(6, (_sign)), \
216 AD7266_CHAN(7, (_sign)), \
217 AD7266_CHAN(8, (_sign)), \
218 AD7266_CHAN(9, (_sign)), \
219 AD7266_CHAN(10, (_sign)), \
220 AD7266_CHAN(11, (_sign)), \
221 IIO_CHAN_SOFT_TIMESTAMP(13), \
222}
223
224#define AD7266_DECLARE_SINGLE_ENDED_CHANNELS_FIXED(_name, _sign) \
225const struct iio_chan_spec ad7266_channels_##_name##_fixed[] = { \
226 AD7266_CHAN(0, (_sign)), \
227 AD7266_CHAN(1, (_sign)), \
228 IIO_CHAN_SOFT_TIMESTAMP(2), \
229}
230
231static AD7266_DECLARE_SINGLE_ENDED_CHANNELS(u, 'u');
232static AD7266_DECLARE_SINGLE_ENDED_CHANNELS(s, 's');
233static AD7266_DECLARE_SINGLE_ENDED_CHANNELS_FIXED(u, 'u');
234static AD7266_DECLARE_SINGLE_ENDED_CHANNELS_FIXED(s, 's');
235
236#define AD7266_CHAN_DIFF(_chan, _sign) { \
237 .type = IIO_VOLTAGE, \
238 .indexed = 1, \
239 .channel = (_chan) * 2, \
240 .channel2 = (_chan) * 2 + 1, \
241 .address = (_chan), \
Jonathan Cameron3234ac72013-02-27 19:04:03 +0000242 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
243 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
244 | BIT(IIO_CHAN_INFO_OFFSET), \
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200245 .scan_index = (_chan), \
246 .scan_type = { \
247 .sign = _sign, \
248 .realbits = 12, \
249 .storagebits = 16, \
250 .shift = 2, \
251 .endianness = IIO_BE, \
252 }, \
253 .differential = 1, \
254}
255
256#define AD7266_DECLARE_DIFF_CHANNELS(_name, _sign) \
257const struct iio_chan_spec ad7266_channels_diff_##_name[] = { \
258 AD7266_CHAN_DIFF(0, (_sign)), \
259 AD7266_CHAN_DIFF(1, (_sign)), \
260 AD7266_CHAN_DIFF(2, (_sign)), \
261 AD7266_CHAN_DIFF(3, (_sign)), \
262 AD7266_CHAN_DIFF(4, (_sign)), \
263 AD7266_CHAN_DIFF(5, (_sign)), \
264 IIO_CHAN_SOFT_TIMESTAMP(6), \
265}
266
267static AD7266_DECLARE_DIFF_CHANNELS(s, 's');
268static AD7266_DECLARE_DIFF_CHANNELS(u, 'u');
269
270#define AD7266_DECLARE_DIFF_CHANNELS_FIXED(_name, _sign) \
271const struct iio_chan_spec ad7266_channels_diff_fixed_##_name[] = { \
272 AD7266_CHAN_DIFF(0, (_sign)), \
273 AD7266_CHAN_DIFF(1, (_sign)), \
274 IIO_CHAN_SOFT_TIMESTAMP(2), \
275}
276
277static AD7266_DECLARE_DIFF_CHANNELS_FIXED(s, 's');
278static AD7266_DECLARE_DIFF_CHANNELS_FIXED(u, 'u');
279
280static const struct iio_info ad7266_info = {
281 .read_raw = &ad7266_read_raw,
282 .update_scan_mode = &ad7266_update_scan_mode,
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200283};
284
Peter Meerwald2bdb3af2013-09-17 22:33:00 +0100285static const unsigned long ad7266_available_scan_masks[] = {
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200286 0x003,
287 0x00c,
288 0x030,
289 0x0c0,
290 0x300,
291 0xc00,
292 0x000,
293};
294
Peter Meerwald2bdb3af2013-09-17 22:33:00 +0100295static const unsigned long ad7266_available_scan_masks_diff[] = {
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200296 0x003,
297 0x00c,
298 0x030,
299 0x000,
300};
301
Peter Meerwald2bdb3af2013-09-17 22:33:00 +0100302static const unsigned long ad7266_available_scan_masks_fixed[] = {
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200303 0x003,
304 0x000,
305};
306
307struct ad7266_chan_info {
308 const struct iio_chan_spec *channels;
309 unsigned int num_channels;
Peter Meerwald2bdb3af2013-09-17 22:33:00 +0100310 const unsigned long *scan_masks;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200311};
312
313#define AD7266_CHAN_INFO_INDEX(_differential, _signed, _fixed) \
314 (((_differential) << 2) | ((_signed) << 1) | ((_fixed) << 0))
315
316static const struct ad7266_chan_info ad7266_chan_infos[] = {
317 [AD7266_CHAN_INFO_INDEX(0, 0, 0)] = {
318 .channels = ad7266_channels_u,
319 .num_channels = ARRAY_SIZE(ad7266_channels_u),
320 .scan_masks = ad7266_available_scan_masks,
321 },
322 [AD7266_CHAN_INFO_INDEX(0, 0, 1)] = {
323 .channels = ad7266_channels_u_fixed,
324 .num_channels = ARRAY_SIZE(ad7266_channels_u_fixed),
325 .scan_masks = ad7266_available_scan_masks_fixed,
326 },
327 [AD7266_CHAN_INFO_INDEX(0, 1, 0)] = {
328 .channels = ad7266_channels_s,
329 .num_channels = ARRAY_SIZE(ad7266_channels_s),
330 .scan_masks = ad7266_available_scan_masks,
331 },
332 [AD7266_CHAN_INFO_INDEX(0, 1, 1)] = {
333 .channels = ad7266_channels_s_fixed,
334 .num_channels = ARRAY_SIZE(ad7266_channels_s_fixed),
335 .scan_masks = ad7266_available_scan_masks_fixed,
336 },
337 [AD7266_CHAN_INFO_INDEX(1, 0, 0)] = {
338 .channels = ad7266_channels_diff_u,
339 .num_channels = ARRAY_SIZE(ad7266_channels_diff_u),
340 .scan_masks = ad7266_available_scan_masks_diff,
341 },
342 [AD7266_CHAN_INFO_INDEX(1, 0, 1)] = {
343 .channels = ad7266_channels_diff_fixed_u,
344 .num_channels = ARRAY_SIZE(ad7266_channels_diff_fixed_u),
345 .scan_masks = ad7266_available_scan_masks_fixed,
346 },
347 [AD7266_CHAN_INFO_INDEX(1, 1, 0)] = {
348 .channels = ad7266_channels_diff_s,
349 .num_channels = ARRAY_SIZE(ad7266_channels_diff_s),
350 .scan_masks = ad7266_available_scan_masks_diff,
351 },
352 [AD7266_CHAN_INFO_INDEX(1, 1, 1)] = {
353 .channels = ad7266_channels_diff_fixed_s,
354 .num_channels = ARRAY_SIZE(ad7266_channels_diff_fixed_s),
355 .scan_masks = ad7266_available_scan_masks_fixed,
356 },
357};
358
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800359static void ad7266_init_channels(struct iio_dev *indio_dev)
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200360{
361 struct ad7266_state *st = iio_priv(indio_dev);
362 bool is_differential, is_signed;
363 const struct ad7266_chan_info *chan_info;
364 int i;
365
366 is_differential = st->mode != AD7266_MODE_SINGLE_ENDED;
367 is_signed = (st->range == AD7266_RANGE_2VREF) |
368 (st->mode == AD7266_MODE_DIFF);
369
370 i = AD7266_CHAN_INFO_INDEX(is_differential, is_signed, st->fixed_addr);
371 chan_info = &ad7266_chan_infos[i];
372
373 indio_dev->channels = chan_info->channels;
374 indio_dev->num_channels = chan_info->num_channels;
375 indio_dev->available_scan_masks = chan_info->scan_masks;
376 indio_dev->masklength = chan_info->num_channels - 1;
377}
378
379static const char * const ad7266_gpio_labels[] = {
380 "AD0", "AD1", "AD2",
381};
382
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800383static int ad7266_probe(struct spi_device *spi)
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200384{
385 struct ad7266_platform_data *pdata = spi->dev.platform_data;
386 struct iio_dev *indio_dev;
387 struct ad7266_state *st;
388 unsigned int i;
389 int ret;
390
Sachin Kamatded4fef2013-07-23 07:50:00 +0100391 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200392 if (indio_dev == NULL)
393 return -ENOMEM;
394
395 st = iio_priv(indio_dev);
396
Mark Browne5511c82016-06-20 13:53:33 +0100397 st->reg = devm_regulator_get_optional(&spi->dev, "vref");
Mark Brown6b7f4e22016-06-20 13:53:32 +0100398 if (!IS_ERR(st->reg)) {
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200399 ret = regulator_enable(st->reg);
400 if (ret)
Sachin Kamatded4fef2013-07-23 07:50:00 +0100401 return ret;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200402
Axel Lin36ce0c12012-12-14 07:47:00 +0000403 ret = regulator_get_voltage(st->reg);
404 if (ret < 0)
405 goto error_disable_reg;
406
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100407 st->vref_mv = ret / 1000;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200408 } else {
Mark Brown68b356e2016-06-20 13:53:34 +0100409 /* Any other error indicates that the regulator does exist */
410 if (PTR_ERR(st->reg) != -ENODEV)
411 return PTR_ERR(st->reg);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200412 /* Use internal reference */
Lars-Peter Clausen2ebc39c2013-09-28 10:31:00 +0100413 st->vref_mv = 2500;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200414 }
415
416 if (pdata) {
417 st->fixed_addr = pdata->fixed_addr;
418 st->mode = pdata->mode;
419 st->range = pdata->range;
420
421 if (!st->fixed_addr) {
422 for (i = 0; i < ARRAY_SIZE(st->gpios); ++i) {
423 st->gpios[i].gpio = pdata->addr_gpios[i];
424 st->gpios[i].flags = GPIOF_OUT_INIT_LOW;
425 st->gpios[i].label = ad7266_gpio_labels[i];
426 }
427 ret = gpio_request_array(st->gpios,
428 ARRAY_SIZE(st->gpios));
429 if (ret)
430 goto error_disable_reg;
431 }
432 } else {
433 st->fixed_addr = true;
434 st->range = AD7266_RANGE_VREF;
435 st->mode = AD7266_MODE_DIFF;
436 }
437
438 spi_set_drvdata(spi, indio_dev);
439 st->spi = spi;
440
441 indio_dev->dev.parent = &spi->dev;
Matt Ranostayb541eaf2016-07-02 17:26:33 -0700442 indio_dev->dev.of_node = spi->dev.of_node;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200443 indio_dev->name = spi_get_device_id(spi)->name;
444 indio_dev->modes = INDIO_DIRECT_MODE;
445 indio_dev->info = &ad7266_info;
446
447 ad7266_init_channels(indio_dev);
448
449 /* wakeup */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +0000450 st->single_xfer[0].rx_buf = &st->data.sample[0];
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200451 st->single_xfer[0].len = 2;
452 st->single_xfer[0].cs_change = 1;
453 /* conversion */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +0000454 st->single_xfer[1].rx_buf = st->data.sample;
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200455 st->single_xfer[1].len = 4;
456 st->single_xfer[1].cs_change = 1;
457 /* powerdown */
Lars-Peter Clausen54e018d2013-11-25 12:42:00 +0000458 st->single_xfer[2].tx_buf = &st->data.sample[0];
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200459 st->single_xfer[2].len = 1;
460
461 spi_message_init(&st->single_msg);
462 spi_message_add_tail(&st->single_xfer[0], &st->single_msg);
463 spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
464 spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
465
466 ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
467 &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
468 if (ret)
469 goto error_free_gpios;
470
471 ret = iio_device_register(indio_dev);
472 if (ret)
473 goto error_buffer_cleanup;
474
475 return 0;
476
477error_buffer_cleanup:
478 iio_triggered_buffer_cleanup(indio_dev);
479error_free_gpios:
480 if (!st->fixed_addr)
481 gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios));
482error_disable_reg:
Crt Morifbe84bd2016-09-05 11:14:49 +0200483 if (!IS_ERR(st->reg))
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200484 regulator_disable(st->reg);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200485
486 return ret;
487}
488
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800489static int ad7266_remove(struct spi_device *spi)
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200490{
491 struct iio_dev *indio_dev = spi_get_drvdata(spi);
492 struct ad7266_state *st = iio_priv(indio_dev);
493
494 iio_device_unregister(indio_dev);
495 iio_triggered_buffer_cleanup(indio_dev);
496 if (!st->fixed_addr)
497 gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios));
Crt Morifbe84bd2016-09-05 11:14:49 +0200498 if (!IS_ERR(st->reg))
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200499 regulator_disable(st->reg);
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200500
501 return 0;
502}
503
504static const struct spi_device_id ad7266_id[] = {
505 {"ad7265", 0},
506 {"ad7266", 0},
507 { }
508};
509MODULE_DEVICE_TABLE(spi, ad7266_id);
510
511static struct spi_driver ad7266_driver = {
512 .driver = {
513 .name = "ad7266",
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200514 },
515 .probe = ad7266_probe,
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800516 .remove = ad7266_remove,
Lars-Peter Clausen8ec4cf52012-06-25 14:52:49 +0200517 .id_table = ad7266_id,
518};
519module_spi_driver(ad7266_driver);
520
521MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
522MODULE_DESCRIPTION("Analog Devices AD7266/65 ADC");
523MODULE_LICENSE("GPL v2");