[PATCH v3 4/6] iio: light: vcnl4000: add support for regulators

Erikas Bitovtas posted 6 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH v3 4/6] iio: light: vcnl4000: add support for regulators
Posted by Erikas Bitovtas 3 weeks, 2 days ago
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 <xerikasxx@gmail.com>
Reported-by: Raymond Hackley <raymondhackley@protonmail.com>
---
 drivers/iio/light/vcnl4000.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 0ee307fc5ab7..e501db7249d7 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -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;

-- 
2.53.0
Re: [PATCH v3 4/6] iio: light: vcnl4000: add support for regulators
Posted by Andy Shevchenko 3 weeks ago
On Sat, Mar 14, 2026 at 06:06:33PM +0200, Erikas Bitovtas 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.

...

> +	ret = devm_regulator_bulk_get_enable(dev,

Below is broken indentation.

> +				      ARRAY_SIZE(regulator_names),

There is still some room on the previous line.

> +				      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);


> +	if (ret < 0)

Do we need ' < 0' part?

> +		return ret;

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 4/6] iio: light: vcnl4000: add support for regulators
Posted by Jonathan Cameron 3 weeks, 1 day ago
On Sat, 14 Mar 2026 18:06:33 +0200
Erikas Bitovtas <xerikasxx@gmail.com> 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 <xerikasxx@gmail.com>
> Reported-by: Raymond Hackley <raymondhackley@protonmail.com>

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

> ---
>  drivers/iio/light/vcnl4000.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 0ee307fc5ab7..e501db7249d7 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -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;
>