forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/adc/ad7887.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AD7887 SPI ADC driver
34 *
45 * Copyright 2010-2011 Analog Devices Inc.
5
- *
6
- * Licensed under the GPL-2.
76 */
87
98 #include <linux/device.h>
....@@ -44,11 +43,17 @@
4443 /**
4544 * struct ad7887_chip_info - chip specifc information
4645 * @int_vref_mv: the internal reference voltage
47
- * @channel: channel specification
46
+ * @channels: channels specification
47
+ * @num_channels: number of channels
48
+ * @dual_channels: channels specification in dual mode
49
+ * @num_dual_channels: number of channels in dual mode
4850 */
4951 struct ad7887_chip_info {
5052 u16 int_vref_mv;
51
- struct iio_chan_spec channel[3];
53
+ const struct iio_chan_spec *channels;
54
+ unsigned int num_channels;
55
+ const struct iio_chan_spec *dual_channels;
56
+ unsigned int num_dual_channels;
5257 };
5358
5459 struct ad7887_state {
....@@ -104,7 +109,7 @@
104109 return spi_sync(st->spi, &st->msg[AD7887_CH0]);
105110 }
106111
107
-/**
112
+/*
108113 * ad7887_trigger_handler() bh of trigger launched polling to ring buffer
109114 *
110115 * Currently there is no option in this driver to disable the saving of
....@@ -131,8 +136,6 @@
131136
132137 static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = {
133138 .preenable = &ad7887_ring_preenable,
134
- .postenable = &iio_triggered_buffer_postenable,
135
- .predisable = &iio_triggered_buffer_predisable,
136139 .postdisable = &ad7887_ring_postdisable,
137140 };
138141
....@@ -184,45 +187,43 @@
184187 return -EINVAL;
185188 }
186189
190
+#define AD7887_CHANNEL(x) { \
191
+ .type = IIO_VOLTAGE, \
192
+ .indexed = 1, \
193
+ .channel = (x), \
194
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
195
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
196
+ .address = (x), \
197
+ .scan_index = (x), \
198
+ .scan_type = { \
199
+ .sign = 'u', \
200
+ .realbits = 12, \
201
+ .storagebits = 16, \
202
+ .shift = 0, \
203
+ .endianness = IIO_BE, \
204
+ }, \
205
+}
206
+
207
+static const struct iio_chan_spec ad7887_channels[] = {
208
+ AD7887_CHANNEL(0),
209
+ IIO_CHAN_SOFT_TIMESTAMP(1),
210
+};
211
+
212
+static const struct iio_chan_spec ad7887_dual_channels[] = {
213
+ AD7887_CHANNEL(0),
214
+ AD7887_CHANNEL(1),
215
+ IIO_CHAN_SOFT_TIMESTAMP(2),
216
+};
187217
188218 static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
189219 /*
190220 * More devices added in future
191221 */
192222 [ID_AD7887] = {
193
- .channel[0] = {
194
- .type = IIO_VOLTAGE,
195
- .indexed = 1,
196
- .channel = 1,
197
- .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
198
- .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
199
- .address = 1,
200
- .scan_index = 1,
201
- .scan_type = {
202
- .sign = 'u',
203
- .realbits = 12,
204
- .storagebits = 16,
205
- .shift = 0,
206
- .endianness = IIO_BE,
207
- },
208
- },
209
- .channel[1] = {
210
- .type = IIO_VOLTAGE,
211
- .indexed = 1,
212
- .channel = 0,
213
- .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
214
- .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
215
- .address = 0,
216
- .scan_index = 0,
217
- .scan_type = {
218
- .sign = 'u',
219
- .realbits = 12,
220
- .storagebits = 16,
221
- .shift = 0,
222
- .endianness = IIO_BE,
223
- },
224
- },
225
- .channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
223
+ .channels = ad7887_channels,
224
+ .num_channels = ARRAY_SIZE(ad7887_channels),
225
+ .dual_channels = ad7887_dual_channels,
226
+ .num_dual_channels = ARRAY_SIZE(ad7887_dual_channels),
226227 .int_vref_mv = 2500,
227228 },
228229 };
....@@ -261,9 +262,6 @@
261262 spi_set_drvdata(spi, indio_dev);
262263 st->spi = spi;
263264
264
- /* Estabilish that the iio_dev is a child of the spi device */
265
- indio_dev->dev.parent = &spi->dev;
266
- indio_dev->dev.of_node = spi->dev.of_node;
267265 indio_dev->name = spi_get_device_id(spi)->name;
268266 indio_dev->info = &ad7887_info;
269267 indio_dev->modes = INDIO_DIRECT_MODE;
....@@ -307,11 +305,11 @@
307305 spi_message_init(&st->msg[AD7887_CH1]);
308306 spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);
309307
310
- indio_dev->channels = st->chip_info->channel;
311
- indio_dev->num_channels = 3;
308
+ indio_dev->channels = st->chip_info->dual_channels;
309
+ indio_dev->num_channels = st->chip_info->num_dual_channels;
312310 } else {
313
- indio_dev->channels = &st->chip_info->channel[1];
314
- indio_dev->num_channels = 2;
311
+ indio_dev->channels = st->chip_info->channels;
312
+ indio_dev->num_channels = st->chip_info->num_channels;
315313 }
316314
317315 ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
....@@ -362,6 +360,6 @@
362360 };
363361 module_spi_driver(ad7887_driver);
364362
365
-MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
363
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
366364 MODULE_DESCRIPTION("Analog Devices AD7887 ADC");
367365 MODULE_LICENSE("GPL v2");