Skip to contentSkip to conversation

Add optional power supply for INA2XX

PATCH Superseded Svyatoslav Ryhel 5 participants 21 messages Mar 8, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add optional power supply for INA2XX

On some devices (like LG Optimus Vu) ina2xx hwmon may require power supply for correct work, hance add one.

Svyatoslav Ryhel (2):
dt-bindings: hwmon: ina2xx: add supply property
hwmon: ina2xx: add optional regulator support

 .../devicetree/bindings/hwmon/ti,ina2xx.yaml         |  4 ++++
 drivers/hwmon/ina2xx.c                               | 12 ++++++++++++
 2 files changed, 16 insertions(+)
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/2 dt-bindings: hwmon: ina2xx: add supply property

Add supply property.

---
 Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +4 -0
index 47af97bb4ced..0f494131fa05 100644
@@ -57,6 +57,8 @@ properties:
     $ref: /schemas/types.yaml#/definitions/uint32
     enum: [1, 2, 4, 8]
 
+  vdd-supply: true
+
 required:
   - compatible
   - reg
@@ -73,5 +75,7 @@ examples:
             compatible = "ti,ina220";
             reg = <0x44>;
             shunt-resistor = <1000>;
+
+            vdd-supply = <&vdd_3v0_sen>;
         };
     };
Signature · 1 line
2.37.2
#2 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

Quoted 1 line · Svyatoslav Ryhel

Add supply property.

You have entire commit msg to explain and give background, but instead there is just sentence duplicating subject. And since you did not explain anything, we have questions... like: INA238 does not have VDD, so this does not look correct.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

ср, 8 бер. 2023 р. о 12:27 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 1 line

Add supply property.

You have entire commit msg to explain and give background, but instead there is just sentence duplicating subject. And since you did not explain anything, we have questions... like: INA238 does not have VDD, so this does not look correct.

This is why a regulator is not mandatory. If ina238 does not have vdd then one who needs ina238 may omit this prop. How about looking from this perspective?

Quoted 4 lines

Best regards,
Krzysztof

Best regards,
Svyatoslav R.

#4 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

Quoted 12 lines · Svyatoslav Ryhel

ср, 8 бер. 2023 р. о 12:27 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 1 line

Add supply property.

You have entire commit msg to explain and give background, but instead there is just sentence duplicating subject. And since you did not explain anything, we have questions... like: INA238 does not have VDD, so this does not look correct.

Quoted 3 lines

This is why a regulator is not mandatory. If ina238 does not have vdd then one who needs ina238 may omit this prop. How about looking from this perspective?

Not required means "optional", not "not existing" or "totally invalid".

Best regards,
Krzysztof

maintainer
#5 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

In reply to Svyatoslav Ryhel
Quoted 12 lines · Svyatoslav Ryhel

ср, 8 бер. 2023 р. о 12:27 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 1 line

Add supply property.

You have entire commit msg to explain and give background, but instead there is just sentence duplicating subject. And since you did not explain anything, we have questions... like: INA238 does not have VDD, so this does not look correct.

Quoted 4 lines

This is why a regulator is not mandatory. If ina238 does not have vdd then one who needs ina238 may omit this prop. How about looking from this perspective?

If a chip does not have VDD, the driver should not even try to get it for that chip. INS238 is supported by a different driver, so that does not require special code, but it needs to be spelled out in the devicetree bindings. Devicetree has a means to specify if a property is valid for a given device.

Having said this, as it turns out, _none_ of the chips supported by the ina2xx and the ina238 drivers have VDD. All of them have Vs, and all but INA219 have Vbus. The bindings don't even explain which one of those is supposed to refer to "VDD".

Also, regulator_get_optional() returns -ENODEV if CONFIG_REGULATOR is not enabled, so it isn't entirely optional. We can not suddenly fail to load the driver on systems with CONFIG_REGULATOR=n, so some conditional code will unfortunately be necessary.

Guenter

Quoted 7 lines
Quoted 4 lines

Best regards,
Krzysztof

Best regards,
Svyatoslav R.

#6 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

8 березня 2023 р. 13:35:46 GMT+02:00, Guenter Roeck <[email protected]> написав(-ла):

Quoted 24 lines · Svyatoslav Ryhel
Quoted 12 lines

ср, 8 бер. 2023 р. о 12:27 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 1 line

Add supply property.

