All of lore.kernel.org
 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 1/2] iio: light: vcnl4000: Preserve conf bits when toggle power
Date: Mon, 26 Sep 2022 10:22:03 +0200	[thread overview]
Message-ID: <YzFhK27LmQlRW9p/@axis.com> (raw)
In-Reply-To: <20220924173724.374305c9@jic23-huawei>

On Sat, Sep 24, 2022 at 06:37:24PM +0200, Jonathan Cameron wrote:
> On Fri, 23 Sep 2022 13:40:30 +0200
> Mårten Lindahl <marten.lindahl@axis.com> wrote:
> 
> > As the vcnl4040 and vcnl4200 chip uses runtime power management for
> > turning the ambient light and proximity sensors on/off, it overwrites
> > the entire register each time. In ALS_CONF register bit fields ALS_IT,
> > ALS_PERS, ALS_INT_EN are overwritten. In PS_CONF1 register bit fields
> > PS_DUTY, PS_PERS, PS_IT, PS_HD, and PS_INT are overwritten.
> > 
> > Add functions for preserving the affected bit fields when changing power
> > state.
> > 
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> See inline.
> Otherwise looks good to me.
> 
> Jonathan
> 
> > ---
> >  drivers/iio/light/vcnl4000.c | 54 ++++++++++++++++++++++++++++++++++--
> >  1 file changed, 51 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> > index 3db4e26731bb..b2ecf8af1aa5 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -74,6 +74,9 @@
> >  #define VCNL4000_PROX_EN	BIT(1) /* start proximity measurement */
> >  #define VCNL4000_SELF_TIMED_EN	BIT(0) /* start self-timed measurement */
> >  
> > +#define VCNL4040_ALS_CONF_ALS_SD	BIT(0) /* Enable ambient light sensor */
>

Hi Jonathan!

> Comment seems inverted. Bit being set is 'shut down'  I would expand the
> name to
> VCNL4040_ALS_CONF_ALS_SHUTDOWN 
> then drop the comment as the name is self explanatory

Ok, I'll do so. Thanks!

Kind regards
Mårten

> 
> > +#define VCNL4040_PS_CONF1_PS_SD	BIT(0) /* Enable proximity sensor */
> > +
> >  /* Bit masks for interrupt registers. */
> >  #define VCNL4010_INT_THR_SEL	BIT(0) /* Select threshold interrupt source */
> >  #define VCNL4010_INT_THR_EN	BIT(1) /* Threshold interrupt type */
> > @@ -188,16 +191,61 @@ static int vcnl4000_init(struct vcnl4000_data *data)
> >  	return data->chip_spec->set_power_state(data, true);
> >  };
> >  
> > +static ssize_t vcnl4000_write_als_enable(struct vcnl4000_data *data, bool en)
> > +{
> > +	int ret;
> > +
> > +	mutex_lock(&data->vcnl4000_lock);
> > +
> > +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	if (en)
> > +		ret &= ~VCNL4040_ALS_CONF_ALS_SD;
> > +	else
> > +		ret |= VCNL4040_ALS_CONF_ALS_SD;
> > +
> > +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, ret);
> > +
> > +out:
> > +	mutex_unlock(&data->vcnl4000_lock);
> > +
> > +	return ret;
> > +}
> > +
> > +static ssize_t vcnl4000_write_ps_enable(struct vcnl4000_data *data, bool en)
> > +{
> > +	int ret;
> > +
> > +	mutex_lock(&data->vcnl4000_lock);
> > +
> > +	ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	if (en)
> > +		ret &= ~VCNL4040_PS_CONF1_PS_SD;
> > +	else
> > +		ret |= VCNL4040_PS_CONF1_PS_SD;
> > +
> > +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, ret);
> > +
> > +out:
> > +	mutex_unlock(&data->vcnl4000_lock);
> > +
> > +	return ret;
> > +}
> > +
> >  static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on)
> >  {
> > -	u16 val = on ? 0 /* power on */ : 1 /* shut down */;
> >  	int ret;
> >  
> > -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, val);
> > +	ret = vcnl4000_write_als_enable(data, on);
> >  	if (ret < 0)
> >  		return ret;
> >  
> > -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, val);
> > +	ret = vcnl4000_write_ps_enable(data, on);
> >  	if (ret < 0)
> >  		return ret;
> >  
> 

  reply	other threads:[~2022-09-26  8:22 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 [this message]
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

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=YzFhK27LmQlRW9p/@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.