public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
To: "Matti Vaittinen" <mazziesaccount@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Rishi Gupta" <gupt21@gmail.com>, <linux-iio@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 2/2] iio: light: veml6030: fix scale to conform to ABI
Date: Tue, 14 Jan 2025 14:02:50 +0100	[thread overview]
Message-ID: <D71TEJCQD9XK.5FNF9SJLFJ94@gmail.com> (raw)
In-Reply-To: <CANhJrGOya1tmYcovYJZWkWmVE9NdLFHiDw7izmKtfYTXm57GVQ@mail.gmail.com>

On Tue Jan 14, 2025 at 7:43 AM CET, Matti Vaittinen wrote:
...
> > I will give you a simple example, so you can tell me where my reasoning
> > fails:
> >
> > raw = 100 counts
> > scale = 2.1504 lux/count (when IT=25ms and GAIN=1/8)
> > processed = 215.04 lux (raw * scale, ABI compliant for IIO_LIGHT)
>
> Your reasoning does not fail. But, the scale = 1 / (N * total_gain),
> right? (N here depends on how we choose the scale/gain values) Here,
> the total_gain means the effect of both the hardware_gain and the
> integration time.
>
> Hence,
> processed =  X * (raw * scale)
>
> => processed = X * (raw * (1 / (N * total_gain))
> => processed = X * raw / (N * total_gain);
>
> Hence I thought you might be able to get rid of this 64bit division by
> using the total_gain from the iio_gts_get_total_gain() instead of
> using the scale. Or, am I missing something?
>

I am not sure by X you mean the maximum resolution, but if that is the
case, the following would work (pseudo-code):

/* Maximum resolution (2.1504 lux/count) * 10000 */
#define VEML6030_MAX_RES 21504

total_gain = iio_gts_get_total_gain();
processed_int = raw * VEML6030_MAX_RES / total_gain / 10000;
processed_micro = ((raw * VEML6030_MAX_RES / total_gain) % 10000) * 100;

return INT_PLUS_MICRO;

Is that what you meant? For my previous example (100 counts, IT=25ms,
GAIN=1/8 → total_gain = 1 * 1):
processed_int = 100 * 21504 / 1 / 10000; (215)
processed_micro = 100 * 21504 / 1 % 10000 * 100; (40000)
The expected value was 215.04 lux

For IT=800ms, GAIN=2 → total_gain = 32 * 16 = 512
processed_int = 100 * 21504 / 512 / 10000; (0)
processed_micro = 100 * 21504 / 512 % 10000 * 100; (420000)
That is also the expected value: 0.42 lux

Given that the driver supports multiple devices with different maximum
scales (currently 2), it will have to be added to the chip data.

If we are now on the same page, I will implement it like that to drop
64-bit divisions.

Thanks again!

Best regards,
Javier Carrasco

  reply	other threads:[~2025-01-14 13:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 20:50 [PATCH 0/2] iio: light: fix scale in veml6030 Javier Carrasco
2025-01-07 20:50 ` [PATCH 1/2] iio: light: veml6030: extend regmap to support regfields and caching Javier Carrasco
2025-01-12 13:18   ` Jonathan Cameron
2025-01-12 14:10     ` Javier Carrasco
2025-01-12 16:40       ` Jonathan Cameron
2025-01-07 20:50 ` [PATCH 2/2] iio: light: veml6030: fix scale to conform to ABI Javier Carrasco
2025-01-09 17:46   ` Javier Carrasco
2025-01-12 13:22   ` Jonathan Cameron
2025-01-13 11:56   ` Matti Vaittinen
2025-01-13 15:05     ` Javier Carrasco
2025-01-13 19:52       ` Matti Vaittinen
2025-01-13 22:32         ` Javier Carrasco
2025-01-14  6:43           ` Matti Vaittinen
2025-01-14 13:02             ` Javier Carrasco [this message]
2025-01-14 14:26               ` Matti Vaittinen
2025-01-18 12:16                 ` Jonathan Cameron
2025-01-13 10:25 ` [PATCH 0/2] iio: light: fix scale in veml6030 Matti Vaittinen
2025-01-13 11:02   ` 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=D71TEJCQD9XK.5FNF9SJLFJ94@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=gupt21@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox