Skip to contentSkip to conversation

hts221: add vdd power regulator

PATCH Superseded Lorenzo Bianconi 2 participants 5 messages Nov 19, 2020 – Nov 21, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lorenzo Bianconi

author maintainer
#0 lore raw

cover hts221: add vdd power regulator

Introduce support to control VDD power line available on hts221 devices

Lorenzo Bianconi (2):
iio: humidity: hts221: add vdd voltage regulator
dt-bindings: iio: humidity: hts221: introduce vdd regulator bindings

 .../bindings/iio/humidity/st,hts221.yaml      |  3 ++
 drivers/iio/humidity/hts221.h                 |  2 +
 drivers/iio/humidity/hts221_core.c            | 39 +++++++++++++++++++
 3 files changed, 44 insertions(+)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/2 iio: humidity: hts221: add vdd voltage regulator

Like all other ST sensors, hts221 devices have VDD power line. Introduce VDD voltage regulator to control it.

---
 drivers/iio/humidity/hts221.h      |  2 ++
 drivers/iio/humidity/hts221_core.c | 39 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/iio/humidity/hts221.h +2 -0
index 721359e226cb..cf3d8d2dccd6 100644
@@ -13,6 +13,7 @@
 #define HTS221_DEV_NAME		"hts221"
 
 #include <linux/iio/iio.h>
