From patchwork Wed Jun 21 08:55:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9801227 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 1BEEF60329 for ; Wed, 21 Jun 2017 08:57:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09E6826E16 for ; Wed, 21 Jun 2017 08:57:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F295D28516; Wed, 21 Jun 2017 08:57:09 +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=unavailable 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 60ADA26E16 for ; Wed, 21 Jun 2017 08:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752838AbdFUIz1 (ORCPT ); Wed, 21 Jun 2017 04:55:27 -0400 Received: from mga14.intel.com ([192.55.52.115]:44431 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbdFUIzZ (ORCPT ); Wed, 21 Jun 2017 04:55:25 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2017 01:55:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,368,1493708400"; d="scan'208";a="276820291" Received: from unknown (HELO lvzheng-MOBLsp3.sh.intel.com) ([10.239.159.55]) by fmsmga004.fm.intel.com with ESMTP; 21 Jun 2017 01:55:17 -0700 From: Lv Zheng To: "Rafael J . Wysocki" , "Rafael J . Wysocki" , Len Brown Cc: Lv Zheng , Lv Zheng , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, systemd-devel@lists.freedesktop.org, Benjamin Tissoires , Peter Hutterer Subject: [RFC PATCH v6 3/5] ACPI: button: Rework lid_init_state=ignore mode Date: Wed, 21 Jun 2017 16:55:15 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: <2a779ae8c280c968b3237ac4a3d9580df7262a46.1493951798.git.lv.zheng@intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are platform variations implementing ACPI lid device in different ways: 1. Some platforms send "open" events to OS and the events arrive before button driver is resumed; 2. Some platforms send "open" events to OS, but the events arrive after button driver is resumed, ex., Samsung N210+; 3. Some platforms never send "open" events to OS, but send "open" events to update the cached _LID return value, and the update events arrive before button driver is resumed; 4. Some platforms never send "open" events to OS, but send "open" events to update the cached _LID return value, but the update events arrive after button driver is resumed, ex., Surface Pro 3; 5. Some platforms never send "open" events, _LID returns value sticks to "close", ex., Surface Pro 1. Currently, all cases work find with systemd 233, but only case 1,2,3,4 work fine with systemd 229. After fixing all the other issues for old userspace programs, case 5 is the only case that the exported input node is still not fully compliant to SW_LID ABI and thus needs quirks or ABI changes. The original button.lid_init_state=ignore ABI change solution is now too complicated if its purpose is to only solve this final incompliant use case. This patch re-works it by unconditionally prepending "open" complement events. Cc: Cc: Benjamin Tissoires Cc: Peter Hutterer Signed-off-by: Lv Zheng --- drivers/acpi/button.c | 85 +++------------------------------------------------ 1 file changed, 5 insertions(+), 80 deletions(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index a8b119e..1256a8c 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -109,8 +109,6 @@ struct acpi_button { struct timer_list lid_timer; char phys[32]; /* for input device */ unsigned long pushed; - int last_state; - ktime_t last_time; bool suspended; }; @@ -118,10 +116,6 @@ static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier); static struct acpi_device *lid_device; static u8 lid_init_state = ACPI_BUTTON_LID_INIT_METHOD; -static unsigned long lid_report_interval __read_mostly = 500; -module_param(lid_report_interval, ulong, 0644); -MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events"); - static unsigned long lid_notify_timeout __read_mostly = 10; module_param(lid_notify_timeout, ulong, 0644); MODULE_PARM_DESC(lid_notify_timeout, "Timeout (s) before receiving lid notification"); @@ -157,79 +151,12 @@ static int acpi_lid_notify_state(struct acpi_device *device, int state) { struct acpi_button *button = acpi_driver_data(device); int ret; - ktime_t next_report; - bool do_update; - - /* - * In lid_init_state=ignore mode, if user opens/closes lid - * frequently with "open" missing, and "last_time" is also updated - * frequently, "close" cannot be delivered to the userspace. - * So "last_time" is only updated after a timeout or an actual - * switch. - */ - if (lid_init_state != ACPI_BUTTON_LID_INIT_IGNORE || - button->last_state != !!state) - do_update = true; - else - do_update = false; - - next_report = ktime_add(button->last_time, - ms_to_ktime(lid_report_interval)); - if (button->last_state == !!state && - ktime_after(ktime_get(), next_report)) { - /* Complain the buggy firmware */ - pr_warn_once("The lid device is not compliant to SW_LID.\n"); - /* - * Send the unreliable complement switch event: - * - * On most platforms, the lid device is reliable. However - * there are exceptions: - * 1. Platforms returning initial lid state as "close" by - * default after booting/resuming: - * https://bugzilla.kernel.org/show_bug.cgi?id=89211 - * https://bugzilla.kernel.org/show_bug.cgi?id=106151 - * 2. Platforms never reporting "open" events: - * https://bugzilla.kernel.org/show_bug.cgi?id=106941 - * On these buggy platforms, the usage model of the ACPI - * lid device actually is: - * 1. The initial returning value of _LID may not be - * reliable. - * 2. The open event may not be reliable. - * 3. The close event is reliable. - * - * But SW_LID is typed as input switch event, the input - * layer checks if the event is redundant. Hence if the - * state is not switched, the userspace cannot see this - * platform triggered reliable event. By inserting a - * complement switch event, it then is guaranteed that the - * platform triggered reliable one can always be seen by - * the userspace. - */ - if (lid_init_state == ACPI_BUTTON_LID_INIT_IGNORE) { - do_update = true; - /* - * Do generate complement switch event for "close" - * as "close" is reliable and wrong "open" won't - * trigger unexpected behaviors. - * Do not generate complement switch event for - * "open" as "open" is not reliable and wrong - * "close" will trigger unexpected behaviors. - */ - if (!state) { - input_report_switch(button->input, - SW_LID, state); - input_sync(button->input); - } - } - } - /* Send the platform triggered reliable event */ - if (do_update) { - input_report_switch(button->input, SW_LID, !state); - input_sync(button->input); - button->last_state = !!state; - button->last_time = ktime_get(); - } + if (lid_init_state == ACPI_BUTTON_LID_INIT_IGNORE) + input_report_switch(button->input, SW_LID, 0); + + input_report_switch(button->input, SW_LID, !state); + input_sync(button->input); if (state) pm_wakeup_event(&device->dev, 0); @@ -524,8 +451,6 @@ static int acpi_button_add(struct acpi_device *device) strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID); sprintf(class, "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); - button->last_state = !!acpi_lid_evaluate_state(device); - button->last_time = ktime_get(); init_timer(&button->lid_timer); setup_timer(&button->lid_timer, acpi_lid_timeout, (ulong)device);