Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Rishi Gupta <gupt21@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] iio: light: veml6030: fix microlux value calculation
Date: Thu, 24 Oct 2024 18:42:45 +0100	[thread overview]
Message-ID: <20241024184245.29374611@jic23-huawei> (raw)
In-Reply-To: <20241019153359.43f0c1af@jic23-huawei>

On Sat, 19 Oct 2024 15:33:59 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Wed, 16 Oct 2024 19:04:31 +0200
> Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:
> 
> > The raw value conversion to obtain a measurement in lux as
> > INT_PLUS_MICRO does not calculate the decimal part properly to display
> > it as micro (in this case microlux). It only calculates the module to
> > obtain the decimal part from a resolution that is 10000 times the
> > provided in the datasheet (0.5376 lux/cnt for the veml6030). The
> > resulting value must still be multiplied by 100 to make it micro.
> > 
> > This bug was introduced with the original implementation of the driver.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 7b779f573c48 ("iio: light: add driver for veml6030 ambient light sensor")
> > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>  
> Applied to the fixes-togreg branch of iio.git.

As per the linux-next merge conflict email that I've just +CC linux-iio on,
I messed this up and it landed on the wrong code block.

Tried again...

Jonathan

> 
> Thanks,
> 
> Jonathan
> 
> > ---
> > I found this almost by chance while testing new supported devices. The
> > decimal part was always suspiciously small, and when I compared samples
> > to the expected value according to the datasheet, it became clear what was
> > going on.
> > 
> > Example with a veml7700 (same resolution as the veml6030):
> > 
> > Resolution for gain = 1/8, IT = 100 ms: 0.5736 lux/cnt.
> > 
> > cat in_illuminance_raw in_illuminance_input
> > 40
> > 21.005040 -> wrong! 40 * 0.5736 is 21.504.
> > 
> > Tested with a veml6035 and a veml7700, the same will happen with the
> > original veml6030, as the operation is identical for all devices.
> > ---
> >  drivers/iio/light/veml6030.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c
> > index d6f3b104b0e6..a0bf03e37df7 100644
> > --- a/drivers/iio/light/veml6030.c
> > +++ b/drivers/iio/light/veml6030.c
> > @@ -691,7 +691,7 @@ static int veml6030_read_raw(struct iio_dev *indio_dev,
> >  			}
> >  			if (mask == IIO_CHAN_INFO_PROCESSED) {
> >  				*val = (reg * data->cur_resolution) / 10000;
> > -				*val2 = (reg * data->cur_resolution) % 10000;
> > +				*val2 = (reg * data->cur_resolution) % 10000 * 100;
> >  				return IIO_VAL_INT_PLUS_MICRO;
> >  			}
> >  			*val = reg;
> > 
> > ---
> > base-commit: 15e7d45e786a62a211dd0098fee7c57f84f8c681
> > change-id: 20241016-veml6030-fix-processed-micro-616d00d555dc
> > 
> > Best regards,  
> 
> 


      reply	other threads:[~2024-10-24 17:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 17:04 [PATCH] iio: light: veml6030: fix microlux value calculation Javier Carrasco
2024-10-19 14:33 ` Jonathan Cameron
2024-10-24 17:42   ` 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=20241024184245.29374611@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=gupt21@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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