| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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> |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | #include <linux/kernel.h> |
|---|
| 10 | 9 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 58 | 57 | * @use_intref: true when the internal voltage reference is used |
|---|
| 59 | 58 | * @vref: actual voltage reference in mVolts |
|---|
| 60 | 59 | * @range: output range mode used |
|---|
| 60 | + * @lock: lock to protect the data buffer during SPI ops |
|---|
| 61 | 61 | * @data: cache aligned spi buffer |
|---|
| 62 | 62 | */ |
|---|
| 63 | 63 | struct ad5761_state { |
|---|
| 64 | 64 | struct spi_device *spi; |
|---|
| 65 | 65 | struct regulator *vref_reg; |
|---|
| 66 | + struct mutex lock; |
|---|
| 66 | 67 | |
|---|
| 67 | 68 | bool use_intref; |
|---|
| 68 | 69 | int vref; |
|---|
| .. | .. |
|---|
| 125 | 126 | struct ad5761_state *st = iio_priv(indio_dev); |
|---|
| 126 | 127 | int ret; |
|---|
| 127 | 128 | |
|---|
| 128 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 129 | + mutex_lock(&st->lock); |
|---|
| 129 | 130 | ret = _ad5761_spi_write(st, addr, val); |
|---|
| 130 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 131 | + mutex_unlock(&st->lock); |
|---|
| 131 | 132 | |
|---|
| 132 | 133 | return ret; |
|---|
| 133 | 134 | } |
|---|
| .. | .. |
|---|
| 164 | 165 | struct ad5761_state *st = iio_priv(indio_dev); |
|---|
| 165 | 166 | int ret; |
|---|
| 166 | 167 | |
|---|
| 167 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 168 | + mutex_lock(&st->lock); |
|---|
| 168 | 169 | ret = _ad5761_spi_read(st, addr, val); |
|---|
| 169 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 170 | + mutex_unlock(&st->lock); |
|---|
| 170 | 171 | |
|---|
| 171 | 172 | return ret; |
|---|
| 172 | 173 | } |
|---|
| .. | .. |
|---|
| 369 | 370 | if (pdata) |
|---|
| 370 | 371 | voltage_range = pdata->voltage_range; |
|---|
| 371 | 372 | |
|---|
| 373 | + mutex_init(&st->lock); |
|---|
| 374 | + |
|---|
| 372 | 375 | ret = ad5761_spi_set_range(st, voltage_range); |
|---|
| 373 | 376 | if (ret) |
|---|
| 374 | 377 | goto disable_regulator_err; |
|---|
| 375 | 378 | |
|---|
| 376 | | - iio_dev->dev.parent = &spi->dev; |
|---|
| 377 | 379 | iio_dev->info = &ad5761_info; |
|---|
| 378 | 380 | iio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 379 | 381 | iio_dev->channels = &chip_info->channel; |
|---|
| .. | .. |
|---|
| 424 | 426 | }; |
|---|
| 425 | 427 | module_spi_driver(ad5761_driver); |
|---|
| 426 | 428 | |
|---|
| 427 | | -MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>"); |
|---|
| 429 | +MODULE_AUTHOR("Ricardo Ribalda <ribalda@kernel.org>"); |
|---|
| 428 | 430 | MODULE_DESCRIPTION("Analog Devices AD5721, AD5721R, AD5761, AD5761R driver"); |
|---|
| 429 | 431 | MODULE_LICENSE("GPL v2"); |
|---|