diff mbox series

[09/14] iio: humidity: hts211: Use devm_regulator_get_enable()

Message ID 20221016163409.320197-10-jic23@kernel.org (mailing list archive)
State Accepted
Headers show
Series IIO: More devm_regulator[_bulk]_get_enable() users | expand

Commit Message

Jonathan Cameron Oct. 16, 2022, 4:34 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

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>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/humidity/hts221.h      |  2 --
 drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
 2 files changed, 4 insertions(+), 25 deletions(-)

Comments

Matti Vaittinen Oct. 17, 2022, 5:53 a.m. UTC | #1
On 10/16/22 19:34, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> 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>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

> ---
>   drivers/iio/humidity/hts221.h      |  2 --
>   drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
>   2 files changed, 4 insertions(+), 25 deletions(-)
>
Lorenzo Bianconi Oct. 17, 2022, 7:11 a.m. UTC | #2
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> 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>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>

Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>

> ---
>  drivers/iio/humidity/hts221.h      |  2 --
>  drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
>  2 files changed, 4 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h
> index cf3d8d2dccd6..721359e226cb 100644
> --- a/drivers/iio/humidity/hts221.h
> +++ b/drivers/iio/humidity/hts221.h
> @@ -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;
> diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> index 517158307d8c..2a413da87b76 100644
> --- a/drivers/iio/humidity/hts221_core.c
> +++ b/drivers/iio/humidity/hts221_core.c
> @@ -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;
> -- 
> 2.37.2
>
diff mbox series

Patch

diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h
index cf3d8d2dccd6..721359e226cb 100644
--- a/drivers/iio/humidity/hts221.h
+++ b/drivers/iio/humidity/hts221.h
@@ -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;
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index 517158307d8c..2a413da87b76 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -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;