[PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers

Andrey Skvortsov posted 3 patches 13 hours ago
[PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
Posted by Andrey Skvortsov 13 hours ago
vdd supply will be automatically disabled on error condition during a
probe and on driver cleanup. Since the vdd handling is moved to
devm-helpers, only vddio regulator has to be disabled in the
driver-specific cleanup action.

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 28 ++++++----------------
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  1 -
 2 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 84eb0ee770086..3a57a3f440526 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1859,15 +1859,9 @@ static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st)
 	return result;
 }
 
-static void inv_mpu_core_disable_regulator_action(void *_data)
+static void inv_mpu_core_disable_regulator_vddio_action(void *_data)
 {
 	struct inv_mpu6050_state *st = _data;
-	int result;
-
-	result = regulator_disable(st->vdd_supply);
-	if (result)
-		dev_err(regmap_get_device(st->map),
-			"Failed to disable vdd regulator: %d\n", result);
 
 	inv_mpu_core_disable_regulator_vddio(st);
 }
@@ -1948,30 +1942,22 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 
 	device_set_wakeup_capable(dev, true);
 
-	st->vdd_supply = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(st->vdd_supply))
-		return dev_err_probe(dev, PTR_ERR(st->vdd_supply),
-				     "Failed to get vdd regulator\n");
-
 	st->vddio_supply = devm_regulator_get(dev, "vddio");
 	if (IS_ERR(st->vddio_supply))
 		return dev_err_probe(dev, PTR_ERR(st->vddio_supply),
 				     "Failed to get vddio regulator\n");
 
-	result = regulator_enable(st->vdd_supply);
-	if (result) {
-		dev_err(dev, "Failed to enable vdd regulator: %d\n", result);
-		return result;
-	}
+	result = devm_regulator_get_enable(dev, "vdd");
+	if (result)
+		return dev_err_probe(dev, result, "Failed to enable vdd regulator\n");
+
 	msleep(INV_MPU6050_POWER_UP_TIME);
 
 	result = inv_mpu_core_enable_regulator_vddio(st);
-	if (result) {
-		regulator_disable(st->vdd_supply);
+	if (result)
 		return result;
-	}
 
-	result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_action,
+	result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_vddio_action,
 				 st);
 	if (result) {
 		dev_err(dev, "Failed to setup regulator cleanup action %d\n",
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 6239b1a803f77..2c0cf53c9a627 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -206,7 +206,6 @@ struct inv_mpu6050_state {
 	u8 irq_mask;
 	unsigned skip_samples;
 	struct inv_sensors_timestamp timestamp;
-	struct regulator *vdd_supply;
 	struct regulator *vddio_supply;
 	bool magn_disabled;
 	s32 magn_raw_to_gauss[3];
-- 
2.51.0
Re: [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
Posted by Andy Shevchenko 7 hours ago
On Wed, Apr 01, 2026 at 11:27:36AM +0300, Andrey Skvortsov wrote:
> vdd supply will be automatically disabled on error condition during a
> probe and on driver cleanup. Since the vdd handling is moved to
> devm-helpers, only vddio regulator has to be disabled in the
> driver-specific cleanup action.

...

> -static void inv_mpu_core_disable_regulator_action(void *_data)
> +static void inv_mpu_core_disable_regulator_vddio_action(void *_data)

You can rename now _data --> st...

>  {
>  	struct inv_mpu6050_state *st = _data;

...and drop this.

>  	inv_mpu_core_disable_regulator_vddio(st);
>  }

...

> -	st->vdd_supply = devm_regulator_get(dev, "vdd");
> -	if (IS_ERR(st->vdd_supply))
> -		return dev_err_probe(dev, PTR_ERR(st->vdd_supply),
> -				     "Failed to get vdd regulator\n");
> -
>  	st->vddio_supply = devm_regulator_get(dev, "vddio");
>  	if (IS_ERR(st->vddio_supply))
>  		return dev_err_probe(dev, PTR_ERR(st->vddio_supply),
>  				     "Failed to get vddio regulator\n");
>  
> -	result = regulator_enable(st->vdd_supply);
> -	if (result) {
> -		dev_err(dev, "Failed to enable vdd regulator: %d\n", result);
> -		return result;
> -	}
> +	result = devm_regulator_get_enable(dev, "vdd");
> +	if (result)
> +		return dev_err_probe(dev, result, "Failed to enable vdd regulator\n");

I'm not that expert in regulator framework, but this change might be sensitive.
I dunno if regulator is exclusive or shared and if order of requesting may affect
anything. Just needs careful review from somebody more familiar with that.

-- 
With Best Regards,
Andy Shevchenko