forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/iio/dac/ad5449.c
....@@ -1,11 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AD5415, AD5426, AD5429, AD5432, AD5439, AD5443, AD5449 Digital to Analog
34 * Converter driver.
45 *
56 * Copyright 2012 Analog Devices Inc.
67 * Author: Lars-Peter Clausen <lars@metafoo.de>
7
- *
8
- * Licensed under the GPL-2.
98 */
109
1110 #include <linux/device.h>
....@@ -57,11 +56,13 @@
5756 * @has_sdo: whether the SDO line is connected
5857 * @dac_cache: Cache for the DAC values
5958 * @data: spi transfer buffers
59
+ * @lock: lock to protect the data buffer during SPI ops
6060 */
6161 struct ad5449 {
6262 struct spi_device *spi;
6363 const struct ad5449_chip_info *chip_info;
6464 struct regulator_bulk_data vref_reg[AD5449_MAX_VREFS];
65
+ struct mutex lock;
6566
6667 bool has_sdo;
6768 uint16_t dac_cache[AD5449_MAX_CHANNELS];
....@@ -88,10 +89,10 @@
8889 struct ad5449 *st = iio_priv(indio_dev);
8990 int ret;
9091
91
- mutex_lock(&indio_dev->mlock);
92
+ mutex_lock(&st->lock);
9293 st->data[0] = cpu_to_be16((addr << 12) | val);
9394 ret = spi_write(st->spi, st->data, 2);
94
- mutex_unlock(&indio_dev->mlock);
95
+ mutex_unlock(&st->lock);
9596
9697 return ret;
9798 }
....@@ -113,7 +114,7 @@
113114 },
114115 };
115116
116
- mutex_lock(&indio_dev->mlock);
117
+ mutex_lock(&st->lock);
117118 st->data[0] = cpu_to_be16(addr << 12);
118119 st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
119120
....@@ -124,7 +125,7 @@
124125 *val = be16_to_cpu(st->data[1]);
125126
126127 out_unlock:
127
- mutex_unlock(&indio_dev->mlock);
128
+ mutex_unlock(&st->lock);
128129 return ret;
129130 }
130131
....@@ -296,13 +297,14 @@
296297 if (ret)
297298 return ret;
298299
299
- indio_dev->dev.parent = &spi->dev;
300300 indio_dev->name = id->name;
301301 indio_dev->info = &ad5449_info;
302302 indio_dev->modes = INDIO_DIRECT_MODE;
303303 indio_dev->channels = st->chip_info->channels;
304304 indio_dev->num_channels = st->chip_info->num_channels;
305305
306
+ mutex_init(&st->lock);
307
+
306308 if (st->chip_info->has_ctrl) {
307309 unsigned int ctrl = 0x00;
308310 if (pdata) {