You have entire commit msg to explain and give background, but instead there is just sentence duplicating subject. And since you did not explain anything, we have questions... like: INA238 does not have VDD, so this does not look correct.

Quoted 4 lines

This is why a regulator is not mandatory. If ina238 does not have vdd then one who needs ina238 may omit this prop. How about looking from this perspective?

If a chip does not have VDD, the driver should not even try to get it for that chip. INS238 is supported by a different driver, so that does not require special code, but it needs to be spelled out in the devicetree bindings. Devicetree has a means to specify if a property is valid for a given device.

Quoted 5 lines

Having said this, as it turns out, _none_ of the chips supported by the ina2xx and the ina238 drivers have VDD. All of them have Vs, and all but INA219 have Vbus. The bindings don't even explain which one of those is supposed to refer to "VDD".

So you refer to vdd as to a real name. Now I understand this misunderstand. Regulator I am interested in is Vs. Since you confirmed that Vs is supported by all ina2xx there should be no contraversions further.

Quoted 7 lines

Also, regulator_get_optional() returns -ENODEV if CONFIG_REGULATOR is not enabled, so it isn't entirely optional. We can not suddenly fail to load the driver on systems with CONFIG_REGULATOR=n, so some conditional code will unfortunately be necessary.

Guenter

Hm, then Lars-Peter Clausen suggestion should be applicable in this case.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Best regards,
Krzysztof

Best regards,
Svyatoslav R.

#7 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

In reply to Svyatoslav Ryhel

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 64

Quoted 7 lines · Svyatoslav Ryhel

Add supply property.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg

Unless the device can work without power the supply should be required.

#8 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

8 березня 2023 р. 14:54:34 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 10 lines · Svyatoslav Ryhel

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 64

Quoted 7 lines

Add supply property.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg

Unless the device can work without power the supply should be required.

Device can work without supply defined on most devices, but in my case power is gated with gpio and devices will not work without fixed regulator.

#9 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

Quoted 12 lines · Svyatoslav Ryhel

8 березня 2023 р. 14:54:34 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 9 lines · Svyatoslav Ryhel
Quoted 7 lines

Add supply property.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg
Quoted 3 lines
Quoted 1 line

Unless the device can work without power the supply should be required.

Device can work without supply defined on most devices,

Are you sure they can work without any power? INA231 does not say VS supply is optional. Datasheet says:
"The INA231 is typically powered by a separate supply that can range from 2.7 V to 5.5 V."

Although it uses word "typically" which could suggest other design, but are you sure it can work without it? From where it gets the power?

Quoted 1 line

but in my case power is gated with gpio and devices will not work

without fixed regulator.

BTW, wrap your lines to match mailing list style.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

In reply to Svyatoslav Ryhel
Quoted 10 lines · Svyatoslav Ryhel

8 березня 2023 р. 14:54:34 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 8 lines · Svyatoslav Ryhel
Quoted 7 lines

Add supply property.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg
Quoted 3 lines
Quoted 1 line

Unless the device can work without power the supply should be required.

Device can work without supply defined on most devices, but in my case power is gated with gpio and devices will not work without fixed regulator.

If there are devices that work without any source of power at all that would be very surprising. It doesn't matter if a particular system has a non-controllable regulator, the binding should still make it mandatory to describe that.

#11 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

8 березня 2023 р. 15:46:52 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 11 lines · Svyatoslav Ryhel
Quoted 9 lines

8 березня 2023 р. 14:54:34 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 8 lines · Svyatoslav Ryhel
Quoted 7 lines

Add supply property.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Unless the device can work without power the supply should be required.

Device can work without supply defined on most devices, but in my case power is gated with gpio and devices will not work without fixed regulator.

If there are devices that work without any source of power at all that would be very surprising. It doesn't matter if a particular system has a non-controllable regulator, the binding should still make it mandatory to describe that.

Then question is WHY and WHO passed driver without power supply system implemented? Why it pops only now?

#12 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

Quoted 8 lines · Svyatoslav Ryhel
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 64

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +2 -0
+  vdd-supply: true
+
 required:
   - compatible
   - reg

Unless the device can work without power the supply should be required.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Device can work without supply defined on most devices, but in my case power is gated with gpio and devices will not work without fixed regulator.

If there are devices that work without any source of power at all that would be very surprising. It doesn't matter if a particular system has a non-controllable regulator, the binding should still make it mandatory to describe that.

Then question is WHY and WHO passed driver without power supply system implemented? Why it pops only now?

Why do you mention driver? We talk about bindings and device. What the driver does, matters less here.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v1 1/2] dt-bindings: hwmon: ina2xx: add supply property

In reply to Svyatoslav Ryhel
Quoted 8 lines · Svyatoslav Ryhel

8 березня 2023 р. 15:46:52 GMT+02:00, Mark Brown <[email protected]> написав(-ла):

Quoted 4 lines

If there are devices that work without any source of power at all that would be very surprising. It doesn't matter if a particular system has a non-controllable regulator, the binding should still make it mandatory to describe that.

Then question is WHY and WHO passed driver without power supply system implemented? Why it pops only now?

You are defining a supply property. When you define a supply property that supply property should be mandatory if it's physically mandatory for the device.

Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.

#14 lore raw

PATCH 2/2 hwmon: ina2xx: add optional regulator support

In reply to Svyatoslav Ryhel

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
 drivers/hwmon/ina2xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +12 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
 	long power_lsb_uW;
 	struct mutex config_lock;
 	struct regmap *regmap;
+	struct regulator *vdd_supply;
 
 	const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
 };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
 		return PTR_ERR(data->regmap);
 	}
 
+	data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+	if (IS_ERR(data->vdd_supply))
+		return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+				     "failed to get vdd regulator\n");
+
+	ret = regulator_enable(data->vdd_supply);
+	if (ret < 0) {
+		dev_err(dev, "failed to enable vdd power supply\n");
+		return ret;
+	}
+
 	ret = ina2xx_init(data);
 	if (ret < 0) {
 		dev_err(dev, "error configuring the device: %d\n", ret);
Signature · 1 line
2.37.2
#15 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

Quoted 23 lines · Svyatoslav Ryhel

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
 drivers/hwmon/ina2xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
 	long power_lsb_uW;
 	struct mutex config_lock;
 	struct regmap *regmap;
+	struct regulator *vdd_supply;
 
 	const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
 };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
 		return PTR_ERR(data->regmap);
 	}

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 10 lines
drivers/hwmon/ina2xx.c +9 -0
 
+	data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+	if (IS_ERR(data->vdd_supply))
+		return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+				     "failed to get vdd regulator\n");
+
+	ret = regulator_enable(data->vdd_supply);
+	if (ret < 0) {
+		dev_err(dev, "failed to enable vdd power supply\n");
+		return ret;

And where is disable? On each error path, removal etc.

Best regards,
Krzysztof

#16 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 24 lines

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
 drivers/hwmon/ina2xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
      long power_lsb_uW;
      struct mutex config_lock;
      struct regmap *regmap;
+     struct regulator *vdd_supply;
 
      const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
 };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
              return PTR_ERR(data->regmap);
      }
 
Quoted 12 lines

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 9 lines
drivers/hwmon/ina2xx.c +9 -0
+     data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+     if (IS_ERR(data->vdd_supply))
+             return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+                                  "failed to get vdd regulator\n");
+
+     ret = regulator_enable(data->vdd_supply);
+     if (ret < 0) {
+             dev_err(dev, "failed to enable vdd power supply\n");
+             return ret;

And where is disable? On each error path, removal etc.

error path ok, should I create a remove function just to disable the regulator?

Quoted 3 lines

Best regards,
Krzysztof

#17 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

Quoted 41 lines · Svyatoslav Ryhel

ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 24 lines

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
 drivers/hwmon/ina2xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
      long power_lsb_uW;
      struct mutex config_lock;
      struct regmap *regmap;
+     struct regulator *vdd_supply;
 
      const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
 };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
              return PTR_ERR(data->regmap);
      }
 
Quoted 12 lines

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 9 lines
drivers/hwmon/ina2xx.c +9 -0
+     data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+     if (IS_ERR(data->vdd_supply))
+             return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+                                  "failed to get vdd regulator\n");
+
+     ret = regulator_enable(data->vdd_supply);
+     if (ret < 0) {
+             dev_err(dev, "failed to enable vdd power supply\n");
+             return ret;

And where is disable? On each error path, removal etc.

Quoted 1 line

error path ok, should I create a remove function just to disable the regulator?

Unbind device. Then bind. Then unbind. Then check regulator status (/sys/kernel/debug). Do you have the answer now?

Best regards,
Krzysztof

maintainer
#18 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

In reply to Svyatoslav Ryhel
Quoted 41 lines · Svyatoslav Ryhel

ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 24 lines

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
  drivers/hwmon/ina2xx.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
       long power_lsb_uW;
       struct mutex config_lock;
       struct regmap *regmap;
+     struct regulator *vdd_supply;
 
       const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
  };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
               return PTR_ERR(data->regmap);
       }
 
