From patchwork Mon Mar 26 13:58:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 10307873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3AD4A60212 for ; Mon, 26 Mar 2018 13:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 349ED29106 for ; Mon, 26 Mar 2018 13:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2975E29187; Mon, 26 Mar 2018 13:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1CFF29106 for ; Mon, 26 Mar 2018 13:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751374AbeCZN6R (ORCPT ); Mon, 26 Mar 2018 09:58:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:12948 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbeCZN6R (ORCPT ); Mon, 26 Mar 2018 09:58:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2018 06:58:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,364,1517904000"; d="scan'208";a="186083727" Received: from lizhicha-mobl2.ccr.corp.intel.com (HELO rzhang-dell-9360.ccr.corp.intel.com) ([10.255.30.156]) by orsmga004.jf.intel.com with ESMTP; 26 Mar 2018 06:58:13 -0700 From: Zhang Rui 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 Message-Id: <1522072683-3968-2-git-send-email-rui.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522072683-3968-1-git-send-email-rui.zhang@intel.com> References: <1522072683-3968-1-git-send-email-rui.zhang@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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, ¤t_alarm); t_current_expires = rtc_tm_to_time64(¤t_alarm.time);