All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: linux-iio@vger.kernel.org, Nuno Sa <Nuno.Sa@analog.com>,
	lars@metafoo.de, Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH v2 02/17] staging:iio:adc:ad7280a: Register define cleanup.
Date: Sun, 6 Feb 2022 17:01:06 +0000	[thread overview]
Message-ID: <20220206170106.69146c7a@jic23-huawei> (raw)
In-Reply-To: <Ybc/bh8Xhm6+EcBC@marsc.168.1.7>

On Mon, 13 Dec 2021 09:41:18 -0300
Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:

> Looks overall good.
> A few comments inline.
> 
> On 12/05, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > 
> > 1. Postfix register addresses with _REG to distinguish them from
> >    fields within the registers
> > 2. Switch to using FIELD_PREP and masks to aid readability.
> > 3. Shorten a few defines to make the lines remain a sensible length.
> > 4. Fix an issue whether where an CTRL_LB field is set in CTRL_HB.
> > 
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>  
> 
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
> > ---
> >  drivers/staging/iio/adc/ad7280a.c | 299 ++++++++++++++++--------------
> >  1 file changed, 161 insertions(+), 138 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
> > index 20183b2ea127..d169c8a7b5f1 100644
> > --- a/drivers/staging/iio/adc/ad7280a.c
> > +++ b/drivers/staging/iio/adc/ad7280a.c
> > @@ -11,6 +11,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/sysfs.h>
> >  #include <linux/spi/spi.h>
> > +#include <linux/bitfield.h>
> >  #include <linux/err.h>
> >  #include <linux/delay.h>
> >  #include <linux/interrupt.h>
> > @@ -23,78 +24,86 @@
> >  #include "ad7280a.h"
> >  
..


> > -/* Bits and Masks */
> > -#define AD7280A_CTRL_HB_CONV_INPUT_ALL			0
> > -#define AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_4	BIT(6)
> > -#define AD7280A_CTRL_HB_CONV_INPUT_6CELL		BIT(7)
> > -#define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST		(BIT(7) | BIT(6))
> > -#define AD7280A_CTRL_HB_CONV_RES_READ_ALL		0
> > -#define AD7280A_CTRL_HB_CONV_RES_READ_6CELL_AUX1_3_4	BIT(4)
...

> > +#define   AD7280A_CTRL_HB_CONV_INPUT_MSK		GENMASK(7, 6)
> > +#define     AD7280A_CTRL_HB_CONV_INPUT_ALL			0
> > +#define     AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_4		1  
> typo, guess you meant
> #define     AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_5		1

That interesting. Was wrong in original code too..
Fixed and added a note to the patch description on this.  Doesn't seem
worth a separate patch as it's not used yet...

Excellent spot.

> 
> > +#define     AD7280A_CTRL_HB_CONV_INPUT_6CELL			2
> > +#define     AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST		3
> > +#define   AD7280A_CTRL_HB_CONV_RREAD_MSK		GENMASK(5, 4)
> > +#define     AD7280A_CTRL_HB_CONV_RREAD_ALL			0
> > +#define     AD7280A_CTRL_HB_CONV_RREAD_6CELL_AUX1_3_4		1  
> Same here
> #define     AD7280A_CTRL_HB_CONV_RREAD_6CELL_AUX1_3_5		1
> 

...

> > @@ -781,17 +805,19 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
> >  		goto out;
> >  
> >  	for (i = 0; i < st->scan_cnt; i++) {
> > -		if (((channels[i] >> 23) & 0xF) <= AD7280A_CELL_VOLTAGE_6) {
> > -			if (((channels[i] >> 11) & 0xFFF) >=
> > -			    st->cell_threshhigh) {
> > +		unsigned int val;
> > +
> > +		val = FIELD_GET(AD7280A_TRANS_READ_CONV_DATA_MSK, channels[i]);  
> AD7280A_TRANS_READ_CONV_DATA_MSK is defined in patch 5.
> Guess its simpler to delay this change to patch 5.

Good find.  I just hit this whilst applying the patch to current kernel
and it not building. oops. Guess I didn't test build at this point in the
series! Indeed make sense to delay this until patch 5.

> 
> > +		if (FIELD_GET(AD7280A_TRANS_READ_CONV_CHANADDR_MSK, channels[i])  
> Same for AD7280A_TRANS_READ_CONV_CHANADDR_MSK.
> 
> > +			<= AD7280A_CELL_VOLTAGE_6_REG) {
> > +			if (val >= st->cell_threshhigh) {  
> These uses of val would also be delayed to patch 5
> 
> >  				u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0,
> >  							 IIO_EV_DIR_RISING,
> >  							 IIO_EV_TYPE_THRESH,
> >  							 0, 0, 0);
> >  				iio_push_event(indio_dev, tmp,
> >  					       iio_get_time_ns(indio_dev));
> > -			} else if (((channels[i] >> 11) & 0xFFF) <=
> > -				   st->cell_threshlow) {
> > +			} else if (val <= st->cell_threshlow) {
> >  				u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0,
> >  							 IIO_EV_DIR_FALLING,
> >  							 IIO_EV_TYPE_THRESH,
> > @@ -800,15 +826,13 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
> >  					       iio_get_time_ns(indio_dev));
> >  			}
> >  		} else {
> > -			if (((channels[i] >> 11) & 0xFFF) >=
> > -			    st->aux_threshhigh) {
> > +			if (val >= st->aux_threshhigh) {
> >  				u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
> >  							IIO_EV_TYPE_THRESH,
> >  							IIO_EV_DIR_RISING);
> >  				iio_push_event(indio_dev, tmp,
> >  					       iio_get_time_ns(indio_dev));
> > -			} else if (((channels[i] >> 11) & 0xFFF) <=
> > -				st->aux_threshlow) {
> > +			} else if (val <= st->aux_threshlow) {
> >  				u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
> >  							IIO_EV_TYPE_THRESH,
> >  							IIO_EV_DIR_FALLING);

...
> > @@ -942,10 +966,9 @@ static int ad7280_probe(struct spi_device *spi)
> >  	st->spi->mode = SPI_MODE_1;
> >  	spi_setup(st->spi);
> >  
> > -	st->ctrl_lb = AD7280A_CTRL_LB_ACQ_TIME(pdata->acquisition_time & 0x3);
> > -	st->ctrl_hb = AD7280A_CTRL_HB_CONV_AVG(pdata->conversion_averaging
> > -			& 0x3) | (pdata->thermistor_term_en ?
> > -			AD7280A_CTRL_LB_THERMISTOR_EN : 0);
> > +	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, pdata->acquisition_time) |
> > +		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, pdata->thermistor_term_en);  
> Writes to the CTRL_LB_REG already set it, but could also set the must_set bit here if want
> FIELD_PREP(AD7280A_CTRL_LB_MUST_SET, 1)

