Skip to contentSkip to conversation

This series adds support for Texas Instruments OPT4041 Ambient light sensor

PATCH In review Jesper X Nilsson 5 participants 14 messages Oct 23 – Nov 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover This series adds support for Texas Instruments OPT4041 Ambient light sensor

Extend the opt4001 driver to support OPT4041, since it is so similar to OPT4001. The OPT4041 adds a second channel, a wide band channel ranging from 380nm to 1000nm. The register map is almost the same for both devices. OPT4001 has an internal fifo of size four, OPT4041 has two fifos of size two, one for each channel.

Since OPT4041 has two channels it has one bit in register 0Bh to select which channel is compared to the threshold register. The driver does not support setting the threshold registers, so no new support has been added for this.

The OPT4041 is pin compatible and has the same package as opt4001-sot-5x3. Although the device id is different, I added a new compatible string since the driver already had different compatible strings to differentiate between the two OPT4001.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
Changes in v2:
- Drop tag Assited-by: LLM from commit messages
- Include patch from Andy: Re-use generic struct s32_fract
- Add trailing commas to structs where it was missing
- Sort variables in reverse xmas tree order in opt4001_read_raw_value()
- Return -ENODATA if i2c_get_match() returns NULL
- Update tristate summary and copy the string to MODULE_DESCRIPTION() and to the comment in the top of the driver
- Change the help text to included OPT4001 and OPT4041 on seperate lines
- Link to v1: https://patch.msgid.link/[email protected]

To: Jonathan Cameron <[email protected]>
To: David Lechner <[email protected]>
To: Nuno Sá <[email protected]>
To: Andy Shevchenko <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Stefan Windfeldt-Prytz <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Andy Shevchenko (1):
iio: light: opt4001: Re-use generic struct s32_fract

Jesper X Nilsson (3):
dt-bindings: iio: light: opt4001: add opt4041
iio: light: opt4001: refactor driver to prepare to support more devices
iio: light: opt4001: add support for opt4041

 .../devicetree/bindings/iio/light/ti,opt4001.yaml  |   9 +-
 drivers/iio/light/Kconfig                          |   6 +-
 drivers/iio/light/opt4001.c                        | 164 +++++++++++++++------
 3 files changed, 133 insertions(+), 46 deletions(-)

---
base-commit: a3b3580713f3ac5a32dc2874ee546828977a1d68
change-id: 20261007-opt4041-18315d8510df

Best regards,

Signature · 1 line
Jesper X Nilsson <[email protected]>
#1 lore raw

PATCH v2 1/4 dt-bindings: iio: light: opt4001: add opt4041

Add a new compatible for opt4041. The opt4041 is only available in the SOT-5X3 package. The device is pin compatible with the opt4001-sot-5x3 and shares the same properties. The opt4041 has one additional channel compared to opt4001, the extra channel has a wide spectral bandwidth ranging from 380nm to 1000nm.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
 Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +7 -2
index 12b0c7ed5d72..35e9b0deb944 100644
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/iio/light/ti,opt4001.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Texas Instruments OPT4001 Ambient Light Sensor
+title: Texas Instruments OPT4001/OPT4041 Ambient Light Sensor
 
 maintainers:
   - Stefan Windfeldt-Prytz <[email protected]>
@@ -13,13 +13,16 @@ description:
   Ambient light sensor with an i2c interface.
   Last part of compatible is for the packaging used.
   Picostar is a 4 pinned SMT and sot-5x3 is a 8 pinned SOT.
+  OPT4041 is only available as sot-5x3 and adds a wide band channel.
   https://www.ti.com/lit/gpn/opt4001
+  https://www.ti.com/lit/gpn/opt4041
 
 properties:
   compatible:
     enum:
       - ti,opt4001-picostar
       - ti,opt4001-sot-5x3
+      - ti,opt4041-sot-5x3
 
   reg:
     maxItems: 1
@@ -39,7 +42,9 @@ allOf:
       properties:
         compatible:
           contains:
-            const: ti,opt4001-sot-5x3
+            enum:
+              - ti,opt4001-sot-5x3
+              - ti,opt4041-sot-5x3
     then:
       properties:
         interrupts:
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH v2 1/4] dt-bindings: iio: light: opt4001: add opt4041

