From patchwork Tue Apr 11 15:48:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 9675661 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 7F320600CB for ; Tue, 11 Apr 2017 15:48:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 733522861C for ; Tue, 11 Apr 2017 15:48:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 680D32863B; Tue, 11 Apr 2017 15:48:57 +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,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 044752861C for ; Tue, 11 Apr 2017 15:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=muf4R0pm6ZPSdRKoYngpTKRz+QqHLWIo9zScSdw3ULI=; b=g/1 zmYm8vCaOAwj0QVzn4OBKmuljDRuBE7Hvps5H5TK3VNe2LIdkwGpYbWOeoCTI86jaLrqHjt18haOH nCZZfvbwPw1Ix+3Qto8w/j9peVIvQ3ju0FJW6f+vuQCHOwILlzsUrCKwPTEdxO1HzNQSvyPfrdwKF XfD61PsFIgvwzZdMZeb23aJbjYwF9v3PVU95glJUCXqEVSumaoUqPnOZ2tfY5EOQr+JFhWYRDvm0w EzyqmmqTnCGL/WH4T7sn+0YG+TD0vDeAimI42qew8+6GgzNFyIH1ibCpF9gJbDeKRc0cUpsz2okfR a97U5+P0fzMYq+tBqqtB0bfbJZI0TYA==; 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 1cxy2K-0006Uq-GI; Tue, 11 Apr 2017 15:48:56 +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 1cxy2H-0006Ol-Kk for linux-arm-kernel@lists.infradead.org; Tue, 11 Apr 2017 15:48:55 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id B730B207D6; Tue, 11 Apr 2017 17:48:30 +0200 (CEST) Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 91EB02076E; Tue, 11 Apr 2017 17:48:30 +0200 (CEST) From: Alexandre Belloni To: Daniel Lezcano , Nicolas Ferre , Thomas Gleixner Subject: [PATCH] clockevents/tcb_clksrc: implement suspend/resume Date: Tue, 11 Apr 2017 17:48:26 +0200 Message-Id: <20170411154826.5883-1-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170411_084853_823936_75FF0772 X-CRM114-Status: GOOD ( 11.89 ) 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: Boris Brezillon , 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 On sama5d2, power to the core may be cut while entering suspend mode. It is necessary to save and restore the TCB registers. Signed-off-by: Alexandre Belloni --- drivers/clocksource/tcb_clksrc.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c index d4ca9962a759..57f5d72328f4 100644 --- a/drivers/clocksource/tcb_clksrc.c +++ b/drivers/clocksource/tcb_clksrc.c @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -40,6 +41,14 @@ */ static void __iomem *tcaddr; +static struct +{ + u32 cmr; + u32 imr; + u32 rc; + bool clken; +} tcb_cache[3]; +static u32 bmr_cache; static u64 tc_get_cycles(struct clocksource *cs) { @@ -61,12 +70,49 @@ 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); +} + 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