Skip to contentSkip to conversation

coresight: Fix missing AMBA dev_pm_ops and modernize PM ops

PATCH New Eric Chan 1 participant 3 messages Sep 10

Subsystems (3)
lore
Share & tools
lore

Eric Chan

author
#0 lore raw

cover coresight: Fix missing AMBA dev_pm_ops and modernize PM ops

This 2-patch series addresses an issue where CoreSight AMBA drivers (TMC, CATU, and ETM4x) missed setting their dev_pm_ops during earlier ACPI and platform driver refactorings, and modernizes runtime PM ops definitions across these drivers to align with Documentation/power/runtime_pm.rst.

- Patch 1 is a bug fix (marked for stable) that sets the missing .pm pointer in the AMBA drivers (tmc_driver, catu_driver, and etm4x_amba_driver) so runtime PM suspend and resume callbacks are properly invoked when probed via AMBA bus.
- Patch 2 modernizes the runtime PM definitions across TMC, CATU, and ETM4x to use DEFINE_RUNTIME_DEV_PM_OPS() and pm_ptr(), eliminating unnecessary #ifdef CONFIG_PM blocks.

Eric Chan (2):
coresight: Add missing dev_pm_ops to AMBA drivers
coresight: Switch to DEFINE_RUNTIME_DEV_PM_OPS()

 drivers/hwtracing/coresight/coresight-catu.c  | 31 +++++++++--------
 .../coresight/coresight-etm4x-core.c          | 30 ++++++++---------
 .../hwtracing/coresight/coresight-tmc-core.c  | 33 +++++++++----------
 3 files changed, 44 insertions(+), 50 deletions(-)
Signature · 1 line
2.55.0.1003.g10538fe699-goog
author
#1 lore raw

PATCH 1/2 coresight: Add missing dev_pm_ops to AMBA drivers

When ACPI or MMIO platform driver support was added for TMC, CATU, and ETM4x, runtime PM support was hooked up for their platform drivers via respective dev_pm_ops, but setting the .pm pointer in their AMBA drivers was missed.

As a result, when these devices are probed via the AMBA bus, runtime power management does not invoke their runtime suspend/resume callbacks, leaving device clocks (such as atclk and pclk) unmanaged during runtime PM transitions.

Move the AMBA drivers next to their platform drivers and hook up dev_pm_ops to their drv.pm pointers across TMC, CATU, and ETM4x.

Fixes 70750e257aab ("coresight: tmc: Move ACPI support from AMBA driver to platform driver")
Fixes 23567323857d ("coresight: catu: Move ACPI support from AMBA driver to platform driver")
Fixes 73d779a03a76 ("coresight: etm4x: Change etm4_platform_driver driver for MMIO devices")
---
 drivers/hwtracing/coresight/coresight-catu.c  | 21 +++++++++--------
 .../coresight/coresight-etm4x-core.c          | 21 +++++++++--------
 .../hwtracing/coresight/coresight-tmc-core.c  | 23 ++++++++++---------
 3 files changed, 34 insertions(+), 31 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +11 -10
