Skip to contentSkip to conversation

iio: light: vcnl4000: add regulator support

PATCH Superseded Erikas Bitovtas 3 participants 7 messages Mar 11 – Mar 15

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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.

---
Erikas Bitovtas (2):
dt-bindings: iio: light: vcnl4000: add regulators
iio: light: vcnl4000: add regulator support

 Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml | 7 +++++++
 drivers/iio/light/vcnl4000.c                                     | 8 ++++++++
 2 files changed, 15 insertions(+)

---
base-commit: 7109a2155340cc7b21f27e832ece6df03592f2e8
change-id: 20260310-vcnl4000-regulators-bcf1b8a01ce6

Best regards,

Signature · 1 line
Erikas Bitovtas <[email protected]>
#1 lore raw

PATCH 1/2 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
index 2ba4d5de4ec4..a1b4c02db246 100644
@@ -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 = <&reg_vdd>;
+            vddio-supply = <&reg_vddio>;
+            vled-supply = <&reg_vled>;
         };
     };
 ...
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 iio: light: vcnl4000: add regulator support

In reply to 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 | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/light/vcnl4000.c +8 -0
index 5e03c3d8874b..967589d5f246 100644
@@ -17,6 +17,8 @@
  *   interrupts (VCNL4040, VCNL4200)
  */
 
+#include "linux/array_size.h"
+#include "linux/regulator/consumer.h"
 #include <linux/bitfield.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
@@ -1983,6 +1985,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;
@@ -1998,6 +2001,11 @@ static int vcnl4000_probe(struct i2c_client *client)
 	data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
 
 	mutex_init(&data->vcnl4000_lock);
+	ret = devm_regulator_bulk_get_enable(&client->dev,
+				      ARRAY_SIZE(regulator_names),
+				      regulator_names);
+	if (ret < 0)
+		return ret;
 
 	ret = data->chip_spec->init(data);
 	if (ret < 0)
Signature · 1 line
2.53.0
#3 lore raw
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.

Where was it reported? Do you need Closes tag?

...

drivers/iio/light/vcnl4000.c line 21

Quoted 2 lines
drivers/iio/light/vcnl4000.c +2 -0
+#include "linux/array_size.h"
+#include "linux/regulator/consumer.h"

Double quotes, huh?!

Quoted 3 lines

#include <linux/bitfield.h>
#include <linux/module.h>
#include <linux/i2c.h>

Also, please keep the list ordered.

...

drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2008

Quoted 6 lines
drivers/iio/light/vcnl4000.c +5 -0
 	mutex_init(&data->vcnl4000_lock);
+	ret = devm_regulator_bulk_get_enable(&client->dev,
+				      ARRAY_SIZE(regulator_names),
+				      regulator_names);
+	if (ret < 0)
+		return ret;

You can't add devm_ after non-devm calls.
Also it would help you to have

	struct device *dev = &client->dev;

at the top of the function.

...

With the above being said, I expect a series out of two patches at least.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 11 lines · Andy Shevchenko
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.

Where was it reported? Do you need Closes tag?

...

The report was done outside of LKML, in a Matrix channel.

Respectfully,
Erikas Bitovtas

#5 lore raw
Quoted 6 lines · Erikas Bitovtas
Quoted 5 lines · Andy Shevchenko
Quoted 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.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Where was it reported? Do you need Closes tag?

The report was done outside of LKML, in a Matrix channel.

Good, next time don't forget to add this type of information in the comments block, so we will know why Closes is not accompanied with the Reported-by. But if that channel has web-available archives, it will be good to have a link to it in the Closes tag.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#6 lore raw
In reply to Andy Shevchenko
Quoted 25 lines · On Wed, 11 Mar 2026 14:22:36 +0200 Andy Shevchenko…
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.

Where was it reported? Do you need Closes tag?

...

drivers/iio/light/vcnl4000.c line 21

Quoted 2 lines
drivers/iio/light/vcnl4000.c +2 -0
+#include "linux/array_size.h"
+#include "linux/regulator/consumer.h"  

Double quotes, huh?!

Quoted 3 lines

#include <linux/bitfield.h>
#include <linux/module.h>
#include <linux/i2c.h>

Also, please keep the list ordered.

...

Quoted 8 lines

drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client) · line 2008

Quoted 6 lines
drivers/iio/light/vcnl4000.c +5 -0
 	mutex_init(&data->vcnl4000_lock);
+	ret = devm_regulator_bulk_get_enable(&client->dev,
+				      ARRAY_SIZE(regulator_names),
+				      regulator_names);
+	if (ret < 0)
+		return ret;  

You can't add devm_ after non-devm calls.

This one happens to be fine because there is no cleanup of the mutex_init(), so it is sort of not mixing devm and non devm. That is kind of a historical thing where I for one wasn't convinced it was worth the annoyance of mutex_destroy() until the devm easy way of doing it came along.

Now, as the code is being touched anyway, I would
like that moved to
ret = devm_mutex_init();
if (ret)

	return ret;

as a precursor patch both as it makes it obvious we are still devm and to get the advantage when lock debugging is turned on.

Thanks

Jonathan

Quoted 10 lines

Also it would help you to have

	struct device *dev = &client->dev;

at the top of the function.

...

With the above being said, I expect a series out of two patches at least.