devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Zhigang Shi <Zhigang.Shi@liteon.com>,
	Paul Gazzillo <paul@pgazz.com>,
	Shreeya Patel <shreeya.patel@collabora.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Mutanen,
	Mikko" <Mikko.Mutanen@fi.rohmeurope.com>
Subject: Re: [PATCH v5 0/5] Support ROHM BU27008 RGB sensor
Date: Fri, 9 Jun 2023 15:46:21 +0300	[thread overview]
Message-ID: <0173eb2b-b6a5-b90a-9740-7a65f806fabc@gmail.com> (raw)
In-Reply-To: <cover.1683541225.git.mazziesaccount@gmail.com>

On 5/8/23 13:30, Matti Vaittinen wrote:
> Add support for ROHM BU27008 RGB sensor.
> 
> The ROHM BU27008 is a sensor with 5 photodiodes (red, green, blue, clear
> and IR) with four configurable channels. Red and green being always
> available and two out of the rest three (blue, clear, IR) can be
> selected to be simultaneously measured. Typical application is adjusting
> LCD backlight of TVs, mobile phones and tablet PCs.
> 
> This series supports reading the RGBC and IR channels using IIO
> framework. However, only two of the BC+IR can be enabled at the same
> time. Series adds also support for scale and integration time
> configuration, where scale consists of impact of both the integration
> time and hardware gain. The gain and time support is backed by the newly
> introduced IIO GTS helper. This series depends on GTS helper patches
> added in BU27034 support series which is already merged in iio/togreg
> which this series is based on.

I started adding support for the BU27010 RGBC + flickering sensor to the 
BU27008 driver. While at it, I wrote some test(s) which try using also 
the 'insane' gain settings.

What I found out is that the scale setting for BU27008 is broken for 
smallest scales: 0.007812500 0.003906250 0.001953125

Reason is the accuracy.

The GTS helpers were made to use NANO scale accuracy. 999999999 is still 
fitting in an 32 bit integer after all :) This allows to handle greater 
"total gains".

The IIO scale setting interface towards the drivers seems to crop the 
val2 to micros (6 digits). This means that when user writes scale 
0.001953125 via sysfs - the driver will get val = 0, val2 = 1953. 
Currently the BU27008 driver (and probably also the BU27035 which I have 
not yet checked) will pass this value to GTS-helpers - which try to use 
it in computations where scale is tried to be converted to gain + 
integration time settings. This will fail because of rounding error this 
leads to.

Regarding the BU27* drivers I see this bug as annoying rather than 
urgent. Bug will appear only with the very smallest of scales - which 
means gains of magnitude ~1000X with the longest integration times - and 
as someone once said - 1000X gains sound pretty insane as errors will 
probably get quite big... Still, this is a bug - and it bothers me :)

What comes to fixing this - my first thought regarding "the right thing 
to do" would be improving the IIO scale setting accuracy. I wonder if 
there has been some heavy reason(s) to only provide 6 digits of val2? (I 
haven't yet looked how IIO formats the val2 from user input so I may be 
very ignorant here). For userland this fix should be relatively 
invisible - the write of for example 0.001953125 is seemingly successful 
from the user-space POV. IIO does not warn about the excess accuracy.

I am not saying this change would be risk-free. For sure there is an 
application somewhere passing this kind of 'high accuracy' scale values 
to sysfs. And it may be we have a driver which is going to have a hiccup 
is such value is passed to it - but I'd argue the driver should be fixed 
then. It's easier for a driver to drop the excess digits by a division - 
than it is to generate the missing digits...

...which leads us to the other potential way of papering over this 
issue. We could go on defining a set of "magic scale values" in the 
bu27008 driver, namely the 1953, 3906 and 7812 - and when these are used 
as val2 just assume it means 001953125, 003906250 and 007812500 
respectively. This would be quick and simple fix - but it would also 
mean this is a driver specific hack.

Finally, we could dive into GTS helpers and drop the accuracy of those 
to MIRCO scale instead of the NANO. If this was to be done it might be 
best to change the BU27008 and BU27034 intensity channel scales to start 
from bigger integers. Yes, it would potentially break any existing user 
of those intensity channels - but I suspect the amount of such users is 
still 0.

Finally, if we really want to keep the accuracy of scales in micros and 
not support nanos, then we probably should adjust the available scales 
displaying to not accept IIO_VAL_INT_PLUS_NANO type lists...

Yours,
	-- Matti

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


  parent reply	other threads:[~2023-06-09 12:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 10:30 [PATCH v5 0/5] Support ROHM BU27008 RGB sensor Matti Vaittinen
2023-05-08 10:30 ` [PATCH v5 1/5] dt-bindings: iio: light: ROHM BU27008 Matti Vaittinen
2023-05-08 10:31 ` [PATCH v5 2/5] iio: trigger: Add simple trigger_validation helper Matti Vaittinen
2023-05-08 10:31 ` [PATCH v5 3/5] iio: kx022a: Use new iio_validate_own_trigger() Matti Vaittinen
2023-05-08 10:39 ` [PATCH v5 4/5] iio: light: ROHM BU27008 color sensor Matti Vaittinen
2023-05-20 16:44   ` Jonathan Cameron
2023-05-08 10:39 ` [PATCH v5 5/5] MAINTAINERS: Add ROHM BU27008 Matti Vaittinen
2023-05-20 16:46 ` [PATCH v5 0/5] Support ROHM BU27008 RGB sensor Jonathan Cameron
2023-06-09 12:46 ` Matti Vaittinen [this message]
2023-06-09 17:19   ` Jonathan Cameron
2023-06-12  6:36     ` Vaittinen, Matti

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=0173eb2b-b6a5-b90a-9740-7a65f806fabc@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=Mikko.Mutanen@fi.rohmeurope.com \
    --cc=Zhigang.Shi@liteon.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=paul@pgazz.com \
    --cc=robh+dt@kernel.org \
    --cc=shreeya.patel@collabora.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;
as well as URLs for NNTP newsgroup(s).