Skip to content

Commit fbe7514

Browse files
Leo-YanSuzuki K Poulose
authored andcommitted
coresight: Consolidate clock enabling
CoreSight drivers enable pclk and atclk conditionally. For example, pclk is only enabled in the static probe, while atclk is an optional clock that it is enabled for both dynamic and static probes, if it is present. In the current CoreSight drivers, these two clocks are initialized separately. This causes complex and duplicate codes. CoreSight drivers are refined so that clocks are initialized in one go. For this purpose, this commit renames coresight_get_enable_apb_pclk() to coresight_get_enable_clocks() and encapsulates clock initialization logic: - If a clock is initialized successfully, its clock pointer is assigned to the double pointer passed as an argument. - For ACPI devices, clocks are controlled by firmware, directly bail out. - Skip enabling pclk for an AMBA device. - If atclk is not found, the corresponding double pointer is set to NULL. The function returns Success (0) to guide callers can proceed with no error. - Otherwise, an error number is returned for failures. The function became complex, move it from the header to the CoreSight core layer and the symbol is exported. Added comments for recording details. Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> 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-7-1dfe10bb3f6f@arm.com
1 parent d091c63 commit fbe7514

11 files changed

Lines changed: 83 additions & 83 deletions

drivers/hwtracing/coresight/coresight-catu.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ static int __catu_probe(struct device *dev, struct resource *res)
520520
struct coresight_platform_data *pdata = NULL;
521521
void __iomem *base;
522522

523-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
524-
if (IS_ERR(drvdata->atclk))
525-
return PTR_ERR(drvdata->atclk);
523+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
524+
if (ret)
525+
return ret;
526526

527527
catu_desc.name = coresight_alloc_device_name(&catu_devs, dev);
528528
if (!catu_desc.name)
@@ -634,10 +634,6 @@ static int catu_platform_probe(struct platform_device *pdev)
634634
if (!drvdata)
635635
return -ENOMEM;
636636

637-
drvdata->pclk = coresight_get_enable_apb_pclk(&pdev->dev);
638-
if (IS_ERR(drvdata->pclk))
639-
return PTR_ERR(drvdata->pclk);
640-
641637
pm_runtime_get_noresume(&pdev->dev);
642638
pm_runtime_set_active(&pdev->dev);
643639
pm_runtime_enable(&pdev->dev);

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
44
*/
55

6+
#include <linux/acpi.h>
67
#include <linux/bitfield.h>
78
#include <linux/build_bug.h>
89
#include <linux/kernel.h>
@@ -1700,6 +1701,53 @@ int coresight_etm_get_trace_id(struct coresight_device *csdev, enum cs_mode mode
17001701
}
17011702
EXPORT_SYMBOL_GPL(coresight_etm_get_trace_id);
17021703

1704+
/*
1705+
* Attempt to find and enable programming clock (pclk) and trace clock (atclk)
1706+
* for the given device.
1707+
*
1708+
* For ACPI devices, clocks are controlled by firmware, so bail out early in
1709+
* this case. Also, skip enabling pclk if the clock is managed by the AMBA
1710+
* bus driver instead.
1711+
*
1712+
* atclk is an optional clock, it will be only enabled when it is existed.
1713+
* Otherwise, a NULL pointer will be returned to caller.
1714+
*
1715+
* Returns: '0' on Success; Error code otherwise.
1716+
*/
1717+
int coresight_get_enable_clocks(struct device *dev, struct clk **pclk,
1718+
struct clk **atclk)
1719+
{
1720+
WARN_ON(!pclk);
1721+
1722+
if (has_acpi_companion(dev))
1723+
return 0;
1724+
1725+
if (!dev_is_amba(dev)) {
1726+
/*
1727+
* "apb_pclk" is the default clock name for an Arm Primecell
1728+
* peripheral, while "apb" is used only by the CTCU driver.
1729+
*
1730+
* For easier maintenance, CoreSight drivers should use
1731+
* "apb_pclk" as the programming clock name.
1732+
*/
1733+
*pclk = devm_clk_get_optional_enabled(dev, "apb_pclk");
1734+
if (!*pclk)
1735+
*pclk = devm_clk_get_optional_enabled(dev, "apb");
1736+
if (IS_ERR(*pclk))
1737+
return PTR_ERR(*pclk);
1738+
}
1739+
1740+
/* Initialization of atclk is skipped if it is a NULL pointer. */
1741+
if (atclk) {
1742+
*atclk = devm_clk_get_optional_enabled(dev, "atclk");
1743+
if (IS_ERR(*atclk))
1744+
return PTR_ERR(*atclk);
1745+
}
1746+
1747+
return 0;
1748+
}
1749+
EXPORT_SYMBOL_GPL(coresight_get_enable_clocks);
1750+
17031751
MODULE_LICENSE("GPL v2");
17041752
MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
17051753
MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");

