iio: light: veml3328: add support for new sensor
Subsystems (5)
Joshua Crofts
maintainerv4 cover iio: light: veml3328: add support for new sensor
This patch series adds support for the Vishay VEML3328 RGBCIR light sensor. The sensor communicates via I2C (SMBus compatible) and provides 5 types of 16-bit measurements: red, green, blue, clear and infrared.
Reasons for adding a new driver:
- Existing Vishay drivers in the kernel do not cover sensors that handle RGBC and IR simultaneously.
- The register map and configuration differ from other Vishay light sensors currently supported by IIO.
Testing:
- Tested on a Raspberry Pi 4 using a VEML3328 breakout board.
Datasheet:
https://www.vishay.com/docs/84968/veml3328.pdf
---
Changes in v4:
- Fix PM_RUNTIME_ACQUIRE_AUTOSUSPEND() macro cleanup scope
- Add mutex to prevent race in veml3328_write_raw()
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Add additional IIO_LIGHT channel for ambient light sensing
- Remove separate dt binding file and added veml3328 entry to veml6030 yaml
- Move driver to PM_RUNTIME_ACQUIRE_AUTOSUSPEND() macro
- Add missing headers
- Remov redundant mutex as regmap handles it itself
- Use regmap_set/clear_bits() instead of regmap_update_bits()
- Removed redundant dev pointer
- Edit commit messages
- Various code style cleanups
- Link to v1: https://patch.msgid.link/[email protected]
Changes in v3:
- Add 2D array of precomputed scale values based on integration time
- Fix chan_spec masks
- Simplify read/write/avail callbacks
---
Joshua Crofts (2):
dt-bindings: iio: light: veml6030: add veml3328
iio: light: veml3328: add support for new device
.../bindings/iio/light/vishay,veml6030.yaml | 5 +- MAINTAINERS | 5 + drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml3328.c | 422 +++++++++++++++++++++ 5 files changed, 443 insertions(+), 1 deletion(-)
---
base-commit: 7b84b1e9dd850a5c9b55e27daa4ecdc2dd5b3431
change-id: 20260530-veml3328-d2ccb26d02c7
Best regards,
Signature · 1 line
Joshua Crofts <[email protected]>
Joshua Crofts
maintainerPATCH v4 1/2 dt-bindings: iio: light: veml6030: add veml3328
The Vishay VEML3328 is an RGBCIR light sensor that shares similar devicetree properties as other existing VEMLxxxx sensors in the kernel.
--- Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml +4 -1
@@ -4,7 +4,7 @@ $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, VEML3328, VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS) maintainers: - Rishi Gupta <[email protected]>
@@ -21,6 +21,7 @@ description: | Specifications about the sensors can be found at: https://www.vishay.com/docs/80131/veml3235.pdf + https://www.vishay.com/docs/84968/veml3328.pdf https://www.vishay.com/docs/84366/veml6030.pdf https://www.vishay.com/docs/84889/veml6035.pdf https://www.vishay.com/docs/84286/veml7700.pdf
@@ -29,6 +30,7 @@ properties: compatible: enum: - vishay,veml3235 + - vishay,veml3328 - vishay,veml6030 - vishay,veml6035 - vishay,veml7700
@@ -79,6 +81,7 @@ allOf: compatible: enum: - vishay,veml3235 + - vishay,veml3328 - vishay,veml7700 then: properties:
Signature · 1 line
2.54.0
Joshua Crofts
maintainerPATCH v4 2/2 iio: light: veml3328: add support for new device
In reply to Joshua CroftsAdd support for the Vishay VEML3328 RGB/IR light sensor communicating via I2C (SMBus compatible).
Also add a new entry for said driver into Kconfig and Makefile.
--- MAINTAINERS | 5 + drivers/iio/light/Kconfig | 11 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/veml3328.c | 422 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 439 insertions(+)
MAINTAINERS +5 -0
@@ -28402,6 +28402,11 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml F: drivers/iio/light/veml3235.c +VISHAY VEML3328 RGB IR LIGHT SENSOR DRIVER +M: Joshua Crofts <[email protected]> +S: Maintained +F: drivers/iio/light/veml3328.c + VISHAY VEML6030 AMBIENT LIGHT SENSOR DRIVER M: Javier Carrasco <[email protected]> S: Maintained
drivers/iio/light/Kconfig +11 -0
@@ -713,6 +713,17 @@ config VEML3235 To compile this driver as a module, choose M here: the module will be called veml3235. +config VEML3328 + tristate "VEML3328 RGBCIR light sensor" + select REGMAP_I2C + depends on I2C + help + Say Y here if you want to build a driver for the Vishay VEML3328 + RGB IR light sensor. + + To compile this driver as a module, choose M here: the + module will be called veml3328 + config VEML6030 tristate "VEML6030 and VEML6035 ambient light sensors" select REGMAP_I2C
drivers/iio/light/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o obj-$(CONFIG_VCNL4035) += vcnl4035.o obj-$(CONFIG_VEML3235) += veml3235.o +obj-$(CONFIG_VEML3328) += veml3328.o obj-$(CONFIG_VEML6030) += veml6030.o obj-$(CONFIG_VEML6040) += veml6040.o obj-$(CONFIG_VEML6046X00) += veml6046x00.o
drivers/iio/light/veml3328.c new file +422 -0
422 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v4 2/2] iio: light: veml3328: add support for new device
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The runtime PM autosuspend timer is not started during probe, preventing the device from…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The runtime PM autosuspend timer is not started during probe, preventing the device from entering a low-power state until its first userspace access.
- [Medium] SCALE attributes are incorrectly exported as shared_by_type instead of shared_by_all for a global hardware setting.
--
commit 3c7cc50c08671c37a310d6d5f49f51c1dd186420
Author: Joshua Crofts <[email protected]>
iio: light: veml3328: add support for new device
Add support for the Vishay VEML3328 RGB/IR light sensor communicating via I2C (SMBus compatible). Also add a new entry for said driver into Kconfig and Makefile.
Quoted 5 lines
drivers/iio/light/veml3328.c new file +0
-0
[ ... ]
Quoted 9 lines
drivers/iio/light/veml3328.c new file +9
-0+#define VEML3328_CHAN_SPEC (_color, _addr) { \ + .type = IIO_INTENSITY, \ + .modified = 1, \ + .channel2 = IIO_MOD_LIGHT_##_color, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \ + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), \
drivers/iio/light/veml3328.c line 76
Quoted 10 lines
drivers/iio/light/veml3328.c new file +10
-0+ .address = _addr, \ +} + +static const struct iio_chan_spec veml3328_channels[] = { + { + .type =IIO_LIGHT , + + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ), + .info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ), + .info_mask_shared_by_type_available =BIT (IIO_CHAN_INFO_SCALE ),
[Severity: Medium]
Will this export two separate sysfs scale attributes that secretly control the same global hardware register?
Since the sensor gain is controlled globally in VEML3328_REG_CONF, and the driver registers both IIO_LIGHT and IIO_INTENSITY channels, using info_mask_shared_by_type will create separate in_light_scale and in_intensity_scale attributes. Modifying one will alter the hardware gain for the other, which might break userspace expectations.
Should this use info_mask_shared_by_all instead, similar to how INT_TIME is configured?
Quoted 4 lines
drivers/iio/light/veml3328.c new file +4
-0+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), + .address = VEML3328_REG_DATA_G, + },
[ ... ]
Quoted 6 lines
drivers/iio/light/veml3328.c new file +6
-0+ indio_dev->name ="veml3328" ; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &veml3328_info; + indio_dev->channels = veml3328_channels; + indio_dev->num_channels =ARRAY_SIZE (veml3328_channels); +
drivers/iio/light/veml3328.c line 366
Quoted 10 lines
drivers/iio/light/veml3328.c new file +10
-0+pm_runtime_set_active (dev); +pm_runtime_set_autosuspend_delay (dev,2000 ); +pm_runtime_use_autosuspend (dev); + + ret =devm_pm_runtime_enable (dev); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable runtime PM\n" ); + +return devm_iio_device_register (dev, indio_dev); +}
[Severity: Medium]
Will the device fail to enter autosuspend after probe?
The driver powers up the sensor earlier in veml3328_probe() and sets the PM state to RPM_ACTIVE here, but it never increments the PM usage count or queues an idle check. As a result, the PM core won't start the autosuspend timer when pm_runtime_enable() is called.
Could this leave the sensor fully powered indefinitely until a userspace read finally acquires and releases a PM reference? Should there be a call to pm_runtime_mark_last_busy() and pm_runtime_put_autosuspend() at the end of probe, paired with an earlier pm_runtime_get_noresume()?
Quoted 2 lines
drivers/iio/light/veml3328.c new file +2
-0+ +static int veml3328_runtime_suspend (struct device *dev)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Javier Carrasco
maintainerRe: [PATCH v4 2/2] iio: light: veml3328: add support for new device
In reply to Joshua CroftsHi Joshua,
Just a nitpick I caught on the fly because it was missing in a driver I recently sent as well.
Quoted 23 lines · Joshua Crofts
Add support for the Vishay VEML3328 RGB/IR light sensor communicating via I2C (SMBus compatible).
Also add a new entry for said driver into
KconfigandMakefile.Assisted-by Gemini:3.1-ProSigned-off-by Joshua Crofts <[email protected]>--- MAINTAINERS | 5 + drivers/iio/light/Kconfig | 11 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/veml3328.c | 422 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 439 insertions(+)+++
b/drivers/iio/light/veml3328.cdrivers/iio/light/veml3328.c new file +7
-0@@ -0,0 +1,422 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Vishay VEML3328 RGBCIR light sensor driver +* +* Copyright (c) 2026 Joshua Crofts <[email protected]> +* +* Datasheet: https://www.vishay.com/docs/84968/veml3328.pdf
drivers/iio/light/veml3328.c line 17
Quoted 10 lines
drivers/iio/light/veml3328.c new file +10
-0+*/ + +#include <linux/array_size.h> +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/module.h>
At least linux/mod_devicetable.h is missing to include of_device_id. Probably that's the only missing header, and it could be added without sending a new version, but that is not for me to decide :)
drivers/iio/light/veml3328.c line 26
Quoted 9 lines
drivers/iio/light/veml3328.c new file +9
-0+#include <linux/mutex.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/time.h> +#include <linux/types.h> + +#include <linux/iio/iio.h> +
Best regards,
Javier
Joshua Crofts
maintainerRe: [PATCH v4 2/2] iio: light: veml3328: add support for new device
Quoted 9 lines · Javier Carrasco
Hi Joshua,
Just a nitpick I caught on the fly because it was missing in a driver I recently sent as well.
At least
linux/mod_devicetable.his missing to includeof_device_id. Probably that's the only missing header, and it could be added without sending a new version, but that is not for me to decide :)
Hi Javier,
Good catch, I completely forgot about mod_devicetable!
Thanks!
Signature · 3 lines
Kind regards CJD
Jonathan Cameron
maintainerRe: [PATCH v4 2/2] iio: light: veml3328: add support for new device
Quoted 8 lines · On Mon, 1 Jun 2026 08:56:17 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Javier Carrasco
Hi Joshua,
Just a nitpick I caught on the fly because it was missing in a driver I recently sent as well.
Quoted 7 lines
Quoted 3 lines
At least
linux/mod_devicetable.his missing to includeof_device_id. Probably that's the only missing header, and it could be added without sending a new version, but that is not for me to decide :)Hi Javier,
Good catch, I completely forgot about
mod_devicetable!
Tweaked.
Applied to the testing branch of iio.git.
Thanks,
Jonathan
Quoted 3 lines
Thanks!