Good point though if we do this it shouldn't really be in this patch
as it's not related to the define cleanup.  Probably one for the todo list rather than
something I'll include in this series.

Thanks,

Jonathan

  reply	other threads:[~2022-02-06 16:54 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-05 20:26 [PATCH v2 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Jonathan Cameron
2021-12-05 20:26 ` [PATCH v2 01/17] staging:iio:adc:ad7280a: Fix handing of device address bit reversing Jonathan Cameron
2021-12-13 12:26   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 02/17] staging:iio:adc:ad7280a: Register define cleanup Jonathan Cameron
2021-12-13 12:41   ` Marcelo Schmitt
2022-02-06 17:01     ` Jonathan Cameron [this message]
2021-12-05 20:26 ` [PATCH v2 03/17] staging:iio:adc:ad7280a: rename _read() to _read_reg() Jonathan Cameron
2021-12-14 17:05   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 04/17] staging:iio:adc:ad7280a: Split buff[2] into tx and rx parts Jonathan Cameron
2021-12-14 17:05   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 05/17] staging:iio:adc:ad7280a: Use bitfield ops to managed fields in transfers Jonathan Cameron
2021-12-14 17:12   ` Marcelo Schmitt
2022-02-06 17:14     ` Jonathan Cameron
2022-02-06 18:02       ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 06/17] staging:iio:adc:ad7280a: Switch to standard event control Jonathan Cameron
2021-12-14 17:41   ` Marcelo Schmitt
2022-02-06 17:34     ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 07/17] staging:iio:adc:ad7280a: Standardize extended ABI naming Jonathan Cameron
2021-12-18 20:17   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 08/17] staging:iio:adc:ad7280a: Drop unused timestamp channel Jonathan Cameron
2021-12-18 20:18   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 09/17] staging:iio:adc:ad7280a: Trivial comment formatting cleanup Jonathan Cameron
2021-12-18 20:21   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 10/17] staging:iio:adc:ad7280a: Make oversampling_ratio a runtime control Jonathan Cameron
2021-12-18 20:22   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 11/17] staging:iio:adc:ad7280a: Cleanup includes Jonathan Cameron
2021-12-18 20:22   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 12/17] staging:iio:ad7280a: Reflect optionality of irq in ABI Jonathan Cameron
2021-12-18 20:30   ` Marcelo Schmitt
2022-01-30 20:05     ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 13/17] staging:iio:adc:ad7280a: Use a local dev pointer to avoid &spi->dev Jonathan Cameron
2021-12-18 20:31   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 14/17] staging:iio:adc:ad7280a: Use device properties to replace platform data Jonathan Cameron
2021-12-18 21:06   ` Marcelo Schmitt
2022-01-30 20:24     ` Jonathan Cameron
2022-02-06 18:06       ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 15/17] dt-bindings:iio:adc:ad7280a: Add binding Jonathan Cameron
2021-12-18 21:18   ` Marcelo Schmitt
2022-01-30 20:29     ` Jonathan Cameron
2022-02-06  2:31       ` Marcelo Schmitt
2022-02-06 18:13         ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 16/17] iio:adc:ad7280a: Document ABI for cell balance switches Jonathan Cameron
2021-12-18 21:20   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 17/17] iio:adc:ad7280a: Move out of staging Jonathan Cameron
2021-12-18 22:08   ` Marcelo Schmitt
2022-01-30 20:46     ` Jonathan Cameron
2022-02-06 18:45       ` Jonathan Cameron
2021-12-13 12:51 ` [PATCH v2 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Marcelo Schmitt
2021-12-16 11:46   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220206170106.69146c7a@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Nuno.Sa@analog.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.