Skip to contentSkip to conversation

iio: Convert some drivers from deprecated UNIVERSAL_DEV_PM_OPS()

PATCH In review Jonathan Cameron 5 participants 9 messages Aug 7, 2022 – Sep 4, 2022

Subsystems (2)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover iio: Convert some drivers from deprecated UNIVERSAL_DEV_PM_OPS()

From: Jonathan Cameron <[email protected]>

During discussions of the new PM macro definitions, it because clear that UNIVERSAL_DEV_PM_OPS() generally doesn't make much sense as it can lead to unnecessary work.

For the drivers in this set I've taken a look at how the ops are used and believe we can just switch to DEFINE_RUNTIME_PM_OPS() which will only do the suspend if the device is not already runtime suspended.

I'd like some review of these (more than for the straight forward NOP conversions).

Thanks,

Jonathan

Jonathan Cameron (2):
iio: pressure: icp10100: Switch from UNIVERSAL to
DEFINE_RUNTIME_DEV_PM_OPS().
iio: temp: mlx90632: Switch form UNVIVERSAL to
DEFINE_RUNTIME_DEV_PM_OPS()

 drivers/iio/pressure/icp10100.c    | 10 +++++-----
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.37.1
author maintainer
#1 lore raw

PATCH 1/2 iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().

From: Jonathan Cameron <[email protected]>

The suspend and resume callbacks in this driver appear to be safe to call repeatedly, but why do so when we can use the DEFINE_RUNTIME_DEV_PM_OPS() macro to supply callbacks that check if we are already runtime suspended before doing unnecessary work.

Cc Jean-Baptiste Maneyrol <[email protected]>
---
 drivers/iio/pressure/icp10100.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/pressure/icp10100.c +5 -5
index af4621eaa6b5..b62f28585db5 100644
@@ -595,7 +595,7 @@ static int icp10100_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-static int __maybe_unused icp10100_suspend(struct device *dev)
+static int icp10100_suspend(struct device *dev)
 {
 	struct icp10100_state *st = iio_priv(dev_get_drvdata(dev));
 	int ret;
@@ -607,7 +607,7 @@ static int __maybe_unused icp10100_suspend(struct device *dev)
 	return ret;
 }
 
-static int __maybe_unused icp10100_resume(struct device *dev)
+static int icp10100_resume(struct device *dev)
 {
 	struct icp10100_state *st = iio_priv(dev_get_drvdata(dev));
 	int ret;
@@ -626,8 +626,8 @@ static int __maybe_unused icp10100_resume(struct device *dev)
 	return ret;
 }
 
