From: Jonathan Cameron <jic23@kernel.org>
To: "Mårten Lindahl" <marten.lindahl@axis.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>, <linux-iio@vger.kernel.org>,
<kernel@axis.com>
Subject: Re: [PATCH 2/2] iio: light: vcnl4000: Add interrupt support for vcnl4040
Date: Fri, 23 Dec 2022 16:00:54 +0000 [thread overview]
Message-ID: <20221223160054.316c473f@jic23-huawei> (raw)
In-Reply-To: <20221220214959.2289330-3-marten.lindahl@axis.com>
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
> ---
> 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.
> 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.
> +}
> +
> +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.
> + 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?
> +
> + return ret;
> +}
> +
next prev parent reply other threads:[~2022-12-23 15:47 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 [this message]
2023-01-09 11:41 ` Marten Lindahl
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=20221223160054.316c473f@jic23-huawei \
--to=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=marten.lindahl@axis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox