All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 2/2] iio: hx711: fix bug in reset functionality
@ 2017-11-30 21:44 Andreas Klinger
  2017-12-02 13:22 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Klinger @ 2017-11-30 21:44 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw, singhalsimran0, linux-iio; +Cc: linux-kernel

return value in hx711_reset() should indicate status of dout
otherwise the calling function is reporting an error als false positive

wait up to 1 second until the device is in normal state
by changing the channel on every trigger event it turned out that the
former 100 ms are not enough for waiting until the device is in normal mode

Signed-off-by: Andreas Klinger <ak@it-klinger.de>
---
 drivers/iio/adc/hx711.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index d773fd69a76d..eabd2e66aca3 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
 	int i, val;
 
 	/*
-	 * a maximum reset cycle time of 56 ms was measured.
-	 * we round it up to 100 ms
+	 * in some rare cases the reset takes quite a long time
+	 * especially when the channel is changed.
+	 * Allow up to one second for it
 	 */
 	for (i = 0; i < 100; i++) {
 		val = gpiod_get_value(hx711_data->gpiod_dout);
 		if (!val)
 			break;
-		/* sleep at least 1 ms */
-		msleep(1);
+		/* sleep at least 10 ms */
+		msleep(10);
 	}
 	if (val)
 		return -EIO;
@@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
 		 * after a dummy read we need to wait vor readiness
 		 * for not mixing gain pulses with the clock
 		 */
-		ret = hx711_wait_for_ready(hx711_data);
-		if (ret)
-			return ret;
+		val = hx711_wait_for_ready(hx711_data);
 	}
 
 	return val;
-- 
2.1.4


-- 

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

* Re: [PATCH v2 2/2] iio: hx711: fix bug in reset functionality
  2017-11-30 21:44 [PATCH v2 2/2] iio: hx711: fix bug in reset functionality Andreas Klinger
@ 2017-12-02 13:22 ` Jonathan Cameron
  2017-12-05 13:12   ` Andreas Klinger
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-12-02 13:22 UTC (permalink / raw)
  To: Andreas Klinger
  Cc: knaack.h, lars, pmeerw, singhalsimran0, linux-iio, linux-kernel

On Thu, 30 Nov 2017 22:44:45 +0100
Andreas Klinger <ak@it-klinger.de> wrote:

> return value in hx711_reset() should indicate status of dout
> otherwise the calling function is reporting an error als false positive
> 
> wait up to 1 second until the device is in normal state
> by changing the channel on every trigger event it turned out that the
> former 100 ms are not enough for waiting until the device is in normal mode

What is the ultimate result of this?  I'm trying to assess if we want
to marked it for stable trees or just apply it ready for the next
merge window.  It think it means that two reads too close to each
other will always result in an error for the second one rather than 
the intended delay and then succeed?

Thanks,

Jonathan
> 
> Signed-off-by: Andreas Klinger <ak@it-klinger.de>
> ---
>  drivers/iio/adc/hx711.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> index d773fd69a76d..eabd2e66aca3 100644
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c
> @@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
>  	int i, val;
>  
>  	/*
> -	 * a maximum reset cycle time of 56 ms was measured.
> -	 * we round it up to 100 ms
> +	 * in some rare cases the reset takes quite a long time
> +	 * especially when the channel is changed.
> +	 * Allow up to one second for it
>  	 */
>  	for (i = 0; i < 100; i++) {
>  		val = gpiod_get_value(hx711_data->gpiod_dout);
>  		if (!val)
>  			break;
> -		/* sleep at least 1 ms */
> -		msleep(1);
> +		/* sleep at least 10 ms */
> +		msleep(10);
>  	}
>  	if (val)
>  		return -EIO;
> @@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
>  		 * after a dummy read we need to wait vor readiness
>  		 * for not mixing gain pulses with the clock
>  		 */
> -		ret = hx711_wait_for_ready(hx711_data);
> -		if (ret)
> -			return ret;
> +		val = hx711_wait_for_ready(hx711_data);
>  	}
>  
>  	return val;

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

* Re: [PATCH v2 2/2] iio: hx711: fix bug in reset functionality
  2017-12-02 13:22 ` Jonathan Cameron
@ 2017-12-05 13:12   ` Andreas Klinger
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Klinger @ 2017-12-05 13:12 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: knaack.h, lars, pmeerw, singhalsimran0, linux-iio, linux-kernel

Hi Jonathan,

see answer to your question below.

Andreas

Jonathan Cameron <jic23@kernel.org> schrieb am Sat, 02. Dec 13:22:
> On Thu, 30 Nov 2017 22:44:45 +0100
> Andreas Klinger <ak@it-klinger.de> wrote:
> 
> > return value in hx711_reset() should indicate status of dout
> > otherwise the calling function is reporting an error als false positive
> > 
> > wait up to 1 second until the device is in normal state
> > by changing the channel on every trigger event it turned out that the
> > former 100 ms are not enough for waiting until the device is in normal mode
> 
> What is the ultimate result of this?  I'm trying to assess if we want
> to marked it for stable trees or just apply it ready for the next
> merge window.  It think it means that two reads too close to each
> other will always result in an error for the second one rather than 
> the intended delay and then succeed?

Exactly. If one is accessing to fast the second access will fail. Especially
when using a trigger the second channel is never read without error.

> 
> Thanks,
> 
> Jonathan
> > 
> > Signed-off-by: Andreas Klinger <ak@it-klinger.de>
> > ---
> >  drivers/iio/adc/hx711.c | 13 ++++++-------
> >  1 file changed, 6 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> > index d773fd69a76d..eabd2e66aca3 100644
> > --- a/drivers/iio/adc/hx711.c
> > +++ b/drivers/iio/adc/hx711.c
> > @@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
> >  	int i, val;
> >  
> >  	/*
> > -	 * a maximum reset cycle time of 56 ms was measured.
> > -	 * we round it up to 100 ms
> > +	 * in some rare cases the reset takes quite a long time
> > +	 * especially when the channel is changed.
> > +	 * Allow up to one second for it
> >  	 */
> >  	for (i = 0; i < 100; i++) {
> >  		val = gpiod_get_value(hx711_data->gpiod_dout);
> >  		if (!val)
> >  			break;
> > -		/* sleep at least 1 ms */
> > -		msleep(1);
> > +		/* sleep at least 10 ms */
> > +		msleep(10);
> >  	}
> >  	if (val)
> >  		return -EIO;
> > @@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
> >  		 * after a dummy read we need to wait vor readiness
> >  		 * for not mixing gain pulses with the clock
> >  		 */
> > -		ret = hx711_wait_for_ready(hx711_data);
> > -		if (ret)
> > -			return ret;
> > +		val = hx711_wait_for_ready(hx711_data);
> >  	}
> >  
> >  	return val;
> 

-- 

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

end of thread, other threads:[~2017-12-05 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-30 21:44 [PATCH v2 2/2] iio: hx711: fix bug in reset functionality Andreas Klinger
2017-12-02 13:22 ` Jonathan Cameron
2017-12-05 13:12   ` Andreas Klinger

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.