Skip to contentSkip to conversation

clocksource/drivers/sprd: Enable register for timer counter from 32 bit to 64 bit

PATCH In review Cixi Geng 2 participants 2 messages Sep 11, 2025 – Sep 22, 2025

Subsystems (2)
lore
Share & tools
lore

Cixi Geng

author
#0 lore raw

PATCH 1/1 clocksource/drivers/sprd: Enable register for timer counter from 32 bit to 64 bit

From: Enlin Mu <[email protected]>

Using 32 bit for suspend compensation, the max compensation time is 36 hours(working clock is 32k).In some IOT devices, the suspend time may be long, even exceeding 36 hours. Therefore, a 64 bit timer counter is needed for counting.

---
 drivers/clocksource/timer-sprd.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/clocksource/timer-sprd.c +15 -6
index 430cb99d8d79..742ee88b05d0 100644
@@ -30,6 +30,7 @@
 #define TIMER_VALUE_SHDW_HI	0x1c
 
 #define TIMER_VALUE_LO_MASK	GENMASK(31, 0)
+#define TIMER_VALUE_HI_MASK	GENMASK(31, 0)
 
 static void sprd_timer_enable(void __iomem *base, u32 flag)
 {
@@ -162,15 +163,23 @@ static struct timer_of suspend_to = {
 
 static u64 sprd_suspend_timer_read(struct clocksource *cs)
 {
-	return ~(u64)readl_relaxed(timer_of_base(&suspend_to) +
-				   TIMER_VALUE_SHDW_LO) & cs->mask;
+	u32 lo, hi;
+
+	lo = readl_relaxed(timer_of_base(&suspend_to) +
+			TIMER_VALUE_SHDW_LO);
+	hi = readl_relaxed(timer_of_base(&suspend_to) +
+			TIMER_VALUE_SHDW_HI);
+	return ~(((u64)hi << 32) | lo);
 }
 
 static int sprd_suspend_timer_enable(struct clocksource *cs)
 {
-	sprd_timer_update_counter(timer_of_base(&suspend_to),
-				  TIMER_VALUE_LO_MASK);
-	sprd_timer_enable(timer_of_base(&suspend_to), TIMER_CTL_PERIOD_MODE);
+	writel_relaxed(TIMER_VALUE_LO_MASK,
+			timer_of_base(&suspend_to) + TIMER_LOAD_LO);
+	writel_relaxed(TIMER_VALUE_HI_MASK,
+			timer_of_base(&suspend_to) + TIMER_LOAD_HI);
+	sprd_timer_enable(timer_of_base(&suspend_to),
+				TIMER_CTL_PERIOD_MODE|TIMER_CTL_64BIT_WIDTH);
 
 	return 0;
 }
@@ -186,7 +195,7 @@ static struct clocksource suspend_clocksource = {
 	.read	= sprd_suspend_timer_read,
 	.enable = sprd_suspend_timer_enable,
 	.disable = sprd_suspend_timer_disable,
-	.mask	= CLOCKSOURCE_MASK(32),
+	.mask	= CLOCKSOURCE_MASK(64),
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP,
 };
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 27 lines · Cixi Geng

From: Enlin Mu <[email protected]>

Using 32 bit for suspend compensation, the max compensation time is 36 hours(working clock is 32k).In some IOT devices, the suspend time may be long, even exceeding 36 hours. Therefore, a 64 bit timer counter is needed for counting.

---
  drivers/clocksource/timer-sprd.c | 21 +++++++++++++++------
  1 file changed, 15 insertions(+), 6 deletions(-)
drivers/clocksource/timer-sprd.c +1 -0
index 430cb99d8d79..742ee88b05d0 100644
@@ -30,6 +30,7 @@
  #define TIMER_VALUE_SHDW_HI	0x1c
 
  #define TIMER_VALUE_LO_MASK	GENMASK(31, 0)
+#define TIMER_VALUE_HI_MASK	GENMASK(31, 0)
 
  static void sprd_timer_enable(void __iomem *base, u32 flag)
  {
@@ -162,15 +163,23 @@ static struct timer_of suspend_to = {
 

drivers/clocksource/timer-sprd.c static struct timer_of suspend_to = { · line 171

Quoted 10 lines
drivers/clocksource/timer-sprd.c +6 -2
  static u64 sprd_suspend_timer_read(struct clocksource *cs)
  {
-	return ~(u64)readl_relaxed(timer_of_base(&suspend_to) +
-				   TIMER_VALUE_SHDW_LO) & cs->mask;
+	u32 lo, hi;
+
+	lo = readl_relaxed(timer_of_base(&suspend_to) +
+			TIMER_VALUE_SHDW_LO);
+	hi = readl_relaxed(timer_of_base(&suspend_to) +
+			TIMER_VALUE_SHDW_HI);

Can you align your code like the previous code?

Quoted 4 lines
drivers/clocksource/timer-sprd.c +1 -0
+	return ~(((u64)hi << 32) | lo);
  }
 
  static int sprd_suspend_timer_enable(struct clocksource *cs)

drivers/clocksource/timer-sprd.c static struct timer_of suspend_to = { · line 182

Quoted 10 lines
drivers/clocksource/timer-sprd.c +6 -3
  {
-	sprd_timer_update_counter(timer_of_base(&suspend_to),
-				  TIMER_VALUE_LO_MASK);
-	sprd_timer_enable(timer_of_base(&suspend_to), TIMER_CTL_PERIOD_MODE);
+	writel_relaxed(TIMER_VALUE_LO_MASK,
+			timer_of_base(&suspend_to) + TIMER_LOAD_LO);
+	writel_relaxed(TIMER_VALUE_HI_MASK,
+			timer_of_base(&suspend_to) + TIMER_LOAD_HI);
+	sprd_timer_enable(timer_of_base(&suspend_to),
+				TIMER_CTL_PERIOD_MODE|TIMER_CTL_64BIT_WIDTH);

Ditto. Otherwise LGTM.

Quoted 12 lines
drivers/clocksource/timer-sprd.c +1 -1
  	return 0;
  }
@@ -186,7 +195,7 @@ static struct clocksource suspend_clocksource = {
  	.read	= sprd_suspend_timer_read,
  	.enable = sprd_suspend_timer_enable,
  	.disable = sprd_suspend_timer_disable,
-	.mask	= CLOCKSOURCE_MASK(32),
+	.mask	= CLOCKSOURCE_MASK(64),
  	.flags	= CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP,
  };