drivers/hwtracing/coresight/coresight-cpu-debug.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ static int __debug_probe(struct device *dev, struct resource *res)
566566
void __iomem *base;
567567
int ret;
568568

569+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, NULL);
570+
if (ret)
571+
return ret;
572+
569573
drvdata->cpu = coresight_get_cpu(dev);
570574
if (drvdata->cpu < 0)
571575
return drvdata->cpu;
@@ -697,10 +701,6 @@ static int debug_platform_probe(struct platform_device *pdev)
697701
if (!drvdata)
698702
return -ENOMEM;
699703

700-
drvdata->pclk = coresight_get_enable_apb_pclk(&pdev->dev);
701-
if (IS_ERR(drvdata->pclk))
702-
return PTR_ERR(drvdata->pclk);
703-
704704
dev_set_drvdata(&pdev->dev, drvdata);
705705
pm_runtime_get_noresume(&pdev->dev);
706706
pm_runtime_set_active(&pdev->dev);

drivers/hwtracing/coresight/coresight-ctcu-core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int ctcu_probe(struct platform_device *pdev)
188188
const struct ctcu_config *cfgs;
189189
struct ctcu_drvdata *drvdata;
190190
void __iomem *base;
191-
int i;
191+
int i, ret;
192192

193193
desc.name = coresight_alloc_device_name(&ctcu_devs, dev);
194194
if (!desc.name)
@@ -207,9 +207,9 @@ static int ctcu_probe(struct platform_device *pdev)
207207
if (IS_ERR(base))
208208
return PTR_ERR(base);
209209

210-
drvdata->apb_clk = coresight_get_enable_apb_pclk(dev);
211-
if (IS_ERR(drvdata->apb_clk))
212-
return PTR_ERR(drvdata->apb_clk);
210+
ret = coresight_get_enable_clocks(dev, &drvdata->apb_clk, NULL);
211+
if (ret)
212+
return ret;
213213

