linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock
@ 2020-05-20  6:18 Sergiu Cuciurean
  2020-05-20  8:46 ` Ardelean, Alexandru
  2020-05-20 12:02 ` [PATCH v2] " Sergiu Cuciurean
  0 siblings, 2 replies; 4+ messages in thread
From: Sergiu Cuciurean @ 2020-05-20  6:18 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/ad5592r-base.c | 28 +++++++++++++++-------------
 drivers/iio/dac/ad5592r-base.h |  1 +
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
index e2110113e884..10109eb81db2 100644
--- a/drivers/iio/dac/ad5592r-base.c
+++ b/drivers/iio/dac/ad5592r-base.c
@@ -166,10 +166,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
 		udelay(1);
 		gpiod_set_value(gpio, 1);
 	} else {
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 		/* Writing this magic value resets the device */
 		st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
-		mutex_unlock(&iio_dev->mlock);
+		mutex_unlock(&st->lock);
 	}
 
 	udelay(250);
@@ -247,7 +247,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
 		}
 	}
 
-	mutex_lock(&iio_dev->mlock);
+	mutex_lock(&st->lock);
 
 	/* Pull down unused pins to GND */
 	ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
@@ -285,7 +285,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
 		ret = -EIO;
 
 err_unlock:
-	mutex_unlock(&iio_dev->mlock);
+	mutex_unlock(&st->lock);
 	return ret;
 }
 
@@ -314,11 +314,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 		if (!chan->output)
 			return -EINVAL;
 
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 		ret = st->ops->write_dac(st, chan->channel, val);
 		if (!ret)
 			st->cached_dac[chan->channel] = val;
-		mutex_unlock(&iio_dev->mlock);
+		mutex_unlock(&st->lock);
 		return ret;
 	case IIO_CHAN_INFO_SCALE:
 		if (chan->type == IIO_VOLTAGE) {
@@ -333,12 +333,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 			else
 				return -EINVAL;
 
-			mutex_lock(&iio_dev->mlock);
+			mutex_lock(&st->lock);
 
 			ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
 						&st->cached_gp_ctrl);
 			if (ret < 0) {
-				mutex_unlock(&iio_dev->mlock);
+				mutex_unlock(&st->lock);
 				return ret;
 			}
 
@@ -360,7 +360,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 
 			ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
 						 st->cached_gp_ctrl);
-			mutex_unlock(&iio_dev->mlock);
+			mutex_unlock(&st->lock);
 
 			return ret;
 		}
@@ -382,7 +382,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 
 		if (!chan->output) {
 			ret = st->ops->read_adc(st, chan->channel, &read_val);
@@ -419,7 +419,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 		} else {
 			int mult;
 
-			mutex_lock(&iio_dev->mlock);
+			mutex_lock(&st->lock);
 
 			if (chan->output)
 				mult = !!(st->cached_gp_ctrl &
@@ -437,7 +437,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 	case IIO_CHAN_INFO_OFFSET:
 		ret = ad5592r_get_vref(st);
 
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 
 		if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
 			*val = (-34365 * 25) / ret;
@@ -450,7 +450,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 	}
 
 unlock:
-	mutex_unlock(&iio_dev->mlock);
+	mutex_unlock(&st->lock);
 	return ret;
 }
 
