From: Eva Rachel Retuya <eraretuya@gmail.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, outreachy-kernel@googlegroups.com,
Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de,
pmeerw@pmeerw.net, gregkh@linuxfoundation.org
Subject: Re: [PATCH] staging: iio: cdc: ad7746: add additional config defines
Date: Mon, 17 Oct 2016 17:45:37 +0800 [thread overview]
Message-ID: <20161017094535.GB2809@Socrates-DK> (raw)
In-Reply-To: <e0a34a65-5443-7fc4-500c-f1b43b1788dc@metafoo.de>
On Mon, Oct 17, 2016 at 09:51:07AM +0200, Lars-Peter Clausen wrote:
> On 10/17/2016 05:21 AM, Eva Rachel Retuya wrote:
> > Introduce defines for shifting and mask under the config register for
> > better readability.
> >
> > Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
>
> Hi,
>
> Thanks for the patch. Comments inline.
>
> > ---
> > drivers/staging/iio/cdc/ad7746.c | 26 ++++++++++++++++----------
> > 1 file changed, 16 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
> > index f41251c..751f0d1 100644
> > --- a/drivers/staging/iio/cdc/ad7746.c
> > +++ b/drivers/staging/iio/cdc/ad7746.c
> > @@ -70,8 +70,12 @@
> > #define AD7746_EXCSETUP_EXCLVL(x) (((x) & 0x3) << 0)
> >
> > /* Config Register Bit Designations (AD7746_REG_CFG) */
> > -#define AD7746_CONF_VTFS(x) ((x) << 6)
> > -#define AD7746_CONF_CAPFS(x) ((x) << 3)
> > +#define AD7746_CONF_VTFS_SHIFT 6
> > +#define AD7746_CONF_CAPFS_SHIFT 3
> > +#define AD7746_CONF_VTFS_MASK 0x3
> > +#define AD7746_CONF_CAPFS_MASK 0x7
> > +#define AD7746_CONF_VTFS(x) ((x) << AD7746_CONF_VTFS_SHIFT)
> > +#define AD7746_CONF_CAPFS(x) ((x) << AD7746_CONF_CAPFS_SHIFT)
> > #define AD7746_CONF_MODE_IDLE (0 << 0)
> > #define AD7746_CONF_MODE_CONT_CONV (1 << 0)
> > #define AD7746_CONF_MODE_SINGLE_CONV (2 << 0)
> > @@ -224,8 +228,8 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
> > case IIO_CAPACITANCE:
> > cap_setup = (chan->address & 0xFF) | AD7746_CAPSETUP_CAPEN;
> > vt_setup = chip->vt_setup & ~AD7746_VTSETUP_VTEN;
> > - delay = ad7746_cap_filter_rate_table[(chip->config >> 3) &
> > - 0x7][1];
> > + delay = ad7746_cap_filter_rate_table[(chip->config &
> > + AD7746_CONF_CAPFS_MASK) >> AD7746_CONF_CAPFS_SHIFT][1];
>
> This flips the order in which the shift and the mask are applied, that will
> break things. But maybe we should change things so that the mask includes
> the offset and use the GENMASK() macro to create them. This would also allow
> to simplify
>
My bad, I blindly followed the feedback from a recent patch I made on
this driver. I'm aware and wondering why the order got reversed,
should've replied back to that thread.
Anyways, thank you for the feedback. Will send v2 with your proposed
changes.
Eva
> chip->config &= ~AD7746_CONF_CAPFS(AD7746_CONF_CAPFS_MASK);
>
> to
>
> chip->config &= ~AD7746_CONF_CAPFS_MASK;
>
> I'd also introduce a helper variable to move the index calculation outside
> of the array brackets. It is a bit convoluted the way it is right now.
>
> Same comment for the similar changes done below.
>
> >
> > if (chip->capdac_set != chan->channel) {
> > ret = i2c_smbus_write_byte_data(chip->client,
> > @@ -246,8 +250,8 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
> > case IIO_TEMP:
> > vt_setup = (chan->address & 0xFF) | AD7746_VTSETUP_VTEN;
> > cap_setup = chip->cap_setup & ~AD7746_CAPSETUP_CAPEN;
> > - delay = ad7746_cap_filter_rate_table[(chip->config >> 6) &
> > - 0x3][1];
> > + delay = ad7746_cap_filter_rate_table[(chip->config &
> > + AD7746_CONF_VTFS_MASK) >> AD7746_CONF_VTFS_SHIFT][1];
> > break;
> > default:
> > return -EINVAL;
> [...]
> > @@ -636,12 +640,14 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
> > switch (chan->type) {
> > case IIO_CAPACITANCE:
> > *val = ad7746_cap_filter_rate_table[
> > - (chip->config >> 3) & 0x7][0];
> > + (chip->config & AD7746_CONF_CAPFS_MASK) >>
> > + AD7746_CONF_CAPFS_SHIFT][0];
> > ret = IIO_VAL_INT;
> > break;
> > case IIO_VOLTAGE:
> > *val = ad7746_vt_filter_rate_table[
> > - (chip->config >> 6) & 0x3][0];
> > + (chip->config & AD7746_CONF_VTFS_MASK) >>
> > + AD7746_CONF_VTFS_SHIFT][0];
> > break;
> > default:
> > ret = -EINVAL;
> >
>
prev parent reply other threads:[~2016-10-17 9:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-17 3:21 [PATCH] staging: iio: cdc: ad7746: add additional config defines Eva Rachel Retuya
2016-10-17 7:51 ` Lars-Peter Clausen
2016-10-17 9:45 ` Eva Rachel Retuya [this message]
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=20161017094535.GB2809@Socrates-DK \
--to=eraretuya@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=outreachy-kernel@googlegroups.com \
--cc=pmeerw@pmeerw.net \
/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 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).