diff mbox series

[05/14] iio: accel: msa311: Use devm_regulator_get_enable()

Message ID 20221016163409.320197-6-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: Dmitry Rokosov <DDRokosov@sberdevices.ru>
---
 drivers/iio/accel/msa311.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

Comments

Dmitry Rokosov Oct. 18, 2022, 3:14 p.m. UTC | #1
Hello Jonathan,

Thank you for the patch! The current devm_regulator_get_enable() looks
much easier to read!

On Sun, Oct 16, 2022 at 05:34:00PM +0100, 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: Dmitry Rokosov <DDRokosov@sberdevices.ru>
> ---
>  drivers/iio/accel/msa311.c | 21 ++-------------------
>  1 file changed, 2 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/accel/msa311.c b/drivers/iio/accel/msa311.c
> index 2fded3759171..af94d3adf6d8 100644
> --- a/drivers/iio/accel/msa311.c
> +++ b/drivers/iio/accel/msa311.c
> @@ -351,7 +351,6 @@ static const struct regmap_config msa311_regmap_config = {
>   * @chip_name: Chip name in the format "msa311-%02x" % partid
>   * @new_data_trig: Optional NEW_DATA interrupt driven trigger used
>   *                 to notify external consumers a new sample is ready
> - * @vdd: Optional external voltage regulator for the device power supply
>   */
>  struct msa311_priv {
>  	struct regmap *regs;
> @@ -362,7 +361,6 @@ struct msa311_priv {
>  	char *chip_name;
>  
>  	struct iio_trigger *new_data_trig;
> -	struct regulator *vdd;
>  };
>  
>  enum msa311_si {
> @@ -1146,11 +1144,6 @@ static void msa311_powerdown(void *msa311)
>  	msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND);
>  }
>  
> -static void msa311_vdd_disable(void *vdd)
> -{
> -	regulator_disable(vdd);
> -}
> -
>  static int msa311_probe(struct i2c_client *i2c)
>  {
>  	struct device *dev = &i2c->dev;
> @@ -1173,19 +1166,9 @@ static int msa311_probe(struct i2c_client *i2c)
>  
>  	mutex_init(&msa311->lock);
>  
> -	msa311->vdd = devm_regulator_get(dev, "vdd");
> -	if (IS_ERR(msa311->vdd))
> -		return dev_err_probe(dev, PTR_ERR(msa311->vdd),
> -				     "can't get vdd supply\n");
> -
> -	err = regulator_enable(msa311->vdd);
> +	err = devm_regulator_get_enable(dev, "vdd");
>  	if (err)
> -		return dev_err_probe(dev, err, "can't enable vdd supply\n");
> -
> -	err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd);
> -	if (err)
> -		return dev_err_probe(dev, err,
> -				     "can't add vdd disable action\n");
> +		return dev_err_probe(dev, err, "can't get vdd supply\n");
>  
>  	err = msa311_check_partid(msa311);
>  	if (err)
> -- 
> 2.37.2
> 

Reviewed-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
diff mbox series

Patch

diff --git a/drivers/iio/accel/msa311.c b/drivers/iio/accel/msa311.c
index 2fded3759171..af94d3adf6d8 100644
--- a/drivers/iio/accel/msa311.c
+++ b/drivers/iio/accel/msa311.c
@@ -351,7 +351,6 @@  static const struct regmap_config msa311_regmap_config = {
  * @chip_name: Chip name in the format "msa311-%02x" % partid
  * @new_data_trig: Optional NEW_DATA interrupt driven trigger used
  *                 to notify external consumers a new sample is ready
- * @vdd: Optional external voltage regulator for the device power supply
  */
 struct msa311_priv {
 	struct regmap *regs;
@@ -362,7 +361,6 @@  struct msa311_priv {
 	char *chip_name;
 
 	struct iio_trigger *new_data_trig;
-	struct regulator *vdd;
 };
 
 enum msa311_si {
@@ -1146,11 +1144,6 @@  static void msa311_powerdown(void *msa311)
 	msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND);
 }
 
-static void msa311_vdd_disable(void *vdd)
-{
-	regulator_disable(vdd);
-}
-
 static int msa311_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
@@ -1173,19 +1166,9 @@  static int msa311_probe(struct i2c_client *i2c)
 
 	mutex_init(&msa311->lock);
 
-	msa311->vdd = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(msa311->vdd))
-		return dev_err_probe(dev, PTR_ERR(msa311->vdd),
-				     "can't get vdd supply\n");
-
-	err = regulator_enable(msa311->vdd);
+	err = devm_regulator_get_enable(dev, "vdd");
 	if (err)
-		return dev_err_probe(dev, err, "can't enable vdd supply\n");
-
-	err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd);
-	if (err)
-		return dev_err_probe(dev, err,
-				     "can't add vdd disable action\n");
+		return dev_err_probe(dev, err, "can't get vdd supply\n");
 
 	err = msa311_check_partid(msa311);
 	if (err)