Re: [PATCH v4 4/4] iio: light: tsl2591: improve lux calculation precision
From: Jonathan Cameron
Date: Wed Nov 25 2026 - 20:27:08 EST
On Thu, 22 Oct 2026 20:56:43 +0200
Jan Remes <ciakval@xxxxxxxxx> wrote:
> From: Jan Remes <jan.remes@xxxxxxxxxxxxxxx>
>
> The lux calculation computes the ratio CH1 / CH0 as a truncated integer
> (CH1 * 1000 / CH0) before using it. When CH1 is close to CH0, the
> truncation makes the result off by up to ~35%, e.g. CH0 = 56097,
> CH1 = 55973 at LOW gain and 100ms gives 1.517 lux instead of 1.118 lux.
>
> The formula (CH0 - CH1) * (1 - CH1 / CH0) / CPL is equal to
>
> (CH0 - CH1)^2 * DF / (CH0 * ATIME_ms * AGAIN)
>
> which needs no intermediate ratio. Compute it like that, with a single
> division at the end.
>
> Also report the result in micro-lux instead of milli-lux. At MAX gain
> and 600ms one count is well below 1 mlx, so the milli-lux resolution
> throws away information. The numerator still fits into u64.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Jan Remes <jan.remes@xxxxxxxxxxxxxxx>
Applied patches 3-4 to the testing branch of iio.git
I just merged in rc4 so for 1 and 2 on which to base this.
Thanks,
Jonathan