Skip to contentSkip to conversation

iio: light: add support for veml3235

PATCH In review Javier Carrasco 3 participants 7 messages Oct 23, 2024 – Oct 27, 2024

Subsystems (4)
lore
Share & tools
lore

Javier Carrasco

author maintainer
#0 lore raw

v3 cover iio: light: add support for veml3235

This series adds support for the Vishay veml3235 ambient light sensor with I2C protocol interface.

I attempted to add support for this device in the existing veml6030 driver, as it shares some operating principles with the supported devices. But given that the veml3235 has different register addresses, bit arrangements, and limited functionality, it ended up making most of the driver kind of device-agnostic.

Instead, the proposed driver is based on the recently updated veml6030 with multiple simplifications and a few clean ups (e.g. regfields, right definition of shared-by-all info masks, which can't be modified in veml6030 as it breaks the ABI).

On the other hand, the dt-bindings can be recycled as there is no real reason to add new ones. From a dt-bindings point of view it resembles the already supported veml7700. But if for whatever reason new bindings would be preferred, I am willing to provide them in further versions.

---
Changes in v3:
- Add missing Tag to [1/2] (Acked-by).
- Drop processed values from the driver, which in turn removes the need to store the current resolution, gain and integration time in the driver data.
- Fix SD0 bit position (15).
- Drop redundant configuration write in hw_init (gain and integration times are the only fields to set).
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Rename SD/SD0 bits to include register name.
- Switch to dev_info() when checking ID.
- Simplify val/val2 handling in veml3235_set_gain().
- Move return -EINVAL to the default case in veml3235_read_avail().
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Javier Carrasco (2):
dt-bindings: iio: light: veml6030: add veml3235
iio: light: add support for veml3235

 .../bindings/iio/light/vishay,veml6030.yaml        |   5 +-
 MAINTAINERS                                        |   6 +
 drivers/iio/light/Kconfig                          |  11 +
 drivers/iio/light/Makefile                         |   1 +
 drivers/iio/light/veml3235.c                       | 504 +++++++++++++++++++++
 5 files changed, 526 insertions(+), 1 deletion(-)

---
base-commit: ceab669fdf7b7510b4e4997b33d6f66e433a96db
change-id: 20241007-veml3235-0a38265e9bae

Best regards,

Signature · 1 line
Javier Carrasco <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: light: veml6030: add veml3235

The veml3235 is another Vishay ambient light sensor that shares similar properties with the other sensors covered by this bindings. In this case, only the compatible, reg, and vdd-supply properties are required, and the device does not have an interrupt line, like the already supported veml7700.

---
 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
index 53b55575efd3..4ea69f1fdd63 100644
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/iio/light/vishay,veml6030.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS)
+title: VEML3235, VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS)
 
 maintainers:
   - Rishi Gupta <[email protected]>
@@ -20,6 +20,7 @@ description: |
   whenever configured threshold is crossed.
 
   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/84889/veml6035.pdf
     https://www.vishay.com/docs/84286/veml7700.pdf
@@ -27,6 +28,7 @@ description: |
 properties:
   compatible:
     enum:
+      - vishay,veml3235
       - vishay,veml6030
       - vishay,veml6035
       - vishay,veml7700
@@ -76,6 +78,7 @@ allOf:
       properties:
         compatible:
           enum:
+            - vishay,veml3235
             - vishay,veml7700
     then:
       properties:
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v3 2/2 iio: light: add support for veml3235

In reply to Javier Carrasco

The Vishay veml3235 is a low-power ambient light sensor with I2C interface. It provides a minimum detectable intensity of 0.0021 lx/cnt, configurable integration time and gain, and an additional white channel to distinguish between different light sources.

---
 MAINTAINERS                  |   6 +
 drivers/iio/light/Kconfig    |  11 +
 drivers/iio/light/Makefile   |   1 +
 drivers/iio/light/veml3235.c | 504 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 522 insertions(+)
MAINTAINERS +6 -0
index 5c977ffd2bdd..228d81ae6dc2 100644
@@ -24679,6 +24679,12 @@ S:	Maintained
 F:	drivers/input/serio/userio.c
 F:	include/uapi/linux/userio.h
 