+#include <linux/regulator/consumer.h>
 
 enum hts221_sensor_type {
 	HTS221_SENSOR_H,
@@ -29,6 +30,7 @@ struct hts221_hw {
 	const char *name;
 	struct device *dev;
 	struct regmap *regmap;
+	struct regulator *vdd;
 
 	struct iio_trigger *trig;
 	int irq;
drivers/iio/humidity/hts221_core.c +39 -0
index 16657789dc45..e1aa99dcf142 100644
@@ -547,6 +547,37 @@ static const struct iio_info hts221_info = {
 
 static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
 
+static int hts221_init_regulators(struct device *dev)
+{
+	struct iio_dev *iio_dev = dev_get_drvdata(dev);
+	struct hts221_hw *hw = iio_priv(iio_dev);
+	int err;
+
+	hw->vdd = devm_regulator_get(dev, "vdd");
+	if (IS_ERR(hw->vdd)) {
+		dev_err(dev, "failed to get vdd regulator: %ld\n",
+			PTR_ERR(hw->vdd));
+		return PTR_ERR(hw->vdd);
+	}
+
+	err = regulator_enable(hw->vdd);
+	if (err) {
+		dev_err(dev, "failed to enable vdd regulator: %d\n", err);
+		return err;
+	}
+
+	msleep(50);
+
+	return 0;
+}
+
+static void hts221_chip_uninit(void *data)
+{
+	struct hts221_hw *hw = data;
+
+	regulator_disable(hw->vdd);
+}
+
 int hts221_probe(struct device *dev, int irq, const char *name,
 		 struct regmap *regmap)
 {
@@ -567,6 +598,14 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 	hw->irq = irq;
 	hw->regmap = regmap;
 
+	err = hts221_init_regulators(dev);
+	if (err)
+		return err;
+
+	err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw);
+	if (err)
+		return err;
+
 	err = hts221_check_whoami(hw);
 	if (err < 0)
 		return err;
Signature · 1 line
2.26.2
maintainer
#2 lore raw

Re: [PATCH 1/2] iio: humidity: hts221: add vdd voltage regulator

Quoted 4 lines · On Thu, 19 Nov 2020 10:13:34 +0100 Lorenzo Bianconi <[email protected]> wrote:

Like all other ST sensors, hts221 devices have VDD power line. Introduce VDD voltage regulator to control it.

Hi Lorenzo,

Minor thing about not printing error message is the deferred case. Otherwise, looks good to me

Thanks,

Jonathan

Quoted 33 lines
---
 drivers/iio/humidity/hts221.h      |  2 ++
 drivers/iio/humidity/hts221_core.c | 39 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/iio/humidity/hts221.h +2 -0
index 721359e226cb..cf3d8d2dccd6 100644
@@ -13,6 +13,7 @@
 #define HTS221_DEV_NAME		"hts221"
 
 #include <linux/iio/iio.h>
+#include <linux/regulator/consumer.h>
 
 enum hts221_sensor_type {
 	HTS221_SENSOR_H,
@@ -29,6 +30,7 @@ struct hts221_hw {
 	const char *name;
 	struct device *dev;
 	struct regmap *regmap;
+	struct regulator *vdd;
 
 	struct iio_trigger *trig;
 	int irq;
drivers/iio/humidity/hts221_core.c +0 -0
index 16657789dc45..e1aa99dcf142 100644
@@ -547,6 +547,37 @@ static const struct iio_info hts221_info = {
 
 static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
 

drivers/iio/humidity/hts221_core.c static const struct iio_info hts221_info = { · line 559

Quoted 10 lines
drivers/iio/humidity/hts221_core.c +10 -0
+static int hts221_init_regulators(struct device *dev)
+{
+	struct iio_dev *iio_dev = dev_get_drvdata(dev);
+	struct hts221_hw *hw = iio_priv(iio_dev);
+	int err;
+
+	hw->vdd = devm_regulator_get(dev, "vdd");
+	if (IS_ERR(hw->vdd)) {
+		dev_err(dev, "failed to get vdd regulator: %ld\n",
+			PTR_ERR(hw->vdd));

dev_err_probe on this as I would assume we want to not print the message on deferred response.

Quoted 39 lines
drivers/iio/humidity/hts221_core.c +29 -0
+		return PTR_ERR(hw->vdd);
+	}
+
+	err = regulator_enable(hw->vdd);
+	if (err) {
+		dev_err(dev, "failed to enable vdd regulator: %d\n", err);
+		return err;
+	}
+
+	msleep(50);
+
+	return 0;
+}
+
+static void hts221_chip_uninit(void *data)
+{
+	struct hts221_hw *hw = data;
+
+	regulator_disable(hw->vdd);
+}
+
 int hts221_probe(struct device *dev, int irq, const char *name,
 		 struct regmap *regmap)
 {
@@ -567,6 +598,14 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 	hw->irq = irq;
 	hw->regmap = regmap;
 
+	err = hts221_init_regulators(dev);
+	if (err)
+		return err;
+
+	err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw);
+	if (err)
+		return err;
+
 	err = hts221_check_whoami(hw);
 	if (err < 0)
 		return err;
author maintainer
#3 lore raw

PATCH 2/2 dt-bindings: iio: humidity: hts221: introduce vdd regulator bindings

In reply to Lorenzo Bianconi
---
 Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml +3 -0
index 396451c26728..53df083b3de6 100644
@@ -26,6 +26,9 @@ properties:
       The interrupt/data ready line will be configured as open drain, which
       is useful if several sensors share the same interrupt line.
 
+  vdd-supply:
+    description: if defined provides VDD power to the sensor.
+
   interrupts:
     maxItems: 1
 
Signature · 1 line
2.26.2
maintainer
#4 lore raw

Re: [PATCH 2/2] dt-bindings: iio: humidity: hts221: introduce vdd regulator bindings

Quoted 1 line · On Thu, 19 Nov 2020 10:13:35 +0100 Lorenzo Bianconi <[email protected]> wrote:

I'd drop the description as kind of obvious.

vdd-supply: true

will work fine.

Thanks,

Jonathan

Quoted 18 lines
---
 Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml +3 -0
index 396451c26728..53df083b3de6 100644
@@ -26,6 +26,9 @@ properties:
       The interrupt/data ready line will be configured as open drain, which
       is useful if several sensors share the same interrupt line.
 
+  vdd-supply:
+    description: if defined provides VDD power to the sensor.
+
   interrupts:
     maxItems: 1