Skip to contentSkip to conversation

rtc suspend()/resume() restores system clock

PATCH In review David Brownell 3 participants 6 messages Feb 22, 2007 – Feb 23, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 6/6 rtc suspend()/resume() restores system clock

RTC class suspend/resume support, re-initializing the system clock on resume from the clock used to initialize it at boot time.

- Inlining the same code used by ARM, which saves and restores the delta between a selected RTC and the current system wall-clock time.

- Removes calls to that ARM code from AT91, OMAP, and S3C RTCs.

This goes on top of the patch series removing "struct class_device" usage from the RTC framework. That makes class suspend()/resume() work.

---
 drivers/rtc/Kconfig          |   24 +++++++++----
 drivers/rtc/class.c          |   74 +++++++++++++++++++++++++++++++++++++++++++
 drivers/rtc/rtc-at91rm9200.c |   30 -----------------
 drivers/rtc/rtc-omap.c       |   17 ---------
 drivers/rtc/rtc-s3c.c        |   22 ------------
 5 files changed, 91 insertions(+), 76 deletions(-)
drivers/rtc/Kconfig +17 -7
Index: at91/drivers/rtc/Kconfig
===================================================================
@@ -21,21 +21,31 @@ config RTC_CLASS
 	  will be called rtc-class.
 
 config RTC_HCTOSYS
-	bool "Set system time from RTC on startup"
+	bool "Set system time from RTC on startup and resume"
 	depends on RTC_CLASS = y
 	default y
 	help
-	  If you say yes here, the system time will be set using
-	  the value read from the specified RTC device. This is useful
-	  in order to avoid unnecessary fsck runs.
+	  If you say yes here, the system time (wall clock) will be set using
+	  the value read from a specified RTC device. This is useful to avoid
+	  unnecessary fsck runs at boot time, and to network better.
 
 config RTC_HCTOSYS_DEVICE
-	string "The RTC to read the time from"
+	string "RTC used to set the system time"
 	depends on RTC_HCTOSYS = y
 	default "rtc0"
 	help
-	  The RTC device that will be used as the source for
-	  the system time, usually rtc0.
+	  The RTC device that will be used to (re)initialize the system
+	  clock, usually rtc0.  Initialization is done when the system
+	  starts up, and when it resumes from a low power state.
+	  
+	  This clock should be battery-backed, so that it reads the correct
+	  time when the system boots from a power-off state.  Otherwise, your
+	  system will need an external clock source (like an NTP server).
+
+	  If the clock you specify here is not battery backed, it may still
+	  be useful to reinitialize system time when resuming from system 
+	  sleep states.  Do not specify an RTC here unless it stays powered
+	  during all this system's supported sleep states.
 
 config RTC_DEBUG
 	bool "RTC debug support"
drivers/rtc/class.c +74 -0

86 lines not on this page · raw message

drivers/rtc/rtc-at91rm9200.c +0 -30
Index: at91/drivers/rtc/rtc-at91rm9200.c
===================================================================
@@ -348,21 +348,10 @@ static int __exit at91_rtc_remove(struct
 
 /* AT91RM9200 RTC Power management control */
 
-static struct timespec at91_rtc_delta;
 static u32 at91_rtc_imr;
 
 static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct rtc_time tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-
-	/* calculate time delta for suspend */
-	at91_rtc_readtime(&pdev->dev, &tm);
-	rtc_tm_to_time(&tm, &time.tv_sec);
-	save_time_delta(&at91_rtc_delta, &time);
-
 	/* this IRQ is shared with DBGU and other hardware which isn't
 	 * necessarily doing PM like we are...
 	 */
@@ -374,36 +363,17 @@ static int at91_rtc_suspend(struct platf
 		else
 			at91_sys_write(AT91_RTC_IDR, at91_rtc_imr);
 	}
-
-	pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
-		1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
-		tm.tm_hour, tm.tm_min, tm.tm_sec);
-
 	return 0;
 }
 
 static int at91_rtc_resume(struct platform_device *pdev)
 {
-	struct rtc_time tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-
-	at91_rtc_readtime(&pdev->dev, &tm);
-	rtc_tm_to_time(&tm, &time.tv_sec);
-	restore_time_delta(&at91_rtc_delta, &time);
-
 	if (at91_rtc_imr) {
 		if (device_may_wakeup(&pdev->dev))
 			disable_irq_wake(AT91_ID_SYS);
 		else
 			at91_sys_write(AT91_RTC_IER, at91_rtc_imr);
 	}
-
-	pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
-		1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
-		tm.tm_hour, tm.tm_min, tm.tm_sec);
-
 	return 0;
 }
 #else