-static UNIVERSAL_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume,
-			    NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume,
+				 NULL);
 
 static const struct of_device_id icp10100_of_match[] = {
 	{
@@ -646,7 +646,7 @@ MODULE_DEVICE_TABLE(i2c, icp10100_id);
 static struct i2c_driver icp10100_driver = {
 	.driver = {
 		.name = "icp10100",
-		.pm = &icp10100_pm,
+		.pm = pm_ptr(&icp10100_pm),
 		.of_match_table = icp10100_of_match,
 	},
 	.probe = icp10100_probe,
Signature · 1 line
2.37.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().

Hello,

looks good, thanks for the patch.

Thanks,
JB

From: Jonathan Cameron <[email protected]>
Sent: Sunday, August 7, 2022 21:04
To: [email protected] <[email protected]>
Cc: Paul Cercueil <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Crt Mori <[email protected]>; Jonathan Cameron <[email protected]>
Subject: [PATCH 1/2] iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().

[CAUTION] This is EXTERNAL email. Do not click any links or open attachments unless you recognize the sender and know the content is safe.

======================================================================
From: Jonathan Cameron <[email protected]>

The suspend and resume callbacks in this driver appear to be safe to call repeatedly, but why do so when we can use the DEFINE_RUNTIME_DEV_PM_OPS() macro to supply callbacks that check if we are already runtime suspended before doing unnecessary work.

Cc Jean-Baptiste Maneyrol <[email protected]>

---
 drivers/iio/pressure/icp10100.c | 10 +++++-----

 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/pressure/icp10100.c +0 -0
index af4621eaa6b5..b62f28585db5 100644
@@ -595,7 +595,7 @@ static int icp10100_probe(struct i2c_client *client,

         return devm_iio_device_register(&client->dev, indio_dev);
 }

-static int __maybe_unused icp10100_suspend(struct device *dev) +static int icp10100_suspend(struct device *dev)
 {
         struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); int ret;
@@ -607,7 +607,7 @@ static int __maybe_unused icp10100_suspend(struct device *dev) return ret;
 }

-static int __maybe_unused icp10100_resume(struct device *dev) +static int icp10100_resume(struct device *dev)
 {
         struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); int ret;
@@ -626,8 +626,8 @@ static int __maybe_unused icp10100_resume(struct device *dev) return ret;
 }

-static UNIVERSAL_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume, -                           NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume, +                                NULL);

 static const struct of_device_id icp10100_of_match[] = {
         {
@@ -646,7 +646,7 @@ MODULE_DEVICE_TABLE(i2c, icp10100_id);
 static struct i2c_driver icp10100_driver = {
         .driver = {
                 .name = "icp10100",
-               .pm = &icp10100_pm,
+               .pm = pm_ptr(&icp10100_pm),
                 .of_match_table = icp10100_of_match,
         },
         .probe = icp10100_probe,

Signature · 1 line
2.37.1
author maintainer Applied
#3 lore raw

Re: [PATCH 1/2] iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().

Quoted 5 lines · On Tue, 16 Aug 2022 13:13:52 +0000 Jean-Baptiste Maneyrol…

Hello,

looks good, thanks for the patch.

Applied

Quoted 69 lines

Thanks,
JB

From: Jonathan Cameron <[email protected]>
Sent: Sunday, August 7, 2022 21:04
To: [email protected] <[email protected]>
Cc: Paul Cercueil <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Crt Mori <[email protected]>; Jonathan Cameron <[email protected]>
Subject: [PATCH 1/2] iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().
_
[CAUTION] This is EXTERNAL email. Do not click any links or open attachments unless you recognize the sender and know the content is safe.

======================================================================
From: Jonathan Cameron <[email protected]>

The suspend and resume callbacks in this driver appear to be safe to call repeatedly, but why do so when we can use the DEFINE_RUNTIME_DEV_PM_OPS() macro to supply callbacks that check if we are already runtime suspended before doing unnecessary work.

Cc Jean-Baptiste Maneyrol <[email protected]>

---
_drivers/iio/pressure/icp10100.c | 10 +++++-----
_1 file changed, 5 insertions(+), 5 deletions(-)

drivers/iio/pressure/icp10100.c +0 -0
index af4621eaa6b5..b62f28585db5 100644
@@ -595,7 +595,7 @@ static int icp10100_probe(struct i2c_client *client,
 ________ return devm_iio_device_register(&client->dev, indio_dev);
 _}

_

drivers/iio/pressure/icp10100.c +1 -1
-static int __maybe_unused icp10100_suspend(struct device *dev)
+static int icp10100_suspend(struct device *dev)

_{
________ struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); ________ int ret;

drivers/iio/pressure/icp10100.c +0 -0
@@ -607,7 +607,7 @@ static int __maybe_unused icp10100_suspend(struct device *dev)
 ________ return ret;
 _}

_

drivers/iio/pressure/icp10100.c +1 -1
-static int __maybe_unused icp10100_resume(struct device *dev)
+static int icp10100_resume(struct device *dev)

_{
________ struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); ________ int ret;

drivers/iio/pressure/icp10100.c +0 -0
@@ -626,8 +626,8 @@ static int __maybe_unused icp10100_resume(struct device *dev)
 ________ return ret;
 _}

_

drivers/iio/pressure/icp10100.c +2 -2
-static UNIVERSAL_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume,
-__________________________ NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume,
+_______________________________ NULL);

