Skip to contentSkip to conversation

i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

PATCH Superseded Artem Shimko 2 participants 5 messages Sep 6, 2025 – Sep 8, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

Hello maintainers and reviewers,

This patch series cleans up the power management code in the AMD MP2 PCI I2C driver by modernizing the PM infrastructure.

The main changes include:
- Replacing UNIVERSAL_DEV_PM_OPS with DEFINE_RUNTIME_DEV_PM_OPS()
- Removing redundant CONFIG_PM preprocessor guards
- Using pm_sleep_ptr() for better code elimination

These changes simplify the codebase while maintaining full functionality. The DEFINE_RUNTIME_DEV_PM_OPS macro automatically handles the necessary config dependencies, making the manual #ifdef guards unnecessary.

The patch maintains backward compatibility.

Thank you for your consideration.

Best regards,
Artem Shimko

Artem Shimko (1):
i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

 drivers/i2c/busses/i2c-amd-mp2-pci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

Simplify the power management code by:
1. Removing the redundant #ifdef CONFIG_PM guards as the DEFINE_RUNTIME_DEV_PM_OPS() macro already handles PM_SLEEP dependencies automatically.
2. Replacing UNIVERSAL_DEV_PM_OPS with DEFINE_RUNTIME_DEV_PM_OPS() which is more appropriate for runtime power management.
3. Using pm_sleep_ptr() for the driver's pm_ops to allow the compiler to eliminate unused code when CONFIG_PM_SLEEP is disabled.

This change reduces preprocessor conditional complexity and ensures better code elimination for non-PM configurations.

---
 drivers/i2c/busses/i2c-amd-mp2-pci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-amd-mp2-pci.c +2 -6
index ef7370d3dbea..8f148c4d641f 100644
@@ -379,7 +379,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);
@@ -431,9 +430,8 @@ 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,
+static DEFINE_RUNTIME_DEV_PM_OPS(amd_mp2_pci_pm_ops, amd_mp2_pci_suspend,
 			    amd_mp2_pci_resume, NULL);
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id amd_mp2_pci_tbl[] = {
 	{PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2)},
@@ -446,11 +444,9 @@ 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,
+		.pm	= pm_sleep_ptr(&amd_mp2_pci_pm_ops),
 	},
-#endif
 };
 module_pci_driver(amd_mp2_pci_driver);
 
Signature · 1 line
2.43.0
#2 lore raw
kernel test robot noticed the following build errors:

Hi Artem,

kernel test robot noticed the following build errors:

