iio: light: vcnl4000: add regulator support
Subsystems (2)
v3 cover iio: light: vcnl4000: add regulator support
This patch series introduces support for voltage supply, I2C and cathode regulators. This fixes an issue where if a regulator is shared between the proximity sensor and some other device, and the other device is powered off, the proximity sensor would be powered off as well.
One of the commits includes a Reported-by: tag without a Closes: tag - the report was done outside of LKML.
---
Changes in v3:
- Added a more detailed description for supplies in the dt-bindings commit.
- Separated sorting includes into a commit of its own.
- Replaced all occurrences of mutex_init with its device-managed
counterpart.
- Moved client->dev variable declaration into a commit for adding
regulators.
- Removed redundant dev_err messages in probe function.
- Replaced all direct usages of client->dev and data->client into usages
by variable.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Removed double quotes in includes.
- Reordered includes alphabetically.
- Enabled regulators before the mutex is initialized.
- Replaced direct usage of &client->dev with a variable.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Erikas Bitovtas (6):
dt-bindings: iio: light: vcnl4000: add regulators
iio: light: vcnl4000: sort includes by their name
iio: light: vcnl4000: replace mutex_init with devm_mutex_init
iio: light: vcnl4000: add support for regulators
iio: light: vcnl4000: remove error messages for trigger and irq
iio: light: vcnl4000: use variables for I2C client and device instances
.../bindings/iio/light/vishay,vcnl4000.yaml | 7 ++ drivers/iio/light/vcnl4000.c | 76 +++++++++++++--------- 2 files changed, 52 insertions(+), 31 deletions(-)
---
base-commit: 6e03baeeb160e6cfd72f2c39f26c50bcd925c7a0
change-id: 20260310-vcnl4000-regulators-bcf1b8a01ce6
Best regards,
Signature · 1 line
Erikas Bitovtas <[email protected]>
PATCH v3 1/6 dt-bindings: iio: light: vcnl4000: add regulators
This commit adds supply properties for the sensor, I2C bus and IR LED anode supplies [1], which can be found in vcnl4000 ambient light and proximity sensors, to ensure the sensor is powered on before proceeding with setup.
[1] https://www.vishay.com/docs/84274/vcnl4040.pdf
--- Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +7 -0
@@ -33,6 +33,10 @@ properties: interrupts: maxItems: 1 + vdd-supply: true + vddio-supply: true + vled-supply: true + reg: maxItems: 1
@@ -54,6 +58,9 @@ examples: compatible = "vishay,vcnl4200"; reg = <0x51>; proximity-near-level = <220>; + vdd-supply = <®_vdd>; + vddio-supply = <®_vddio>; + vled-supply = <®_vled>; }; }; ...
Signature · 1 line
2.53.0
Re: [PATCH v3 1/6] dt-bindings: iio: light: vcnl4000: add regulators
Quoted 1 line · Erikas Bitovtas
This commit adds supply properties for the sensor, I2C bus and IR LED
Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94
Quoted 1 line
anode supplies [1], which can be found in vcnl4000 ambient light and
So other devices do not have these supplies? Or have only some?
You already received that question, so I assume you checked. Then check again because 4040 has VDD.
thus in
that case
Quoted 15 lines
proximity sensors, to ensure the sensor is powered on before proceeding with setup.
[1] https://www.vishay.com/docs/84274/vcnl4040.pdf
Signed-off-by Erikas Bitovtas <[email protected]>--- Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0
-0
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 37
Quoted 5 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +2
-0@@ -33,6 +33,10 @@ properties: interrupts: maxItems: 1 + vdd-supply: true + vddio-supply: true
VCNL4000 does not have VDDIO and VLED pins.
Best regards,
Krzysztof
Re: [PATCH v3 1/6] dt-bindings: iio: light: vcnl4000: add regulators
Quoted 7 lines · Krzysztof Kozlowski
Quoted 1 line · Erikas Bitovtas
This commit adds supply properties for the sensor, I2C bus and IR LED
Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94
Quoted 7 lines
Quoted 1 line
anode supplies [1], which can be found in vcnl4000 ambient light and
So other devices do not have these supplies? Or have only some?
You already received that question, so I assume you checked. Then check again because 4040 has VDD.
VLED is supposed to be the IR anode pin. Every model has one. It is pin 1 on vcnl4000, vcnl4010 and vcnl4020, pin 6 on vcnl4200 and pin 4 on vcnl4040.
VDD pin is pin 7 on vcnl4000 and vcnl4010, pin 5 on vcnl4020 and pin 3 on vcnl4040 and vcnl4200.
VDDIO is an external supply to the I2C bus for the sensor.
Quoted 29 lines
thus in
that caseQuoted 15 lines
proximity sensors, to ensure the sensor is powered on before proceeding with setup.
[1] https://www.vishay.com/docs/84274/vcnl4040.pdf
Signed-off-by Erikas Bitovtas <[email protected]>--- Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0
-0Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 37
Quoted 5 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +2
-0@@ -33,6 +33,10 @@ properties: interrupts: maxItems: 1 + vdd-supply: true + vddio-supply: trueVCNL4000 does not have VDDIO and VLED pins.
Best regards,
Krzysztof
PATCH v3 2/6 iio: light: vcnl4000: sort includes by their name
In reply to Erikas BitovtasSort include headers by file name for better readability.
--- drivers/iio/light/vcnl4000.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/light/vcnl4000.c +4 -4
@@ -18,12 +18,12 @@*/ #include <linux/bitfield.h> -#include <linux/module.h> -#include <linux/i2c.h> -#include <linux/err.h> #include <linux/delay.h> -#include <linux/pm_runtime.h> +#include <linux/err.h> +#include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> #include <linux/units.h> #include <linux/iio/buffer.h>
Signature · 1 line
2.53.0
PATCH v3 3/6 iio: light: vcnl4000: replace mutex_init with devm_mutex_init
In reply to Erikas BitovtasReplace mutex_init used across driver with its device-managed counterpart, so all assigned mutexes get destroyed.
--- drivers/iio/light/vcnl4000.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/iio/light/vcnl4000.c +14 -3
@@ -356,6 +356,8 @@ static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on)static int vcnl4200_init (struct vcnl4000_data *data) { +struct i2c_client *client = data->client; +struct device *dev = &client->dev;int ret, id;u16 regval;
@@ -400,8 +402,14 @@ static int vcnl4200_init(struct vcnl4000_data *data) } data->al_scale = data->chip_spec->ulux_step; data->ps_scale =16 ; -mutex_init (&data->vcnl4200_al.lock); -mutex_init (&data->vcnl4200_ps.lock); + + ret =devm_mutex_init (dev, &data->vcnl4200_al.lock); +if (ret <0 ) +return ret; + + ret =devm_mutex_init (dev, &data->vcnl4200_ps.lock); +if (ret <0 ) +return ret;/* Use 16 bits proximity sensor readings */ ret =i2c_smbus_read_word_data (data->client,VCNL4200_PS_CONF1 );
@@ -1985,6 +1993,7 @@ static int vcnl4000_probe(struct i2c_client *client)const struct i2c_device_id *id =i2c_client_get_device_id (client);struct vcnl4000_data *data;struct iio_dev *indio_dev; +struct device *dev = &client->dev;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));
@@ -1997,7 +2006,9 @@ static int vcnl4000_probe(struct i2c_client *client) data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; -mutex_init (&data->vcnl4000_lock); + ret =devm_mutex_init (dev, &data->vcnl4000_lock); +if (ret <0 ) +return ret; ret = data->chip_spec->init (data);if (ret <0 )
Signature · 1 line
2.53.0
David Lechner
reviewerRe: [PATCH v3 3/6] iio: light: vcnl4000: replace mutex_init with devm_mutex_init
Quoted 3 lines · Erikas Bitovtas
Replace
mutex_initused across driver with its device-managed counterpart, so all assigned mutexes get destroyed.
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 1996
Quoted 5 lines
drivers/iio/light/vcnl4000.c +1
-0@@ -1985,6 +1993,7 @@ static int vcnl4000_probe(struct i2c_client *client)const struct i2c_device_id *id =i2c_client_get_device_id (client);struct vcnl4000_data *data;struct iio_dev *indio_dev; +struct device *dev = &client->dev;
Purely cosmetic, but I would have put this two lines up (right after *id) to keep assignments and longer lines together.
No need to v4 though, everything else look good.
Quoted 3 lines
drivers/iio/light/vcnl4000.c +0
-0int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));
Jonathan Cameron
maintainerRe: [PATCH v3 3/6] iio: light: vcnl4000: replace mutex_init with devm_mutex_init
In reply to Erikas BitovtasQuoted 4 lines · On Sat, 14 Mar 2026 18:06:32 +0200 Erikas Bitovtas <[email protected]> wrote:
Replace
mutex_initused across driver with its device-managed counterpart, so all assigned mutexes get destroyed.Signed-off-by Erikas Bitovtas <[email protected]>
Hi Erikas,
One related area that I noticed whilst checking this patch was safe wrt to ordering. I think cleaning that up before this patch would make this one more obviously correct.
Jonathan
Quoted 21 lines
--- drivers/iio/light/vcnl4000.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/iio/light/vcnl4000.c +2
-0@@ -356,6 +356,8 @@ static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on)static int vcnl4200_init (struct vcnl4000_data *data) { +struct i2c_client *client = data->client; +struct device *dev = &client->dev;int ret, id;u16 regval;@@ -400,8 +402,14 @@ static int vcnl4200_init(struct vcnl4000_data *data) } data->al_scale = data->chip_spec->ulux_step; data->ps_scale =16 ;
drivers/iio/light/vcnl4000.c static int vcnl4200_init(struct vcnl4000_data *data) · line 412
Quoted 10 lines
drivers/iio/light/vcnl4000.c +8
-2-mutex_init (&data->vcnl4200_al.lock); -mutex_init (&data->vcnl4200_ps.lock); + + ret =devm_mutex_init (dev, &data->vcnl4200_al.lock); +if (ret <0 ) +return ret; + + ret =devm_mutex_init (dev, &data->vcnl4200_ps.lock); +if (ret <0 ) +return ret;
I think this is ok because the only thing undone in remove is the power state setting that is the last call in this function but the mixture of non devm and devm calls in init is less than helpful for readability. Given both init() callbacks end with
return data->chip_spec->set_power_state(data, true) and the remove just calls that callback without any wrapping up in different init functions I'm thinking it would make it all more readable if we didn't consider turning on the power as part of the _init() but instead called it directly from probe().
That would perhaps give more readable code and avoid mix of devm cleanup and other cleanup in those callbacks.
Quoted 23 lines
drivers/iio/light/vcnl4000.c +4
-1/* Use 16 bits proximity sensor readings */ ret =i2c_smbus_read_word_data (data->client,VCNL4200_PS_CONF1 );@@ -1985,6 +1993,7 @@ static int vcnl4000_probe(struct i2c_client *client)const struct i2c_device_id *id =i2c_client_get_device_id (client);struct vcnl4000_data *data;struct iio_dev *indio_dev; +struct device *dev = &client->dev;int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));@@ -1997,7 +2006,9 @@ static int vcnl4000_probe(struct i2c_client *client) data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; -mutex_init (&data->vcnl4000_lock); + ret =devm_mutex_init (dev, &data->vcnl4000_lock); +if (ret <0 ) +return ret; ret = data->chip_spec->init (data);if (ret <0 )
Re: [PATCH v3 3/6] iio: light: vcnl4000: replace mutex_init with devm_mutex_init
In reply to Erikas BitovtasQuoted 2 lines · Erikas Bitovtas
Replace
mutex_initused across driver with its device-managed counterpart, so all assigned mutexes get destroyed.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ ret = devm_mutex_init(dev, &data->vcnl4200_al.lock); + if (ret < 0)
Do we need ' < 0' parts?
Quoted 5 lines
drivers/iio/light/vcnl4000.c +5
-0+return ret; + + ret =devm_mutex_init (dev, &data->vcnl4200_ps.lock); +if (ret <0 ) +return ret;
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2011
Quoted 3 lines
drivers/iio/light/vcnl4000.c +3
-0+ ret =devm_mutex_init (dev, &data->vcnl4000_lock); +if (ret <0 ) +return ret;
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 4/6 iio: light: vcnl4000: add support for regulators
In reply to Erikas BitovtasAdd supply, I2C and cathode voltage regulators to the sensor and enable them. This keeps the sensor powered on even after its only supply shared by another device shuts down.
--- drivers/iio/light/vcnl4000.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/light/vcnl4000.c +8 -0
@@ -24,6 +24,7 @@#include <linux/interrupt.h> #include <linux/module.h> #include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> #include <linux/units.h> #include <linux/iio/buffer.h>
@@ -1991,6 +1992,7 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)static int vcnl4000_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client); +const char *const regulator_names[] = {"vdd" ,"vddio" ,"vled" };struct vcnl4000_data *data;struct iio_dev *indio_dev;struct device *dev = &client->dev;
@@ -2006,6 +2008,12 @@ static int vcnl4000_probe(struct i2c_client *client) data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; + ret =devm_regulator_bulk_get_enable (dev, +ARRAY_SIZE (regulator_names), + regulator_names); +if (ret <0 ) +return ret; + ret =devm_mutex_init (dev, &data->vcnl4000_lock);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Jonathan Cameron
maintainerRe: [PATCH v3 4/6] iio: light: vcnl4000: add support for regulators
Quoted 6 lines · On Sat, 14 Mar 2026 18:06:33 +0200 Erikas Bitovtas <[email protected]> wrote:
Add supply, I2C and cathode voltage regulators to the sensor and enable them. This keeps the sensor powered on even after its only supply shared by another device shuts down.
Signed-off-by Erikas Bitovtas <[email protected]>Reported-by Raymond Hackley <[email protected]>
Mixing new features and cleanup through the series isn't ideal. Can we move this one to the end? So do all the cleanup first then add this new handling?
Thanks,
Jonathan
Quoted 38 lines
--- drivers/iio/light/vcnl4000.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/iio/light/vcnl4000.c +8
-0@@ -24,6 +24,7 @@#include <linux/interrupt.h> #include <linux/module.h> #include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> #include <linux/units.h> #include <linux/iio/buffer.h> @@ -1991,6 +1992,7 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)static int vcnl4000_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client); +const char *const regulator_names[] = {"vdd" ,"vddio" ,"vled" };struct vcnl4000_data *data;struct iio_dev *indio_dev;struct device *dev = &client->dev;@@ -2006,6 +2008,12 @@ static int vcnl4000_probe(struct i2c_client *client) data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; + ret =devm_regulator_bulk_get_enable (dev, +ARRAY_SIZE (regulator_names), + regulator_names); +if (ret <0 ) +return ret; + ret =devm_mutex_init (dev, &data->vcnl4000_lock);if (ret <0 )return ret;
Re: [PATCH v3 4/6] iio: light: vcnl4000: add support for regulators
In reply to Erikas BitovtasQuoted 3 lines · Erikas Bitovtas
Add supply, I2C and cathode voltage regulators to the sensor and enable them. This keeps the sensor powered on even after its only supply shared by another device shuts down.
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2011
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+ ret = devm_regulator_bulk_get_enable(dev,
Below is broken indentation.
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2012
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+ ARRAY_SIZE(regulator_names),
There is still some room on the previous line.
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2013
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+ regulator_names);
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), regulator_names);
OTOH the logical split is rather to have the last two on a single line, but that one becomes too long, so your initial variant is okay with fixed indentation.
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), regulator_names);
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2014
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+if (ret <0 )
Do we need ' < 0' part?
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 5/6 iio: light: vcnl4000: remove error messages for trigger and irq
In reply to Erikas BitovtasThe error code is available in the log after return. Remove duplicate error messages to reduce noise in dmesg.
--- drivers/iio/light/vcnl4000.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/light/vcnl4000.c +2 -7
@@ -2041,11 +2041,8 @@ static int vcnl4000_probe(struct i2c_client *client)NULL , data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops); -if (ret <0 ) { -dev_err (&client->dev, -"unable to setup iio triggered buffer\n" ); +if (ret <0 )return ret; - } }if (client->irq && data->chip_spec->irq_thread) {
@@ -2055,10 +2052,8 @@ static int vcnl4000_probe(struct i2c_client *client)IRQF_ONESHOT ,"vcnl4000_irq" , indio_dev); -if (ret <0 ) { -dev_err (&client->dev,"irq request failed\n" ); +if (ret <0 )return ret; - } ret =vcnl4010_probe_trigger (indio_dev);if (ret <0 )
Signature · 1 line
2.53.0
Jonathan Cameron
maintainerRe: [PATCH v3 5/6] iio: light: vcnl4000: remove error messages for trigger and irq
Quoted 13 lines · On Sat, 14 Mar 2026 18:06:34 +0200 Erikas Bitovtas <[email protected]> wrote:
The error code is available in the log after return. Remove duplicate error messages to reduce noise in dmesg.
Signed-off-by Erikas Bitovtas <[email protected]>--- drivers/iio/light/vcnl4000.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/iio/light/vcnl4000.c +0
-0
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2046
Quoted 6 lines
drivers/iio/light/vcnl4000.c +0
-3@@ -2041,11 +2041,8 @@ static int vcnl4000_probe(struct i2c_client *client)NULL , data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops); -if (ret <0 ) { -dev_err (&client->dev, -"unable to setup iio triggered buffer\n" );
Is this one a duplicate? I don't recall us being particular verbose in terms of error messages in iio_triggered_buffer_setup_ext() which is where that ends up coming from. I think there is only one path where it can return anything other than -ENOMEM and that one is a duplicate registration check (so fair to not print). So perhaps all this patch needs is a comment on what errors can surface from this call and why it is therefore not worth printing anything.
Quoted 19 lines
drivers/iio/light/vcnl4000.c +2
-4+if (ret <0 )return ret; - } }if (client->irq && data->chip_spec->irq_thread) {@@ -2055,10 +2052,8 @@ static int vcnl4000_probe(struct i2c_client *client)IRQF_ONESHOT ,"vcnl4000_irq" , indio_dev); -if (ret <0 ) { -dev_err (&client->dev,"irq request failed\n" ); +if (ret <0 )return ret; - } ret =vcnl4010_probe_trigger (indio_dev);if (ret <0 )
Re: [PATCH v3 5/6] iio: light: vcnl4000: remove error messages for trigger and irq
Quoted 23 lines · Jonathan Cameron
Quoted 13 lines · On Sat, 14 Mar 2026 18:06:34 +0200 Erikas Bitovtas <[email protected]> wrote:
The error code is available in the log after return. Remove duplicate error messages to reduce noise in dmesg.
Signed-off-by Erikas Bitovtas <[email protected]>--- drivers/iio/light/vcnl4000.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/iio/light/vcnl4000.c +0
-0drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2046
Quoted 6 lines
drivers/iio/light/vcnl4000.c +0
-3@@ -2041,11 +2041,8 @@ static int vcnl4000_probe(struct i2c_client *client)NULL , data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops); -if (ret <0 ) { -dev_err (&client->dev, -"unable to setup iio triggered buffer\n" );
Quoted 8 lines
Is this one a duplicate? I don't recall us being particular verbose in terms of error messages in
iio_triggered_buffer_setup_ext()which is where that ends up coming from. I think there is only one path where it can return anything other than-ENOMEMand that one is a duplicate registration check (so fair to not print). So perhaps all this patch needs is a comment on what errors can surface from this call and why it is therefore not worth printing anything.
I do not see anything being printed on iio_triggered_buffer_setup_ext(), so I guess this is not a duplicate. The function can return -EADDRINUSE if a buffer is already assigned, to prevent cleanup function being called on a buffer that wasn't allocated.
I will add this print back if necessary in v4.
Re: [PATCH v3 5/6] iio: light: vcnl4000: remove error messages for trigger and irq
Quoted 35 lines · Erikas Bitovtas
Quoted 23 lines · Jonathan Cameron
Quoted 13 lines · On Sat, 14 Mar 2026 18:06:34 +0200 Erikas Bitovtas <[email protected]> wrote:
The error code is available in the log after return. Remove duplicate error messages to reduce noise in dmesg.
Signed-off-by Erikas Bitovtas <[email protected]>--- drivers/iio/light/vcnl4000.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/iio/light/vcnl4000.c +0
-0drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2046
Quoted 6 lines
drivers/iio/light/vcnl4000.c +0
-3@@ -2041,11 +2041,8 @@ static int vcnl4000_probe(struct i2c_client *client)NULL , data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops); -if (ret <0 ) { -dev_err (&client->dev, -"unable to setup iio triggered buffer\n" );Quoted 8 lines
Is this one a duplicate? I don't recall us being particular verbose in terms of error messages in
iio_triggered_buffer_setup_ext()which is where that ends up coming from. I think there is only one path where it can return anything other than-ENOMEMand that one is a duplicate registration check (so fair to not print). So perhaps all this patch needs is a comment on what errors can surface from this call and why it is therefore not worth printing anything.
Quoted 6 lines
I do not see anything being printed on
iio_triggered_buffer_setup_ext(), so I guess this is not a duplicate. The function can return-EADDRINUSEif a buffer is already assigned, to prevent cleanup function being called on a buffer that wasn't allocated.
I will add this print back if necessary in v4.
I think it is fine to drop the print but more detail on why is needed for the commit message.
PATCH v3 6/6 iio: light: vcnl4000: use variables for I2C client and device instances
In reply to Erikas BitovtasAfter moving data->client and client->dev into variables of their own, replace all instances of data->client and client->dev being used in vcnl4200_init and vcnl4000_probe by the said variables to reduce clutter.
--- drivers/iio/light/vcnl4000.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/iio/light/vcnl4000.c +17 -17
@@ -362,14 +362,14 @@ static int vcnl4200_init(struct vcnl4000_data *data)int ret, id;u16 regval; - ret =i2c_smbus_read_word_data (data->client,VCNL4200_DEV_ID ); + ret =i2c_smbus_read_word_data (client,VCNL4200_DEV_ID );if (ret <0 )return ret; id = ret &0xff ;if (id !=VCNL4200_PROD_ID ) { - ret =i2c_smbus_read_word_data (data->client,VCNL4040_DEV_ID ); + ret =i2c_smbus_read_word_data (client,VCNL4040_DEV_ID );if (ret <0 )return ret;
@@ -379,7 +379,7 @@ static int vcnl4200_init(struct vcnl4000_data *data)return -ENODEV ; } -dev_dbg (&data->client->dev,"device id 0x%x" , id); +dev_dbg (dev,"device id 0x%x" , id); data->rev = (ret >>8 ) &0xf ; data->ps_int =0 ;
@@ -413,23 +413,23 @@ static int vcnl4200_init(struct vcnl4000_data *data)return ret;/* Use 16 bits proximity sensor readings */ - ret =i2c_smbus_read_word_data (data->client,VCNL4200_PS_CONF1 ); + ret =i2c_smbus_read_word_data (client,VCNL4200_PS_CONF1 );if (ret <0 )return ret; regval = ret |VCNL4040_PS_CONF2_PS_HD ; - ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF1 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF1 , regval);if (ret <0 )return ret;/* Align proximity sensor sample rate to 16 bits data width */ - ret =i2c_smbus_read_word_data (data->client,VCNL4200_PS_CONF3 ); + ret =i2c_smbus_read_word_data (client,VCNL4200_PS_CONF3 );if (ret <0 )return ret; regval = ret |VCNL4040_CONF3_PS_SAMPLE_16BITS ; - ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF3 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF3 , regval);if (ret <0 )return ret;
@@ -1998,7 +1998,7 @@ static int vcnl4000_probe(struct i2c_client *client)struct device *dev = &client->dev;int ret; - indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); + indio_dev =devm_iio_device_alloc (dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;
@@ -2022,10 +2022,10 @@ static int vcnl4000_probe(struct i2c_client *client)if (ret <0 )return ret; -dev_dbg (&client->dev,"%s Ambient light/proximity sensor, Rev: %02x\n" , +dev_dbg (dev,"%s Ambient light/proximity sensor, Rev: %02x\n" , data->chip_spec->prod, data->rev); -if (device_property_read_u32 (&client->dev,"proximity-near-level" , +if (device_property_read_u32 (dev,"proximity-near-level" , &data->near_level)) data->near_level =0 ;
@@ -2037,7 +2037,7 @@ static int vcnl4000_probe(struct i2c_client *client)if (data->chip_spec->trig_buffer_func && data->chip_spec->buffer_setup_ops) { - ret =devm_iio_triggered_buffer_setup (&client->dev, indio_dev, + ret =devm_iio_triggered_buffer_setup (dev, indio_dev,NULL , data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops);
@@ -2046,8 +2046,8 @@ static int vcnl4000_probe(struct i2c_client *client) }if (client->irq && data->chip_spec->irq_thread) { - ret = devm_request_threaded_irq(&client->dev, client->irq, - NULL, data->chip_spec->irq_thread, + ret = devm_request_threaded_irq(dev, client->irq, NULL, + data->chip_spec->irq_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "vcnl4000_irq",
@@ -2060,7 +2060,7 @@ static int vcnl4000_probe(struct i2c_client *client)return ret; } - ret =pm_runtime_set_active (&client->dev); + ret =pm_runtime_set_active (dev);if (ret <0 ) goto fail_poweroff;
@@ -2068,9 +2068,9 @@ static int vcnl4000_probe(struct i2c_client *client)if (ret <0 ) goto fail_poweroff; -pm_runtime_enable (&client->dev); -pm_runtime_set_autosuspend_delay (&client->dev,VCNL4000_SLEEP_DELAY_MS ); -pm_runtime_use_autosuspend (&client->dev); +pm_runtime_enable (dev); +pm_runtime_set_autosuspend_delay (dev,VCNL4000_SLEEP_DELAY_MS ); +pm_runtime_use_autosuspend (dev);return 0 ; fail_poweroff:
Signature · 1 line
2.53.0
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Quoted 4 lines · Erikas Bitovtas
After moving
data->clientandclient->devinto variables of their own, replace all instances ofdata->clientandclient->devbeing used invcnl4200_initandvcnl4000_probeby the said variables to reduce clutter.
...
drivers/iio/light/vcnl4000.c static int vcnl4200_init(struct vcnl4000_data *data) · line 422
Quoted 3 lines
drivers/iio/light/vcnl4000.c +1
-1- ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF1 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF1 , regval);
Now it's perfectly a single line.
ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1, regval);
Quoted 2 lines
(quoted diff) +0
-0if (ret < 0) return ret;
...
drivers/iio/light/vcnl4000.c static int vcnl4200_init(struct vcnl4000_data *data) · line 433
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-1regval = ret |VCNL4040_CONF3_PS_SAMPLE_16BITS ; - ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF3 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF3 , regval);
Ditto.
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2030
Quoted 7 lines
drivers/iio/light/vcnl4000.c +1
-1if (ret <0 )return ret; -if (device_property_read_u32 (&client->dev,"proximity-near-level" , +if (device_property_read_u32 (dev,"proximity-near-level" , &data->near_level)) data->near_level =0 ;
The 'if' is redundant, I think you can drop it at some point, probably to avoid churn in the follow up
- if (device_property_read_u32(&client->dev, "proximity-near-level",
- data->near_level = 0;
+ device_property_read_u32(dev, "proximity-near-level", &data->near_level);
Assuming data is allocated with kzalloc() or equivalent.
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2041
Quoted 3 lines
drivers/iio/light/vcnl4000.c +1
-1- ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
Now NULL can be moved to upper line.
Quoted 2 lines
drivers/iio/light/vcnl4000.c +0
-0data->chip_spec->trig_buffer_func, data->chip_spec->buffer_setup_ops);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Quoted 39 lines · Andy Shevchenko
Quoted 4 lines · Erikas Bitovtas
After moving
data->clientandclient->devinto variables of their own, replace all instances ofdata->clientandclient->devbeing used invcnl4200_initandvcnl4000_probeby the said variables to reduce clutter....
drivers/iio/light/vcnl4000.c static int vcnl4200_init(struct vcnl4000_data *data) · line 422
Quoted 3 lines
drivers/iio/light/vcnl4000.c +1
-1- ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF1 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF1 , regval);Now it's perfectly a single line.
ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1, regval);Quoted 2 lines
(quoted diff) +0
-0if (ret < 0) return ret;...
drivers/iio/light/vcnl4000.c static int vcnl4200_init(struct vcnl4000_data *data) · line 433
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-1regval = ret |VCNL4040_CONF3_PS_SAMPLE_16BITS ; - ret =i2c_smbus_write_word_data (data->client,VCNL4200_PS_CONF3 , + ret =i2c_smbus_write_word_data (client,VCNL4200_PS_CONF3 , regval);Ditto.
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2030
Quoted 7 lines
drivers/iio/light/vcnl4000.c +1
-1if (ret <0 )return ret; -if (device_property_read_u32 (&client->dev,"proximity-near-level" , +if (device_property_read_u32 (dev,"proximity-near-level" , &data->near_level)) data->near_level =0 ;The 'if' is redundant, I think you can drop it at some point, probably to avoid churn in the follow up
Quoted 4 lines
- if (device_property_read_u32(&client->dev, "proximity-near-level",
-data->near_level= 0;
+device_property_read_u32(dev, "proximity-near-level", &data->near_level);
device_property_read_u32() throws an error if a property is missing. Would data->near_level be left without an assigned default value in that case?
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Quoted 1 line · Erikas Bitovtas
On 3/16/26 12:39 PM, Andy Shevchenko wrote:
First of all, remove the content you are not replying to!
...
Quoted 8 lines
Quoted 8 lines
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2030
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-1-if (device_property_read_u32 (&client->dev,"proximity-near-level" , +if (device_property_read_u32 (dev,"proximity-near-level" , &data->near_level)) data->near_level =0 ;The 'if' is redundant, I think you can drop it at some point, probably to avoid churn in the follow up
Quoted 8 lines
Quoted 4 lines
- if (device_property_read_u32(&client->dev, "proximity-near-level",
-data->near_level= 0;
+device_property_read_u32(dev, "proximity-near-level", &data->near_level);
device_property_read_u32()throws an error if a property is missing. Woulddata->near_levelbe left without an assigned default value in that case?
Second, have you read my reply carefully?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Erikas Bitovtas
This patch series introduces support for voltage supply, I2C and cathode regulators. This fixes an issue where if a regulator is shared between the proximity sensor and some other device, and the other device is powered off, the proximity sensor would be powered off as well.
One of the commits includes a Reported-by: tag without a Closes: tag - the report was done outside of LKML.
If it is on the public web, we can still add a link. You can just reply to that patch with the tag (if there is one) and it will get picked up.
Quoted 3 lines
Signed-off-by Erikas Bitovtas <[email protected]>---