iio: light: vcnl4000: add regulator support
Subsystems (2)
v2 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 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 (3):
dt-bindings: iio: light: vcnl4000: add regulators
iio: light: vcnl4000: add support for regulators
iio: light: vcnl4000: move client->dev in probe into a variable
.../bindings/iio/light/vishay,vcnl4000.yaml | 7 ++++ drivers/iio/light/vcnl4000.c | 41 +++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-)
---
base-commit: f90aadf1c67c8b4969d1e5e6d4fd7227adb6e4d7
change-id: 20260310-vcnl4000-regulators-bcf1b8a01ce6
Best regards,
Signature · 1 line
Erikas Bitovtas <[email protected]>
PATCH v2 1/3 dt-bindings: iio: light: vcnl4000: add regulators
This commit adds regulator properties for vcnl4000 ambient light and proximity sensors.
--- 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 v2 1/3] dt-bindings: iio: light: vcnl4000: add regulators
Quoted 2 lines · Erikas Bitovtas
This commit adds regulator properties for vcnl4000 ambient light and proximity sensors.
This we can see. Your commit message should say why.
Do all devices in the binding have all of these supplies?
Quoted 35 lines
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 +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 · 2 lines
-- 2.53.0
Re: [PATCH v2 1/3] dt-bindings: iio: light: vcnl4000: add regulators
Quoted 8 lines · Conor Dooley
Quoted 2 lines · Erikas Bitovtas
This commit adds regulator properties for vcnl4000 ambient light and proximity sensors.
This we can see. Your commit message should say why.
Do all devices in the binding have all of these supplies?
If we look at the datasheet for vcnl4040,
https://www.vishay.com/docs/84274/vcnl4040.pdf, in figure 11 we can see that there can be 3 supplies: sensor supply Vdd (vdd), I2C supply for the bus Vpull_up (vddio) and IR LED anode Vdd_led (vled). The other datasheets refer to three supplies as well - one for the sensor, one for anode and one for the bus:
https://www.vishay.com/docs/83372/vcnl4000.pdf
https://www.vishay.com/docs/84138/designingvcnl4010.pdf
https://www.vishay.com/docs/84327/designingvcnl4200.pdf
Quoted 35 lines
Quoted 35 lines
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 +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 · 2 lines
-- 2.53.0
Re: [PATCH v2 1/3] dt-bindings: iio: light: vcnl4000: add regulators
Quoted 12 lines · Erikas Bitovtas
Quoted 8 lines · Conor Dooley
Quoted 2 lines · Erikas Bitovtas
This commit adds regulator properties for vcnl4000 ambient light and proximity sensors.
This we can see. Your commit message should say why.
Do all devices in the binding have all of these supplies?
Quoted 9 lines
If we look at the datasheet for vcnl4040,
https://www.vishay.com/docs/84274/vcnl4040.pdf, in figure 11 we can see that there can be 3 supplies: sensor supply Vdd (vdd), I2C supply for the busVpull_up(vddio) and IR LED anodeVdd_led(vled). The other datasheets refer to three supplies as well - one for the sensor, one for anode and one for the bus:
https://www.vishay.com/docs/83372/vcnl4000.pdf
https://www.vishay.com/docs/84138/designingvcnl4010.pdf
https://www.vishay.com/docs/84327/designingvcnl4200.pdf
Please provide this information in the commit message in v2.
Thanks,
Conor.
pw-bot: changes-requested
Quoted 37 lines
Quoted 36 lines
Quoted 36 lines
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 +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 · 2 lines
-- 2.53.0
PATCH v2 2/3 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.
This bug was reported outside of LKML, so no Closes: tag can be attached.
--- drivers/iio/light/vcnl4000.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/iio/light/vcnl4000.c +12 -4
@@ -18,12 +18,13 @@*/ #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/regulator/consumer.h> #include <linux/units.h> #include <linux/iio/buffer.h>
@@ -1983,6 +1984,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;int ret;
@@ -1997,6 +1999,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 (&client->dev, +ARRAY_SIZE (regulator_names), + regulator_names); +if (ret <0 ) +return ret; +mutex_init (&data->vcnl4000_lock); ret = data->chip_spec->init (data);
Signature · 1 line
2.53.0
Re: [PATCH v2 2/3] iio: light: vcnl4000: add support for regulators
Quoted 6 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.
This bug was reported outside of LKML, so no Closes: tag can be attached.
This paragraph should not be part of the commit message. There is a comment/changelog block for that.
...
drivers/iio/light/vcnl4000.c line 28
Quoted 13 lines
#include <
linux/bitfield.h>drivers/iio/light/vcnl4000.c +5
-4-#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/regulator/consumer.h> #include <linux/units.h>
Sorting headers should be a separate prerequisite change.
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client)
Quoted 7 lines
drivers/iio/light/vcnl4000.c +5
-0+ ret =devm_regulator_bulk_get_enable (&client->dev, +ARRAY_SIZE (regulator_names), + regulator_names); +if (ret <0 ) +return ret;mutex_init (&data->vcnl4000_lock);
I would rather expect another prerequisite patch that moves to devm_mutex_init().
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/3 iio: light: vcnl4000: move client->dev in probe into a variable
In reply to Erikas BitovtasMove client->dev into a variable of its own and replace all instances of client->dev being used by it.
--- drivers/iio/light/vcnl4000.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/iio/light/vcnl4000.c +14 -13
@@ -1987,9 +1987,10 @@ static int vcnl4000_probe(struct i2c_client *client)const char *const regulator_names[] = {"vdd" ,"vddio" ,"vled" };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)); + indio_dev =devm_iio_device_alloc (dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;
@@ -1999,7 +2000,7 @@ 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 (&client->dev, + ret =devm_regulator_bulk_get_enable (dev,ARRAY_SIZE (regulator_names), regulator_names);if (ret <0 )
@@ -2011,10 +2012,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 ;
@@ -2026,26 +2027,26 @@ 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);if (ret <0 ) { -dev_err (&client->dev, +dev_err (dev,"unable to setup iio triggered buffer\n" );return ret; } }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" , indio_dev);if (ret <0 ) { -dev_err (&client->dev,"irq request failed\n" ); +dev_err (dev,"irq request failed\n" );return ret; }
@@ -2054,7 +2055,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;
@@ -2062,9 +2063,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 v2 3/3] iio: light: vcnl4000: move client->dev in probe into a variable
Quoted 2 lines · Erikas Bitovtas
Move
client->devinto a variable of its own and replace all instances ofclient->devbeing used by it.
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 1990
Quoted 1 line
drivers/iio/light/vcnl4000.c +1
-0+struct device *dev = &client->dev;
This should be done in the previous patch to reduce churn...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2003
Quoted 2 lines
drivers/iio/light/vcnl4000.c +1
-1- ret = devm_regulator_bulk_get_enable(&client->dev, + ret = devm_regulator_bulk_get_enable(dev,
...like this one.
Quoted 2 lines
drivers/iio/light/vcnl4000.c +0
-0ARRAY_SIZE (regulator_names), regulator_names);
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client)
Quoted 12 lines
drivers/iio/light/vcnl4000.c +3
-1+ ret =devm_request_threaded_irq (dev, client->irq,NULL , + data->chip_spec->irq_thread,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,"vcnl4000_irq" , indio_dev);if (ret <0 ) { -dev_err (&client->dev,"irq request failed\n" ); +dev_err (dev,"irq request failed\n" );return ret; }
This should be another patch to remove the dup message completely before doing struct device conversion.
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.
...
Quoted 3 lines
- Removed double quotes in includes.
- Reordered includes alphabetically.
Yes, but should be done in a separate change.
Quoted 1 line
- Enabled regulators before the mutex is initialized.
Why?
Quoted 1 line
- Replaced direct usage of
&client->devwith a variable.
...
TL;DR: this has to be series out of 6 patches.
Signature · 2 lines
With Best Regards, Andy Shevchenko