From patchwork Mon Oct 27 13:47:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 5160811 Return-Path: X-Original-To: patchwork-linux-rockchip@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 8336F9F318 for ; Mon, 27 Oct 2014 13:48:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF94520256 for ; Mon, 27 Oct 2014 13:48:44 +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 CED40201E4 for ; Mon, 27 Oct 2014 13:48:43 +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 1Xikf5-0004lR-HX; Mon, 27 Oct 2014 13:48:43 +0000 Received: from mail-pa0-f65.google.com ([209.85.220.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xikf4-0004f3-4J for linux-rockchip@lists.infradead.org; Mon, 27 Oct 2014 13:48:42 +0000 Received: by mail-pa0-f65.google.com with SMTP id eu11so2667707pac.8 for ; Mon, 27 Oct 2014 06:48:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nx4fECQt2MT+nedb9WHeK5TanpUctHiS7bdJ7RmUgV8=; b=FoDRK/3uhZccqXUygyKoJOjsUIFMqu7NBNiX6rg0qaYWBUsRpfBtJOOeL7B9WmbWw4 qMgIb/UdvZVyG4DpXHjAFSmmYkYE7tG8aPMOJOBO/EsMWJGpGQt34WI5FoQsjyHcbmFV p5F+EFTToe1+/aJo8ksuATCRrkBFEsz7AjqybbV69qQRqqfTwfPW+12Ai9G3rdN20CuP sWASRldtJlvk8Xli3vHzv5xuCt3ZovQUrXr3MVP1Yr74qu6r/fqE0NfWjQO9JtIIC/Nb TA8V/6ct2gXNo5WB7qwk19IYmai//m3nsCU8i+t1sql4K+How/FReTfAHrDUiZOoCwKK 9gKw== X-Received: by 10.70.140.4 with SMTP id rc4mr24666728pdb.108.1414417700857; Mon, 27 Oct 2014 06:48:20 -0700 (PDT) Received: from localhost.localdomain ([58.22.7.114]) by mx.google.com with ESMTPSA id cc2sm9971830pbd.62.2014.10.27.06.48.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 27 Oct 2014 06:48:19 -0700 (PDT) From: Chris Zhong To: heiko@sntech.de, dianders@chromium.org Subject: [PATCH v5 3/6] clk: rockchip: RK3288: add suspend and resume Date: Mon, 27 Oct 2014 21:47:27 +0800 Message-Id: <1414417650-19402-4-git-send-email-zyw@rock-chips.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414417650-19402-1-git-send-email-zyw@rock-chips.com> References: <1414417650-19402-1-git-send-email-zyw@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141027_064842_188135_CB350319 X-CRM114-Status: GOOD ( 15.08 ) X-Spam-Score: -0.5 (/) Cc: Mark Rutland , Russell King , Pawel Moll , Ian Campbell , Linus Walleij , khilman@kernel.org, linux-rockchip@lists.infradead.org, Rob Herring , Chris Zhong , mturquette@linaro.org, Tony Xie X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 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 save and restore some clks, which might be changed in suspend. Signed-off-by: Tony Xie Signed-off-by: Chris Zhong Reviewed-by: Doug Anderson Tested-by: Doug Anderson --- Changes in v5: - modify comments Changes in v4: None Changes in v3: None Changes in v2: - __raw_readl/__raw_writel replaced by readl_relaxed/writel_relaxed drivers/clk/rockchip/clk-rk3288.c | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/clk/rockchip/clk-rk3288.c b/drivers/clk/rockchip/clk-rk3288.c index 2327829..94da06c 100644 --- a/drivers/clk/rockchip/clk-rk3288.c +++ b/drivers/clk/rockchip/clk-rk3288.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "clk.h" @@ -762,6 +763,64 @@ static const char *rk3288_critical_clocks[] __initconst = { "hclk_peri", }; +#ifdef CONFIG_PM_SLEEP +static void __iomem *rk3288_cru_base; +static const int rk3288_saved_cru_reg_ids[] = { + RK3288_MODE_CON, + RK3288_CLKSEL_CON(0), + RK3288_CLKSEL_CON(1), + RK3288_CLKSEL_CON(10), + RK3288_CLKSEL_CON(33), + RK3288_CLKSEL_CON(37), +}; + +static u32 rk3288_saved_cru_regs[ARRAY_SIZE(rk3288_saved_cru_reg_ids)]; + +/* + * Cru will be reset in maskrom when system wake up from fastboot. + * The apll/cpll/gpll will be set into slow mode in maskrom. + * So save them before suspend, restore them after resume. + */ +static int rk3288_clk_suspend(void) +{ + int i, reg_id; + + for (i = 0; i < ARRAY_SIZE(rk3288_saved_cru_reg_ids); i++) { + reg_id = rk3288_saved_cru_reg_ids[i]; + + rk3288_saved_cru_regs[i] = + readl_relaxed(rk3288_cru_base + reg_id); + } + return 0; +} + +static void rk3288_clk_resume(void) +{ + int i, reg_id; + + for (i = ARRAY_SIZE(rk3288_saved_cru_reg_ids) - 1; i >= 0; i--) { + reg_id = rk3288_saved_cru_reg_ids[i]; + + writel_relaxed(rk3288_saved_cru_regs[i] | 0xffff0000, + rk3288_cru_base + reg_id); + } +} + +static struct syscore_ops rk3288_clk_syscore_ops = { + .suspend = rk3288_clk_suspend, + .resume = rk3288_clk_resume, +}; + +static void rk3288_clk_sleep_init(void __iomem *reg_base) +{ + rk3288_cru_base = reg_base; + register_syscore_ops(&rk3288_clk_syscore_ops); +} + +#else /* CONFIG_PM_SLEEP */ +static void rk3288_clk_sleep_init(void __iomem *reg_base) {} +#endif + static void __init rk3288_clk_init(struct device_node *np) { void __iomem *reg_base; @@ -810,5 +869,6 @@ static void __init rk3288_clk_init(struct device_node *np) ROCKCHIP_SOFTRST_HIWORD_MASK); rockchip_register_restart_notifier(RK3288_GLB_SRST_FST); + rk3288_clk_sleep_init(reg_base); } CLK_OF_DECLARE(rk3288_cru, "rockchip,rk3288-cru", rk3288_clk_init);