In reply to Jesper X Nilsson
Quoted 26 lines · On Fri, 23 Oct 2026 14:30:28 +0200 Jesper X Nilsson…

Add a new compatible for opt4041. The opt4041 is only available in the SOT-5X3 package. The device is pin compatible with the opt4001-sot-5x3 and shares the same properties. The opt4041 has one additional channel compared to opt4001, the extra channel has a wide spectral bandwidth ranging from 380nm to 1000nm.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
 Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +1 -1
index 12b0c7ed5d72..35e9b0deb944 100644
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/iio/light/ti,opt4001.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Texas Instruments OPT4001 Ambient Light Sensor
+title: Texas Instruments OPT4001/OPT4041 Ambient Light Sensor
 
 maintainers:
   - Stefan Windfeldt-Prytz <[email protected]>

Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml description: · line 16

Quoted 4 lines
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +1 -0
@@ -13,13 +13,16 @@ description:
   Ambient light sensor with an i2c interface.
   Last part of compatible is for the packaging used.
   Picostar is a 4 pinned SMT and sot-5x3 is a 8 pinned SOT.
+  OPT4041 is only available as sot-5x3 and adds a wide band channel.

I guess we keep the compatible naming because some crazy person might one day release it in a different package.

J

Quoted 24 lines
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +5 -1
   https://www.ti.com/lit/gpn/opt4001
+  https://www.ti.com/lit/gpn/opt4041
 
 properties:
   compatible:
     enum:
       - ti,opt4001-picostar
       - ti,opt4001-sot-5x3
+      - ti,opt4041-sot-5x3
 
   reg:
     maxItems: 1
@@ -39,7 +42,9 @@ allOf:
       properties:
         compatible:
           contains:
-            const: ti,opt4001-sot-5x3
+            enum:
+              - ti,opt4001-sot-5x3
+              - ti,opt4041-sot-5x3
     then:
       properties:
         interrupts:
#4 lore raw

Re: [PATCH v2 1/4] dt-bindings: iio: light: opt4001: add opt4041

Quoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Fri, 23 Oct 2026 14:30:28 +0200 Jesper X Nilsson…

Add a new compatible for opt4041. The opt4041 is only available in the SOT-5X3 package. The device is pin compatible with the opt4001-sot-5x3 and shares the same properties. The opt4041 has one additional channel compared to opt4001, the extra channel has a wide spectral bandwidth ranging from 380nm to 1000nm.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
 Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +1 -1
index 12b0c7ed5d72..35e9b0deb944 100644
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/iio/light/ti,opt4001.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Texas Instruments OPT4001 Ambient Light Sensor
+title: Texas Instruments OPT4001/OPT4041 Ambient Light Sensor
 
Quoted 10 lines

Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml description: · line 16

Quoted 7 lines
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +1 -0
 maintainers:
   - Stefan Windfeldt-Prytz <[email protected]>
@@ -13,13 +13,16 @@ description:
   Ambient light sensor with an i2c interface.
   Last part of compatible is for the packaging used.
   Picostar is a 4 pinned SMT and sot-5x3 is a 8 pinned SOT.
+  OPT4041 is only available as sot-5x3 and adds a wide band channel.

I guess we keep the compatible naming because some crazy person might one day release it in a different package.

Ye it is a bit weird. I did notice it but passed it off cos the existing device was like that and there was a behavioural difference in the driver between the two packages for the 4001. Maybe this fancy picostarTM package is no longer a thing? Would really need to get someone from TI to tell us what the plans are.

Quoted 27 lines

J

Quoted 24 lines
Documentation/devicetree/bindings/iio/light/ti,opt4001.yaml +5 -1
   https://www.ti.com/lit/gpn/opt4001
+  https://www.ti.com/lit/gpn/opt4041
 
 properties:
   compatible:
     enum:
       - ti,opt4001-picostar
       - ti,opt4001-sot-5x3
+      - ti,opt4041-sot-5x3
 
   reg:
     maxItems: 1
@@ -39,7 +42,9 @@ allOf:
       properties:
         compatible:
           contains:
-            const: ti,opt4001-sot-5x3
+            enum:
+              - ti,opt4001-sot-5x3
+              - ti,opt4041-sot-5x3
     then:
       properties:
         interrupts:
#5 lore raw