index ad8dafea7d2f..d9a12d5e48fa 100644
@@ -612,16 +612,6 @@ static const struct amba_id catu_ids[] = {
 
 MODULE_DEVICE_TABLE(amba, catu_ids);
 
-static struct amba_driver catu_driver = {
-	.drv = {
-		.name			= "coresight-catu",
-		.suppress_bind_attrs	= true,
-	},
-	.probe				= catu_probe,
-	.remove				= catu_remove,
-	.id_table			= catu_ids,
-};
-
 static int catu_platform_probe(struct platform_device *pdev)
 {
 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -702,6 +692,17 @@ static struct platform_driver catu_platform_driver = {
 	},
 };
 
+static struct amba_driver catu_driver = {
+	.drv = {
+		.name			= "coresight-catu",
+		.pm			= &catu_dev_pm_ops,
+		.suppress_bind_attrs	= true,
+	},
+	.probe				= catu_probe,
+	.remove				= catu_remove,
+	.id_table			= catu_ids,
+};
+
 static int __init catu_init(void)
 {
 	int ret;
drivers/hwtracing/coresight/coresight-etm4x-core.c +11 -10
index 2247ad55d444..ace5e077a10c 100644
@@ -2460,16 +2460,6 @@ static const struct amba_id etm4_ids[] = {
 
 MODULE_DEVICE_TABLE(amba, etm4_ids);
 
-static struct amba_driver etm4x_amba_driver = {
-	.drv = {
-		.name   = "coresight-etm4x",
-		.suppress_bind_attrs = true,
-	},
-	.probe		= etm4_probe_amba,
-	.remove         = etm4_remove_amba,
-	.id_table	= etm4_ids,
-};
-
 #ifdef CONFIG_PM
 static int etm4_runtime_suspend(struct device *dev)
 {
@@ -2528,6 +2518,17 @@ static struct platform_driver etm4_platform_driver = {
 	},
 };
 
+static struct amba_driver etm4x_amba_driver = {
+	.drv = {
+		.name   = "coresight-etm4x",
+		.pm	= &etm4_dev_pm_ops,
+		.suppress_bind_attrs = true,
+	},
+	.probe		= etm4_probe_amba,
+	.remove         = etm4_remove_amba,
+	.id_table	= etm4_ids,
+};
+
 static int __init etm4x_init(void)
 {
 	int ret;
drivers/hwtracing/coresight/coresight-tmc-core.c +12 -11
index bc5a133ada3e..ece2e8c9be26 100644
@@ -953,17 +953,6 @@ static const struct amba_id tmc_ids[] = {
 
 MODULE_DEVICE_TABLE(amba, tmc_ids);
 
-static struct amba_driver tmc_driver = {
-	.drv = {
-		.name   = "coresight-tmc",
-		.suppress_bind_attrs = true,
-	},
-	.probe		= tmc_probe,
-	.shutdown	= tmc_shutdown,
-	.remove		= tmc_remove,
-	.id_table	= tmc_ids,
-};
-
 static int tmc_platform_probe(struct platform_device *pdev)
 {
 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1044,6 +1033,18 @@ static struct platform_driver tmc_platform_driver = {
 	},
 };
 
+static struct amba_driver tmc_driver = {
+	.drv = {
+		.name   = "coresight-tmc",
+		.pm	= &tmc_dev_pm_ops,
+		.suppress_bind_attrs = true,
+	},
+	.probe		= tmc_probe,
+	.shutdown	= tmc_shutdown,
+	.remove		= tmc_remove,
+	.id_table	= tmc_ids,
+};
+
 static int __init tmc_init(void)
 {
 	return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver);
Signature · 1 line
2.55.0.1003.g10538fe699-goog
author
#2 lore raw

PATCH 2/2 coresight: Switch to DEFINE_RUNTIME_DEV_PM_OPS()

In reply to Eric Chan

According to Documentation/power/runtime_pm.rst and include/linux/pm_runtime.h, modern drivers are encouraged to use DEFINE_RUNTIME_DEV_PM_OPS() and pm_ptr() to simplify runtime PM ops definitions and eliminate unnecessary #ifdef CONFIG_PM guards.

Convert the CoreSight TMC, CATU, and ETM4x drivers to use DEFINE_RUNTIME_DEV_PM_OPS() and replace direct references to their dev_pm_ops structures with pm_ptr(). This removes the #ifdef CONFIG_PM blocks around the runtime suspend and resume callbacks, allowing the compiler to always validate them regardless of CONFIG_PM.

---
 drivers/hwtracing/coresight/coresight-catu.c       | 12 +++++-------
 drivers/hwtracing/coresight/coresight-etm4x-core.c | 11 ++++-------
 drivers/hwtracing/coresight/coresight-tmc-core.c   | 12 ++++--------
 3 files changed, 13 insertions(+), 22 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +5 -7
index d9a12d5e48fa..e3bbfb707f73 100644
@@ -14,6 +14,7 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/slab.h>
 
 #include "coresight-catu.h"
@@ -640,7 +641,6 @@ static void catu_platform_remove(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 }
 
-#ifdef CONFIG_PM
 static int catu_runtime_suspend(struct device *dev)
 {
 	struct catu_drvdata *drvdata = dev_get_drvdata(dev);
@@ -666,11 +666,9 @@ static int catu_runtime_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops catu_dev_pm_ops = {
-	SET_RUNTIME_PM_OPS(catu_runtime_suspend, catu_runtime_resume, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(catu_dev_pm_ops,
+				 catu_runtime_suspend, catu_runtime_resume, NULL);
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id catu_acpi_ids[] = {
@@ -688,14 +686,14 @@ static struct platform_driver catu_platform_driver = {
 		.name			= "coresight-catu-platform",
 		.acpi_match_table	= ACPI_PTR(catu_acpi_ids),
 		.suppress_bind_attrs	= true,
-		.pm			= &catu_dev_pm_ops,
+		.pm			= pm_ptr(&catu_dev_pm_ops),
 	},
 };
 
 static struct amba_driver catu_driver = {
 	.drv = {
 		.name			= "coresight-catu",
-		.pm			= &catu_dev_pm_ops,
+		.pm			= pm_ptr(&catu_dev_pm_ops),
 		.suppress_bind_attrs	= true,
 	},
 	.probe				= catu_probe,
drivers/hwtracing/coresight/coresight-etm4x-core.c +4 -7
index ace5e077a10c..ef664a84120f 100644
@@ -2460,7 +2460,6 @@ static const struct amba_id etm4_ids[] = {
 
 MODULE_DEVICE_TABLE(amba, etm4_ids);
 
-#ifdef CONFIG_PM
 static int etm4_runtime_suspend(struct device *dev)
 {
 	struct etmv4_drvdata *drvdata = dev_get_drvdata(dev);
@@ -2486,11 +2485,9 @@ static int etm4_runtime_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops etm4_dev_pm_ops = {
-	SET_RUNTIME_PM_OPS(etm4_runtime_suspend, etm4_runtime_resume, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(etm4_dev_pm_ops,
+				 etm4_runtime_suspend, etm4_runtime_resume, NULL);
 
 static const struct of_device_id etm4_sysreg_match[] = {
 	{ .compatible	= "arm,coresight-etm4x-sysreg" },
@@ -2514,14 +2511,14 @@ static struct platform_driver etm4_platform_driver = {
 		.of_match_table		= etm4_sysreg_match,
 		.acpi_match_table	= ACPI_PTR(etm4x_acpi_ids),
 		.suppress_bind_attrs	= true,
-		.pm			= &etm4_dev_pm_ops,
+		.pm			= pm_ptr(&etm4_dev_pm_ops),
 	},
 };
 
 static struct amba_driver etm4x_amba_driver = {
 	.drv = {
 		.name   = "coresight-etm4x",
-		.pm	= &etm4_dev_pm_ops,
+		.pm	= pm_ptr(&etm4_dev_pm_ops),
 		.suppress_bind_attrs = true,
 	},
 	.probe		= etm4_probe_amba,
drivers/hwtracing/coresight/coresight-tmc-core.c +4 -8
index ece2e8c9be26..77588d53e1b0 100644
@@ -980,8 +980,6 @@ static void tmc_platform_remove(struct platform_device *pdev)
 	__tmc_remove(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 }
-
-#ifdef CONFIG_PM
 static int tmc_runtime_suspend(struct device *dev)
 {
 	struct tmc_drvdata *drvdata = dev_get_drvdata(dev);
@@ -1007,11 +1005,9 @@ static int tmc_runtime_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops tmc_dev_pm_ops = {
-	SET_RUNTIME_PM_OPS(tmc_runtime_suspend, tmc_runtime_resume, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(tmc_dev_pm_ops,
+				 tmc_runtime_suspend, tmc_runtime_resume, NULL);
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id tmc_acpi_ids[] = {
@@ -1029,14 +1025,14 @@ static struct platform_driver tmc_platform_driver = {
 		.name			= "coresight-tmc-platform",
 		.acpi_match_table	= ACPI_PTR(tmc_acpi_ids),
 		.suppress_bind_attrs	= true,
-		.pm			= &tmc_dev_pm_ops,
+		.pm			= pm_ptr(&tmc_dev_pm_ops),
 	},
 };
 
 static struct amba_driver tmc_driver = {
 	.drv = {
 		.name   = "coresight-tmc",
-		.pm	= &tmc_dev_pm_ops,
+		.pm	= pm_ptr(&tmc_dev_pm_ops),
 		.suppress_bind_attrs = true,
 	},
 	.probe		= tmc_probe,
Signature · 1 line
2.55.0.1003.g10538fe699-goog