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 v2 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
Date: Thu, 26 Nov 2026 16:20:35 +0200 [thread overview]
Message-ID: <awhAMzB83rSV9UUZ@ashevche-desk.local> (raw)
In-Reply-To: <20261126-iio-tcs3430-v2-2-6c5329d20919@gmail.com>
On Thu, Nov 26, 2026 at 09:11:48AM +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).
>
> 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).
...
> +config TCS3430
> + tristate "ams OSRAM TCS3430 ambient light and XYZ color sensor"
Make this, top comment in the driver and MODULE_DESCRIPTION() text to be very
similar if not the same.
> + 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.
> +
> + This driver can also be built as a module. If so, the module
> + will be called tcs3430.
...
> +#include <linux/array_size.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/cleanup.h>
> +#include <linux/device.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>
...
> +static const struct regmap_config tcs3430_regmap_config = {
> + .name = "tcs3430",
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = TCS3430_REG_INTENAB,
No cache? Why?
> +};
...
With
struct regmap *map = data->regmap;
at the top of the function helps with this...
> + ret = regmap_write(data->regmap, TCS3430_REG_CFG3,
> + TCS3430_CFG3_DEFAULT);
...to become this.
ret = regmap_write(map, TCS3430_REG_CFG3, TCS3430_CFG3_DEFAULT);
> + if (ret)
> + return ret;
You may use this trick elsewhere to achieve better readability.
...
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW: {
> + __le16 raw;
> +
> + guard(mutex)(&data->lock);
+ Blank line to make guard()() visible at a glance. Ditto for all such cases.
> + ret = regmap_bulk_read(data->regmap, chan->address, &raw,
> + sizeof(raw));
> + if (ret)
> + return ret;
> + *val = le16_to_cpu(raw);
> + return IIO_VAL_INT;
> + }
...
> +static int tcs3430_set_scale(struct tcs3430_data *data, int val, int val2)
> +{
> + int gain_sel, time_sel, ret;
> + bool keep_time = false;
> +
> + ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, data->atime,
> + val, val2, &gain_sel);
> + if (!ret) {
Why non-standard pattern?
> + keep_time = true;
> + time_sel = data->atime;
> + } else {
> + ret = iio_gts_find_gain_time_sel_for_scale(&data->gts, val, val2,
> + &gain_sel, &time_sel);
> + if (ret)
> + return ret;
> + }
> +
> + if (!keep_time) {
> + ret = tcs3430_apply_itime(data, time_sel);
> + if (ret)
> + return ret;
> + }
> +
> + return tcs3430_apply_gain(data, gain_sel);
> +}
...
> +static int tcs3430_set_itime(struct tcs3430_data *data, int val, int val2)
> +{
> + struct device *dev = regmap_get_device(data->regmap);
> + int prev_gain, prev_time, new_gain, gain_sel, time_sel, ret;
> + bool in_range;
Better to rename to avoid confusion with generic in_range() helper.
> +
> + if (val || !iio_gts_valid_time(&data->gts, val2))
> + return -EINVAL;
> +
> + prev_time = iio_gts_find_int_time_by_sel(&data->gts, data->atime);
> + if (prev_time < 0)
> + return prev_time;
> + if (prev_time == val2)
> + return 0;
> +
> + prev_gain = iio_gts_find_gain_by_sel(&data->gts, data->gain_sel);
> + if (prev_gain < 0)
> + return prev_gain;
> +
> + ret = iio_gts_find_new_gain_by_gain_time_min(&data->gts, prev_gain,
> + prev_time, val2,
> + &new_gain, &in_range);
> + if (ret)
> + return ret;
> + if (!in_range)
> + dev_dbg(dev, "optimal gain out of range for integration time %d\n",
> + val2);
I would make it a single line despite the length.
> +
> + time_sel = iio_gts_find_sel_by_int_time(&data->gts, val2);
> + if (time_sel < 0)
> + return time_sel;
> +
> + gain_sel = iio_gts_find_sel_by_gain(&data->gts, new_gain);
> + if (gain_sel < 0)
> + return gain_sel;
> +
> + ret = tcs3430_apply_itime(data, time_sel);
> + if (ret)
> + return ret;
> +
> + return tcs3430_apply_gain(data, gain_sel);
> +}
...
> +static DEFINE_SIMPLE_DEV_PM_OPS(tcs3430_pm_ops, tcs3430_suspend,
> + tcs3430_resume);
A single line
static DEFINE_SIMPLE_DEV_PM_OPS(tcs3430_pm_ops, tcs3430_suspend, tcs3430_resume);
or wrap on a logical borders
static DEFINE_SIMPLE_DEV_PM_OPS(tcs3430_pm_ops,
tcs3430_suspend, tcs3430_resume);
But the above is only 81 character long.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-26 14:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 8:11 [PATCH v2 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma via B4 Relay
2026-11-26 8:11 ` [PATCH v2 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
2026-11-26 8:11 ` [PATCH v2 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
2026-11-26 8:20 ` sashiko-bot
2026-11-26 14:20 ` Andy Shevchenko [this message]
2026-11-26 14:10 ` [PATCH v2 0/2] iio: light: add support for ams OSRAM TCS3430 Andy Shevchenko
2026-11-26 14:14 ` Robert Ijtsma
2026-11-26 14:21 ` Andy Shevchenko
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=awhAMzB83rSV9UUZ@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