214214
cfgs = of_device_get_match_data(dev);
215215
if (cfgs) {

drivers/hwtracing/coresight/coresight-etm4x-core.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,13 +2217,14 @@ static int etm4_probe(struct device *dev)
22172217
struct csdev_access access = { 0 };
22182218
struct etm4_init_arg init_arg = { 0 };
22192219
struct etm4_init_arg *delayed;
2220+
int ret;
22202221

22212222
if (WARN_ON(!drvdata))
22222223
return -ENOMEM;
22232224

2224-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
2225-
if (IS_ERR(drvdata->atclk))
2226-
return PTR_ERR(drvdata->atclk);
2225+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
2226+
if (ret)
2227+
return ret;
22272228

22282229
if (pm_save_enable == PARAM_PM_SAVE_FIRMWARE)
22292230
pm_save_enable = coresight_loses_context_with_cpu(dev) ?
@@ -2307,10 +2308,6 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
23072308
if (!drvdata)
23082309
return -ENOMEM;
23092310

2310-
drvdata->pclk = coresight_get_enable_apb_pclk(&pdev->dev);
2311-
if (IS_ERR(drvdata->pclk))
2312-
return PTR_ERR(drvdata->pclk);
2313-
23142311
if (res) {
23152312
drvdata->base = devm_ioremap_resource(&pdev->dev, res);
23162313
if (IS_ERR(drvdata->base))

drivers/hwtracing/coresight/coresight-funnel.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static int funnel_probe(struct device *dev, struct resource *res)
217217
struct coresight_platform_data *pdata = NULL;
218218
struct funnel_drvdata *drvdata;
219219
struct coresight_desc desc = { 0 };
220+
int ret;
220221

221222
if (is_of_node(dev_fwnode(dev)) &&
222223
of_device_is_compatible(dev->of_node, "arm,coresight-funnel"))
@@ -230,13 +231,9 @@ static int funnel_probe(struct device *dev, struct resource *res)
230231
if (!drvdata)
231232
return -ENOMEM;
232233

233-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
234-
if (IS_ERR(drvdata->atclk))
235-
return PTR_ERR(drvdata->atclk);
236-
237-
drvdata->pclk = coresight_get_enable_apb_pclk(dev);
238-
if (IS_ERR(drvdata->pclk))
239-
return PTR_ERR(drvdata->pclk);
234+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
235+
if (ret)
236+
return ret;
240237

241238
/*
242239
* Map the device base for dynamic-funnel, which has been

drivers/hwtracing/coresight/coresight-replicator.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ static int replicator_probe(struct device *dev, struct resource *res)
223223
struct replicator_drvdata *drvdata;
224224
struct coresight_desc desc = { 0 };
225225
void __iomem *base;
226+
int ret;
226227

227228
if (is_of_node(dev_fwnode(dev)) &&
228229
of_device_is_compatible(dev->of_node, "arm,coresight-replicator"))
@@ -237,13 +238,9 @@ static int replicator_probe(struct device *dev, struct resource *res)
237238
if (!drvdata)
238239
return -ENOMEM;
239240

240-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
241-
if (IS_ERR(drvdata->atclk))
242-
return PTR_ERR(drvdata->atclk);
243-
244-
drvdata->pclk = coresight_get_enable_apb_pclk(dev);
245-
if (IS_ERR(drvdata->pclk))
246-
return PTR_ERR(drvdata->pclk);
241+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
242+
if (ret)
243+
return ret;
247244

248245
/*
249246
* Map the device base for dynamic-replicator, which has been

drivers/hwtracing/coresight/coresight-stm.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,10 @@ static int __stm_probe(struct device *dev, struct resource *res)
842842
if (!drvdata)
843843
return -ENOMEM;
844844

845-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
846-
if (IS_ERR(drvdata->atclk))
847-
return PTR_ERR(drvdata->atclk);
845+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
846+
if (ret)
847+
return ret;
848848

849-
drvdata->pclk = coresight_get_enable_apb_pclk(dev);
850-
if (IS_ERR(drvdata->pclk))
851-
return PTR_ERR(drvdata->pclk);
852849
dev_set_drvdata(dev, drvdata);
853850

854851
base = devm_ioremap_resource(dev, res);

drivers/hwtracing/coresight/coresight-tmc-core.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,9 @@ static int __tmc_probe(struct device *dev, struct resource *res)
779779
struct coresight_desc desc = { 0 };
780780
struct coresight_dev_list *dev_list = NULL;
781781

782-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
783-
if (IS_ERR(drvdata->atclk))
784-
return PTR_ERR(drvdata->atclk);
782+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
783+
if (ret)
784+
return ret;
785785

786786
ret = -ENOMEM;
787787

@@ -979,10 +979,6 @@ static int tmc_platform_probe(struct platform_device *pdev)
979979
if (!drvdata)
980980
return -ENOMEM;
981981

982-
drvdata->pclk = coresight_get_enable_apb_pclk(&pdev->dev);
983-
if (IS_ERR(drvdata->pclk))
984-
return PTR_ERR(drvdata->pclk);
985-
986982
dev_set_drvdata(&pdev->dev, drvdata);
987983
pm_runtime_get_noresume(&pdev->dev);
988984
pm_runtime_set_active(&pdev->dev);

drivers/hwtracing/coresight/coresight-tpiu.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ static int __tpiu_probe(struct device *dev, struct resource *res)
132132
struct coresight_platform_data *pdata = NULL;
133133
struct tpiu_drvdata *drvdata;
134134
struct coresight_desc desc = { 0 };
135+
int ret;
135136

136137
desc.name = coresight_alloc_device_name(&tpiu_devs, dev);
137138
if (!desc.name)
@@ -143,13 +144,10 @@ static int __tpiu_probe(struct device *dev, struct resource *res)
143144

144145
spin_lock_init(&drvdata->spinlock);
145146

146-
drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk");
147-
if (IS_ERR(drvdata->atclk))
148-
return PTR_ERR(drvdata->atclk);
147+
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
148+
if (ret)
149+
return ret;
149150

150-
drvdata->pclk = coresight_get_enable_apb_pclk(dev);
151-
if (IS_ERR(drvdata->pclk))
152-
return PTR_ERR(drvdata->pclk);
153151
dev_set_drvdata(dev, drvdata);
154152

155153
/* Validity for the resource is already checked by the AMBA core */

0 commit comments

Comments
 (0)