linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions
@ 2019-05-29 14:20 Alexandru Ardelean
  2019-06-08 14:24 ` Jonathan Cameron
  2019-09-20  7:57 ` [PATCH][RESEND] " Alexandru Ardelean
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandru Ardelean @ 2019-05-29 14:20 UTC (permalink / raw)
  To: linux-iio; +Cc: pmeerw, Alexandru Ardelean

The iio_triggered_buffer_{predisable,postenable} functions attach/detach
the poll functions.

For the predisable hook, the disable code should occur before detaching
the poll func, and for the postenable hook, the poll func should be
attached before the enable code.

The driver was slightly reworked. The preenable hook was moved to the
postenable, to add some symmetry to the postenable/predisable part.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/light/tcs3414.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
index 205e5659ce6b..ae70bf89be70 100644
--- a/drivers/iio/light/tcs3414.c
+++ b/drivers/iio/light/tcs3414.c
@@ -243,32 +243,42 @@ static const struct iio_info tcs3414_info = {
 	.attrs = &tcs3414_attribute_group,
 };
 
-static int tcs3414_buffer_preenable(struct iio_dev *indio_dev)
+static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
 {
 	struct tcs3414_data *data = iio_priv(indio_dev);
+	int ret;
+
+	ret = iio_triggered_buffer_postenable(indio_dev);
+	if (ret)
+		return ret;
 
 	data->control |= TCS3414_CONTROL_ADC_EN;
-	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
+	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
 		data->control);
+	if (ret)
+		iio_triggered_buffer_predisable(indio_dev);
+
+	return ret;
 }
 
 static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
 {
 	struct tcs3414_data *data = iio_priv(indio_dev);
-	int ret;
-
-	ret = iio_triggered_buffer_predisable(indio_dev);
-	if (ret < 0)
-		return ret;
+	int ret, ret2;
 
 	data->control &= ~TCS3414_CONTROL_ADC_EN;
-	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
+	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
 		data->control);
+
+	ret2 = iio_triggered_buffer_predisable(indio_dev);
+	if (!ret)
+		ret = ret2;
+
+	return ret;
 }
 
 static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
-	.preenable = tcs3414_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
+	.postenable = tcs3414_buffer_postenable,
 	.predisable = tcs3414_buffer_predisable,
 };
 
-- 
2.20.1


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

* Re: [PATCH] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions
  2019-05-29 14:20 [PATCH] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions Alexandru Ardelean
@ 2019-06-08 14:24 ` Jonathan Cameron
  2019-09-20  7:57 ` [PATCH][RESEND] " Alexandru Ardelean
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-06-08 14:24 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, pmeerw

On Wed, 29 May 2019 17:20:40 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> The iio_triggered_buffer_{predisable,postenable} functions attach/detach
> the poll functions.
> 
> For the predisable hook, the disable code should occur before detaching
> the poll func, and for the postenable hook, the poll func should be
> attached before the enable code.
> 
> The driver was slightly reworked. The preenable hook was moved to the
> postenable, to add some symmetry to the postenable/predisable part.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

Looks fine to me, but I'm looking for a tested-by/ack from Peter.

Thanks,

Jonathan

> ---
>  drivers/iio/light/tcs3414.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
> index 205e5659ce6b..ae70bf89be70 100644
> --- a/drivers/iio/light/tcs3414.c
> +++ b/drivers/iio/light/tcs3414.c
> @@ -243,32 +243,42 @@ static const struct iio_info tcs3414_info = {
>  	.attrs = &tcs3414_attribute_group,
>  };
>  
> -static int tcs3414_buffer_preenable(struct iio_dev *indio_dev)
> +static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
>  {
>  	struct tcs3414_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = iio_triggered_buffer_postenable(indio_dev);
> +	if (ret)
> +		return ret;
>  
>  	data->control |= TCS3414_CONTROL_ADC_EN;
> -	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
>  		data->control);
> +	if (ret)
> +		iio_triggered_buffer_predisable(indio_dev);
> +
> +	return ret;
>  }
>  
>  static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
>  {
>  	struct tcs3414_data *data = iio_priv(indio_dev);
> -	int ret;
> -
> -	ret = iio_triggered_buffer_predisable(indio_dev);
> -	if (ret < 0)
> -		return ret;
> +	int ret, ret2;
>  
>  	data->control &= ~TCS3414_CONTROL_ADC_EN;
> -	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
>  		data->control);
> +
> +	ret2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (!ret)
> +		ret = ret2;
> +
> +	return ret;
>  }
>  
>  static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
> -	.preenable = tcs3414_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> +	.postenable = tcs3414_buffer_postenable,
>  	.predisable = tcs3414_buffer_predisable,
>  };
>  


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

