hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/iio/dac/ad5761.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter
34 *
45 * Copyright 2016 Qtechnology A/S
5
- * 2016 Ricardo Ribalda <ricardo.ribalda@gmail.com>
6
- *
7
- * Licensed under the GPL-2.
6
+ * 2016 Ricardo Ribalda <ribalda@kernel.org>
87 */
98 #include <linux/kernel.h>
109 #include <linux/module.h>
....@@ -58,11 +57,13 @@
5857 * @use_intref: true when the internal voltage reference is used
5958 * @vref: actual voltage reference in mVolts
6059 * @range: output range mode used
60
+ * @lock: lock to protect the data buffer during SPI ops
6161 * @data: cache aligned spi buffer
6262 */
6363 struct ad5761_state {
6464 struct spi_device *spi;
6565 struct regulator *vref_reg;
66
+ struct mutex lock;
6667
6768 bool use_intref;
6869 int vref;
....@@ -125,9 +126,9 @@
125126 struct ad5761_state *st = iio_priv(indio_dev);
126127 int ret;
127128
128
- mutex_lock(&indio_dev->mlock);
129
+ mutex_lock(&st->lock);
129130 ret = _ad5761_spi_write(st, addr, val);
130
- mutex_unlock(&indio_dev->mlock);
131
+ mutex_unlock(&st->lock);
131132
132133 return ret;
133134 }
....@@ -164,9 +165,9 @@
164165 struct ad5761_state *st = iio_priv(indio_dev);
165166 int ret;
166167
167
- mutex_lock(&indio_dev->mlock);
168
+ mutex_lock(&st->lock);
168169 ret = _ad5761_spi_read(st, addr, val);
169
- mutex_unlock(&indio_dev->mlock);
170
+ mutex_unlock(&st->lock);
170171
171172 return ret;
172173 }
....@@ -369,11 +370,12 @@
369370 if (pdata)
370371 voltage_range = pdata->voltage_range;
371372
373
+ mutex_init(&st->lock);
374
+
372375 ret = ad5761_spi_set_range(st, voltage_range);
373376 if (ret)
374377 goto disable_regulator_err;
375378
376
- iio_dev->dev.parent = &spi->dev;
377379 iio_dev->info = &ad5761_info;
378380 iio_dev->modes = INDIO_DIRECT_MODE;
379381 iio_dev->channels = &chip_info->channel;
....@@ -424,6 +426,6 @@
424426 };
425427 module_spi_driver(ad5761_driver);
426428
427
-MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>");
429
+MODULE_AUTHOR("Ricardo Ribalda <ribalda@kernel.org>");
428430 MODULE_DESCRIPTION("Analog Devices AD5721, AD5721R, AD5761, AD5761R driver");
429431 MODULE_LICENSE("GPL v2");