+VISHAY VEML3235 AMBIENT LIGHT SENSOR DRIVER
+M:	Javier Carrasco <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
+F:	drivers/iio/light/veml3235.c
+
 VISHAY VEML6030 AMBIENT LIGHT SENSOR DRIVER
 M:	Javier Carrasco <[email protected]>
 S:	Maintained
drivers/iio/light/Kconfig +11 -0
index 39c0e08a8e06..8fdabe7c8b29 100644
@@ -670,6 +670,17 @@ config VCNL4035
 	  To compile this driver as a module, choose M here: the
 	  module will be called vcnl4035.
 
+config VEML3235
+	tristate "VEML3235 ambient light sensor"
+	select REGMAP_I2C
+	depends on I2C
+	help
+	  Say Y here if you want to build a driver for the Vishay VEML3235
+	  ambient light sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called veml3235.
+
 config VEML6030
 	tristate "VEML6030 and VEML6035 ambient light sensors"
 	select REGMAP_I2C
drivers/iio/light/Makefile +1 -0
index 321010fc0b93..f14a37442712 100644
@@ -62,6 +62,7 @@ obj-$(CONFIG_TSL4531)		+= tsl4531.o
 obj-$(CONFIG_US5182D)		+= us5182d.o
 obj-$(CONFIG_VCNL4000)		+= vcnl4000.o
 obj-$(CONFIG_VCNL4035)		+= vcnl4035.o
+obj-$(CONFIG_VEML3235)		+= veml3235.o
 obj-$(CONFIG_VEML6030)		+= veml6030.o
 obj-$(CONFIG_VEML6040)		+= veml6040.o
 obj-$(CONFIG_VEML6070)		+= veml6070.o
drivers/iio/light/veml3235.c new file +504 -0

504 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw
kernel test robot noticed the following build warnings:

Hi Javier,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ceab669fdf7b7510b4e4997b33d6f66e433a96db]

url:    https://github.com/intel-lab-lkp/linux/commits/Javier-Carrasco/dt-bindings-iio-light-veml6030-add-veml3235/20241024-030144
base:   ceab669fdf7b7510b4e4997b33d6f66e433a96db
patch link:    https://lore.kernel.org/r/20241023-veml3235-v3-2-8490f2622f9a%40gmail.com
patch subject: [PATCH v3 2/2] iio: light: add support for veml3235
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20241025/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241025/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/iio/light/veml3235.c: In function 'veml3235_set_it':

>> drivers/iio/light/veml3235.c:148:26: warning: variable 'it_idx' set but not used [-Wunused-but-set-variable]
     148 |         int ret, new_it, it_idx;
         |                          ^~~~~~
   drivers/iio/light/veml3235.c: In function 'veml3235_set_gain':
>> drivers/iio/light/veml3235.c:191:28: warning: variable 'gain_idx' set but not used [-Wunused-but-set-variable]
     191 |         int ret, new_gain, gain_idx;
         |                            ^~~~~~~~

vim +/it_idx +148 drivers/iio/light/veml3235.c

144
145 static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
146 {
147 struct veml3235_data *data = iio_priv(indio_dev);

 > 148		int ret, new_it, it_idx;
   149	
   150		if (val)
   151			return -EINVAL;
   152	
   153		switch (val2) {
   154		case 50000:
   155			new_it = 0x00;
   156			it_idx = 4;
   157			break;
   158		case 100000:
   159			new_it = 0x01;
   160			it_idx = 3;
   161			break;
   162		case 200000:
   163			new_it = 0x02;
   164			it_idx = 2;
   165			break;
   166		case 400000:
   167			new_it = 0x03;
   168			it_idx = 1;
   169			break;
   170		case 800000:
   171			new_it = 0x04;
   172			it_idx = 0;
   173			break;
   174		default:
   175			return -EINVAL;
   176		}
   177	
   178		ret = regmap_field_write(data->rf.it, new_it);
   179		if (ret) {
   180			dev_err(data->dev,
   181				"failed to update integration time: %d\n", ret);
   182			return ret;
   183		}
   184	
   185		return 0;
   186	}
   187	
   188	static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
   189	{
   190		struct veml3235_data *data = iio_priv(indio_dev);
 > 191		int ret, new_gain, gain_idx;

192
193 if (val2 != 0)
194 return -EINVAL;
195
196 switch (val) {
197 case 1:
198 new_gain = 0x00;
199 gain_idx = 3;
200 break;
201 case 2:
202 new_gain = 0x01;
203 gain_idx = 2;
204 break;
205 case 4:
206 new_gain = 0x03;
207 gain_idx = 1;
208 break;
209 case 8:
210 new_gain = 0x07;
211 gain_idx = 0;
212 break;
213 default:
214 return -EINVAL;
215 }
216
217 ret = regmap_field_write(data->rf.gain, new_gain);
218 if (ret) {
219 dev_err(data->dev, "failed to set gain: %d\n", ret);
220 return ret;
221 }
222
223 return 0;
224 }
225

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#4 lore raw
Quoted 107 lines · kernel test robot

