* [PATCH v2 0/3] iio: imu: inv_mpu6050: runtime pm fixes
@ 2026-04-01 8:27 Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable Andrey Skvortsov
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Andrey Skvortsov @ 2026-04-01 8:27 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
Cc: Andrey Skvortsov
This patchset fixes problem with inv_mpu6050 driver,
when it fails after device is suspended by runtime pm during a probe.
To simplify runtime pm handling in the driver more devm-helpers are used.
Andrey Skvortsov (3):
iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable
iio: imu: inv_mpu6050: control vdd supply using devm-helpers
iio: imu: inv_mpu6050: fix unbalanced regulator_disable calls, when
probe fails
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 52 ++++++++--------------
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 -
2 files changed, 18 insertions(+), 35 deletions(-)
Changes in v2:
- minimize call trace in commit message
- use runtime pm framework to track vddio regulator state
- include specific driver name in patch subject
- add more patches to use device managed functions
--
2.51.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable
2026-04-01 8:27 [PATCH v2 0/3] iio: imu: inv_mpu6050: runtime pm fixes Andrey Skvortsov
@ 2026-04-01 8:27 ` Andrey Skvortsov
2026-04-01 15:00 ` Andy Shevchenko
2026-04-01 8:27 ` [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 3/3] iio: imu: inv_mpu6050: fix unbalanced regulator_disable calls, when probe fails Andrey Skvortsov
2 siblings, 1 reply; 8+ messages in thread
From: Andrey Skvortsov @ 2026-04-01 8:27 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
Cc: Andrey Skvortsov
That allows remove driver-specific action, that does the same as
default action.
Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5796896d54cd8..84eb0ee770086 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1872,12 +1872,7 @@ static void inv_mpu_core_disable_regulator_action(void *_data)
inv_mpu_core_disable_regulator_vddio(st);
}
-static void inv_mpu_pm_disable(void *data)
-{
- struct device *dev = data;
- pm_runtime_disable(dev);
-}
int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type)
@@ -2019,13 +2014,12 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
if (result)
goto error_power_off;
pm_runtime_get_noresume(dev);
- pm_runtime_enable(dev);
+ result = devm_pm_runtime_enable(dev);
+ if (result)
+ return result;
pm_runtime_set_autosuspend_delay(dev, INV_MPU6050_SUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(dev);
pm_runtime_put(dev);
- result = devm_add_action_or_reset(dev, inv_mpu_pm_disable, dev);
- if (result)
- return result;
switch (chip_type) {
case INV_MPU6000:
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
2026-04-01 8:27 [PATCH v2 0/3] iio: imu: inv_mpu6050: runtime pm fixes Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable Andrey Skvortsov
@ 2026-04-01 8:27 ` Andrey Skvortsov
2026-04-01 15:10 ` Andy Shevchenko
2026-04-01 8:27 ` [PATCH v2 3/3] iio: imu: inv_mpu6050: fix unbalanced regulator_disable calls, when probe fails Andrey Skvortsov
2 siblings, 1 reply; 8+ messages in thread
From: Andrey Skvortsov @ 2026-04-01 8:27 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
Cc: Andrey Skvortsov
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] iio: imu: inv_mpu6050: fix unbalanced regulator_disable calls, when probe fails
2026-04-01 8:27 [PATCH v2 0/3] iio: imu: inv_mpu6050: runtime pm fixes Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers Andrey Skvortsov
@ 2026-04-01 8:27 ` Andrey Skvortsov
2 siblings, 0 replies; 8+ messages in thread
From: Andrey Skvortsov @ 2026-04-01 8:27 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
Cc: Andrey Skvortsov
During a probe functions after all regulators are enabled, runtime pm
is enabled. Before probe function finishes, runtime pm triggers and
disables vddio regulator. When probe function fails after that,
inv_mpu_core_disable_regulator_action tries to disable already
disabled by runtime pm vddio regulator causing following backtrace:
inv-mpu6050-i2c 1-0068: trigger probe fail -19
WARNING: drivers/regulator/core.c:3244 at _regulator_disable+0x2ac/0x600
Call trace:
_regulator_disable+0x2ac/0x600 (P)
regulator_disable+0xac/0x148
inv_mpu_core_disable_regulator_vddio_action+0x3c/0xb0 [inv_mpu6050]
devm_action_release+0x4c/0x88
release_nodes+0xd8/0x178
devres_release_group+0x214/0x3c8
i2c_device_probe+0x6fc/0x9b0
...
inv-mpu6050-i2c 1-0068: Failed to disable vddio regulator: -5
Fix the issue by checking runtime suspend status, when vddio regulator
is disabled. To handle this correctly pm_runtime active status has to
be set early before vddio regulator setup.
Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fixes: 07c12b1c007c ("iio: imu: mpu6050: add support for regulator framework")
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 3a57a3f440526..86e4d42c4d3d1 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1862,8 +1862,10 @@ static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st)
static void inv_mpu_core_disable_regulator_vddio_action(void *_data)
{
struct inv_mpu6050_state *st = _data;
+ struct device *dev = regmap_get_device(st->map);
- inv_mpu_core_disable_regulator_vddio(st);
+ if (!pm_runtime_status_suspended(dev))
+ inv_mpu_core_disable_regulator_vddio(st);
}
@@ -1953,6 +1955,11 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
msleep(INV_MPU6050_POWER_UP_TIME);
+ /* set pm_runtime active early for disable vddio resource cleanup */
+ result = pm_runtime_set_active(dev);
+ if (result)
+ return result;
+
result = inv_mpu_core_enable_regulator_vddio(st);
if (result)
return result;
@@ -1996,9 +2003,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
}
/* chip init is done, turning on runtime power management */
- result = pm_runtime_set_active(dev);
- if (result)
- goto error_power_off;
pm_runtime_get_noresume(dev);
result = devm_pm_runtime_enable(dev);
if (result)
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable
2026-04-01 8:27 ` [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable Andrey Skvortsov
@ 2026-04-01 15:00 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-04-01 15:00 UTC (permalink / raw)
To: Andrey Skvortsov
Cc: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
On Wed, Apr 01, 2026 at 11:27:35AM +0300, Andrey Skvortsov wrote:
> That allows remove driver-specific action, that does the same as
> default action.
Don't use the Subject as the first sentence in the explanation. Id est
always start a commit message as no Subject was ever existed.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
2026-04-01 8:27 ` [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers Andrey Skvortsov
@ 2026-04-01 15:10 ` Andy Shevchenko
2026-04-06 6:53 ` Andrey Skvortsov
0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-04-01 15:10 UTC (permalink / raw)
To: Andrey Skvortsov
Cc: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
2026-04-01 15:10 ` Andy Shevchenko
@ 2026-04-06 6:53 ` Andrey Skvortsov
2026-04-06 19:16 ` Andy Shevchenko
0 siblings, 1 reply; 8+ messages in thread
From: Andrey Skvortsov @ 2026-04-06 6:53 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel,
Jonathan Marek, Brian Masney, Rob Herring
On 26-04-01 18:10, Andy Shevchenko wrote:
> 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);
> > }
Hi, Andy,
thanks for the review.
You are right, but this variable will be added in patch 3. Do you
think it's still worth removing variable here and add it back in patch
3? If yes, I'll change it in v2.
--
Best regards,
Andrey Skvortsov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers
2026-04-06 6:53 ` Andrey Skvortsov
@ 2026-04-06 19:16 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-04-06 19:16 UTC (permalink / raw)
To: Andrey Skvortsov, Jean-Baptiste Maneyrol, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
linux-kernel, Jonathan Marek, Brian Masney, Rob Herring
On Mon, Apr 06, 2026 at 09:53:14AM +0300, Andrey Skvortsov wrote:
> On 26-04-01 18:10, Andy Shevchenko wrote:
> > On Wed, Apr 01, 2026 at 11:27:36AM +0300, Andrey Skvortsov wrote:
...
> > > -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);
> > > }
>
> thanks for the review.
> You are right, but this variable will be added in patch 3. Do you
> think it's still worth removing variable here and add it back in patch
> 3? If yes, I'll change it in v2.
Yes, we do not add a dead code. Add it when it's really being used.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-06 19:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 8:27 [PATCH v2 0/3] iio: imu: inv_mpu6050: runtime pm fixes Andrey Skvortsov
2026-04-01 8:27 ` [PATCH v2 1/3] iio: imu: inv_mpu6050: use devres-enabled version of pm_runtime_enable Andrey Skvortsov
2026-04-01 15:00 ` Andy Shevchenko
2026-04-01 8:27 ` [PATCH v2 2/3] iio: imu: inv_mpu6050: control vdd supply using devm-helpers Andrey Skvortsov
2026-04-01 15:10 ` Andy Shevchenko
2026-04-06 6:53 ` Andrey Skvortsov
2026-04-06 19:16 ` Andy Shevchenko
2026-04-01 8:27 ` [PATCH v2 3/3] iio: imu: inv_mpu6050: fix unbalanced regulator_disable calls, when probe fails Andrey Skvortsov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox