forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/iio/dac/ad5686.c
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0+
1
+// SPDX-License-Identifier: GPL-2.0
22 /*
33 * AD5686R, AD5685R, AD5684R Digital to analog converters driver
44 *
....@@ -71,7 +71,7 @@
7171 int ret;
7272 struct ad5686_state *st = iio_priv(indio_dev);
7373 unsigned int val, ref_bit_msk;
74
- u8 shift;
74
+ u8 shift, address = 0;
7575
7676 ret = strtobool(buf, &readin);
7777 if (ret)
....@@ -83,6 +83,10 @@
8383 st->pwr_down_mask &= ~(0x3 << (chan->channel * 2));
8484
8585 switch (st->chip_info->regmap_type) {
86
+ case AD5310_REGMAP:
87
+ shift = 9;
88
+ ref_bit_msk = AD5310_REF_BIT_MSK;
89
+ break;
8690 case AD5683_REGMAP:
8791 shift = 13;
8892 ref_bit_msk = AD5683_REF_BIT_MSK;
....@@ -90,6 +94,9 @@
9094 case AD5686_REGMAP:
9195 shift = 0;
9296 ref_bit_msk = 0;
97
+ /* AD5674R/AD5679R have 16 channels and 2 powerdown registers */
98
+ if (chan->channel > 0x7)
99
+ address = 0x8;
93100 break;
94101 case AD5693_REGMAP:
95102 shift = 13;
....@@ -103,7 +110,8 @@
103110 if (!st->use_internal_vref)
104111 val |= ref_bit_msk;
105112
106
- ret = st->write(st, AD5686_CMD_POWERDOWN_DAC, 0, val);
113
+ ret = st->write(st, AD5686_CMD_POWERDOWN_DAC,
114
+ address, val >> (address * 2));
107115
108116 return ret ? ret : len;
109117 }
....@@ -119,9 +127,9 @@
119127
120128 switch (m) {
121129 case IIO_CHAN_INFO_RAW:
122
- mutex_lock(&indio_dev->mlock);
130
+ mutex_lock(&st->lock);
123131 ret = st->read(st, chan->address);
124
- mutex_unlock(&indio_dev->mlock);
132
+ mutex_unlock(&st->lock);
125133 if (ret < 0)
126134 return ret;
127135 *val = (ret >> chan->scan_type.shift) &
....@@ -149,12 +157,12 @@
149157 if (val > (1 << chan->scan_type.realbits) || val < 0)
150158 return -EINVAL;
151159
152
- mutex_lock(&indio_dev->mlock);
160
+ mutex_lock(&st->lock);
153161 ret = st->write(st,
154162 AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
155163 chan->address,
156164 val << chan->scan_type.shift);
157
- mutex_unlock(&indio_dev->mlock);
165
+ mutex_unlock(&st->lock);
158166 break;
159167 default:
160168 ret = -EINVAL;
....@@ -198,12 +206,12 @@
198206 }
199207
200208 #define DECLARE_AD5693_CHANNELS(name, bits, _shift) \
201
-static struct iio_chan_spec name[] = { \
209
+static const struct iio_chan_spec name[] = { \
202210 AD5868_CHANNEL(0, 0, bits, _shift), \
203211 }
204212
205213 #define DECLARE_AD5686_CHANNELS(name, bits, _shift) \
206
-static struct iio_chan_spec name[] = { \
214
+static const struct iio_chan_spec name[] = { \
207215 AD5868_CHANNEL(0, 1, bits, _shift), \
208216 AD5868_CHANNEL(1, 2, bits, _shift), \
209217 AD5868_CHANNEL(2, 4, bits, _shift), \
....@@ -211,7 +219,7 @@
211219 }
212220
213221 #define DECLARE_AD5676_CHANNELS(name, bits, _shift) \
214
-static struct iio_chan_spec name[] = { \
222
+static const struct iio_chan_spec name[] = { \
215223 AD5868_CHANNEL(0, 0, bits, _shift), \
216224 AD5868_CHANNEL(1, 1, bits, _shift), \
217225 AD5868_CHANNEL(2, 2, bits, _shift), \
....@@ -222,9 +230,32 @@
222230 AD5868_CHANNEL(7, 7, bits, _shift), \
223231 }
224232
233
+#define DECLARE_AD5679_CHANNELS(name, bits, _shift) \
234
+static const struct iio_chan_spec name[] = { \
235
+ AD5868_CHANNEL(0, 0, bits, _shift), \
236
+ AD5868_CHANNEL(1, 1, bits, _shift), \
237
+ AD5868_CHANNEL(2, 2, bits, _shift), \
238
+ AD5868_CHANNEL(3, 3, bits, _shift), \
239
+ AD5868_CHANNEL(4, 4, bits, _shift), \
240
+ AD5868_CHANNEL(5, 5, bits, _shift), \
241
+ AD5868_CHANNEL(6, 6, bits, _shift), \
242
+ AD5868_CHANNEL(7, 7, bits, _shift), \
243
+ AD5868_CHANNEL(8, 8, bits, _shift), \
244
+ AD5868_CHANNEL(9, 9, bits, _shift), \
245
+ AD5868_CHANNEL(10, 10, bits, _shift), \
246
+ AD5868_CHANNEL(11, 11, bits, _shift), \
247
+ AD5868_CHANNEL(12, 12, bits, _shift), \
248
+ AD5868_CHANNEL(13, 13, bits, _shift), \
249
+ AD5868_CHANNEL(14, 14, bits, _shift), \
250
+ AD5868_CHANNEL(15, 15, bits, _shift), \
251
+}
252
+
253
+DECLARE_AD5693_CHANNELS(ad5310r_channels, 10, 2);
225254 DECLARE_AD5693_CHANNELS(ad5311r_channels, 10, 6);
226255 DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
256
+DECLARE_AD5679_CHANNELS(ad5674r_channels, 12, 4);
227257 DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
258
+DECLARE_AD5679_CHANNELS(ad5679r_channels, 16, 0);
228259 DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
229260 DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
230261 DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
....@@ -233,6 +264,12 @@
233264 DECLARE_AD5693_CHANNELS(ad5691r_channels, 12, 4);
234265
235266 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
267
+ [ID_AD5310R] = {
268
+ .channels = ad5310r_channels,
269
+ .int_vref_mv = 2500,
270
+ .num_channels = 1,
271
+ .regmap_type = AD5310_REGMAP,
272
+ },
236273 [ID_AD5311R] = {
237274 .channels = ad5311r_channels,
238275 .int_vref_mv = 2500,
....@@ -251,6 +288,12 @@
251288 .num_channels = 8,
252289 .regmap_type = AD5686_REGMAP,
253290 },
291
+ [ID_AD5674R] = {
292
+ .channels = ad5674r_channels,
293
+ .int_vref_mv = 2500,
294
+ .num_channels = 16,
295
+ .regmap_type = AD5686_REGMAP,
296
+ },
254297 [ID_AD5675R] = {
255298 .channels = ad5676_channels,
256299 .int_vref_mv = 2500,
....@@ -266,6 +309,12 @@
266309 .channels = ad5676_channels,
267310 .int_vref_mv = 2500,
268311 .num_channels = 8,
312
+ .regmap_type = AD5686_REGMAP,
313
+ },
314
+ [ID_AD5679R] = {
315
+ .channels = ad5679r_channels,
316
+ .int_vref_mv = 2500,
317
+ .num_channels = 16,
269318 .regmap_type = AD5686_REGMAP,
270319 },
271320 [ID_AD5681R] = {
....@@ -412,14 +461,20 @@
412461 for (i = 0; i < st->chip_info->num_channels; i++)
413462 st->pwr_down_mode |= (0x01 << (i * 2));
414463
415
- indio_dev->dev.parent = dev;
416464 indio_dev->name = name;
417465 indio_dev->info = &ad5686_info;
418466 indio_dev->modes = INDIO_DIRECT_MODE;
419467 indio_dev->channels = st->chip_info->channels;
420468 indio_dev->num_channels = st->chip_info->num_channels;
421469
470
+ mutex_init(&st->lock);
471
+
422472 switch (st->chip_info->regmap_type) {
473
+ case AD5310_REGMAP:
474
+ cmd = AD5686_CMD_CONTROL_REG;
475
+ ref_bit_msk = AD5310_REF_BIT_MSK;
476
+ st->use_internal_vref = !voltage_uv;
477
+ break;
423478 case AD5683_REGMAP:
424479 cmd = AD5686_CMD_CONTROL_REG;
425480 ref_bit_msk = AD5683_REF_BIT_MSK;
....@@ -471,6 +526,6 @@
471526 }
472527 EXPORT_SYMBOL_GPL(ad5686_remove);
473528
474
-MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
529
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
475530 MODULE_DESCRIPTION("Analog Devices AD5686/85/84 DAC");
476531 MODULE_LICENSE("GPL v2");