PATCH v2 2/4 iio: light: opt4001: Re-use generic struct s32_fract

In reply to Jesper X Nilsson

From: Andy Shevchenko <[email protected]>

Instead of custom data type re-use generic struct s32_fract. No functional changes intended.

---
 drivers/iio/light/opt4001.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/iio/light/opt4001.c +5 -8
index aa3d87995b7c..dcde10914a1e 100644
@@ -75,8 +75,7 @@
  * lux values.
  */
 struct opt4001_chip_info {
-	int mul;
-	int div;
+	struct s32_fract ratio;
 	const char *name;
 };
 
@@ -88,14 +87,12 @@ struct opt4001_chip {
 };
 
 static const struct opt4001_chip_info opt4001_sot_5x3_info = {
-	.mul = 4375,
-	.div = 10000000,
+	.ratio = { .numerator = 4375, .denominator = 10000000 },
 	.name = "opt4001-sot-5x3"
 };
 
 static const struct opt4001_chip_info opt4001_picostar_info = {
-	.mul = 3125,
-	.div = 10000000,
+	.ratio = { .numerator = 3125, .denominator = 10000000 },
 	.name = "opt4001-picostar"
 };
 
@@ -199,8 +196,8 @@ static int opt4001_read_lux_value(struct iio_dev *indio_dev,
 		return -EIO;
 
 	lux_raw = lux_raw << exp;
-	lux_raw = lux_raw * chip->chip_info->mul;
-	*val = div_u64_rem(lux_raw, chip->chip_info->div, &rem);
+	lux_raw = lux_raw * chip->chip_info->ratio.numerator;
+	*val = div_u64_rem(lux_raw, chip->chip_info->ratio.denominator, &rem);
 	*val2 = rem * 100;
 
 	return IIO_VAL_INT_PLUS_NANO;
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 3/4 iio: light: opt4001: refactor driver to prepare to support more devices

In reply to Jesper X Nilsson

Prepare opt4001 driver to be able to support OPT4041. Extend struct opt4001_chip_info with fields channels and device_id because OPT4041 has two channels and another device id.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
 drivers/iio/light/opt4001.c | 85 +++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 30 deletions(-)
drivers/iio/light/opt4001.c +55 -30
index dcde10914a1e..dc2eac8ad4af 100644
@@ -77,6 +77,9 @@
 struct opt4001_chip_info {
 	struct s32_fract ratio;
 	const char *name;
+	const struct iio_chan_spec *channels;
+	int num_channels;
+	u16 device_id;
 };
 
 struct opt4001_chip {
@@ -86,14 +89,30 @@ struct opt4001_chip {
 	const struct opt4001_chip_info *chip_info;
 };
 
+static const struct iio_chan_spec opt4001_channels[] = {
+	{
+		.type = IIO_LIGHT,
+		.address = OPT4001_LIGHT1_MSB,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+		.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
+		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
+	},
+};
+
 static const struct opt4001_chip_info opt4001_sot_5x3_info = {
 	.ratio = { .numerator = 4375, .denominator = 10000000 },
-	.name = "opt4001-sot-5x3"
+	.name = "opt4001-sot-5x3",
+	.channels = opt4001_channels,
+	.num_channels = ARRAY_SIZE(opt4001_channels),
+	.device_id = OPT4001_DEVICE_ID_VAL,
 };
 
 static const struct opt4001_chip_info opt4001_picostar_info = {
 	.ratio = { .numerator = 3125, .denominator = 10000000 },
-	.name = "opt4001-picostar"
+	.name = "opt4001-picostar",
+	.channels = opt4001_channels,
+	.num_channels = ARRAY_SIZE(opt4001_channels),
+	.device_id = OPT4001_DEVICE_ID_VAL,
 };
 
 static const int opt4001_int_time_available[][2] = {
@@ -156,30 +175,28 @@ static u8 opt4001_calculate_crc(u8 exp, u32 mantissa, u8 count)
 	return crc;
 }
 
-static int opt4001_read_lux_value(struct iio_dev *indio_dev,
-				  int *val, int *val2)
+static int opt4001_read_raw_value(struct opt4001_chip *chip, unsigned int reg,
+				  u64 *raw_value)
 {
-	struct opt4001_chip *chip = iio_priv(indio_dev);
 	struct device *dev = &chip->client->dev;
 	unsigned int light1;
 	unsigned int light2;
+	u32 mantissa;
+	u8 calc_crc;
+	u8 count;
 	u16 msb;
 	u16 lsb;
+	int ret;
 	u8 exp;
-	u8 count;
 	u8 crc;
-	u8 calc_crc;
-	u64 lux_raw;
-	u32 rem;
-	int ret;
 
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_MSB, &light1);
+	ret = regmap_read(chip->regmap, reg, &light1);
 	if (ret < 0) {
 		dev_err(dev, "Failed to read data bytes");
 		return ret;
 	}
 
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_LSB, &light2);
+	ret = regmap_read(chip->regmap, reg + 1, &light2);
 	if (ret < 0) {
 		dev_err(dev, "Failed to read data bytes");
 		return ret;
@@ -190,12 +207,27 @@ static int opt4001_read_lux_value(struct iio_dev *indio_dev,
 	crc = FIELD_GET(OPT4001_CRC_MASK, light2);
 	msb = FIELD_GET(OPT4001_MSB_MASK, light1);
 	lsb = FIELD_GET(OPT4001_LSB_MASK, light2);
-	lux_raw = (msb << 8) + lsb;
-	calc_crc = opt4001_calculate_crc(exp, lux_raw, count);
+	mantissa = (msb << 8) + lsb;
+	calc_crc = opt4001_calculate_crc(exp, mantissa, count);
 	if (calc_crc != crc)
 		return -EIO;
 
-	lux_raw = lux_raw << exp;
+	*raw_value = (u64)mantissa << exp;
+
+	return 0;
+}
+
+static int opt4001_read_lux_value(struct opt4001_chip *chip, unsigned int reg,
+				  int *val, int *val2)
+{
+	u64 lux_raw;
+	u32 rem;
+	int ret;
+
+	ret = opt4001_read_raw_value(chip, reg, &lux_raw);
+	if (ret)
+		return ret;
+
 	lux_raw = lux_raw * chip->chip_info->ratio.numerator;
 	*val = div_u64_rem(lux_raw, chip->chip_info->ratio.denominator, &rem);
 	*val2 = rem * 100;
@@ -230,15 +262,6 @@ static void opt4001_chip_off_action(void *data)
 		dev_err(&chip->client->dev, "Failed to power down\n");
 }
 
-static const struct iio_chan_spec opt4001_channels[] = {
-	{
-		.type = IIO_LIGHT,
-		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
-		.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
-		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME)
-	},
-};
-
 static int opt4001_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val, int *val2, long mask)
