Skip to contentSkip to conversation

This series adds support for Texas Instruments OPT4041 Ambient light sensor

PATCH Superseded Jesper X Nilsson 5 participants 14 messages Oct 23

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
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                          |   2 +-
 drivers/iio/light/opt4001.c                        | 144 ++++++++++++++++-----
 3 files changed, 121 insertions(+), 34 deletions(-)

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

Best regards,

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

PATCH 1/3 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
#2 lore raw

PATCH 2/3 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

Assisted-by LLM
---
 drivers/iio/light/opt4001.c | 77 +++++++++++++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 27 deletions(-)
drivers/iio/light/opt4001.c +50 -27
index aa3d87995b7c..bf5dc1c8514c 100644
@@ -78,6 +78,9 @@ struct opt4001_chip_info {
 	int mul;
 	int div;
 	const char *name;
+	const struct iio_chan_spec *channels;
+	int num_channels;
+	u16 device_id;
 };
 
 struct opt4001_chip {
@@ -87,16 +90,32 @@ 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 = {
 	.mul = 4375,
 	.div = 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 = {
 	.mul = 3125,
 	.div = 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] = {
@@ -159,10 +178,9 @@ 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;
@@ -172,17 +190,16 @@ static int opt4001_read_lux_value(struct iio_dev *indio_dev,
 	u8 count;
 	u8 crc;
 	u8 calc_crc;
-	u64 lux_raw;
-	u32 rem;
+	u32 mantissa;
 	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;
@@ -193,12 +210,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->mul;
 	*val = div_u64_rem(lux_raw, chip->chip_info->div, &rem);
 	*val2 = rem * 100;
@@ -233,15 +265,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)
@@ -250,7 +273,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];
@@ -388,19 +411,19 @@ 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);
+
 	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
#3 lore raw

Re: [PATCH 2/3] 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.

...

Quoted 1 line
Assisted-by LLM

Drop this tag.

...

drivers/iio/light/opt4001.c struct opt4001_chip { · line 99

Quoted 7 lines
drivers/iio/light/opt4001.c +7 -0
+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)

While at it (and I see it was in the original code), add a trailing comma here.

Quoted 2 lines
drivers/iio/light/opt4001.c +2 -0
+	},
+};

...

drivers/iio/light/opt4001.c static int opt4001_read_lux_value(struct iio_dev *indio_dev, · line 193

Quoted 6 lines
drivers/iio/light/opt4001.c +1 -2
 	u8 count;
 	u8 crc;
 	u8 calc_crc;
-	u64 lux_raw;
-	u32 rem;
+	u32 mantissa;

Try to put it to make more of reversed xmas tree order.

Quoted 1 line

int ret;

...

drivers/iio/light/opt4001.c static int opt4001_probe(struct i2c_client *client) · line 414

Quoted 1 line
drivers/iio/light/opt4001.c +1 -0
+	chip->chip_info = i2c_get_match_data(client);

For now it requires

	if (!chip->chip_info)
		return -ENODATA;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

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

Quoted 7 lines · Andy Shevchenko

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

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 6 lines

...

Quoted 1 line
Assisted-by LLM

Drop this tag.

I will drop the tag in v2.> ...

Quoted 11 lines

drivers/iio/light/opt4001.c struct opt4001_chip { · line 99

Quoted 8 lines
drivers/iio/light/opt4001.c +7 -0
+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)

While at it (and I see it was in the original code), add a trailing comma here.

I will add trailing comma in v2.

Quoted 5 lines
Quoted 2 lines
drivers/iio/light/opt4001.c +2 -0
+     },
+};

...

Quoted 9 lines

drivers/iio/light/opt4001.c static int opt4001_read_lux_value(struct iio_dev *indio_dev, · line 193

Quoted 6 lines
       u8 count;
       u8 crc;
       u8 calc_crc;
drivers/iio/light/opt4001.c +1 -2
-     u64 lux_raw;
-     u32 rem;
+     u32 mantissa;

Try to put it to make more of reversed xmas tree order.

I will fix it in v2.

Quoted 11 lines
Quoted 1 line
       int ret;

...

Quoted 1 line

+ chip->chip_info = i2c_get_match_data(client);

For now it requires

         if (!chip->chip_info)
                 return -ENODATA;

I will add the if check in v2.

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

Thanks for the fast review!

Best regards,
Jesper

maintainer
#5 lore raw

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

Quoted 8 lines · On Fri, 23 Oct 2026 12:07:41 +0200 Jesper X Nilsson <[email protected]> wrote:
Quoted 7 lines · Andy Shevchenko

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

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
Quoted 6 lines

...

Quoted 1 line
Assisted-by LLM

Drop this tag.

I will drop the tag in v2.> ...

Hi Jesper,

Small process thing.

If you agree with all the suggestions in a patch, don't reply as a separate email. The place for the info in here and the thanks is the change log of v2.

Note I send this email at least once a week to ask people to basically be less polite in the interests of efficiency :)

Jonathan

#6 lore raw

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

