diff mbox

[1/2] rtc-cmos: Clear expired alarm after resume

Message ID 1464795615-7748-1-git-send-email-gabriele.mzt@gmail.com
State Superseded
Headers show

Commit Message

Gabriele Mazzotta June 1, 2016, 3:40 p.m. UTC
If the system wakes up because of a wake alarm, the internal state
of the alarm is not updated. As consequence, the state no longer
reflects the actual state of the hardware and setting a new alarm
is not possible until the expired alarm is cleared.

Signed-off-by: Gabriele Mazzotta <gabriele.mzt@gmail.com>
---
 drivers/rtc/rtc-cmos.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Gabriele Mazzotta June 1, 2016, 4:11 p.m. UTC | #1
On 01/06/2016 17:40, Gabriele Mazzotta wrote:
> If the system wakes up because of a wake alarm, the internal state
> of the alarm is not updated. As consequence, the state no longer
> reflects the actual state of the hardware and setting a new alarm
> is not possible until the expired alarm is cleared.
> 
> Signed-off-by: Gabriele Mazzotta <gabriele.mzt@gmail.com>
> ---
>  drivers/rtc/rtc-cmos.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
> index fbe9c72..fd121e3 100644
> --- a/drivers/rtc/rtc-cmos.c
> +++ b/drivers/rtc/rtc-cmos.c
> @@ -900,11 +900,33 @@ static inline int cmos_poweroff(struct device *dev)
>  
>  #ifdef	CONFIG_PM_SLEEP
>  
> +static void cmos_check_alarm(struct device *dev)
> +{
> +	struct cmos_rtc *cmos = dev_get_drvdata(dev);
> +	struct rtc_wkalrm alarm;
> +	struct rtc_time now;
> +	time64_t t_now;
> +	time64_t t_expires;
> +
> +	cmos_read_time(dev, &now);
> +	rtc_read_alarm(cmos->rtc, &alarm);

Here it should probably check the return value and exit in case of error.

> +	t_now = rtc_tm_to_time64(&now);
> +	t_expires = rtc_tm_to_time64(&alarm.time);
> +
> +	if (t_expires <= t_now && alarm.enabled) {
> +		alarm.enabled = 0;
> +		cmos->suspend_ctrl &= ~RTC_AIE;
> +		rtc_set_alarm(cmos->rtc, &alarm);

Same here.

> +	}
> +}
> +
>  static int cmos_resume(struct device *dev)
>  {
>  	struct cmos_rtc	*cmos = dev_get_drvdata(dev);
>  	unsigned char tmp;
>  
> +	cmos_check_alarm(dev);
> +
>  	if (cmos->enabled_wake) {
>  		if (cmos->wake_off)
>  			cmos->wake_off(dev);
>
Alexandre Belloni June 4, 2016, 2:46 p.m. UTC | #2
Hi,

On 01/06/2016 at 17:40:14 +0200, Gabriele Mazzotta wrote :
> If the system wakes up because of a wake alarm, the internal state
> of the alarm is not updated. As consequence, the state no longer
> reflects the actual state of the hardware and setting a new alarm
> is not possible until the expired alarm is cleared.
> 

I'm not completely sure to understand what is happening but could you
check whether that one is solved by
2b2f5ff00f63847d95adad6289bd8b05f5983dd5 in my tree (rtc-next).
diff mbox

Patch

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index fbe9c72..fd121e3 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -900,11 +900,33 @@  static inline int cmos_poweroff(struct device *dev)
 
 #ifdef	CONFIG_PM_SLEEP
 
+static void cmos_check_alarm(struct device *dev)
+{
+	struct cmos_rtc *cmos = dev_get_drvdata(dev);
+	struct rtc_wkalrm alarm;
+	struct rtc_time now;
+	time64_t t_now;
+	time64_t t_expires;
+
+	cmos_read_time(dev, &now);
+	rtc_read_alarm(cmos->rtc, &alarm);
+	t_now = rtc_tm_to_time64(&now);
+	t_expires = rtc_tm_to_time64(&alarm.time);
+
+	if (t_expires <= t_now && alarm.enabled) {
+		alarm.enabled = 0;
+		cmos->suspend_ctrl &= ~RTC_AIE;
+		rtc_set_alarm(cmos->rtc, &alarm);
+	}
+}
+
 static int cmos_resume(struct device *dev)
 {
 	struct cmos_rtc	*cmos = dev_get_drvdata(dev);
 	unsigned char tmp;
 
+	cmos_check_alarm(dev);
+
 	if (cmos->enabled_wake) {
 		if (cmos->wake_off)
 			cmos->wake_off(dev);