@@ -247,7 +270,7 @@ static int opt4001_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_PROCESSED:
-		return opt4001_read_lux_value(indio_dev, val, val2);
+		return opt4001_read_lux_value(chip, chan->address, val, val2);
 	case IIO_CHAN_INFO_INT_TIME:
 		*val = 0;
 		*val2 = opt4001_int_time_reg[chip->int_time][0];
@@ -385,19 +408,21 @@ static int opt4001_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, ret,
 				     "failed to reinit regmap cache\n");
 
+	chip->chip_info = i2c_get_match_data(client);
+	if (!chip->chip_info)
+		return -ENODATA;
+
 	ret = regmap_read(chip->regmap, OPT4001_DEVICE_ID, &dev_id);
 	if (ret < 0)
 		return dev_err_probe(&client->dev, ret,
 			"Failed to read the device ID register\n");
 
 	dev_id = FIELD_GET(OPT4001_DEVICE_ID_MASK, dev_id);
-	if (dev_id != OPT4001_DEVICE_ID_VAL)
+	if (dev_id != chip->chip_info->device_id)
 		dev_warn(&client->dev, "Device ID: %#04x unknown\n", dev_id);
 
-	chip->chip_info = i2c_get_match_data(client);
-
-	indio_dev->channels = opt4001_channels;
-	indio_dev->num_channels = ARRAY_SIZE(opt4001_channels);
+	indio_dev->channels = chip->chip_info->channels;
+	indio_dev->num_channels = chip->chip_info->num_channels;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->name = chip->chip_info->name;
 
Signature · 1 line
2.43.0
Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 3/4] iio: light: opt4001: refactor driver to prepare to support more devices

