All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: adc: ti-ads1015: write config register only on change
@ 2017-08-24  8:25 Ladislav Michl
  2017-09-03 15:56 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Ladislav Michl @ 2017-08-24  8:25 UTC (permalink / raw)
  To: linux-iio; +Cc: Daniel Baluta, Jonathan Cameron, Akinobu Mita

There is no point writing ADS1015_CFG_REG when configuration
didn't change. Avoid that.

Cc: Daniel Baluta <daniel.baluta@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 drivers/iio/adc/ti-ads1015.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 7838e39c790c..034e48566ab5 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -240,7 +240,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on)
 static
 int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
 {
-	int ret, pga, dr, conv_time;
+	int ret, pga, dr, dr_old, conv_time;
 	unsigned int old, mask, cfg;
 
 	if (chan < 0 || chan >= ADS1015_CHANNELS)
@@ -256,17 +256,16 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
 		ADS1015_CFG_DR_MASK;
 	cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
 		dr << ADS1015_CFG_DR_SHIFT;
-
 	cfg = (old & ~mask) | (cfg & mask);
 
-	ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
-	if (ret)
-		return ret;
-
-	if (old != cfg || data->conv_invalid) {
-		int dr_old = (old & ADS1015_CFG_DR_MASK) >>
-				ADS1015_CFG_DR_SHIFT;
-
+	if (old != cfg) {
+		ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
+		if (ret)
+			return ret;
+		data->conv_invalid = true;
+	}
+	if (data->conv_invalid) {
+		dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
 		conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]);
 		conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
 		usleep_range(conv_time, conv_time + 1);
-- 
2.11.0

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

* Re: [PATCH 1/2] iio: adc: ti-ads1015: write config register only on change
  2017-08-24  8:25 [PATCH 1/2] iio: adc: ti-ads1015: write config register only on change Ladislav Michl
@ 2017-09-03 15:56 ` Jonathan Cameron
  2017-09-03 16:00   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-09-03 15:56 UTC (permalink / raw)
  To: Ladislav Michl; +Cc: linux-iio, Daniel Baluta, Akinobu Mita

On Thu, 24 Aug 2017 10:25:51 +0200
Ladislav Michl <ladis@linux-mips.org> wrote:

> There is no point writing ADS1015_CFG_REG when configuration
> didn't change. Avoid that.
> 
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Akinobu Mita <akinobu.mita@gmail.com>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>

Fair enough.  Applied to the togreg branch of iio.git which will be
pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ti-ads1015.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 7838e39c790c..034e48566ab5 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -240,7 +240,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on)
>  static
>  int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
>  {
> -	int ret, pga, dr, conv_time;
> +	int ret, pga, dr, dr_old, conv_time;
>  	unsigned int old, mask, cfg;
>  
>  	if (chan < 0 || chan >= ADS1015_CHANNELS)
> @@ -256,17 +256,16 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
>  		ADS1015_CFG_DR_MASK;
>  	cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
>  		dr << ADS1015_CFG_DR_SHIFT;
> -
>  	cfg = (old & ~mask) | (cfg & mask);
>  
> -	ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
> -	if (ret)
> -		return ret;
> -
> -	if (old != cfg || data->conv_invalid) {
> -		int dr_old = (old & ADS1015_CFG_DR_MASK) >>
> -				ADS1015_CFG_DR_SHIFT;
> -
> +	if (old != cfg) {
> +		ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
> +		if (ret)
> +			return ret;
> +		data->conv_invalid = true;
> +	}
> +	if (data->conv_invalid) {
> +		dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
>  		conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]);
>  		conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
>  		usleep_range(conv_time, conv_time + 1);


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

* Re: [PATCH 1/2] iio: adc: ti-ads1015: write config register only on change
  2017-09-03 15:56 ` Jonathan Cameron
@ 2017-09-03 16:00   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-09-03 16:00 UTC (permalink / raw)
  To: Ladislav Michl; +Cc: linux-iio, Daniel Baluta, Akinobu Mita

On Sun, 3 Sep 2017 16:56:35 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu, 24 Aug 2017 10:25:51 +0200
> Ladislav Michl <ladis@linux-mips.org> wrote:
> 
> > There is no point writing ADS1015_CFG_REG when configuration
> > didn't change. Avoid that.
> > 
> > Cc: Daniel Baluta <daniel.baluta@gmail.com>
> > Cc: Jonathan Cameron <jic23@kernel.org>
> > Cc: Akinobu Mita <akinobu.mita@gmail.com>
> > Signed-off-by: Ladislav Michl <ladis@linux-mips.org>  
> 
> Fair enough.  Applied to the togreg branch of iio.git which will be
> pushed out as testing for the autobuilders to play with it.
> 
> Thanks,
> 
> Jonathan

There was a bit of fuzz so please check the result once it is
up in the testing branch.

Jonathan

> 
> > ---
> >  drivers/iio/adc/ti-ads1015.c | 19 +++++++++----------
> >  1 file changed, 9 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> > index 7838e39c790c..034e48566ab5 100644
> > --- a/drivers/iio/adc/ti-ads1015.c
> > +++ b/drivers/iio/adc/ti-ads1015.c
> > @@ -240,7 +240,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on)
> >  static
> >  int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
> >  {
> > -	int ret, pga, dr, conv_time;
> > +	int ret, pga, dr, dr_old, conv_time;
> >  	unsigned int old, mask, cfg;
> >  
> >  	if (chan < 0 || chan >= ADS1015_CHANNELS)
> > @@ -256,17 +256,16 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
> >  		ADS1015_CFG_DR_MASK;
> >  	cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
> >  		dr << ADS1015_CFG_DR_SHIFT;
> > -
> >  	cfg = (old & ~mask) | (cfg & mask);
> >  
> > -	ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
> > -	if (ret)
> > -		return ret;
> > -
> > -	if (old != cfg || data->conv_invalid) {
> > -		int dr_old = (old & ADS1015_CFG_DR_MASK) >>
> > -				ADS1015_CFG_DR_SHIFT;
> > -
> > +	if (old != cfg) {
> > +		ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
> > +		if (ret)
> > +			return ret;
> > +		data->conv_invalid = true;
> > +	}
> > +	if (data->conv_invalid) {
> > +		dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
> >  		conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]);
> >  		conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
> >  		usleep_range(conv_time, conv_time + 1);  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

end of thread, other threads:[~2017-09-03 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24  8:25 [PATCH 1/2] iio: adc: ti-ads1015: write config register only on change Ladislav Michl
2017-09-03 15:56 ` Jonathan Cameron
2017-09-03 16:00   ` 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.