.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * AD7787/AD7788/AD7789/AD7790/AD7791 SPI ADC driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2012 Analog Devices Inc. |
---|
5 | 6 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
---|
6 | | - * |
---|
7 | | - * Licensed under the GPL-2. |
---|
8 | 7 | */ |
---|
9 | 8 | |
---|
10 | 9 | #include <linux/interrupt.h> |
---|
.. | .. |
---|
65 | 64 | #define AD7791_MODE_SEL_MASK (0x3 << 6) |
---|
66 | 65 | #define AD7791_MODE_SEL(x) ((x) << 6) |
---|
67 | 66 | |
---|
| 67 | +#define __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ |
---|
| 68 | + _storagebits, _shift, _extend_name, _type, _mask_all) \ |
---|
| 69 | + { \ |
---|
| 70 | + .type = (_type), \ |
---|
| 71 | + .differential = (_channel2 == -1 ? 0 : 1), \ |
---|
| 72 | + .indexed = 1, \ |
---|
| 73 | + .channel = (_channel1), \ |
---|
| 74 | + .channel2 = (_channel2), \ |
---|
| 75 | + .address = (_address), \ |
---|
| 76 | + .extend_name = (_extend_name), \ |
---|
| 77 | + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
---|
| 78 | + BIT(IIO_CHAN_INFO_OFFSET), \ |
---|
| 79 | + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
---|
| 80 | + .info_mask_shared_by_all = _mask_all, \ |
---|
| 81 | + .scan_index = (_si), \ |
---|
| 82 | + .scan_type = { \ |
---|
| 83 | + .sign = 'u', \ |
---|
| 84 | + .realbits = (_bits), \ |
---|
| 85 | + .storagebits = (_storagebits), \ |
---|
| 86 | + .shift = (_shift), \ |
---|
| 87 | + .endianness = IIO_BE, \ |
---|
| 88 | + }, \ |
---|
| 89 | + } |
---|
| 90 | + |
---|
| 91 | +#define AD7991_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ |
---|
| 92 | + _storagebits, _shift) \ |
---|
| 93 | + __AD7991_CHANNEL(_si, _channel, _channel, _address, _bits, \ |
---|
| 94 | + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ |
---|
| 95 | + BIT(IIO_CHAN_INFO_SAMP_FREQ)) |
---|
| 96 | + |
---|
| 97 | +#define AD7991_CHANNEL(_si, _channel, _address, _bits, \ |
---|
| 98 | + _storagebits, _shift) \ |
---|
| 99 | + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ |
---|
| 100 | + _storagebits, _shift, NULL, IIO_VOLTAGE, \ |
---|
| 101 | + BIT(IIO_CHAN_INFO_SAMP_FREQ)) |
---|
| 102 | + |
---|
| 103 | +#define AD7991_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ |
---|
| 104 | + _storagebits, _shift) \ |
---|
| 105 | + __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ |
---|
| 106 | + _storagebits, _shift, NULL, IIO_VOLTAGE, \ |
---|
| 107 | + BIT(IIO_CHAN_INFO_SAMP_FREQ)) |
---|
| 108 | + |
---|
| 109 | +#define AD7991_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ |
---|
| 110 | + _shift) \ |
---|
| 111 | + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ |
---|
| 112 | + _storagebits, _shift, "supply", IIO_VOLTAGE, \ |
---|
| 113 | + BIT(IIO_CHAN_INFO_SAMP_FREQ)) |
---|
| 114 | + |
---|
68 | 115 | #define DECLARE_AD7787_CHANNELS(name, bits, storagebits) \ |
---|
69 | 116 | const struct iio_chan_spec name[] = { \ |
---|
70 | | - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ |
---|
| 117 | + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ |
---|
71 | 118 | (bits), (storagebits), 0), \ |
---|
72 | | - AD_SD_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ |
---|
73 | | - AD_SD_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ |
---|
| 119 | + AD7991_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ |
---|
| 120 | + AD7991_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ |
---|
74 | 121 | (bits), (storagebits), 0), \ |
---|
75 | | - AD_SD_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ |
---|
| 122 | + AD7991_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ |
---|
76 | 123 | (bits), (storagebits), 0), \ |
---|
77 | 124 | IIO_CHAN_SOFT_TIMESTAMP(4), \ |
---|
78 | 125 | } |
---|
79 | 126 | |
---|
80 | 127 | #define DECLARE_AD7791_CHANNELS(name, bits, storagebits) \ |
---|
81 | 128 | const struct iio_chan_spec name[] = { \ |
---|
82 | | - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ |
---|
| 129 | + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ |
---|
83 | 130 | (bits), (storagebits), 0), \ |
---|
84 | | - AD_SD_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ |
---|
| 131 | + AD7991_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ |
---|
85 | 132 | (bits), (storagebits), 0), \ |
---|
86 | | - AD_SD_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ |
---|
| 133 | + AD7991_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ |
---|
87 | 134 | (bits), (storagebits), 0), \ |
---|
88 | 135 | IIO_CHAN_SOFT_TIMESTAMP(3), \ |
---|
89 | 136 | } |
---|
.. | .. |
---|
206 | 253 | .has_registers = true, |
---|
207 | 254 | .addr_shift = 4, |
---|
208 | 255 | .read_mask = BIT(3), |
---|
| 256 | + .irq_flags = IRQF_TRIGGER_FALLING, |
---|
209 | 257 | }; |
---|
210 | 258 | |
---|
211 | 259 | static int ad7791_read_raw(struct iio_dev *indio_dev, |
---|
.. | .. |
---|
377 | 425 | |
---|
378 | 426 | spi_set_drvdata(spi, indio_dev); |
---|
379 | 427 | |
---|
380 | | - indio_dev->dev.parent = &spi->dev; |
---|
381 | | - indio_dev->dev.of_node = spi->dev.of_node; |
---|
382 | 428 | indio_dev->name = spi_get_device_id(spi)->name; |
---|
383 | 429 | indio_dev->modes = INDIO_DIRECT_MODE; |
---|
384 | 430 | indio_dev->channels = st->info->channels; |
---|
.. | .. |
---|
444 | 490 | module_spi_driver(ad7791_driver); |
---|
445 | 491 | |
---|
446 | 492 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
---|
447 | | -MODULE_DESCRIPTION("Analog Device AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver"); |
---|
| 493 | +MODULE_DESCRIPTION("Analog Devices AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver"); |
---|
448 | 494 | MODULE_LICENSE("GPL v2"); |
---|