iio: light: add support for veml6031x00 ALS series
Subsystems (4)
Javier Carrasco
maintainerv2 cover iio: light: add support for veml6031x00 ALS series
These ambient light sensors with I2C interface provide two light channels (ALS and IR), high/low threshold alarms with configurable persistence, and a data ready signal.
The devices covered by this driver have the same resolution, and they share most of their functionality. These are the differences between them (note that the x belongs to their names, and it is not a wildcard):
- Device ID: accessible via two 8-byte registers, different values for veml6031x00/veml6031x01 and veml60311x00/veml60311x01.
- I2C address: same grouping, 0x29 and 0x10 I2C addresses.
- AEC qualification: AEC-Q100 for veml6031x00/veml60311x00 and AEC-Q101 for veml6031x01/veml60311x01.
The alarms and the data ready signals share the interrupt pin, and an interrupt status register must be accessed to identify the source. Such multiplexing is not new in IIO, and I have followed existing examples for it. The persistence setting (own attribute) to trigger the alarms uses the pattern that has already been used for the veml6030.
The device configuration is in general documented in the datasheet and the application note. There is an exception, though: the activation of the "active force" mode that is required for the data ready signal must be carried out in two steps even though the affected bits are located in the same register: first ALS_AF (active force mode enable) must be set, and then ALS_TRIG (active force trigger setting) must be enabled. I have added a brief commentary in the code to explain this behavior, which has been confirmed by the manufacturer.
The only functionality that has not been implemented yet is the x0.66 gain (and its x0.165 counterpart when PD_DIV=1), which makes the gts helpers less usable due to the conversions required. It is indeed an uncommon gain to use (there are x0.5 and x0.125 gains) with no known use-case at the moment that justifies making adjustments to the gts helpers or adding artificial conversions to make it work.
This driver has been tested with the four supported devices separately as well as in pairs where the I2C addresses don't overlap.
I found a couple of issues in veml6030.c while programming this new driver, which shares some functionality with the former, and I added to the patch stack.
To: Jonathan Cameron <[email protected]>
To: Lars-Peter Clausen <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Rishi Gupta <[email protected]>
To: David Lechner <[email protected]>
To: Nuno Sá <[email protected]>
To: Andy Shevchenko <[email protected]>
To: Matti Vaittinen <[email protected]>
Changes in v2:
- Add commit to fix bug in veml6030.c (channel type when pushing
events) and remove dead code.
- Use gts helpers to simplify operations.
- Drop unused gain_idx.
- Build INT_MASK as an OR operation of the involved bits.
- Format arrays to follow the desired standard for IIO.
- Directly return function result as the last operation within another function instead of 'ret = x; if (ret) return ret; return 0;'.
- Fix some spacing (double space, tab for alignemnt in info struct).
- Use sizeof() for __le16 reg instead of 2.
- Return an error if the part ID could not be read.
- Spell out sd -> shutdown.
- Use devm_mutex_init() instead of mutex_init().
- Avoid using conditional guard, use claim/release instead.
- Access integration times from the global array to get and set the integration time instead of using a switch.
- Simplify read of available periods (persistence).
- Drop IRQF_TRIGGER_FALLING in the threaded irq request.
- Add regmap ranges.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Javier Carrasco (4):
iio: light: veml6030: remove unnecessary read of IT index
iio: light: veml6030: fix channel type when pushing events
dt-bindings: iio: light: veml6030: add veml6031x00 ALS series
iio: light: add support for veml6031x00 ALS series
.../bindings/iio/light/vishay,veml6030.yaml | 23 +- MAINTAINERS | 6 + drivers/iio/light/Kconfig | 14 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6030.c | 14 +- drivers/iio/light/veml6031x00.c | 1193 ++++++++++++++++++++ 6 files changed, 1242 insertions(+), 9 deletions(-)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20241109-veml6031x00-aa9463da064a
Best regards,
Signature · 1 line
Javier Carrasco <[email protected]>
Javier Carrasco
maintainerPATCH v2 1/4 iio: light: veml6030: remove unnecessary read of IT index
This is dead code as the IT index is not used by gts to set the new scale. In its current form, the value is read but not used afterward. Remove the dead code.
--- drivers/iio/light/veml6030.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/iio/light/veml6030.c +1 -5
@@ -521,13 +521,9 @@ static int veml6030_write_persistence(struct iio_dev *indio_dev,static int veml6030_set_scale (struct iio_dev *indio_dev,int val,int val2) { -int ret, gain_sel, it_idx, it_sel; +int ret, gain_sel, it_sel;struct veml6030_data *data =iio_priv (indio_dev); - ret =regmap_field_read (data->rf.it, &it_idx); -if (ret) -return ret; - ret =iio_gts_find_gain_time_sel_for_scale (&data->gts, val, val2, &gain_sel, &it_sel);if (ret)
Signature · 1 line
2.43.0
Re: [PATCH v2 1/4] iio: light: veml6030: remove unnecessary read of IT index
Quoted 3 lines · Javier Carrasco
This is dead code as the IT index is not used by gts to set the new scale. In its current form, the value is read but not used afterward. Remove the dead code.
Does it have any side-effects on the HW side? Exempli gratia, flushing FIFO, R1C (read to clear 1) bits?
Quoted 1 line
Fixes 22eaca4283b2 ("iio: light: veml6030: fix scale to conform to ABI")
Not sure it fixes anything. But it might regress, see above why.
...
If no side-effects, the code wise looks good.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Javier Carrasco
maintainerRe: [PATCH v2 1/4] iio: light: veml6030: remove unnecessary read of IT index
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Javier Carrasco
This is dead code as the IT index is not used by gts to set the new scale. In its current form, the value is read but not used afterward. Remove the dead code.
Does it have any side-effects on the HW side? Exempli gratia, flushing FIFO, R1C (read to clear 1) bits?
Quoted 7 lines
Quoted 1 line
Fixes 22eaca4283b2 ("iio: light: veml6030: fix scale to conform to ABI")Not sure it fixes anything. But it might regress, see above why.
...
If no side-effects, the code wise looks good.
Hi Andy,
This patch does not have side effects on the HW side. Apart from having it tested with real HW, the operation being handled here is setting a new scale, which is stored in a persistent register.
Best regards,
Javier
Andy Shevchenko
Reviewed-byRe: [PATCH v2 1/4] iio: light: veml6030: remove unnecessary read of IT index
Quoted 13 lines · Javier Carrasco
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Javier Carrasco
This is dead code as the IT index is not used by gts to set the new scale. In its current form, the value is read but not used afterward. Remove the dead code.
Does it have any side-effects on the HW side? Exempli gratia, flushing FIFO, R1C (read to clear 1) bits?
Quoted 1 line
Fixes 22eaca4283b2 ("iio: light: veml6030: fix scale to conform to ABI")Not sure it fixes anything. But it might regress, see above why.
Quoted 7 lines
Quoted 3 lines
...
If no side-effects, the code wise looks good.
This patch does not have side effects on the HW side. Apart from having it tested with real HW, the operation being handled here is setting a new scale, which is stored in a persistent register.
It's not only about volatile bits, but good that you able to test on real HW, this is much better than just theoretical clean up, thanks for confirming it works as expected.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v2 1/4] iio: light: veml6030: remove unnecessary read of IT index
Quoted 22 lines · On Wed, 13 May 2026 22:58:10 +0300 Andy Shevchenko…
Quoted 13 lines · Javier Carrasco
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Javier Carrasco
This is dead code as the IT index is not used by gts to set the new scale. In its current form, the value is read but not used afterward. Remove the dead code.
Does it have any side-effects on the HW side? Exempli gratia, flushing FIFO, R1C (read to clear 1) bits?
Quoted 1 line
Fixes 22eaca4283b2 ("iio: light: veml6030: fix scale to conform to ABI")Not sure it fixes anything. But it might regress, see above why.
Quoted 7 lines
Quoted 3 lines
...
If no side-effects, the code wise looks good.
This patch does not have side effects on the HW side. Apart from having it tested with real HW, the operation being handled here is setting a new scale, which is stored in a persistent register.
Quoted 6 lines
It's not only about volatile bits, but good that you able to test on real HW, this is much better than just theoretical clean up, thanks for confirming it works as expected.
Reviewed-by Andy Shevchenko <[email protected]>
Applied to the testing branch of iio.git with fixes tag dropped.
[email protected]
AI reviewRe: [PATCH v2 1/4] iio: light: veml6030: remove unnecessary read of IT index
In reply to Javier CarrascoThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Setting the scale arbitrarily overwrites the user-configured integration time (ABI Violation).…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Setting the scale arbitrarily overwrites the user-configured integration time (ABI Violation).
- [High] Missing IIO direct mode locking creates severe race conditions.
--
commit 74466b38c7e17d127927fcfba05be4a756ae8325
Author: Javier Carrasco <[email protected]>
iio: light: veml6030: remove unnecessary read of IT index
This commit removes the read of the integration time index from veml6030_set_scale(), as the value is read but not used afterward by gts to set the new scale.
Quoted 6 lines
drivers/iio/light/veml6030.c +0
-0@@ -521,13 +521,9 @@ static int veml6030_write_persistence(struct iio_dev *indio_dev,
drivers/iio/light/veml6030.c static int veml6030_write_persistence(struct iio_dev *indio_dev, · line 530
Quoted 10 lines
drivers/iio/light/veml6030.c +1
-5static int veml6030_set_scale (struct iio_dev *indio_dev,int val,int val2) { -int ret, gain_sel, it_idx, it_sel; +int ret, gain_sel, it_sel;struct veml6030_data *data =iio_priv (indio_dev); - ret =regmap_field_read (data->rf.it, &it_idx); -if (ret) -return ret; -
Instead of removing the it_idx read, should the driver use it with iio_gts_find_gain_sel_for_scale_using_time() to attempt to preserve the current integration time?
Currently, iio_gts_find_gain_time_sel_for_scale() ignores the current integration time and picks the first matching combination from the gts table.
This clobbers the sensor's current integration time, which might have been explicitly set by the user for 50Hz/60Hz noise rejection.
drivers/iio/light/veml6030.c static int veml6030_write_persistence(struct iio_dev *indio_dev, · line 529
Quoted 3 lines
drivers/iio/light/veml6030.c +0
-0ret =iio_gts_find_gain_time_sel_for_scale (&data->gts, val, val2, &gain_sel, &it_sel);if (ret)
Is state locking and a call to iio_device_claim_direct() missing here?
Since the driver supports a triggered buffer, omitting this allows userspace to concurrently change hardware configuration parameters mid-capture, which can corrupt the buffered data stream.
Furthermore, this function performs independent regmap_field_write() operations for the gain and integration time.
Without driver-level serialization, concurrent sysfs writes can interleave, leaving the device configured with a mismatched, invalid gain and integration time pair.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Javier Carrasco
maintainerPATCH v2 2/4 iio: light: veml6030: fix channel type when pushing events
In reply to Javier CarrascoThe events are registered for IIO_LIGHT and not for IIO_INTENSITY. Use the correct channel type.
This bug was introduced in the first version of the driver.
When at it, fix minor checkpatch code style warning (alignment).
--- drivers/iio/light/veml6030.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iio/light/veml6030.c +5 -3
@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)else evtdir =IIO_EV_DIR_FALLING ; -iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));return IRQ_HANDLED ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 4 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.This bug was introduced in the first version of the driver.
Unneeded detail, if it's a bug, use Fixes tag.
Quoted 1 line
When at it, fix minor checkpatch code style warning (alignment).
...
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 878
Quoted 8 lines
drivers/iio/light/veml6030.c +5
-3-iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));
AFAICS the indentation is still broken. Why not doing like this:
iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, IIO_EV_TYPE_THRESH, evtdir), iio_get_time_ns(indio_dev));
Signature · 2 lines
With Best Regards, Andy Shevchenko
Javier Carrasco
maintainerRe: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 26 lines · Andy Shevchenko
Quoted 4 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.This bug was introduced in the first version of the driver.
Unneeded detail, if it's a bug, use Fixes tag.
Quoted 1 line
When at it, fix minor checkpatch code style warning (alignment).
...
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 878
Quoted 8 lines
drivers/iio/light/veml6030.c +5
-3-iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));AFAICS the indentation is still broken. Why not doing like this:
Quoted 3 lines
iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, IIO_EV_TYPE_THRESH, evtdir), iio_get_time_ns(indio_dev));
Hi Andy,
Thank you for your feedback. According to checkpatch.pl, both variants are fine. Mine takes into account the indentation within IIO_UNMOD_EVENT_CODE(), and yours only accounts for the indentation for the arguments of iio_push_event(). Moreover, your suggestion goes beyond 80 characters and mine does not, so I would prefer sticking to mine if possible. As I said, it passes checkpatch --strict without warnings in both cases.
I will send a new version adding the Fixes tag and removing the comment.
Best regards,
Javier
Re: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 10 lines · Javier Carrasco
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.This bug was introduced in the first version of the driver.
Unneeded detail, if it's a bug, use Fixes tag.
Quoted 1 line
When at it, fix minor checkpatch code style warning (alignment).
...
Quoted 11 lines
Quoted 11 lines
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 878
Quoted 8 lines
drivers/iio/light/veml6030.c +5
-3-iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));AFAICS the indentation is still broken. Why not doing like this:
Quoted 7 lines
Quoted 3 lines
iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, IIO_EV_TYPE_THRESH, evtdir), iio_get_time_ns(indio_dev));Thank you for your feedback. According to checkpatch.pl, both variants are fine. Mine takes into account the indentation within
IIO_UNMOD_EVENT_CODE(),
And still have broken indentation with the last parameter. So it's not fine.
Quoted 3 lines
and yours only accounts for the indentation for
the arguments ofiio_push_event(). Moreover, your suggestion goes beyond 80 characters and mine does not,
When it's about readability the 80 characters is not a strict limit.
Quoted 2 lines
so I would prefer sticking to mine if
possible.
I recommend to reconsider. Mine has no indentation issues, the only subtle "problem" is 86 character line. And looking at the result I find mine better to read (hence the exception may apply and we are fine with the length of the line).
Quoted 4 lines
As I said, it passes checkpatch --strict without warnings in both cases.
I will send a new version adding the Fixes tag and removing the comment.
Make it the first patch as the currently first one does not sound like a fix to me.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Javier Carrasco
maintainerRe: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 29 lines · Andy Shevchenko
Quoted 10 lines · Javier Carrasco
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.This bug was introduced in the first version of the driver.
Unneeded detail, if it's a bug, use Fixes tag.
Quoted 1 line
When at it, fix minor checkpatch code style warning (alignment).
...
Quoted 15 lines
Quoted 14 lines
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 878
Quoted 8 lines
drivers/iio/light/veml6030.c +5
-3-iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));AFAICS the indentation is still broken. Why not doing like this:
iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, IIO_EV_TYPE_THRESH, evtdir), iio_get_time_ns(indio_dev));
Quoted 6 lines
Quoted 3 lines
Thank you for your feedback. According to checkpatch.pl, both variants are fine. Mine takes into account the indentation within
IIO_UNMOD_EVENT_CODE(),And still have broken indentation with the last parameter. So it's not fine.
I am sorry to insist on this, but I beg to differ. The last paramter (iio_get_time_ns()) is properly aligned as an argument of iio_push_event() and not IIO_UNMOD_EVENT_CODE(). That is exactly my
point: with my indentation it is clear that iio_get_time_ns() is an argument of iio_push_event() and not IIO_UNMOD_EVENT_CODE() because of the alignment. Moreove, my proposed alignment (which again, is fine with checkpatch --strict and the original one for example wasn't) is consistent with many usages of iio_push_event() in existing drivers. I just checked that there are dozens like mine, being the majority when it comes to this kind of indentation.
Quoted 14 lines
Quoted 3 lines
and yours only accounts for the indentation for
the arguments ofiio_push_event(). Moreover, your suggestion goes beyond 80 characters and mine does not,When it's about readability the 80 characters is not a strict limit.
Quoted 2 lines
so I would prefer sticking to mine if
possible.I recommend to reconsider. Mine has no indentation issues, the only subtle "problem" is 86 character line. And looking at the result I find mine better to read (hence the exception may apply and we are fine with the length of the line).
Quoted 7 lines
Quoted 4 lines
As I said, it passes checkpatch --strict without warnings in both cases.
I will send a new version adding the Fixes tag and removing the comment.
Make it the first patch as the currently first one does not sound like a fix to me.
Ok, I will make this one the first patch of a smaller series with the right Fixes tag added to it and removed from the other patch that affects veml6030. I will split the new driver in smaller chunks and send it as a dedicated series but continuing with the current versioning.
Best regards,
Javier
Re: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 12 lines · Javier Carrasco
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Javier Carrasco
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.This bug was introduced in the first version of the driver.
Unneeded detail, if it's a bug, use Fixes tag.
Quoted 1 line
When at it, fix minor checkpatch code style warning (alignment).
...
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 878
Quoted 8 lines
drivers/iio/light/veml6030.c +5
-3-iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));AFAICS the indentation is still broken. Why not doing like this:
iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, IIO_EV_TYPE_THRESH, evtdir), iio_get_time_ns(indio_dev));
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Thank you for your feedback. According to checkpatch.pl, both variants are fine. Mine takes into account the indentation within
IIO_UNMOD_EVENT_CODE(),And still have broken indentation with the last parameter. So it's not fine.
I am sorry to insist on this, but I beg to differ. The last paramter (
iio_get_time_ns()) is properly
Nope. It's aligned with TAB TAB TAB, the correct one is TAB TAB 7 spaces. I dunno what the editor or fonts you are using, but that's what I see with my Vim and monospace fonts.
Quoted 29 lines
aligned as an argument of
iio_push_event()and notIIO_UNMOD_EVENT_CODE(). That is exactly my
point: with my indentation it is clear thatiio_get_time_ns()is an argument ofiio_push_event()and notIIO_UNMOD_EVENT_CODE()because of the alignment. Moreove, my proposed alignment (which again, is fine with checkpatch --strict and the original one for example wasn't) is consistent with many usages ofiio_push_event()in existing drivers. I just checked that there are dozens like mine, being the majority when it comes to this kind of indentation.Quoted 19 lines
Quoted 3 lines
and yours only accounts for the indentation for
the arguments ofiio_push_event(). Moreover, your suggestion goes beyond 80 characters and mine does not,When it's about readability the 80 characters is not a strict limit.
Quoted 2 lines
so I would prefer sticking to mine if
possible.I recommend to reconsider. Mine has no indentation issues, the only subtle "problem" is 86 character line. And looking at the result I find mine better to read (hence the exception may apply and we are fine with the length of the line).
Quoted 4 lines
As I said, it passes checkpatch --strict without warnings in both cases.
I will send a new version adding the Fixes tag and removing the comment.
Quoted 7 lines
Quoted 2 lines
Make it the first patch as the currently first one does not sound like a fix to me.
Ok, I will make this one the first patch of a smaller series with the right Fixes tag added to it and removed from the other patch that affects veml6030. I will split the new driver in smaller chunks and send it as a dedicated series but continuing with the current versioning.
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
[email protected]
AI reviewRe: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
In reply to Javier CarrascoThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Returning IRQ_HANDLED on I2C read failure in the interrupt handler causes an interrupt storm. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Returning IRQ_HANDLED on I2C read failure in the interrupt handler causes an interrupt storm. --
commit 198c71e09b48e4ebbfc54cfa1edf78cced994d05
Author: Javier Carrasco <[email protected]>
iio: light: veml6030: fix channel type when pushing events
The events are registered for IIO_LIGHT and not for IIO_INTENSITY. Use the correct channel type.
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private)
Quoted 5 lines
drivers/iio/light/veml6030.c +0
-0@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)
This isn't a bug introduced by this commit, but looking at the beginning of veml6030_event_handler():
ret = regmap_read(data->regmap, VEML6030_REG_ALS_INT, ®);
if (ret) {
dev_err(&data->client->dev,
"can't read als interrupt register %d\n", ret);
return IRQ_HANDLED;
}Could returning IRQ_HANDLED on I2C read failure cause an interrupt storm?
The VEML6030 device uses a level-triggered interrupt which is cleared by the hardware only when the VEML6030_REG_ALS_INT register is successfully read. If regmap_read() fails, the device continues to assert the interrupt line.
Because the line is still asserted and IRQ_HANDLED signals the interrupt was serviced, the core IRQ subsystem unmasks the line, which fires immediately and wakes the threaded handler again.
Would it be better to return IRQ_NONE instead, so the IRQ core's spurious interrupt detector can track the unhandled threaded interrupt and eventually disable the misbehaving line?
Quoted 14 lines
drivers/iio/light/veml6030.c +5
-3else evtdir =IIO_EV_DIR_FALLING ; -iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_INTENSITY , -0 ,IIO_EV_TYPE_THRESH , evtdir), -iio_get_time_ns (indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));return IRQ_HANDLED ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
In reply to Javier CarrascoQuoted 21 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.
This bug was introduced in the first version of the driver.When at it, fix minor checkpatch code style warning (alignment).
Signed-off-by Javier Carrasco <[email protected]>--- drivers/iio/light/veml6030.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/iio/light/veml6030.c +0
-1@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)else evtdir =IIO_EV_DIR_FALLING ; - iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_INTENSITY,
drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 881
Quoted 10 lines
drivers/iio/light/veml6030.c +5
-2- 0, IIO_EV_TYPE_THRESH, evtdir), - iio_get_time_ns(indio_dev)); +iio_push_event (indio_dev,IIO_UNMOD_EVENT_CODE (IIO_LIGHT , +0 , +IIO_EV_TYPE_THRESH , + evtdir), +iio_get_time_ns (indio_dev));return IRQ_HANDLED ; }
Is this change reflected to the user-space? If so, is it safe? We shouldn't break the ABI, right?
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
David Lechner
reviewerRe: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 24 lines · Matti Vaittinen
Quoted 23 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.
This bug was introduced in the first version of the driver.When at it, fix minor checkpatch code style warning (alignment).
Signed-off-by Javier Carrasco <[email protected]>---
drivers/iio/light/veml6030.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/iio/light/veml6030.c +0
-0@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)else
evtdir =IIO_EV_DIR_FALLING;
- iio_push_event(indio_dev,IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, - 0, IIO_EV_TYPE_THRESH, evtdir),
-iio_get_time_ns(indio_dev));
+ iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, + 0,
Quoted 8 lines
Quoted 6 lines
+
IIO_EV_TYPE_THRESH, + evtdir),
+iio_get_time_ns(indio_dev)); returnIRQ_HANDLED;
}Is this change reflected to the user-space? If so, is it safe? We shouldn't break the ABI, right?
On things like this, we will sometime risk breaking userspace in hopes that no one was actually depending on it. If no one notices that we broke it, did we really break it?
Quoted 11 lines
Yours,
-- Matti---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland~~ When things go utterly wrong vim users can always type :help! ~~
Jonathan Cameron
maintainerRe: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 34 lines · On Mon, 18 May 2026 09:48:39 -0500 David Lechner <[email protected]> wrote:
Quoted 24 lines · Matti Vaittinen
Quoted 23 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.
This bug was introduced in the first version of the driver.When at it, fix minor checkpatch code style warning (alignment).
Signed-off-by Javier Carrasco <[email protected]>---
drivers/iio/light/veml6030.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/iio/light/veml6030.c +0
-0@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)else
evtdir =IIO_EV_DIR_FALLING;
- iio_push_event(indio_dev,IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, - 0, IIO_EV_TYPE_THRESH, evtdir),
-iio_get_time_ns(indio_dev));
+ iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, + 0,Quoted 8 lines
Quoted 6 lines
+
IIO_EV_TYPE_THRESH, + evtdir),
+iio_get_time_ns(indio_dev)); returnIRQ_HANDLED;
}Is this change reflected to the user-space? If so, is it safe? We shouldn't break the ABI, right?
Quoted 3 lines
On things like this, we will sometime risk breaking userspace in hopes that no one was actually depending on it. If no one notices that we broke it, did we really break it?
If it's a bug we often just break ABI compatibility anyway. If we get a report we'll make it spit out both events (and someone doesn't handle an extra one we point them at the docs - that hopefully exist ;) - that say you must handle ones you don't expect).
J
Quoted 13 lines
Quoted 12 lines
Yours,
-- Matti---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland~~ When things go utterly wrong vim users can always type :help! ~~
Re: [PATCH v2 2/4] iio: light: veml6030: fix channel type when pushing events
Quoted 37 lines · Jonathan Cameron
Quoted 34 lines · On Mon, 18 May 2026 09:48:39 -0500 David Lechner <[email protected]> wrote:
Quoted 32 lines · Matti Vaittinen
Quoted 19 lines · Javier Carrasco
The events are registered for
IIO_LIGHTand not forIIO_INTENSITY. Use the correct channel type.
This bug was introduced in the first version of the driver.When at it, fix minor checkpatch code style warning (alignment).
Signed-off-by Javier Carrasco <[email protected]>--- drivers/iio/light/veml6030.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/iio/light/veml6030.c +0
-0@@ -871,9 +871,11 @@ static irqreturn_t veml6030_event_handler(int irq, void *private) else evtdir = IIO_EV_DIR_FALLING; - iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_INTENSITY,drivers/iio/light/veml6030.c static irqreturn_t veml6030_event_handler(int irq, void *private) · line 881
Quoted 10 lines
drivers/iio/light/veml6030.c +5
-2- 0, IIO_EV_TYPE_THRESH, evtdir), - iio_get_time_ns(indio_dev)); + iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, + 0, + IIO_EV_TYPE_THRESH, + evtdir), + iio_get_time_ns(indio_dev)); return IRQ_HANDLED; }Is this change reflected to the user-space? If so, is it safe? We shouldn't break the ABI, right?
Quoted 8 lines
Quoted 3 lines
On things like this, we will sometime risk breaking userspace in hopes that no one was actually depending on it. If no one notices that we broke it, did we really break it?
If it's a bug we often just break ABI compatibility anyway. If we get a report we'll make it spit out both events (and someone doesn't handle an extra one we point them at the docs - that hopefully exist ;) - that say you must handle ones you don't expect).
Well, you guys are the ones being grilled if the brown thing hits the fan. ;) So, if you're willing to take the risk, then I am not complaining :)
Yours,
-- Matti
Signature · 6 lines
--- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Javier Carrasco
maintainerPATCH v2 3/4 dt-bindings: iio: light: veml6030: add veml6031x00 ALS series
In reply to Javier CarrascoThese ambient light sensors share their properties with the ones from the same manufacturer that are supported by this bindings.
Note that only two datasheets are provided as every one of them covers two devices (veml6031x00/veml60311x00 and veml6031x01/veml60311x01).
--- .../bindings/iio/light/vishay,veml6030.yaml | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml +22 -1
@@ -4,7 +4,9 @@ $id: http://devicetree.org/schemas/iio/light/vishay,veml6030.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: VEML3235, VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS) +title: + VEML3235, VEML6030, VEML6031x00 series, VEML6035 and VEML7700 Ambient + Light Sensors (ALS) maintainers: - Rishi Gupta <[email protected]>
@@ -22,12 +24,18 @@ description: | Specifications about the sensors can be found at: https://www.vishay.com/docs/80131/veml3235.pdf https://www.vishay.com/docs/84366/veml6030.pdf + https://www.vishay.com/docs/80007/veml6031x00.pdf + https://www.vishay.com/docs/80008/veml6031x01.pdf https://www.vishay.com/docs/84889/veml6035.pdf https://www.vishay.com/docs/84286/veml7700.pdf properties: compatible: enum: + - vishay,veml6031x00 + - vishay,veml6031x01 + - vishay,veml60311x00 + - vishay,veml60311x01 - vishay,veml3235 - vishay,veml6030 - vishay,veml6035
@@ -67,6 +75,8 @@ allOf: properties: compatible: enum: + - vishay,veml6031x00 + - vishay,veml6031x01 - vishay,veml6035 then: properties:
@@ -79,12 +89,23 @@ allOf: compatible: enum: - vishay,veml3235 + - vishay,veml60311x00 + - vishay,veml60311x01 - vishay,veml7700 then: properties: reg: enum: - 0x10 + + - if: + properties: + compatible: + enum: + - vishay,veml3235 + - vishay,veml7700 + then: + properties: interrupts: false additionalProperties: false
Signature · 1 line
2.43.0
Javier Carrasco
maintainerPATCH v2 4/4 iio: light: add support for veml6031x00 ALS series
In reply to Javier CarrascoThese sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
--- MAINTAINERS | 6 + drivers/iio/light/Kconfig | 14 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6031x00.c | 1193 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1214 insertions(+)
MAINTAINERS +6 -0
@@ -28381,6 +28381,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml F: drivers/iio/light/veml6046x00.c +VISHAY VEML6031X00 AMBIENT LIGHT SENSOR DRIVER +M: Javier Carrasco <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml +F: drivers/iio/light/veml6031x00.c + VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER M: Javier Carrasco <[email protected]> S: Maintained
drivers/iio/light/Kconfig +14 -0
@@ -713,6 +713,20 @@ config VEML6030 To compile this driver as a module, choose M here: the module will be called veml6030. +config VEML6031X00 + tristate "VEML6031X00 ambient light sensor series" + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select IIO_GTS_HELPER + depends on I2C + help + Say Y here if you want to build a driver for the Vishay VEML6031X00 + ambient light sensor series. + + To compile this driver as a module, choose M here: the + module will be called veml6031x00. + config VEML6040 tristate "VEML6040 RGBW light sensor" select REGMAP_I2C
drivers/iio/light/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_VCNL4000) += vcnl4000.o obj-$(CONFIG_VCNL4035) += vcnl4035.o obj-$(CONFIG_VEML3235) += veml3235.o obj-$(CONFIG_VEML6030) += veml6030.o +obj-$(CONFIG_VEML6031X00) += veml6031x00.o obj-$(CONFIG_VEML6040) += veml6040.o obj-$(CONFIG_VEML6046X00) += veml6046x00.o obj-$(CONFIG_VEML6070) += veml6070.o
drivers/iio/light/veml6031x00.c new file +1193 -0
1,193 lines not on this page · raw message
Signature · 1 line
2.43.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · Sanjay Chitroda
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Thank you for new driver support.
It would be good to add blank line after this to have iio and common header group separate.
Also, header should be in order.
Something went so wrong with your email. You answered with something like 5 lines of text in the messages of almost 2000 lines... (It seems your message have the full text of the original one + HTML crap on top.)
Can you avoid doing that in the future, please?
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Sanjay Chitroda
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Thank you for new driver support.
Quoted 7 lines
Quoted 3 lines
It would be good to add blank line after this to have iio and common header group separate.
Also, header should be in order.
Something went so wrong with your email. You answered with something like 5 lines of text in the messages of almost 2000 lines... (It seems your message have the full text of the original one + HTML crap on top.)
1 <no description> [multipa/alternativ, 7bit, 84K]
2 ├─><no description> [text/plain, quoted, utf-8, 36K] 3 └─><no description> [text/html, quoted, utf-8, 47K]
Quoted 2 lines
Can you avoid doing that in the future, please?
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Can you split this to two or more patches:
- basic functionality
- feature 1 (exempli gratia, IR)
- feature 2 (exempli gratia, multiplexed interrupt)
- ...
?
But let's wait for Sashiko if it swallows this big slice of the pie and not choke on it.
...
drivers/iio/light/veml6031x00.c line 1165
Quoted 12 lines
drivers/iio/light/veml6031x00.c new file +12
-0+ { + .compatible = "vishay,veml6031x01", + .data = &veml6031x01_chip, + }, + { + .compatible = "vishay,veml60311x00", + .data = &veml60311x00_chip, + }, + { + .compatible = "vishay,veml60311x01", + .data = &veml60311x01_chip, + },
Oh, is 'x' is a real letter in the part number or a wildcard? If the latter, please avoid. Choose the base part number instead.
...
drivers/iio/light/veml6031x00.c line 1176
Quoted 7 lines
drivers/iio/light/veml6031x00.c new file +7
-0+static const struct i2c_device_id veml6031x00_id[] = { + {"veml6031x00" , (kernel_ulong_t)&veml6031x00_chip }, + {"veml6031x01" , (kernel_ulong_t)&veml6031x01_chip }, + {"veml60311x00" , (kernel_ulong_t)&veml60311x00_chip }, + {"veml60311x01" , (kernel_ulong_t)&veml60311x01_chip }, + { } +};
Perhaps use C99 initialisers, as there is an activity to change all drivers to follow that. Jonathan, btw, what do you think we should do in the light of Uwe's approach? Require C99 initialisers in new code, or something else?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Javier Carrasco
maintainerQuoted 5 lines · Andy Shevchenko
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Quoted 7 lines
Can you split this to two or more patches:
- basic functionality
- feature 1 (exempli gratia, IR)
- feature 2 (exempli gratia, multiplexed interrupt)
- ...?
Yes, I can. I will wait for more feedback before proceeding.
Quoted 6 lines
But let's wait for Sashiko if it swallows this big slice of the pie and not choke on it.
...
Quoted 16 lines
drivers/iio/light/veml6031x00.c line 1165
Quoted 12 lines
drivers/iio/light/veml6031x00.c new file +12
-0+ { + .compatible = "vishay,veml6031x01", + .data = &veml6031x01_chip, + }, + { + .compatible = "vishay,veml60311x00", + .data = &veml60311x00_chip, + }, + { + .compatible = "vishay,veml60311x01", + .data = &veml60311x01_chip, + },Oh, is 'x' is a real letter in the part number or a wildcard? If the latter, please avoid. Choose the base part number instead.
I mentioned that in the cover letter: the x belongs to the names in the datasheets and every part number.
Quoted 13 lines
...
drivers/iio/light/veml6031x00.c line 1176
Quoted 7 lines
drivers/iio/light/veml6031x00.c new file +7
-0+static const struct i2c_device_id veml6031x00_id[] = { + {"veml6031x00" , (kernel_ulong_t)&veml6031x00_chip }, + {"veml6031x01" , (kernel_ulong_t)&veml6031x01_chip }, + {"veml60311x00" , (kernel_ulong_t)&veml60311x00_chip }, + {"veml60311x01" , (kernel_ulong_t)&veml60311x01_chip }, + { } +};Perhaps use C99 initialisers, as there is an activity to change all drivers to follow that. Jonathan, btw, what do you think we should do in the light of Uwe's approach? Require C99 initialisers in new code, or something else?
I will account for that in v3 alongside any other suggestions that might still arise, thank you.
Best regards,
Javier
Quoted 12 lines · Javier Carrasco
Quoted 11 lines · Andy Shevchenko
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Can you split this to two or more patches:
- basic functionality
- feature 1 (exempli gratia, IR)
- feature 2 (exempli gratia, multiplexed interrupt)
- ...
Quoted 3 lines
Quoted 1 line
?
Yes, I can. I will wait for more feedback before proceeding.
Sure, with a driver like this the recommended time between the sequential versions is about 1 week.
Quoted 2 lines
Quoted 2 lines
But let's wait for Sashiko if it swallows this big slice of the pie and not choke on it.
Also note that in IIO we expect ~750 lines per patch with rare exceptions. ~1300 is almost double of this, so the split I am sure is desirable.
...
Quoted 5 lines
Quoted 2 lines
Oh, is 'x' is a real letter in the part number or a wildcard? If the latter, please avoid. Choose the base part number instead.
I mentioned that in the cover letter: the x belongs to the names in the datasheets and every part number.
Ah, I missed that. Thanks for confirming.
...
Quoted 12 lines
Quoted 11 lines
drivers/iio/light/veml6031x00.c line 1176
Quoted 7 lines
drivers/iio/light/veml6031x00.c new file +7
-0+static const struct i2c_device_id veml6031x00_id[] = { + {"veml6031x00" , (kernel_ulong_t)&veml6031x00_chip }, + {"veml6031x01" , (kernel_ulong_t)&veml6031x01_chip }, + {"veml60311x00" , (kernel_ulong_t)&veml60311x00_chip }, + {"veml60311x01" , (kernel_ulong_t)&veml60311x01_chip }, + { } +};Perhaps use C99 initialisers, as there is an activity to change all drivers to follow that. Jonathan, btw, what do you think we should do in the light of Uwe's approach? Require C99 initialisers in new code, or something else?
Quoted 2 lines
I will account for that in v3 alongside any other suggestions that might still arise, thank you.
At least C99 initialisers make code robust, independently on the decision it might be good to go with them, the only question here is more administrative (if we want this to be already a requirement for a new code in IIO or not...
yet).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 18 lines · On Wed, 13 May 2026 19:56:54 +0300 Andy Shevchenko…
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Can you split this to two or more patches:
- basic functionality
- feature 1 (exempli gratia, IR)
- feature 2 (exempli gratia, multiplexed interrupt)
- ...?
But let's wait for Sashiko if it swallows this big slice of the pie and not choke on it.
...
Quoted 16 lines
drivers/iio/light/veml6031x00.c line 1165
Quoted 12 lines
drivers/iio/light/veml6031x00.c new file +12
-0+ { + .compatible = "vishay,veml6031x01", + .data = &veml6031x01_chip, + }, + { + .compatible = "vishay,veml60311x00", + .data = &veml60311x00_chip, + }, + { + .compatible = "vishay,veml60311x01", + .data = &veml60311x01_chip, + },Oh, is 'x' is a real letter in the part number or a wildcard? If the latter, please avoid. Choose the base part number instead.
FWIW I wondered this before. It's an actual x not a wildcard.
Quoted 13 lines
...
drivers/iio/light/veml6031x00.c line 1176
Quoted 7 lines
drivers/iio/light/veml6031x00.c new file +7
-0+static const struct i2c_device_id veml6031x00_id[] = { + {"veml6031x00" , (kernel_ulong_t)&veml6031x00_chip }, + {"veml6031x01" , (kernel_ulong_t)&veml6031x01_chip }, + {"veml60311x00" , (kernel_ulong_t)&veml60311x00_chip }, + {"veml60311x01" , (kernel_ulong_t)&veml60311x01_chip }, + { } +};Perhaps use C99 initialisers, as there is an activity to change all drivers to follow that. Jonathan, btw, what do you think we should do in the light of Uwe's approach? Require C99 initialisers in new code, or something else?
Require them for device_id tables so that Uwe doesn't fight a loosing battle for ever!
Quoted 1 line
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Race Condition and API Violation in `veml6031x00_write_raw` - [High] Out-of-Bounds Array Access in…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Race Condition and API Violation in veml6031x00_write_raw
- [High] Out-of-Bounds Array Access in Trigger Handler
- [High] PM Runtime Usage Counter Underflow and Race Condition in veml6031x00_write_event_config
- [High] TOCTOU Race and Lockless Hardware State Rollback in veml6031x00_set_trigger_state
- [High] Sensor Left in Hardware Shutdown During Initial Active PM State
- [Medium] PM Runtime Usage Counter Leak on Probe Error Paths
- [Medium] Negative Input Values Bypass Period Validation
- [Medium] iio_device_claim_direct Blocks Needlessly Due to Long Sleep in veml6031x00_single_read --
commit a33cd1a810baeac2c7084228357077baf67cdd60
Author: Javier Carrasco <[email protected]>
iio: light: add support for veml6031x00 ALS series
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Quoted 5 lines
drivers/iio/light/veml6031x00.c new file +0
-0
[ ... ]
drivers/iio/light/veml6031x00.c line 426
Quoted 9 lines
drivers/iio/light/veml6031x00.c new file +9
-0+static int veml6031x00_write_period (struct iio_dev *iio,int val) +{ +struct veml6031x00_data *data =iio_priv (iio); + +if (val >8 ||hweight8 (val) !=1 ) +return -EINVAL ; + +return regmap_field_write (data->rf.pers,ffs (val) -1 ); +}
Is it possible for negative values to bypass this validation?
If val is a negative number such as -128, val > 8 is false, and hweight8(-128) checks the bottom 8 bits, which evaluates to exactly 1 bit set. This would bypass the check and allow malformed inputs to be written to the hardware.
[ ... ]
Quoted 3 lines
drivers/iio/light/veml6031x00.c new file +3
-0+static int veml6031x00_single_read (struct iio_dev *iio,enum iio_chan_type type, +int *val) +{
[ ... ]
drivers/iio/light/veml6031x00.c line 559
Quoted 11 lines
drivers/iio/light/veml6031x00.c new file +11
-0+ ret =veml6031x00_get_it (data, &it_sec, &it_usec); +if (ret <0 ) + goto put_autosuspend; + +/* integration time + 10 % to ensure completion */ +fsleep ((it_sec *MICRO ) + it_usec + (it_usec /10 )); + +if (!iio_device_claim_direct (iio)) { + ret = -EBUSY ; + goto put_autosuspend; + }
Could iio_device_claim_direct() be called before sleeping?
Currently, if a triggered buffer is actively capturing data, this will sleep for the entire integration delay (which could be up to 400ms) before returning -EBUSY and rejecting the direct read.
[ ... ]
drivers/iio/light/veml6031x00.c line 622
Quoted 13 lines
drivers/iio/light/veml6031x00.c new file +13
-0+static int veml6031x00_write_raw (struct iio_dev *iio, +struct iio_chan_spec const *chan, +int val,int val2,long mask) +{ +switch (mask) { +case IIO_CHAN_INFO_INT_TIME : +return veml6031x00_set_it (iio, val, val2); +case IIO_CHAN_INFO_SCALE : +return veml6031x00_set_scale (iio, val, val2); +default : +return -EINVAL ; + } +}
Does this need to hold a lock or claim direct mode?
The helpers veml6031x00_set_it() and veml6031x00_set_scale() perform multiple regmap operations.
Without holding a driver-level mutex or claiming direct mode with iio_device_claim_direct_mode(), concurrent sysfs writes could interleave and corrupt the configuration. This also allows userspace to alter hardware settings while a triggered buffer is actively capturing data.
[ ... ]
Quoted 18 lines
drivers/iio/light/veml6031x00.c new file +18
-0+static int veml6031x00_write_event_config (struct iio_dev *iio, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +bool state) +{ +struct veml6031x00_data *data =iio_priv (iio); +int ret; + + scoped_guard(mutex, &data->lock) { +/* avoid multiple increments/decrements from one source */ +if (state == data->ev_en) +return 0 ; + + ret =veml6031x00_set_interrupt (data, state); +if (ret) +return ret; +
drivers/iio/light/veml6031x00.c line 735
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ data->ev_en = state; + } + +if (state) +return pm_runtime_resume_and_get (data->dev); + +pm_runtime_put_autosuspend (data->dev); + +return 0 ; +}
Could this lead to a PM runtime usage counter underflow or a race condition?
If state is true and pm_runtime_resume_and_get() fails, the function returns an error but leaves data->ev_en as true and the interrupt enabled. A subsequent call to disable the event would unconditionally call pm_runtime_put_autosuspend(), underflowing the usage counter.
Additionally, because the PM runtime calls are outside the mutex, concurrent calls could execute the PM runtime updates out-of-order, leading to reference count corruption.
[ ... ]
Quoted 14 lines
drivers/iio/light/veml6031x00.c new file +14
-0+static int veml6031x00_set_trigger_state (struct iio_trigger *trig,bool state) +{ +struct iio_dev *iio =iio_trigger_get_drvdata (trig); +struct veml6031x00_data *data =iio_priv (iio); +int ret; + + scoped_guard(mutex, &data->lock) { +if (state == data->trig_en) +return 0 ; + + ret =veml6031x00_set_interrupt (data, state); +if (ret) +return ret; + }
[ ... ]
Quoted 7 lines
drivers/iio/light/veml6031x00.c new file +7
-0+ ret =veml6031x00_set_af_trig (data, state); +if (ret) + goto err_clear_af; + +scoped_guard (mutex, &data->lock) + data->trig_en = state; +
drivers/iio/light/veml6031x00.c line 884
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+return 0 ; + +err_clear_af: +regmap_update_bits (data->regmap,VEML6031X00_REG_CONF0 , +VEML6031X00_CONF0_AF , +FIELD_PREP (VEML6031X00_CONF0_AF , !state)); +err_disable_interrupt: +veml6031x00_set_interrupt (data, !state); +return ret; +}
Does this sequence create a race condition with the lock handling?
The function checks state == data->trig_en and increments an internal counter in veml6031x00_set_interrupt() inside the first scoped_guard, but data->trig_en isn't updated until the second scoped_guard. Concurrent callers could bypass the state check before data->trig_en is updated.
Also, if an error occurs, the err_disable_interrupt path calls veml6031x00_set_interrupt() outside the lock. This could race with other event configurations and desynchronize the software state from the hardware state.
[ ... ]
Quoted 14 lines
drivers/iio/light/veml6031x00.c new file +14
-0+static irqreturn_t veml6031x00_trig_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *iio = pf->indio_dev; +struct veml6031x00_data *data =iio_priv (iio); +int ch, ret, i =0 ; +struct { +__le16 chans[2 ]; +aligned_s64 timestamp; + } scan; + +memset (&scan,0 ,sizeof (scan)); + +if (*iio->active_scan_mask ==VEML6031X00_ALL_CH_MASK ) {
[ ... ]
drivers/iio/light/veml6031x00.c line 922
Quoted 9 lines
drivers/iio/light/veml6031x00.c new file +9
-0+ }else { +iio_for_each_active_channel (iio, ch) { + ret =regmap_bulk_read (data->regmap, + iio->channels[ch].address, + &scan.chans[i++],2 ); +if (ret) + goto done; + } + }
Can this loop overflow scan.chans[]?
If the user enables the IIO timestamp channel alongside ALS and IR, the active scan mask includes the timestamp bit, so execution falls into the else branch.
The iio_for_each_active_channel() loop doesn't skip the timestamp channel, so it would execute an I2C read into scan.chans[i++] when i reaches 2, overflowing the 2-element array.
[ ... ]
Quoted 2 lines
drivers/iio/light/veml6031x00.c new file +2
-0+static int veml6031x00_probe (struct i2c_client *i2c) +{
[ ... ]
Quoted 5 lines
drivers/iio/light/veml6031x00.c new file +5
-0+ ret =pm_runtime_set_active (dev); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to activate PM runtime\n" ); + + ret =devm_pm_runtime_enable (dev);
drivers/iio/light/veml6031x00.c line 1077
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to enable PM runtime\n" ); + +pm_runtime_get_noresume (dev); +pm_runtime_set_autosuspend_delay (dev,VEML6031X00_AUTOSUSPEND_MS ); +pm_runtime_use_autosuspend (dev); + + ret =veml6031x00_validate_part_id (data); +if (ret) +return ret;
Should the sensor be powered on before marking it active?
The hardware powers up in a shutdown state, and veml6031x00_als_power_on() is not called here before pm_runtime_set_active(). During the initial autosuspend delay, reads will assume the device is awake and attempt to read from a powered-down sensor.
Also, does this code leak the PM runtime reference on probe errors?
If an error occurs during veml6031x00_validate_part_id() or subsequent initialization steps, the function returns without dropping the reference acquired by pm_runtime_get_noresume(dev).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jonathan Cameron
maintainerQuoted 5 lines · On Wed, 13 May 2026 17:49:44 +1300 Javier Carrasco…
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Signed-off-by Javier Carrasco <[email protected]>
Usual stuff of check what Sashiko came up with:
https://sashiko.dev/#/patchset/20260513-veml6031x00-v2-0-4703ca661a1d%40gmail.com
I'm fairly sure one or two of them are wrong (the timestamp scan index thing trips it up a lot).
Anyhow, a couple of other things inline (+ highlighting one sashiko bug I definitely agree with!)
Pretty good state on the whole. Obviously it is a bit big though so breaking it up as Andy requested will get more eyes on the code.
Thanks,
Jonathan
Quoted 12 lines
--- MAINTAINERS | 6 + drivers/iio/light/Kconfig | 14 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6031x00.c | 1193 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1214 insertions(+)MAINTAINERS +0
-0
MAINTAINERS S: Maintained · line 28387
Quoted 7 lines
MAINTAINERS +4
-0@@ -28381,6 +28381,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml F: drivers/iio/light/veml6046x00.c +VISHAY VEML6031X00 AMBIENT LIGHT SENSOR DRIVER +M: Javier Carrasco <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
Minor but I'd prefer the entry to be added in previous patch (the dt binding) and then updated here. Avoids a few script warnings and correctly reflects what is covered after each patch.
Quoted 11 lines
MAINTAINERS +2
-0+F: drivers/iio/light/veml6031x00.c + VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER M: Javier Carrasco <[email protected]> S: Maintaineddrivers/iio/light/veml6031x00.c new file +0
-0
drivers/iio/light/veml6031x00.c line 39
Quoted 3 lines
drivers/iio/light/veml6031x00.c new file +2
-0+/* Bit masks for specific functionality */ +#define VEML6031X00_ALL_CH_MASK GENMASK(1, 0)
This isn't a mask. I'd express it as BIT() | BIT() where it's used.
drivers/iio/light/veml6031x00.c line 52
Quoted 2 lines
drivers/iio/light/veml6031x00.c new file +2
-0+/* Autosuspend delay */ +#define VEML6031X00_AUTOSUSPEND_MS 2000
Given it's an arbitrary value used in one place. I'd be tempted just to put the value in that call as that's where we'd typically look if wondering what it is.
drivers/iio/light/veml6031x00.c line 327
Quoted 2 lines
drivers/iio/light/veml6031x00.c new file +2
-0+ +static int veml6031x00_get_it (struct veml6031x00_data *data,int *val,int *val2)
See below. Why pass in val?
Quoted 14 lines
drivers/iio/light/veml6031x00.c new file +14
-0+{ +int ret, it_idx; + + ret =regmap_field_read (data->rf.it, &it_idx); +if (ret) +return ret; + + ret =iio_gts_find_int_time_by_sel (&data->gts, it_idx); +if (ret <0 ) +return ret; + + *val2 = ret; + *val =0 ; +
drivers/iio/light/veml6031x00.c
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +8
-0+return IIO_VAL_INT_PLUS_MICRO ; +} + +static int veml6031x00_write_period (struct iio_dev *iio,int val) +{ +struct veml6031x00_data *data =iio_priv (iio); + +if (val >8 ||hweight8 (val) !=1 )
Sashiko points out that this should probably sanity check val >= 0 as top bit set passes that test but is garbage.
Quoted 15 lines
drivers/iio/light/veml6031x00.c new file +13
-0+return -EINVAL ; + +return regmap_field_write (data->rf.pers,ffs (val) -1 ); +} +static int veml6031x00_single_read (struct iio_dev *iio,enum iio_chan_type type, +int *val) +{ +struct veml6031x00_data *data =iio_priv (iio); +int addr, it_sec, it_usec, ret; +__le16 reg; + +switch (type) { +case IIO_LIGHT :
drivers/iio/light/veml6031x00.c line 545
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ addr =VEML6031X00_REG_ALS_L ; +break ; +case IIO_INTENSITY : + addr =VEML6031X00_REG_IR_L ; +break ; +default : +return -EINVAL ; + } + + ret =pm_runtime_resume_and_get (data->dev);
Ideally:
Use PM_RUNTIME_ACQUIRE_AUTOSUSPEND() and PM_RUNTIME_ACQUIRE_ERR() + further down:IIO_DEV_ACQUIRE_DIRECT_MODE() and IIO_DEV_ACQUIRE_FAILED() -
I'm slowly trying to encourage more use of those in IIO (but not mass conversions!) and would like a few more good examples of how to do it in tree!
That should then allow direct returns in error paths. The scope will extend a tiny bit further but only to include the le16_to_cpu so that is fine.
Quoted 29 lines
drivers/iio/light/veml6031x00.c new file +29
-0+if (ret) +return ret; + + ret =veml6031x00_get_it (data, &it_sec, &it_usec); +if (ret <0 ) + goto put_autosuspend; + +/* integration time + 10 % to ensure completion */ +fsleep ((it_sec *MICRO ) + it_usec + (it_usec /10 )); + +if (!iio_device_claim_direct (iio)) { + ret = -EBUSY ; + goto put_autosuspend; + } + + ret =regmap_bulk_read (data->regmap, addr, ®,sizeof (reg)); +iio_device_release_direct (iio); +if (ret <0 ) + goto put_autosuspend; + + *val =le16_to_cpu (reg); + ret =IIO_VAL_INT ; + +put_autosuspend: +pm_runtime_put_autosuspend (data->dev); +return ret; +} + +static int veml6031x00_read_raw(struct iio_dev *iio,
drivers/iio/light/veml6031x00.c line 584
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct veml6031x00_data *data = iio_priv(iio); + +switch (mask) { +case IIO_CHAN_INFO_RAW : +return veml6031x00_single_read (iio, chan->type, val); +case IIO_CHAN_INFO_INT_TIME : + *val =0 ;
Forcing only *val to 0 then passing it to the get_it made me wonder why not val2. Seems better option is don't pass val to a function that doesn't use it.
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+return veml6031x00_get_it (data, val, val2); +case IIO_CHAN_INFO_SCALE : +return veml6031x00_get_scale (data, val, val2); +default : +return -EINVAL ; + } +} + +static int veml6031x00_read_avail(struct iio_dev *iio, + struct iio_chan_spec const *chan,
drivers/iio/light/veml6031x00.c line 604
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ const int **vals, int *type, int *length, + long mask) +{ + struct veml6031x00_data *data = iio_priv(iio); + +switch (mask) { +case IIO_CHAN_INFO_INT_TIME : +return iio_gts_avail_times (&data->gts, vals, type, length); +case IIO_CHAN_INFO_SCALE : +return iio_gts_all_avail_scales (&data->gts, vals, type, length);
default: return -EINVAL;
for consistency and because it makes intent a little clearer.
drivers/iio/light/veml6031x00.c line 640
Quoted 8 lines
drivers/iio/light/veml6031x00.c new file +7
-0+ } + +return -EINVAL ; +} +static int veml6031x00_set_interrupt (struct veml6031x00_data *data,bool state) +{ +int ret;
I wondered about whether the locking around this was sufficient to not need atomics + ensure we don't end up with an error decrement resulting in a counter going to 0 that wasn't previously... Not quite I think because you don't hold the lock on the error path in veml6031x00_set_trigger_state()
I think the lock should be held there then mark this as __must_hold() and the atomics aren't necessary. Right now they don't quite do the job anyway.
Quoted 43 lines
drivers/iio/light/veml6031x00.c new file +41
-0+ +if (state) { +if (atomic_inc_return (&data->int_users) >1 ) +return 0 ; + }else { +if (atomic_dec_return (&data->int_users) >0 ) +return 0 ; + } + + ret =regmap_field_write (data->rf.int_en, state); +if (ret) { +if (state) +atomic_dec (&data->int_users); +else +atomic_inc (&data->int_users); + } + +return ret; +} + +static int veml6031x00_buffer_preenable (struct iio_dev *iio) +{ +struct veml6031x00_data *data =iio_priv (iio); +int ret, it_sec, it_usec; + + ret =pm_runtime_resume_and_get (data->dev); +if (ret) +return ret; + + ret =veml6031x00_get_it (data, &it_sec, &it_usec); +if (ret <0 ) { +pm_runtime_put_autosuspend (data->dev); +return ret; + } + +/* +* Wait one integration period + 10% margin so the first triggered +* read does not race with the sensor completing its first conversion +* after power-on. +*/ +fsleep ((it_sec *MICRO ) + it_usec + (it_usec /10 ));
drivers/iio/light/veml6031x00.c
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ +return 0 ; +} + +static int veml6031x00_buffer_postdisable (struct iio_dev *iio) +{ +struct veml6031x00_data *data =iio_priv (iio); +struct device *dev = data->dev; + +pm_runtime_put_autosuspend (dev);
Might as well do
pm_runtime_put_autosuspend(data->dev);
and save a local variable.
Quoted 8 lines
drivers/iio/light/veml6031x00.c new file +6
-0+ +return 0 ; +} + +static irqreturn_t veml6031x00_trig_handler (int irq,void *p) +{
drivers/iio/light/veml6031x00.c line 906
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+struct iio_poll_func *pf = p; +struct iio_dev *iio = pf->indio_dev; +struct veml6031x00_data *data =iio_priv (iio); +int ch, ret, i =0 ; +struct { +__le16 chans[2 ]; +aligned_s64 timestamp; + } scan; + +memset (&scan,0 ,sizeof (scan));
Can do
} scan = { };Which is guaranteed by the options the kernel is built with + self tests to initialize the holes as well.
drivers/iio/light/veml6031x00.c line 918
Quoted 12 lines
drivers/iio/light/veml6031x00.c new file +12
-0+ +if (*iio->active_scan_mask ==VEML6031X00_ALL_CH_MASK ) { + ret =regmap_bulk_read (data->regmap, +VEML6031X00_REG_ALS_L , + &scan.chans,sizeof (scan.chans)); +if (ret) + goto done; + }else { +iio_for_each_active_channel (iio, ch) { + ret =regmap_bulk_read (data->regmap, + iio->channels[ch].address, + &scan.chans[i++],2 );
sizeof(*scan.chans) nicer than the 2. I would have said sizeof(scan.chans[i]) but then you'll have to pull the i++ out of the call. Either is fine, jut replace the magic 2.
drivers/iio/light/veml6031x00.c line 924
Quoted 6 lines
drivers/iio/light/veml6031x00.c new file +6
-0+if (ret) + goto done; + } + } + +iio_push_to_buffers_with_timestamp (iio, &scan, pf->timestamp);
iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), pf->timestamp);
The _timestamp variant is deprecated as we can't do sanity checks on the buffer being big enough.
Quoted 14 lines
drivers/iio/light/veml6031x00.c new file +13
-0+ +done: +iio_trigger_notify_done (iio->trig); + +return IRQ_HANDLED ; +} + +static int veml6031x00_hw_init (struct iio_dev *iio) +{ +struct veml6031x00_data *data =iio_priv (iio); +struct device *dev = data->dev; +int ret, val; +__le16 reg;
drivers/iio/light/veml6031x00.c line 964
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ +/* Max resolution = 6.9632 lx/cnt for gain = 0.125 and IT = 3.125ms */ + ret =devm_iio_init_iio_gts (data->dev,6 ,963200000 , + veml6031x00_gain_sel, +ARRAY_SIZE (veml6031x00_gain_sel), + veml6031x00_it_sel, +ARRAY_SIZE (veml6031x00_it_sel), + &data->gts); +if (ret) +return dev_err_probe (data->dev, ret,"failed to init iio gts\n" );
Use dev
drivers/iio/light/veml6031x00.c line 968
Quoted 4 lines
drivers/iio/light/veml6031x00.c new file +4
-0+ + reg =0 ; + ret =regmap_bulk_write (data->regmap,VEML6031X00_REG_WL_L , ®, +sizeof (reg));
I don't mind slightly long lines if it helps readability. Here I think it would be nicer as:
ret = regmap_bulk_write(data->regmap, VEML6031X00_REG_WL_L, ®, sizeof(reg));
drivers/iio/light/veml6031x00.c line 974
Quoted 6 lines
drivers/iio/light/veml6031x00.c new file +6
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to set low threshold\n" ); + + reg =cpu_to_le16 (U16_MAX ); + ret =regmap_bulk_write (data->regmap,VEML6031X00_REG_WH_L , ®, +sizeof (reg));
Similar on slightly long lines.
Quoted 32 lines
drivers/iio/light/veml6031x00.c new file +32
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to set high threshold\n" ); + + ret =regmap_field_write (data->rf.int_en,0 ); +if (ret <0 ) +return ret; + + ret =regmap_read (data->regmap,VEML6031X00_REG_INT , &val); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to clear interrupts\n" ); + +return 0 ; +} + +static int veml6031x00_setup_irq (struct i2c_client *i2c,struct iio_dev *iio) +{ +struct veml6031x00_data *data =iio_priv (iio); +struct device *dev = data->dev; +int ret; + + data->trig =devm_iio_trigger_alloc (dev,"%s-drdy%d" , iio->name, +iio_device_id (iio)); +if (!data->trig) +return -ENOMEM ; + + data->trig->ops = &veml6031x00_trigger_ops; +iio_trigger_set_drvdata (data->trig, iio); + + ret =devm_iio_trigger_register (dev, data->trig); +if (ret) +return ret; +
drivers/iio/light/veml6031x00.c line 1016
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ iio->trig =iio_trigger_get (data->trig); + ret =devm_request_threaded_irq (dev, i2c->irq,NULL , + veml6031x00_interrupt, +IRQF_ONESHOT , + iio->name, iio); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to request irq %d\n" , + i2c->irq); + + iio->info = &veml6031x00_info;
As below - I'd set this in the caller.
Quoted 61 lines
drivers/iio/light/veml6031x00.c new file +61
-0+ +return 0 ; +} + +static int veml6031x00_probe (struct i2c_client *i2c) +{ +struct device *dev = &i2c->dev; +struct veml6031x00_data *data; +struct iio_dev *iio; +struct regmap *regmap; +int ret; + + regmap =devm_regmap_init_i2c (i2c, &veml6031x00_regmap_config); +if (IS_ERR (regmap)) +return dev_err_probe (dev,PTR_ERR (regmap), +"Failed to set regmap\n" ); + + iio =devm_iio_device_alloc (dev,sizeof (*data)); +if (!iio) +return -ENOMEM ; + + data =iio_priv (iio); +i2c_set_clientdata (i2c, iio); + data->dev = dev; + data->regmap = regmap; + + ret =devm_mutex_init (dev, &data->lock); +if (ret) +return ret; + + ret =veml6031x00_regfield_init (data); +if (ret) +return dev_err_probe (dev, ret,"Failed to init regfield\n" ); + + ret =devm_regulator_get_enable (dev,"vdd" ); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable regulator\n" ); + + data->chip =i2c_get_match_data (i2c); +if (!data->chip) +return dev_err_probe (dev, -EINVAL ,"Failed to get chip data\n" ); + + ret =devm_add_action_or_reset (dev, veml6031x00_als_shutdown_action, data); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to add shutdown action\n" ); + + ret =pm_runtime_set_active (dev); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to activate PM runtime\n" ); + + ret =devm_pm_runtime_enable (dev); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable PM runtime\n" ); + +pm_runtime_get_noresume (dev); +pm_runtime_set_autosuspend_delay (dev,VEML6031X00_AUTOSUSPEND_MS ); +pm_runtime_use_autosuspend (dev); + + ret =veml6031x00_validate_part_id (data); +if (ret) +return ret;
drivers/iio/light/veml6031x00.c line 1087
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+ + iio->name = data->chip->name; + iio->channels = veml6031x00_channels; + iio->num_channels =ARRAY_SIZE (veml6031x00_channels); + iio->modes =INDIO_DIRECT_MODE ; + +if (i2c->irq) { + ret =veml6031x00_setup_irq (i2c, iio); +if (ret <0 ) +return ret;
I'd drag the setting of info out of setup_irq() and having it here just so it's obvious this is also picking between two different versions of that.
(really minor!)
Quoted 23 lines
drivers/iio/light/veml6031x00.c new file +23
-0+ }else { + iio->info = &veml6031x00_info_no_irq; + } + + ret =veml6031x00_hw_init (iio); +if (ret <0 ) +return ret; + + ret =devm_iio_triggered_buffer_setup (dev, iio,NULL , + veml6031x00_trig_handler, + &veml6031x00_buffer_setup_ops); +if (ret) +return dev_err_probe (dev, ret, +"Failed to register triggered buffer\n" ); + +pm_runtime_put_autosuspend (dev); + + ret =devm_iio_device_register (dev, iio); +if (ret) +return dev_err_probe (dev, ret,"Failed to register iio device\n" ); + +return 0 ; +}
Quoted 3 lines · Javier Carrasco
These sensors provide two light channels (ALS and IR), I2C communication and a multiplexed interrupt line to signal data ready and configurable threshold alarms.
Thanks for the patch! I did only a very quick review, sorry for that. Overall this looks nice! I think Jonathan already asked about the atomics - I agree it looks like locking might be needed.
Anyways, the GTS usage (at a glance) looked nice! :) Just very minor questions below.
Yours,
-- Matti
Quoted 14 lines
Signed-off-by Javier Carrasco <[email protected]>--- MAINTAINERS | 6 + drivers/iio/light/Kconfig | 14 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6031x00.c | 1193 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1214 insertions(+)MAINTAINERS +0
-0
MAINTAINERS S: Maintained · line 28387
Quoted 7 lines
MAINTAINERS +4
-0@@ -28381,6 +28381,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml F: drivers/iio/light/veml6046x00.c +VISHAY VEML6031X00 AMBIENT LIGHT SENSOR DRIVER +M: Javier Carrasco <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
Is this needed? I was (once upon a time) asked to drop the binding doc file from the MAINTAINERS because the binding doc contains the maintainer information. Not sure if it is used by the get_maintainer.pl though, so maybe this is Ok?
Quoted 205 lines
MAINTAINERS +2
-0+F: drivers/iio/light/veml6031x00.c + VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER M: Javier Carrasco <[email protected]> S: Maintaineddrivers/iio/light/Kconfig +14
-0@@ -713,6 +713,20 @@ config VEML6030 To compile this driver as a module, choose M here: the module will be called veml6030. +config VEML6031X00 + tristate "VEML6031X00 ambient light sensor series" + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select IIO_GTS_HELPER + depends on I2C + help + Say Y here if you want to build a driver for the Vishay VEML6031X00 + ambient light sensor series. + + To compile this driver as a module, choose M here: the + module will be called veml6031x00. + config VEML6040 tristate "VEML6040 RGBW light sensor" select REGMAP_I2Cdrivers/iio/light/Makefile +1
-0@@ -66,6 +66,7 @@ obj-$(CONFIG_VCNL4000) += vcnl4000.o obj-$(CONFIG_VCNL4035) += vcnl4035.o obj-$(CONFIG_VEML3235) += veml3235.o obj-$(CONFIG_VEML6030) += veml6030.o +obj-$(CONFIG_VEML6031X00) += veml6031x00.o obj-$(CONFIG_VEML6040) += veml6040.o obj-$(CONFIG_VEML6046X00) += veml6046x00.o obj-$(CONFIG_VEML6070) += veml6070.odrivers/iio/light/veml6031x00.c new file +157
-0@@ -0,0 +1,1193 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* VEML6031X00 Ambient Light Sensor +* +* Copyright (c) 2026, Javier Carrasco <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/interrupt.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/events.h> +#include <linux/iio/trigger.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/iio/triggered_buffer.h> +#include <linux/iio/iio-gts-helper.h> + +/* Device registers */ +#define VEML6031X00_REG_CONF0 0x00 +#define VEML6031X00_REG_CONF1 0x01 +#define VEML6031X00_REG_WH_L 0x04 +#define VEML6031X00_REG_WH_H 0x05 +#define VEML6031X00_REG_WL_L 0x06 +#define VEML6031X00_REG_WL_H 0x07 +#define VEML6031X00_REG_ALS_L 0x10 +#define VEML6031X00_REG_ALS_H 0x11 +#define VEML6031X00_REG_IR_L 0x12 +#define VEML6031X00_REG_IR_H 0x13 +#define VEML6031X00_REG_ID_L 0x14 +#define VEML6031X00_REG_ID_H 0x15 +#define VEML6031X00_REG_INT 0x17 + +/* Bit masks for specific functionality */ +#define VEML6031X00_ALL_CH_MASK GENMASK(1, 0) +#define VEML6031X00_CONF0_SD BIT(0) +#define VEML6031X00_CONF0_AF_TRIG BIT(2) +#define VEML6031X00_CONF0_AF BIT(3) +#define VEML6031X00_CONF1_IR_SD BIT(7) +#define VEML6031X00_INT_TH_H BIT(1) +#define VEML6031X00_INT_TH_L BIT(2) +#define VEML6031X00_INT_DRDY BIT(3) +#define VEML6031X00_INT_MASK (VEML6031X00_INT_TH_L | \ + VEML6031X00_INT_TH_H | \ + VEML6031X00_INT_DRDY) + +/* Autosuspend delay */ +#define VEML6031X00_AUTOSUSPEND_MS 2000 + +enum veml6031x00_scan { +VEML6031X00_SCAN_ALS , +VEML6031X00_SCAN_IR , +VEML6031X00_SCAN_TIMESTAMP , +}; + +struct veml6031x00_rf { +struct regmap_field *gain; +struct regmap_field *int_en; +struct regmap_field *it; +struct regmap_field *pd_div4; +struct regmap_field *pers; +}; + +struct veml6031x00_chip { +const char *name; +const int part_id; +}; + +struct veml6031x00_data { +struct device *dev; +struct iio_gts gts; +struct regmap *regmap; +struct iio_trigger *trig; +struct veml6031x00_rf rf; +const struct veml6031x00_chip *chip; +/* serialize access to irq enable/disable by events and trigger */ +struct mutex lock; +atomic_t int_users; +bool ev_en; +bool trig_en; +}; + +static const struct iio_itime_sel_mul veml6031x00_it_sel[] = { +GAIN_SCALE_ITIME_US (3125 ,0 ,1 ), +GAIN_SCALE_ITIME_US (6250 ,1 ,2 ), +GAIN_SCALE_ITIME_US (12500 ,2 ,4 ), +GAIN_SCALE_ITIME_US (25000 ,3 ,8 ), +GAIN_SCALE_ITIME_US (50000 ,4 ,16 ), +GAIN_SCALE_ITIME_US (100000 ,5 ,32 ), +GAIN_SCALE_ITIME_US (200000 ,6 ,64 ), +GAIN_SCALE_ITIME_US (400000 ,7 ,128 ), +}; + +/* +* The gain selector encodes (PD_D4 << 2) | GAIN to identify each gain setting. +* Gains are multiplied by 8 to work with integers. The values in the iio-gts +* tables don't need corrections because the maximum value of the scale refers +* to GAIN = x1, and the rest of the values are obtained from the resulting +* linear function. +* TODO: add support for MILLI_GAIN_X165 and MILLI_GAIN_X660 +*/ +#define VEML6031X00_SEL_MILLI_GAIN_X125 0x07 +#define VEML6031X00_SEL_MILLI_GAIN_X250 0x04 +#define VEML6031X00_SEL_MILLI_GAIN_X500 0x03 +#define VEML6031X00_SEL_MILLI_GAIN_X1000 0x00 +#define VEML6031X00_SEL_MILLI_GAIN_X2000 0x01 +static const struct iio_gain_sel_pair veml6031x00_gain_sel[] = { +GAIN_SCALE_GAIN (1 ,VEML6031X00_SEL_MILLI_GAIN_X125 ), +GAIN_SCALE_GAIN (2 ,VEML6031X00_SEL_MILLI_GAIN_X250 ), +GAIN_SCALE_GAIN (4 ,VEML6031X00_SEL_MILLI_GAIN_X500 ), +GAIN_SCALE_GAIN (8 ,VEML6031X00_SEL_MILLI_GAIN_X1000 ), +GAIN_SCALE_GAIN (16 ,VEML6031X00_SEL_MILLI_GAIN_X2000 ), +}; + +static IIO_CONST_ATTR(in_illuminance_thresh_either_period_available, "1 2 4 8"); + +static struct attribute *veml6031x00_event_attributes[] = { + &iio_const_attr_in_illuminance_thresh_either_period_available.dev_attr.attr, +NULL +}; + +static const struct attribute_group veml6031x00_event_attr_group = { + .attrs = veml6031x00_event_attributes, +}; + +/* +* Two shutdown bits (SD and ALS_IR_SD) must be cleared to power on +* the device. +*/ +static int veml6031x00_als_power_on (struct veml6031x00_data *data) +{ +int ret; + + ret =regmap_clear_bits (data->regmap,VEML6031X00_REG_CONF0 , +VEML6031X00_CONF0_SD ); +if (ret) +return ret; + +return regmap_clear_bits (data->regmap,VEML6031X00_REG_CONF1 , +VEML6031X00_CONF1_IR_SD ); +} + +/* +* Two shutdown bits (SD and ALS_IR_SD) must be set to power off +* the device. +*/ +static int veml6031x00_als_shutdown (struct veml6031x00_data *data) +{ +int ret; + + ret =regmap_set_bits (data->regmap,VEML6031X00_REG_CONF0 , +VEML6031X00_CONF0_SD ); +if (ret)
drivers/iio/light/veml6031x00.c line 167
Quoted 10 lines
drivers/iio/light/veml6031x00.c new file +10
-0+return ret; + +return regmap_set_bits (data->regmap,VEML6031X00_REG_CONF1 , +VEML6031X00_CONF1_IR_SD ); +} + +static void veml6031x00_als_shutdown_action (void *data) +{ +veml6031x00_als_shutdown (data); +}
I wonder if the register values are maintained when the device is powered down? If not, then the regmap cache should be invalidated.
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~