| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Analog devices AD5360, AD5361, AD5362, AD5363, AD5370, AD5371, AD5373 |
|---|
| 3 | 4 | * multi-channel Digital to Analog Converters driver |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Copyright 2011 Analog Devices Inc. |
|---|
| 6 | | - * |
|---|
| 7 | | - * Licensed under the GPL-2. |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 68 | 67 | * @chip_info: chip model specific constants, available modes etc |
|---|
| 69 | 68 | * @vref_reg: vref supply regulators |
|---|
| 70 | 69 | * @ctrl: control register cache |
|---|
| 70 | + * @lock: lock to protect the data buffer during SPI ops |
|---|
| 71 | 71 | * @data: spi transfer buffers |
|---|
| 72 | 72 | */ |
|---|
| 73 | 73 | |
|---|
| .. | .. |
|---|
| 76 | 76 | const struct ad5360_chip_info *chip_info; |
|---|
| 77 | 77 | struct regulator_bulk_data vref_reg[3]; |
|---|
| 78 | 78 | unsigned int ctrl; |
|---|
| 79 | + struct mutex lock; |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | /* |
|---|
| 81 | 82 | * DMA (thus cache coherency maintenance) requires the |
|---|
| .. | .. |
|---|
| 206 | 207 | unsigned int addr, unsigned int val, unsigned int shift) |
|---|
| 207 | 208 | { |
|---|
| 208 | 209 | int ret; |
|---|
| 210 | + struct ad5360_state *st = iio_priv(indio_dev); |
|---|
| 209 | 211 | |
|---|
| 210 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 212 | + mutex_lock(&st->lock); |
|---|
| 211 | 213 | ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift); |
|---|
| 212 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 214 | + mutex_unlock(&st->lock); |
|---|
| 213 | 215 | |
|---|
| 214 | 216 | return ret; |
|---|
| 215 | 217 | } |
|---|
| .. | .. |
|---|
| 230 | 232 | }, |
|---|
| 231 | 233 | }; |
|---|
| 232 | 234 | |
|---|
| 233 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 235 | + mutex_lock(&st->lock); |
|---|
| 234 | 236 | |
|---|
| 235 | 237 | st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | |
|---|
| 236 | 238 | AD5360_ADDR(AD5360_REG_SF_READBACK) | |
|---|
| .. | .. |
|---|
| 241 | 243 | if (ret >= 0) |
|---|
| 242 | 244 | ret = be32_to_cpu(st->data[1].d32) & 0xffff; |
|---|
| 243 | 245 | |
|---|
| 244 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 246 | + mutex_unlock(&st->lock); |
|---|
| 245 | 247 | |
|---|
| 246 | 248 | return ret; |
|---|
| 247 | 249 | } |
|---|
| .. | .. |
|---|
| 262 | 264 | struct ad5360_state *st = iio_priv(indio_dev); |
|---|
| 263 | 265 | unsigned int ret; |
|---|
| 264 | 266 | |
|---|
| 265 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 267 | + mutex_lock(&st->lock); |
|---|
| 266 | 268 | |
|---|
| 267 | 269 | st->ctrl |= set; |
|---|
| 268 | 270 | st->ctrl &= ~clr; |
|---|
| .. | .. |
|---|
| 270 | 272 | ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION, |
|---|
| 271 | 273 | AD5360_REG_SF_CTRL, st->ctrl, 0); |
|---|
| 272 | 274 | |
|---|
| 273 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 275 | + mutex_unlock(&st->lock); |
|---|
| 274 | 276 | |
|---|
| 275 | 277 | return ret; |
|---|
| 276 | 278 | } |
|---|
| .. | .. |
|---|
| 474 | 476 | st->chip_info = &ad5360_chip_info_tbl[type]; |
|---|
| 475 | 477 | st->spi = spi; |
|---|
| 476 | 478 | |
|---|
| 477 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 478 | 479 | indio_dev->name = spi_get_device_id(spi)->name; |
|---|
| 479 | 480 | indio_dev->info = &ad5360_info; |
|---|
| 480 | 481 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 481 | 482 | indio_dev->num_channels = st->chip_info->num_channels; |
|---|
| 482 | 483 | |
|---|
| 484 | + mutex_init(&st->lock); |
|---|
| 485 | + |
|---|
| 483 | 486 | ret = ad5360_alloc_channels(indio_dev); |
|---|
| 484 | 487 | if (ret) { |
|---|
| 485 | 488 | dev_err(&spi->dev, "Failed to allocate channel spec: %d\n", ret); |
|---|