Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1665785

[PATCH 20/23] clocksource/drivers/tcb_clksrc: Save timer context on suspend/resume

From Daniel Lezcano <daniel.lezcano@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 20/23] clocksource/drivers/tcb_clksrc: Save timer context on suspend/resume
Date 2017-06-14 14:50 +0200
Message-ID <tSfUf-5dU-59@gated-at.bofh.it> (permalink)
References <tSfKy-5an-33@gated-at.bofh.it> <tSfUd-5dU-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Alexandre Belloni <alexandre.belloni@free-electrons.com>

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 <alexandre.belloni@free-electrons.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/clocksource/tcb_clksrc.c | 51 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

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 <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
+#include <linux/syscore_ops.h>
 #include <linux/atmel_tc.h>
 
 
@@ -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
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL] clockevents for 4.13 Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:40 +0200
  [PATCH 02/23] clocksource/drivers/fttmr010: Fix the clock handling Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
  [PATCH 09/23] clocksource/drivers/fttmr010: Add AST2500 compatible string Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
  [PATCH 16/23] clocksource/drivers: Rename CLKSRC_OF to TIMER_OF Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
  [PATCH 03/23] clocksource/drivers/fttmr010: Merge FTTMR010 DT bindings Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
  [PATCH 01/23] arm: aspeed: Add clock-names property to timer node Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 11/23] Revert "clockevents: Add a clkevt-of mechanism like clksrc-of" Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 05/23] clocksource/drivers/fttmr010: Use state container Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 19/23] clocksource/drivers/fttmr010: Optimize sched_clock() Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 06/23] clocksource/drivers/fttmr010: Switch to use bitops Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 07/23] clocksource/drivers/fttmr010: Switch to use TIMER2 src Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 08/23] clocksource/drivers/fttmr010: Merge Moxa into FTTMR010 Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 10/23] clocksource/drivers/fttmr010: Fix aspeed-2500 initialization Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 17/23] clocksource/drivers: Rename CLKSRC_ACPI to TIMER_ACPI Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 14/23] clocksource/drivers: Rename CLOCKSOURCE_ACPI_DECLARE to TIMER_ACPI_DECLARE Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 18/23] clocksource/drivers: Add an alias macro CLOCKSOURCE_OF_DECLARE Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 15/23] clocksource/drivers: Rename clksrc table to timer Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 04/23] clocksource/drivers/fttmr010: Drop Gemini specifics Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 20/23] clocksource/drivers/tcb_clksrc: Save timer context on suspend/resume Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 21/23] clocksource/drivers: Add timer-of common init routine Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 22/23] clocksource/drivers/fttmr010: Implement delay timer Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200
    [PATCH 23/23] clocksource/drivers/fttmr010: Factor out clock read code Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-06-14 14:50 +0200

csiph-web