From: Jonathan Cameron <jic23@kernel.org>
To: Matt Ranostay <mranostay@gmail.com>, lars@metafoo.de, pmeerw@pmeerw.net
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: chemical: vz89x hardware i2c workaround
Date: Sun, 27 Sep 2015 16:39:07 +0100 [thread overview]
Message-ID: <56080D9B.9040905@kernel.org> (raw)
In-Reply-To: <1442982309-3925-1-git-send-email-mranostay@gmail.com>
On 23/09/15 05:25, Matt Ranostay wrote:
> Chipset sometime updates in the middle of a reading causing it
> to reset the data pointer, and causing invalid reading of previous data.
>
> We can check for this invalid state by reading MSB of the resistance
> reading that is always zero, and by also confirming the VOC_short isn't
> zero.
>
> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
Applied.
> ---
> drivers/iio/chemical/vz89x.c | 23 +++++++++++++++++++++--
> 1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
> index b454200..11e59a5 100644
> --- a/drivers/iio/chemical/vz89x.c
> +++ b/drivers/iio/chemical/vz89x.c
> @@ -85,6 +85,21 @@ static const struct attribute_group vz89x_attrs_group = {
> .attrs = vz89x_attributes,
> };
>
> +/*
> + * Chipset sometime updates in the middle of a reading causing it to reset the
> + * data pointer, and causing invalid reading of previous data.
> + * We can check for this by reading MSB of the resistance reading that is
> + * always zero, and by also confirming the VOC_short isn't zero.
> + */
> +
> +static int vz89x_measurement_is_valid(struct vz89x_data *data)
> +{
> + if (data->buffer[VZ89X_VOC_SHORT_IDX] == 0)
> + return 1;
> +
> + return !!(data->buffer[VZ89X_REG_MEASUREMENT_SIZE - 1] > 0);
> +}
> +
> static int vz89x_get_measurement(struct vz89x_data *data)
> {
> int ret;
> @@ -106,6 +121,10 @@ static int vz89x_get_measurement(struct vz89x_data *data)
> data->buffer[i] = ret;
> }
>
> + ret = vz89x_measurement_is_valid(data);
> + if (ret)
> + return -EAGAIN;
> +
> data->last_update = jiffies;
>
> return 0;
> @@ -113,9 +132,9 @@ static int vz89x_get_measurement(struct vz89x_data *data)
>
> static int vz89x_get_resistance_reading(struct vz89x_data *data)
> {
> - u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
> + u8 *buf = &data->buffer[VZ89X_VOC_RESISTANCE_IDX];
>
> - return buf[0] | (buf[1] << 8) | (buf[2] << 16);
> + return buf[0] | (buf[1] << 8);
> }
>
> static int vz89x_read_raw(struct iio_dev *indio_dev,
>
prev parent reply other threads:[~2015-09-27 15:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-23 4:25 [PATCH] iio: chemical: vz89x hardware i2c workaround Matt Ranostay
2015-09-27 15:39 ` Jonathan Cameron [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=56080D9B.9040905@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=mranostay@gmail.com \
--cc=pmeerw@pmeerw.net \
/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).