Message ID | cover.1683541225.git.mazziesaccount@gmail.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2066050vqo; Mon, 8 May 2023 04:05:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Xe27z0n0KQoDCw4sO7Fi5EyS+1A7gZvmm/lh1J1HsDS4azOWRoCl0K4dJSWevyclEX+mL X-Received: by 2002:a05:6a20:8f06:b0:ff:e397:a87a with SMTP id b6-20020a056a208f0600b000ffe397a87amr7167062pzk.33.1683543948342; Mon, 08 May 2023 04:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683543948; cv=none; d=google.com; s=arc-20160816; b=DxEtMduCk01rPKOqWOIsrr5NKAjvqhtEprj8g7vu5v6dy8yyzNEkMz3Wlmxv9Tw0WN 1q+UVpALqxq+Y+HNo3dbQsUNJvT2vdDML7ir8k4FIM4VGOmtGoJMhZAC4TywfQmBthKF bj+gSK9/IpbXaLDnvaQYogltVScNb4KY6T6nCmH2Ys6RwSL20MukE6UydYcYgA06ZFD/ pzR0XkX4PQVVgyNL4B4RZMwPuir87uEEtsuQ7EalEtzWRva5Mva0NTslCp1O8JPITlBi dMcoA3gQkMSlfJeSYBl69HNaUhJ+gh8QDL5yDobaLK3843mbIqREkqciNleWoxfsD1Uo pxSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=u4n+sPW796mS9dhJ6fHd9qvr1mW3PkrYQCtXjQ0ZTZo=; b=JjcZA81Id9XoOtGi4jstO/vtLCX32LrbKSEjL7itql2OASmADd0GVzqqpVMuLQSpDE JpZ29EB2r7sGcyTTwPvm3x3rwTCzO04gZ5HDvLsY4g56Cfa6o9/zxYmPlR4WBzI7L516 38uUeyov9M16ENyRkbneoEfQBBirx9HpBf0Y8It+83sHaDkQr9NjKM8S+KPMd4ZTmxOQ tKTtC/iEXmHN5AEovoOCY4CR8bH/fjhAFATW6eXzfzqB3CSLSbYn25VPUrVSS/Yyi4DE 5aUk7C2KaqlKIe9YyOoNJtrPYhL0XfsUAubEHIR8/i2rpE9jcv2qHrHAQL7yw0ycRL/+ /6jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QJ2rbssU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a639d0e000000b0051b9a71329fsi8079057pgd.360.2023.05.08.04.05.35; Mon, 08 May 2023 04:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QJ2rbssU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234658AbjEHKas (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Mon, 8 May 2023 06:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234647AbjEHKap (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 8 May 2023 06:30:45 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B62C924A8D; Mon, 8 May 2023 03:30:43 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2ac831bb762so41740931fa.3; Mon, 08 May 2023 03:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683541842; x=1686133842; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=u4n+sPW796mS9dhJ6fHd9qvr1mW3PkrYQCtXjQ0ZTZo=; b=QJ2rbssUzSgbKCZkXM9w7Jy0q9Ix8lJSjNabHHhe83scfou2njTVA3OeVd6BRwpSAS Y2kXOkoQHhszriKKexHeyuv5TkLFALBm0HfQ8P8OcZZDMbXMKdBDppYtwoAh1uv+jt9c S1fIL9/nb7bkjAY4tGXwjoRoolDp+C6Oum9P5o1ksQqlrYU8YSrY1Lm6BIbElpSNWhmR CiTm/JmGS5ZaLUBN6uVGcpo3AdXaDcSzVzPmCytsq14l3uPhMCdWWN0UxSKLFmvfYIHW K4YYUiGoWmu7o3Uklb0nH1xljrlZKEWBLdJnaMrmuzL12a5oh5J6YSuup+RrDFVGgrfP nZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683541842; x=1686133842; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u4n+sPW796mS9dhJ6fHd9qvr1mW3PkrYQCtXjQ0ZTZo=; b=idry36PbWBvxLmL6t2TRuwP2KC1Rxmfi3IAj2Mm4a2HoeGPXh7cEMxNH4M7LduKo/B HZJfEjaAnQ322dW1v2I/wkfqFej0+N5Jc/VSQnHznVfTp8nM415GDlVbpZz2mBINlhMT 4c4xWNz+CUOG9O+/dfZm5FlooX0S1wRPyrOWLfAppDqpeFTQGe1eR9cVpCYuCipd1MZ9 WCQfLp1f/VvxvrRwRGu4jfJQx/+R50q3A2LpL5unxuAuQ2AUghONw9wcudDCuniI1gQX 82QKSfUTMVy3dZVfMLLTvwOVYyL8Bv3+jwhwnwLYZE1oTYdYmAtbmOoRcF6tLGB/lODH ascg== X-Gm-Message-State: AC+VfDw+hybmBte7tWtAnHdQNtSXLtJj60lO+UR6+o+iEfEIaFb3h0Q3 9n3DJLi3lsu8wmMTj/gwMWA= X-Received: by 2002:a2e:9e45:0:b0:2ac:7764:aa4 with SMTP id g5-20020a2e9e45000000b002ac77640aa4mr2886398ljk.10.1683541841688; Mon, 08 May 2023 03:30:41 -0700 (PDT) Received: from fedora (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id w8-20020a2e9bc8000000b002a8b205bb50sm1104959ljj.61.2023.05.08.03.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 03:30:40 -0700 (PDT) Date: Mon, 8 May 2023 13:30:28 +0300 From: Matti Vaittinen <mazziesaccount@gmail.com> To: Matti Vaittinen <mazziesaccount@gmail.com>, 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>, Matti Vaittinen <mazziesaccount@gmail.com>, 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 Subject: [PATCH v5 0/5] Support ROHM BU27008 RGB sensor Message-ID: <cover.1683541225.git.mazziesaccount@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tywmqNVigfIf5Z/k" Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765323779343293318?= X-GMAIL-MSGID: =?utf-8?q?1765323779343293318?= |
Series | Support ROHM BU27008 RGB sensor | |
Message
Matti Vaittinen
May 8, 2023, 10:30 a.m. UTC
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. 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. Finally, the scales_available is also provided for all other channels except the IR channel, which does not allow the scale to be changed. The sensor provides a data-ready IRQ and the driver implements a triggered buffer mode using this IRQ as a trigger. Finally, the series introduces generic iio_validate_own_trigger() helper which can be used as a validate_trigger callback for drivers which require the trigger and iio-device to be parented by same device. The KX022A driver is converted to use this new callback instead of rolling it's own function. The new helper and KX022A can be merged in as independent changes if need be. Revision history v3 => v4: iio_validate_own_trigger: - kernel-doc fix bu27008 driver fixes: - re-enable IRQ in trigger renable-callback - do trigger setup on own function - drop regmap lock - configure channels in appropriate callback v3 => v4: bu27008 driver fixes: - Drop thread from device IRQ handler - Styling and some minor improvements - Use kernel-doc for enums - Correctly order entries in Makefile v2 => v3: dt-bindings: - No changes iio_validate_own_trigger: - subject fix bu27008: - Mostly styling based on comments from Andy and Andi More accurate changelog in individual patches v1 => v2: dt-bindings: - Fix issues pointed by Krzysztof. bu27008 driver: - Fix issues pointed by Jonathan Add new helper for validating own trigger More accurate changelog in individual patches --- Matti Vaittinen (5): dt-bindings: iio: light: ROHM BU27008 iio: trigger: Add simple trigger_validation helper iio: kx022a: Use new iio_validate_own_trigger() iio: light: ROHM BU27008 color sensor MAINTAINERS: Add ROHM BU27008 .../bindings/iio/light/rohm,bu27008.yaml | 49 + MAINTAINERS | 3 +- drivers/iio/accel/kionix-kx022a.c | 13 +- drivers/iio/industrialio-trigger.c | 22 +- drivers/iio/light/Kconfig | 14 + drivers/iio/light/Makefile | 1 + drivers/iio/light/rohm-bu27008.c | 1026 +++++++++++++++++ include/linux/iio/trigger.h | 1 + 8 files changed, 1115 insertions(+), 14 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/light/rohm,bu27008.yaml create mode 100644 drivers/iio/light/rohm-bu27008.c
Comments
On Mon, 8 May 2023 13:30:28 +0300 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > Add support for ROHM BU27008 RGB sensor. Series applied to the togreg branch of iio.git and pushed out initially as testing for all the normal reasons. Thanks, Jonathan > > 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. > > 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. > > Finally, the scales_available is also provided for all other channels > except the IR channel, which does not allow the scale to be changed. > > The sensor provides a data-ready IRQ and the driver implements a > triggered buffer mode using this IRQ as a trigger. > > Finally, the series introduces generic iio_validate_own_trigger() helper > which can be used as a validate_trigger callback for drivers which > require the trigger and iio-device to be parented by same device. The > KX022A driver is converted to use this new callback instead of rolling > it's own function. The new helper and KX022A can be merged in as > independent changes if need be. > > > Revision history > v3 => v4: > iio_validate_own_trigger: > - kernel-doc fix > bu27008 driver fixes: > - re-enable IRQ in trigger renable-callback > - do trigger setup on own function > - drop regmap lock > - configure channels in appropriate callback > v3 => v4: > bu27008 driver fixes: > - Drop thread from device IRQ handler > - Styling and some minor improvements > - Use kernel-doc for enums > - Correctly order entries in Makefile > v2 => v3: > dt-bindings: > - No changes > iio_validate_own_trigger: > - subject fix > bu27008: > - Mostly styling based on comments from Andy and Andi > > More accurate changelog in individual patches > > v1 => v2: > dt-bindings: > - Fix issues pointed by Krzysztof. > bu27008 driver: > - Fix issues pointed by Jonathan > Add new helper for validating own trigger > > More accurate changelog in individual patches > > --- > > Matti Vaittinen (5): > dt-bindings: iio: light: ROHM BU27008 > iio: trigger: Add simple trigger_validation helper > iio: kx022a: Use new iio_validate_own_trigger() > iio: light: ROHM BU27008 color sensor > MAINTAINERS: Add ROHM BU27008 > > .../bindings/iio/light/rohm,bu27008.yaml | 49 + > MAINTAINERS | 3 +- > drivers/iio/accel/kionix-kx022a.c | 13 +- > drivers/iio/industrialio-trigger.c | 22 +- > drivers/iio/light/Kconfig | 14 + > drivers/iio/light/Makefile | 1 + > drivers/iio/light/rohm-bu27008.c | 1026 +++++++++++++++++ > include/linux/iio/trigger.h | 1 + > 8 files changed, 1115 insertions(+), 14 deletions(-) > create mode 100644 Documentation/devicetree/bindings/iio/light/rohm,bu27008.yaml > create mode 100644 drivers/iio/light/rohm-bu27008.c >
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
On 6/9/23 20:19, Jonathan Cameron wrote: > On Fri, 9 Jun 2023 15:46:21 +0300 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> 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? > > History... > >> (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. > > IIO_VAL_INTO_PLUS_NANO might solve this > and you'll need to provide the callback write_raw_get_fmt() if you aren't > already so that the conversion from string to val and val2 takes into > account that the driver expects val2 to be *10^-9 > It seems the biggest problem (once again) was my ignorance :) I didn't know of write_raw_get_fmt(). I think You just really saved my day! After a quick glance it seems to me that all I need to do is indeed just to implement the write_raw_get_fmt() callback in BU27xxx drivers. I was already getting a bit uncomfortable as I have promised to do few other things and I just hit this issue - which seemed much bigger that it now is. On top of this I'll be in Embedded Linux Conf for the last week of June (I hope to meet some of you guys there!) - and after that I plan to take a month off... So, things started to pile up once again. Now, Jonathan just lifted off a rock from my shoulders - big thanks! I hope I'll be able to cook some patches Today or tomorrow. > > Given that I think you just need to have the driver tell the core it wants > IIO_VAL_INT_PLUS_NANO. Problem still occurs, but several orders of magnitude > smaller. Several magnitudes indeed! > But I may be miss understanding. No :) It was me who didn't (once again) see all the cool things provided by IIO :) Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~