From patchwork Thu Mar 28 16:11:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Andersson X-Patchwork-Id: 2357591 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 16D44DF2A1 for ; Thu, 28 Mar 2013 16:16:07 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ULFS1-00064t-4o; Thu, 28 Mar 2013 16:13:17 +0000 Received: from eu1sys200aog124.obsmtp.com ([207.126.144.157]) by merlin.infradead.org with smtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ULFQv-0005nr-Jk for linux-arm-kernel@lists.infradead.org; Thu, 28 Mar 2013 16:12:16 +0000 Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob124.postini.com ([207.126.147.11]) with SMTP ID DSNKUVRr0mM07/JVKvyA3Ulxt8uqlNEwk7NC@postini.com; Thu, 28 Mar 2013 16:12:09 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 63E8A41; Thu, 28 Mar 2013 16:11:02 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 755895C; Thu, 28 Mar 2013 09:39:35 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id C304AA8074; Thu, 28 Mar 2013 17:11:46 +0100 (CET) Received: from steludxu2826.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Thu, 28 Mar 2013 17:11:52 +0100 From: Rickard Andersson To: , , Subject: [PATCH V2 06/12] clk: ux500: Add PRCC power management Date: Thu, 28 Mar 2013 17:11:32 +0100 Message-ID: <1364487098-10319-7-git-send-email-rickard.andersson@stericsson.com> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com> References: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130328_121210_065035_268F5956 X-CRM114-Status: GOOD ( 20.93 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: hongbo.zhang@linaro.org, ulf.hansson@linaro.org, khilman@linaro.org, linus.walleij@stericsson.com, daniel.lezcano@linaro.org, rickard.andersson@stericsson.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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 When reaching a sleep state where the APE power domain is being turned off the context of the PRCC block needs to saved. When the power domain is turned on again the context is restored in order for the PRCC clocks to function correctly. Signed-off-by: Rickard Andersson --- drivers/clk/ux500/clk-prcc.c | 71 ++++++++++++++++++++++++++++++++++++- drivers/clk/ux500/clk.h | 5 +++ drivers/clk/ux500/u8500_clk.c | 82 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) diff --git a/drivers/clk/ux500/clk-prcc.c b/drivers/clk/ux500/clk-prcc.c index 7eee7f7..01739f7 100644 --- a/drivers/clk/ux500/clk-prcc.c +++ b/drivers/clk/ux500/clk-prcc.c @@ -3,7 +3,8 @@ * * Copyright (C) 2012 ST-Ericsson SA * Author: Ulf Hansson - * + * Rickard Andersson + * Jonas Aaberg * License terms: GNU General Public License (GPL) version 2 */ @@ -13,10 +14,13 @@ #include #include #include +#include #include #include "clk.h" +#define UX500_NR_PRCC_BANKS 5 + #define PRCC_PCKEN 0x000 #define PRCC_PCKDIS 0x004 #define PRCC_KCKEN 0x008 @@ -33,6 +37,12 @@ struct clk_prcc { int is_enabled; }; +static struct { + void __iomem *base; + u32 bus_clk; + u32 kern_clk; +} context_prcc[UX500_NR_PRCC_BANKS]; + /* PRCC clock operations. */ static int clk_prcc_pclk_enable(struct clk_hw *hw) @@ -162,3 +172,62 @@ struct clk *clk_reg_prcc_kclk(const char *name, return clk_reg_prcc(name, parent_name, phy_base, cg_sel, flags, &clk_prcc_kclk_ops); } + +void clk_prcc_save_context(void) +{ + int i; + + for (i = 0; i < UX500_NR_PRCC_BANKS; i++) { + context_prcc[i].bus_clk = + readl(context_prcc[i].base + PRCC_PCKSR); + context_prcc[i].kern_clk = + readl(context_prcc[i].base + PRCC_KCKSR); + } +} + +void clk_prcc_restore_context(void) +{ + int i; + + for (i = 0; i < UX500_NR_PRCC_BANKS; i++) { + writel(~context_prcc[i].bus_clk, + context_prcc[i].base + PRCC_PCKDIS); + writel(~context_prcc[i].kern_clk, + context_prcc[i].base + PRCC_KCKDIS); + + writel(context_prcc[i].bus_clk, + context_prcc[i].base + PRCC_PCKEN); + writel(context_prcc[i].kern_clk, + context_prcc[i].base + PRCC_KCKEN); + } +} + +int __init clk_prcc_init(struct platform_device *pdev) +{ + int i; + struct resource *res; + int ret = 0; + + for (i = 0; i < UX500_NR_PRCC_BANKS; i++) { + res = platform_get_resource(pdev, IORESOURCE_MEM, i); + if (!res) { + ret = -EINVAL; + goto err_iounmap; + } + + context_prcc[i].base = ioremap(res->start, resource_size(res)); + if (!context_prcc[i].base) { + ret = -ENOMEM; + goto err_iounmap; + } + } + + return ret; + + err_iounmap: + for (i = 0; i < UX500_NR_PRCC_BANKS; i++) { + if (context_prcc[i].base) + iounmap(context_prcc[i].base); + } + return ret; +} diff --git a/drivers/clk/ux500/clk.h b/drivers/clk/ux500/clk.h index c3e4491..3394fb8 100644 --- a/drivers/clk/ux500/clk.h +++ b/drivers/clk/ux500/clk.h @@ -11,6 +11,7 @@ #define __UX500_CLK_H #include +#include struct clk *clk_reg_prcc_pclk(const char *name, const char *parent_name, @@ -57,4 +58,8 @@ struct clk *clk_reg_prcmu_opp_volt_scalable(const char *name, unsigned long rate, unsigned long flags); +void clk_prcc_save_context(void); +void clk_prcc_restore_context(void); +int __init clk_prcc_init(struct platform_device *pdev); + #endif /* __UX500_CLK_H */ diff --git a/drivers/clk/ux500/u8500_clk.c b/drivers/clk/ux500/u8500_clk.c index 6b889a0..63ed580 100644 --- a/drivers/clk/ux500/u8500_clk.c +++ b/drivers/clk/ux500/u8500_clk.c @@ -12,9 +12,19 @@ #include #include #include +#include +#include #include #include "clk.h" +/* + * Number of PRCC parent clocks that needs to be + * enabled when saving/restoring PRCC context. + */ +#define NR_PRCC_PARENT_CLOCKS 5 + +struct clk *prcc_context_parent[NR_PRCC_PARENT_CLOCKS]; + void u8500_clk_init(void) { struct prcmu_fw_version *fw_version; @@ -522,3 +532,75 @@ void u8500_clk_init(void) U8500_CLKRST6_BASE, BIT(0), CLK_SET_RATE_GATE); clk_register_clkdev(clk, NULL, "rng"); } + +static void prcc_parents_enable(bool enable) +{ + int i; + + for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) { + if (enable) + clk_enable(prcc_context_parent[i]); + else + clk_disable(prcc_context_parent[i]); + } +} + +static int prcc_context_call(struct notifier_block *this, + unsigned long event, void *data) +{ + bool power_on = (bool)event; + + prcc_parents_enable(true); + + if (power_on) + clk_prcc_restore_context(); + else + clk_prcc_save_context(); + + prcc_parents_enable(false); + + return 0; +} + +static struct notifier_block prcc_context_notifier = { + .notifier_call = prcc_context_call, +}; + +static struct platform_driver u8500_clk_plat_driver = { + .driver = { + .name = "u8500-clk", + }, +}; + +static int __init u8500_clk_probe(struct platform_device *pdev) +{ + int ret; + int i; + + ret = clk_prcc_init(pdev); + if (ret) + return ret; + + for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) { + const int clusters[] = {1, 2, 3, 5, 6}; + char clkname[10]; + + snprintf(clkname, sizeof(clkname), "PERIPH%d", clusters[i]); + + prcc_context_parent[i] = clk_get_sys(clkname, NULL); + BUG_ON(IS_ERR(prcc_context_parent[i])); + clk_prepare(prcc_context_parent[i]); + } + + ret = pm_genpd_register_on_off_notifier(&pdev->dev, + &prcc_context_notifier); + return ret; +} + +static int __init u8500_clk_arch_init(void) +{ + return platform_driver_probe(&u8500_clk_plat_driver, + u8500_clk_probe); +} + +arch_initcall(u8500_clk_arch_init);