1 // SPDX-License-Identifier: GPL-2.0-only
3 * Analog Devices AD738x Simultaneous Sampling SAR ADCs
5 * Copyright 2017 Analog Devices Inc.
6 * Copyright 2024 BayLibre, SAS
8 * Datasheets of supported parts:
9 * ad7380/1 : https://www.analog.com/media/en/technical-documentation/data-sheets/AD7380-7381.pdf
10 * ad7383/4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-7384.pdf
11 * ad7380-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7380-4.pdf
12 * ad7381-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-4.pdf
13 * ad7383/4-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-4-ad7384-4.pdf
16 #include <linux/align.h>
17 #include <linux/bitfield.h>
18 #include <linux/bitops.h>
19 #include <linux/cleanup.h>
20 #include <linux/device.h>
21 #include <linux/err.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/regmap.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/slab.h>
27 #include <linux/spi/spi.h>
29 #include <linux/iio/buffer.h>
30 #include <linux/iio/iio.h>
31 #include <linux/iio/trigger_consumer.h>
32 #include <linux/iio/triggered_buffer.h>
34 #define MAX_NUM_CHANNELS 4
35 /* 2.5V internal reference voltage */
36 #define AD7380_INTERNAL_REF_MV 2500
38 /* reading and writing registers is more reliable at lower than max speed */
39 #define AD7380_REG_WR_SPEED_HZ 10000000
41 #define AD7380_REG_WR BIT(15)
42 #define AD7380_REG_REGADDR GENMASK(14, 12)
43 #define AD7380_REG_DATA GENMASK(11, 0)
45 #define AD7380_REG_ADDR_NOP 0x0
46 #define AD7380_REG_ADDR_CONFIG1 0x1
47 #define AD7380_REG_ADDR_CONFIG2 0x2
48 #define AD7380_REG_ADDR_ALERT 0x3
49 #define AD7380_REG_ADDR_ALERT_LOW_TH 0x4
50 #define AD7380_REG_ADDR_ALERT_HIGH_TH 0x5
52 #define AD7380_CONFIG1_OS_MODE BIT(9)
53 #define AD7380_CONFIG1_OSR GENMASK(8, 6)
54 #define AD7380_CONFIG1_CRC_W BIT(5)
55 #define AD7380_CONFIG1_CRC_R BIT(4)
56 #define AD7380_CONFIG1_ALERTEN BIT(3)
57 #define AD7380_CONFIG1_RES BIT(2)
58 #define AD7380_CONFIG1_REFSEL BIT(1)
59 #define AD7380_CONFIG1_PMODE BIT(0)
61 #define AD7380_CONFIG2_SDO2 GENMASK(9, 8)
62 #define AD7380_CONFIG2_SDO BIT(8)
63 #define AD7380_CONFIG2_RESET GENMASK(7, 0)
65 #define AD7380_CONFIG2_RESET_SOFT 0x3C
66 #define AD7380_CONFIG2_RESET_HARD 0xFF
68 #define AD7380_ALERT_LOW_TH GENMASK(11, 0)
69 #define AD7380_ALERT_HIGH_TH GENMASK(11, 0)
71 #define T_CONVERT_NS 190 /* conversion time */
72 #define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */
73 #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */
75 struct ad7380_timing_specs {
76 const unsigned int t_csh_ns; /* CS minimum high time */
79 struct ad7380_chip_info {
81 const struct iio_chan_spec *channels;
82 unsigned int num_channels;
83 const char * const *vcm_supplies;
84 unsigned int num_vcm_supplies;
85 const unsigned long *available_scan_masks;
86 const struct ad7380_timing_specs *timing_specs;
90 AD7380_SCAN_TYPE_NORMAL,
91 AD7380_SCAN_TYPE_RESOLUTION_BOOST,
94 /* Extended scan types for 14-bit chips. */
95 static const struct iio_scan_type ad7380_scan_type_14[] = {
96 [AD7380_SCAN_TYPE_NORMAL] = {
100 .endianness = IIO_CPU
102 [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
106 .endianness = IIO_CPU
110 /* Extended scan types for 16-bit chips. */
111 static const struct iio_scan_type ad7380_scan_type_16[] = {
112 [AD7380_SCAN_TYPE_NORMAL] = {
116 .endianness = IIO_CPU
118 [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
122 .endianness = IIO_CPU
126 #define AD7380_CHANNEL(index, bits, diff) { \
127 .type = IIO_VOLTAGE, \
128 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
129 ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \
130 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
131 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
132 .info_mask_shared_by_type_available = \
133 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
135 .differential = (diff), \
136 .channel = (diff) ? (2 * (index)) : (index), \
137 .channel2 = (diff) ? (2 * (index) + 1) : 0, \
138 .scan_index = (index), \
139 .has_ext_scan_type = 1, \
140 .ext_scan_type = ad7380_scan_type_##bits, \
141 .num_ext_scan_type = ARRAY_SIZE(ad7380_scan_type_##bits),\
144 #define DEFINE_AD7380_2_CHANNEL(name, bits, diff) \
145 static const struct iio_chan_spec name[] = { \
146 AD7380_CHANNEL(0, bits, diff), \
147 AD7380_CHANNEL(1, bits, diff), \
148 IIO_CHAN_SOFT_TIMESTAMP(2), \
151 #define DEFINE_AD7380_4_CHANNEL(name, bits, diff) \
152 static const struct iio_chan_spec name[] = { \
153 AD7380_CHANNEL(0, bits, diff), \
154 AD7380_CHANNEL(1, bits, diff), \
155 AD7380_CHANNEL(2, bits, diff), \
156 AD7380_CHANNEL(3, bits, diff), \
157 IIO_CHAN_SOFT_TIMESTAMP(4), \
160 /* fully differential */
161 DEFINE_AD7380_2_CHANNEL(ad7380_channels, 16, 1);
162 DEFINE_AD7380_2_CHANNEL(ad7381_channels, 14, 1);
163 DEFINE_AD7380_4_CHANNEL(ad7380_4_channels, 16, 1);
164 DEFINE_AD7380_4_CHANNEL(ad7381_4_channels, 14, 1);
165 /* pseudo differential */
166 DEFINE_AD7380_2_CHANNEL(ad7383_channels, 16, 0);
167 DEFINE_AD7380_2_CHANNEL(ad7384_channels, 14, 0);
168 DEFINE_AD7380_4_CHANNEL(ad7383_4_channels, 16, 0);
169 DEFINE_AD7380_4_CHANNEL(ad7384_4_channels, 14, 0);
171 static const char * const ad7380_2_channel_vcm_supplies[] = {
175 static const char * const ad7380_4_channel_vcm_supplies[] = {
176 "aina", "ainb", "ainc", "aind",
179 /* Since this is simultaneous sampling, we don't allow individual channels. */
180 static const unsigned long ad7380_2_channel_scan_masks[] = {
185 static const unsigned long ad7380_4_channel_scan_masks[] = {
190 static const struct ad7380_timing_specs ad7380_timing = {
194 static const struct ad7380_timing_specs ad7380_4_timing = {
199 * Available oversampling ratios. The indices correspond with the bit value
200 * expected by the chip. The available ratios depend on the averaging mode,
201 * only normal averaging is supported for now.
203 static const int ad7380_oversampling_ratios[] = {
207 static const struct ad7380_chip_info ad7380_chip_info = {
209 .channels = ad7380_channels,
210 .num_channels = ARRAY_SIZE(ad7380_channels),
211 .available_scan_masks = ad7380_2_channel_scan_masks,
212 .timing_specs = &ad7380_timing,
215 static const struct ad7380_chip_info ad7381_chip_info = {
217 .channels = ad7381_channels,
218 .num_channels = ARRAY_SIZE(ad7381_channels),
219 .available_scan_masks = ad7380_2_channel_scan_masks,
220 .timing_specs = &ad7380_timing,
223 static const struct ad7380_chip_info ad7383_chip_info = {
225 .channels = ad7383_channels,
226 .num_channels = ARRAY_SIZE(ad7383_channels),
227 .vcm_supplies = ad7380_2_channel_vcm_supplies,
228 .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
229 .available_scan_masks = ad7380_2_channel_scan_masks,
230 .timing_specs = &ad7380_timing,
233 static const struct ad7380_chip_info ad7384_chip_info = {
235 .channels = ad7384_channels,
236 .num_channels = ARRAY_SIZE(ad7384_channels),
237 .vcm_supplies = ad7380_2_channel_vcm_supplies,
238 .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
239 .available_scan_masks = ad7380_2_channel_scan_masks,
240 .timing_specs = &ad7380_timing,
243 static const struct ad7380_chip_info ad7380_4_chip_info = {
245 .channels = ad7380_4_channels,
246 .num_channels = ARRAY_SIZE(ad7380_4_channels),
247 .available_scan_masks = ad7380_4_channel_scan_masks,
248 .timing_specs = &ad7380_4_timing,
251 static const struct ad7380_chip_info ad7381_4_chip_info = {
253 .channels = ad7381_4_channels,
254 .num_channels = ARRAY_SIZE(ad7381_4_channels),
255 .available_scan_masks = ad7380_4_channel_scan_masks,
256 .timing_specs = &ad7380_4_timing,
259 static const struct ad7380_chip_info ad7383_4_chip_info = {
261 .channels = ad7383_4_channels,
262 .num_channels = ARRAY_SIZE(ad7383_4_channels),
263 .vcm_supplies = ad7380_4_channel_vcm_supplies,
264 .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
265 .available_scan_masks = ad7380_4_channel_scan_masks,
266 .timing_specs = &ad7380_4_timing,
269 static const struct ad7380_chip_info ad7384_4_chip_info = {
271 .channels = ad7384_4_channels,
272 .num_channels = ARRAY_SIZE(ad7384_4_channels),
273 .vcm_supplies = ad7380_4_channel_vcm_supplies,
274 .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
275 .available_scan_masks = ad7380_4_channel_scan_masks,
276 .timing_specs = &ad7380_4_timing,
279 struct ad7380_state {
280 const struct ad7380_chip_info *chip_info;
281 struct spi_device *spi;
282 struct regmap *regmap;
283 unsigned int oversampling_ratio;
284 bool resolution_boost_enabled;
285 unsigned int vref_mv;
286 unsigned int vcm_mv[MAX_NUM_CHANNELS];
287 /* xfers, message an buffer for reading sample data */
288 struct spi_transfer xfer[2];
289 struct spi_message msg;
291 * DMA (thus cache coherency maintenance) requires the transfer buffers
292 * to live in their own cache lines.
294 * Make the buffer large enough for MAX_NUM_CHANNELS 32-bit samples and
295 * one 64-bit aligned 64-bit timestamp.
297 u8 scan_data[ALIGN(MAX_NUM_CHANNELS * sizeof(u32), sizeof(s64))
298 + sizeof(s64)] __aligned(IIO_DMA_MINALIGN);
299 /* buffers for reading/writing registers */
304 static int ad7380_regmap_reg_write(void *context, unsigned int reg,
307 struct ad7380_state *st = context;
308 struct spi_transfer xfer = {
309 .speed_hz = AD7380_REG_WR_SPEED_HZ,
315 st->tx = FIELD_PREP(AD7380_REG_WR, 1) |
316 FIELD_PREP(AD7380_REG_REGADDR, reg) |
317 FIELD_PREP(AD7380_REG_DATA, val);
319 return spi_sync_transfer(st->spi, &xfer, 1);
322 static int ad7380_regmap_reg_read(void *context, unsigned int reg,
325 struct ad7380_state *st = context;
326 struct spi_transfer xfers[] = {
328 .speed_hz = AD7380_REG_WR_SPEED_HZ,
334 .value = st->chip_info->timing_specs->t_csh_ns,
335 .unit = SPI_DELAY_UNIT_NSECS,
338 .speed_hz = AD7380_REG_WR_SPEED_HZ,
346 st->tx = FIELD_PREP(AD7380_REG_WR, 0) |
347 FIELD_PREP(AD7380_REG_REGADDR, reg) |
348 FIELD_PREP(AD7380_REG_DATA, 0);
350 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
354 *val = FIELD_GET(AD7380_REG_DATA, st->rx);
359 static const struct regmap_config ad7380_regmap_config = {
362 .reg_read = ad7380_regmap_reg_read,
363 .reg_write = ad7380_regmap_reg_write,
364 .max_register = AD7380_REG_ADDR_ALERT_HIGH_TH,
368 static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
369 u32 writeval, u32 *readval)
371 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
372 struct ad7380_state *st = iio_priv(indio_dev);
375 return regmap_read(st->regmap, reg, readval);
377 return regmap_write(st->regmap, reg, writeval);
383 * ad7380_update_xfers - update the SPI transfers base on the current scan type
384 * @st: device instance specific state
385 * @scan_type: current scan type
387 static void ad7380_update_xfers(struct ad7380_state *st,
388 const struct iio_scan_type *scan_type)
391 * First xfer only triggers conversion and has to be long enough for
392 * all conversions to complete, which can be multiple conversion in the
393 * case of oversampling. Technically T_CONVERT_X_NS is lower for some
394 * chips, but we use the maximum value for simplicity for now.
396 if (st->oversampling_ratio > 1)
397 st->xfer[0].delay.value = T_CONVERT_0_NS + T_CONVERT_X_NS *
398 (st->oversampling_ratio - 1);
400 st->xfer[0].delay.value = T_CONVERT_NS;
402 st->xfer[0].delay.unit = SPI_DELAY_UNIT_NSECS;
405 * Second xfer reads all channels. Data size depends on if resolution
406 * boost is enabled or not.
408 st->xfer[1].bits_per_word = scan_type->realbits;
409 st->xfer[1].len = BITS_TO_BYTES(scan_type->storagebits) *
410 (st->chip_info->num_channels - 1);
413 static int ad7380_triggered_buffer_preenable(struct iio_dev *indio_dev)
415 struct ad7380_state *st = iio_priv(indio_dev);
416 const struct iio_scan_type *scan_type;
419 * Currently, we always read all channels at the same time. The scan_type
420 * is the same for all channels, so we just pass the first channel.
422 scan_type = iio_get_current_scan_type(indio_dev, &indio_dev->channels[0]);
423 if (IS_ERR(scan_type))
424 return PTR_ERR(scan_type);
426 ad7380_update_xfers(st, scan_type);
428 return spi_optimize_message(st->spi, &st->msg);
431 static int ad7380_triggered_buffer_postdisable(struct iio_dev *indio_dev)
433 struct ad7380_state *st = iio_priv(indio_dev);
435 spi_unoptimize_message(&st->msg);
440 static const struct iio_buffer_setup_ops ad7380_buffer_setup_ops = {
441 .preenable = ad7380_triggered_buffer_preenable,
442 .postdisable = ad7380_triggered_buffer_postdisable,
445 static irqreturn_t ad7380_trigger_handler(int irq, void *p)
447 struct iio_poll_func *pf = p;
448 struct iio_dev *indio_dev = pf->indio_dev;
449 struct ad7380_state *st = iio_priv(indio_dev);
452 ret = spi_sync(st->spi, &st->msg);
456 iio_push_to_buffers_with_timestamp(indio_dev, &st->scan_data,
460 iio_trigger_notify_done(indio_dev->trig);
465 static int ad7380_read_direct(struct ad7380_state *st, unsigned int scan_index,
466 const struct iio_scan_type *scan_type, int *val)
470 ad7380_update_xfers(st, scan_type);
472 ret = spi_sync(st->spi, &st->msg);
476 if (scan_type->storagebits > 16)
477 *val = sign_extend32(*(u32 *)(st->scan_data + 4 * scan_index),
478 scan_type->realbits - 1);
480 *val = sign_extend32(*(u16 *)(st->scan_data + 2 * scan_index),
481 scan_type->realbits - 1);
486 static int ad7380_read_raw(struct iio_dev *indio_dev,
487 struct iio_chan_spec const *chan,
488 int *val, int *val2, long info)
490 struct ad7380_state *st = iio_priv(indio_dev);
491 const struct iio_scan_type *scan_type;
493 scan_type = iio_get_current_scan_type(indio_dev, chan);
495 if (IS_ERR(scan_type))
496 return PTR_ERR(scan_type);
499 case IIO_CHAN_INFO_RAW:
500 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
501 return ad7380_read_direct(st, chan->scan_index,
505 case IIO_CHAN_INFO_SCALE:
507 * According to the datasheet, the LSB size is:
508 * * (2 × VREF) / 2^N, for differential chips
509 * * VREF / 2^N, for pseudo-differential chips
510 * where N is the ADC resolution (i.e realbits)
513 *val2 = scan_type->realbits - chan->differential;
515 return IIO_VAL_FRACTIONAL_LOG2;
516 case IIO_CHAN_INFO_OFFSET:
518 * According to IIO ABI, offset is applied before scale,
519 * so offset is: vcm_mv / scale
521 *val = st->vcm_mv[chan->channel] * (1 << scan_type->realbits)
525 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
526 *val = st->oversampling_ratio;
534 static int ad7380_read_avail(struct iio_dev *indio_dev,
535 struct iio_chan_spec const *chan,
536 const int **vals, int *type, int *length,
540 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
541 *vals = ad7380_oversampling_ratios;
542 *length = ARRAY_SIZE(ad7380_oversampling_ratios);
545 return IIO_AVAIL_LIST;
552 * ad7380_osr_to_regval - convert ratio to OSR register value
553 * @ratio: ratio to check
555 * Check if ratio is present in the list of available ratios and return the
556 * corresponding value that needs to be written to the register to select that
559 * Returns: register value (0 to 7) or -EINVAL if there is not an exact match
561 static int ad7380_osr_to_regval(int ratio)
565 for (i = 0; i < ARRAY_SIZE(ad7380_oversampling_ratios); i++) {
566 if (ratio == ad7380_oversampling_ratios[i])
573 static int ad7380_write_raw(struct iio_dev *indio_dev,
574 struct iio_chan_spec const *chan, int val,
577 struct ad7380_state *st = iio_priv(indio_dev);
581 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
582 osr = ad7380_osr_to_regval(val);
586 /* always enable resolution boost when oversampling is enabled */
587 boost = osr > 0 ? 1 : 0;
589 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
590 ret = regmap_update_bits(st->regmap,
591 AD7380_REG_ADDR_CONFIG1,
592 AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
593 FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
594 FIELD_PREP(AD7380_CONFIG1_RES, boost));
599 st->oversampling_ratio = val;
600 st->resolution_boost_enabled = boost;
603 * Perform a soft reset. This will flush the oversampling
604 * block and FIFO but will maintain the content of the
605 * configurable registers.
607 return regmap_update_bits(st->regmap,
608 AD7380_REG_ADDR_CONFIG2,
609 AD7380_CONFIG2_RESET,
610 FIELD_PREP(AD7380_CONFIG2_RESET,
611 AD7380_CONFIG2_RESET_SOFT));
619 static int ad7380_get_current_scan_type(const struct iio_dev *indio_dev,
620 const struct iio_chan_spec *chan)
622 struct ad7380_state *st = iio_priv(indio_dev);
624 return st->resolution_boost_enabled ? AD7380_SCAN_TYPE_RESOLUTION_BOOST
625 : AD7380_SCAN_TYPE_NORMAL;
628 static const struct iio_info ad7380_info = {
629 .read_raw = &ad7380_read_raw,
630 .read_avail = &ad7380_read_avail,
631 .write_raw = &ad7380_write_raw,
632 .get_current_scan_type = &ad7380_get_current_scan_type,
633 .debugfs_reg_access = &ad7380_debugfs_reg_access,
636 static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
640 /* perform hard reset */
641 ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
642 AD7380_CONFIG2_RESET,
643 FIELD_PREP(AD7380_CONFIG2_RESET,
644 AD7380_CONFIG2_RESET_HARD));
648 /* select internal or external reference voltage */
649 ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
650 AD7380_CONFIG1_REFSEL,
651 FIELD_PREP(AD7380_CONFIG1_REFSEL,
656 /* This is the default value after reset. */
657 st->oversampling_ratio = 1;
659 /* SPI 1-wire mode */
660 return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
662 FIELD_PREP(AD7380_CONFIG2_SDO, 1));
665 static void ad7380_regulator_disable(void *p)
667 regulator_disable(p);
670 static int ad7380_probe(struct spi_device *spi)
672 struct iio_dev *indio_dev;
673 struct ad7380_state *st;
674 struct regulator *vref;
677 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
681 st = iio_priv(indio_dev);
683 st->chip_info = spi_get_device_match_data(spi);
685 return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n");
687 vref = devm_regulator_get_optional(&spi->dev, "refio");
689 if (PTR_ERR(vref) != -ENODEV)
690 return dev_err_probe(&spi->dev, PTR_ERR(vref),
691 "Failed to get refio regulator\n");
697 * If there is no REFIO supply, then it means that we are using
698 * the internal 2.5V reference, otherwise REFIO is reference voltage.
701 ret = regulator_enable(vref);
705 ret = devm_add_action_or_reset(&spi->dev,
706 ad7380_regulator_disable, vref);
710 ret = regulator_get_voltage(vref);
714 st->vref_mv = ret / 1000;
716 st->vref_mv = AD7380_INTERNAL_REF_MV;
719 if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
720 return dev_err_probe(&spi->dev, -EINVAL,
721 "invalid number of VCM supplies\n");
724 * pseudo-differential chips have common mode supplies for the negative
727 for (i = 0; i < st->chip_info->num_vcm_supplies; i++) {
728 struct regulator *vcm;
730 vcm = devm_regulator_get(&spi->dev,
731 st->chip_info->vcm_supplies[i]);
733 return dev_err_probe(&spi->dev, PTR_ERR(vcm),
734 "Failed to get %s regulator\n",
735 st->chip_info->vcm_supplies[i]);
737 ret = regulator_enable(vcm);
741 ret = devm_add_action_or_reset(&spi->dev,
742 ad7380_regulator_disable, vcm);
746 ret = regulator_get_voltage(vcm);
750 st->vcm_mv[i] = ret / 1000;
753 st->regmap = devm_regmap_init(&spi->dev, NULL, st, &ad7380_regmap_config);
754 if (IS_ERR(st->regmap))
755 return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
756 "failed to allocate register map\n");
759 * Setting up a low latency read for getting sample data. Used for both
760 * direct read an triggered buffer. Additional fields will be set up in
761 * ad7380_update_xfers() based on the current state of the driver at the
765 /* toggle CS (no data xfer) to trigger a conversion */
766 st->xfer[0].cs_change = 1;
767 st->xfer[0].cs_change_delay.value = st->chip_info->timing_specs->t_csh_ns;
768 st->xfer[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
770 /* then do a second xfer to read the data */
771 st->xfer[1].rx_buf = st->scan_data;
773 spi_message_init_with_transfers(&st->msg, st->xfer, ARRAY_SIZE(st->xfer));
775 indio_dev->channels = st->chip_info->channels;
776 indio_dev->num_channels = st->chip_info->num_channels;
777 indio_dev->name = st->chip_info->name;
778 indio_dev->info = &ad7380_info;
779 indio_dev->modes = INDIO_DIRECT_MODE;
780 indio_dev->available_scan_masks = st->chip_info->available_scan_masks;
782 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
783 iio_pollfunc_store_time,
784 ad7380_trigger_handler,
785 &ad7380_buffer_setup_ops);
789 ret = ad7380_init(st, vref);
793 return devm_iio_device_register(&spi->dev, indio_dev);
796 static const struct of_device_id ad7380_of_match_table[] = {
797 { .compatible = "adi,ad7380", .data = &ad7380_chip_info },
798 { .compatible = "adi,ad7381", .data = &ad7381_chip_info },
799 { .compatible = "adi,ad7383", .data = &ad7383_chip_info },
800 { .compatible = "adi,ad7384", .data = &ad7384_chip_info },
801 { .compatible = "adi,ad7380-4", .data = &ad7380_4_chip_info },
802 { .compatible = "adi,ad7381-4", .data = &ad7381_4_chip_info },
803 { .compatible = "adi,ad7383-4", .data = &ad7383_4_chip_info },
804 { .compatible = "adi,ad7384-4", .data = &ad7384_4_chip_info },
808 static const struct spi_device_id ad7380_id_table[] = {
809 { "ad7380", (kernel_ulong_t)&ad7380_chip_info },
810 { "ad7381", (kernel_ulong_t)&ad7381_chip_info },
811 { "ad7383", (kernel_ulong_t)&ad7383_chip_info },
812 { "ad7384", (kernel_ulong_t)&ad7384_chip_info },
813 { "ad7380-4", (kernel_ulong_t)&ad7380_4_chip_info },
814 { "ad7381-4", (kernel_ulong_t)&ad7381_4_chip_info },
815 { "ad7383-4", (kernel_ulong_t)&ad7383_4_chip_info },
816 { "ad7384-4", (kernel_ulong_t)&ad7384_4_chip_info },
819 MODULE_DEVICE_TABLE(spi, ad7380_id_table);
821 static struct spi_driver ad7380_driver = {
824 .of_match_table = ad7380_of_match_table,
826 .probe = ad7380_probe,
827 .id_table = ad7380_id_table,
829 module_spi_driver(ad7380_driver);
832 MODULE_DESCRIPTION("Analog Devices AD738x ADC driver");
833 MODULE_LICENSE("GPL");