[auto build test ERROR on andi-shyti/i2c/i2c-host]
[also build test ERROR on linus/master v6.17-rc4 next-20250905] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Artem-Shimko/i2c-amd-mp2-pci-Simplify-PM-code-using-DEFINE_RUNTIME_DEV_PM_OPS/20250906-081304
base:   https://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git i2c/i2c-host
patch link:    https://lore.kernel.org/r/20250906001217.3792723-2-artyom.shimko%40gmail.com
patch subject: [PATCH 1/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
config: x86_64-buildonly-randconfig-002-20250907 (https://download.01.org/0day-ci/archive/20250907/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250907/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/i2c/busses/i2c-amd-mp2-pci.c:393:16: error: no member named 'suspend' in 'struct amd_i2c_common'
     393 |                         i2c_common->suspend(i2c_common);
         |                         ~~~~~~~~~~  ^
>> drivers/i2c/busses/i2c-amd-mp2-pci.c:424:22: error: no member named 'resume' in 'struct amd_i2c_common'
     424 |                         ret = i2c_common->resume(i2c_common);
         |                               ~~~~~~~~~~  ^

2 errors generated.

vim +393 drivers/i2c/busses/i2c-amd-mp2-pci.c

529766e0a01144 Elie Morisse    2019-03-05  381  
529766e0a01144 Elie Morisse    2019-03-05  382  static int amd_mp2_pci_suspend(struct device *dev)
529766e0a01144 Elie Morisse    2019-03-05  383  {
529766e0a01144 Elie Morisse    2019-03-05  384  	struct pci_dev *pci_dev = to_pci_dev(dev);
529766e0a01144 Elie Morisse    2019-03-05  385  	struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  386  	struct amd_i2c_common *i2c_common;
529766e0a01144 Elie Morisse    2019-03-05  387  	unsigned int bus_id;
529766e0a01144 Elie Morisse    2019-03-05  388  	int ret = 0;
529766e0a01144 Elie Morisse    2019-03-05  389  
529766e0a01144 Elie Morisse    2019-03-05  390  	for (bus_id = 0; bus_id < 2; bus_id++) {
529766e0a01144 Elie Morisse    2019-03-05  391  		i2c_common = privdata->busses[bus_id];
529766e0a01144 Elie Morisse    2019-03-05  392  		if (i2c_common)
529766e0a01144 Elie Morisse    2019-03-05 @393  			i2c_common->suspend(i2c_common);
529766e0a01144 Elie Morisse    2019-03-05  394  	}
529766e0a01144 Elie Morisse    2019-03-05  395  
529766e0a01144 Elie Morisse    2019-03-05  396  	ret = pci_save_state(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  397  	if (ret) {
267e82b9592d0d Richard Neumann 2021-02-01  398  		pci_err(pci_dev, "pci_save_state failed = %d\n", ret);
529766e0a01144 Elie Morisse    2019-03-05  399  		return ret;
529766e0a01144 Elie Morisse    2019-03-05  400  	}
529766e0a01144 Elie Morisse    2019-03-05  401  
529766e0a01144 Elie Morisse    2019-03-05  402  	pci_disable_device(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  403  	return ret;
529766e0a01144 Elie Morisse    2019-03-05  404  }
529766e0a01144 Elie Morisse    2019-03-05  405  
529766e0a01144 Elie Morisse    2019-03-05  406  static int amd_mp2_pci_resume(struct device *dev)
529766e0a01144 Elie Morisse    2019-03-05  407  {
529766e0a01144 Elie Morisse    2019-03-05  408  	struct pci_dev *pci_dev = to_pci_dev(dev);
529766e0a01144 Elie Morisse    2019-03-05  409  	struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  410  	struct amd_i2c_common *i2c_common;
529766e0a01144 Elie Morisse    2019-03-05  411  	unsigned int bus_id;
529766e0a01144 Elie Morisse    2019-03-05  412  	int ret = 0;
529766e0a01144 Elie Morisse    2019-03-05  413  
529766e0a01144 Elie Morisse    2019-03-05  414  	pci_restore_state(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  415  	ret = pci_enable_device(pci_dev);
529766e0a01144 Elie Morisse    2019-03-05  416  	if (ret < 0) {
267e82b9592d0d Richard Neumann 2021-02-01  417  		pci_err(pci_dev, "pci_enable_device failed = %d\n", ret);
529766e0a01144 Elie Morisse    2019-03-05  418  		return ret;
529766e0a01144 Elie Morisse    2019-03-05  419  	}
529766e0a01144 Elie Morisse    2019-03-05  420  
529766e0a01144 Elie Morisse    2019-03-05  421  	for (bus_id = 0; bus_id < 2; bus_id++) {
529766e0a01144 Elie Morisse    2019-03-05  422  		i2c_common = privdata->busses[bus_id];
529766e0a01144 Elie Morisse    2019-03-05  423  		if (i2c_common) {
529766e0a01144 Elie Morisse    2019-03-05 @424  			ret = i2c_common->resume(i2c_common);
529766e0a01144 Elie Morisse    2019-03-05  425  			if (ret < 0)
529766e0a01144 Elie Morisse    2019-03-05  426  				return ret;
529766e0a01144 Elie Morisse    2019-03-05  427  		}
529766e0a01144 Elie Morisse    2019-03-05  428  	}
529766e0a01144 Elie Morisse    2019-03-05  429  
529766e0a01144 Elie Morisse    2019-03-05  430  	return ret;
529766e0a01144 Elie Morisse    2019-03-05  431  }
529766e0a01144 Elie Morisse    2019-03-05  432  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

v2 cover i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

Simplify the power management code by:
1. Removing the redundant #ifdef CONFIG_PM guards as the DEFINE_RUNTIME_DEV_PM_OPS() macro already handles PM_SLEEP dependencies automatically.
2. Replacing UNIVERSAL_DEV_PM_OPS with DEFINE_RUNTIME_DEV_PM_OPS() which is more appropriate for runtime power management.
3. Using pm_sleep_ptr() for the driver's pm_ops to allow the compiler to eliminate unused code when CONFIG_PM_SLEEP is disabled.

This change reduces preprocessor conditional complexity and ensures better code elimination for non-PM configurations.

---
 drivers/i2c/busses/i2c-amd-mp2-pci.c  | 8 ++------
 drivers/i2c/busses/i2c-amd-mp2-plat.c | 4 ----
 drivers/i2c/busses/i2c-amd-mp2.h      | 2 --
 3 files changed, 2 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-amd-mp2-pci.c +2 -6
index ef7370d3dbea..8f148c4d641f 100644
@@ -379,7 +379,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);
@@ -431,9 +430,8 @@ 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,
+static DEFINE_RUNTIME_DEV_PM_OPS(amd_mp2_pci_pm_ops, amd_mp2_pci_suspend,
 			    amd_mp2_pci_resume, NULL);
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id amd_mp2_pci_tbl[] = {
 	{PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2)},
@@ -446,11 +444,9 @@ 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,
+		.pm	= pm_sleep_ptr(&amd_mp2_pci_pm_ops),
 	},
-#endif
 };
 module_pci_driver(amd_mp2_pci_driver);
 
drivers/i2c/busses/i2c-amd-mp2-plat.c +0 -4
index 188e24cc4d35..430d01824a0d 100644
@@ -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
 
 	/* Register the adapter */
 	amd_mp2_pm_runtime_get(mp2_dev);
drivers/i2c/busses/i2c-amd-mp2.h +0 -2
index 018a42de8b1e..40f3cdcc60aa 100644
@@ -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 */
 };
 
 /**
Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 1/1 i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS

In reply to kernel test robot

Hello maintainers and reviewers,

Fix build errors when CONFIG_PM is disabled by:

Removing #ifdef CONFIG_PM guards around suspend/resume function declarations in i2c-amd-mp2.h

Removing #ifdef CONFIG_PM guards around suspend/resume function assignments in i2c-amd-mp2-plat.c

Keeping the suspend/resume function pointers defined but unused when CONFIG_PM is disabled, as the common structure should have consistent layout regardless of PM configuration

This change reduces preprocessor conditional complexity and ensures better code elimination for non-PM configurations while maintaining build correctness in all config scenarios.

Thank you for your consideration.

Best regards,
Artem Shimko

ChangeLog:
v2:
* Fixed build errors when CONFIG_PM is disabled by properly handling suspend/resume function pointers in i2c-amd-mp2.h and i2c-amd-mp2-plat.c

drivers/i2c/busses/i2c-amd-mp2.h | 4 +--- drivers/i2c/busses/i2c-amd-mp2-pci.c | 9 +++------ drivers/i2c/busses/i2c-amd-mp2-plat.c | 5 +----

3 files changed, 5 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0