]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: humidity: hts221: add vdd voltage regulator
authorLorenzo Bianconi <lorenzo@kernel.org>
Sun, 22 Nov 2020 11:56:48 +0000 (12:56 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 3 Dec 2020 19:32:39 +0000 (19:32 +0000)
Like all other ST sensors, hts221 devices have VDD power line.
Introduce VDD voltage regulator to control it.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/6b3347e78f4f920c48eb6a66936d3b69cb9ff53a.1606045688.git.lorenzo@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/humidity/hts221.h
drivers/iio/humidity/hts221_core.c

index 721359e226cb97f7df1c32ad5ddfa20913d82592..cf3d8d2dccd6bd402a35d6be74f1718dd24bcf4b 100644 (file)
@@ -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;
index 16657789dc457552c110aa7427000cb5e4dead76..6a39615b696114cd43d486465ed6f944c08406a8 100644 (file)
@@ -547,6 +547,35 @@ 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))
+               return dev_err_probe(dev, PTR_ERR(hw->vdd),
+                                    "failed to get vdd regulator\n");
+
+       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 +596,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;