From nobody Fri Dec 19 08:04:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 639FCE7D0A7 for ; Thu, 21 Sep 2023 20:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjIUUXg (ORCPT ); Thu, 21 Sep 2023 16:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231809AbjIUUXJ (ORCPT ); Thu, 21 Sep 2023 16:23:09 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA60D561C3 for ; Thu, 21 Sep 2023 10:17:39 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E7581477; Wed, 20 Sep 2023 21:21:52 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.32.120]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DC0053F59C; Wed, 20 Sep 2023 21:21:12 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com Cc: Anshuman Khandual , James Clark , Mike Leach , coresight@lists.linaro.org, linux-kernel@vger.kernel.org Subject: [RFC RESEND 7/7] coresight: debug: Move ACPI support from AMBA driver to platform driver Date: Thu, 21 Sep 2023 09:50:40 +0530 Message-Id: <20230921042040.1334641-8-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921042040.1334641-1-anshuman.khandual@arm.com> References: <20230921042040.1334641-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for the cpu debug devices in a new platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available. Signed-off-by: Anshuman Khandual --- drivers/acpi/arm64/amba.c | 1 - .../hwtracing/coresight/coresight-cpu-debug.c | 130 ++++++++++++++++-- 2 files changed, 117 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/arm64/amba.c b/drivers/acpi/arm64/amba.c index ebc866518057..b591c7a650aa 100644 --- a/drivers/acpi/arm64/amba.c +++ b/drivers/acpi/arm64/amba.c @@ -22,7 +22,6 @@ static const struct acpi_device_id amba_id_list[] =3D { {"ARMH0061", 0}, /* PL061 GPIO Device */ {"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */ - {"ARMHC503", 0}, /* ARM CoreSight Debug */ {"", 0}, }; =20 diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hw= tracing/coresight/coresight-cpu-debug.c index 1874df7c6a73..77a42a7d5d7c 100644 --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include =20 #include "coresight-priv.h" =20 @@ -84,6 +86,7 @@ #define DEBUG_WAIT_TIMEOUT 32000 =20 struct debug_drvdata { + struct clk *pclk; void __iomem *base; struct device *dev; int cpu; @@ -557,18 +560,12 @@ static void debug_func_exit(void) debugfs_remove_recursive(debug_debugfs_dir); } =20 -static int debug_probe(struct amba_device *adev, const struct amba_id *id) +static int __debug_probe(struct device *dev, struct resource *res) { + struct debug_drvdata *drvdata =3D dev_get_drvdata(dev); void __iomem *base; - struct device *dev =3D &adev->dev; - struct debug_drvdata *drvdata; - struct resource *res =3D &adev->res; int ret; =20 - drvdata =3D devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); - if (!drvdata) - return -ENOMEM; - drvdata->cpu =3D coresight_get_cpu(dev); if (drvdata->cpu < 0) return drvdata->cpu; @@ -579,8 +576,7 @@ static int debug_probe(struct amba_device *adev, const = struct amba_id *id) return -EBUSY; } =20 - drvdata->dev =3D &adev->dev; - amba_set_drvdata(adev, drvdata); + drvdata->dev =3D dev; =20 /* Validity for the resource is already checked by the AMBA core */ base =3D devm_ioremap_resource(dev, res); @@ -629,10 +625,21 @@ static int debug_probe(struct amba_device *adev, cons= t struct amba_id *id) return ret; } =20 -static void debug_remove(struct amba_device *adev) +static int debug_probe(struct amba_device *adev, const struct amba_id *id) { - struct device *dev =3D &adev->dev; - struct debug_drvdata *drvdata =3D amba_get_drvdata(adev); + struct debug_drvdata *drvdata; + + drvdata =3D devm_kzalloc(&adev->dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + amba_set_drvdata(adev, drvdata); + return __debug_probe(&adev->dev, &adev->res); +} + +static void __debug_remove(struct device *dev) +{ + struct debug_drvdata *drvdata =3D dev_get_drvdata(dev); =20 per_cpu(debug_drvdata, drvdata->cpu) =3D NULL; =20 @@ -646,6 +653,11 @@ static void debug_remove(struct amba_device *adev) debug_func_exit(); } =20 +static void debug_remove(struct amba_device *adev) +{ + __debug_remove(&adev->dev); +} + static const struct amba_cs_uci_id uci_id_debug[] =3D { { /* CPU Debug UCI data */ @@ -679,6 +691,98 @@ static struct amba_driver debug_driver =3D { =20 module_amba_driver(debug_driver); =20 +static int debug_platform_probe(struct platform_device *pdev) +{ + struct resource *res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + struct debug_drvdata *drvdata; + int ret =3D 0; + + drvdata =3D devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + drvdata->pclk =3D coresight_get_enable_apb_pclk(&pdev->dev); + if (IS_ERR(drvdata->pclk)) + return -ENODEV; + + if (res) { + drvdata->base =3D devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(drvdata->base)) { + clk_put(drvdata->pclk); + return PTR_ERR(drvdata->base); + } + } + + dev_set_drvdata(&pdev->dev, drvdata); + pm_runtime_get_noresume(&pdev->dev); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + + ret =3D __debug_probe(&pdev->dev, res); + if (ret) { + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); + } + return ret; +} + +static int debug_platform_remove(struct platform_device *pdev) +{ + struct debug_drvdata *drvdata =3D dev_get_drvdata(&pdev->dev); + + if (drvdata) + __debug_remove(&pdev->dev); + + pm_runtime_disable(&pdev->dev); + if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk)) + clk_put(drvdata->pclk); + return 0; +} + +#ifdef CONFIG_ACPI +static const struct acpi_device_id debug_platform_ids[] =3D { + {"ARMHC503", 0}, /* ARM CoreSight Debug */ + {}, +}; +MODULE_DEVICE_TABLE(acpi, debug_platform_ids); +#endif + +#ifdef CONFIG_PM +static int debug_runtime_suspend(struct device *dev) +{ + struct debug_drvdata *drvdata =3D dev_get_drvdata(dev); + + if (drvdata->pclk && !IS_ERR(drvdata->pclk)) + clk_disable_unprepare(drvdata->pclk); + return 0; +} + +static int debug_runtime_resume(struct device *dev) +{ + struct debug_drvdata *drvdata =3D dev_get_drvdata(dev); + + if (drvdata->pclk && !IS_ERR(drvdata->pclk)) + clk_prepare_enable(drvdata->pclk); + return 0; +} +#endif + +static const struct dev_pm_ops debug_dev_pm_ops =3D { + SET_RUNTIME_PM_OPS(debug_runtime_suspend, debug_runtime_resume, NULL) +}; + +static struct platform_driver debug_platform_driver =3D { + .probe =3D debug_platform_probe, + .remove =3D debug_platform_remove, + .driver =3D { + .name =3D "coresight-debug-platform", + .acpi_match_table =3D ACPI_PTR(debug_platform_ids), + .suppress_bind_attrs =3D true, + .pm =3D &debug_dev_pm_ops, + }, +}; +module_platform_driver(debug_platform_driver); + MODULE_AUTHOR("Leo Yan "); MODULE_DESCRIPTION("ARM Coresight CPU Debug Driver"); MODULE_LICENSE("GPL"); --=20 2.25.1