* [PATCH v2 2/3] iio: adc: hx711: optimize performance in read cycle
@ 2019-09-09 12:37 Andreas Klinger
2019-09-15 12:59 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Klinger @ 2019-09-09 12:37 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel
Set gain in hx711_reset() to its default value after a reset cycle. This
omits one precautionary read cycle, because the read is performed in
hx711_set_gain_for_channel() anyway if gain has changed.
Check for DOUT low and if its high wait some time if it goes down
instead of doing a blind reset cycle when DOUT is not down.
This is a performance optimization which allows to query the sensor with
a higher frequency.
Signed-off-by: Andreas Klinger <ak@it-klinger.de>
---
drivers/iio/adc/hx711.c | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index 0678964dbd21..c8686558429b 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -23,6 +23,7 @@
/* gain to pulse and scale conversion */
#define HX711_GAIN_MAX 3
+#define HX711_RESET_GAIN 128
struct hx711_gain_to_scale {
int gain;
@@ -100,7 +101,6 @@ struct hx711_data {
static int hx711_cycle(struct hx711_data *hx711_data)
{
- int val;
unsigned long flags;
/*
@@ -186,8 +186,7 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
static int hx711_reset(struct hx711_data *hx711_data)
{
- int ret;
- int val = gpiod_get_value(hx711_data->gpiod_dout);
+ int val = hx711_wait_for_ready(hx711_data);
if (val) {
/*
@@ -203,22 +202,10 @@ static int hx711_reset(struct hx711_data *hx711_data)
msleep(10);
gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
- ret = hx711_wait_for_ready(hx711_data);
- if (ret)
- return ret;
- /*
- * after a reset the gain is 128 so we do a dummy read
- * to set the gain for the next read
- */
- ret = hx711_read(hx711_data);
- if (ret < 0)
- return ret;
-
- /*
- * after a dummy read we need to wait vor readiness
- * for not mixing gain pulses with the clock
- */
val = hx711_wait_for_ready(hx711_data);
+
+ /* after a reset the gain is 128 */
+ hx711_data->gain_set = HX711_RESET_GAIN;
}
return val;
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/3] iio: adc: hx711: optimize performance in read cycle
2019-09-09 12:37 [PATCH v2 2/3] iio: adc: hx711: optimize performance in read cycle Andreas Klinger
@ 2019-09-15 12:59 ` Jonathan Cameron
2019-10-22 11:58 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2019-09-15 12:59 UTC (permalink / raw)
To: Andreas Klinger; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel
On Mon, 9 Sep 2019 14:37:48 +0200
Andreas Klinger <ak@it-klinger.de> wrote:
> Set gain in hx711_reset() to its default value after a reset cycle. This
> omits one precautionary read cycle, because the read is performed in
> hx711_set_gain_for_channel() anyway if gain has changed.
>
> Check for DOUT low and if its high wait some time if it goes down
> instead of doing a blind reset cycle when DOUT is not down.
>
> This is a performance optimization which allows to query the sensor with
> a higher frequency.
>
> Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Hi Andreas,
This one seems to have a slightly non trivial interaction with patch 1
so will have to wait until the fixes-togreg branch works it's way back
around to the upstream for the togreg branch. Give me a poke if I seem
to have lost it!
Thanks,
Jonathan
> ---
> drivers/iio/adc/hx711.c | 23 +++++------------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> index 0678964dbd21..c8686558429b 100644
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c
> @@ -23,6 +23,7 @@
>
> /* gain to pulse and scale conversion */
> #define HX711_GAIN_MAX 3
> +#define HX711_RESET_GAIN 128
>
> struct hx711_gain_to_scale {
> int gain;
> @@ -100,7 +101,6 @@ struct hx711_data {
>
> static int hx711_cycle(struct hx711_data *hx711_data)
> {
> - int val;
> unsigned long flags;
>
> /*
> @@ -186,8 +186,7 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
>
> static int hx711_reset(struct hx711_data *hx711_data)
> {
> - int ret;
> - int val = gpiod_get_value(hx711_data->gpiod_dout);
> + int val = hx711_wait_for_ready(hx711_data);
>
> if (val) {
> /*
> @@ -203,22 +202,10 @@ static int hx711_reset(struct hx711_data *hx711_data)
> msleep(10);
> gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
>
> - ret = hx711_wait_for_ready(hx711_data);
> - if (ret)
> - return ret;
> - /*
> - * after a reset the gain is 128 so we do a dummy read
> - * to set the gain for the next read
> - */
> - ret = hx711_read(hx711_data);
> - if (ret < 0)
> - return ret;
> -
> - /*
> - * after a dummy read we need to wait vor readiness
> - * for not mixing gain pulses with the clock
> - */
> val = hx711_wait_for_ready(hx711_data);
> +
> + /* after a reset the gain is 128 */
> + hx711_data->gain_set = HX711_RESET_GAIN;
> }
>
> return val;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/3] iio: adc: hx711: optimize performance in read cycle
2019-09-15 12:59 ` Jonathan Cameron
@ 2019-10-22 11:58 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2019-10-22 11:58 UTC (permalink / raw)
To: Andreas Klinger; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel
On Sun, 15 Sep 2019 13:59:48 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Mon, 9 Sep 2019 14:37:48 +0200
> Andreas Klinger <ak@it-klinger.de> wrote:
>
> > Set gain in hx711_reset() to its default value after a reset cycle. This
> > omits one precautionary read cycle, because the read is performed in
> > hx711_set_gain_for_channel() anyway if gain has changed.
> >
> > Check for DOUT low and if its high wait some time if it goes down
> > instead of doing a blind reset cycle when DOUT is not down.
> >
> > This is a performance optimization which allows to query the sensor with
> > a higher frequency.
> >
> > Signed-off-by: Andreas Klinger <ak@it-klinger.de>
> Hi Andreas,
>
> This one seems to have a slightly non trivial interaction with patch 1
> so will have to wait until the fixes-togreg branch works it's way back
> around to the upstream for the togreg branch. Give me a poke if I seem
> to have lost it!
Applied.
Thanks,
Jonathan
>
> Thanks,
>
> Jonathan
>
> > ---
> > drivers/iio/adc/hx711.c | 23 +++++------------------
> > 1 file changed, 5 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> > index 0678964dbd21..c8686558429b 100644
> > --- a/drivers/iio/adc/hx711.c
> > +++ b/drivers/iio/adc/hx711.c
> > @@ -23,6 +23,7 @@
> >
> > /* gain to pulse and scale conversion */
> > #define HX711_GAIN_MAX 3
> > +#define HX711_RESET_GAIN 128
> >
> > struct hx711_gain_to_scale {
> > int gain;
> > @@ -100,7 +101,6 @@ struct hx711_data {
> >
> > static int hx711_cycle(struct hx711_data *hx711_data)
> > {
> > - int val;
> > unsigned long flags;
> >
> > /*
> > @@ -186,8 +186,7 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
> >
> > static int hx711_reset(struct hx711_data *hx711_data)
> > {
> > - int ret;
> > - int val = gpiod_get_value(hx711_data->gpiod_dout);
> > + int val = hx711_wait_for_ready(hx711_data);
> >
> > if (val) {
> > /*
> > @@ -203,22 +202,10 @@ static int hx711_reset(struct hx711_data *hx711_data)
> > msleep(10);
> > gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
> >
> > - ret = hx711_wait_for_ready(hx711_data);
> > - if (ret)
> > - return ret;
> > - /*
> > - * after a reset the gain is 128 so we do a dummy read
> > - * to set the gain for the next read
> > - */
> > - ret = hx711_read(hx711_data);
> > - if (ret < 0)
> > - return ret;
> > -
> > - /*
> > - * after a dummy read we need to wait vor readiness
> > - * for not mixing gain pulses with the clock
> > - */
> > val = hx711_wait_for_ready(hx711_data);
> > +
> > + /* after a reset the gain is 128 */
> > + hx711_data->gain_set = HX711_RESET_GAIN;
> > }
> >
> > return val;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-22 11:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 12:37 [PATCH v2 2/3] iio: adc: hx711: optimize performance in read cycle Andreas Klinger
2019-09-15 12:59 ` Jonathan Cameron
2019-10-22 11:58 ` 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).