mbox series

[00/23] i2c: Use new PM macros

Message ID 20230705204314.89800-1-paul@crapouillou.net
Headers show
Series i2c: Use new PM macros | expand

Message

Paul Cercueil July 5, 2023, 8:42 p.m. UTC
Hi Wolfram,

This patchset converts the I2C subsystem to use the PM macros that were
introduced in v5.17, which allow the dev_pm_ops and related callbacks to
be automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.

The point of this, is that all this code is now compiled independently
of any Kconfig option, which makes bugs and regressions easier to catch.

This continues the work that has been started in other subsystems (DRM,
IIO, watchdog).

As an added bonus, the diff is 71+/192-, that means less code you will
have to maintain ;)

The patches generally don't change the behaviour, with a few exceptions,
that are documented in the corresponding patches.

I would like to draw the attention to a few patches in particular:

- [01/23] the driver most likely does something that it shouldn't do
  (use the same callbacks for runtime PM and system PM). The patch does
  not change this behaviour but I have questions.

- [11/23] uses platform_driver.{suspend,resume} instead of the regular
  .driver.pm. I have no idea why it does that and I believe it doesn't
  really have to.

- [18/23] I feel like the qup_i2c_suspend / qup_i2c_resume don't really
  need to exist, and the pm_runtime_force_suspend() /
  pm_runtime_force_resume() helpers should be used instead, using the
  DEFINE_RUNTIME_DEV_PM_OPS() macro.

Cheers,
-Paul

Paul Cercueil (23):
  i2c: amd-mp2: Remove #ifdef guards for PM related functions
  i2c: au1550: Remove #ifdef guards for PM related functions
  i2c: iproc: Remove #ifdef guards for PM related functions
  i2c: brcmstb: Remove #ifdef guards for PM related functions
  i2c: davinci: Remove #ifdef guards for PM related functions
  i2c: designware: Remove #ifdef guards for PM related functions
  i2c: exynos5: Remove #ifdef guards for PM related functions
  i2c: hix5hd2: Remove #ifdef guards for PM related functions
  i2c: i801: Remove #ifdef guards for PM related functions
  i2c: img-scb: Remove #ifdef guards for PM related functions
  i2c: kempld: Remove #ifdef guards for PM related functions
  i2c: lpc2k: Remove #ifdef guards for PM related functions
  i2c: mt65xx: Remove #ifdef guards for PM related functions
  i2c: nomadik: Remove #ifdef guards for PM related functions
  i2c: ocores: Remove #ifdef guards for PM related functions
  i2c: pnx: Remove #ifdef guards for PM related functions
  i2c: pxa: Remove #ifdef guards for PM related functions
  i2c: qup: Remove #ifdef guards for PM related functions
  i2c: rcar: Remove #ifdef guards for PM related functions
  i2c: s3c2410: Remove #ifdef guards for PM related functions
  i2c: sh-mobile: Remove #ifdef guards for PM related functions
  i2c: virtio: Remove #ifdef guards for PM related functions
  i2c: mux: pca954x: Remove #ifdef guards for PM related functions

 drivers/i2c/busses/i2c-amd-mp2-pci.c        | 14 +++++--------
 drivers/i2c/busses/i2c-amd-mp2-plat.c       |  8 ++------
 drivers/i2c/busses/i2c-amd-mp2.h            |  2 --
 drivers/i2c/busses/i2c-au1550.c             | 15 +++-----------
 drivers/i2c/busses/i2c-bcm-iproc.c          | 10 +---------
 drivers/i2c/busses/i2c-brcmstb.c            |  8 +++-----
 drivers/i2c/busses/i2c-davinci.c            | 12 +++--------
 drivers/i2c/busses/i2c-designware-platdrv.c | 22 ++++++---------------
 drivers/i2c/busses/i2c-exynos5.c            |  8 +++-----
 drivers/i2c/busses/i2c-hix5hd2.c            | 10 ++++------
 drivers/i2c/busses/i2c-i801.c               |  6 ++----
 drivers/i2c/busses/i2c-img-scb.c            | 13 ++++--------
 drivers/i2c/busses/i2c-kempld.c             |  9 ++-------
 drivers/i2c/busses/i2c-lpc2k.c              |  8 +-------
 drivers/i2c/busses/i2c-mt65xx.c             |  8 +++-----
 drivers/i2c/busses/i2c-nomadik.c            | 14 +++++--------
 drivers/i2c/busses/i2c-ocores.c             | 10 +++-------
 drivers/i2c/busses/i2c-pnx.c                | 12 ++++-------
 drivers/i2c/busses/i2c-pxa.c                |  8 +-------
 drivers/i2c/busses/i2c-qup.c                | 16 ++++-----------
 drivers/i2c/busses/i2c-rcar.c               | 10 ++--------
 drivers/i2c/busses/i2c-s3c2410.c            | 14 +++----------
 drivers/i2c/busses/i2c-sh_mobile.c          | 12 +++--------
 drivers/i2c/busses/i2c-virtio.c             |  8 ++------
 drivers/i2c/muxes/i2c-mux-pca954x.c         |  6 ++----
 25 files changed, 71 insertions(+), 192 deletions(-)

