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>,
<linux-kernel@vger.kernel.org>, <kernel@axis.com>
Subject: Re: [PATCH 2/2] iio: light: vcnl4000: Add ps high definition for vcnl4040
Date: Sun, 17 Dec 2023 14:15:54 +0000 [thread overview]
Message-ID: <20231217141554.04c8863d@jic23-huawei> (raw)
In-Reply-To: <20231212-vcnl4000-ps-hd-v1-2-1c62a95828c0@axis.com>
On Fri, 15 Dec 2023 13:43:05 +0100
Mårten Lindahl <marten.lindahl@axis.com> wrote:
> The vcnl4040 proximity sensor defaults to 12 bit data resolution, but
> the chip also supports 16 bit data resolution, which is called proximity
> high definition (PS_HD).
>
> Add read/write attribute for proximity resolution, and read attribute
> for available proximity resolution values for the vcnl4040 chip.
>
> Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
I'll review this on basis the usecase is clear (see reply to cover letter)
The manipulation of the CONF1 and CONF2 registers in a pair is rather odd given you
only want to change one bit here.
Why is that done?
> ---
> drivers/iio/light/vcnl4000.c | 87 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 85 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index fdf763a04b0b..2addff635b79 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -90,6 +90,7 @@
> #define VCNL4040_PS_CONF1_PS_SHUTDOWN BIT(0)
> #define VCNL4040_PS_CONF2_PS_IT GENMASK(3, 1) /* Proximity integration time */
> #define VCNL4040_CONF1_PS_PERS GENMASK(5, 4) /* Proximity interrupt persistence setting */
> +#define VCNL4040_PS_CONF2_PS_HD BIT(11) /* Proximity high definition */
> #define VCNL4040_PS_CONF2_PS_INT GENMASK(9, 8) /* Proximity interrupt mode */
> #define VCNL4040_PS_CONF3_MPS GENMASK(6, 5) /* Proximity multi pulse number */
> #define VCNL4040_PS_MS_LED_I GENMASK(10, 8) /* Proximity current */
> @@ -170,6 +171,11 @@ static const int vcnl4040_ps_calibbias_ua[][2] = {
> {0, 200000},
> };
>
> +static const int vcnl4040_ps_resolutions[2] = {
> + 12,
> + 16
> +};
> +
> static const int vcnl4040_als_persistence[] = {1, 2, 4, 8};
> static const int vcnl4040_ps_persistence[] = {1, 2, 3, 4};
> static const int vcnl4040_ps_oversampling_ratio[] = {1, 2, 4, 8};
> @@ -880,6 +886,54 @@ static ssize_t vcnl4040_write_ps_calibbias(struct vcnl4000_data *data, int val)
> return ret;
> }
>
> +static ssize_t vcnl4040_read_ps_resolution(struct vcnl4000_data *data, int *val, int *val2)
> +{
> + int ret;
> +
> + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
The field seems to be in PS_CONF2. So you are reading a word and I guess that
gets you two registers. Can we not do a byte read to get just CONF2?
> + if (ret < 0)
> + return ret;
> +
> + ret = FIELD_GET(VCNL4040_PS_CONF2_PS_HD, ret);
> + if (ret >= ARRAY_SIZE(vcnl4040_ps_resolutions))
> + return -EINVAL;
> +
> + *val = vcnl4040_ps_resolutions[ret];
> + *val2 = 0;
> +
> + return ret;
> +}
> +
> +static ssize_t vcnl4040_write_ps_resolution(struct vcnl4000_data *data, int val)
> +{
> + unsigned int i;
> + int ret;
> + u16 regval;
> +
> + for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_resolutions); i++) {
> + if (val == vcnl4040_ps_resolutions[i])
> + break;
> + }
> +
> + if (i >= ARRAY_SIZE(vcnl4040_ps_resolutions))
> + return -EINVAL;
> +
> + mutex_lock(&data->vcnl4000_lock);
> +
> + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> + if (ret < 0)
> + goto out_unlock;
> +
> + regval = (ret & ~VCNL4040_PS_CONF2_PS_HD);
> + regval |= FIELD_PREP(VCNL4040_PS_CONF2_PS_HD, i);
> + ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
> + regval);
> +
> +out_unlock:
> + mutex_unlock(&data->vcnl4000_lock);
> + return ret;
> +}
c),
>
next prev parent reply other threads:[~2023-12-17 14:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 12:43 [PATCH 0/2] Introduce new iio resolution standard attribute Mårten Lindahl
2023-12-15 12:43 ` [PATCH 1/2] iio: core: Introduce " Mårten Lindahl
2023-12-15 12:43 ` [PATCH 2/2] iio: light: vcnl4000: Add ps high definition for vcnl4040 Mårten Lindahl
2023-12-17 14:15 ` Jonathan Cameron [this message]
2023-12-18 15:19 ` Mårten Lindahl
2023-12-18 16:00 ` Mårten Lindahl
2023-12-18 18:14 ` Jonathan Cameron
2023-12-17 14:10 ` [PATCH 0/2] Introduce new iio resolution standard attribute Jonathan Cameron
2023-12-18 15:08 ` Mårten 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=20231217141554.04c8863d@jic23-huawei \
--to=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@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