@@ -625,6 +625,8 @@ int ad5592r_probe(struct device *dev, const char *name,
 	iio_dev->info = &ad5592r_info;
 	iio_dev->modes = INDIO_DIRECT_MODE;
 
+	mutex_init(&st->lock);
+
 	ad5592r_init_scales(st, ad5592r_get_vref(st));
 
 	ret = ad5592r_reset(st);
diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-base.h
index 4774e4cd9c11..23dac2f1ff8a 100644
--- a/drivers/iio/dac/ad5592r-base.h
+++ b/drivers/iio/dac/ad5592r-base.h
@@ -52,6 +52,7 @@ struct ad5592r_state {
 	struct regulator *reg;
 	struct gpio_chip gpiochip;
 	struct mutex gpio_lock;	/* Protect cached gpio_out, gpio_val, etc. */
+	struct mutex lock;
 	unsigned int num_channels;
 	const struct ad5592r_rw_ops *ops;
 	int scale_avail[2][2];
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock
  2020-05-20  6:18 [PATCH] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
@ 2020-05-20  8:46 ` Ardelean, Alexandru
  2020-05-20 12:02 ` [PATCH v2] " Sergiu Cuciurean
  1 sibling, 0 replies; 4+ messages in thread
From: Ardelean, Alexandru @ 2020-05-20  8:46 UTC (permalink / raw)
  To: Cuciurean, Sergiu, linux-kernel, linux-iio
  Cc: stefan.popa, Hennerich, Michael, jic23, lars, knaack.h, pmeerw

On Wed, 2020-05-20 at 09:18 +0300, Sergiu Cuciurean wrote:
> [External]
> 
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock on the device's state structure.
> 

This requires a V2.
It produces a warning:

  159 |  struct iio_dev *iio_dev = iio_priv_to_dev(st);
      |                  ^~~~~~~
drivers/iio/dac/ad5592r-base.c: In function ‘ad5592r_set_channel_modes’:
drivers/iio/dac/ad5592r-base.c:200:18: warning: unused variable ‘iio_dev’
[-Wunused-variable]
  200 |  struct iio_dev *iio_dev = iio_priv_to_dev(st);


You can remove both instances of
 struct iio_dev *iio_dev = iio_priv_to_dev(st);


> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> ---
>  drivers/iio/dac/ad5592r-base.c | 28 +++++++++++++++-------------
>  drivers/iio/dac/ad5592r-base.h |  1 +
>  2 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-
> base.c
> index e2110113e884..10109eb81db2 100644
> --- a/drivers/iio/dac/ad5592r-base.c
> +++ b/drivers/iio/dac/ad5592r-base.c
> @@ -166,10 +166,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
>  		udelay(1);
>  		gpiod_set_value(gpio, 1);
>  	} else {
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  		/* Writing this magic value resets the device */
>  		st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
> -		mutex_unlock(&iio_dev->mlock);
> +		mutex_unlock(&st->lock);
>  	}
>  
>  	udelay(250);
> @@ -247,7 +247,7 @@ static int ad5592r_set_channel_modes(struct
> ad5592r_state *st)
>  		}
>  	}
>  
> -	mutex_lock(&iio_dev->mlock);
> +	mutex_lock(&st->lock);
>  
>  	/* Pull down unused pins to GND */
>  	ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
> @@ -285,7 +285,7 @@ static int ad5592r_set_channel_modes(struct
> ad5592r_state *st)
>  		ret = -EIO;
>  
>  err_unlock:
> -	mutex_unlock(&iio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  	return ret;
>  }
>  
> @@ -314,11 +314,11 @@ static int ad5592r_write_raw(struct iio_dev
> *iio_dev,
>  		if (!chan->output)
>  			return -EINVAL;
>  
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  		ret = st->ops->write_dac(st, chan->channel, val);
>  		if (!ret)
>  			st->cached_dac[chan->channel] = val;
> -		mutex_unlock(&iio_dev->mlock);
> +		mutex_unlock(&st->lock);
>  		return ret;
>  	case IIO_CHAN_INFO_SCALE:
>  		if (chan->type == IIO_VOLTAGE) {
> @@ -333,12 +333,12 @@ static int ad5592r_write_raw(struct iio_dev
> *iio_dev,
>  			else
>  				return -EINVAL;
>  
> -			mutex_lock(&iio_dev->mlock);
> +			mutex_lock(&st->lock);
>  
>  			ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
>  						&st->cached_gp_ctrl);
>  			if (ret < 0) {
> -				mutex_unlock(&iio_dev->mlock);
> +				mutex_unlock(&st->lock);
>  				return ret;
>  			}
>  
> @@ -360,7 +360,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
>  
>  			ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
>  						 st->cached_gp_ctrl);
> -			mutex_unlock(&iio_dev->mlock);
> +			mutex_unlock(&st->lock);
>  
>  			return ret;
>  		}
> @@ -382,7 +382,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  
>  	switch (m) {
>  	case IIO_CHAN_INFO_RAW:
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  
>  		if (!chan->output) {
>  			ret = st->ops->read_adc(st, chan->channel,
> &read_val);
> @@ -419,7 +419,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  		} else {
>  			int mult;
>  
> -			mutex_lock(&iio_dev->mlock);
> +			mutex_lock(&st->lock);
>  
>  			if (chan->output)
>  				mult = !!(st->cached_gp_ctrl &
> @@ -437,7 +437,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_OFFSET:
>  		ret = ad5592r_get_vref(st);
>  
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  
>  		if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
>  			*val = (-34365 * 25) / ret;
> @@ -450,7 +450,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  	}
>  
>  unlock:
> -	mutex_unlock(&iio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  	return ret;
>  }
>  
> @@ -625,6 +625,8 @@ int ad5592r_probe(struct device *dev, const char
> *name,
>  	iio_dev->info = &ad5592r_info;
>  	iio_dev->modes = INDIO_DIRECT_MODE;
>  
> +	mutex_init(&st->lock);
> +
>  	ad5592r_init_scales(st, ad5592r_get_vref(st));
>  
>  	ret = ad5592r_reset(st);
> diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-
> base.h
> index 4774e4cd9c11..23dac2f1ff8a 100644
> --- a/drivers/iio/dac/ad5592r-base.h
> +++ b/drivers/iio/dac/ad5592r-base.h
> @@ -52,6 +52,7 @@ struct ad5592r_state {
>  	struct regulator *reg;
>  	struct gpio_chip gpiochip;
>  	struct mutex gpio_lock;	/* Protect cached gpio_out, gpio_val,
> etc. */
> +	struct mutex lock;
>  	unsigned int num_channels;
>  	const struct ad5592r_rw_ops *ops;
>  	int scale_avail[2][2];

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock
  2020-05-20  6:18 [PATCH] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
  2020-05-20  8:46 ` Ardelean, Alexandru
@ 2020-05-20 12:02 ` Sergiu Cuciurean
  2020-05-21 18:38   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Sergiu Cuciurean @ 2020-05-20 12:02 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.
This also removes unused iio_dev pointers.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
---
 drivers/iio/dac/ad5592r-base.c | 30 +++++++++++++++---------------
 drivers/iio/dac/ad5592r-base.h |  1 +
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
index e2110113e884..410e90e5f75f 100644
--- a/drivers/iio/dac/ad5592r-base.c
+++ b/drivers/iio/dac/ad5592r-base.c
@@ -156,7 +156,6 @@ static void ad5592r_gpio_cleanup(struct ad5592r_state *st)
 static int ad5592r_reset(struct ad5592r_state *st)
 {
 	struct gpio_desc *gpio;
-	struct iio_dev *iio_dev = iio_priv_to_dev(st);
 
 	gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW);
 	if (IS_ERR(gpio))
@@ -166,10 +165,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
 		udelay(1);
 		gpiod_set_value(gpio, 1);
 	} else {
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 		/* Writing this magic value resets the device */
 		st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
-		mutex_unlock(&iio_dev->mlock);
+		mutex_unlock(&st->lock);
 	}
 
 	udelay(250);
@@ -197,7 +196,6 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
 	const struct ad5592r_rw_ops *ops = st->ops;
 	int ret;
 	unsigned i;
-	struct iio_dev *iio_dev = iio_priv_to_dev(st);
 	u8 pulldown = 0, tristate = 0, dac = 0, adc = 0;
 	u16 read_back;
 
@@ -247,7 +245,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
 		}
 	}
 
-	mutex_lock(&iio_dev->mlock);
+	mutex_lock(&st->lock);
 
 	/* Pull down unused pins to GND */
 	ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
@@ -285,7 +283,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
 		ret = -EIO;
 
 err_unlock:
-	mutex_unlock(&iio_dev->mlock);
+	mutex_unlock(&st->lock);
 	return ret;
 }
 