* [PATCH][RESEND] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions
  2019-05-29 14:20 [PATCH] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions Alexandru Ardelean
  2019-06-08 14:24 ` Jonathan Cameron
@ 2019-09-20  7:57 ` Alexandru Ardelean
  2019-09-21 15:32   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandru Ardelean @ 2019-09-20  7:57 UTC (permalink / raw)
  To: linux-iio; +Cc: pmeerw, jic23, Alexandru Ardelean

The iio_triggered_buffer_{predisable,postenable} functions attach/detach
the poll functions.

For the predisable hook, the disable code should occur before detaching
the poll func, and for the postenable hook, the poll func should be
attached before the enable code.

The driver was slightly reworked. The preenable hook was moved to the
postenable, to add some symmetry to the postenable/predisable part.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/light/tcs3414.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
index 7c0291c5fe76..b542e5619ead 100644
--- a/drivers/iio/light/tcs3414.c
+++ b/drivers/iio/light/tcs3414.c
@@ -240,32 +240,42 @@ static const struct iio_info tcs3414_info = {
 	.attrs = &tcs3414_attribute_group,
 };
 
-static int tcs3414_buffer_preenable(struct iio_dev *indio_dev)
+static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
 {
 	struct tcs3414_data *data = iio_priv(indio_dev);
+	int ret;
+
+	ret = iio_triggered_buffer_postenable(indio_dev);
+	if (ret)
+		return ret;
 
 	data->control |= TCS3414_CONTROL_ADC_EN;
-	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
+	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
 		data->control);
+	if (ret)
+		iio_triggered_buffer_predisable(indio_dev);
+
+	return ret;
 }
 
 static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
 {
 	struct tcs3414_data *data = iio_priv(indio_dev);
-	int ret;
-
-	ret = iio_triggered_buffer_predisable(indio_dev);
-	if (ret < 0)
-		return ret;
+	int ret, ret2;
 
 	data->control &= ~TCS3414_CONTROL_ADC_EN;
-	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
+	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
 		data->control);
+
+	ret2 = iio_triggered_buffer_predisable(indio_dev);
+	if (!ret)
+		ret = ret2;
+
+	return ret;
 }
 
 static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
-	.preenable = tcs3414_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
+	.postenable = tcs3414_buffer_postenable,
 	.predisable = tcs3414_buffer_predisable,
 };
 
-- 
2.20.1


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

* Re: [PATCH][RESEND] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions
  2019-09-20  7:57 ` [PATCH][RESEND] " Alexandru Ardelean
@ 2019-09-21 15:32   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-09-21 15:32 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, pmeerw

On Fri, 20 Sep 2019 10:57:23 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> The iio_triggered_buffer_{predisable,postenable} functions attach/detach
> the poll functions.
> 
> For the predisable hook, the disable code should occur before detaching
> the poll func, and for the postenable hook, the poll func should be
> attached before the enable code.
> 
> The driver was slightly reworked. The preenable hook was moved to the
> postenable, to add some symmetry to the postenable/predisable part.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Seem's Peter is busy or missed this one.  Still time to send a review
though as I won't push out a non rebasing tree for at least a week.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders
to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/light/tcs3414.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
> index 7c0291c5fe76..b542e5619ead 100644
> --- a/drivers/iio/light/tcs3414.c
> +++ b/drivers/iio/light/tcs3414.c
> @@ -240,32 +240,42 @@ static const struct iio_info tcs3414_info = {
>  	.attrs = &tcs3414_attribute_group,
>  };
>  
> -static int tcs3414_buffer_preenable(struct iio_dev *indio_dev)
> +static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
>  {
>  	struct tcs3414_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = iio_triggered_buffer_postenable(indio_dev);
> +	if (ret)
> +		return ret;
>  
>  	data->control |= TCS3414_CONTROL_ADC_EN;
> -	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
>  		data->control);
> +	if (ret)
> +		iio_triggered_buffer_predisable(indio_dev);
> +
> +	return ret;
>  }
>  
>  static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
>  {
>  	struct tcs3414_data *data = iio_priv(indio_dev);
> -	int ret;
> -
> -	ret = iio_triggered_buffer_predisable(indio_dev);
> -	if (ret < 0)
> -		return ret;
> +	int ret, ret2;
>  
>  	data->control &= ~TCS3414_CONTROL_ADC_EN;
> -	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
>  		data->control);
> +
> +	ret2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (!ret)
> +		ret = ret2;
> +
> +	return ret;
>  }
>  
>  static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
> -	.preenable = tcs3414_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> +	.postenable = tcs3414_buffer_postenable,
>  	.predisable = tcs3414_buffer_predisable,
>  };
>  


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

end of thread, other threads:[~2019-09-21 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29 14:20 [PATCH] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions Alexandru Ardelean
2019-06-08 14:24 ` Jonathan Cameron
2019-09-20  7:57 ` [PATCH][RESEND] " Alexandru Ardelean
2019-09-21 15:32   ` 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).