| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ADIS16080/100 Yaw Rate Gyroscope with SPI driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2010 Analog Devices Inc. |
|---|
| 5 | | - * |
|---|
| 6 | | - * Licensed under the GPL-2 or later. |
|---|
| 7 | 6 | */ |
|---|
| 8 | 7 | #include <linux/delay.h> |
|---|
| 9 | 8 | #include <linux/mutex.h> |
|---|
| .. | .. |
|---|
| 39 | 38 | * @us: actual spi_device to write data |
|---|
| 40 | 39 | * @info: chip specific parameters |
|---|
| 41 | 40 | * @buf: transmit or receive buffer |
|---|
| 41 | + * @lock: lock to protect buffer during reads |
|---|
| 42 | 42 | **/ |
|---|
| 43 | 43 | struct adis16080_state { |
|---|
| 44 | 44 | struct spi_device *us; |
|---|
| 45 | 45 | const struct adis16080_chip_info *info; |
|---|
| 46 | + struct mutex lock; |
|---|
| 46 | 47 | |
|---|
| 47 | 48 | __be16 buf ____cacheline_aligned; |
|---|
| 48 | 49 | }; |
|---|
| .. | .. |
|---|
| 83 | 84 | |
|---|
| 84 | 85 | switch (mask) { |
|---|
| 85 | 86 | case IIO_CHAN_INFO_RAW: |
|---|
| 86 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 87 | + mutex_lock(&st->lock); |
|---|
| 87 | 88 | ret = adis16080_read_sample(indio_dev, chan->address, val); |
|---|
| 88 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 89 | + mutex_unlock(&st->lock); |
|---|
| 89 | 90 | return ret ? ret : IIO_VAL_INT; |
|---|
| 90 | 91 | case IIO_CHAN_INFO_SCALE: |
|---|
| 91 | 92 | switch (chan->type) { |
|---|
| .. | .. |
|---|
| 197 | 198 | /* this is only used for removal purposes */ |
|---|
| 198 | 199 | spi_set_drvdata(spi, indio_dev); |
|---|
| 199 | 200 | |
|---|
| 201 | + mutex_init(&st->lock); |
|---|
| 202 | + |
|---|
| 200 | 203 | /* Allocate the comms buffers */ |
|---|
| 201 | 204 | st->us = spi; |
|---|
| 202 | 205 | st->info = &adis16080_chip_info[id->driver_data]; |
|---|
| .. | .. |
|---|
| 204 | 207 | indio_dev->name = spi->dev.driver->name; |
|---|
| 205 | 208 | indio_dev->channels = adis16080_channels; |
|---|
| 206 | 209 | indio_dev->num_channels = ARRAY_SIZE(adis16080_channels); |
|---|
| 207 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 208 | 210 | indio_dev->info = &adis16080_info; |
|---|
| 209 | 211 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 210 | 212 | |
|---|