From patchwork Wed Jun 14 12:39:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 105503 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp271920qgd; Wed, 14 Jun 2017 05:42:22 -0700 (PDT) X-Received: by 10.98.74.194 with SMTP id c63mr423349pfj.58.1497444142198; Wed, 14 Jun 2017 05:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497444142; cv=none; d=google.com; s=arc-20160816; b=xHe32As96c8CScPXiQzwQHho6SknCR0c+VmGI8GB+lkYdieBCS6sFtFVcNEIm9tOe1 Q4Dm5pmOk7d9idflg9PjKnYrEliWJGE9NSb7ICKgsK6euA5zNRFBM1uYRIUWXQSlyQ1c JIodbm27CiJ00aCR+ZexeFpNqm0OIE43CiTd91gs4EqPhxfXfAUuWNqoR7jXO+VWjgJt kqgB1dEQnlp1dlC3Aok4IfkVF+0D11MkNOT5IM+16XeXOcGbctU85CUCiWze6d2IvTUY pGJVS7RXualocHk5wkn9CWxaV6s5kMl1xfUI7gTGvGGwVy2e76PageYbI+WbDxNqICSh aIEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=K1xWgYiNDJXhWeMiZ86uYArKySkZl5+SdjrhjZsMJno=; b=XN0BJkBCXcaaeIaKKdG5bVoJa0Sujl9E1GqT6eVnIIGE+v6AuWc4B/ulwFuiYWtsVT SQjWDz46PBXxmGTyBnBJYeNeJrSVKgA+t2e8wZ8frF7kp5fww5nRD1xrrj+GY2/E+pNK rx8XquPdC36uUqMlghMCfD7UQUVm4/aVRY8kzZkVf/D5EjKz1TM1JgnkmpHHqOYtGjrL zmL5cfWSheGD20qwLuYa012jRPkUdTCJ1w86sAmMDf5Tr8tpg6iUiupLvikO2GEzM4yB ySmsAOkA8oWrBK9VRvQ84afoh6xEEBgVkQZlji0H2qB7LGUOIHPtNt6agFkZ8v4nxZvq rOZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=UniCp7k1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6si629373plj.223.2017.06.14.05.42.21; Wed, 14 Jun 2017 05:42:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=UniCp7k1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752673AbdFNMmS (ORCPT + 25 others); Wed, 14 Jun 2017 08:42:18 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:35732 "EHLO mail-wr0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbdFNMmO (ORCPT ); Wed, 14 Jun 2017 08:42:14 -0400 Received: by mail-wr0-f176.google.com with SMTP id q97so188269949wrb.2 for ; Wed, 14 Jun 2017 05:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K1xWgYiNDJXhWeMiZ86uYArKySkZl5+SdjrhjZsMJno=; b=UniCp7k1RYWgSkHGYipOr3pgIYqTvkhQ8yFCsjdMUzwlhisskAy17nvlZbGLNgMHtR SzTxdImPEYQ2lCR2DQJ6PEZLkBOjmUHHmudZMW66fFhmRcejdJ7E5fCvYnv3zi9poaz5 BUCuWP0thfEwLpdBufqLLVkaLVyh7Y06SAPD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=K1xWgYiNDJXhWeMiZ86uYArKySkZl5+SdjrhjZsMJno=; b=gRPVNeDby+RWhjDI49N7VQGZ6BN6WOvynUxgt4DhTYm6tsgKNrPfHb/2bqep/ShysU 7DmJfznv3TGjbRqGfAK5PINM+/vhMj7WWo1h/V9/8e2K0EB+i9uVSb55TpGTXvZU+4vZ U1MaZHb/vBbwCxFCkwy/di3IpEgwwA/Wg6XmdM1MpBNAFWhc2PdLdt+wpXCrdBomOdNp i1cr8CbKv+1Wu3/mHmGBu0Qtu5JlTT+gMlqldQPZSvEPWtwZlFihna8oOBEXOsOBqGMw fnrW5rNC80jy85QFpA4fi8BHlTZN2FyH95MUtJ1BH+xZNW47sw6SL37zKyIF73ByAX9D XCrg== X-Gm-Message-State: AKS2vOzwvbLm4jxrJbJUuyy6W2J+6sbtJ/zV/aFWGU9WJcyGixvsAeKW /5auPNrvPEyKSd8E X-Received: by 10.223.179.86 with SMTP id k22mr389732wrd.5.1497444133367; Wed, 14 Jun 2017 05:42:13 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:19a:b336:54d7:46e9]) by smtp.gmail.com with ESMTPSA id 80sm1457015wmg.17.2017.06.14.05.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 05:42:12 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Alexandre Belloni , Nicolas Ferre , linux-arm-kernel@lists.infradead.org (moderated list:ATMEL Timer Count...) Subject: [PATCH 20/23] clocksource/drivers/tcb_clksrc: Save timer context on suspend/resume Date: Wed, 14 Jun 2017 14:39:41 +0200 Message-Id: <1497443984-12371-20-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497443984-12371-1-git-send-email-daniel.lezcano@linaro.org> References: <20170614123800.GH2261@mai> <1497443984-12371-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni 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 Signed-off-by: Daniel Lezcano --- drivers/clocksource/tcb_clksrc.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) -- 2.7.4 diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c index d4ca996..828729c 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,54 @@ 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 < ARRAY_SIZE(tcb_cache); 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 < ARRAY_SIZE(tcb_cache); i++) { + /* Restore registers for the channel, RA and RB are not used */ + writel(tcb_cache[i].cmr, tcaddr + ATMEL_TC_REG(i, CMR)); + writel(tcb_cache[i].rc, tcaddr + ATMEL_TC_REG(i, RC)); + writel(0, tcaddr + ATMEL_TC_REG(i, RA)); + writel(0, tcaddr + ATMEL_TC_REG(i, RB)); + /* Disable all the interrupts */ + writel(0xff, tcaddr + ATMEL_TC_REG(i, IDR)); + /* Reenable interrupts that were enabled before suspending */ + writel(tcb_cache[i].imr, tcaddr + ATMEL_TC_REG(i, IER)); + /* Start the clock if it was used */ + if (tcb_cache[i].clken) + writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(i, CCR)); + } + + /* Dual channel, chain channels */ + writel(bmr_cache, tcaddr + ATMEL_TC_BMR); + /* Finally, trigger all the channels*/ + 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