diff mbox series

[v3,09/14] iio: st_lsm6dsx: Simplify using devm_regulator_*get_enable()

Message ID 876e58428cec056d51070e49eff559e2d7c23b12.1660934107.git.mazziesaccount@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series Use devm helpers for regulator get and enable | expand

Commit Message

Matti Vaittinen Aug. 19, 2022, 7:19 p.m. UTC
Use devm_regulator_bulk_get_enable() instead of open coded bulk-get,
bulk-enable, add-action-to-disable-at-detach - pattern.

A functional change (which seems like a bugfix) is that if
regulator_bulk_get fails, the enable is not attempted.

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

---
v2 => v3
Split to own patch.
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  2 --
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 ++++----------------
 2 files changed, 5 insertions(+), 27 deletions(-)

Comments

Jonathan Cameron Oct. 16, 2022, 4:11 p.m. UTC | #1
On Fri, 19 Aug 2022 22:19:46 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> Use devm_regulator_bulk_get_enable() instead of open coded bulk-get,
> bulk-enable, add-action-to-disable-at-detach - pattern.
> 
> A functional change (which seems like a bugfix) is that if
> regulator_bulk_get fails, the enable is not attempted.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>

Applied with similar ordering, patch naming and spacing tweaks to earlier patches.

> 
> ---
> v2 => v3
> Split to own patch.
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  2 --
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 ++++----------------
>  2 files changed, 5 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index a86dd29a4738..03238c64c777 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -372,7 +372,6 @@ struct st_lsm6dsx_sensor {
>   * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
>   * @dev: Pointer to instance of struct device (I2C or SPI).
>   * @regmap: Register map of the device.
> - * @regulators: VDD/VDDIO voltage regulators.
>   * @irq: Device interrupt line (I2C or SPI).
>   * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
>   * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
> @@ -395,7 +394,6 @@ struct st_lsm6dsx_sensor {
>  struct st_lsm6dsx_hw {
>  	struct device *dev;
>  	struct regmap *regmap;
> -	struct regulator_bulk_data regulators[2];
>  	int irq;
>  
>  	struct mutex fifo_lock;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index b5e4a4113652..c328d1a36d34 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2172,36 +2172,20 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  
>  static int st_lsm6dsx_init_regulators(struct device *dev)
>  {
> -	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
>  	int err;
> -
>  	/* vdd-vddio power regulators */
> -	hw->regulators[0].supply = "vdd";
> -	hw->regulators[1].supply = "vddio";
> -	err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators),
> -				      hw->regulators);
> -	if (err)
> -		return dev_err_probe(dev, err, "failed to get regulators\n");
> +	static const char * const regulators[] = {"vdd", "vddio"};
>  
> -	err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators),
> -				    hw->regulators);
> -	if (err) {
> -		dev_err(dev, "failed to enable regulators: %d\n", err);
> -		return err;
> -	}
> +	err = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
> +					     regulators);
> +	if (err)
> +		return dev_err_probe(dev, err, "failed to enable regulators\n");
>  
>  	msleep(50);
>  
>  	return 0;
>  }
>  
> -static void st_lsm6dsx_chip_uninit(void *data)
> -{
> -	struct st_lsm6dsx_hw *hw = data;
> -
> -	regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators);
> -}
> -
>  int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
>  		     struct regmap *regmap)
>  {
> @@ -2225,10 +2209,6 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
>  	if (err)
>  		return err;
>  
> -	err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw);
> -	if (err)
> -		return err;
> -
>  	hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL);
>  	if (!hw->buff)
>  		return -ENOMEM;
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index a86dd29a4738..03238c64c777 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -372,7 +372,6 @@  struct st_lsm6dsx_sensor {
  * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
  * @dev: Pointer to instance of struct device (I2C or SPI).
  * @regmap: Register map of the device.
- * @regulators: VDD/VDDIO voltage regulators.
  * @irq: Device interrupt line (I2C or SPI).
  * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
  * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
@@ -395,7 +394,6 @@  struct st_lsm6dsx_sensor {
 struct st_lsm6dsx_hw {
 	struct device *dev;
 	struct regmap *regmap;
-	struct regulator_bulk_data regulators[2];
 	int irq;
 
 	struct mutex fifo_lock;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index b5e4a4113652..c328d1a36d34 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2172,36 +2172,20 @@  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 
 static int st_lsm6dsx_init_regulators(struct device *dev)
 {
-	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
 	int err;
-
 	/* vdd-vddio power regulators */
-	hw->regulators[0].supply = "vdd";
-	hw->regulators[1].supply = "vddio";
-	err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators),
-				      hw->regulators);
-	if (err)
-		return dev_err_probe(dev, err, "failed to get regulators\n");
+	static const char * const regulators[] = {"vdd", "vddio"};
 
-	err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators),
-				    hw->regulators);
-	if (err) {
-		dev_err(dev, "failed to enable regulators: %d\n", err);
-		return err;
-	}
+	err = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
+					     regulators);
+	if (err)
+		return dev_err_probe(dev, err, "failed to enable regulators\n");
 
 	msleep(50);
 
 	return 0;
 }
 
-static void st_lsm6dsx_chip_uninit(void *data)
-{
-	struct st_lsm6dsx_hw *hw = data;
-
-	regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators);
-}
-
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap)
 {
@@ -2225,10 +2209,6 @@  int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 	if (err)
 		return err;
 
-	err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw);
-	if (err)
-		return err;
-
 	hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL);
 	if (!hw->buff)
 		return -ENOMEM;