hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/iio/dac/ad5360.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Analog devices AD5360, AD5361, AD5362, AD5363, AD5370, AD5371, AD5373
34 * multi-channel 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>
....@@ -68,6 +67,7 @@
6867 * @chip_info: chip model specific constants, available modes etc
6968 * @vref_reg: vref supply regulators
7069 * @ctrl: control register cache
70
+ * @lock: lock to protect the data buffer during SPI ops
7171 * @data: spi transfer buffers
7272 */
7373
....@@ -76,6 +76,7 @@
7676 const struct ad5360_chip_info *chip_info;
7777 struct regulator_bulk_data vref_reg[3];
7878 unsigned int ctrl;
79
+ struct mutex lock;
7980
8081 /*
8182 * DMA (thus cache coherency maintenance) requires the
....@@ -206,10 +207,11 @@
206207 unsigned int addr, unsigned int val, unsigned int shift)
207208 {
208209 int ret;
210
+ struct ad5360_state *st = iio_priv(indio_dev);
209211
210
- mutex_lock(&indio_dev->mlock);
212
+ mutex_lock(&st->lock);
211213 ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
212
- mutex_unlock(&indio_dev->mlock);
214
+ mutex_unlock(&st->lock);
213215
214216 return ret;
215217 }
....@@ -230,7 +232,7 @@
230232 },
231233 };
232234
233
- mutex_lock(&indio_dev->mlock);
235
+ mutex_lock(&st->lock);
234236
235237 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
236238 AD5360_ADDR(AD5360_REG_SF_READBACK) |
....@@ -241,7 +243,7 @@
241243 if (ret >= 0)
242244 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
243245
244
- mutex_unlock(&indio_dev->mlock);
246
+ mutex_unlock(&st->lock);
245247
246248 return ret;
247249 }
....@@ -262,7 +264,7 @@
262264 struct ad5360_state *st = iio_priv(indio_dev);
263265 unsigned int ret;
264266
265
- mutex_lock(&indio_dev->mlock);
267
+ mutex_lock(&st->lock);
266268
267269 st->ctrl |= set;
268270 st->ctrl &= ~clr;
....@@ -270,7 +272,7 @@
270272 ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
271273 AD5360_REG_SF_CTRL, st->ctrl, 0);
272274
273
- mutex_unlock(&indio_dev->mlock);
275
+ mutex_unlock(&st->lock);
274276
275277 return ret;
276278 }
....@@ -474,12 +476,13 @@
474476 st->chip_info = &ad5360_chip_info_tbl[type];
475477 st->spi = spi;
476478
477
- indio_dev->dev.parent = &spi->dev;
478479 indio_dev->name = spi_get_device_id(spi)->name;
479480 indio_dev->info = &ad5360_info;
480481 indio_dev->modes = INDIO_DIRECT_MODE;
481482 indio_dev->num_channels = st->chip_info->num_channels;
482483
484
+ mutex_init(&st->lock);
485
+
483486 ret = ad5360_alloc_channels(indio_dev);
484487 if (ret) {
485488 dev_err(&spi->dev, "Failed to allocate channel spec: %d\n", ret);