Hi Javier,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ceab669fdf7b7510b4e4997b33d6f66e433a96db]

url:    https://github.com/intel-lab-lkp/linux/commits/Javier-Carrasco/dt-bindings-iio-light-veml6030-add-veml3235/20241024-030144
base:   ceab669fdf7b7510b4e4997b33d6f66e433a96db
patch link:    https://lore.kernel.org/r/20241023-veml3235-v3-2-8490f2622f9a%40gmail.com
patch subject: [PATCH v3 2/2] iio: light: add support for veml3235
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20241025/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241025/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

   drivers/iio/light/veml3235.c: In function 'veml3235_set_it':
Quoted 1 line
Quoted 1 line

drivers/iio/light/veml3235.c:148:26: warning: variable 'it_idx' set but not used [-Wunused-but-set-variable]

     148 |         int ret, new_it, it_idx;
         |                          ^~~~~~

drivers/iio/light/veml3235.c: In function 'veml3235_set_gain':

Quoted 1 line
Quoted 1 line

drivers/iio/light/veml3235.c:191:28: warning: variable 'gain_idx' set but not used [-Wunused-but-set-variable]

     191 |         int ret, new_gain, gain_idx;
         |                            ^~~~~~~~

vim +/it_idx +148 drivers/iio/light/veml3235.c

   144	
   145	static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
   146	{
   147		struct veml3235_data *data = iio_priv(indio_dev);
Quoted 1 line

148 int ret, new_it, it_idx;

149
150 if (val)

   151			return -EINVAL;
   152	
   153		switch (val2) {
   154		case 50000:
   155			new_it = 0x00;
   156			it_idx = 4;
   157			break;
   158		case 100000:
   159			new_it = 0x01;
   160			it_idx = 3;
   161			break;
   162		case 200000:
   163			new_it = 0x02;
   164			it_idx = 2;
   165			break;
   166		case 400000:
   167			new_it = 0x03;
   168			it_idx = 1;
   169			break;
   170		case 800000:
   171			new_it = 0x04;
   172			it_idx = 0;
   173			break;
   174		default:
   175			return -EINVAL;
   176		}
   177	
   178		ret = regmap_field_write(data->rf.it, new_it);
   179		if (ret) {
   180			dev_err(data->dev,
   181				"failed to update integration time: %d\n", ret);
   182			return ret;
   183		}
   184	
   185		return 0;
   186	}
   187	
   188	static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
   189	{
   190		struct veml3235_data *data = iio_priv(indio_dev);
Quoted 1 line

191 int ret, new_gain, gain_idx;

192
193 if (val2 != 0)

   194			return -EINVAL;
   195	
   196		switch (val) {
   197		case 1:
   198			new_gain = 0x00;
   199			gain_idx = 3;
   200			break;
   201		case 2:
   202			new_gain = 0x01;
   203			gain_idx = 2;
   204			break;
   205		case 4:
   206			new_gain = 0x03;
   207			gain_idx = 1;
   208			break;
   209		case 8:
   210			new_gain = 0x07;
   211			gain_idx = 0;
   212			break;
   213		default:
   214			return -EINVAL;
   215		}
   216	
   217		ret = regmap_field_write(data->rf.gain, new_gain);
Quoted 9 lines
   218		if (ret) {
   219			dev_err(data->dev, "failed to set gain: %d\n", ret);
   220			return ret;
   221		}
   222	
   223		return 0;
   224	}
   225	

Unused as there is no processed values anymore. I will drop them for v4.

maintainer
#5 lore raw

Hi Javier,

