mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] iio: light: add support for ams OSRAM TCS3430
@ 2026-11-24 22:46 Robert Ijtsma via B4 Relay
  2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
  2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
  0 siblings, 2 replies; 7+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-iio, devicetree, linux-kernel, Robert Ijtsma

Add Devicetree binding documentation and an IIO driver for the ams OSRAM
TCS3430 ambient light and CIE 1931 XYZ tristimulus color sensor.

Tested on Microsoft Surface Pro X SQ2 (SC8180X), where the sensor is
connected on I2C at 0x39 and used for ambient light sensing.

Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
Robert Ijtsma (2):
      dt-bindings: iio: light: add ams OSRAM TCS3430
      iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver

 .../devicetree/bindings/iio/light/ams,tcs3430.yaml |  52 ++++
 MAINTAINERS                                        |   7 +
 drivers/iio/light/Kconfig                          |  10 +
 drivers/iio/light/Makefile                         |   1 +
 drivers/iio/light/tcs3430.c                        | 345 +++++++++++++++++++++
 5 files changed, 415 insertions(+)
---
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
change-id: 20261124-iio-tcs3430-2f53879527ed

Best regards,
--  
Robert Ijtsma <robertijtsma@gmail.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] dt-bindings: iio: light: add ams OSRAM TCS3430
  2026-11-24 22:46 [PATCH 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma via B4 Relay
@ 2026-11-24 22:46 ` Robert Ijtsma via B4 Relay
  2026-11-25  7:43   ` Krzysztof Kozlowski
  2026-11-25  8:02   ` Joshua Crofts
  2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
  1 sibling, 2 replies; 7+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-iio, devicetree, linux-kernel, Robert Ijtsma

From: Robert Ijtsma <robertijtsma@gmail.com>

Add Devicetree binding schema for the ams OSRAM TCS3430 ambient light
and CIE 1931 XYZ tristimulus color sensor.

Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
 .../devicetree/bindings/iio/light/ams,tcs3430.yaml | 52 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 +++
 2 files changed, 58 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml b/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
new file mode 100644
index 0000000..085a70e
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/ams,tcs3430.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ams OSRAM TCS3430 XYZ Tristimulus Color and Ambient Light Sensor
+
+maintainers:
+  - Robert Ijtsma <robertijtsma@gmail.com>
+
+description: |
+  The ams OSRAM TCS3430 is an I2C ambient light and CIE 1931 XYZ tristimulus
+  color sensor with photopic Y, Z, X, and IR channels.
+
+  Datasheet: https://look.ams-osram.com/m/43d518b4cd81e3f2/original/TCS3430-DS000539.pdf
+
+properties:
+  compatible:
+    const: ams,tcs3430
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        light-sensor@39 {
+            compatible = "ams,tcs3430";
+            reg = <0x39>;
+            vdd-supply = <&vdd_reg>;
+            interrupts = <24 IRQ_TYPE_LEVEL_LOW>;
+        };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1..b1cebc2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1489,6 +1489,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
 F:	drivers/iio/light/as73211.c
 
+AMS TCS3430 DRIVER
+M:	Robert Ijtsma <robertijtsma@gmail.com>
+L:	linux-iio@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
+
 AMT (Automatic Multicast Tunneling)
 M:	Taehee Yoo <ap420073@gmail.com>
 L:	netdev@vger.kernel.org

-- 
2.56.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
  2026-11-24 22:46 [PATCH 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma via B4 Relay
  2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
@ 2026-11-24 22:46 ` Robert Ijtsma via B4 Relay
  2026-11-25  6:28   ` kernel test robot
  2026-11-25  8:31   ` Joshua Crofts
  1 sibling, 2 replies; 7+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-iio, devicetree, linux-kernel, Robert Ijtsma

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).

The driver exposes:
- Illuminance (photopic Y channel) with raw counts and lux scale
- Modified intensity channels for X, Y, Z, and IR1
- Selectable hardware gain (1x, 4x, 16x, 64x, 128x) and integration time
- Regulator management and system sleep suspend/resume support

Tested on Microsoft Surface Pro X SQ2 (SC8180X).

Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
 MAINTAINERS                 |   1 +
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/tcs3430.c | 345 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 357 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b1cebc2..5194709 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1494,6 +1494,7 @@ M:	Robert Ijtsma <robertijtsma@gmail.com>
 L:	linux-iio@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
