forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/dac/ad5421.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AD5421 Digital to analog converters driver
34 *
45 * Copyright 2011 Analog Devices Inc.
5
- *
6
- * Licensed under the GPL-2.
76 */
87
98 #include <linux/device.h>
....@@ -63,12 +62,14 @@
6362 * @current_range: current range which the device is configured for
6463 * @data: spi transfer buffers
6564 * @fault_mask: software masking of events
65
+ * @lock: lock to protect the data buffer during SPI ops
6666 */
6767 struct ad5421_state {
6868 struct spi_device *spi;
6969 unsigned int ctrl;
7070 enum ad5421_current_range current_range;
7171 unsigned int fault_mask;
72
+ struct mutex lock;
7273
7374 /*
7475 * DMA (thus cache coherency maintenance) requires the
....@@ -143,11 +144,12 @@
143144 static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
144145 unsigned int val)
145146 {
147
+ struct ad5421_state *st = iio_priv(indio_dev);
146148 int ret;
147149
148
- mutex_lock(&indio_dev->mlock);
150
+ mutex_lock(&st->lock);
149151 ret = ad5421_write_unlocked(indio_dev, reg, val);
150
- mutex_unlock(&indio_dev->mlock);
152
+ mutex_unlock(&st->lock);
151153
152154 return ret;
153155 }
....@@ -167,7 +169,7 @@
167169 },
168170 };
169171
170
- mutex_lock(&indio_dev->mlock);
172
+ mutex_lock(&st->lock);
171173
172174 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
173175
....@@ -175,7 +177,7 @@
175177 if (ret >= 0)
176178 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
177179
178
- mutex_unlock(&indio_dev->mlock);
180
+ mutex_unlock(&st->lock);
179181
180182 return ret;
181183 }
....@@ -186,14 +188,14 @@
186188 struct ad5421_state *st = iio_priv(indio_dev);
187189 unsigned int ret;
188190
189
- mutex_lock(&indio_dev->mlock);
191
+ mutex_lock(&st->lock);
190192
191193 st->ctrl &= ~clr;
192194 st->ctrl |= set;
193195
194196 ret = ad5421_write_unlocked(indio_dev, AD5421_REG_CTRL, st->ctrl);
195197
196
- mutex_unlock(&indio_dev->mlock);
198
+ mutex_unlock(&st->lock);
197199
198200 return ret;
199201 }
....@@ -401,12 +403,12 @@
401403 return -EINVAL;
402404 }
403405
404
- mutex_lock(&indio_dev->mlock);
406
+ mutex_lock(&st->lock);
405407 if (state)
406408 st->fault_mask |= mask;
407409 else
408410 st->fault_mask &= ~mask;
409
- mutex_unlock(&indio_dev->mlock);
411
+ mutex_unlock(&st->lock);
410412
411413 return 0;
412414 }
....@@ -485,13 +487,14 @@
485487
486488 st->spi = spi;
487489
488
- indio_dev->dev.parent = &spi->dev;
489490 indio_dev->name = "ad5421";
490491 indio_dev->info = &ad5421_info;
491492 indio_dev->modes = INDIO_DIRECT_MODE;
492493 indio_dev->channels = ad5421_channels;
493494 indio_dev->num_channels = ARRAY_SIZE(ad5421_channels);
494495
496
+ mutex_init(&st->lock);
497
+
495498 st->ctrl = AD5421_CTRL_WATCHDOG_DISABLE |
496499 AD5421_CTRL_AUTO_FAULT_READBACK;
497500