OSDN Git Service

iio: humidity: hts211: Use devm_regulator_get_enable()
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 16 Oct 2022 16:34:04 +0000 (17:34 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 23 Nov 2022 19:44:02 +0000 (19:44 +0000)
This driver only turns the power on at probe and off via a custom
devm_add_action_or_reset() callback. The new devm_regulator_get_enable()
replaces this boilerplate code.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221016163409.320197-10-jic23@kernel.org
drivers/iio/humidity/hts221.h
drivers/iio/humidity/hts221_core.c

index cf3d8d2..721359e 100644 (file)
@@ -13,7 +13,6 @@
 #define HTS221_DEV_NAME                "hts221"
 
 #include <linux/iio/iio.h>
-#include <linux/regulator/consumer.h>
 
 enum hts221_sensor_type {
        HTS221_SENSOR_H,
@@ -30,7 +29,6 @@ struct hts221_hw {
        const char *name;
        struct device *dev;
        struct regmap *regmap;
-       struct regulator *vdd;
 
        struct iio_trigger *trig;
        int irq;
index 5171583..2a413da 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/bitfield.h>
 
 #include "hts221.h"
@@ -549,33 +550,17 @@ 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;
-       }
+       err = devm_regulator_get_enable(dev, "vdd");
+       if (err)
+               return dev_err_probe(dev, err, "failed to get vdd regulator\n");
 
        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)
 {
@@ -600,10 +585,6 @@ int hts221_probe(struct device *dev, int irq, const char *name,
        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;