linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
@ 2025-09-06  0:12 Artem Shimko
  2025-09-06  0:12 ` [PATCH 1/1] " Artem Shimko
  0 siblings, 1 reply; 5+ messages in thread
From: Artem Shimko @ 2025-09-06  0:12 UTC (permalink / raw)
  Cc: Artem Shimko, Elie Morisse, Shyam Sundar S K, Andi Shyti,
	linux-i2c, linux-kernel

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(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
  2025-09-06  0:12 [PATCH 0/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS Artem Shimko
@ 2025-09-06  0:12 ` Artem Shimko
  2025-09-06 21:26   ` kernel test robot
  0 siblings, 1 reply; 5+ messages in thread
From: Artem Shimko @ 2025-09-06  0:12 UTC (permalink / raw)
  Cc: Artem Shimko, Elie Morisse, Shyam Sundar S K, Andi Shyti,
	linux-i2c, linux-kernel

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.

Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
---
 drivers/i2c/busses/i2c-amd-mp2-pci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index ef7370d3dbea..8f148c4d641f 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -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);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
  2025-09-06  0:12 ` [PATCH 1/1] " Artem Shimko
@ 2025-09-06 21:26   ` kernel test robot
       [not found]     ` <20250908115942.752356-1-artyom.shimko@gmail.com>
  2025-09-08 12:11     ` [PATCH v2 1/1] " Artem Shimko
  0 siblings, 2 replies; 5+ messages in thread
From: kernel test robot @ 2025-09-06 21:26 UTC (permalink / raw)
  To: Artem Shimko
  Cc: llvm, oe-kbuild-all, Artem Shimko, Elie Morisse, Shyam Sundar S K,
	Andi Shyti, linux-i2c, linux-kernel

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/202509070541.ilqlMkml-lkp@intel.com/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/202509070541.ilqlMkml-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509070541.ilqlMkml-lkp@intel.com/

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  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 0/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
       [not found]     ` <20250908115942.752356-1-artyom.shimko@gmail.com>
@ 2025-09-08 11:59       ` Artem Shimko
  0 siblings, 0 replies; 5+ messages in thread
From: Artem Shimko @ 2025-09-08 11:59 UTC (permalink / raw)
  Cc: Artem Shimko, Elie Morisse, Shyam Sundar S K, Andi Shyti,
	linux-i2c, linux-kernel

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.

Signed-off-by: Artem Shimko <artyom.shimko@gmail.com>
---
 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(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index ef7370d3dbea..8f148c4d641f 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -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);
 
diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
index 188e24cc4d35..430d01824a0d 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
 
 	/* 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 */
 };
 
 /**
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS
  2025-09-06 21:26   ` kernel test robot
       [not found]     ` <20250908115942.752356-1-artyom.shimko@gmail.com>
@ 2025-09-08 12:11     ` Artem Shimko
  1 sibling, 0 replies; 5+ messages in thread
From: Artem Shimko @ 2025-09-08 12:11 UTC (permalink / raw)
  Cc: Artem Shimko, Elie Morisse, Shyam Sundar S K, Andi Shyti,
	linux-i2c, linux-kernel

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(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-08 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-06  0:12 [PATCH 0/1] i2c: amd-mp2-pci: Simplify PM code using DEFINE_RUNTIME_DEV_PM_OPS Artem Shimko
2025-09-06  0:12 ` [PATCH 1/1] " Artem Shimko
2025-09-06 21:26   ` kernel test robot
     [not found]     ` <20250908115942.752356-1-artyom.shimko@gmail.com>
2025-09-08 11:59       ` [PATCH v2 0/1] " Artem Shimko
2025-09-08 12:11     ` [PATCH v2 1/1] " Artem Shimko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).