@@ -314,11 +312,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 		if (!chan->output)
 			return -EINVAL;
 
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 		ret = st->ops->write_dac(st, chan->channel, val);
 		if (!ret)
 			st->cached_dac[chan->channel] = val;
-		mutex_unlock(&iio_dev->mlock);
+		mutex_unlock(&st->lock);
 		return ret;
 	case IIO_CHAN_INFO_SCALE:
 		if (chan->type == IIO_VOLTAGE) {
@@ -333,12 +331,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 			else
 				return -EINVAL;
 
-			mutex_lock(&iio_dev->mlock);
+			mutex_lock(&st->lock);
 
 			ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
 						&st->cached_gp_ctrl);
 			if (ret < 0) {
-				mutex_unlock(&iio_dev->mlock);
+				mutex_unlock(&st->lock);
 				return ret;
 			}
 
@@ -360,7 +358,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 
 			ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
 						 st->cached_gp_ctrl);
-			mutex_unlock(&iio_dev->mlock);
+			mutex_unlock(&st->lock);
 
 			return ret;
 		}
@@ -382,7 +380,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 
 		if (!chan->output) {
 			ret = st->ops->read_adc(st, chan->channel, &read_val);
@@ -419,7 +417,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 		} else {
 			int mult;
 
-			mutex_lock(&iio_dev->mlock);
+			mutex_lock(&st->lock);
 
 			if (chan->output)
 				mult = !!(st->cached_gp_ctrl &
@@ -437,7 +435,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 	case IIO_CHAN_INFO_OFFSET:
 		ret = ad5592r_get_vref(st);
 
-		mutex_lock(&iio_dev->mlock);
+		mutex_lock(&st->lock);
 
 		if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
 			*val = (-34365 * 25) / ret;
@@ -450,7 +448,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 	}
 
 unlock:
-	mutex_unlock(&iio_dev->mlock);
+	mutex_unlock(&st->lock);
 	return ret;
 }
 