Comments

Jonathan Cameron July 6, 2023, 2:09 a.m. UTC | #1
On Wed,  5 Jul 2023 22:42:52 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Note that the use of the UNIVERSAL_DEV_PM_OPS() macro was likely to be
> wrong, as it sets the same callbacks for the runtime-PM and system
> suspend/resume. This patch does not change this behaviour, but I suspect
> that it should be changed to use DEFINE_RUNTIME_DEV_PM_OPS() instead, as
> the current documentation for UNIVERSAL_DEV_PM_OPS() suggests.

I'd be tempted to leave this one alone because it'll be much harder
to spot that it's an ex UNIVERSAL_DEV_PM_OPS() that needs some thinking
about after this change.

> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> 
> ---
> Cc: Elie Morisse <syniurge@gmail.com>
> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> ---
>  drivers/i2c/busses/i2c-amd-mp2-pci.c  | 14 +++++---------
>  drivers/i2c/busses/i2c-amd-mp2-plat.c |  8 ++------
>  drivers/i2c/busses/i2c-amd-mp2.h      |  2 --
>  3 files changed, 7 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> index 143165300949..114fe329279a 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
> +++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> @@ -382,7 +382,6 @@ static void amd_mp2_pci_remove(struct pci_dev *pci_dev)
>  	amd_mp2_clear_reg(privdata);
>  }
>  
> -#ifdef CONFIG_PM
>  static int amd_mp2_pci_suspend(struct device *dev)
>  {
>  	struct pci_dev *pci_dev = to_pci_dev(dev);
> @@ -434,9 +433,10 @@ static int amd_mp2_pci_resume(struct device *dev)
>  	return ret;
>  }
>  
> -static UNIVERSAL_DEV_PM_OPS(amd_mp2_pci_pm_ops, amd_mp2_pci_suspend,
> -			    amd_mp2_pci_resume, NULL);
> -#endif /* CONFIG_PM */
> +static const struct dev_pm_ops amd_mp2_pci_pm_ops = {
> +	SYSTEM_SLEEP_PM_OPS(amd_mp2_pci_suspend, amd_mp2_pci_resume)
> +	RUNTIME_PM_OPS(amd_mp2_pci_suspend, amd_mp2_pci_resume, NULL)
> +};
>  
>  static const struct pci_device_id amd_mp2_pci_tbl[] = {
>  	{PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2)},
> @@ -449,11 +449,7 @@ static struct pci_driver amd_mp2_pci_driver = {
>  	.id_table	= amd_mp2_pci_tbl,
>  	.probe		= amd_mp2_pci_probe,
>  	.remove		= amd_mp2_pci_remove,
> -#ifdef CONFIG_PM
> -	.driver = {
> -		.pm	= &amd_mp2_pci_pm_ops,
> -	},
> -#endif
> +	.driver.pm	= pm_ptr(&amd_mp2_pci_pm_ops),
>  };
>  module_pci_driver(amd_mp2_pci_driver);
>  
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> index 112fe2bc5662..4c677aeaca29 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2-plat.c
> +++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> @@ -183,7 +183,6 @@ static const struct i2c_algorithm i2c_amd_algorithm = {
>  	.functionality = i2c_amd_func,
>  };
>  
> -#ifdef CONFIG_PM
>  static int i2c_amd_suspend(struct amd_i2c_common *i2c_common)
>  {
>  	struct amd_i2c_dev *i2c_dev = amd_i2c_dev_common(i2c_common);
> @@ -198,7 +197,6 @@ static int i2c_amd_resume(struct amd_i2c_common *i2c_common)
>  
>  	return i2c_amd_enable_set(i2c_dev, true);
>  }
> -#endif
>  
>  static const u32 supported_speeds[] = {
>  	I2C_MAX_HIGH_SPEED_MODE_FREQ,
> @@ -276,10 +274,8 @@ static int i2c_amd_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, i2c_dev);
>  
>  	i2c_dev->common.cmd_completion = &i2c_amd_cmd_completion;
> -#ifdef CONFIG_PM
> -	i2c_dev->common.suspend = &i2c_amd_suspend;
> -	i2c_dev->common.resume = &i2c_amd_resume;
> -#endif
> +	i2c_dev->common.suspend = pm_ptr(&i2c_amd_suspend);
> +	i2c_dev->common.resume = pm_ptr(&i2c_amd_resume);
>  
>  	/* Register the adapter */
>  	amd_mp2_pm_runtime_get(mp2_dev);
> diff --git a/drivers/i2c/busses/i2c-amd-mp2.h b/drivers/i2c/busses/i2c-amd-mp2.h
> index 018a42de8b1e..40f3cdcc60aa 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2.h
> +++ b/drivers/i2c/busses/i2c-amd-mp2.h
> @@ -160,10 +160,8 @@ struct amd_i2c_common {
>  	enum speed_enum i2c_speed;
>  	u8 *dma_buf;
>  	dma_addr_t dma_addr;
> -#ifdef CONFIG_PM
>  	int (*suspend)(struct amd_i2c_common *i2c_common);
>  	int (*resume)(struct amd_i2c_common *i2c_common);
> -#endif /* CONFIG_PM */
>  };
>  
>  /**
Jonathan Cameron July 6, 2023, 2:11 a.m. UTC | #2
On Wed,  5 Jul 2023 22:42:54 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:15 a.m. UTC | #3
On Wed,  5 Jul 2023 22:42:56 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Note that the behaviour is slightly different than before; the original
> code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
> resulted in these functions being compiled in but never used when
> CONFIG_PM_SLEEP was disabled.
> 
> Now, those functions are only compiled in when CONFIG_PM_SLEEP is
> enabled.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Slightly odd combination of callbacks in this driver, but your change
looks good to me.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:25 a.m. UTC | #4
On Wed,  5 Jul 2023 22:42:58 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:28 a.m. UTC | #5
On Wed,  5 Jul 2023 22:43:00 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:37 a.m. UTC | #6
On Wed,  5 Jul 2023 22:43:02 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Note that the driver should most likely be updated to use the
> platform_driver.driver.pm.{suspend,resume} callbacks.

Agreed.  In this particular case I'd be tempted to do that first
so that we don't introduce pm_ptr() usage for these hooks.
Look at the platform device core, I suspect they should be pm_sleep_ptr()
but not 100% sure.

Jonathan

> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  drivers/i2c/busses/i2c-kempld.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-kempld.c b/drivers/i2c/busses/i2c-kempld.c
> index 281058e3ea46..cb61e7b9202c 100644
> --- a/drivers/i2c/busses/i2c-kempld.c
> +++ b/drivers/i2c/busses/i2c-kempld.c
> @@ -350,7 +350,6 @@ static void kempld_i2c_remove(struct platform_device *pdev)
>  	i2c_del_adapter(&i2c->adap);
>  }
>  
> -#ifdef CONFIG_PM
>  static int kempld_i2c_suspend(struct platform_device *pdev, pm_message_t state)
>  {
>  	struct kempld_i2c_data *i2c = platform_get_drvdata(pdev);
> @@ -377,10 +376,6 @@ static int kempld_i2c_resume(struct platform_device *pdev)
>  
>  	return 0;
>  }
> -#else
> -#define kempld_i2c_suspend	NULL
> -#define kempld_i2c_resume	NULL
> -#endif
>  
>  static struct platform_driver kempld_i2c_driver = {
>  	.driver = {
> @@ -388,8 +383,8 @@ static struct platform_driver kempld_i2c_driver = {
>  	},
>  	.probe		= kempld_i2c_probe,
>  	.remove_new	= kempld_i2c_remove,
> -	.suspend	= kempld_i2c_suspend,
> -	.resume		= kempld_i2c_resume,
> +	.suspend	= pm_ptr(kempld_i2c_suspend),
> +	.resume		= pm_ptr(kempld_i2c_resume),
>  };
>  
>  module_platform_driver(kempld_i2c_driver);
Jonathan Cameron July 6, 2023, 2:40 a.m. UTC | #7
On Wed,  5 Jul 2023 22:43:04 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:42 a.m. UTC | #8
On Wed,  5 Jul 2023 22:43:06 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:50 a.m. UTC | #9
On Wed,  5 Jul 2023 22:43:08 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Note that the behaviour is slightly different than before; the original
> code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
> resulted in these functions being compiled in but never used when
> CONFIG_PM_SLEEP was disabled.
> 
> Now, those functions are only compiled in when CONFIG_PM_SLEEP is
> enabled.
> 
> Also note that pm_sleep_ptr() has not been applied to each callback
> in the dev_pm_ops structure because the pm_sleep_ptr() at the usage site
> is sufficient.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 2:52 a.m. UTC | #10
On Wed,  5 Jul 2023 22:45:17 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 3:07 a.m. UTC | #11
On Wed,  5 Jul 2023 22:45:19 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Jonathan Cameron July 6, 2023, 3:07 a.m. UTC | #12
On Wed,  5 Jul 2023 22:45:21 +0200
Paul Cercueil <paul@crapouillou.net> wrote:

> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Ray Jui July 6, 2023, 5:01 p.m. UTC | #13
On 7/5/2023 1:42 PM, Paul Cercueil wrote:
> Use the new 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.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> 
> ---
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
> Cc: linux-arm-kernel@lists.infradead.org
> ---
>  drivers/i2c/busses/i2c-bcm-iproc.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
> index 2d8342fdc25d..8a3e2208475c 100644
> --- a/drivers/i2c/busses/i2c-bcm-iproc.c
> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
> @@ -1125,8 +1125,6 @@ static void bcm_iproc_i2c_remove(struct platform_device *pdev)
>  	bcm_iproc_i2c_enable_disable(iproc_i2c, false);
>  }
>  
> -#ifdef CONFIG_PM_SLEEP
> -
>  static int bcm_iproc_i2c_suspend(struct device *dev)
>  {
>  	struct bcm_iproc_i2c_dev *iproc_i2c = dev_get_drvdata(dev);
> @@ -1177,12 +1175,6 @@ static const struct dev_pm_ops bcm_iproc_i2c_pm_ops = {
>  	.resume_early = &bcm_iproc_i2c_resume
>  };
>  
> -#define BCM_IPROC_I2C_PM_OPS (&bcm_iproc_i2c_pm_ops)
> -#else
> -#define BCM_IPROC_I2C_PM_OPS NULL
> -#endif /* CONFIG_PM_SLEEP */
> -
> -
>  static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave)
>  {
>  	struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter);
> @@ -1255,7 +1247,7 @@ static struct platform_driver bcm_iproc_i2c_driver = {
>  	.driver = {
>  		.name = "bcm-iproc-i2c",
>  		.of_match_table = bcm_iproc_i2c_of_match,
> -		.pm = BCM_IPROC_I2C_PM_OPS,
> +		.pm = pm_sleep_ptr(&bcm_iproc_i2c_pm_ops),
>  	},
>  	.probe = bcm_iproc_i2c_probe,
>  	.remove_new = bcm_iproc_i2c_remove,

Thanks.

Acked-by: Ray Jui <ray.jui@broadcom.com>
Paul Cercueil July 8, 2023, 8:42 a.m. UTC | #14
Hi Jonathan,

Le jeudi 06 juillet 2023 à 10:09 +0800, Jonathan Cameron a écrit :
> On Wed,  5 Jul 2023 22:42:52 +0200
> Paul Cercueil <paul@crapouillou.net> wrote:
> 
> > Use the new 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.
> > 
> > Note that the use of the UNIVERSAL_DEV_PM_OPS() macro was likely to
> > be
> > wrong, as it sets the same callbacks for the runtime-PM and system
> > suspend/resume. This patch does not change this behaviour, but I
> > suspect
> > that it should be changed to use DEFINE_RUNTIME_DEV_PM_OPS()
> > instead, as
> > the current documentation for UNIVERSAL_DEV_PM_OPS() suggests.
> 
> I'd be tempted to leave this one alone because it'll be much harder
> to spot that it's an ex UNIVERSAL_DEV_PM_OPS() that needs some
> thinking
> about after this change.

Ok, that's a good point.

Cheers,
-Paul

> > 
> > Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> > 
> > ---
> > Cc: Elie Morisse <syniurge@gmail.com>
> > Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> > ---
> >  drivers/i2c/busses/i2c-amd-mp2-pci.c  | 14 +++++---------
> >  drivers/i2c/busses/i2c-amd-mp2-plat.c |  8 ++------
> >  drivers/i2c/busses/i2c-amd-mp2.h      |  2 --
> >  3 files changed, 7 insertions(+), 17 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c
> > b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> > index 143165300949..114fe329279a 100644
> > --- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
> > +++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> > @@ -382,7 +382,6 @@ static void amd_mp2_pci_remove(struct pci_dev
> > *pci_dev)
> >         amd_mp2_clear_reg(privdata);
> >  }
> >  
> > -#ifdef CONFIG_PM
> >  static int amd_mp2_pci_suspend(struct device *dev)
> >  {
> >         struct pci_dev *pci_dev = to_pci_dev(dev);
> > @@ -434,9 +433,10 @@ static int amd_mp2_pci_resume(struct device
> > *dev)
> >         return ret;
> >  }
> >  
> > -static UNIVERSAL_DEV_PM_OPS(amd_mp2_pci_pm_ops,
> > amd_mp2_pci_suspend,
> > -                           amd_mp2_pci_resume, NULL);
> > -#endif /* CONFIG_PM */
> > +static const struct dev_pm_ops amd_mp2_pci_pm_ops = {
> > +       SYSTEM_SLEEP_PM_OPS(amd_mp2_pci_suspend,
> > amd_mp2_pci_resume)
> > +       RUNTIME_PM_OPS(amd_mp2_pci_suspend, amd_mp2_pci_resume,
> > NULL)
> > +};
> >  
> >  static const struct pci_device_id amd_mp2_pci_tbl[] = {
> >         {PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2)},
> > @@ -449,11 +449,7 @@ static struct pci_driver amd_mp2_pci_driver =
> > {
> >         .id_table       = amd_mp2_pci_tbl,
> >         .probe          = amd_mp2_pci_probe,
> >         .remove         = amd_mp2_pci_remove,
> > -#ifdef CONFIG_PM
> > -       .driver = {
> > -               .pm     = &amd_mp2_pci_pm_ops,
> > -       },
> > -#endif
> > +       .driver.pm      = pm_ptr(&amd_mp2_pci_pm_ops),
> >  };
> >  module_pci_driver(amd_mp2_pci_driver);
> >  
> > diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c
> > b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> > index 112fe2bc5662..4c677aeaca29 100644
> > --- a/drivers/i2c/busses/i2c-amd-mp2-plat.c
> > +++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> > @@ -183,7 +183,6 @@ static const struct i2c_algorithm
> > i2c_amd_algorithm = {
> >         .functionality = i2c_amd_func,
> >  };
> >  
> > -#ifdef CONFIG_PM
> >  static int i2c_amd_suspend(struct amd_i2c_common *i2c_common)
> >  {
> >         struct amd_i2c_dev *i2c_dev =
> > amd_i2c_dev_common(i2c_common);
> > @@ -198,7 +197,6 @@ static int i2c_amd_resume(struct amd_i2c_common
> > *i2c_common)
> >  
> >         return i2c_amd_enable_set(i2c_dev, true);
> >  }
> > -#endif
> >  
> >  static const u32 supported_speeds[] = {
> >         I2C_MAX_HIGH_SPEED_MODE_FREQ,
> > @@ -276,10 +274,8 @@ static int i2c_amd_probe(struct
> > platform_device *pdev)
> >         platform_set_drvdata(pdev, i2c_dev);
> >  
> >         i2c_dev->common.cmd_completion = &i2c_amd_cmd_completion;
> > -#ifdef CONFIG_PM
> > -       i2c_dev->common.suspend = &i2c_amd_suspend;
> > -       i2c_dev->common.resume = &i2c_amd_resume;
> > -#endif
> > +       i2c_dev->common.suspend = pm_ptr(&i2c_amd_suspend);
> > +       i2c_dev->common.resume = pm_ptr(&i2c_amd_resume);
> >  
> >         /* Register the adapter */
> >         amd_mp2_pm_runtime_get(mp2_dev);
> > diff --git a/drivers/i2c/busses/i2c-amd-mp2.h
> > b/drivers/i2c/busses/i2c-amd-mp2.h
> > index 018a42de8b1e..40f3cdcc60aa 100644
> > --- a/drivers/i2c/busses/i2c-amd-mp2.h
> > +++ b/drivers/i2c/busses/i2c-amd-mp2.h
> > @@ -160,10 +160,8 @@ struct amd_i2c_common {
> >         enum speed_enum i2c_speed;
> >         u8 *dma_buf;
> >         dma_addr_t dma_addr;
> > -#ifdef CONFIG_PM
> >         int (*suspend)(struct amd_i2c_common *i2c_common);
> >         int (*resume)(struct amd_i2c_common *i2c_common);
> > -#endif /* CONFIG_PM */
> >  };
> >  
> >  /**
>
Paul Cercueil July 8, 2023, 9:13 a.m. UTC | #15
Hi Jonathan,

Le jeudi 06 juillet 2023 à 10:37 +0800, Jonathan Cameron a écrit :
> On Wed,  5 Jul 2023 22:43:02 +0200
> Paul Cercueil <paul@crapouillou.net> wrote:
> 
> > Use the new 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.
> > 
> > Note that the driver should most likely be updated to use the
> > platform_driver.driver.pm.{suspend,resume} callbacks.
> 
> Agreed.  In this particular case I'd be tempted to do that first
> so that we don't introduce pm_ptr() usage for these hooks.
> Look at the platform device core, I suspect they should be
> pm_sleep_ptr()
> but not 100% sure.

Ok, I'll just convert it then, the diff won't be much bigger.

Cheers,
-Paul

> Jonathan
> 
> > 
> > Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> > ---
> >  drivers/i2c/busses/i2c-kempld.c | 9 ++-------
> >  1 file changed, 2 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-kempld.c
> > b/drivers/i2c/busses/i2c-kempld.c
> > index 281058e3ea46..cb61e7b9202c 100644
> > --- a/drivers/i2c/busses/i2c-kempld.c
> > +++ b/drivers/i2c/busses/i2c-kempld.c
> > @@ -350,7 +350,6 @@ static void kempld_i2c_remove(struct
> > platform_device *pdev)
> >         i2c_del_adapter(&i2c->adap);
> >  }
> >  
> > -#ifdef CONFIG_PM
> >  static int kempld_i2c_suspend(struct platform_device *pdev,
> > pm_message_t state)
> >  {
> >         struct kempld_i2c_data *i2c = platform_get_drvdata(pdev);
> > @@ -377,10 +376,6 @@ static int kempld_i2c_resume(struct
> > platform_device *pdev)
> >  
> >         return 0;
> >  }
> > -#else
> > -#define kempld_i2c_suspend     NULL
> > -#define kempld_i2c_resume      NULL
> > -#endif
> >  
> >  static struct platform_driver kempld_i2c_driver = {
> >         .driver = {
> > @@ -388,8 +383,8 @@ static struct platform_driver kempld_i2c_driver
> > = {
> >         },
> >         .probe          = kempld_i2c_probe,
> >         .remove_new     = kempld_i2c_remove,
> > -       .suspend        = kempld_i2c_suspend,
> > -       .resume         = kempld_i2c_resume,
> > +       .suspend        = pm_ptr(kempld_i2c_suspend),
> > +       .resume         = pm_ptr(kempld_i2c_resume),
> >  };
> >  
> >  module_platform_driver(kempld_i2c_driver);
>