linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: linux-pm@vger.kernel.org, linux-rtc@vger.kernel.org
Cc: rjw@rjwysocki.net, alexandre.belloni@free-electrons.com,
	gabriele.mzt@gmail.com, rui.zhang@intel.com
Subject: [PATCH 2/3] rtc: cmos: acknowledge ACPI driven wake alarms upon resume
Date: Mon, 26 Mar 2018 21:58:02 +0800	[thread overview]
Message-ID: <1522072683-3968-2-git-send-email-rui.zhang@intel.com> (raw)
In-Reply-To: <1522072683-3968-1-git-send-email-rui.zhang@intel.com>

Previously, the RTC alarm is acknowledged either by the cmos rtc irq
handler, or by the hpet rtc irq handler.

When using ACPI RTC Fixed event as the RTC alarm, the RTC alarm is
acknowledged by the ACPI RTC event handler, as addressed in the previous
patch.
But, when resume from suspend-to-ram (ACPI S3), the ACPI SCI is cleared
right after resume, thus the ACPI RTC event handler is not invoked at all,
results in the RTC Alarm unacknowledged.

Handle this by comparing the current time and the RTC Alarm time in the
rtc_cmos driver .resume() callback
1. Assume the wakeup event has already been fired if the RTC Alarm time
   is earlier than/equal to the current time, and ACK the RTC Alarm.
2. Assume the wakeup event has not been fired if the RTC Alarm time
   is later than current time, and re-arm it if needed.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/rtc/rtc-cmos.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 9665a72..bcf86e1 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -1022,8 +1022,26 @@ static void cmos_check_wkalrm(struct device *dev)
 {
 	struct cmos_rtc *cmos = dev_get_drvdata(dev);
 	struct rtc_wkalrm current_alarm;
+	time64_t t_now;
 	time64_t t_current_expires;
 	time64_t t_saved_expires;
+	struct rtc_time now;
+
+	/* Check if we have RTC Alarm armed */
+	if (!(cmos->suspend_ctrl & RTC_AIE))
+		return;
+
+	cmos_read_time(dev, &now);
+	t_now = rtc_tm_to_time64(&now);
+
+	/*
+	 * ACPI RTC wake event is cleared after resume from STR,
+	 * ACK the rtc irq here
+	 */
+	if (t_now >= cmos->alarm_expires && use_acpi_alarm) {
+		cmos_interrupt(0, (void *)cmos->rtc);
+		return;
+	}
 
 	cmos_read_alarm(dev, &current_alarm);
 	t_current_expires = rtc_tm_to_time64(&current_alarm.time);
-- 
2.7.4

  reply	other threads:[~2018-03-26 13:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-26 13:58 [PATCH 1/3] rtc: cmos: allow using ACPI for RTC alarm instead of HPET Zhang Rui
2018-03-26 13:58 ` Zhang Rui [this message]
2018-03-26 13:58 ` [PATCH 3/3] rtc: cmos: introduce quirks to enable use_acpi_alarm mode Zhang Rui
2018-04-19 14:05 ` [PATCH 1/3] rtc: cmos: allow using ACPI for RTC alarm instead of HPET Alexandre Belloni
2018-04-20  5:59   ` Zhang Rui
2018-04-20  6:46     ` Alexandre Belloni
2018-04-24 13:15       ` Zhang Rui
2018-04-24 13:30         ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1522072683-3968-2-git-send-email-rui.zhang@intel.com \
    --to=rui.zhang@intel.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=gabriele.mzt@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).