Quoted 3 lines · Jesper X Nilsson

Prepare opt4001 driver to be able to support OPT4041. Extend struct opt4001_chip_info with fields channels and device_id because OPT4041 has two channels and another device id.

...

drivers/iio/light/opt4001.c static u8 opt4001_calculate_crc(u8 exp, u32 mantissa, u8 count) · line 202

Quoted 12 lines
drivers/iio/light/opt4001.c +2 -2
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_MSB, &light1);
+	ret = regmap_read(chip->regmap, reg, &light1);
 	if (ret < 0) {
 		dev_err(dev, "Failed to read data bytes");
 		return ret;
 	}
 
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_LSB, &light2);
+	ret = regmap_read(chip->regmap, reg + 1, &light2);
 	if (ret < 0) {
 		dev_err(dev, "Failed to read data bytes");
 		return ret;

Can it be actually a bulk read? (Not part of this series, I assume.)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v2 3/4] iio: light: opt4001: refactor driver to prepare to support more devices

Quoted 16 lines · Andy Shevchenko
Quoted 3 lines · Jesper X Nilsson

Prepare opt4001 driver to be able to support OPT4041. Extend struct opt4001_chip_info with fields channels and device_id because OPT4041 has two channels and another device id.

...

Quoted 7 lines
drivers/iio/light/opt4001.c +1 -1
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_MSB, &light1);
+	ret = regmap_read(chip->regmap, reg, &light1);
  	if (ret < 0) {
  		dev_err(dev, "Failed to read data bytes");
  		return ret;
  	}
Quoted 8 lines

drivers/iio/light/opt4001.c static u8 opt4001_calculate_crc(u8 exp, u32 mantissa, u8 count) · line 202

