From patchwork Thu Sep 25 15:05:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 4975171 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E44579F1D4 for ; Thu, 25 Sep 2014 15:09:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13EC42013D for ; Thu, 25 Sep 2014 15:09:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 94A912011B for ; Thu, 25 Sep 2014 15:09:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXAd9-00035S-KA; Thu, 25 Sep 2014 15:06:51 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXAci-0002tn-M4 for linux-arm-kernel@lists.infradead.org; Thu, 25 Sep 2014 15:06:25 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s8PF5k2c019154; Thu, 25 Sep 2014 10:05:46 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s8PF5kaK005221; Thu, 25 Sep 2014 10:05:46 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 25 Sep 2014 10:05:45 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s8PF5iuD023570; Thu, 25 Sep 2014 10:05:45 -0500 From: Grygorii Strashko To: , "Rafael J. Wysocki" , Subject: [RFC PATCH 2/4] ARM: keystone: pm: switch to use generic pm domains Date: Thu, 25 Sep 2014 18:05:35 +0300 Message-ID: <1411657537-25238-3-git-send-email-grygorii.strashko@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411657537-25238-1-git-send-email-grygorii.strashko@ti.com> References: <1411657537-25238-1-git-send-email-grygorii.strashko@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140925_080624_858112_983C6B56 X-CRM114-Status: GOOD ( 20.10 ) X-Spam-Score: -5.8 (-----) Cc: ulf.hansson@linaro.org, Grygorii Strashko , Geert Uytterhoeven , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, grant.likely@secretlab.ca, ben.dooks@codethink.co.uk, laurent.pinchart@ideasonboard.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch switches Keystone 2 PM code to use Generic PM domains instead of PM clock domains because of the lack of DT support for the last. Keystone 2 PM domain should be specified per device for which Runtime PM has to be enabled and handles the list of functional clocks to enable/disable device. Example: qmss_domain: qmss_pm_controller { compatible = "ti,keystone-pm-controller"; clocks = <&chipclk13>; #power-domain-cells = <0>; }; qmss: qmss@2a40000 { compatible = "ti,keystone-navigator-qmss"; ... power-domains = <&qmss_domain>; Signed-off-by: Grygorii Strashko --- .../devicetree/bindings/power/ti,keystone-gpc.txt | 37 +++++++ arch/arm/mach-keystone/Kconfig | 1 + arch/arm/mach-keystone/pm_domain.c | 123 ++++++++++++++++++++- 3 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/ti,keystone-gpc.txt diff --git a/Documentation/devicetree/bindings/power/ti,keystone-gpc.txt b/Documentation/devicetree/bindings/power/ti,keystone-gpc.txt new file mode 100644 index 0000000..adf63fb --- /dev/null +++ b/Documentation/devicetree/bindings/power/ti,keystone-gpc.txt @@ -0,0 +1,37 @@ +* TI Keystone 2 Generic PM Controller + +The TI Keystone 2 Generic PM Controller is responsible for Clock gating +for each controlled IP module. + +Required properties: +- compatible: Should be "ti,keystone-gpc" +- clocks: Clock's phandles to devices in the power domain that need + to be enabled during domain power-up/down. +- #power-domain-cells: Should be 0, see below: + +The gpc node is a power-controller as documented by the generic power domain +bindings in Documentation/devicetree/bindings/power/power_domain.txt. + +The IP module is allowed to reuse clocks controlled by its power domain +controller for internal proposes (get current clock rate for example). + +Example: + + netcp_domain: netcp_pm_controller { + compatible = "ti,keystone-pm-controller"; + clocks = <&clkpa>, <&clkcpgmac>, <&chipclk12>; + #power-domain-cells = <0>; + }; + + netcp: netcp@2090000 { + reg = <0x2620110 0x8>; + reg-names = "efuse"; + ... + #address-cells = <1>; + #size-cells = <1>; + ranges; + power-domains = <&netcp_domain>; + + clocks = <&clkpa>, <&clkcpgmac>, <&chipclk12>; + dma-coherent; + } diff --git a/arch/arm/mach-keystone/Kconfig b/arch/arm/mach-keystone/Kconfig index e571084..0132bde 100644 --- a/arch/arm/mach-keystone/Kconfig +++ b/arch/arm/mach-keystone/Kconfig @@ -9,6 +9,7 @@ config ARCH_KEYSTONE select COMMON_CLK_KEYSTONE select ARCH_SUPPORTS_BIG_ENDIAN select ZONE_DMA if ARM_LPAE + select PM_GENERIC_DOMAINS if PM help Support for boards based on the Texas Instruments Keystone family of SoCs. diff --git a/arch/arm/mach-keystone/pm_domain.c b/arch/arm/mach-keystone/pm_domain.c index ca79dda..3cf6696 100644 --- a/arch/arm/mach-keystone/pm_domain.c +++ b/arch/arm/mach-keystone/pm_domain.c @@ -12,14 +12,17 @@ * version 2, as published by the Free Software Foundation. */ +#include +#include #include #include #include +#include #include -#include #include #ifdef CONFIG_PM_RUNTIME + static int keystone_pm_runtime_suspend(struct device *dev) { int ret; @@ -66,6 +69,118 @@ static struct of_device_id of_keystone_table[] = { { /* end of list */ }, }; +#ifdef CONFIG_PM_GENERIC_DOMAINS + +struct keystone_domain { + struct generic_pm_domain base; + struct device *dev; +}; + +static int keystone_pm_domain_power_off(struct generic_pm_domain *genpd) +{ + int ret; + struct keystone_domain *dm = container_of(genpd, + struct keystone_domain, + base); + + /* Enable reset clocks for all devices in the PU domain */ + ret = pm_clk_suspend(dm->dev); + if (ret) + dev_err(dm->dev, "can't turn off clocks %d\n", ret); + + return ret; +} + +static int keystone_pm_domain_power_on(struct generic_pm_domain *genpd) +{ + int ret; + struct keystone_domain *dm = container_of(genpd, + struct keystone_domain, + base); + + /* Disable reset clocks for all devices in the PU domain */ + ret = pm_clk_resume(dm->dev); + if (ret) + dev_err(dm->dev, "can't turn on clocks %d\n", ret); + + return ret; +} + +static const struct keystone_domain keystone_domain = { + .base = { + .name = "keystone", + .power_off = keystone_pm_domain_power_off, + .power_on = keystone_pm_domain_power_on, + .power_off_latency_ns = 25000, + .power_on_latency_ns = 2000000, + }, +}; + +static int keystone_pm_domain_probe(struct platform_device *pdev) +{ + struct clk *clk; + bool is_off; + int i = 0; + struct keystone_domain *domain; + int ret = 0; + + domain = devm_kzalloc(&pdev->dev, + sizeof(struct keystone_domain), GFP_KERNEL); + if (!domain) + return -ENOMEM; + + domain->base = keystone_domain.base; + domain->base.of_node = pdev->dev.of_node; + domain->dev = &pdev->dev; + + ret = pm_clk_create(&pdev->dev); + if (ret) { + dev_err(&pdev->dev, "pm_clk_create failed %d\n", ret); + return ret; + }; + + while ((clk = of_clk_get(pdev->dev.of_node, i++)) && !IS_ERR(clk)) { + ret = pm_clk_add_clk(&pdev->dev, clk); + if (ret) { + dev_err(&pdev->dev, "pm_clk_add_clk failed %d\n", ret); + goto clk_err; + }; + } + + is_off = IS_ENABLED(CONFIG_PM_RUNTIME); + if (is_off) + keystone_pm_domain_power_off(&domain->base); + + pm_genpd_init(&domain->base, NULL, is_off); + return of_genpd_add_provider_simple(pdev->dev.of_node, &domain->base); + +clk_err: + pm_clk_destroy(&pdev->dev); + return ret; +} + +static struct of_device_id keystone_pm_domain_dt_ids[] = { + { .compatible = "ti,keystone-gpc" }, + { } +}; + +static struct platform_driver keystone_pm_domain_driver = { + .driver = { + .name = "ti,keystone-gpc", + .owner = THIS_MODULE, + .of_match_table = keystone_pm_domain_dt_ids, + }, + .probe = keystone_pm_domain_probe, +}; + +static int __init keystone_pm_domain_init(void) +{ + return platform_driver_register(&keystone_pm_domain_driver); +} +#else +static int __init keystone_pm_domain_init(void) { return 0; } +#endif /* CONFIG_PM_GENERIC_DOMAINS */ + int __init keystone_pm_runtime_init(void) { struct device_node *np; @@ -74,7 +189,9 @@ int __init keystone_pm_runtime_init(void) if (!np) return 0; - pm_clk_add_notifier(&platform_bus_type, &platform_domain_notifier); + /* TODO: remove clock_ops code + * pm_clk_add_notifier(&platform_bus_type, &platform_domain_notifier); + */ - return 0; + return keystone_pm_domain_init(); }