From patchwork Tue Jul 19 08:11:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9236331 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 2CF82600CB for ; Tue, 19 Jul 2016 08:12:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E688205AA for ; Tue, 19 Jul 2016 08:12:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 132922094F; Tue, 19 Jul 2016 08:12:18 +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 6C07F205AA for ; Tue, 19 Jul 2016 08:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752842AbcGSILZ (ORCPT ); Tue, 19 Jul 2016 04:11:25 -0400 Received: from mga09.intel.com ([134.134.136.24]:21165 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753242AbcGSILT (ORCPT ); Tue, 19 Jul 2016 04:11:19 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 19 Jul 2016 01:11:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,388,1464678000"; d="scan'208";a="998083281" Received: from liujj.sh.intel.com (HELO lvzheng-z530.sh.intel.com) ([10.239.159.24]) by orsmga001.jf.intel.com with ESMTP; 19 Jul 2016 01:11:15 -0700 From: Lv Zheng To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown Cc: Lv Zheng , Lv Zheng , , linux-acpi@vger.kernel.org, Dmitry Torokhov , Benjamin Tissoires , "Bastien Nocera:" , linux-input@vger.kernel.org Subject: [PATCH v4 1/2] ACPI / button: Add KEY_LID_OPEN/KEY_LID_CLOSE for new usage model Date: Tue, 19 Jul 2016 16:11:02 +0800 Message-Id: <1b96ee1e5b5ebbed0096adde410a9fd0b7930848.1468915808.git.lv.zheng@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: References: Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are many AML tables reporting wrong initial lid state, and some of them never report lid open state. As a proxy layer acting between, ACPI button driver is not able to handle all such cases, but need to re-define the usage model of the ACPI lid. That is: 1. It's initial state is not reliable; 2. There may not be an open event; 3. Userspace should only take action against the close event which is reliable, always sent after a real lid close. OTOH, using an input switch event for the lid device on such platforms can cause the loss of the close event, but the platforms purposely want to use these close events to trigger power saving actions. So we need to introduce a new ABI, which is input key events based, not input switch events based. This patch adds a set of new input key events so that the new userspace programs can use them to handle this usage model correctly. And in the meanwhile, the old input switch event is kept so that no old programs will be broken by the ABI change. Signed-off-by: Lv Zheng Cc: Dmitry Torokhov Cc: Benjamin Tissoires Cc: Bastien Nocera: Cc: linux-input@vger.kernel.org Reviewed-by: Benjamin Tissoires --- drivers/acpi/button.c | 34 +++++++++++++++++++++++++++++++- include/uapi/linux/input-event-codes.h | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 148f4e5..dd16879 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -104,6 +104,8 @@ struct acpi_button { struct input_dev *input; char phys[32]; /* for input device */ unsigned long pushed; + int last_state; + unsigned long timestamp; bool suspended; }; @@ -111,6 +113,10 @@ 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"); + /* -------------------------------------------------------------------------- FS Interface (/proc) -------------------------------------------------------------------------- */ @@ -133,12 +139,34 @@ static int acpi_lid_evaluate_state(struct acpi_device *device) static int acpi_lid_notify_state(struct acpi_device *device, int state) { struct acpi_button *button = acpi_driver_data(device); + int keycode; + unsigned long timeout; int ret; - /* input layer checks if event is redundant */ + /* + * Send the switch event. + * The input layer checks if the event is redundant. + */ input_report_switch(button->input, SW_LID, !state); input_sync(button->input); + /* + * Send the key event. + * The input layer doesn't check if the event is redundant. + */ + timeout = button->timestamp + + msecs_to_jiffies(lid_report_interval); + if (button->last_state != !!state || + time_after(jiffies, timeout)) { + keycode = state ? KEY_LID_OPEN : KEY_LID_CLOSE; + input_report_key(button->input, keycode, 1); + input_sync(button->input); + input_report_key(button->input, keycode, 0); + input_sync(button->input); + button->last_state = !!state; + button->timestamp = jiffies; + } + if (state) pm_wakeup_event(&device->dev, 0); @@ -407,6 +435,8 @@ 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->timestamp = jiffies; } else { printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid); error = -ENODEV; @@ -436,6 +466,8 @@ static int acpi_button_add(struct acpi_device *device) case ACPI_BUTTON_TYPE_LID: input_set_capability(input, EV_SW, SW_LID); + input_set_capability(input, EV_KEY, KEY_LID_OPEN); + input_set_capability(input, EV_KEY, KEY_LID_CLOSE); break; } diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h index 737fa32..b062fe1 100644 --- a/include/uapi/linux/input-event-codes.h +++ b/include/uapi/linux/input-event-codes.h @@ -641,6 +641,13 @@ * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.) */ #define KEY_DATA 0x275 +/* + * Key events sent by the lid drivers. + * The drivers may not be able to send paired "open"/"close" events, in + * which case, they send KEY_LID_OPEN/KEY_LID_CLOSE instead of SW_LID. + */ +#define KEY_LID_OPEN 0x278 +#define KEY_LID_CLOSE 0x279 #define BTN_TRIGGER_HAPPY 0x2c0 #define BTN_TRIGGER_HAPPY1 0x2c0