@@ -625,6 +623,8 @@ int ad5592r_probe(struct device *dev, const char *name,
 	iio_dev->info = &ad5592r_info;
 	iio_dev->modes = INDIO_DIRECT_MODE;
 
+	mutex_init(&st->lock);
+
 	ad5592r_init_scales(st, ad5592r_get_vref(st));
 
 	ret = ad5592r_reset(st);
diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-base.h
index 4774e4cd9c11..23dac2f1ff8a 100644
--- a/drivers/iio/dac/ad5592r-base.h
+++ b/drivers/iio/dac/ad5592r-base.h
@@ -52,6 +52,7 @@ struct ad5592r_state {
 	struct regulator *reg;
 	struct gpio_chip gpiochip;
 	struct mutex gpio_lock;	/* Protect cached gpio_out, gpio_val, etc. */
+	struct mutex lock;
 	unsigned int num_channels;
 	const struct ad5592r_rw_ops *ops;
 	int scale_avail[2][2];
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock
  2020-05-20 12:02 ` [PATCH v2] " Sergiu Cuciurean
@ 2020-05-21 18:38   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-05-21 18:38 UTC (permalink / raw)
  To: Sergiu Cuciurean
  Cc: linux-kernel, linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Stefan Popa, Hartmut Knaack, Peter Meerwald-Stadler

On Wed, 20 May 2020 15:02:01 +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.
> This also removes unused iio_dev pointers.
> 
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/dac/ad5592r-base.c | 30 +++++++++++++++---------------
>  drivers/iio/dac/ad5592r-base.h |  1 +
>  2 files changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
> index e2110113e884..410e90e5f75f 100644
> --- a/drivers/iio/dac/ad5592r-base.c
> +++ b/drivers/iio/dac/ad5592r-base.c
> @@ -156,7 +156,6 @@ static void ad5592r_gpio_cleanup(struct ad5592r_state *st)
>  static int ad5592r_reset(struct ad5592r_state *st)
>  {
>  	struct gpio_desc *gpio;
> -	struct iio_dev *iio_dev = iio_priv_to_dev(st);
>  
>  	gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW);
>  	if (IS_ERR(gpio))
> @@ -166,10 +165,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
>  		udelay(1);
>  		gpiod_set_value(gpio, 1);
>  	} else {
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  		/* Writing this magic value resets the device */
>  		st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
> -		mutex_unlock(&iio_dev->mlock);
> +		mutex_unlock(&st->lock);
>  	}
>  
>  	udelay(250);
> @@ -197,7 +196,6 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
>  	const struct ad5592r_rw_ops *ops = st->ops;
>  	int ret;
>  	unsigned i;
> -	struct iio_dev *iio_dev = iio_priv_to_dev(st);
>  	u8 pulldown = 0, tristate = 0, dac = 0, adc = 0;
>  	u16 read_back;
>  
> @@ -247,7 +245,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
>  		}
>  	}
>  
> -	mutex_lock(&iio_dev->mlock);
> +	mutex_lock(&st->lock);
>  
>  	/* Pull down unused pins to GND */
>  	ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
> @@ -285,7 +283,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
>  		ret = -EIO;
>  
>  err_unlock:
> -	mutex_unlock(&iio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  	return ret;
>  }
>  
> @@ -314,11 +312,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
>  		if (!chan->output)
>  			return -EINVAL;
>  
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  		ret = st->ops->write_dac(st, chan->channel, val);
>  		if (!ret)
>  			st->cached_dac[chan->channel] = val;
> -		mutex_unlock(&iio_dev->mlock);
> +		mutex_unlock(&st->lock);
>  		return ret;
>  	case IIO_CHAN_INFO_SCALE:
>  		if (chan->type == IIO_VOLTAGE) {
> @@ -333,12 +331,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
>  			else
>  				return -EINVAL;
>  
> -			mutex_lock(&iio_dev->mlock);
> +			mutex_lock(&st->lock);
>  
>  			ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
>  						&st->cached_gp_ctrl);
>  			if (ret < 0) {
> -				mutex_unlock(&iio_dev->mlock);
> +				mutex_unlock(&st->lock);
>  				return ret;
>  			}
>  
> @@ -360,7 +358,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
>  
>  			ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
>  						 st->cached_gp_ctrl);
> -			mutex_unlock(&iio_dev->mlock);
> +			mutex_unlock(&st->lock);
>  
>  			return ret;
>  		}
> @@ -382,7 +380,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  
>  	switch (m) {
>  	case IIO_CHAN_INFO_RAW:
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  
>  		if (!chan->output) {
>  			ret = st->ops->read_adc(st, chan->channel, &read_val);
> @@ -419,7 +417,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  		} else {
>  			int mult;
>  
> -			mutex_lock(&iio_dev->mlock);
> +			mutex_lock(&st->lock);
>  
>  			if (chan->output)
>  				mult = !!(st->cached_gp_ctrl &
> @@ -437,7 +435,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_OFFSET:
>  		ret = ad5592r_get_vref(st);
>  
> -		mutex_lock(&iio_dev->mlock);
> +		mutex_lock(&st->lock);
>  
>  		if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
>  			*val = (-34365 * 25) / ret;
> @@ -450,7 +448,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
>  	}
>  
>  unlock:
> -	mutex_unlock(&iio_dev->mlock);
> +	mutex_unlock(&st->lock);
>  	return ret;
>  }
>  
> @@ -625,6 +623,8 @@ int ad5592r_probe(struct device *dev, const char *name,
>  	iio_dev->info = &ad5592r_info;
>  	iio_dev->modes = INDIO_DIRECT_MODE;
>  
> +	mutex_init(&st->lock);
> +
>  	ad5592r_init_scales(st, ad5592r_get_vref(st));
>  
>  	ret = ad5592r_reset(st);
> diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-base.h
> index 4774e4cd9c11..23dac2f1ff8a 100644
> --- a/drivers/iio/dac/ad5592r-base.h
> +++ b/drivers/iio/dac/ad5592r-base.h
> @@ -52,6 +52,7 @@ struct ad5592r_state {
>  	struct regulator *reg;
>  	struct gpio_chip gpiochip;
>  	struct mutex gpio_lock;	/* Protect cached gpio_out, gpio_val, etc. */
> +	struct mutex lock;
>  	unsigned int num_channels;
>  	const struct ad5592r_rw_ops *ops;
>  	int scale_avail[2][2];


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-21 18:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20  6:18 [PATCH] iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock Sergiu Cuciurean
2020-05-20  8:46 ` Ardelean, Alexandru
2020-05-20 12:02 ` [PATCH v2] " Sergiu Cuciurean
2020-05-21 18:38   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).