| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AD5415, AD5426, AD5429, AD5432, AD5439, AD5443, AD5449 Digital to Analog |
|---|
| 3 | 4 | * Converter driver. |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Copyright 2012 Analog Devices Inc. |
|---|
| 6 | 7 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
|---|
| 7 | | - * |
|---|
| 8 | | - * Licensed under the GPL-2. |
|---|
| 9 | 8 | */ |
|---|
| 10 | 9 | |
|---|
| 11 | 10 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 57 | 56 | * @has_sdo: whether the SDO line is connected |
|---|
| 58 | 57 | * @dac_cache: Cache for the DAC values |
|---|
| 59 | 58 | * @data: spi transfer buffers |
|---|
| 59 | + * @lock: lock to protect the data buffer during SPI ops |
|---|
| 60 | 60 | */ |
|---|
| 61 | 61 | struct ad5449 { |
|---|
| 62 | 62 | struct spi_device *spi; |
|---|
| 63 | 63 | const struct ad5449_chip_info *chip_info; |
|---|
| 64 | 64 | struct regulator_bulk_data vref_reg[AD5449_MAX_VREFS]; |
|---|
| 65 | + struct mutex lock; |
|---|
| 65 | 66 | |
|---|
| 66 | 67 | bool has_sdo; |
|---|
| 67 | 68 | uint16_t dac_cache[AD5449_MAX_CHANNELS]; |
|---|
| .. | .. |
|---|
| 88 | 89 | struct ad5449 *st = iio_priv(indio_dev); |
|---|
| 89 | 90 | int ret; |
|---|
| 90 | 91 | |
|---|
| 91 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 92 | + mutex_lock(&st->lock); |
|---|
| 92 | 93 | st->data[0] = cpu_to_be16((addr << 12) | val); |
|---|
| 93 | 94 | ret = spi_write(st->spi, st->data, 2); |
|---|
| 94 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 95 | + mutex_unlock(&st->lock); |
|---|
| 95 | 96 | |
|---|
| 96 | 97 | return ret; |
|---|
| 97 | 98 | } |
|---|
| .. | .. |
|---|
| 113 | 114 | }, |
|---|
| 114 | 115 | }; |
|---|
| 115 | 116 | |
|---|
| 116 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 117 | + mutex_lock(&st->lock); |
|---|
| 117 | 118 | st->data[0] = cpu_to_be16(addr << 12); |
|---|
| 118 | 119 | st->data[1] = cpu_to_be16(AD5449_CMD_NOOP); |
|---|
| 119 | 120 | |
|---|
| .. | .. |
|---|
| 124 | 125 | *val = be16_to_cpu(st->data[1]); |
|---|
| 125 | 126 | |
|---|
| 126 | 127 | out_unlock: |
|---|
| 127 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 128 | + mutex_unlock(&st->lock); |
|---|
| 128 | 129 | return ret; |
|---|
| 129 | 130 | } |
|---|
| 130 | 131 | |
|---|
| .. | .. |
|---|
| 296 | 297 | if (ret) |
|---|
| 297 | 298 | return ret; |
|---|
| 298 | 299 | |
|---|
| 299 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 300 | 300 | indio_dev->name = id->name; |
|---|
| 301 | 301 | indio_dev->info = &ad5449_info; |
|---|
| 302 | 302 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 303 | 303 | indio_dev->channels = st->chip_info->channels; |
|---|
| 304 | 304 | indio_dev->num_channels = st->chip_info->num_channels; |
|---|
| 305 | 305 | |
|---|
| 306 | + mutex_init(&st->lock); |
|---|
| 307 | + |
|---|
| 306 | 308 | if (st->chip_info->has_ctrl) { |
|---|
| 307 | 309 | unsigned int ctrl = 0x00; |
|---|
| 308 | 310 | if (pdata) { |
|---|