Re: [PATCH v1 0/3] Support ROHM BU27008 RGB sensor

From: Vaittinen, Matti
Date: Mon Apr 24 2023 - 01:35:33 EST


On 4/23/23 15:04, Jonathan Cameron wrote:
> On Fri, 21 Apr 2023 12:37:30 +0300
> Matti Vaittinen <mazziesaccount@xxxxxxxxx> 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
>> frameeork. However, only two of the BC+IR can be enabled at the same
>
> framework

Thanks!

>
>> 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.
>>
>> The hardware allows configuring gain setting by writing a 5-bit gain
>> selector value to a register. Part of the gain setting is common for all
>> channels (RGBC + IR) but part of the selector value can be set
>> separately for RGBC and IR:
>>
>> MODE_CONTROL2 REG:
>> bit 7 6 5 4 3 2 1 0
>> -----------------------------------------------------------------
>> | RGB selector |
>> +---------------------------------------+
>> -----------------------------------------------------------------
>> | high bits IR | | low bits IR selector |
>> +---------------+ +-----------------------+
>>
>> In theory it would be possible to set certain separate gain values for
>> RGBC and IR channels, but this gets pretty confusing because there are a
>> few 'unsupported' selector values. If only RGBC or IR was set, some
>> extra handling should be done to prevent the other channel from getting
>> unsupported value due to change in high-bits. Furthermore, allowing the
>> channels to be set different gain values (in some cases when gains are
>> such the HW supports it) would make the cases where also integration
>> time is changed to achieve correct scale ... interesting. It might also
>> be confusing for user to try predicting when setting different scales
>> succeeds and when it does not. Furthermore, if for example the scale
>> setting for RGBC caused IR selector to be invalid - it could also cause
>> the IR scale to "jump" very far from previous value.
>>
>> To make the code simpler and more predictable for users, the current
>> logic is as follows:
>>
>> 1. Prevent setting IR scale. (My assumption is IR is less used than
>> RGBC)
>> 2. When RGBC scale is set, set also the IR-selector to the same value.
>> This prevents unsupported selector values and makes the IR scale changes
>> predictable.
>>
>> The 2) could mean we effectively have the same scale for all channels.
>> Unfortunately, the HW design is slightly peculiar and selector 0 means
>> gain 1X on RGBC but gain 2X on IR. Rest of the selectors equal same gain
>> values on RGBC and IR. The result is that while changin selector from 0
>> => 1 causes RGBC gain to go from 1X => 4X, it causes IR gain to go from
>> 2X => 4X.
>>
>> So, the driver provides separate scale entries for all channels (also
>> RGB and C will have separate gain entries because these channels are of
>> same type as IR channel). This makes it possible for user applications
>> to go read the scales for all channels after setting scale for one (in
>> order to detect the IR scale difference).
>>
>> Having the separate IR scale entry which applications can read to detect
>> "arbitrary scale changes" makes it possible for applications to be
>> written so they can cope if we need to implement the 'allow setting some
>> different gains for IR and RGBC' - later.
>
> Hmm. I'm not sure preventing it is the best approach. That makes for an
> interface that is perhaps even less intuitive than having it affect the
> scales of the other channels. Still having it configurable at all is
> optional from an ABI point of view, so we could go with what you have
> here and see if anyone shouts about it in future.

I am not sure either. This is really a dance between making driver which
is still understandable and maintainable, ABI which allows us to improve
things if needed and providing users the features they need.

So. let's begin with this - and as you say, if it appears to be
suboptimal, then we can re-work it :)

Yours,
-- Matti

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

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