Quoted 12 lines

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 9 lines
drivers/hwmon/ina2xx.c +9 -0
+     data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+     if (IS_ERR(data->vdd_supply))
+             return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+                                  "failed to get vdd regulator\n");
+
+     ret = regulator_enable(data->vdd_supply);
+     if (ret < 0) {
+             dev_err(dev, "failed to enable vdd power supply\n");
+             return ret;

And where is disable? On each error path, removal etc.

Quoted 2 lines

error path ok, should I create a remove function just to disable the regulator?

Use devm_add_action_or_reset().

Guenter

Quoted 3 lines
Quoted 3 lines

Best regards,
Krzysztof

#19 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

8 березня 2023 р. 13:13:18 GMT+02:00, Guenter Roeck <[email protected]> написав(-ла):

Quoted 42 lines · Svyatoslav Ryhel
Quoted 41 lines

ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 38 lines · Svyatoslav Ryhel
Quoted 23 lines

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
  drivers/hwmon/ina2xx.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
       long power_lsb_uW;
       struct mutex config_lock;
       struct regmap *regmap;
+     struct regulator *vdd_supply;
 
       const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
  };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
               return PTR_ERR(data->regmap);
       }

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 10 lines
drivers/hwmon/ina2xx.c +9 -0
 
+     data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+     if (IS_ERR(data->vdd_supply))
+             return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+                                  "failed to get vdd regulator\n");
+
+     ret = regulator_enable(data->vdd_supply);
+     if (ret < 0) {
+             dev_err(dev, "failed to enable vdd power supply\n");
+             return ret;

And where is disable? On each error path, removal etc.

Quoted 6 lines
Quoted 2 lines

error path ok, should I create a remove function just to disable the regulator?

Use devm_add_action_or_reset().

Guenter

That is good suggestion. Thanks!

Best regards,
Svyatoslav R.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

Best regards,
Krzysztof

#20 lore raw

Re: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support

Quoted 41 lines · Svyatoslav Ryhel

8 березня 2023 р. 13:13:18 GMT+02:00, Guenter Roeck <[email protected]> написав(-ла):

Quoted 39 lines · Svyatoslav Ryhel
Quoted 38 lines

ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 36 lines · Svyatoslav Ryhel
Quoted 23 lines

Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.

---
   drivers/hwmon/ina2xx.c | 12 ++++++++++++
   1 file changed, 12 insertions(+)
drivers/hwmon/ina2xx.c +1 -0
index 00fc70305a89..4a3e2b1bbe8b 100644
@@ -119,6 +119,7 @@ struct ina2xx_data {
        long power_lsb_uW;
        struct mutex config_lock;
        struct regmap *regmap;
+     struct regulator *vdd_supply;
 
        const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
   };
@@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client)
                return PTR_ERR(data->regmap);
        }

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client) · line 668

Quoted 10 lines
drivers/hwmon/ina2xx.c +9 -0
 
+     data->vdd_supply = devm_regulator_get_optional(dev, "vdd");
+     if (IS_ERR(data->vdd_supply))
+             return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
+                                  "failed to get vdd regulator\n");
+
+     ret = regulator_enable(data->vdd_supply);
+     if (ret < 0) {
+             dev_err(dev, "failed to enable vdd power supply\n");
+             return ret;

And where is disable? On each error path, removal etc.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

error path ok, should I create a remove function just to disable the regulator?

Use devm_add_action_or_reset().

Guenter

That is good suggestion. Thanks!

There is a new function devm_regulator_get_enable(). It will both request the regulator and enable in and then automatically disable and free it when the device is removed.

The API can be slightly confusing in this regard. In your case you also want to use the non-optional API. The optional API is for cases where you need to know whether a regulator is connected or not. If you do not need to know use the non-optional API, if no regulator is specified the regulator framework will just a return a noop regulator as a placeholder. The optional version will actually return an error if no regulator is specified, so with your patch existing users of this driver will break.