* [PATCH] iio: dac: ad5764: Replace indio_dev->mlock with own device lock
@ 2020-05-14 9:12 Sergiu Cuciurean
2020-05-16 15:25 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Sergiu Cuciurean @ 2020-05-14 9:12 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: Sergiu Cuciurean, Lars-Peter Clausen, Michael Hennerich,
Stefan Popa, Jonathan Cameron, Hartmut Knaack,
Peter Meerwald-Stadler
As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
---
drivers/iio/dac/ad5764.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
index f7ab211604a1..5b0f0fe354f6 100644
--- a/drivers/iio/dac/ad5764.c
+++ b/drivers/iio/dac/ad5764.c
@@ -46,6 +46,7 @@ struct ad5764_chip_info {
* @spi: spi_device
* @chip_info: chip info
* @vref_reg: vref supply regulators
+ * @lock lock to protect the data buffer during SPI ops
* @data: spi transfer buffers
*/
@@ -53,6 +54,7 @@ struct ad5764_state {
struct spi_device *spi;
const struct ad5764_chip_info *chip_info;
struct regulator_bulk_data vref_reg[2];
+ struct mutex lock;
/*
* DMA (thus cache coherency maintenance) requires the
@@ -126,11 +128,11 @@ static int ad5764_write(struct iio_dev *indio_dev, unsigned int reg,
struct ad5764_state *st = iio_priv(indio_dev);
int ret;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
st->data[0].d32 = cpu_to_be32((reg << 16) | val);
ret = spi_write(st->spi, &st->data[0].d8[1], 3);
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -151,7 +153,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
},
};
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
@@ -159,7 +161,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
if (ret >= 0)
*val = be32_to_cpu(st->data[1].d32) & 0xffff;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -295,6 +297,8 @@ static int ad5764_probe(struct spi_device *spi)
indio_dev->num_channels = AD5764_NUM_CHANNELS;
indio_dev->channels = st->chip_info->channels;
+ mutex_init(&st->lock);
+
if (st->chip_info->int_vref == 0) {
st->vref_reg[0].supply = "vrefAB";
st->vref_reg[1].supply = "vrefCD";
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: dac: ad5764: Replace indio_dev->mlock with own device lock
2020-05-14 9:12 [PATCH] iio: dac: ad5764: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
@ 2020-05-16 15:25 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-05-16 15:25 UTC (permalink / raw)
To: Sergiu Cuciurean
Cc: linux-kernel, linux-iio, Lars-Peter Clausen, Michael Hennerich,
Stefan Popa, Hartmut Knaack, Peter Meerwald-Stadler
On Thu, 14 May 2020 12:12:12 +0300
Sergiu Cuciurean <sergiu.cuciurean@analog.com> wrote:
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock on the device's state structure.
>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing.
Thanks,
Jonathan
> ---
> drivers/iio/dac/ad5764.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
> index f7ab211604a1..5b0f0fe354f6 100644
> --- a/drivers/iio/dac/ad5764.c
> +++ b/drivers/iio/dac/ad5764.c
> @@ -46,6 +46,7 @@ struct ad5764_chip_info {
> * @spi: spi_device
> * @chip_info: chip info
> * @vref_reg: vref supply regulators
> + * @lock lock to protect the data buffer during SPI ops
> * @data: spi transfer buffers
> */
>
> @@ -53,6 +54,7 @@ struct ad5764_state {
> struct spi_device *spi;
> const struct ad5764_chip_info *chip_info;
> struct regulator_bulk_data vref_reg[2];
> + struct mutex lock;
>
> /*
> * DMA (thus cache coherency maintenance) requires the
> @@ -126,11 +128,11 @@ static int ad5764_write(struct iio_dev *indio_dev, unsigned int reg,
> struct ad5764_state *st = iio_priv(indio_dev);
> int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> st->data[0].d32 = cpu_to_be32((reg << 16) | val);
>
> ret = spi_write(st->spi, &st->data[0].d8[1], 3);
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -151,7 +153,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
> },
> };
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
>
> st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
>
> @@ -159,7 +161,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
> if (ret >= 0)
> *val = be32_to_cpu(st->data[1].d32) & 0xffff;
>
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -295,6 +297,8 @@ static int ad5764_probe(struct spi_device *spi)
> indio_dev->num_channels = AD5764_NUM_CHANNELS;
> indio_dev->channels = st->chip_info->channels;
>
> + mutex_init(&st->lock);
> +
> if (st->chip_info->int_vref == 0) {
> st->vref_reg[0].supply = "vrefAB";
> st->vref_reg[1].supply = "vrefCD";
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-16 15:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 9:12 [PATCH] iio: dac: ad5764: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
2020-05-16 15:25 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.