From patchwork Mon Nov 24 13:04:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kachhap X-Patchwork-Id: 5366431 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 27AD7C11AC for ; Mon, 24 Nov 2014 13:26:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1AA33203B6 for ; Mon, 24 Nov 2014 13:26:47 +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 09A0620107 for ; Mon, 24 Nov 2014 13:26:46 +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 1XstcL-0001rm-T9; Mon, 24 Nov 2014 13:23:49 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XstaP-0000DC-Hg for linux-arm-kernel@lists.infradead.org; Mon, 24 Nov 2014 13:21:50 +0000 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NFJ003FZP3SDDD0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 24 Nov 2014 22:21:28 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.122]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 75.32.17016.7D033745; Mon, 24 Nov 2014 22:21:28 +0900 (KST) X-AuditID: cbfee68d-f79296d000004278-30-547330d76aca Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id E6.C6.09430.7D033745; Mon, 24 Nov 2014 22:21:27 +0900 (KST) Received: from chromebld-server.sisodomain.com ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NFJ00EZLOLG6V60@mmp2.samsung.com>; Mon, 24 Nov 2014 22:21:27 +0900 (KST) From: Amit Daniel Kachhap To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH RFC v2 11/12] drivers: soc: samsung: Add support for clock rate save/restore in power domain Date: Mon, 24 Nov 2014 18:34:15 +0530 Message-id: <1416834256-11225-11-git-send-email-amit.daniel@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1416834256-11225-1-git-send-email-amit.daniel@samsung.com> References: <1416833572-6880-1-git-send-email-amit.daniel@samsung.com> <1416834256-11225-1-git-send-email-amit.daniel@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeLIzCtJLcpLzFFi42JZI2JSpXvDoDjEYFYrm0XD1RCL+UfOsVo8 u7WXyaJ3wVU2i6ebHzNZbHp8jdXi8q45bBafe48wWsw4v4/JYtHWL+wWZ05fYrU4/Kad1eL4 2nAHXo9NqzrZPO5c28PmcehwB6PH5iX1HluutrN49G1ZxejxeZNcAHsUl01Kak5mWWqRvl0C V8btxd/YC5q0Kzafe8PewPhdqYuRk0NCwETi5KG7TBC2mMSFe+vZuhi5OIQEljJK7J2/jwmm 6NLxxcwQiemMEic2PYByJjBJHOnYwwhSxSZgLPFz5372LkYODhEBb4nl1xRBapgFVjNJbG3/ ADZJWCBPYuvUPrAaFgFViQ8vREHCvAIeEncmtbKAhCUEFCTmTLIBCXMChV8cbIFa1cIocenx XFYQR0LgErvEkj9/2EGqWAQEJL5N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k3NDYxNzU2tTSxMDGzVBLnvXEzN0RIID2xJDU7NbUgtQimj4mDU6qBMTTvtGPa 3akeISaWmxkmTFaY+7jquatD/8aditt3y+vWh25329l0RlFYPfu4zz+FrOmC7jKvEtxNXm7M 3MiZtXbjdPtvj5/Mj9ZattAs8TkHa0J3GesDz7iFctYJueEsDKey89UjnqySu/2i331y1r0p 33jnHK5N/GvmnVuaVLz805xFdUsnKrEUZyQaajEXFScCAFeVs9TdAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141124_052149_789236_9ABC0DD4 X-CRM114-Status: GOOD ( 16.83 ) X-Spam-Score: -5.0 (-----) Cc: devicetree@vger.kernel.org, ulf.hansson@linaro.org, kgene.kim@samsung.com, khilman@kernel.org, pankaj.dubey@samsung.com, linux-pm@vger.kernel.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, Amit Daniel Kachhap , geert@linux-m68k.org, s.nawrocki@samsung.com 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: , MIME-Version: 1.0 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_LOW, T_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 While turning power domain to on/off, some clocks rates might change and need to be saved/restored in the Exynos7 SOC. This patch adds the framework for saving those clocks before power off and restoring it back after power on operation. Signed-off-by: Amit Daniel Kachhap --- .../bindings/arm/exynos/power_domain.txt | 7 ++ drivers/soc/samsung/pm_domains.c | 74 ++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt index c48769e..97fec1b 100644 --- a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt +++ b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt @@ -32,6 +32,11 @@ Optional Properties: before turning off a power domain. - pd-off-en-clock-names: clocks can be specified as, - clkN: N can vary between 0-30. +- pd-rate-clocks: List of clock handles. The rates of these clocks are required + to be saved before turning off a power domain and restoring after turning + on a power domain. +- pd-rate-clock-names: clocks can be specified as, + - clkN: N can vary between 0-30. - parents: phandle of parent power domains. Node of a device using power domains must have a samsung,power-domain property @@ -55,6 +60,8 @@ Example: pd-on-en-clock-names = "clk0", "clk1"; pd-off-en-clocks = <&clock CLK_IP1>, <&clock CLK_IP2>, pd-off-en-clock-names = "clk0", "clk1"; + pd-rate-clocks = <&clock CLK_IP3>, <&clock CLK_IP4>, + pd-rate-clock-names = "clk0", "clk1"; #power-domain-cells = <0>; }; diff --git a/drivers/soc/samsung/pm_domains.c b/drivers/soc/samsung/pm_domains.c index 5407eb7..a235277 100644 --- a/drivers/soc/samsung/pm_domains.c +++ b/drivers/soc/samsung/pm_domains.c @@ -36,6 +36,12 @@ struct clk_enable_list { unsigned int en_status; }; +struct clk_rate_list { + struct clk **clks; + unsigned int *rates; + unsigned int count; +}; + struct clk_parent_list { struct clk **clks; struct clk **parent_clks; @@ -53,6 +59,7 @@ struct exynos_pm_domain { struct generic_pm_domain pd; struct clk_enable_list *clk_pd_on; struct clk_enable_list *clk_pd_off; + struct clk_rate_list *clk_rate; struct clk_parent_list *clk_parent; }; @@ -198,6 +205,49 @@ static int pd_init_parent_clocks(struct platform_device *pdev, return 0; } +static int pd_init_rate_clocks(struct platform_device *pdev, + struct device_node *np, struct exynos_pm_domain *pd) +{ + struct clk_rate_list *list; + char propname[32], clk_name[8]; + int count, i; + struct clk *clk = ERR_PTR(-ENOENT); + + list = devm_kzalloc(&pdev->dev, sizeof(*list), GFP_KERNEL); + if (!list) + return -ENOMEM; + + pd->clk_rate = list; + snprintf(propname, sizeof(propname), "pd-rate-clock-names"); + + count = of_property_count_strings(np, propname); + if (!count || count > MAX_CLK_PER_DOMAIN) + return -EINVAL; + + list->count = count; + list->clks = devm_kzalloc(&pdev->dev, sizeof(*list->clks) * count, + GFP_KERNEL); + if (!list->clks) + return -ENOMEM; + + list->rates = devm_kzalloc(&pdev->dev, sizeof(list->rates) * count, + GFP_KERNEL); + if (!list->rates) + return -ENOMEM; + + for (i = 0; i < count; i++) { + snprintf(clk_name, sizeof(clk_name), "clk%d", i); + clk = exynos_pd_clk_get(np, "pd-rate", clk_name); + if (IS_ERR(clk)) { + dev_err(&pdev->dev, "%s clock not found\n", clk_name); + return -EINVAL; + } + list->clks[i] = clk; + } + dev_info(&pdev->dev, "pd rate clocks initialised\n"); + return 0; +} + static void exynos_pd_poweron_prepare(struct exynos_pm_domain *pd) { struct clk_enable_list *en_list; @@ -220,6 +270,7 @@ static void exynos_pd_post_poweron(struct exynos_pm_domain *pd) { struct clk_parent_list *p_list; struct clk_enable_list *en_list; + struct clk_rate_list *rt_list; int i; p_list = pd->clk_parent; @@ -229,6 +280,17 @@ static void exynos_pd_post_poweron(struct exynos_pm_domain *pd) clk_set_parent(p_list->clks[i], p_list->parent_clks[i]); } + rt_list = pd->clk_rate; + if (rt_list) { + /* restore the rate from the rate clock list */ + for (i = 0; i < rt_list->count; i++) { + if (!rt_list->rates[i]) + continue; + clk_set_rate(rt_list->clks[i], rt_list->rates[i]); + rt_list->rates[i] = 0; + } + } + en_list = pd->clk_pd_on; if (!en_list) return; @@ -246,6 +308,7 @@ static void exynos_pd_poweroff_prepare(struct exynos_pm_domain *pd) { struct clk_parent_list *p_list; struct clk_enable_list *en_list; + struct clk_rate_list *rt_list; int i; en_list = pd->clk_pd_off; @@ -259,6 +322,13 @@ static void exynos_pd_poweroff_prepare(struct exynos_pm_domain *pd) } } + rt_list = pd->clk_rate; + if (rt_list) { + /* save the rate from the rate clock list */ + for (i = 0; i < rt_list->count; i++) + rt_list->rates[i] = clk_get_rate(rt_list->clks[i]); + } + p_list = pd->clk_parent; if (!p_list) return; @@ -366,6 +436,10 @@ static int exynos_power_domain_probe(struct platform_device *pdev) if (pd_init_parent_clocks(pdev, np, pd)) return -EINVAL; + if (of_find_property(np, "pd-rate-clocks", NULL)) + if (pd_init_rate_clocks(pdev, np, pd)) + return -EINVAL; + on = pd_ops->pd_status(pd->base); pm_genpd_init(&pd->pd, NULL, !on);