Quoted 8 lines
Quoted 5 lines
   222	
   223		return 0;
   224	}
   225	

Unused as there is no processed values anymore. I will drop them for v4.

Given I didn't have any other comments I just fixed these up whilst applying.

Series applied to the togreg branch of iio.git and initially pushed out as testing for 0-day to take a first look at it.
Thanks,

Jonathan

p.s. Diff was as follows, shout if I mess it up.

drivers/iio/light/veml3235.c +2 -11
index 18ab73f4377c..66361c3012a3 100644
@@ -145,7 +145,7 @@ static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2)
 static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
 {
        struct veml3235_data *data = iio_priv(indio_dev);
-       int ret, new_it, it_idx;
+       int ret, new_it;
 
        if (val)
                return -EINVAL;
@@ -153,23 +153,18 @@ static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
        switch (val2) {
        case 50000:
                new_it = 0x00;
-               it_idx = 4;
                break;
        case 100000:
                new_it = 0x01;
-               it_idx = 3;
                break;
        case 200000:
                new_it = 0x02;
-               it_idx = 2;
                break;
        case 400000:
                new_it = 0x03;
-               it_idx = 1;
                break;
        case 800000:
                new_it = 0x04;
-               it_idx = 0;
                break;
        default:
                return -EINVAL;
@@ -188,7 +183,7 @@ static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
 static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
 {
        struct veml3235_data *data = iio_priv(indio_dev);
-       int ret, new_gain, gain_idx;
+       int ret, new_gain;
 
        if (val2 != 0)
                return -EINVAL;
@@ -196,19 +191,15 @@ static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
        switch (val) {
        case 1:
                new_gain = 0x00;
-               gain_idx = 3;
                break;
        case 2:
                new_gain = 0x01;
-               gain_idx = 2;
                break;
        case 4:
                new_gain = 0x03;
-               gain_idx = 1;
                break;
        case 8:
                new_gain = 0x07;
-               gain_idx = 0;
                break;
        default:
                return -EINVAL;
Quoted 1 line
author maintainer
#6 lore raw
Quoted 88 lines · Jonathan Cameron

Hi Javier,

Quoted 8 lines
Quoted 5 lines
   222	
   223		return 0;
   224	}
   225	

Unused as there is no processed values anymore. I will drop them for v4.

Given I didn't have any other comments I just fixed these up whilst applying.

Series applied to the togreg branch of iio.git and initially pushed out as testing for 0-day to take a first look at it.
Thanks,

Jonathan

p.s. Diff was as follows, shout if I mess it up.

drivers/iio/light/veml3235.c +2 -11
index 18ab73f4377c..66361c3012a3 100644
@@ -145,7 +145,7 @@ static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2)
 static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
 {
        struct veml3235_data *data = iio_priv(indio_dev);
-       int ret, new_it, it_idx;
+       int ret, new_it;
 
        if (val)
                return -EINVAL;
@@ -153,23 +153,18 @@ static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
        switch (val2) {
        case 50000:
                new_it = 0x00;
-               it_idx = 4;
                break;
        case 100000:
                new_it = 0x01;
-               it_idx = 3;
                break;
        case 200000:
                new_it = 0x02;
-               it_idx = 2;
                break;
        case 400000:
                new_it = 0x03;
-               it_idx = 1;
                break;
        case 800000:
                new_it = 0x04;
-               it_idx = 0;
                break;
        default:
                return -EINVAL;
@@ -188,7 +183,7 @@ static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2)
 static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
 {
        struct veml3235_data *data = iio_priv(indio_dev);
-       int ret, new_gain, gain_idx;
+       int ret, new_gain;
 
        if (val2 != 0)
                return -EINVAL;
@@ -196,19 +191,15 @@ static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2)
        switch (val) {
        case 1:
                new_gain = 0x00;
-               gain_idx = 3;
                break;
        case 2:
                new_gain = 0x01;
-               gain_idx = 2;
                break;
        case 4:
                new_gain = 0x03;
-               gain_idx = 1;
                break;
        case 8:
                new_gain = 0x07;
-               gain_idx = 0;
                break;
        default:
                return -EINVAL;
Quoted 2 lines
Quoted 1 line

Hi Jonathan, that is exactly the diff I wanted to add for v4. Thanks for fixing it.

Best regards,
Javier Carrasco