In reply to Jesper X Nilsson
Quoted 6 lines · On Fri, 23 Oct 2026 09:48:14 +0200 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

Assisted-by LLM

This tag has been deprecated.

Quoted 1 line

...

drivers/iio/light/opt4001.c static int opt4001_probe(struct i2c_client *client) · line 414

Quoted 5 lines
drivers/iio/light/opt4001.c +1 -0
@@ -388,19 +411,19 @@ 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);

+ null check and return -ENODATA on failure.

Signature · 2 lines
Kind regards,
Joshua Crofts
#7 lore raw

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

Quoted 16 lines · On Fri, 23 Oct 2026 11:10:32 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · On Fri, 23 Oct 2026 09:48:14 +0200 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

Assisted-by LLM

This tag has been deprecated.

Quoted 1 line

...

Quoted 8 lines

drivers/iio/light/opt4001.c static int opt4001_probe(struct i2c_client *client) · line 414

Quoted 5 lines
drivers/iio/light/opt4001.c +1 -0
@@ -388,19 +411,19 @@ 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);  

+ null check and return -ENODATA on failure.

Just noticed that Andy was faster :)

Signature · 2 lines
Kind regards,
Joshua Crofts
#8 lore raw

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

Quoted 23 lines · Joshua Crofts
Quoted 20 lines · On Fri, 23 Oct 2026 11:10:32 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · On Fri, 23 Oct 2026 09:48:14 +0200 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

Assisted-by LLM

This tag has been deprecated.

Quoted 1 line

...

Quoted 4 lines
drivers/iio/light/opt4001.c +0 -0
@@ -388,19 +411,19 @@ static int opt4001_probe(struct i2c_client *client)
  		return dev_err_probe(&client->dev, ret,
  				     "failed to reinit regmap cache\n");
 
Quoted 7 lines
Quoted 4 lines

drivers/iio/light/opt4001.c static int opt4001_probe(struct i2c_client *client) · line 414

Quoted 1 line
drivers/iio/light/opt4001.c +1 -0
+	chip->chip_info = i2c_get_match_data(client);

+ null check and return -ENODATA on failure.

Just noticed that Andy was faster :)

Yes, you were both fast :)
Thanks for the review!

Best regards,
Jesper

#9 lore raw

PATCH 3/3 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

Assisted-by LLM
---
 drivers/iio/light/Kconfig   |  2 +-
 drivers/iio/light/opt4001.c | 67 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 64 insertions(+), 5 deletions(-)
drivers/iio/light/Kconfig +1 -1
index 462fff1ddef2..625ebb10ad1b 100644
@@ -508,7 +508,7 @@ config OPT4001
 	select REGMAP_I2C
 	help
 	  If you say Y or M here, you get support for Texas Instruments
-	  OPT4001 Ambient Light Sensor.
+	  OPT4001 and OPT4041 Ambient Light Sensors.
 
 	  If built as a dynamically linked module, it will be called
 	  opt4001.
drivers/iio/light/opt4001.c +63 -4

142 lines not on this page · raw message

Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 3/3] 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.

...

Quoted 1 line
Assisted-by LLM

Drop this.

...

drivers/iio/light/Kconfig config OPT4001 · line 511

Quoted 4 lines
drivers/iio/light/Kconfig +1 -1
 	help
 	  If you say Y or M here, you get support for Texas Instruments
-	  OPT4001 Ambient Light Sensor.
+	  OPT4001 and OPT4041 Ambient Light Sensors.

We in IIO established kinda a style for this to be scalable, id est list them one-per-line:

If you say Y or M here, you get support for Texas Instruments Ambient Light Sensors:
- OPT4001 (...can add some short useful detail here...)
- OPT4041 (...can add some short useful detail here...)

drivers/iio/light/Kconfig config OPT4001 · line 514

Quoted 2 lines
drivers/iio/light/Kconfig +0 -0
 	  If built as a dynamically linked module, it will be called
 	  opt4001.

Perhaps also consider changing summary text at tristate to make it like "...OPT4001 and compatible".

...

Quoted 2 lines

- * Device driver for the Texas Instruments OPT4001.
+ * Device driver for the Texas Instruments OPT4001 and OPT4041.

Make this and MODULE_DESCRIPTION() to be the same as summary in the Kconfig, see above.

Quoted 1 line

*/

...

drivers/iio/light/opt4001.c static const struct iio_chan_spec opt4001_channels[] = { · line 114

Quoted 7 lines
drivers/iio/light/opt4001.c +7 -0
+static const struct iio_chan_spec opt4041_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)

Trailing comma.

drivers/iio/light/opt4001.c static const struct iio_chan_spec opt4001_channels[] = { · line 123

Quoted 9 lines
drivers/iio/light/opt4001.c +9 -0
+	},
+	{
+		.type = IIO_INTENSITY,
+		.modified = 1,
+		.channel2 = IIO_MOD_LIGHT_BOTH,
+		.address = OPT4041_LIGHT2_MSB,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+		.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
+		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME)

Ditto.

