From patchwork Wed Aug 31 07:33:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei-Ning Huang X-Patchwork-Id: 9306475 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 8BF05607D2 for ; Wed, 31 Aug 2016 07:34:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81D5C28C07 for ; Wed, 31 Aug 2016 07:34:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 760A928C16; Wed, 31 Aug 2016 07:34:10 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 20E4A28C07 for ; Wed, 31 Aug 2016 07:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756532AbcHaHdy (ORCPT ); Wed, 31 Aug 2016 03:33:54 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:32816 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756050AbcHaHdu (ORCPT ); Wed, 31 Aug 2016 03:33:50 -0400 Received: by mail-pa0-f42.google.com with SMTP id cy9so16012537pac.0 for ; Wed, 31 Aug 2016 00:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=truG3kRFW1FdVcMIU7yUi1L7PBf8pEtJZgv3TTzdilc=; b=HgFbsDA/TkXVfmK3hRy7b6vlp4C6CgmyOFscnbzOdBNV10LRbfeRrRVNWO6+fD++0W 1nmNsSbPcEqZPfN7QsA02DWMIZfiE8jVpxgcx0GxmyUIN7/utKwuh6UBnnVqgxZFgu4/ 5udYU1XsYgsPZspfJw636C10vLAHV5MQZBDbk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=truG3kRFW1FdVcMIU7yUi1L7PBf8pEtJZgv3TTzdilc=; b=B5CdleQgoWPJOllI9tk6PcMFXaiiWAN4wb3zMqt8YLci/lPeeIcd4SShOlwf60mjbU jbDTWXEGrls4jwLdE7MBRb0/qVpP6WRuMk8hJWWK9sOHfxq4sSAvLqhaYFyB/vP56hFs 1EPMa6ZP8MHWNh1fRnwQzGVM8/MMCk2n3p1+z8Zm9fVJsKZbq1yp2KBLnAjCnnjv0bvC F44vyLNj962yP+zJfcJkYroZUF0L+1uXahNoYHihzxKGal+83zr7Z0jBnPH64M0R82hy H1/uGych9AyWdbrGC2Vfi5KVeRKRiZaSf/zlhgygX/llWrTQZxRo+sa7cB7mmT/Ks+YT 46iw== X-Gm-Message-State: AE9vXwMalyAc+xL3frvghC+lX9vxVXNUxaIBsvLbks+hDuwT5snZRSrDaMDHcG43l1v39aLg X-Received: by 10.66.193.163 with SMTP id hp3mr14401453pac.73.1472628829793; Wed, 31 Aug 2016 00:33:49 -0700 (PDT) Received: from wnhuang0.tpe.corp.google.com ([172.30.210.18]) by smtp.gmail.com with ESMTPSA id m24sm62377272pfi.34.2016.08.31.00.33.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Aug 2016 00:33:48 -0700 (PDT) From: Wei-Ning Huang X-Google-Original-From: Wei-Ning Huang To: "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wei-Ning Huang , Wei-Ning Huang Subject: [PATCH] ACPI / button: add support for tablet mode switch Date: Wed, 31 Aug 2016 15:33:37 +0800 Message-Id: <1472628817-3145-1-git-send-email-wnhuang@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 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 From: Wei-Ning Huang ACPI PNP device HID 'PNP0C60' is a device that indicates tablet mode status. Add support for mapping this device to the SW_TABLET_MODE input event. Signed-off-by: Wei-Ning Huang --- drivers/acpi/button.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 148f4e5..50e9de6 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -53,6 +53,11 @@ #define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch" #define ACPI_BUTTON_TYPE_LID 0x05 +#define ACPI_BUTTON_SUBCLASS_TABLET "tablet" +#define ACPI_BUTTON_HID_TABLET "PNP0C60" +#define ACPI_BUTTON_DEVICE_NAME_TABLET "Tablet Mode Switch" +#define ACPI_BUTTON_TYPE_TABLET 0x07 + #define ACPI_BUTTON_LID_INIT_IGNORE 0x00 #define ACPI_BUTTON_LID_INIT_OPEN 0x01 #define ACPI_BUTTON_LID_INIT_METHOD 0x02 @@ -70,6 +75,7 @@ static const struct acpi_device_id button_device_ids[] = { {ACPI_BUTTON_HID_SLEEPF, 0}, {ACPI_BUTTON_HID_POWER, 0}, {ACPI_BUTTON_HID_POWERF, 0}, + {ACPI_BUTTON_HID_TABLET, 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, button_device_ids); @@ -305,6 +311,23 @@ static void acpi_lid_initialize_state(struct acpi_device *device) } } +static int acpi_tablet_send_state(struct acpi_device *device) +{ + struct acpi_button *button = acpi_driver_data(device); + unsigned long long state; + acpi_status status; + + status = acpi_evaluate_integer(device->handle, "_TBL", NULL, &state); + if (ACPI_FAILURE(status)) + return -ENODEV; + + /* input layer checks if event is redundant */ + input_report_switch(button->input, SW_TABLET_MODE, state); + input_sync(button->input); + + return 0; +} + static void acpi_button_notify(struct acpi_device *device, u32 event) { struct acpi_button *button = acpi_driver_data(device); @@ -318,6 +341,8 @@ static void acpi_button_notify(struct acpi_device *device, u32 event) input = button->input; if (button->type == ACPI_BUTTON_TYPE_LID) { acpi_lid_update_state(device); + } else if (button->type == ACPI_BUTTON_TYPE_TABLET) { + acpi_tablet_send_state(device); } else { int keycode; @@ -407,6 +432,11 @@ 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); + } else if (!strcmp(hid, ACPI_BUTTON_HID_TABLET)) { + button->type = ACPI_BUTTON_TYPE_TABLET; + strcpy(name, ACPI_BUTTON_DEVICE_NAME_TABLET); + sprintf(class, "%s/%s", + ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_TABLET); } else { printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid); error = -ENODEV; @@ -437,6 +467,10 @@ static int acpi_button_add(struct acpi_device *device) case ACPI_BUTTON_TYPE_LID: input_set_capability(input, EV_SW, SW_LID); break; + + case ACPI_BUTTON_TYPE_TABLET: + input_set_capability(input, EV_SW, SW_TABLET_MODE); + break; } error = input_register_device(input); @@ -450,6 +484,8 @@ static int acpi_button_add(struct acpi_device *device) */ lid_device = device; } + if (button->type == ACPI_BUTTON_TYPE_TABLET) + acpi_tablet_send_state(device); printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device)); return 0;