From: Marten Lindahl <martenli@axis.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Mårten Lindahl" <Marten.Lindahl@axis.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
kernel <kernel@axis.com>
Subject: Re: [PATCH 2/2] iio: light: vcnl4000: Add interrupt support for vcnl4040
Date: Mon, 9 Jan 2023 12:41:56 +0100 [thread overview]
Message-ID: <Y7v9hP60m52vjRMo@axis.com> (raw)
In-Reply-To: <20221223160054.316c473f@jic23-huawei>
On Fri, Dec 23, 2022 at 05:00:54PM +0100, Jonathan Cameron wrote:
> On Tue, 20 Dec 2022 22:49:59 +0100
> Mårten Lindahl <marten.lindahl@axis.com> wrote:
>
> > Add support to configure proximity sensor interrupts and threshold
> > limits for vcnl4040. If an interrupt is detected an event will be
> > pushed to the event interface.
> >
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> Hi,
>
> Code looks good in general. A few readability related suggestions inline.
>
> Thanks,
>
> Jonathan
Hi Jonathan!
Thank you. Please see my reflections below.
>
> > ---
> > drivers/iio/light/vcnl4000.c | 163 +++++++++++++++++++++++++++++++++++
> > 1 file changed, 163 insertions(+)
> >
> > diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> > index 142d1760f65d..61d18c404ea6 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -60,8 +60,11 @@
>
> ...
>
> > /* Bit masks for interrupt registers. */
> > #define VCNL4010_INT_THR_SEL BIT(0) /* Select threshold interrupt source */
> > @@ -138,6 +144,7 @@ struct vcnl4000_data {
> > enum vcnl4000_device_ids id;
> > int rev;
> > int al_scale;
> > + int ps_int;
>
> Bit big for 2 bits ;) Maybe size it same as register size.
>
> Also, probably benefit from a comment as ps_int isn't a particularly obviously name.
Ok, I'll do so.
>
> > const struct vcnl4000_chip_spec *chip_spec;
> > struct mutex vcnl4000_lock;
> > struct vcnl4200_channel vcnl4200_al;
>
>
> ...
>
> >
> > +static int vcnl4040_read_event_config(struct iio_dev *indio_dev,
> > + const struct iio_chan_spec *chan,
> > + enum iio_event_type type,
> > + enum iio_event_direction dir)
> > +{
> > + struct vcnl4000_data *data = iio_priv(indio_dev);
> > +
> > + return (dir == IIO_EV_DIR_RISING) ?
> > + (data->ps_int & 0x01) : (data->ps_int & 0x02) >> 1;
>
> Add some field definitions and FIELD_GET() to extract them.
I will do that.
>
> > +}
> > +
> > +static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
> > + const struct iio_chan_spec *chan,
> > + enum iio_event_type type,
> > + enum iio_event_direction dir, int state)
> > +{
> > + int ret;
> > + u16 val;
> > + struct vcnl4000_data *data = iio_priv(indio_dev);
> > +
> > + mutex_lock(&data->vcnl4000_lock);
> > +
> > + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> > + if (ret < 0)
> > + goto out;
> > +
> > + val = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, ret);
> > +
> > + if (dir == IIO_EV_DIR_RISING)
> > + val = state ? (val | 0x1) : (val & 0x2);
>
> Whilst I'm sure this is correct, it's not easy to follow. Perhaps
> val = state ? (val | 0x1) : (val & ~0x1);
> to make it clear you are turning on an off one bit?
> Also as above, some field definitions may make this easier to follow.
I will do that to make it more clear.
>
> > + else
> > + val = state ? (val | 0x2) : (val & 0x1);
> > +
> > + data->ps_int = val;
> > + val = (ret & ~VCNL4040_PS_CONF2_PS_INT) |
>
> It's been quite a few lines. Probably better to put that ret into
> a reg_val or similarly named field to make it slightly easier to see it
> is retained from above.
>
> > + FIELD_PREP(VCNL4040_PS_CONF2_PS_INT, val);
> > + ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, val);
> > +
> > +out:
> > + mutex_unlock(&data->vcnl4000_lock);
> > + data->chip_spec->set_power_state(data, (bool)data->ps_int);
> the bool cast is a little nasty. Perhaps != 0 is clearer?
I will rework these lines using field definitions. I'll send v2 shortly.
Kind regards
Mårten
>
> > +
> > + return ret;
> > +}
> > +
>
>
prev parent reply other threads:[~2023-01-09 11:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 21:49 [PATCH 0/2] iio: light: vcnl4000: Add vcnl4040 interrupt support Mårten Lindahl
2022-12-20 21:49 ` [PATCH 1/2] iio: light: vcnl4000: Make irq handling more generic Mårten Lindahl
2022-12-23 15:53 ` Jonathan Cameron
2023-01-09 11:32 ` Marten Lindahl
2023-01-09 15:30 ` Jonathan Cameron
2023-01-10 12:24 ` Marten Lindahl
2022-12-20 21:49 ` [PATCH 2/2] iio: light: vcnl4000: Add interrupt support for vcnl4040 Mårten Lindahl
2022-12-23 16:00 ` Jonathan Cameron
2023-01-09 11:41 ` Marten Lindahl [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=Y7v9hP60m52vjRMo@axis.com \
--to=martenli@axis.com \
--cc=Marten.Lindahl@axis.com \
--cc=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/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