drivers/rtc/rtc-omap.c +0 -17
Index: at91/drivers/rtc/rtc-omap.c
===================================================================
@@ -488,19 +488,10 @@ static int __devexit omap_rtc_remove(str
 
 #ifdef CONFIG_PM
 
-static struct timespec rtc_delta;
 static u8 irqstat;
 
 static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct rtc_time rtc_tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-	omap_rtc_read_time(NULL, &rtc_tm);
-	rtc_tm_to_time(&rtc_tm, &time.tv_sec);
-
-	save_time_delta(&rtc_delta, &time);
 	irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG);
 
 	/* FIXME the RTC alarm is not currently acting as a wakeup event
@@ -517,14 +508,6 @@ static int omap_rtc_suspend(struct platf
 
 static int omap_rtc_resume(struct platform_device *pdev)
 {
-	struct rtc_time rtc_tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-	omap_rtc_read_time(NULL, &rtc_tm);
-	rtc_tm_to_time(&rtc_tm, &time.tv_sec);
-
-	restore_time_delta(&rtc_delta, &time);
 	if (device_may_wakeup(&pdev->dev))
 		disable_irq_wake(omap_rtc_alarm);
 	else
drivers/rtc/rtc-s3c.c +0 -22
Index: at91/drivers/rtc/rtc-s3c.c
===================================================================
@@ -548,37 +548,15 @@ static int ticnt_save;
 
 static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct rtc_time tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-
 	/* save TICNT for anyone using periodic interrupts */
-
 	ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
-
-	/* calculate time delta for suspend */
-
-	s3c_rtc_gettime(&pdev->dev, &tm);
-	rtc_tm_to_time(&tm, &time.tv_sec);
-	save_time_delta(&s3c_rtc_delta, &time);
 	s3c_rtc_enable(pdev, 0);
-
 	return 0;
 }
 
 static int s3c_rtc_resume(struct platform_device *pdev)
 {
-	struct rtc_time tm;
-	struct timespec time;
-
-	time.tv_nsec = 0;
-
 	s3c_rtc_enable(pdev, 1);
-	s3c_rtc_gettime(&pdev->dev, &tm);
-	rtc_tm_to_time(&tm, &time.tv_sec);
-	restore_time_delta(&s3c_rtc_delta, &time);
-
 	writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
 	return 0;
 }
#2 lore raw

Re: several messages

of the following 2 patches:

Quoted 9 lines · Johannes Berg

This patch removes the time suspend/restore code that was done through a PMU notifier in arch/platforms/powermac/time.c.

Instead, we introduce arch/powerpc/sysdev/timer.c which creates a sys device and handles time of day suspend/resume through that.

Cc Andrew Morton <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>

[patch trimmed]

Quoted 13 lines · David Brownell

RTC class suspend/resume support, re-initializing the system clock on resume

Quoted 1 line

from the clock used to initialize it at boot time.

- Inlining the same code used by ARM, which saves and restores the delta between a selected RTC and the current system wall-clock time.

- Removes calls to that ARM code from AT91, OMAP, and S3C RTCs.

This goes on top of the patch series removing "struct class_device" usage

Quoted 1 line

from the RTC framework. That makes class suspend()/resume() work.

Quoted 7 lines
---
 drivers/rtc/Kconfig          |   24 +++++++++----
 drivers/rtc/class.c          |   74 +++++++++++++++++++++++++++++++++++++++++++
 drivers/rtc/rtc-at91rm9200.c |   30 -----------------
 drivers/rtc/rtc-omap.c       |   17 ---------
 drivers/rtc/rtc-s3c.c        |   22 ------------
 5 files changed, 91 insertions(+), 76 deletions(-)

[patch trimmed]

I think, we only want 1, right? And the latter seems to be more generic / platform independent? And as a side-effect, powermac would have to migrate to generic rtc:-)

Thanks
Guennadi
---
Guennadi Liakhovetski

#3 lore raw

Re: several messages

Quoted 4 lines · Guennadi Liakhovetski

I think, we only want 1, right? And the latter seems to be more generic / platform independent? And as a side-effect, powermac would have to migrate to generic rtc:-)

I'd certainly think that restoring the system clock should be, as much as possible, in platform-agnostic code. Like the generic RTC framework.

And hmm, that powermac/time.c file replicates other RTC code...

Minor obstacle: removing the EXPERIMENTAL label from that code.

- Dave

#4 lore raw

Re: several messages

In reply to Guennadi Liakhovetski
Quoted 3 lines · Guennadi Liakhovetski

I think, we only want 1, right? And the latter seems to be more generic / platform independent? And as a side-effect, powermac would have to migrate to generic rtc:-)

Can we migrate all of powerpc to genrtc? But yes, I agree. Had enough to do though already to get suspend working :)

johannes

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#5 lore raw

First, sorry for messing up the subject line.

Quoted 8 lines · Johannes Berg
Quoted 3 lines · Guennadi Liakhovetski

I think, we only want 1, right? And the latter seems to be more generic / platform independent? And as a side-effect, powermac would have to migrate to generic rtc:-)

Can we migrate all of powerpc to genrtc? But yes, I agree. Had enough to do though already to get suspend working :)

Johannes, is there any special meaning in "migrate all of powerpc to genrtc"? Or is it just porting every single rtc driver to the generic rtc API, moving it under drivers/rtc and adjusting its users or are there any global changes required to arch/powerpc? Linkstation is now happily using a driver under drivers/rtc, whereas originally it also had a "all special" driver, and the migration for me wasn't that difficult... Or is there more to do for other platforms?

Thanks
Guennadi
---
Guennadi Liakhovetski

#6 lore raw
Quoted 4 lines · Guennadi Liakhovetski

Johannes, is there any special meaning in "migrate all of powerpc to genrtc"? Or is it just porting every single rtc driver to the generic rtc API, moving it under drivers/rtc and adjusting its users or are there any global changes required to arch/powerpc?

I don't know. powerpc has some platform-specific rtc hooks that will want conversion (or deletion?), I think.

johannes