summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorLeo Yan <leo.yan@arm.com>2025-07-31 13:23:40 +0100
committerSuzuki K Poulose <suzuki.poulose@arm.com>2025-09-23 14:14:12 +0100
commit1abc1b212effe920f4729353880c8e03f1d76b4b (patch)
treefaf572babf778940bd4d904b4ec7046737dbcd26 /include/linux
parent40c0cdc9cbbebae9f43bef1cab9ce152318d0cce (diff)
coresight: Appropriately disable programming clocks
Some CoreSight components have programming clocks (pclk) and are enabled using clk_get() and clk_prepare_enable(). However, in many cases, these clocks are not disabled when modules exit and only released by clk_put(). To fix the issue, this commit refactors programming clock by replacing clk_get() and clk_prepare_enable() with devm_clk_get_optional_enabled() for enabling APB clock. If the "apb_pclk" clock is not found, a NULL pointer is returned, and the function proceeds to attempt enabling the "apb" clock. Since ACPI platforms rely on firmware to manage clocks, returning a NULL pointer in this case leaves clock management to the firmware rather than the driver. This effectively avoids a clock imbalance issue during module removal - where the clock could be disabled twice: once during the ACPI runtime suspend and again during the devm resource release. Callers are updated to reuse the returned error value. With the change, programming clocks are managed as resources in driver model layer, allowing clock cleanup to be handled automatically. As a result, manual cleanup operations are no longer needed and are removed from the Coresight drivers. Fixes: 73d779a03a76 ("coresight: etm4x: Change etm4_platform_driver driver for MMIO devices") Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com> Tested-by: James Clark <james.clark@linaro.org> Signed-off-by: Leo Yan <leo.yan@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20250731-arm_cs_fix_clock_v4-v6-4-1dfe10bb3f6f@arm.com
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/coresight.h22
1 files changed, 9 insertions, 13 deletions
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 4ac65c68bbf4..1e652e157841 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -6,6 +6,7 @@
#ifndef _LINUX_CORESIGHT_H
#define _LINUX_CORESIGHT_H
+#include <linux/acpi.h>
#include <linux/amba/bus.h>
#include <linux/clk.h>
#include <linux/device.h>
@@ -480,26 +481,21 @@ static inline bool is_coresight_device(void __iomem *base)
* Returns:
*
* clk - Clock is found and enabled
- * NULL - clock is not found
+ * NULL - Clock is controlled by firmware (ACPI device only)
* ERROR - Clock is found but failed to enable
*/
static inline struct clk *coresight_get_enable_apb_pclk(struct device *dev)
{
struct clk *pclk;
- int ret;
- pclk = clk_get(dev, "apb_pclk");
- if (IS_ERR(pclk)) {
- pclk = clk_get(dev, "apb");
- if (IS_ERR(pclk))
- return NULL;
- }
+ /* Firmware controls clocks for an ACPI device. */
+ if (has_acpi_companion(dev))
+ return NULL;
+
+ pclk = devm_clk_get_optional_enabled(dev, "apb_pclk");
+ if (!pclk)
+ pclk = devm_clk_get_optional_enabled(dev, "apb");
- ret = clk_prepare_enable(pclk);
- if (ret) {
- clk_put(pclk);
- return ERR_PTR(ret);
- }
return pclk;
}