From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: robertijtsma@gmail.com
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"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
Subject: Re: [PATCH v3 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
Date: Fri, 27 Nov 2026 19:45:56 +0200 [thread overview]
Message-ID: <awnB1KT-oJQoPjOM@ashevche-desk.local> (raw)
In-Reply-To: <20261127-iio-tcs3430-v3-2-e191a40a4ae9@gmail.com>
On Fri, Nov 27, 2026 at 09:12:50AM +0100, Robert Ijtsma via B4 Relay wrote:
>
> 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).
There are a couple of nit-picks below, but overall LGTM, after addressing them
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
...
> +config TCS3430
> + tristate "ams OSRAM TCS3430 ambient light and CIE 1931 XYZ sensor"
This doesn't scale, but okay, I don't expect this kind of compatible devices
appear in a volume, we may rephrase this later on.
> + depends on I2C
> + select IIO_GTS_HELPER
> + select REGMAP_I2C
> + help
> + If you say yes here you get support for the ams OSRAM TCS3430
> + ambient light and CIE 1931 XYZ tristimulus color sensor.
Usually when it starts with more that a single vendor line of the devices
the list of them is better as it's easier to tweak later on:
If you say yes here you get support for the following sensors:
- ams OSRAM TCS3430 ambient light
- CIE 1931 XYZ tristimulus color
(feel free to amend this example). But if you go to do that, change the
above text to something like
tristate "ams OSRAM TCS3430 ambient light and compatible sensors"
(and sync with other places),
TL;DR: Change if you wish, but I'm okay with the proposed texts for now.
> + This driver can also be built as a module. If so, the module
> + will be called tcs3430.
...
> +static int tcs3430_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + struct tcs3430_data *data;
> + struct iio_dev *indio_dev;
> + unsigned int dev_id;
> + int ret;
> + ret = devm_regulator_get_enable(dev, "vdd");
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to enable vdd supply\n");
Why so early? It's better to avoid touching HW as long as we can, then all
other possible errors will not provoke any glitches and unneeded power
consumption and delays.
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
So, somewhere here (to be robust against the cases when regmap wants to fill
the cache from HW or somebody reads debugfs at the time of initialisation.
> + data = iio_priv(indio_dev);
> + data->regmap = devm_regmap_init_i2c(client, &tcs3430_regmap_config);
> + if (IS_ERR(data->regmap))
> + return dev_err_probe(dev, PTR_ERR(data->regmap),
> + "failed to initialize regmap\n");
> +
> + ret = devm_iio_init_iio_gts(dev, TCS3430_MAX_SCALE_INT,
> + TCS3430_MAX_SCALE_NANO,
> + tcs3430_gain_sel,
> + ARRAY_SIZE(tcs3430_gain_sel),
> + tcs3430_itime_sel,
> + ARRAY_SIZE(tcs3430_itime_sel),
> + &data->gts);
> + if (ret)
> + return ret;
> +
> + data->gain_sel = TCS3430_DEFAULT_GAIN_SEL;
> + data->atime = TCS3430_DEFAULT_ATIME_SEL;
> + dev_set_drvdata(dev, data);
> + ret = devm_mutex_init(dev, &data->lock);
> + if (ret)
> + return ret;
> + ret = regmap_read(data->regmap, TCS3430_REG_ID, &dev_id);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to read device ID\n");
> + if ((dev_id & TCS3430_ID_MASK) != TCS3430_ID_VAL)
> + dev_info(dev, "unexpected part ID 0x%02x\n", dev_id);
> +
> + ret = tcs3430_init_hw(data);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to initialize device\n");
> +
> + ret = devm_add_action_or_reset(dev, tcs3430_power_off, data);
> + if (ret)
> + return ret;
> +
> + indio_dev->name = "tcs3430";
> + indio_dev->info = &tcs3430_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = tcs3430_channels;
> + indio_dev->num_channels = ARRAY_SIZE(tcs3430_channels);
> +
> + return devm_iio_device_register(dev, indio_dev);
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-27 17:46 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 [this message]
2026-11-28 1:17 ` Jonathan Cameron
2026-11-28 1:42 ` Jonathan Cameron
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=awnB1KT-oJQoPjOM@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®