All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
To: "Shardul Deshpande" <iamsharduld@gmail.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: light: veml6075: fix UV index reported at half value
Date: Fri, 26 Jun 2026 15:39:16 +0200	[thread overview]
Message-ID: <DJJ0U2MQA2I9.2UNT5E1OYW733@gmail.com> (raw)
In-Reply-To: <20260626110400.68885-1-iamsharduld@gmail.com>

On Fri Jun 26, 2026 at 1:04 PM CEST, Shardul Deshpande wrote:
> veml6075_get_uvi_micro() normalises the UV index for the configured
> integration time by dividing the summed, responsivity-weighted UVA/UVB
> components by the integration-time scale factor relative to the 50 ms
> base case (which is returned undivided).
>
> The supported integration times are 50, 100, 200, 400 and 800 ms, i.e.
> the register field index int_index in 0..4 selects (50 << int_index) ms,
> so the correct scale factor is 2^int_index == (1 << int_index).
>
> The code instead divides by (2 << int_index) == 2^(int_index + 1), which
> is twice the correct value. The reported UV index is therefore half of
> the true value for every integration time except 50 ms (handled as a
> separate case). As the driver powers up with VEML6075_IT_100_MS, the UV
> index is reported at half value out of the box.
>
> Divide by (1 << int_index) instead; this also matches the undivided
> 50 ms case (1 << 0 == 1).
>
> Fixes: 3b82f43238ae ("iio: light: add VEML6075 UVA and UVB light sensor driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shardul Deshpande <iamsharduld@gmail.com>
> ---
>  drivers/iio/light/veml6075.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/light/veml6075.c b/drivers/iio/light/veml6075.c
> index 59187244a..af71df69f 100644
> --- a/drivers/iio/light/veml6075.c
> +++ b/drivers/iio/light/veml6075.c
> @@ -244,7 +244,7 @@ static int veml6075_get_uvi_micro(struct veml6075_data *data, int uva_comp,
>  	case VEML6075_IT_200_MS:
>  	case VEML6075_IT_400_MS:
>  	case VEML6075_IT_800_MS:
> -		return (uvia_micro + uvib_micro) / (2 << int_index);
> +		return (uvia_micro + uvib_micro) / (1 << int_index);
>  	default:
>  		return -EINVAL;
>  	}

Hi Shardul, thank you for your patch.

I agree with your reasoning, but why don't you get rid of the switch
once the operation is the same for all cases?

Best regards,
Javier

  parent reply	other threads:[~2026-06-26 13:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 11:04 [PATCH] iio: light: veml6075: fix UV index reported at half value Shardul Deshpande
2026-06-26 12:21 ` Andy Shevchenko
2026-06-26 13:39 ` Javier Carrasco [this message]
2026-06-27  8:53 ` [PATCH v2] " Shardul Deshpande
2026-06-27  9:14   ` Javier Carrasco

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=DJJ0U2MQA2I9.2UNT5E1OYW733@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=iamsharduld@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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.