Quoted 2 lines
(quoted diff) +2 -0
+	},
+};

...

drivers/iio/light/opt4001.c static const struct opt4001_chip_info opt4001_picostar_info = { · line 147

Quoted 3 lines
drivers/iio/light/opt4001.c +3 -0
+static const struct opt4001_chip_info opt4041_sot_5x3_info = {
+	.mul = 5850,
+	.div = 10000000,

Just sent a patch to move this to use struct s32_fract, I believe you may incorporate it into your series as a precursor).

Quoted 5 lines
drivers/iio/light/opt4001.c +5 -0
+	.name = "opt4041-sot-5x3",
+	.channels = opt4041_channels,
+	.num_channels = ARRAY_SIZE(opt4041_channels),
+	.device_id = OPT4041_DEVICE_ID_VAL,
+};

...

Quoted 1 line

+MODULE_DESCRIPTION("Texas Instruments opt4001 and opt4041 ambient light sensor driver");

See above.

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

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

Quoted 9 lines · Andy Shevchenko
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.

Quoted 6 lines

...

Quoted 1 line
Assisted-by LLM

Drop this.

I will drop the tag in v2.

Quoted 10 lines

...

drivers/iio/light/Kconfig config OPT4001 · line 511

Quoted 4 lines

help
If you say Y or M here, you get support for Texas Instruments

drivers/iio/light/Kconfig +1 -1
-	  OPT4001 Ambient Light Sensor.
+	  OPT4001 and OPT4041 Ambient Light Sensors.

We in IIO established kinda a style for this to be scalable, id est list them one-per-line:

Quoted 5 lines

If you say Y or M here, you get support for Texas Instruments Ambient Light Sensors:
- OPT4001 (...can add some short useful detail here...)
- OPT4041 (...can add some short useful detail here...)

I will change to this style in v2.

Quoted 6 lines
Quoted 2 lines

If built as a dynamically linked module, it will be called opt4001.

Perhaps also consider changing summary text at tristate to make it like "...OPT4001 and compatible".

Good suggestion, will add it in v2.

Quoted 8 lines

...

Quoted 2 lines

- * Device driver for the Texas Instruments OPT4001.
+ * Device driver for the Texas Instruments OPT4001 and OPT4041.

Make this and MODULE_DESCRIPTION() to be the same as summary in the Kconfig, see above.

I will update the MODULE_DESCRIPTION() in v2.

Quoted 31 lines
Quoted 1 line
   */

...

drivers/iio/light/opt4001.c static const struct iio_chan_spec opt4001_channels[] = { · line 114

Quoted 7 lines
drivers/iio/light/opt4001.c +7 -0
+static const struct iio_chan_spec opt4041_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)

Trailing comma.

drivers/iio/light/opt4001.c static const struct iio_chan_spec opt4001_channels[] = { · line 123

Quoted 9 lines
drivers/iio/light/opt4001.c +9 -0
+	},
+	{
+		.type = IIO_INTENSITY,
+		.modified = 1,
+		.channel2 = IIO_MOD_LIGHT_BOTH,
+		.address = OPT4041_LIGHT2_MSB,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+		.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
+		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME)

Ditto.

Quoted 2 lines
(quoted diff) +2 -0
+	},
+};

...

Quoted 7 lines

drivers/iio/light/opt4001.c static const struct opt4001_chip_info opt4001_picostar_info = { · line 147

Quoted 3 lines
drivers/iio/light/opt4001.c +3 -0
+static const struct opt4001_chip_info opt4041_sot_5x3_info = {
+	.mul = 5850,
+	.div = 10000000,

Just sent a patch to move this to use struct s32_fract, I believe you may incorporate it into your series as a precursor).

I will add the patch to my series.

Quoted 8 lines
Quoted 5 lines
drivers/iio/light/opt4001.c +5 -0
+	.name = "opt4041-sot-5x3",
+	.channels = opt4041_channels,
+	.num_channels = ARRAY_SIZE(opt4041_channels),
+	.device_id = OPT4041_DEVICE_ID_VAL,
+};

...

Quoted 4 lines
Quoted 1 line

+MODULE_DESCRIPTION("Texas Instruments opt4001 and opt4041 ambient light sensor driver");

See above.

Thanks for the fast review!

Best regards,
Jesper

#12 lore raw
In reply to Jesper X Nilsson
Quoted 11 lines · 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 4 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.

Overall very good small series, I have a few comments, but they like 15 minutes to address, id est mostly style related. I'll give my tag if you send a v2 with the changes as suggested.

Quoted 3 lines

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

No blank lines in the tag block :-)

Quoted 1 line
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw
Quoted 21 lines · Andy Shevchenko
Quoted 11 lines · 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 4 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.

Overall very good small series, I have a few comments, but they like 15 minutes to address, id est mostly style related. I'll give my tag if you send a v2 with the changes as suggested.

Quoted 6 lines
Quoted 3 lines

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

No blank lines in the tag block :-)

I will update it in v2.

Quoted 2 lines
Quoted 1 line

Best regards,
Jesper