_
_static const struct of_device_id icp10100_of_match[] = { ________ {

drivers/iio/pressure/icp10100.c +1 -1
@@ -646,7 +646,7 @@ MODULE_DEVICE_TABLE(i2c, icp10100_id);
 _static struct i2c_driver icp10100_driver = {
 ________ .driver = {
 ________________ .name = "icp10100",
-______________ .pm = &icp10100_pm,
+______________ .pm = pm_ptr(&icp10100_pm),
 ________________ .of_match_table = icp10100_of_match,
 ________ },
 ________ .probe = icp10100_probe,
author maintainer
#4 lore raw

PATCH 2/2 iio: temp: mlx90632: Switch form UNVIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

The callbacks in this driver are simple and it doesn't matter if they are unnecessarily called multiple times. However, we might as well not repeat the effort if the device is already suspended. The new DEFINE_RUNTIME_DEV_PM_OPS() has the advantage that we don't need to mark the callbacks __maybe_unused. The compiler will still remove them for us if CONFIG_PM is not set.

---
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/temperature/mlx90632.c +5 -5
index 7ee7ff8047a4..9fc69d099784 100644
@@ -952,7 +952,7 @@ static const struct of_device_id mlx90632_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mlx90632_of_match);
 
-static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
+static int mlx90632_pm_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mlx90632_data *data = iio_priv(indio_dev);
@@ -960,7 +960,7 @@ static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
 	return mlx90632_sleep(data);
 }
 
-static int __maybe_unused mlx90632_pm_resume(struct device *dev)
+static int mlx90632_pm_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mlx90632_data *data = iio_priv(indio_dev);
@@ -968,14 +968,14 @@ static int __maybe_unused mlx90632_pm_resume(struct device *dev)
 	return mlx90632_wakeup(data);
 }
 
-static UNIVERSAL_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
-			    mlx90632_pm_resume, NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
+				 mlx90632_pm_resume, NULL);
 
 static struct i2c_driver mlx90632_driver = {
 	.driver = {
 		.name	= "mlx90632",
 		.of_match_table = mlx90632_of_match,
-		.pm	= &mlx90632_pm_ops,
+		.pm	= pm_ptr(&mlx90632_pm_ops),
 	},
 	.probe = mlx90632_probe,
 	.remove = mlx90632_remove,
Signature · 1 line
2.37.1
maintainer Acked-by Tested-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] iio: temp: mlx90632: Switch form UNVIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS()

Not sure if I should apply both but:

Quoted 59 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

The callbacks in this driver are simple and it doesn't matter if they are unnecessarily called multiple times. However, we might as well not repeat the effort if the device is already suspended. The new DEFINE_RUNTIME_DEV_PM_OPS() has the advantage that we don't need to mark the callbacks __maybe_unused. The compiler will still remove them for us if CONFIG_PM is not set.

---
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/temperature/mlx90632.c +5 -6
index 7ee7ff8047a4..9fc69d099784 100644
@@ -952,7 +952,7 @@ static const struct of_device_id mlx90632_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mlx90632_of_match);
 
-static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
+static int mlx90632_pm_suspend(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -960,7 +960,7 @@ static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
        return mlx90632_sleep(data);
 }
 
-static int __maybe_unused mlx90632_pm_resume(struct device *dev)
+static int mlx90632_pm_resume(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -968,14 +968,14 @@ static int __maybe_unused mlx90632_pm_resume(struct device *dev)
        return mlx90632_wakeup(data);
 }
 
-static UNIVERSAL_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
-                           mlx90632_pm_resume, NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
+                                mlx90632_pm_resume, NULL);
 
 static struct i2c_driver mlx90632_driver = {
        .driver = {
                .name   = "mlx90632",
                .of_match_table = mlx90632_of_match,
-               .pm     = &mlx90632_pm_ops,
+               .pm     = pm_ptr(&mlx90632_pm_ops),
        },
        .probe = mlx90632_probe,
        .remove = mlx90632_remove,
--

2.37.1

#6 lore raw

Re: [PATCH 2/2] iio: temp: mlx90632: Switch form UNVIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS()

Quoted 4 lines · On Mon, 8 Aug 2022 13:26:42 +0200 Crt Mori <[email protected]> wrote:

Not sure if I should apply both but:

Absolutely. Both is perfect. Thanks!

Quoted 62 lines · Jonathan Cameron
Quoted 59 lines

From: Jonathan Cameron <[email protected]>

The callbacks in this driver are simple and it doesn't matter if they are unnecessarily called multiple times. However, we might as well not repeat the effort if the device is already suspended. The new DEFINE_RUNTIME_DEV_PM_OPS() has the advantage that we don't need to mark the callbacks __maybe_unused. The compiler will still remove them for us if CONFIG_PM is not set.

---
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/temperature/mlx90632.c +5 -6
index 7ee7ff8047a4..9fc69d099784 100644
@@ -952,7 +952,7 @@ static const struct of_device_id mlx90632_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mlx90632_of_match);
 