+F:	drivers/iio/light/tcs3430.c
 
 AMT (Automatic Multicast Tunneling)
 M:	Taehee Yoo <ap420073@gmail.com>
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 462fff1..09894cd 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -609,6 +609,16 @@ config TCS3414
 	  This driver can also be built as a module.  If so, the module
 	  will be called tcs3414.
 
+config TCS3430
+	tristate "ams OSRAM TCS3430 ambient light and XYZ color sensor"
+	depends on 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.
+
 config TCS3472
 	tristate "TAOS TCS3472 color light-to-digital converter"
 	depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 6672ed0..cd7b42e 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_ST_UVIS25)		+= st_uvis25_core.o
 obj-$(CONFIG_ST_UVIS25_I2C)	+= st_uvis25_i2c.o
 obj-$(CONFIG_ST_UVIS25_SPI)	+= st_uvis25_spi.o
 obj-$(CONFIG_TCS3414)		+= tcs3414.o
+obj-$(CONFIG_TCS3430)		+= tcs3430.o
 obj-$(CONFIG_TCS3472)		+= tcs3472.o
 obj-$(CONFIG_SENSORS_TSL2563)	+= tsl2563.o
 obj-$(CONFIG_TSL2583)		+= tsl2583.o
diff --git a/drivers/iio/light/tcs3430.c b/drivers/iio/light/tcs3430.c
new file mode 100644
index 0000000..138c8ab
--- /dev/null
+++ b/drivers/iio/light/tcs3430.c
@@ -0,0 +1,345 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * IIO driver for ams OSRAM TCS3430 Ambient Light and CIE 1931 XYZ Sensor
+ *
+ * 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>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/math64.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <linux/iio/iio.h>
+
+#define TCS3430_REG_ENABLE		0x80
+#define   TCS3430_ENABLE_PON		BIT(0)
+#define   TCS3430_ENABLE_AEN		BIT(1)
+#define TCS3430_REG_ATIME		0x81
+#define TCS3430_REG_CFG1		0x90
+#define   TCS3430_CFG1_AGAIN_MASK	GENMASK(1, 0)
+#define TCS3430_REG_ID			0x92
+#define   TCS3430_ID_MASK		GENMASK(7, 2)
+#define   TCS3430_ID_VAL		0xdc
+#define TCS3430_REG_CH0DATAL		0x94
+#define TCS3430_REG_CH1DATAL		0x96
+#define TCS3430_REG_CH2DATAL		0x98
+#define TCS3430_REG_CH3DATAL		0x9a
+#define TCS3430_REG_CFG2		0x9f
+#define   TCS3430_CFG2_DEFAULT		0x04
+#define   TCS3430_CFG2_HGAIN		BIT(4)
+#define TCS3430_REG_CFG3		0xab
+#define   TCS3430_CFG3_DEFAULT		0x0c
+#define TCS3430_REG_INTENAB		0xdd
+
+/* 72 integration cycles * 2.78 ms = 200.16 ms */
+#define TCS3430_DEFAULT_ATIME_CYCLES	72
+#define TCS3430_ATIME_STEP_US		2780
+
+/*
+ * 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)
+ */
+#define TCS3430_LUX_FACTOR		2980ULL
+
+static const int tcs3430_gains[] = { 1, 4, 16, 64, 128 };
+
+struct tcs3430_data {
+	struct i2c_client *client;
+	/* Protects device configuration across multi-register updates */
+	struct mutex lock;
+	u8 gain_idx;
+};
+
+static int tcs3430_apply_gain(struct tcs3430_data *data, u8 gain_idx)
+{
+	u8 cfg1, cfg2;
+	int ret;
+
+	if (gain_idx == 4) {
+		cfg1 = FIELD_PREP(TCS3430_CFG1_AGAIN_MASK, 3);
+		cfg2 = TCS3430_CFG2_DEFAULT | TCS3430_CFG2_HGAIN;
+	} else {
+		cfg1 = FIELD_PREP(TCS3430_CFG1_AGAIN_MASK, gain_idx);
+		cfg2 = TCS3430_CFG2_DEFAULT;
+	}
+
+	ret = i2c_smbus_write_byte_data(data->client, TCS3430_REG_CFG1, cfg1);
+	if (ret)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(data->client, TCS3430_REG_CFG2, cfg2);
+	if (ret)
+		return ret;
+
+	data->gain_idx = gain_idx;
+	return 0;
+}
+
+static int tcs3430_init_hw(struct tcs3430_data *data)
+{
+	struct i2c_client *client = data->client;
+	int ret;
+
+	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_ENABLE, 0x00);
+	if (ret)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_ATIME,
+					TCS3430_DEFAULT_ATIME_CYCLES - 1);
+	if (ret)
+		return ret;
+
+	ret = tcs3430_apply_gain(data, data->gain_idx);
+	if (ret)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_CFG3,
+					TCS3430_CFG3_DEFAULT);
+	if (ret)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_INTENAB, 0x00);
+	if (ret)
+		return ret;
+
+	return i2c_smbus_write_byte_data(client, TCS3430_REG_ENABLE,
+					 TCS3430_ENABLE_PON |
+					 TCS3430_ENABLE_AEN);
+}
+
+static void tcs3430_power_off(void *priv)
+{
+	struct tcs3430_data *data = priv;
+
+	i2c_smbus_write_byte_data(data->client, TCS3430_REG_ENABLE, 0x00);
+}
+
+static int tcs3430_read_raw(struct iio_dev *indio_dev,
+			    const struct iio_chan_spec *chan,
+			    int *val, int *val2, long mask)
+{
+	struct tcs3430_data *data = iio_priv(indio_dev);
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		guard(mutex)(&data->lock);
+		ret = i2c_smbus_read_word_data(data->client, chan->address);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		u32 itime_us = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
+		u64 scale_nano;
+		u32 rem;
+		int gain;
+
+		scoped_guard(mutex, &data->lock)
+			gain = tcs3430_gains[data->gain_idx];
+
+		scale_nano = div_u64(TCS3430_LUX_FACTOR * NSEC_PER_SEC * USEC_PER_MSEC,
+				     (u32)gain * itime_us);
+		*val = div_u64_rem(scale_nano, NSEC_PER_SEC, &rem);
+		*val2 = rem;
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN:
+		guard(mutex)(&data->lock);
+		*val = tcs3430_gains[data->gain_idx];
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_INT_TIME:
+		*val = 0;
+		*val2 = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	default:
+		return -EINVAL;
+	}
+}
+
+static int tcs3430_write_raw(struct iio_dev *indio_dev,
+			     const struct iio_chan_spec *chan,
+			     int val, int val2, long mask)
+{
+	struct tcs3430_data *data = iio_priv(indio_dev);
+	unsigned int i;
+
+	if (mask != IIO_CHAN_INFO_HARDWAREGAIN || val2 != 0)
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(tcs3430_gains); i++) {
+		if (tcs3430_gains[i] == val) {
+			guard(mutex)(&data->lock);
+			return tcs3430_apply_gain(data, i);
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int tcs3430_read_avail(struct iio_dev *indio_dev,
+			      const struct iio_chan_spec *chan,
+			      const int **vals, int *type, int *length,
+			      long mask)
+{
+	if (mask != IIO_CHAN_INFO_HARDWAREGAIN)
+		return -EINVAL;
+
+	*vals = tcs3430_gains;
+	*type = IIO_VAL_INT;
+	*length = ARRAY_SIZE(tcs3430_gains);
+	return IIO_AVAIL_LIST;
+}
+
+#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_HARDWAREGAIN) |	\
+				   BIT(IIO_CHAN_INFO_INT_TIME),		\
+	.info_mask_shared_by_all_available =				\
+		BIT(IIO_CHAN_INFO_HARDWAREGAIN),			\
+}
+
+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_shared_by_all = BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
+					   BIT(IIO_CHAN_INFO_INT_TIME),
+		.info_mask_shared_by_all_available =
+			BIT(IIO_CHAN_INFO_HARDWAREGAIN),
+	},
+	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),
+};
+
+static const struct iio_info tcs3430_info = {
+	.read_raw = tcs3430_read_raw,
+	.write_raw = tcs3430_write_raw,
+	.read_avail = tcs3430_read_avail,
+};
+
+static int tcs3430_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct tcs3430_data *data;
+	struct iio_dev *indio_dev;
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_BYTE_DATA |
+				     I2C_FUNC_SMBUS_WORD_DATA))
+		return -EOPNOTSUPP;
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable vdd supply\n");
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->client = client;
+	data->gain_idx = 3; /* 64x default gain */
+	i2c_set_clientdata(client, data);
+
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
+
+	ret = i2c_smbus_read_byte_data(client, TCS3430_REG_ID);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read device ID\n");
+	if ((ret & TCS3430_ID_MASK) != TCS3430_ID_VAL)
+		dev_info(dev, "unexpected part ID 0x%02x\n", ret);
+
+	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);
+}
+
+static int tcs3430_suspend(struct device *dev)
+{
+	struct tcs3430_data *data = dev_get_drvdata(dev);
+
+	guard(mutex)(&data->lock);
+	return i2c_smbus_write_byte_data(data->client, TCS3430_REG_ENABLE, 0x00);
+}
+
+static int tcs3430_resume(struct device *dev)
+{
+	struct tcs3430_data *data = dev_get_drvdata(dev);
+
+	guard(mutex)(&data->lock);
+	return tcs3430_init_hw(data);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(tcs3430_pm_ops, tcs3430_suspend,
+				tcs3430_resume);
+
+static const struct of_device_id tcs3430_of_match[] = {
+	{ .compatible = "ams,tcs3430" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, tcs3430_of_match);
+
+static const struct i2c_device_id tcs3430_id[] = {
+	{ .name = "tcs3430" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, tcs3430_id);
+
+static struct i2c_driver tcs3430_driver = {
+	.driver = {
+		.name = "tcs3430",
+		.of_match_table = tcs3430_of_match,
+		.pm = pm_sleep_ptr(&tcs3430_pm_ops),
+	},
+	.probe = tcs3430_probe,
+	.id_table = tcs3430_id,
+};
+module_i2c_driver(tcs3430_driver);
+
+MODULE_AUTHOR("Robert Ijtsma <robertijtsma@gmail.com>");
+MODULE_DESCRIPTION("ams OSRAM TCS3430 Ambient Light and XYZ Color Sensor Driver");
+MODULE_LICENSE("GPL");

-- 
2.56.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
  2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
@ 2026-11-25  6:28   ` kernel test robot
  2026-11-25  8:31   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2026-11-25  6:28 UTC (permalink / raw)
  To: Robert Ijtsma via B4 Relay, Jonathan Cameron, David Lechner,
	Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: llvm, oe-kbuild-all, linux-iio, devicetree, linux-kernel, Robert Ijtsma

Hi Robert,

kernel test robot noticed the following build errors:

[auto build test ERROR on 4843f6873f7c4835e62f2c73ba0fd538e57a2f22]

url:    https://github.com/intel-lab-lkp/linux/commits/Robert-Ijtsma-via-B4-Relay/dt-bindings-iio-light-add-ams-OSRAM-TCS3430/20261124-234657
base:   4843f6873f7c4835e62f2c73ba0fd538e57a2f22
patch link:    https://lore.kernel.org/r/20261124-iio-tcs3430-v1-2-0f2a38a6a4c1%40gmail.com
patch subject: [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20261125/20261125142230.FjfgcgpD-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261125/20261125142230.FjfgcgpD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261125142230.FjfgcgpD-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/iio/light/tcs3430.c:175:2: error: cannot jump from switch statement to this case label
     175 |         default:
         |         ^
   drivers/iio/light/tcs3430.c:166:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     166 |                 guard(mutex)(&data->lock);
         |                 ^
   include/linux/cleanup.h:416:2: note: expanded from macro 'guard'
     416 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:299:3: note: expanded from macro 'CLASS'
     299 |                 class_##_name##_constructor
         |                 ^
   <scratch space>:22:1: note: expanded from here
      22 | class_mutex_constructor
         | ^
   note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
      16 | #define __PASTE(a, b) ___PASTE(a, b)
         |                       ^
   include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
      15 | #define ___PASTE(a, b) a##b
         |                        ^
   <scratch space>:28:1: note: expanded from here
      28 | __UNIQUE_ID_unlock_541
         | ^
   drivers/iio/light/tcs3430.c:166:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
   include/linux/cleanup.h:416:15: note: expanded from macro 'guard'
     416 |         CLASS(_name, __UNIQUE_ID(guard))
         |                      ^
   include/linux/compiler.h:165:2: note: expanded from macro '__UNIQUE_ID'
     165 |         __PASTE(__UNIQUE_ID_,                                   \
         |         ^
   include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
      16 | #define __PASTE(a, b) ___PASTE(a, b)
         |                       ^
   include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
      15 | #define ___PASTE(a, b) a##b
         |                        ^
   <scratch space>:16:1: note: expanded from here
      16 | __UNIQUE_ID_guard_540
         | ^
   drivers/iio/light/tcs3430.c:142:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     142 |                 guard(mutex)(&data->lock);
         |                 ^
   include/linux/cleanup.h:416:2: note: expanded from macro 'guard'
     416 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:299:3: note: expanded from macro 'CLASS'
     299 |                 class_##_name##_constructor
         |                 ^
   <scratch space>:17:1: note: expanded from here
      17 | class_mutex_constructor
         | ^
   note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
      16 | #define __PASTE(a, b) ___PASTE(a, b)
         |                       ^
   include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
      15 | #define ___PASTE(a, b) a##b
         |                        ^
   <scratch space>:23:1: note: expanded from here
      23 | __UNIQUE_ID_unlock_537
         | ^
   drivers/iio/light/tcs3430.c:142:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
   include/linux/cleanup.h:416:15: note: expanded from macro 'guard'
     416 |         CLASS(_name, __UNIQUE_ID(guard))
         |                      ^
   include/linux/compiler.h:165:2: note: expanded from macro '__UNIQUE_ID'
     165 |         __PASTE(__UNIQUE_ID_,                                   \
         |         ^
   include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
      16 | #define __PASTE(a, b) ___PASTE(a, b)
         |                       ^
   include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
      15 | #define ___PASTE(a, b) a##b
         |                        ^
   <scratch space>:11:1: note: expanded from here
      11 | __UNIQUE_ID_guard_536
         | ^
   drivers/iio/light/tcs3430.c:170:2: error: cannot jump from switch statement to this case label
     170 |         case IIO_CHAN_INFO_INT_TIME:
         |         ^
   drivers/iio/light/tcs3430.c:166:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     166 |                 guard(mutex)(&data->lock);
         |                 ^
   include/linux/cleanup.h:416:2: note: expanded from macro 'guard'
     416 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:299:3: note: expanded from macro 'CLASS'
     299 |                 class_##_name##_constructor
         |                 ^
   <scratch space>:22:1: note: expanded from here
      22 | class_mutex_constructor
         | ^
   note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
      16 | #define __PASTE(a, b) ___PASTE(a, b)
         |                       ^
   include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
      15 | #define ___PASTE(a, b) a##b
         |                        ^


vim +175 drivers/iio/light/tcs3430.c

   132	
   133	static int tcs3430_read_raw(struct iio_dev *indio_dev,
   134				    const struct iio_chan_spec *chan,
   135				    int *val, int *val2, long mask)
   136	{
   137		struct tcs3430_data *data = iio_priv(indio_dev);
   138		int ret;
   139	
   140		switch (mask) {
   141		case IIO_CHAN_INFO_RAW:
   142			guard(mutex)(&data->lock);
   143			ret = i2c_smbus_read_word_data(data->client, chan->address);
   144			if (ret < 0)
   145				return ret;
   146			*val = ret;
   147			return IIO_VAL_INT;
   148	
   149		case IIO_CHAN_INFO_SCALE: {
   150			u32 itime_us = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
   151			u64 scale_nano;
   152			u32 rem;
   153			int gain;
   154	
   155			scoped_guard(mutex, &data->lock)
   156				gain = tcs3430_gains[data->gain_idx];
   157	
   158			scale_nano = div_u64(TCS3430_LUX_FACTOR * NSEC_PER_SEC * USEC_PER_MSEC,
   159					     (u32)gain * itime_us);
   160			*val = div_u64_rem(scale_nano, NSEC_PER_SEC, &rem);
   161			*val2 = rem;
   162			return IIO_VAL_INT_PLUS_NANO;
   163		}
   164	
   165		case IIO_CHAN_INFO_HARDWAREGAIN:
   166			guard(mutex)(&data->lock);
   167			*val = tcs3430_gains[data->gain_idx];
   168			return IIO_VAL_INT;
   169	
   170		case IIO_CHAN_INFO_INT_TIME:
   171			*val = 0;
   172			*val2 = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
   173			return IIO_VAL_INT_PLUS_MICRO;
   174	
 > 175		default:
   176			return -EINVAL;
   177		}
   178	}
   179	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dt-bindings: iio: light: add ams OSRAM TCS3430
  2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
@ 2026-11-25  7:43   ` Krzysztof Kozlowski
  2026-11-25  8:02   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25  7:43 UTC (permalink / raw)
  To: Robert Ijtsma
  Cc: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-iio, devicetree, linux-kernel, Krzysztof Kozlowski

On 2026-11-24 23:46 +0100, Robert Ijtsma wrote:
> Add Devicetree binding schema for the ams OSRAM TCS3430 ambient light
> and CIE 1931 XYZ tristimulus color sensor.
> 
> Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
> ---
>  .../devicetree/bindings/iio/light/ams,tcs3430.yaml | 52 ++++++++++++++++++++++
>  MAINTAINERS                                        |  6 +++
>  2 files changed, 58 insertions(+)

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

Best regards,
Krzysztof

-- 
Krzysztof Kozlowski <krzk@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dt-bindings: iio: light: add ams OSRAM TCS3430
  2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
  2026-11-25  7:43   ` Krzysztof Kozlowski
@ 2026-11-25  8:02   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-11-25  8:02 UTC (permalink / raw)
  To: robertijtsma, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-iio, devicetree, linux-kernel

On 24-Nov-26 23:46, Robert Ijtsma via B4 Relay wrote:
> From: Robert Ijtsma <robertijtsma@gmail.com>
> 
> Add Devicetree binding schema for the ams OSRAM TCS3430 ambient light
> and CIE 1931 XYZ tristimulus color sensor.
> 
> Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
> ---
>  .../devicetree/bindings/iio/light/ams,tcs3430.yaml | 52 ++++++++++++++++++++++
>  MAINTAINERS                                        |  6 +++
>  2 files changed, 58 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml b/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
> new file mode 100644
> index 0000000..085a70e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/light/ams,tcs3430.yaml
> @@ -0,0 +1,52 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/light/ams,tcs3430.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: ams OSRAM TCS3430 XYZ Tristimulus Color and Ambient Light Sensor
> +
> +maintainers:
> +  - Robert Ijtsma <robertijtsma@gmail.com>
> +
> +description: |
> +  The ams OSRAM TCS3430 is an I2C ambient light and CIE 1931 XYZ tristimulus
> +  color sensor with photopic Y, Z, X, and IR channels.
> +
> +  Datasheet: https://look.ams-osram.com/m/43d518b4cd81e3f2/original/TCS3430-DS000539.pdf
> +
> +properties:
> +  compatible:
> +    const: ams,tcs3430
> +
> +  reg:
> +    maxItems: 1
> +
> +  vdd-supply: true
> +
> +  interrupts:
> +    maxItems: 1
> +
> +required:
> +  - compatible
> +  - reg
> +  - vdd-supply
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +
> +    i2c {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        light-sensor@39 {
> +            compatible = "ams,tcs3430";
> +            reg = <0x39>;
> +            vdd-supply = <&vdd_reg>;
> +            interrupts = <24 IRQ_TYPE_LEVEL_LOW>;
> +        };
> +    };
> +...
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 44540a1..b1cebc2 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1489,6 +1489,12 @@ S:	Maintained
>  F:	Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
>  F:	drivers/iio/light/as73211.c
>  
> +AMS TCS3430 DRIVER
> +M:	Robert Ijtsma <robertijtsma@gmail.com>
> +L:	linux-iio@vger.kernel.org
Drop the list entry, get_maintainer.pl will get this using the path.

-- 
Kind regards,
Joshua Crofts


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
  2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
  2026-11-25  6:28   ` kernel test robot
@ 2026-11-25  8:31   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-11-25  8:31 UTC (permalink / raw)
  To: robertijtsma, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-iio, devicetree, linux-kernel

On 24-Nov-26 23:46, Robert Ijtsma via B4 Relay wrote:

...

> diff --git a/drivers/iio/light/tcs3430.c b/drivers/iio/light/tcs3430.c
> new file mode 100644
> index 0000000..138c8ab
> --- /dev/null
> +++ b/drivers/iio/light/tcs3430.c
> @@ -0,0 +1,345 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * IIO driver for ams OSRAM TCS3430 Ambient Light and CIE 1931 XYZ Sensor
> + *
> + * 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>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/math64.h>
> +#include <linux/mod_devicetable.h>

No need for this, the device tables required will be pulled in
via the respective bus headers.

> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>
> +#include <linux/units.h>
> +
> +#include <linux/iio/iio.h>
> +

..

> +static int tcs3430_apply_gain(struct tcs3430_data *data, u8 gain_idx)
> +{
> +	u8 cfg1, cfg2;
> +	int ret;
> +
> +	if (gain_idx == 4) {
> +		cfg1 = FIELD_PREP(TCS3430_CFG1_AGAIN_MASK, 3);
> +		cfg2 = TCS3430_CFG2_DEFAULT | TCS3430_CFG2_HGAIN;
> +	} else {
> +		cfg1 = FIELD_PREP(TCS3430_CFG1_AGAIN_MASK, gain_idx);
> +		cfg2 = TCS3430_CFG2_DEFAULT;
> +	}
> +
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3430_REG_CFG1, cfg1);

Why not use regmap for read/write operations?

> +	if (ret)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(data->client, TCS3430_REG_CFG2, cfg2);
> +	if (ret)
> +		return ret;
> +
> +	data->gain_idx = gain_idx;
> +	return 0;
> +}
> +
> +static int tcs3430_init_hw(struct tcs3430_data *data)
> +{
> +	struct i2c_client *client = data->client;
> +	int ret;
> +
> +	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_ENABLE, 0x00);
> +	if (ret)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_ATIME,
> +					TCS3430_DEFAULT_ATIME_CYCLES - 1);
> +	if (ret)
> +		return ret;
> +
> +	ret = tcs3430_apply_gain(data, data->gain_idx);
> +	if (ret)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_CFG3,
> +					TCS3430_CFG3_DEFAULT);
> +	if (ret)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(client, TCS3430_REG_INTENAB, 0x00);
> +	if (ret)
> +		return ret;
> +
> +	return i2c_smbus_write_byte_data(client, TCS3430_REG_ENABLE,
> +					 TCS3430_ENABLE_PON |
> +					 TCS3430_ENABLE_AEN);
> +}
> +
> +static void tcs3430_power_off(void *priv)
> +{
> +	struct tcs3430_data *data = priv;
> +
> +	i2c_smbus_write_byte_data(data->client, TCS3430_REG_ENABLE, 0x00);
> +}
> +
> +static int tcs3430_read_raw(struct iio_dev *indio_dev,
> +			    const struct iio_chan_spec *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct tcs3430_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		guard(mutex)(&data->lock);

cleanup.h magic works thanks to local variables and a scope. When using
guard() in a switch case it has to be surrounded by brackets to define
the scope (this is what the email from lkp is warning about).

> +		ret = i2c_smbus_read_word_data(data->client, chan->address);
> +		if (ret < 0)
> +			return ret;
> +		*val = ret;
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_SCALE: {
> +		u32 itime_us = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
> +		u64 scale_nano;
> +		u32 rem;
> +		int gain;
> +
> +		scoped_guard(mutex, &data->lock)
> +			gain = tcs3430_gains[data->gain_idx];
> +
> +		scale_nano = div_u64(TCS3430_LUX_FACTOR * NSEC_PER_SEC * USEC_PER_MSEC,
> +				     (u32)gain * itime_us);
> +		*val = div_u64_rem(scale_nano, NSEC_PER_SEC, &rem);
> +		*val2 = rem;
> +		return IIO_VAL_INT_PLUS_NANO;
> +	}
> +
> +	case IIO_CHAN_INFO_HARDWAREGAIN:
> +		guard(mutex)(&data->lock);

Same here.

> +		*val = tcs3430_gains[data->gain_idx];
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_INT_TIME:
> +		*val = 0;
> +		*val2 = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
> +		return IIO_VAL_INT_PLUS_MICRO;
> +
> +	default:
> +		return -EINVAL;
> +	}
> +}

...

> +static int tcs3430_read_avail(struct iio_dev *indio_dev,
> +			      const struct iio_chan_spec *chan,
> +			      const int **vals, int *type, int *length,
> +			      long mask)
> +{
> +	if (mask != IIO_CHAN_INFO_HARDWAREGAIN)
> +		return -EINVAL;
> +
> +	*vals = tcs3430_gains;
> +	*type = IIO_VAL_INT;
> +	*length = ARRAY_SIZE(tcs3430_gains);
> +	return IIO_AVAIL_LIST;

For IIO macros we usually use a switch, even if we're only checking
for one case.

-- 
Kind regards,
Joshua Crofts


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-25  8:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 22:46 [PATCH 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma via B4 Relay
2026-11-25  7:43   ` Krzysztof Kozlowski
2026-11-25  8:02   ` Joshua Crofts
2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma via B4 Relay
2026-11-25  6:28   ` kernel test robot
2026-11-25  8:31   ` Joshua Crofts

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®