Quoted 5 lines
drivers/iio/light/opt4001.c +1 -1
-	ret = regmap_read(chip->regmap, OPT4001_LIGHT1_LSB, &light2);
+	ret = regmap_read(chip->regmap, reg + 1, &light2);
  	if (ret < 0) {
  		dev_err(dev, "Failed to read data bytes");
  		return ret;

Can it be actually a bulk read? (Not part of this series, I assume.)

Yes it can be a bulk read, but not part of this series.
If no one else adds a patch, I think I can send a patch later this week.

Best regards,
Jesper

#9 lore raw

PATCH v2 4/4 iio: light: opt4001: add support for opt4041

In reply to Jesper X Nilsson

Extend the opt4001 driver to also support OPT4041. The devices are very similar, with the difference being OPT4041 having two channels, one visible and one wide band channel ranging from 380nm to 1000nm.

The register map is almost the same. OPT4001 has registers to read out the last four values sampled. OPT4041 maps to the same registers, but has two channels, saving the last two samples for each channel.

Datasheet: https://www.ti.com/lit/gpn/opt4041

---
 drivers/iio/light/Kconfig   |  6 +++--
 drivers/iio/light/opt4001.c | 66 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 66 insertions(+), 6 deletions(-)
drivers/iio/light/Kconfig +4 -2
index 462fff1ddef2..26c3fa057a38 100644
@@ -503,12 +503,14 @@ config OPT3001
 	  opt3001.
 
 config OPT4001
-	tristate "Texas Instruments OPT4001 Light Sensor"
+	tristate "Texas Instruments OPT4001 and compatible Light Sensors"
 	depends on I2C
 	select REGMAP_I2C
 	help
 	  If you say Y or M here, you get support for Texas Instruments
-	  OPT4001 Ambient Light Sensor.
+	  Ambient Light Sensors:
+	  - OPT4001
+	  - OPT4041
 
 	  If built as a dynamically linked module, it will be called
 	  opt4001.
drivers/iio/light/opt4001.c +62 -4

141 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v2 4/4
#10 lore raw

Re: [PATCH v2 4/4] iio: light: opt4001: add support for opt4041

Quoted 7 lines · Jesper X Nilsson

Extend the opt4001 driver to also support OPT4041. The devices are very similar, with the difference being OPT4041 having two channels, one visible and one wide band channel ranging from 380nm to 1000nm.

The register map is almost the same. OPT4001 has registers to read out the last four values sampled. OPT4041 maps to the same registers, but has two channels, saving the last two samples for each channel.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#11 lore raw
In reply to Jesper X Nilsson
Quoted 11 lines · On Fri, 23 Oct 2026 14:30:27 +0200 Jesper X Nilsson…

Extend the opt4001 driver to support OPT4041, since it is so similar to OPT4001. The OPT4041 adds a second channel, a wide band channel ranging from 380nm to 1000nm. The register map is almost the same for both devices. OPT4001 has an internal fifo of size four, OPT4041 has two fifos of size two, one for each channel.

Since OPT4041 has two channels it has one bit in register 0Bh to select which channel is compared to the threshold register. The driver does not support setting the threshold registers, so no new support has been added for this.

Quoted 7 lines

The OPT4041 is pin compatible and has the same package as opt4001-sot-5x3. Although the device id is different, I added a new compatible string since the driver already had different compatible strings to differentiate between the two OPT4001.

Datasheet: https://www.ti.com/lit/gpn/opt4041

Normally I'd say slow down to give more time for review, but seems you got good reviews anyway and the code looks clean to me.

Ah well, sometimes you win - but generally wait a few days at lesat between versions.

Applied to the testing branch of iio.git. I'll be rebasing that on rc1 once available.

thanks,

Jonathan

#12 lore raw
Quoted 23 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 23 Oct 2026 14:30:27 +0200 Jesper X Nilsson…

Extend the opt4001 driver to support OPT4041, since it is so similar to OPT4001. The OPT4041 adds a second channel, a wide band channel ranging from 380nm to 1000nm. The register map is almost the same for both devices. OPT4001 has an internal fifo of size four, OPT4041 has two fifos of size two, one for each channel.

Since OPT4041 has two channels it has one bit in register 0Bh to select which channel is compared to the threshold register. The driver does not support setting the threshold registers, so no new support has been added for this.

Quoted 7 lines

The OPT4041 is pin compatible and has the same package as opt4001-sot-5x3. Although the device id is different, I added a new compatible string since the driver already had different compatible strings to differentiate between the two OPT4001.

Datasheet: https://www.ti.com/lit/gpn/opt4041

Quoted 6 lines

Normally I'd say slow down to give more time for review, but seems you got good reviews anyway and the code looks clean to me.

Ah well, sometimes you win - but generally wait a few days at lesat between versions.

I will keep that in mind. Since I got good comments so fast, I was eager to fix them.

Quoted 3 lines

Applied to the testing branch of iio.git. I'll be rebasing that on rc1 once available.

Have the changes been applied? I can not see them on the testing branch of iio.git

Best regards,
Jesper

Quoted 3 lines

thanks,

Jonathan

maintainer
#13 lore raw
Quoted 30 lines · On Tue, 10 Nov 2026 17:08:38 +0100 Jesper X Nilsson <[email protected]> wrote:
Quoted 23 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 23 Oct 2026 14:30:27 +0200 Jesper X Nilsson…

Extend the opt4001 driver to support OPT4041, since it is so similar to OPT4001. The OPT4041 adds a second channel, a wide band channel ranging from 380nm to 1000nm. The register map is almost the same for both devices. OPT4001 has an internal fifo of size four, OPT4041 has two fifos of size two, one for each channel.

Since OPT4041 has two channels it has one bit in register 0Bh to select which channel is compared to the threshold register. The driver does not support setting the threshold registers, so no new support has been added for this.

Quoted 7 lines

The OPT4041 is pin compatible and has the same package as opt4001-sot-5x3. Although the device id is different, I added a new compatible string since the driver already had different compatible strings to differentiate between the two OPT4001.

Datasheet: https://www.ti.com/lit/gpn/opt4041

Quoted 6 lines

Normally I'd say slow down to give more time for review, but seems you got good reviews anyway and the code looks clean to me.

Ah well, sometimes you win - but generally wait a few days at lesat between versions.

Quoted 9 lines

I will keep that in mind. Since I got good comments so fast, I was eager to fix them.

Quoted 3 lines

Applied to the testing branch of iio.git. I'll be rebasing that on rc1 once available.

Have the changes been applied? I can not see them on the testing branch of iio.git

I clearly messed something up because indeed they aren't there.

Sorry about that. Now actually applied and pushed out on the testing branch.

Quoted 7 lines

Best regards,
Jesper

Quoted 3 lines

thanks,

Jonathan