-static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
+static int mlx90632_pm_suspend(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -960,7 +960,7 @@ static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
        return mlx90632_sleep(data);
 }
 
-static int __maybe_unused mlx90632_pm_resume(struct device *dev)
+static int mlx90632_pm_resume(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -968,14 +968,14 @@ static int __maybe_unused mlx90632_pm_resume(struct device *dev)
        return mlx90632_wakeup(data);
 }
 
-static UNIVERSAL_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
-                           mlx90632_pm_resume, NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
+                                mlx90632_pm_resume, NULL);
 
 static struct i2c_driver mlx90632_driver = {
        .driver = {
                .name   = "mlx90632",
                .of_match_table = mlx90632_of_match,
-               .pm     = &mlx90632_pm_ops,
+               .pm     = pm_ptr(&mlx90632_pm_ops),
        },
        .probe = mlx90632_probe,
        .remove = mlx90632_remove,
--

2.37.1

author maintainer
#7 lore raw

Re: [PATCH 2/2] iio: temp: mlx90632: Switch form UNVIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS()

Quoted 8 lines · On Thu, 11 Aug 2022 15:18:34 +0100 Jonathan Cameron…
Quoted 4 lines · On Mon, 8 Aug 2022 13:26:42 +0200 Crt Mori <[email protected]> wrote:

Not sure if I should apply both but:

Absolutely. Both is perfect. Thanks!

Given I forgot to pick this up and your set is moving towards being merged, I'll not bother with this one.

Jonathan

Quoted 63 lines
Quoted 62 lines · Jonathan Cameron
Quoted 59 lines

From: Jonathan Cameron <[email protected]>

The callbacks in this driver are simple and it doesn't matter if they are unnecessarily called multiple times. However, we might as well not repeat the effort if the device is already suspended. The new DEFINE_RUNTIME_DEV_PM_OPS() has the advantage that we don't need to mark the callbacks __maybe_unused. The compiler will still remove them for us if CONFIG_PM is not set.

---
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/temperature/mlx90632.c +5 -6
index 7ee7ff8047a4..9fc69d099784 100644
@@ -952,7 +952,7 @@ static const struct of_device_id mlx90632_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mlx90632_of_match);
 
-static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
+static int mlx90632_pm_suspend(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -960,7 +960,7 @@ static int __maybe_unused mlx90632_pm_suspend(struct device *dev)
        return mlx90632_sleep(data);
 }
 
-static int __maybe_unused mlx90632_pm_resume(struct device *dev)
+static int mlx90632_pm_resume(struct device *dev)
 {
        struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
        struct mlx90632_data *data = iio_priv(indio_dev);
@@ -968,14 +968,14 @@ static int __maybe_unused mlx90632_pm_resume(struct device *dev)
        return mlx90632_wakeup(data);
 }
 
-static UNIVERSAL_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
-                           mlx90632_pm_resume, NULL);
+static DEFINE_RUNTIME_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend,
+                                mlx90632_pm_resume, NULL);
 
 static struct i2c_driver mlx90632_driver = {
        .driver = {
                .name   = "mlx90632",
                .of_match_table = mlx90632_of_match,
-               .pm     = &mlx90632_pm_ops,
+               .pm     = pm_ptr(&mlx90632_pm_ops),
        },
        .probe = mlx90632_probe,
        .remove = mlx90632_remove,
--

2.37.1

Reviewed-by on the v1 series
#8 lore raw
In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

During discussions of the new PM macro definitions, it because clear that UNIVERSAL_DEV_PM_OPS() generally doesn't make much sense as it can lead to unnecessary work.

Quoted 5 lines

For the drivers in this set I've taken a look at how the ops are used and believe we can just switch to DEFINE_RUNTIME_PM_OPS() which will only do the suspend if the device is not already runtime suspended.

I'd like some review of these (more than for the straight forward NOP conversions).

Quoted 18 lines

Thanks,

Jonathan

Jonathan Cameron (2):
iio: pressure: icp10100: Switch from UNIVERSAL to
DEFINE_RUNTIME_DEV_PM_OPS().
iio: temp: mlx90632: Switch form UNVIVERSAL to
DEFINE_RUNTIME_DEV_PM_OPS()

 drivers/iio/pressure/icp10100.c    | 10 +++++-----
 drivers/iio/temperature/mlx90632.c | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

--
2.37.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko