From: Jonathan Cameron <jic23@kernel.org>
To: Robert Ijtsma via B4 Relay <devnull+robertijtsma.gmail.com@kernel.org>
Cc: robertijtsma@gmail.com, "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Matti Vaittinen" <mazziesaccount@gmail.com>
Subject: Re: [PATCH v3 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
Date: Sat, 28 Nov 2026 01:42:14 +0000 [thread overview]
Message-ID: <20261128014214.1541d7ee@jic23-hlaptop> (raw)
In-Reply-To: <20261127-iio-tcs3430-v3-2-e191a40a4ae9@gmail.com>
On Fri, 27 Nov 2026 09:12:50 +0100
Robert Ijtsma via B4 Relay <devnull+robertijtsma.gmail.com@kernel.org> wrote:
> From: Robert Ijtsma <robertijtsma@gmail.com>
>
> Add an IIO driver for the ams OSRAM TCS3430 ambient light and CIE 1931
> XYZ tristimulus color sensor (found at I2C address 0x39 on devices such
> as the Microsoft Surface Pro X).
>
> Unlike the older TAOS RGBC drivers (tcs3414, tcs3472) that use the 0x80
> COMMAND-bit SMBus protocol and RGBC channels, and unlike the banked
> MAZeT/JENCOLOR as73211 driver, the TCS3430 uses ams's direct-addressed
> 0x80..0xdd register map and exposes Z, Y, IR1, and X tristimulus channels.
>
> The driver exposes:
> - Illuminance (photopic Y channel) with raw counts and lux scale
> - Modified intensity channels for X, Y, Z, and IR1
> - Selectable scale and integration time via the IIO GTS helper across
> 1x/4x/16x/64x/128x gain and 50.04/100.08/200.16/400.32 ms integration
> time settings
> - Regulator management and system sleep suspend/resume support
>
> Tested on Microsoft Surface Pro X SQ2 (SC8180X).
>
> Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
Looking good.
Only significant remaining question I had is over scaling of the
channels other than the illuminance one.
I'm not sure how easy it is to make the gts helper deal with the
different scales (it was written much more recently than when I last
touched a light sensor and I haven't used it myself yet as a result!)
+CC Matti for input on this.
Thanks,
Jonathan
> diff --git a/drivers/iio/light/tcs3430.c b/drivers/iio/light/tcs3430.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..06e5ecd91f6502a1d8c99de4707e590dac4f5beb
> --- /dev/null
> +++ b/drivers/iio/light/tcs3430.c
> @@ -0,0 +1,521 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * ams OSRAM TCS3430 ambient light and CIE 1931 XYZ sensor driver
> + *
> + * Copyright (C) 2026 Robert Ijtsma <robertijtsma@gmail.com>
> + *
> + * Datasheet:
> + * https://look.ams-osram.com/m/43d518b4cd81e3f2/original/TCS3430-DS000539.pdf
> + */
> +
> +#include <linux/array_size.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/cleanup.h>
> +#include <linux/device.h>
I didn't check, but do we need device.h itself or can we use
more specific headers like dev_printk.h?
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>
> +
> +#include <asm/byteorder.h>
> +
> +/*
> + * Photopic Y channel typical sensitivity from datasheet optical characteristics:
> + * ~0.537 counts/lux at AGAIN = 16x and ATIME = 100 ms (36 cycles), giving:
> + * lux/count = 2980 / (gain * integration_time_ms)
> + *
> + * At minimum gain (1x) and shortest integration time (50.04 ms, 18 cycles):
> + * max_scale = 2980 / 50.04 = 59.552358113 lux/count
> + */
> +#define TCS3430_MAX_SCALE_INT 59
> +#define TCS3430_MAX_SCALE_NANO 552358113
> +static int tcs3430_apply_itime(struct tcs3430_data *data, u8 atime)
> +{
> + int ret;
> +
> + ret = regmap_write(data->regmap, TCS3430_REG_ATIME, atime);
> + if (ret)
> + return ret;
> +
> + data->atime = atime;
Trivial but slightly preference for a blank line before simple
returns of 0 for success like these. Just makes them stand out a tiny
bit more as being the good path.
> + return 0;
> +}
> +
> +#define TCS3430_INTENSITY_CHANNEL(_mod, _addr) { \
> + .type = IIO_INTENSITY, \
> + .modified = 1, \
> + .channel2 = (_mod), \
> + .address = (_addr), \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \
> + .info_mask_shared_by_all_available = \
> + BIT(IIO_CHAN_INFO_INT_TIME), \
> +}
> +
> +static const struct iio_chan_spec tcs3430_channels[] = {
> + {
> + .type = IIO_LIGHT,
> + .address = TCS3430_REG_CH1DATAL,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
Scale is a bit of a weird concept for the various intensity channels
but I'd still expect that if we change this scale, they would be affected
(if it modifies AGAIN rather than the integration time that you are exposing).
Hence I'm a little surprised to see it only here.
The actual scaling doesn't matter for intensity channels because they are
normally poorly defined though for CIE XYZ we are in a better state than
normal so if the gain doubles they should double. I'd expect the same
for the IR channel. Or am I missing something?
Upshot, I think this is either shared_by_all or separate but for
each element with appropriate additional scale factors rolled in
I played with an LLM and it thinks the values are a bit wrong for the
listed 2700K white test relecting perhaps a small channel specific scaling?
I'm not immediately sure how we do that with the gts code.
Perhaps just keeping the one simple scaling control is the right option
but I think we do need to expose it for all channels.
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
> + .info_mask_shared_by_all_available =
> + BIT(IIO_CHAN_INFO_INT_TIME),
> + },
> + TCS3430_INTENSITY_CHANNEL(IIO_MOD_Z, TCS3430_REG_CH0DATAL),
> + TCS3430_INTENSITY_CHANNEL(IIO_MOD_Y, TCS3430_REG_CH1DATAL),
> + TCS3430_INTENSITY_CHANNEL(IIO_MOD_LIGHT_IR, TCS3430_REG_CH2DATAL),
> + TCS3430_INTENSITY_CHANNEL(IIO_MOD_X, TCS3430_REG_CH3DATAL),
> +};
prev parent reply other threads:[~2026-11-28 1:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 8:12 [PATCH v3 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma via B4 Relay
2026-11-27 8:12 ` [PATCH v3 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
2026-11-27 8:12 ` [PATCH v3 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
2026-11-27 17:45 ` Andy Shevchenko
2026-11-28 1:17 ` Jonathan Cameron
2026-11-28 1:42 ` Jonathan Cameron [this message]
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=20261128014214.1541d7ee@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=devnull+robertijtsma.gmail.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robertijtsma@gmail.com \
--cc=robh@kernel.org \
/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