From patchwork Thu Feb 2 18:51:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 9553065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4992760405 for ; Thu, 2 Feb 2017 18:53:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C275281E1 for ; Thu, 2 Feb 2017 18:53:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30DAB28425; Thu, 2 Feb 2017 18:53:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB5EC281E1 for ; Thu, 2 Feb 2017 18:53:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZMVB-0006oS-RB; Thu, 02 Feb 2017 18:53:01 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZMUw-0006Nh-9R for linux-arm-kernel@lists.infradead.org; Thu, 02 Feb 2017 18:52:51 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 3FE4420DA7; Thu, 2 Feb 2017 19:52:26 +0100 (CET) Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1E2FA20DAF; Thu, 2 Feb 2017 19:52:16 +0100 (CET) From: Alexandre Belloni To: Nicolas Ferre Subject: [PATCH 04/23] TCB backup Date: Thu, 2 Feb 2017 19:51:54 +0100 Message-Id: <20170202185213.21698-4-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170202185213.21698-1-alexandre.belloni@free-electrons.com> References: <20170202185213.21698-1-alexandre.belloni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170202_105246_577695_15AF7C9F X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Alexandre Belloni --- drivers/clocksource/tcb_clksrc.c | 55 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c index d4ca9962a759..e49f6cf2daf3 100644 --- a/drivers/clocksource/tcb_clksrc.c +++ b/drivers/clocksource/tcb_clksrc.c @@ -3,7 +3,7 @@ #include #include #include - +#include #include #include #include @@ -39,7 +39,15 @@ * For deeper system sleep states, this will be mandatory... */ -static void __iomem *tcaddr; +void __iomem *tcaddr; +static struct +{ + u32 cmr; + u32 imr; + u32 rc; + bool clken; +} tcb_cache[3]; +u32 bmr_cache; static u64 tc_get_cycles(struct clocksource *cs) { @@ -61,12 +69,55 @@ static u64 tc_get_cycles32(struct clocksource *cs) return __raw_readl(tcaddr + ATMEL_TC_REG(0, CV)); } +void tc_clksrc_suspend(struct clocksource *cs) +{ + int i; + + for (i = 0; i < 3; i++) { + tcb_cache[i].cmr = readl(tcaddr + ATMEL_TC_REG(i, CMR)); + tcb_cache[i].imr = readl(tcaddr + ATMEL_TC_REG(i, IMR)); + tcb_cache[i].rc = readl(tcaddr + ATMEL_TC_REG(i, RC)); + tcb_cache[i].clken = !!(readl(tcaddr + ATMEL_TC_REG(i, SR)) & + ATMEL_TC_CLKSTA); + } + + bmr_cache = readl(tcaddr + ATMEL_TC_BMR); +} + +void tc_clksrc_resume(struct clocksource *cs) +{ + int i; + + for (i = 0; i < 3; i++) { + __raw_writel(tcb_cache[i].cmr, tcaddr + ATMEL_TC_REG(i, CMR)); + __raw_writel(0, tcaddr + ATMEL_TC_REG(i, RA)); + __raw_writel(0, tcaddr + ATMEL_TC_REG(i, RB)); + __raw_writel(tcb_cache[i].rc, tcaddr + ATMEL_TC_REG(i, RC)); + __raw_writel(0xff, tcaddr + ATMEL_TC_REG(i, IDR)); + __raw_writel(tcb_cache[i].imr, tcaddr + ATMEL_TC_REG(i, IER)); + if (tcb_cache[i].clken) + __raw_writel(ATMEL_TC_CLKEN, tcaddr + + ATMEL_TC_REG(i, CCR)); + } + + writel(bmr_cache, tcaddr + ATMEL_TC_BMR); + writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); + + for (i = 0; i < 3; i++) { + tcb_cache[i].cmr = readl(tcaddr + ATMEL_TC_REG(i, CMR)); + tcb_cache[i].imr = readl(tcaddr + ATMEL_TC_REG(i, IMR)); + tcb_cache[i].rc = readl(tcaddr + ATMEL_TC_REG(i, RC)); + } +} + static struct clocksource clksrc = { .name = "tcb_clksrc", .rating = 200, .read = tc_get_cycles, .mask = CLOCKSOURCE_MASK(32), .flags = CLOCK_SOURCE_IS_CONTINUOUS, + .suspend = tc_clksrc_suspend, + .resume = tc_clksrc_resume, }; #ifdef CONFIG_GENERIC_CLOCKEVENTS