iio:light: add driver for veml6046x00 RGBIR color sensor
Andreas Klinger
maintainerv7 cover iio:light: add driver for veml6046x00 RGBIR color sensor
This patchset adds an IIO driver for Vishay veml6046x00 RGBIR color sensor.
Changes in v7:
- Thanks to the reviews of Jonathan and Andy improvements in the PM could be implemented like removal of pm_runtime_mark_last_busy() and consistency in PM handling in some functions.
Changes in v6:
- Thanks to the in-depth review of Andy many datatype improvements were realized.
- According to Jonathans review change the channel types from IIO_LIGHT to IIO_INTENSITY.
Changes in v5:
- Thanks to the feedback of Andy and further explanations of Jonathan many improvements could be implemented.
- add documentation in kernel-doc format
- iio_push_to_buffers_with_ts() is not used as also testing against linux-stable where it is not available so far.
Changes in v4:
- implement feedback from Andy and Jonathan
- implement feedback from vendor (reading interrupt register as bulk read)
Changes in v3:
- implement a lot of feedback from Jonathan
- change scale value to real factor of lux per raw count instead of hardware gain
- optimize code by using more lookup tables
- remove unimplemented threshold functionality
Changes in v2:
- fix missing include for example in vishay,veml6046x00.yaml
Andreas Klinger (3):
dt-bindings: iio: light: veml6046x00: add color sensor
iio: light: add support for veml6046x00 RGBIR color sensor
MAINTAINER: add maintainer for veml6046x00
.../iio/light/vishay,veml6046x00.yaml | 51 + MAINTAINERS | 6 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6046x00.c | 1031 +++++++++++++++++ 5 files changed, 1102 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml create mode 100644 drivers/iio/light/veml6046x00.c
Signature · 1 line
2.39.5
Andreas Klinger
maintainerPATCH v7 1/3 dt-bindings: iio: light: veml6046x00: add color sensor
Add a new compatible for Vishay high accuracy RGBIR color sensor veml6046x00.
--- .../iio/light/vishay,veml6046x00.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml
Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/vishay,veml6046x00.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Vishay VEML6046X00 High accuracy RGBIR color sensor + +maintainers: + - Andreas Klinger <[email protected]> + +description: + VEML6046X00 datasheet at https://www.vishay.com/docs/80173/veml6046x00.pdf + +properties: + compatible: + enum: + - vishay,veml6046x00 + + reg: + maxItems: 1 + + vdd-supply: true + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + color-sensor@29 { + compatible = "vishay,veml6046x00"; + reg = <0x29>; + vdd-supply = <&vdd_reg>; + interrupt-parent = <&gpio2>; + interrupts = <3 IRQ_TYPE_EDGE_FALLING>; + }; + }; +...
Signature · 1 line
2.39.5
Andreas Klinger
maintainerPATCH v7 2/3 iio: light: add support for veml6046x00 RGBIR color sensor
In reply to Andreas KlingerAdd Vishay VEML6046X00 high accuracy RGBIR color sensor.
This sensor provides three colour (red, green and blue) as well as one infrared (IR) channel through I2C.
Support direct and buffered mode.
An optional interrupt for signaling green colour threshold underflow or overflow is not supported so far.
--- drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6046x00.c | 1031 +++++++++++++++++++++++++++++++ 3 files changed, 1045 insertions(+) create mode 100644 drivers/iio/light/veml6046x00.c
drivers/iio/light/Kconfig +13 -0
@@ -724,6 +724,19 @@ config VEML6040 To compile this driver as a module, choose M here: the module will be called veml6040. +config VEML6046X00 + tristate "VEML6046X00 RGBIR color sensor" + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + depends on I2C + help + Say Y here if you want to build a driver for the Vishay VEML6046X00 + high accuracy RGBIR color sensor. + + To compile this driver as a module, choose M here: the + module will be called veml6046x00. + config VEML6070 tristate "VEML6070 UV A light sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_VCNL4035) += vcnl4035.o obj-$(CONFIG_VEML3235) += veml3235.o obj-$(CONFIG_VEML6030) += veml6030.o obj-$(CONFIG_VEML6040) += veml6040.o +obj-$(CONFIG_VEML6046X00) += veml6046x00.o obj-$(CONFIG_VEML6070) += veml6070.o obj-$(CONFIG_VEML6075) += veml6075.o obj-$(CONFIG_VL6180) += vl6180.o
drivers/iio/light/veml6046x00.c new file +1031 -0
1,031 lines not on this page · raw message
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerRe: [PATCH v7 2/3] iio: light: add support for veml6046x00 RGBIR color sensor
Quoted 11 lines · On Mon, 28 Jul 2025 09:54:45 +0200 Andreas Klinger <[email protected]> wrote:
Add Vishay VEML6046X00 high accuracy RGBIR color sensor.
This sensor provides three colour (red, green and blue) as well as one infrared (IR) channel through I2C.
Support direct and buffered mode.
An optional interrupt for signaling green colour threshold underflow or overflow is not supported so far.
Signed-off-by Andreas Klinger <[email protected]>
Hi Andreas
A few things inline, but they are all the sort of thing I'll just tweak whilst applying, if nothing else comes up. Saves time for both of us!
Given Andy has been active in reviewing earlier versions I'll leave this for a little while. If Andy is otherwise happy (or busy!) then I'll pick this up and tweak some or maybe all of the things commented on
Thanks,
Jonathan
Quoted 22 lines
drivers/iio/light/Makefile +1
-0@@ -67,6 +67,7 @@ obj-$(CONFIG_VCNL4035) += vcnl4035.o obj-$(CONFIG_VEML3235) += veml3235.o obj-$(CONFIG_VEML6030) += veml6030.o obj-$(CONFIG_VEML6040) += veml6040.o +obj-$(CONFIG_VEML6046X00) += veml6046x00.o obj-$(CONFIG_VEML6070) += veml6070.o obj-$(CONFIG_VEML6075) += veml6075.o obj-$(CONFIG_VL6180) += vl6180.odrivers/iio/light/veml6046x00.c new file +4
-0+static int veml6046x00_get_val_gain_idx (struct veml6046x00_data *data,int val, +int val2) +{ +unsigned int i;
drivers/iio/light/veml6046x00.c line 512
Quoted 10 lines
drivers/iio/light/veml6046x00.c new file +10
-0+int it_idx; + + it_idx =veml6046x00_get_it_index (data); +if (it_idx <0 ) +return it_idx; + +for (i =0 ; i <ARRAY_SIZE (veml6046x00_it_gains[it_idx]); i++) { +if ((veml6046x00_it_gains[it_idx][i][0 ] == val) && + (veml6046x00_it_gains[it_idx][i][1 ] == val2)) { +return i;
As below.
Quoted 12 lines
drivers/iio/light/veml6046x00.c new file +12
-0+ } + } + +return -EINVAL ; +} + +static int veml6046x00_get_gain_idx (struct veml6046x00_data *data) +{ +int ret; +unsigned int i, reg, reg_gain, reg_pd; + + ret =regmap_read (data->regmap,VEML6046X00_REG_CONF1 , ®);
drivers/iio/light/veml6046x00.c line 534
Quoted 10 lines
drivers/iio/light/veml6046x00.c new file +10
-0+if (ret) +return ret; + + reg_gain =FIELD_GET (VEML6046X00_CONF1_GAIN , reg); + reg_pd = reg &VEML6046X00_CONF1_PD_D2 ; + +for (i =0 ; i <ARRAY_SIZE (veml6046x00_gain_pd); i++) { +if ((veml6046x00_gain_pd[i].gain_sen == reg_gain) && + (veml6046x00_gain_pd[i].pd == reg_pd)) { +return i;
Technically style is no {} for this as only a single statement. I can see why you did this given the more complex condition, but I think the difference in indent is still enough to not need it.
Quoted 13 lines
drivers/iio/light/veml6046x00.c new file +12
-0+ } + } + +return -EINVAL ; +} +static irqreturn_t veml6046x00_trig_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *iio = pf->indio_dev; +struct veml6046x00_data *data =iio_priv (iio); +int ret; +struct {
drivers/iio/light/veml6046x00.c line 851
Quoted 10 lines
drivers/iio/light/veml6046x00.c new file +10
-0+__le16 chans[4 ]; +aligned_s64 timestamp; + } scan; + + ret =regmap_bulk_read (data->regmap,VEML6046X00_REG_R , + &scan.chans,sizeof (scan.chans)); +if (ret) + goto done; + +iio_push_to_buffers_with_timestamp (iio, &scan,iio_get_time_ns (iio));
If we spin again, preference for
iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), iio_get_time_ns(iio));
If not I might tweak whilst applying or might just leave this to get swept up in a future series moving to that safer interface.
Jonathan
Andreas Klinger
maintainerPATCH v7 3/3 MAINTAINER: add maintainer for veml6046x00
In reply to Andreas KlingerAdd maintainer for Vishay veml6046x00 RGBIR color sensor driver and dt binding.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -26424,6 +26424,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml F: drivers/iio/light/veml6030.c +VISHAY VEML6046X00 RGBIR COLOR SENSOR DRIVER +M: Andreas Klinger <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml +F: drivers/iio/light/veml6046x00.c + VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER M: Javier Carrasco <[email protected]> S: Maintained
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerQuoted 1 line · On Mon, 28 Jul 2025 09:54:43 +0200 Andreas Klinger <[email protected]> wrote:
This patchset adds an IIO driver for Vishay veml6046x00 RGBIR color sensor.
Tweaks as per comments on patch 2 and applied to the testing branch of iio.git.
I'll rebase on rc1 in the next few days and then push this out as a tree linux-next picks up.
Thanks,
Jonathan
Quoted 47 lines
Changes in v7:
- Thanks to the reviews of Jonathan and Andy improvements in the PM could be implemented like removal ofpm_runtime_mark_last_busy()and consistency in PM handling in some functions.Changes in v6:
- Thanks to the in-depth review of Andy many datatype improvements were realized.
- According to Jonathans review change the channel types fromIIO_LIGHTtoIIO_INTENSITY.Changes in v5:
- Thanks to the feedback of Andy and further explanations of Jonathan many improvements could be implemented.
- add documentation in kernel-doc format
-iio_push_to_buffers_with_ts()is not used as also testing against linux-stable where it is not available so far.Changes in v4:
- implement feedback from Andy and Jonathan
- implement feedback from vendor (reading interrupt register as bulk read)Changes in v3:
- implement a lot of feedback from Jonathan
- change scale value to real factor of lux per raw count instead of hardware gain
- optimize code by using more lookup tables
- remove unimplemented threshold functionalityChanges in v2:
- fix missing include for example in vishay,veml6046x00.yamlAndreas Klinger (3):
dt-bindings: iio: light: veml6046x00: add color sensor
iio: light: add support for veml6046x00 RGBIR color sensor
MAINTAINER: add maintainer for veml6046x00.../iio/light/vishay,veml6046x00.yaml | 51 + MAINTAINERS | 6 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/veml6046x00.c | 1031 +++++++++++++++++ 5 files changed, 1102 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml create mode 100644 drivers/iio/light/veml6046x00.c