blob: 793a803919c528db25659568f5de4f2da917858f [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * AD7124 SPI ADC driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7#include <linux/bitfield.h>
8#include <linux/clk.h>
9#include <linux/delay.h>
10#include <linux/device.h>
11#include <linux/err.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/regulator/consumer.h>
15#include <linux/spi/spi.h>
16
17#include <linux/iio/iio.h>
18#include <linux/iio/adc/ad_sigma_delta.h>
19#include <linux/iio/sysfs.h>
20
21/* AD7124 registers */
22#define AD7124_COMMS 0x00
23#define AD7124_STATUS 0x00
24#define AD7124_ADC_CONTROL 0x01
25#define AD7124_DATA 0x02
26#define AD7124_IO_CONTROL_1 0x03
27#define AD7124_IO_CONTROL_2 0x04
28#define AD7124_ID 0x05
29#define AD7124_ERROR 0x06
30#define AD7124_ERROR_EN 0x07
31#define AD7124_MCLK_COUNT 0x08
32#define AD7124_CHANNEL(x) (0x09 + (x))
33#define AD7124_CONFIG(x) (0x19 + (x))
34#define AD7124_FILTER(x) (0x21 + (x))
35#define AD7124_OFFSET(x) (0x29 + (x))
36#define AD7124_GAIN(x) (0x31 + (x))
37
38/* AD7124_STATUS */
39#define AD7124_STATUS_POR_FLAG_MSK BIT(4)
40
41/* AD7124_ADC_CONTROL */
42#define AD7124_ADC_CTRL_REF_EN_MSK BIT(8)
43#define AD7124_ADC_CTRL_REF_EN(x) FIELD_PREP(AD7124_ADC_CTRL_REF_EN_MSK, x)
44#define AD7124_ADC_CTRL_PWR_MSK GENMASK(7, 6)
45#define AD7124_ADC_CTRL_PWR(x) FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
46#define AD7124_ADC_CTRL_MODE_MSK GENMASK(5, 2)
47#define AD7124_ADC_CTRL_MODE(x) FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
48
49/* AD7124_CHANNEL_X */
50#define AD7124_CHANNEL_EN_MSK BIT(15)
51#define AD7124_CHANNEL_EN(x) FIELD_PREP(AD7124_CHANNEL_EN_MSK, x)
52#define AD7124_CHANNEL_SETUP_MSK GENMASK(14, 12)
53#define AD7124_CHANNEL_SETUP(x) FIELD_PREP(AD7124_CHANNEL_SETUP_MSK, x)
54#define AD7124_CHANNEL_AINP_MSK GENMASK(9, 5)
55#define AD7124_CHANNEL_AINP(x) FIELD_PREP(AD7124_CHANNEL_AINP_MSK, x)
56#define AD7124_CHANNEL_AINM_MSK GENMASK(4, 0)
57#define AD7124_CHANNEL_AINM(x) FIELD_PREP(AD7124_CHANNEL_AINM_MSK, x)
58
59/* AD7124_CONFIG_X */
60#define AD7124_CONFIG_BIPOLAR_MSK BIT(11)
61#define AD7124_CONFIG_BIPOLAR(x) FIELD_PREP(AD7124_CONFIG_BIPOLAR_MSK, x)
62#define AD7124_CONFIG_REF_SEL_MSK GENMASK(4, 3)
63#define AD7124_CONFIG_REF_SEL(x) FIELD_PREP(AD7124_CONFIG_REF_SEL_MSK, x)
64#define AD7124_CONFIG_PGA_MSK GENMASK(2, 0)
65#define AD7124_CONFIG_PGA(x) FIELD_PREP(AD7124_CONFIG_PGA_MSK, x)
66#define AD7124_CONFIG_IN_BUFF_MSK GENMASK(6, 5)
67#define AD7124_CONFIG_IN_BUFF(x) FIELD_PREP(AD7124_CONFIG_IN_BUFF_MSK, x)
68
69/* AD7124_FILTER_X */
70#define AD7124_FILTER_FS_MSK GENMASK(10, 0)
71#define AD7124_FILTER_FS(x) FIELD_PREP(AD7124_FILTER_FS_MSK, x)
72
73enum ad7124_ids {
74 ID_AD7124_4,
75 ID_AD7124_8,
76};
77
78enum ad7124_ref_sel {
79 AD7124_REFIN1,
80 AD7124_REFIN2,
81 AD7124_INT_REF,
82 AD7124_AVDD_REF,
83};
84
85enum ad7124_power_mode {
86 AD7124_LOW_POWER,
87 AD7124_MID_POWER,
88 AD7124_FULL_POWER,
89};
90
91static const unsigned int ad7124_gain[8] = {
92 1, 2, 4, 8, 16, 32, 64, 128
93};
94
95static const int ad7124_master_clk_freq_hz[3] = {
96 [AD7124_LOW_POWER] = 76800,
97 [AD7124_MID_POWER] = 153600,
98 [AD7124_FULL_POWER] = 614400,
99};
100
101static const char * const ad7124_ref_names[] = {
102 [AD7124_REFIN1] = "refin1",
103 [AD7124_REFIN2] = "refin2",
104 [AD7124_INT_REF] = "int",
105 [AD7124_AVDD_REF] = "avdd",
106};
107
108struct ad7124_chip_info {
109 unsigned int num_inputs;
110};
111
112struct ad7124_channel_config {
113 enum ad7124_ref_sel refsel;
114 bool bipolar;
115 bool buf_positive;
116 bool buf_negative;
117 unsigned int ain;
118 unsigned int vref_mv;
119 unsigned int pga_bits;
120 unsigned int odr;
121};
122
123struct ad7124_state {
124 const struct ad7124_chip_info *chip_info;
125 struct ad_sigma_delta sd;
126 struct ad7124_channel_config *channel_config;
127 struct regulator *vref[4];
128 struct clk *mclk;
129 unsigned int adc_control;
130 unsigned int num_channels;
131};
132
133static const struct iio_chan_spec ad7124_channel_template = {
134 .type = IIO_VOLTAGE,
135 .indexed = 1,
136 .differential = 1,
137 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
138 BIT(IIO_CHAN_INFO_SCALE) |
139 BIT(IIO_CHAN_INFO_OFFSET) |
140 BIT(IIO_CHAN_INFO_SAMP_FREQ),
141 .scan_type = {
142 .sign = 'u',
143 .realbits = 24,
144 .storagebits = 32,
145 .endianness = IIO_BE,
146 },
147};
148
149static struct ad7124_chip_info ad7124_chip_info_tbl[] = {
150 [ID_AD7124_4] = {
151 .num_inputs = 8,
152 },
153 [ID_AD7124_8] = {
154 .num_inputs = 16,
155 },
156};
157
158static int ad7124_find_closest_match(const int *array,
159 unsigned int size, int val)
160{
161 int i, idx;
162 unsigned int diff_new, diff_old;
163
164 diff_old = U32_MAX;
165 idx = 0;
166
167 for (i = 0; i < size; i++) {
168 diff_new = abs(val - array[i]);
169 if (diff_new < diff_old) {
170 diff_old = diff_new;
171 idx = i;
172 }
173 }
174
175 return idx;
176}
177
178static int ad7124_spi_write_mask(struct ad7124_state *st,
179 unsigned int addr,
180 unsigned long mask,
181 unsigned int val,
182 unsigned int bytes)
183{
184 unsigned int readval;
185 int ret;
186
187 ret = ad_sd_read_reg(&st->sd, addr, bytes, &readval);
188 if (ret < 0)
189 return ret;
190
191 readval &= ~mask;
192 readval |= val;
193
194 return ad_sd_write_reg(&st->sd, addr, bytes, readval);
195}
196
197static int ad7124_set_mode(struct ad_sigma_delta *sd,
198 enum ad_sigma_delta_mode mode)
199{
200 struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
201
202 st->adc_control &= ~AD7124_ADC_CTRL_MODE_MSK;
203 st->adc_control |= AD7124_ADC_CTRL_MODE(mode);
204
205 return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
206}
207
208static int ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel)
209{
210 struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
211 unsigned int val;
212
213 val = st->channel_config[channel].ain | AD7124_CHANNEL_EN(1) |
214 AD7124_CHANNEL_SETUP(channel);
215
216 return ad_sd_write_reg(&st->sd, AD7124_CHANNEL(channel), 2, val);
217}
218
219static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
220 .set_channel = ad7124_set_channel,
221 .set_mode = ad7124_set_mode,
222 .has_registers = true,
223 .addr_shift = 0,
224 .read_mask = BIT(6),
225 .data_reg = AD7124_DATA,
226};
227
228static int ad7124_set_channel_odr(struct ad7124_state *st,
229 unsigned int channel,
230 unsigned int odr)
231{
232 unsigned int fclk, odr_sel_bits;
233 int ret;
234
235 fclk = clk_get_rate(st->mclk);
236 /*
237 * FS[10:0] = fCLK / (fADC x 32) where:
238 * fADC is the output data rate
239 * fCLK is the master clock frequency
240 * FS[10:0] are the bits in the filter register
241 * FS[10:0] can have a value from 1 to 2047
242 */
243 odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * 32);
244 if (odr_sel_bits < 1)
245 odr_sel_bits = 1;
246 else if (odr_sel_bits > 2047)
247 odr_sel_bits = 2047;
248
249 ret = ad7124_spi_write_mask(st, AD7124_FILTER(channel),
250 AD7124_FILTER_FS_MSK,
251 AD7124_FILTER_FS(odr_sel_bits), 3);
252 if (ret < 0)
253 return ret;
254 /* fADC = fCLK / (FS[10:0] x 32) */
255 st->channel_config[channel].odr =
256 DIV_ROUND_CLOSEST(fclk, odr_sel_bits * 32);
257
258 return 0;
259}
260
261static int ad7124_set_channel_gain(struct ad7124_state *st,
262 unsigned int channel,
263 unsigned int gain)
264{
265 unsigned int res;
266 int ret;
267
268 res = ad7124_find_closest_match(ad7124_gain,
269 ARRAY_SIZE(ad7124_gain), gain);
270 ret = ad7124_spi_write_mask(st, AD7124_CONFIG(channel),
271 AD7124_CONFIG_PGA_MSK,
272 AD7124_CONFIG_PGA(res), 2);
273 if (ret < 0)
274 return ret;
275
276 st->channel_config[channel].pga_bits = res;
277
278 return 0;
279}
280
281static int ad7124_read_raw(struct iio_dev *indio_dev,
282 struct iio_chan_spec const *chan,
283 int *val, int *val2, long info)
284{
285 struct ad7124_state *st = iio_priv(indio_dev);
286 int idx, ret;
287
288 switch (info) {
289 case IIO_CHAN_INFO_RAW:
290 ret = ad_sigma_delta_single_conversion(indio_dev, chan, val);
291 if (ret < 0)
292 return ret;
293
294 /* After the conversion is performed, disable the channel */
295 ret = ad_sd_write_reg(&st->sd,
296 AD7124_CHANNEL(chan->address), 2,
297 st->channel_config[chan->address].ain |
298 AD7124_CHANNEL_EN(0));
299 if (ret < 0)
300 return ret;
301
302 return IIO_VAL_INT;
303 case IIO_CHAN_INFO_SCALE:
304 idx = st->channel_config[chan->address].pga_bits;
305 *val = st->channel_config[chan->address].vref_mv;
306 if (st->channel_config[chan->address].bipolar)
307 *val2 = chan->scan_type.realbits - 1 + idx;
308 else
309 *val2 = chan->scan_type.realbits + idx;
310
311 return IIO_VAL_FRACTIONAL_LOG2;
312 case IIO_CHAN_INFO_OFFSET:
313 if (st->channel_config[chan->address].bipolar)
314 *val = -(1 << (chan->scan_type.realbits - 1));
315 else
316 *val = 0;
317
318 return IIO_VAL_INT;
319 case IIO_CHAN_INFO_SAMP_FREQ:
320 *val = st->channel_config[chan->address].odr;
321
322 return IIO_VAL_INT;
323 default:
324 return -EINVAL;
325 }
326}
327
328static int ad7124_write_raw(struct iio_dev *indio_dev,
329 struct iio_chan_spec const *chan,
330 int val, int val2, long info)
331{
332 struct ad7124_state *st = iio_priv(indio_dev);
333 unsigned int res, gain, full_scale, vref;
334
335 switch (info) {
336 case IIO_CHAN_INFO_SAMP_FREQ:
337 if (val2 != 0)
338 return -EINVAL;
339
340 return ad7124_set_channel_odr(st, chan->address, val);
341 case IIO_CHAN_INFO_SCALE:
342 if (val != 0)
343 return -EINVAL;
344
345 if (st->channel_config[chan->address].bipolar)
346 full_scale = 1 << (chan->scan_type.realbits - 1);
347 else
348 full_scale = 1 << chan->scan_type.realbits;
349
350 vref = st->channel_config[chan->address].vref_mv * 1000000LL;
351 res = DIV_ROUND_CLOSEST(vref, full_scale);
352 gain = DIV_ROUND_CLOSEST(res, val2);
353
354 return ad7124_set_channel_gain(st, chan->address, gain);
355 default:
356 return -EINVAL;
357 }
358}
359
360static IIO_CONST_ATTR(in_voltage_scale_available,
361 "0.000001164 0.000002328 0.000004656 0.000009313 0.000018626 0.000037252 0.000074505 0.000149011 0.000298023");
362
363static struct attribute *ad7124_attributes[] = {
364 &iio_const_attr_in_voltage_scale_available.dev_attr.attr,
365 NULL,
366};
367
368static const struct attribute_group ad7124_attrs_group = {
369 .attrs = ad7124_attributes,
370};
371
372static const struct iio_info ad7124_info = {
373 .read_raw = ad7124_read_raw,
374 .write_raw = ad7124_write_raw,
375 .validate_trigger = ad_sd_validate_trigger,
376 .attrs = &ad7124_attrs_group,
377};
378
379static int ad7124_soft_reset(struct ad7124_state *st)
380{
381 unsigned int readval, timeout;
382 int ret;
383
384 ret = ad_sd_reset(&st->sd, 64);
385 if (ret < 0)
386 return ret;
387
388 timeout = 100;
389 do {
390 ret = ad_sd_read_reg(&st->sd, AD7124_STATUS, 1, &readval);
391 if (ret < 0)
392 return ret;
393
394 if (!(readval & AD7124_STATUS_POR_FLAG_MSK))
395 return 0;
396
397 /* The AD7124 requires typically 2ms to power up and settle */
398 usleep_range(100, 2000);
399 } while (--timeout);
400
401 dev_err(&st->sd.spi->dev, "Soft reset failed\n");
402
403 return -EIO;
404}
405
406static int ad7124_init_channel_vref(struct ad7124_state *st,
407 unsigned int channel_number)
408{
409 unsigned int refsel = st->channel_config[channel_number].refsel;
410
411 switch (refsel) {
412 case AD7124_REFIN1:
413 case AD7124_REFIN2:
414 case AD7124_AVDD_REF:
415 if (IS_ERR(st->vref[refsel])) {
416 dev_err(&st->sd.spi->dev,
417 "Error, trying to use external voltage reference without a %s regulator.\n",
418 ad7124_ref_names[refsel]);
419 return PTR_ERR(st->vref[refsel]);
420 }
421 st->channel_config[channel_number].vref_mv =
422 regulator_get_voltage(st->vref[refsel]);
423 /* Conversion from uV to mV */
424 st->channel_config[channel_number].vref_mv /= 1000;
425 break;
426 case AD7124_INT_REF:
427 st->channel_config[channel_number].vref_mv = 2500;
428 st->adc_control &= ~AD7124_ADC_CTRL_REF_EN_MSK;
429 st->adc_control |= AD7124_ADC_CTRL_REF_EN(1);
430 return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL,
431 2, st->adc_control);
432 default:
433 dev_err(&st->sd.spi->dev, "Invalid reference %d\n", refsel);
434 return -EINVAL;
435 }
436
437 return 0;
438}
439
440static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
441 struct device_node *np)
442{
443 struct ad7124_state *st = iio_priv(indio_dev);
444 struct device_node *child;
445 struct iio_chan_spec *chan;
446 struct ad7124_channel_config *chan_config;
447 unsigned int ain[2], channel = 0, tmp;
448 int ret;
449
450 st->num_channels = of_get_available_child_count(np);
451 if (!st->num_channels) {
452 dev_err(indio_dev->dev.parent, "no channel children\n");
453 return -ENODEV;
454 }
455
456 chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
457 sizeof(*chan), GFP_KERNEL);
458 if (!chan)
459 return -ENOMEM;
460
461 chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
462 sizeof(*chan_config), GFP_KERNEL);
463 if (!chan_config)
464 return -ENOMEM;
465
466 indio_dev->channels = chan;
467 indio_dev->num_channels = st->num_channels;
468 st->channel_config = chan_config;
469
470 for_each_available_child_of_node(np, child) {
471 ret = of_property_read_u32(child, "reg", &channel);
472 if (ret)
473 goto err;
474
475 if (channel >= indio_dev->num_channels) {
476 dev_err(indio_dev->dev.parent,
477 "Channel index >= number of channels\n");
478 ret = -EINVAL;
479 goto err;
480 }
481
482 ret = of_property_read_u32_array(child, "diff-channels",
483 ain, 2);
484 if (ret)
485 goto err;
486
487 st->channel_config[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
488 AD7124_CHANNEL_AINM(ain[1]);
489 st->channel_config[channel].bipolar =
490 of_property_read_bool(child, "bipolar");
491
492 ret = of_property_read_u32(child, "adi,reference-select", &tmp);
493 if (ret)
494 st->channel_config[channel].refsel = AD7124_INT_REF;
495 else
496 st->channel_config[channel].refsel = tmp;
497
498 st->channel_config[channel].buf_positive =
499 of_property_read_bool(child, "adi,buffered-positive");
500 st->channel_config[channel].buf_negative =
501 of_property_read_bool(child, "adi,buffered-negative");
502
503 chan[channel] = ad7124_channel_template;
504 chan[channel].address = channel;
505 chan[channel].scan_index = channel;
506 chan[channel].channel = ain[0];
507 chan[channel].channel2 = ain[1];
508 }
509
510 return 0;
511err:
512 of_node_put(child);
513
514 return ret;
515}
516
517static int ad7124_setup(struct ad7124_state *st)
518{
519 unsigned int val, fclk, power_mode;
520 int i, ret, tmp;
521
522 fclk = clk_get_rate(st->mclk);
523 if (!fclk)
524 return -EINVAL;
525
526 /* The power mode changes the master clock frequency */
527 power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz,
528 ARRAY_SIZE(ad7124_master_clk_freq_hz),
529 fclk);
530 if (fclk != ad7124_master_clk_freq_hz[power_mode]) {
531 ret = clk_set_rate(st->mclk, fclk);
532 if (ret)
533 return ret;
534 }
535
536 /* Set the power mode */
537 st->adc_control &= ~AD7124_ADC_CTRL_PWR_MSK;
538 st->adc_control |= AD7124_ADC_CTRL_PWR(power_mode);
539 ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
540 if (ret < 0)
541 return ret;
542
543 for (i = 0; i < st->num_channels; i++) {
544 val = st->channel_config[i].ain | AD7124_CHANNEL_SETUP(i);
545 ret = ad_sd_write_reg(&st->sd, AD7124_CHANNEL(i), 2, val);
546 if (ret < 0)
547 return ret;
548
549 ret = ad7124_init_channel_vref(st, i);
550 if (ret < 0)
551 return ret;
552
553 tmp = (st->channel_config[i].buf_positive << 1) +
554 st->channel_config[i].buf_negative;
555
556 val = AD7124_CONFIG_BIPOLAR(st->channel_config[i].bipolar) |
557 AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel) |
558 AD7124_CONFIG_IN_BUFF(tmp);
559 ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(i), 2, val);
560 if (ret < 0)
561 return ret;
562 /*
563 * 9.38 SPS is the minimum output data rate supported
564 * regardless of the selected power mode. Round it up to 10 and
565 * set all the enabled channels to this default value.
566 */
567 ret = ad7124_set_channel_odr(st, i, 10);
568 }
569
570 return ret;
571}
572
573static void ad7124_reg_disable(void *r)
574{
575 regulator_disable(r);
576}
577
578static int ad7124_probe(struct spi_device *spi)
579{
580 const struct spi_device_id *id;
581 struct ad7124_state *st;
582 struct iio_dev *indio_dev;
583 int i, ret;
584
585 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
586 if (!indio_dev)
587 return -ENOMEM;
588
589 st = iio_priv(indio_dev);
590
591 id = spi_get_device_id(spi);
592 st->chip_info = &ad7124_chip_info_tbl[id->driver_data];
593
594 ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
595
596 spi_set_drvdata(spi, indio_dev);
597
598 indio_dev->dev.parent = &spi->dev;
599 indio_dev->name = spi_get_device_id(spi)->name;
600 indio_dev->modes = INDIO_DIRECT_MODE;
601 indio_dev->info = &ad7124_info;
602
603 ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node);
604 if (ret < 0)
605 return ret;
606
607 for (i = 0; i < ARRAY_SIZE(st->vref); i++) {
608 if (i == AD7124_INT_REF)
609 continue;
610
611 st->vref[i] = devm_regulator_get_optional(&spi->dev,
612 ad7124_ref_names[i]);
613 if (PTR_ERR(st->vref[i]) == -ENODEV)
614 continue;
615 else if (IS_ERR(st->vref[i]))
616 return PTR_ERR(st->vref[i]);
617
618 ret = regulator_enable(st->vref[i]);
619 if (ret)
620 return ret;
621
622 ret = devm_add_action_or_reset(&spi->dev, ad7124_reg_disable,
623 st->vref[i]);
624 if (ret)
625 return ret;
626 }
627
628 st->mclk = devm_clk_get(&spi->dev, "mclk");
629 if (IS_ERR(st->mclk))
630 return PTR_ERR(st->mclk);
631
632 ret = clk_prepare_enable(st->mclk);
633 if (ret < 0)
634 return ret;
635
636 ret = ad7124_soft_reset(st);
637 if (ret < 0)
638 goto error_clk_disable_unprepare;
639
640 ret = ad7124_setup(st);
641 if (ret < 0)
642 goto error_clk_disable_unprepare;
643
644 ret = ad_sd_setup_buffer_and_trigger(indio_dev);
645 if (ret < 0)
646 goto error_clk_disable_unprepare;
647
648 ret = iio_device_register(indio_dev);
649 if (ret < 0) {
650 dev_err(&spi->dev, "Failed to register iio device\n");
651 goto error_remove_trigger;
652 }
653
654 return 0;
655
656error_remove_trigger:
657 ad_sd_cleanup_buffer_and_trigger(indio_dev);
658error_clk_disable_unprepare:
659 clk_disable_unprepare(st->mclk);
660
661 return ret;
662}
663
664static int ad7124_remove(struct spi_device *spi)
665{
666 struct iio_dev *indio_dev = spi_get_drvdata(spi);
667 struct ad7124_state *st = iio_priv(indio_dev);
668
669 iio_device_unregister(indio_dev);
670 ad_sd_cleanup_buffer_and_trigger(indio_dev);
671 clk_disable_unprepare(st->mclk);
672
673 return 0;
674}
675
676static const struct spi_device_id ad7124_id_table[] = {
677 { "ad7124-4", ID_AD7124_4 },
678 { "ad7124-8", ID_AD7124_8 },
679 {}
680};
681MODULE_DEVICE_TABLE(spi, ad7124_id_table);
682
683static const struct of_device_id ad7124_of_match[] = {
684 { .compatible = "adi,ad7124-4" },
685 { .compatible = "adi,ad7124-8" },
686 { },
687};
688MODULE_DEVICE_TABLE(of, ad7124_of_match);
689
690static struct spi_driver ad71124_driver = {
691 .driver = {
692 .name = "ad7124",
693 .of_match_table = ad7124_of_match,
694 },
695 .probe = ad7124_probe,
696 .remove = ad7124_remove,
697 .id_table = ad7124_id_table,
698};
699module_spi_driver(ad71124_driver);
700
701MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
702MODULE_DESCRIPTION("Analog Devices AD7124 SPI driver");
703MODULE_LICENSE("GPL");