linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	"Paul Cercueil" <paul@crapouillou.net>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	kernel <kernel@axis.com>
Subject: Re: [PATCH v2 2/2] iio: light: vcnl4000: Add ps_it attributes for vcnl4040
Date: Mon, 26 Sep 2022 10:25:38 +0200	[thread overview]
Message-ID: <YzFiAl5zMZjET9em@axis.com> (raw)
In-Reply-To: <20220924174044.44ecb02f@jic23-huawei>

On Sat, Sep 24, 2022 at 06:40:44PM +0200, Jonathan Cameron wrote:
> On Fri, 23 Sep 2022 13:40:31 +0200
> Mårten Lindahl <marten.lindahl@axis.com> wrote:
> 
> > Add read/write attribute for proximity integration time, and read
> > attribute for available proximity integration times for the vcnl4040
> > chip.
> > 
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> Hi Mårten,
> 
> One minor comment inline given I've asked for changes that mean you'll
> probably be doing a v3 anyway.
> 
> Thanks,
> 
> Jonathan
> 
> > ---
> >  drivers/iio/light/vcnl4000.c | 129 ++++++++++++++++++++++++++++++++++-
> >  1 file changed, 126 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> > index b2ecf8af1aa5..056079b592c6 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -17,6 +17,7 @@
> >   *   interrupts (VCNL4040, VCNL4200)
> >   */
> >  
> > +#include <linux/bitfield.h>
> >  #include <linux/module.h>
> >  #include <linux/i2c.h>
> >  #include <linux/err.h>
> > @@ -76,6 +77,7 @@
> >  
> >  #define VCNL4040_ALS_CONF_ALS_SD	BIT(0) /* Enable ambient light sensor */
> >  #define VCNL4040_PS_CONF1_PS_SD	BIT(0) /* Enable proximity sensor */
> > +#define VCNL4040_PS_CONF2_PS_IT	GENMASK(3, 1) /* Proximity integration time */
> >  
> >  /* Bit masks for interrupt registers. */
> >  #define VCNL4010_INT_THR_SEL	BIT(0) /* Select threshold interrupt source */
> > @@ -104,6 +106,17 @@ static const int vcnl4010_prox_sampling_frequency[][2] = {
> >  	{250, 0},
> >  };
> >  
> > +static const int vcnl4040_ps_it_times[][2] = {
> > +	{0, 100},
> > +	{0, 150},
> > +	{0, 200},
> > +	{0, 250},
> > +	{0, 300},
> > +	{0, 350},
> > +	{0, 400},
> > +	{0, 800},
> > +};
> > +
> >  #define VCNL4000_SLEEP_DELAY_MS	2000 /* before we enter pm_runtime_suspend */
> >  
> >  enum vcnl4000_device_ids {
> > @@ -470,6 +483,55 @@ static int vcnl4000_set_pm_runtime_state(struct vcnl4000_data *data, bool on)
> >  	return ret;
> >  }
> >  
> > +static int vcnl4040_read_ps_it(struct vcnl4000_data *data, int *val, int *val2)
> > +{
> > +	int ret;
> > +
> > +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = FIELD_GET(VCNL4040_PS_CONF2_PS_IT, ret);
> > +
> > +	if (ret >= ARRAY_SIZE(vcnl4040_ps_it_times))
> > +		return -EINVAL;
> > +
> > +	*val = vcnl4040_ps_it_times[ret][0];
> > +	*val2 = vcnl4040_ps_it_times[ret][1];
> > +
> > +	return 0;
> > +}
> > +
> > +static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val)
> > +{
> > +	unsigned int i;
> > +	int ret, index = -1;
> > +
> > +	for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_it_times); i++) {
> > +		if (val == vcnl4040_ps_it_times[i][1]) {
> > +			index = i;
> > +			break;
> > +		}
> > +	}
> > +
> > +	if (index < 0)
> > +		return -EINVAL;
> > +
> > +	mutex_lock(&data->vcnl4000_lock);
> > +
> > +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = (ret & ~VCNL4040_PS_CONF2_PS_IT) |
> > +	    FIELD_PREP(VCNL4040_PS_CONF2_PS_IT, index);
> 
> It can be confusing to read ret both as a temporary to build value ad for the
> return code. I would introduce a
> u16 val
> and build the value in that.

Hi Jonathan!

Thanks. I'll do so. As there already is a 'val' I will call it 'regval'.

Kind regards
Mårten
> 
> > +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, ret);
> > +
> > +out:
> > +	mutex_unlock(&data->vcnl4000_lock);
> > +	return ret;
> > +}
> > +

      reply	other threads:[~2022-09-26  8:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 11:40 [PATCH v2 0/2] Add ps_it attributes for vcnl4040 Mårten Lindahl
2022-09-23 11:40 ` [PATCH v2 1/2] iio: light: vcnl4000: Preserve conf bits when toggle power Mårten Lindahl
2022-09-24 16:37   ` Jonathan Cameron
2022-09-26  8:22     ` Marten Lindahl
2022-09-23 11:40 ` [PATCH v2 2/2] iio: light: vcnl4000: Add ps_it attributes for vcnl4040 Mårten Lindahl
2022-09-24 16:40   ` Jonathan Cameron
2022-09-26  8:25     ` 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=YzFiAl5zMZjET9em@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 \
    --cc=paul@crapouillou.net \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).