From patchwork Mon Mar 26 13:58:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 10307875 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 388C0600F6 for ; Mon, 26 Mar 2018 13:58:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3070129106 for ; Mon, 26 Mar 2018 13:58:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 244EB29187; Mon, 26 Mar 2018 13:58:22 +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 B6A4329106 for ; Mon, 26 Mar 2018 13:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbeCZN6U (ORCPT ); Mon, 26 Mar 2018 09:58:20 -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 S1750983AbeCZN6U (ORCPT ); Mon, 26 Mar 2018 09:58:20 -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:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,364,1517904000"; d="scan'208";a="186083738" 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:17 -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 3/3] rtc: cmos: introduce quirks to enable use_acpi_alarm mode Date: Mon, 26 Mar 2018 21:58:03 +0800 Message-Id: <1522072683-3968-3-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 Use ACPI for RTC Alarm only for Intel platforms 1. with Low Power S0 support 2. with HPET RTC emulation enabled 3. no earlier than 2015 Note that, during the test, it is found that this patch 1. works in 4.15-rc kernel 2. hangs the platform after suspend-to-idle for 2 or 3 times, in 4.15.0 3. works again in 4.16-rc3 kernel. 4. works in the latest 4.15.12 stable kernel. Thus although this patch breaks 4.15.0 kernel for some unknown reason, still, it is safe for both upstream and backport. Signed-off-by: Zhang Rui --- drivers/rtc/rtc-cmos.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index bcf86e1..75c4bdc 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -43,6 +43,8 @@ #include #ifdef CONFIG_X86 #include +#include +#include #endif /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ @@ -1183,6 +1185,28 @@ static void rtc_wake_off(struct device *dev) acpi_disable_event(ACPI_EVENT_RTC, 0); } +#ifdef CONFIG_X86 +/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */ +static void use_acpi_alarm_quirks(void) +{ + int year; + + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) + return; + + if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) + return; + + if (!is_hpet_enabled()) + return; + + if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015) + use_acpi_alarm = true; +} +#else +static inline void use_acpi_alarm_quirks(void) { } +#endif + /* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find * its device node and pass extra config data. This helps its driver use * capabilities that the now-obsolete mc146818 didn't have, and informs it @@ -1195,6 +1219,8 @@ static void cmos_wake_setup(struct device *dev) if (acpi_disabled) return; + use_acpi_alarm_quirks(); + rtc_wake_setup(dev); acpi_rtc_info.wake_on = rtc_wake_on; acpi_rtc_info.wake_off = rtc_wake_off;