forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/dac/ad5764.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Analog devices AD5764, AD5764R, AD5744, AD5744R quad-channel
34 * Digital to Analog Converters driver
45 *
56 * Copyright 2011 Analog Devices Inc.
6
- *
7
- * Licensed under the GPL-2.
87 */
98
109 #include <linux/device.h>
....@@ -34,9 +33,8 @@
3433 * struct ad5764_chip_info - chip specific information
3534 * @int_vref: Value of the internal reference voltage in uV - 0 if external
3635 * reference voltage is used
37
- * @channel channel specification
36
+ * @channels: channel specification
3837 */
39
-
4038 struct ad5764_chip_info {
4139 unsigned long int_vref;
4240 const struct iio_chan_spec *channels;
....@@ -47,6 +45,7 @@
4745 * @spi: spi_device
4846 * @chip_info: chip info
4947 * @vref_reg: vref supply regulators
48
+ * @lock: lock to protect the data buffer during SPI ops
5049 * @data: spi transfer buffers
5150 */
5251
....@@ -54,6 +53,7 @@
5453 struct spi_device *spi;
5554 const struct ad5764_chip_info *chip_info;
5655 struct regulator_bulk_data vref_reg[2];
56
+ struct mutex lock;
5757
5858 /*
5959 * DMA (thus cache coherency maintenance) requires the
....@@ -127,11 +127,11 @@
127127 struct ad5764_state *st = iio_priv(indio_dev);
128128 int ret;
129129
130
- mutex_lock(&indio_dev->mlock);
130
+ mutex_lock(&st->lock);
131131 st->data[0].d32 = cpu_to_be32((reg << 16) | val);
132132
133133 ret = spi_write(st->spi, &st->data[0].d8[1], 3);
134
- mutex_unlock(&indio_dev->mlock);
134
+ mutex_unlock(&st->lock);
135135
136136 return ret;
137137 }
....@@ -152,7 +152,7 @@
152152 },
153153 };
154154
155
- mutex_lock(&indio_dev->mlock);
155
+ mutex_lock(&st->lock);
156156
157157 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
158158
....@@ -160,7 +160,7 @@
160160 if (ret >= 0)
161161 *val = be32_to_cpu(st->data[1].d32) & 0xffff;
162162
163
- mutex_unlock(&indio_dev->mlock);
163
+ mutex_unlock(&st->lock);
164164
165165 return ret;
166166 }
....@@ -289,13 +289,14 @@
289289 st->spi = spi;
290290 st->chip_info = &ad5764_chip_infos[type];
291291
292
- indio_dev->dev.parent = &spi->dev;
293292 indio_dev->name = spi_get_device_id(spi)->name;
294293 indio_dev->info = &ad5764_info;
295294 indio_dev->modes = INDIO_DIRECT_MODE;
296295 indio_dev->num_channels = AD5764_NUM_CHANNELS;
297296 indio_dev->channels = st->chip_info->channels;
298297
298
+ mutex_init(&st->lock);
299
+
299300 if (st->chip_info->int_vref == 0) {
300301 st->vref_reg[0].supply = "vrefAB";
301302 st->vref_reg[1].supply = "vrefCD";