[PATCH 09/38] mmc: cb710-mmc: use modern PM macros

Jisheng Zhang posted 38 patches 1 month, 2 weeks ago
[PATCH 09/38] mmc: cb710-mmc: use modern PM macros
Posted by Jisheng Zhang 1 month, 2 weeks ago
Use the modern PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

At the same time, replace the platform_driver's .suspend and .resume
usage with modern device_driver's .pm usage.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 drivers/mmc/host/cb710-mmc.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/host/cb710-mmc.c b/drivers/mmc/host/cb710-mmc.c
index 448d2f9159ea..31daec787495 100644
--- a/drivers/mmc/host/cb710-mmc.c
+++ b/drivers/mmc/host/cb710-mmc.c
@@ -664,25 +664,25 @@ static const struct mmc_host_ops cb710_mmc_host = {
 	.get_cd = cb710_mmc_get_cd,
 };
 
-#ifdef CONFIG_PM
-
-static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
+static int cb710_mmc_suspend(struct device *dev)
 {
+	struct platform_device *pdev = to_platform_device(dev);
 	struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
 
 	cb710_mmc_enable_irq(slot, 0, ~0);
 	return 0;
 }
 
-static int cb710_mmc_resume(struct platform_device *pdev)
+static int cb710_mmc_resume(struct device *dev)
 {
+	struct platform_device *pdev = to_platform_device(dev);
 	struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
 
 	cb710_mmc_enable_irq(slot, 0, ~0);
 	return 0;
 }
 
-#endif /* CONFIG_PM */
+static DEFINE_SIMPLE_DEV_PM_OPS(cb710_mmc_pmops, cb710_mmc_suspend, cb710_mmc_resume);
 
 static int cb710_mmc_init(struct platform_device *pdev)
 {
@@ -767,13 +767,12 @@ static void cb710_mmc_exit(struct platform_device *pdev)
 }
 
 static struct platform_driver cb710_mmc_driver = {
-	.driver.name = "cb710-mmc",
+	.driver = {
+		.name = "cb710-mmc",
+		.pm = pm_sleep_ptr(&cb710_mmc_pmops),
+	},
 	.probe = cb710_mmc_init,
 	.remove = cb710_mmc_exit,
-#ifdef CONFIG_PM
-	.suspend = cb710_mmc_suspend,
-	.resume = cb710_mmc_resume,
-#endif
 };
 
 module_platform_driver(cb710_mmc_driver);
-- 
2.50.0
Re: [PATCH 09/38] mmc: cb710-mmc: use modern PM macros
Posted by Michał Mirosław 1 month, 2 weeks ago
On Fri, Aug 15, 2025 at 09:33:44AM +0800, Jisheng Zhang wrote:
> Use the modern PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.
> 
> This has the advantage of always compiling these functions in,
> independently of any Kconfig option. Thanks to that, bugs and other
> regressions are subsequently easier to catch.
> 
> At the same time, replace the platform_driver's .suspend and .resume
> usage with modern device_driver's .pm usage.
> 
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  drivers/mmc/host/cb710-mmc.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mmc/host/cb710-mmc.c b/drivers/mmc/host/cb710-mmc.c
> index 448d2f9159ea..31daec787495 100644
> --- a/drivers/mmc/host/cb710-mmc.c
> +++ b/drivers/mmc/host/cb710-mmc.c
> @@ -664,25 +664,25 @@ static const struct mmc_host_ops cb710_mmc_host = {
>  	.get_cd = cb710_mmc_get_cd,
>  };
>  
> -#ifdef CONFIG_PM
> -
> -static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
> +static int cb710_mmc_suspend(struct device *dev)
>  {
> +	struct platform_device *pdev = to_platform_device(dev);
>  	struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
>  
>  	cb710_mmc_enable_irq(slot, 0, ~0);
>  	return 0;
>  }
>  
> -static int cb710_mmc_resume(struct platform_device *pdev)
> +static int cb710_mmc_resume(struct device *dev)
>  {
> +	struct platform_device *pdev = to_platform_device(dev);
>  	struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
>  
>  	cb710_mmc_enable_irq(slot, 0, ~0);
>  	return 0;
>  }
>  
> -#endif /* CONFIG_PM */
> +static DEFINE_SIMPLE_DEV_PM_OPS(cb710_mmc_pmops, cb710_mmc_suspend, cb710_mmc_resume);
>  
>  static int cb710_mmc_init(struct platform_device *pdev)
>  {
> @@ -767,13 +767,12 @@ static void cb710_mmc_exit(struct platform_device *pdev)
>  }
>  
>  static struct platform_driver cb710_mmc_driver = {
> -	.driver.name = "cb710-mmc",
> +	.driver = {
> +		.name = "cb710-mmc",
> +		.pm = pm_sleep_ptr(&cb710_mmc_pmops),
> +	},
>  	.probe = cb710_mmc_init,
>  	.remove = cb710_mmc_exit,
> -#ifdef CONFIG_PM
> -	.suspend = cb710_mmc_suspend,
> -	.resume = cb710_mmc_resume,
> -#endif
>  };
>  
>  module_platform_driver(cb710_mmc_driver);
> -- 
> 2.50.0
> 

Acked-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>