From: Marten Lindahl <martenli@axis.com>
To: Paul Cercueil <paul@crapouillou.net>
Cc: "Mårten Lindahl" <Marten.Lindahl@axis.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"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 3/3] iio: light: vcnl4000: Add ps_it attributes for vcnl4040
Date: Thu, 22 Sep 2022 15:31:20 +0200 [thread overview]
Message-ID: <YyxjqIzNr6Fn9w73@axis.com> (raw)
In-Reply-To: <RC4JIR.84Y31Q6YBI06@crapouillou.net>
On Wed, Sep 21, 2022 at 12:12:27AM +0200, Paul Cercueil wrote:
> Hi Mårten,
>
> Le mar., sept. 20 2022 at 20:09:58 +0200, Mårten Lindahl
> <marten.lindahl@axis.com> a écrit :
> > Add read/write attribute for proximity integration time, and a read
> > attribute for available integration times for the vcnl4040 chip.
> >
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> > ---
> > drivers/iio/light/vcnl4000.c | 83
> > +++++++++++++++++++++++++++++++++++-
> > 1 file changed, 82 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/light/vcnl4000.c
> > b/drivers/iio/light/vcnl4000.c
> > index 9838f0868372..7a207e48335d 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -76,6 +76,8 @@
> >
> > #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 \
> > + (BIT(3) | BIT(2) | BIT(1)) /* Proximity integration time */
Hi Paul!
>
> Use the GENMASK() macro.
>
Will do!
> >
> > /* Bit masks for interrupt registers. */
> > #define VCNL4010_INT_THR_SEL BIT(0) /* Select threshold interrupt
> > source */
> > @@ -103,6 +105,16 @@ static const int
> > vcnl4010_prox_sampling_frequency[][2] = {
> > {125, 0},
> > {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 */
> >
> > @@ -486,6 +498,49 @@ 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 = (ret & VCNL4040_PS_CONF2_PS_IT) >> 1;
>
> Use the FIELD_GET() macro.
>
Will do!
> > +
> > + 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;
> > +
> > + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = (ret & ~VCNL4040_PS_CONF2_PS_IT) | (index << 1);
>
> Use the FIELD_PREP() macro.
>
Will do!
> > +
> > + return i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
> > ret);
> > +}
> > +
> > static int vcnl4000_read_raw(struct iio_dev *indio_dev,
> > struct iio_chan_spec const *chan,
> > int *val, int *val2, long mask)
> > @@ -533,6 +588,13 @@ static int vcnl4000_read_raw(struct iio_dev
> > *indio_dev,
> > default:
> > return -EINVAL;
> > }
> > + case IIO_CHAN_INFO_INT_TIME:
> > + if (chan->type != IIO_PROXIMITY)
> > + return -EINVAL;
> > + ret = vcnl4040_read_ps_it(data, val, val2);
> > + if (ret < 0)
> > + return ret;
> > + return IIO_VAL_INT_PLUS_MICRO;
> > default:
> > return -EINVAL;
> > }
> > @@ -554,6 +616,12 @@ static int vcnl4040_write_raw(struct iio_dev
> > *indio_dev,
> > default:
> > return -EINVAL;
> > }
> > + case IIO_CHAN_INFO_INT_TIME:
> > + if (val != 0)
> > + return -EINVAL;
> > + if (chan->type != IIO_PROXIMITY)
> > + return -EINVAL;
> > + return vcnl4040_write_ps_it(data, val2);
> > default:
> > return -EINVAL;
> > }
> > @@ -900,11 +968,23 @@ static const struct iio_chan_spec
> > vcnl4040_channels[] = {
> > }, {
> > .type = IIO_PROXIMITY,
> > .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> > - BIT(IIO_CHAN_INFO_ENABLE),
> > + BIT(IIO_CHAN_INFO_ENABLE) | BIT(IIO_CHAN_INFO_INT_TIME),
> > .ext_info = vcnl4000_ext_info,
> > }
> > };
> >
> > +static IIO_CONST_ATTR(in_proximity_integration_time_available,
> > + "0.000100 0.000150 0.000200 0.000250 0.000300 0.000350 0.000400
> > 0.000800");
>
> Hmm, this is not how you define a "_available" attribute.
>
> You need to add a
> .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME)
>
> to your iio_chan_spec, then implement the .read_avail callback in your
> iio_info structure.
Ok, I didn't notice that possibility. Thanks, I will do so!
Kind regards
Mårten
>
> Cheers,
> -Paul
>
> > +
> > +static struct attribute *vcnl4040_attributes[] = {
> > + &iio_const_attr_in_proximity_integration_time_available.dev_attr.attr,
> > + NULL,
> > +};
> > +
> > +static const struct attribute_group vcnl4040_attribute_group = {
> > + .attrs = vcnl4040_attributes,
> > +};
> > +
> > static const struct iio_info vcnl4000_info = {
> > .read_raw = vcnl4000_read_raw,
> > };
> > @@ -922,6 +1002,7 @@ static const struct iio_info vcnl4010_info = {
> > static const struct iio_info vcnl4040_info = {
> > .read_raw = vcnl4000_read_raw,
> > .write_raw = vcnl4040_write_raw,
> > + .attrs = &vcnl4040_attribute_group,
> > };
> >
> > static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
> > --
> > 2.30.2
> >
>
>
prev parent reply other threads:[~2022-09-22 13:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 18:09 [PATCH 0/3] Add basic attributes for vcnl4040 Mårten Lindahl
2022-09-20 18:09 ` [PATCH 1/3] iio: light: vcnl4000: Preserve conf bits when toggle power Mårten Lindahl
2022-09-20 22:23 ` Paul Cercueil
2022-09-22 12:18 ` Marten Lindahl
2022-09-20 18:09 ` [PATCH 2/3] iio: light: vcnl4000: Add enable attributes for vcnl4040 Mårten Lindahl
2022-09-20 22:01 ` Paul Cercueil
2022-09-22 13:04 ` Marten Lindahl
2022-09-22 14:10 ` Paul Cercueil
2022-09-22 18:39 ` Marten Lindahl
2022-09-20 18:09 ` [PATCH 3/3] iio: light: vcnl4000: Add ps_it " Mårten Lindahl
2022-09-20 22:12 ` Paul Cercueil
2022-09-22 13:31 ` 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=YyxjqIzNr6Fn9w73@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