From patchwork Thu Oct 15 13:57:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11839395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74E7317D1 for ; Thu, 15 Oct 2020 13:58:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E6B52222B for ; Thu, 15 Oct 2020 13:58:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729498AbgJON57 (ORCPT ); Thu, 15 Oct 2020 09:57:59 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.2]:47553 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730367AbgJON57 (ORCPT ); Thu, 15 Oct 2020 09:57:59 -0400 Received: from [100.112.129.88] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta.az-a.us-west-2.aws.symcld.net id F1/A4-59651-565588F5; Thu, 15 Oct 2020 13:57:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkleJIrShJLcpLzFFi42JJl3vFppsa2hF v8OiCpMWhcweYLQ4vesFo8fXbbXaLN8enM1mcub2QyeLmp2+sFqv3vGB2YPeY1dDL5rFz1l12 j1/b1rB4LD84jcnj/b6rbB6fN8kFsEWxZuYl5VcksGacfDSJveATd8Xb48uYGhgXc3UxcnEIC fxnlFi7tZUNwnnNKLGw7QxzFyMnB5uAtsSWLb+AEhwcIgIyEh/WeoLUMAvcZpR4vquBDaRGWM BdYveHF0wgNouAqsTLd1vZQWxeARuJ9dNvg82REJCXeNq7HMzmFLCVePfwOivITCGBMInXm9I hygUlTs58wgJiMwOVN2+dzQxhS0gcfPECbszfJ09YIewEiWUv7zBPYBSYhaR9FpL2WUjaFzAy r2K0SCrKTM8oyU3MzNE1NDDQNTQ00jU0stQ1tDTSS6zSTdQrLdYtTy0u0QVyy4v1iitzk3NS9 PJSSzYxAmMlpaDxwA7GG68/6B1ilORgUhLljQ7qiBfiS8pPqcxILM6ILyrNSS0+xCjDwaEkwc sEjD4hwaLU9NSKtMwcYNzCpCU4eJREeA+FAKV5iwsSc4sz0yFSpxh1OXYenbeIWYglLz8vVUq cdxZIkQBIUUZpHtwIWAq5xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUUmYNwhkCk9mXgncpldA RzABHWG/pAXkiJJEhJRUA5M4+4XsuXzL3NLaDQ9p6La8KvJL9P7fcrLmjefKcB3OX9dfSOddL G55IfWp9vWVo7Y8wRNnbzv9t/egr0vsxCqOQNtVtiwfH8WWqUv/Ds3ITej6dI3173uR6akF/O dnJUvnMG6Mjfx7ui7nfPOh/Dj9ww0LV/yMCuet8nY47/qL34TVreT360synQFfpO+9yJ4W9jf TNVB4suWMtQFB9r/+ea3KMcp45FK0JIev9XFJAp9/cnr0o9/fvX/4KP2fZGyz7tHOUoaVVpVm M7LX3826f/XcP/HSq8naCV/WXT5+z3KD3WRW2zNy8etDT0u4MWpkfF2QsuR+e4fn0/jVmpOam 6SY4+yNn/rOejRbQomlOCPRUIu5qDgRAIK/0C6cAwAA X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-40.tower-335.messagelabs.com!1602770275!71468!1 X-Originating-IP: [103.30.234.6] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.60.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18406 invoked from network); 15 Oct 2020 13:57:57 -0000 Received: from unknown (HELO lenovo.com) (103.30.234.6) by server-40.tower-335.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Oct 2020 13:57:57 -0000 Received: from reswpmail04.lenovo.com (unknown [10.62.32.23]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by Forcepoint Email with ESMTPS id 6ECDFA67145CD874BE2D; Thu, 15 Oct 2020 21:57:53 +0800 (CST) Received: from localhost.localdomain.com (10.64.83.59) by reswpmail04.lenovo.com (10.62.32.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2044.4; Thu, 15 Oct 2020 06:57:50 -0700 From: Mark Pearson To: CC: , , , , , , , Subject: [PATCH 1/3] Adding event codes for Lenovo lap and palm sensors Date: Thu, 15 Oct 2020 09:57:15 -0400 Message-ID: <20201015135717.384610-2-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015135717.384610-1-markpearson@lenovo.com> References: <20201015135717.384610-1-markpearson@lenovo.com> MIME-Version: 1.0 X-Originating-IP: [10.64.83.59] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org These sensors are used for thermal mode changes and modifying WWAN transmitter power. Signed-off-by: Nitin Joshi Signed-off-by: Mark Pearson --- include/linux/mod_devicetable.h | 2 +- include/uapi/linux/input-event-codes.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 5b08a473cdba..897f5a3e7721 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -320,7 +320,7 @@ struct pcmcia_device_id { #define INPUT_DEVICE_ID_LED_MAX 0x0f #define INPUT_DEVICE_ID_SND_MAX 0x07 #define INPUT_DEVICE_ID_FF_MAX 0x7f -#define INPUT_DEVICE_ID_SW_MAX 0x10 +#define INPUT_DEVICE_ID_SW_MAX 0x12 #define INPUT_DEVICE_ID_PROP_MAX 0x1f #define INPUT_DEVICE_ID_MATCH_BUS 1 diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h index 0c2e27d28e0a..26f71a9a6936 100644 --- a/include/uapi/linux/input-event-codes.h +++ b/include/uapi/linux/input-event-codes.h @@ -889,7 +889,9 @@ #define SW_MUTE_DEVICE 0x0e /* set = device disabled */ #define SW_PEN_INSERTED 0x0f /* set = pen inserted */ #define SW_MACHINE_COVER 0x10 /* set = cover closed */ -#define SW_MAX 0x10 +#define SW_LAP_PROXIMITY 0x11 /* set = lap proximity sensor active */ +#define SW_PALMREST_PROXIMITY 0x12 /* set = palmrest proximity sensor active */ +#define SW_MAX 0x12 #define SW_CNT (SW_MAX+1) /* From patchwork Thu Oct 15 13:57:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11839399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C22D1752 for ; Thu, 15 Oct 2020 13:58:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 770F122248 for ; Thu, 15 Oct 2020 13:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730423AbgJON6D (ORCPT ); Thu, 15 Oct 2020 09:58:03 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.2]:51355 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730360AbgJON6C (ORCPT ); Thu, 15 Oct 2020 09:58:02 -0400 Received: from [100.112.1.102] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta.az-b.us-east-1.aws.symcld.net id 2E/00-19530-865588F5; Thu, 15 Oct 2020 13:58:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNIsWRWlGSWpSXmKPExsWSLveKTTcjtCP e4MELHotD5w4wWxxe9ILR4uu32+wWb45PZ7I4c3shk8XNT99YLVbvecHswO4xq6GXzWPnrLvs Hr+2rWHxWH5wGpPH+31X2Tw+b5ILYItizcxLyq9IYM34vmQZc0GbYsWLnzOZGxgPynQxcnEIC fxnlNjVe5EFwnnNKHGz/xtbFyMnB5uAtsSWLb+AbA4OEQEZiQ9rPUFqmAVuM0o839UAViMsYC 7x/fc8FhCbRUBV4mjfDkYQm1fARmLFjg/sILaEgLzE097lzCA2p4CtxLuH11lBZgoJhEm83pQ OUS4ocXLmE7AxzEDlzVtnM0PYEhIHX7xghhnz98kTVgg7QWLZyzvMExgFZiFpn4WkfRaS9gWM zKsYzZKKMtMzSnITM3N0DQ0MdA0NjXQNdI2MjPQSq3ST9EqLdVMTi0t0DfUSy4v1iitzk3NS9 PJSSzYxAuMkpYDh3g7GP68/6B1ilORgUhLljQ7qiBfiS8pPqcxILM6ILyrNSS0+xCjDwaEkwS seDJQTLEpNT61Iy8wBxixMWoKDR0mEtwUkzVtckJhbnJkOkTrFqCglzmsBkhAASWSU5sG1wdL EJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvMIgU3gy80rgpr8CWswEtNh+SQvI4pJEhJRU A1Odaf6UorNGizcuXsKpViZ7jS+KM21uO1thtN7VZouo3rWX/jrr/uBgnqbIOk2pr3TOR40z1 31N9rDy137eV3z9iUo1X5Q9P/OxRU17bp15sK2j9vmdCTaaRbM5mzf2lPO6uKlvkbr84/3617 zX/vhNb/vqZMsRYbzxfHhTlmXzh6hYu7hKJ4OeO8un7StXv5d2quNv9aS1imyiVQaMte8fxam v8O+Um+8nzfs4zOlGnbhO4xEZPUXrI7uOND+M9gx1CVf8eYsvOuJFYKiRbpH4ucM33hpUL5T4 l3DFfPsH20vTe6bUci9jdftnfcZ0P+u9T4E6Ek6zvFu+iyc9OSWza4a1rJOt6Gd73ue/lFiKM xINtZiLihMB9pYSPY4DAAA= X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-34.tower-395.messagelabs.com!1602770278!95511!1 X-Originating-IP: [103.30.234.6] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.60.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20893 invoked from network); 15 Oct 2020 13:57:59 -0000 Received: from unknown (HELO lenovo.com) (103.30.234.6) by server-34.tower-395.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Oct 2020 13:57:59 -0000 Received: from reswpmail04.lenovo.com (unknown [10.62.32.23]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by Forcepoint Email with ESMTPS id 2D13296B98AEF6E363C9; Thu, 15 Oct 2020 21:57:55 +0800 (CST) Received: from localhost.localdomain.com (10.64.83.59) by reswpmail04.lenovo.com (10.62.32.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2044.4; Thu, 15 Oct 2020 06:57:53 -0700 From: Mark Pearson To: CC: , , , , , , , Subject: [PATCH 2/3] Add support for Lenovo palm sensor Date: Thu, 15 Oct 2020 09:57:16 -0400 Message-ID: <20201015135717.384610-3-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015135717.384610-1-markpearson@lenovo.com> References: <20201015135717.384610-1-markpearson@lenovo.com> MIME-Version: 1.0 X-Originating-IP: [10.64.83.59] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Use input device event support for palm sensor state changes. Co-developed-by: Nitin Joshi Signed-off-by: Nitin Joshi Signed-off-by: Mark Pearson --- drivers/platform/x86/thinkpad_acpi.c | 99 +++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index eae3579f106f..5ddf2775fb06 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -4013,6 +4013,7 @@ static bool hotkey_notify_usrevent(const u32 hkey, } static void thermal_dump_all_sensors(void); +static void proxsensor_refresh(void); static bool hotkey_notify_6xxx(const u32 hkey, bool *send_acpi_ev, @@ -4079,8 +4080,8 @@ static bool hotkey_notify_6xxx(const u32 hkey, case TP_HKEY_EV_PALM_DETECTED: case TP_HKEY_EV_PALM_UNDETECTED: - /* palm detected hovering the keyboard, forward to user-space - * via netlink for consumption */ + /* palm detected - pass on to event handler */ + proxsensor_refresh(); return true; default: @@ -9918,6 +9919,96 @@ static struct ibm_struct dytc_driver_data = { .exit = dytc_exit, }; +/************************************************************************* + * Proximity sensor subdriver + */ + +#define PALMSENSOR_PRESENT_BIT 0 /* Determine if psensor present */ +#define PALMSENSOR_ON_BIT 1 /* psensor status */ + +struct input_dev *tpacpi_sw_dev; +bool has_palmsensor; +bool palmsensor_state; + +static int palmsensor_get(bool *present, bool *state) +{ + acpi_handle psensor_handle; + int output; + + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GPSS", &psensor_handle))) + return -ENODEV; + if (!acpi_evalf(psensor_handle, &output, NULL, "d")) + return -EIO; + + *present = output & BIT(PALMSENSOR_PRESENT_BIT) ? true : false; + *state = output & BIT(PALMSENSOR_ON_BIT) ? true : false; + return 0; +} + +static void proxsensor_refresh(void) +{ + bool new_state; + int err; + + if (has_palmsensor) { + err = palmsensor_get(&has_palmsensor, &new_state); + if (err) + return; + if (new_state != palmsensor_state) { + input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, new_state); + input_sync(tpacpi_sw_dev); + palmsensor_state = new_state; + } + } +} + +static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) +{ + int palm_err; + + palm_err = palmsensor_get(&has_palmsensor, &palmsensor_state); + /* If support isn't available (ENODEV) then don't return an error */ + if (palm_err == -ENODEV) + return 0; + /* For all other errors we can flag the failure */ + if (palm_err) + return palm_err; + + if (has_palmsensor) { + tpacpi_sw_dev = input_allocate_device(); + if (!tpacpi_sw_dev) + return -ENOMEM; + tpacpi_sw_dev->name = "Thinkpad proximity switches"; + tpacpi_sw_dev->phys = TPACPI_DRVR_NAME "/input1"; + tpacpi_sw_dev->id.bustype = BUS_HOST; + tpacpi_sw_dev->id.vendor = thinkpad_id.vendor; + tpacpi_sw_dev->id.product = TPACPI_HKEY_INPUT_PRODUCT; + tpacpi_sw_dev->id.version = TPACPI_HKEY_INPUT_VERSION; + tpacpi_sw_dev->dev.parent = &tpacpi_pdev->dev; + + if (has_palmsensor) { + input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY); + input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palmsensor_state); + } + palm_err = input_register_device(tpacpi_sw_dev); + if (palm_err) { + input_free_device(tpacpi_sw_dev); + return palm_err; + } + } + return 0; +} + +static void proxsensor_exit(void) +{ + input_unregister_device(tpacpi_sw_dev); + input_free_device(tpacpi_sw_dev); +} + +static struct ibm_struct proxsensor_driver_data = { + .name = "proximity-sensor", + .exit = proxsensor_exit, +}; /**************************************************************************** **************************************************************************** * @@ -10411,6 +10502,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { .init = tpacpi_dytc_init, .data = &dytc_driver_data, }, + { + .init = tpacpi_proxsensor_init, + .data = &proxsensor_driver_data, + }, }; static int __init set_ibm_param(const char *val, const struct kernel_param *kp) From patchwork Thu Oct 15 13:57:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11839403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0114B1752 for ; Thu, 15 Oct 2020 13:58:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DED5722254 for ; Thu, 15 Oct 2020 13:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730360AbgJON6H (ORCPT ); Thu, 15 Oct 2020 09:58:07 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.116]:58952 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730142AbgJON6G (ORCPT ); Thu, 15 Oct 2020 09:58:06 -0400 Received: from [100.112.7.19] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta.az-c.us-east-1.aws.symcld.net id 05/55-63275-C65588F5; Thu, 15 Oct 2020 13:58:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFIsWRWlGSWpSXmKPExsWSLveKTTcntCP e4ECPoMWhcweYLQ4vesFo8fXbbXaLN8enM1mcub2QyeLmp2+sFqv3vGB2YPeY1dDL5rFz1l12 j1/b1rB4LD84jcnj/b6rbB6fN8kFsEWxZuYl5VcksGZM3nuIreCcasWdyRsYGxivy3cxcnEIC fxnlPhwayEzhPOaUaLh9FP2LkZODjYBbYktW36xdTFycIgIyEh8WOsJUsMscJtR4vmuBrC4sI CZxMUb9SDlLAKqEv8ndIC18grYSLzZv5kFxJYQkJd42rucGcTmFLCVePfwOitIq5BAmMTrTek Q5YISJ2c+AStnBipv3jqbGcKWkDj44gUzzJi/T56wQtgJEste3mGewCgwC0n7LCTts5C0L2Bk XsVollSUmZ5RkpuYmaNraGCga2hopGuma2RgopdYpZusV1qsm5pYXKJrqJdYXqxXXJmbnJOil 5dasokRGCUpBWxndjBuf/NB7xCjJAeTkihvdFBHvBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXv FgoJxgUWp6akVaZg4wYmHSEhw8SiK8h0KA0rzFBYm5xZnpEKlTjIpS4ryzQBICIImM0jy4Nli SuMQoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmDcIZApPZl4J3PRXQIuZgBbbL2kBWVySiJCS amBiuvJ/wsRDGllZb1f/max6gDln2ekP165NixPInFXfO00g2/yVg6SO24TDts77t3bEzj4Zm 3pT9cgE5XTjDypfhPxtvjfJxC4waHOvKLeZIvzn2apzVrrfjdiXMJx3e1g+a5/PbcVvvfNyH/ IZf/zSXSDw976c02NDg9fJKjtTS5+Fhz3cVnS0w/ffvCmSfQ8W3nwyoSGn4bdl3qEPrM93nyr 8e8Thvoplenr/zIsNEzIeLzteV2ry19vQumbx4bTfKmkJ/LbB3E8ezXkSbvXkubmD9qGWVTEH Th99wu8s8sqolsnF2HXRfEv9y1P8q3XuT7GIP5/YfbP8+QOfhHsiH15m/djpIW67Nmv5jIvVS izFGYmGWsxFxYkAgp2t0Y0DAAA= X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-11.tower-415.messagelabs.com!1602770281!158452!1 X-Originating-IP: [103.30.234.6] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.60.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32675 invoked from network); 15 Oct 2020 13:58:04 -0000 Received: from unknown (HELO lenovo.com) (103.30.234.6) by server-11.tower-415.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Oct 2020 13:58:04 -0000 Received: from reswpmail04.lenovo.com (unknown [10.62.32.23]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by Forcepoint Email with ESMTPS id A7B7E8A2CCC0E6A83FC8; Thu, 15 Oct 2020 21:57:59 +0800 (CST) Received: from localhost.localdomain.com (10.64.83.59) by reswpmail04.lenovo.com (10.62.32.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2044.4; Thu, 15 Oct 2020 06:57:56 -0700 From: Mark Pearson To: CC: , , , , , , , Subject: [PATCH 3/3] Add support for Lenovo lap sensor Date: Thu, 15 Oct 2020 09:57:17 -0400 Message-ID: <20201015135717.384610-4-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015135717.384610-1-markpearson@lenovo.com> References: <20201015135717.384610-1-markpearson@lenovo.com> MIME-Version: 1.0 X-Originating-IP: [10.64.83.59] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This adds the Lenovo lap sensor to the input_sw_dev event sensor alongside the previously added palmsensor. Signed-off-by: Nitin Joshi Signed-off-by: Mark Pearson --- drivers/platform/x86/thinkpad_acpi.c | 75 ++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 5ddf2775fb06..c20b9902270b 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -4013,7 +4013,7 @@ static bool hotkey_notify_usrevent(const u32 hkey, } static void thermal_dump_all_sensors(void); -static void proxsensor_refresh(void); +static void proxsensor_refresh(bool palm, bool lap); static bool hotkey_notify_6xxx(const u32 hkey, bool *send_acpi_ev, @@ -4081,7 +4081,7 @@ static bool hotkey_notify_6xxx(const u32 hkey, case TP_HKEY_EV_PALM_DETECTED: case TP_HKEY_EV_PALM_UNDETECTED: /* palm detected - pass on to event handler */ - proxsensor_refresh(); + proxsensor_refresh(true /* palm */, false /* lap */); return true; default: @@ -9929,6 +9929,23 @@ static struct ibm_struct dytc_driver_data = { struct input_dev *tpacpi_sw_dev; bool has_palmsensor; bool palmsensor_state; +bool has_lapsensor; +bool lapsensor_state; + +static int lapsensor_get(bool *present, bool *state) +{ + acpi_handle dytc_handle; + int output; + + *present = false; + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "DYTC", &dytc_handle))) + return -ENODEV; + if (!acpi_evalf(dytc_handle, &output, NULL, "dd", DYTC_CMD_GET)) + return -EIO; + *present = true; /* If we get his far, we have lapmode support */ + *state = output & BIT(DYTC_GET_LAPMODE_BIT) ? true : false; + return 0; +} static int palmsensor_get(bool *present, bool *state) { @@ -9945,36 +9962,56 @@ static int palmsensor_get(bool *present, bool *state) return 0; } -static void proxsensor_refresh(void) +static void proxsensor_refresh(bool palm, bool lap) { bool new_state; int err; - if (has_palmsensor) { + if (palm && has_palmsensor) { err = palmsensor_get(&has_palmsensor, &new_state); - if (err) - return; - if (new_state != palmsensor_state) { + if (!err && (new_state != palmsensor_state)) { input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, new_state); input_sync(tpacpi_sw_dev); palmsensor_state = new_state; } } + + if (lap && has_lapsensor) { + err = lapsensor_get(&has_lapsensor, &new_state); + if (!err && (new_state != lapsensor_state)) { + input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, new_state); + input_sync(tpacpi_sw_dev); + lapsensor_state = new_state; + } + } } static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) { - int palm_err; + int palm_err, lap_err, err; + /* Make sure globals are set to a sensible initial value */ + has_palmsensor = false; + has_lapsensor = false; palm_err = palmsensor_get(&has_palmsensor, &palmsensor_state); + lap_err = lapsensor_get(&has_lapsensor, &lapsensor_state); + /* If support isn't available (ENODEV) then don't return an error */ - if (palm_err == -ENODEV) + if ((palm_err == -ENODEV) && (lap_err == -ENODEV)) return 0; - /* For all other errors we can flag the failure */ + /* If both sensors error out - return an error */ + if (palm_err && lap_err) + return palm_err ? palm_err : lap_err; + /* + * If just one sensor not available, we still want the input device, + * so just flag it and carry on + */ if (palm_err) - return palm_err; + pr_info("Palm sensor returned error %d", palm_err); + if (lap_err) + pr_info("Lap sensor returned error %d", lap_err); - if (has_palmsensor) { + if (has_palmsensor || has_lapsensor) { tpacpi_sw_dev = input_allocate_device(); if (!tpacpi_sw_dev) return -ENOMEM; @@ -9990,10 +10027,14 @@ static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY); input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palmsensor_state); } - palm_err = input_register_device(tpacpi_sw_dev); - if (palm_err) { + if (has_lapsensor) { + input_set_capability(tpacpi_sw_dev, EV_SW, SW_LAP_PROXIMITY); + input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, lapsensor_state); + } + err = input_register_device(tpacpi_sw_dev); + if (err) { input_free_device(tpacpi_sw_dev); - return palm_err; + return err; } } return 0; @@ -10057,8 +10098,10 @@ static void tpacpi_driver_event(const unsigned int hkey_event) mutex_unlock(&kbdlight_mutex); } - if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) + if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) { dytc_lapmode_refresh(); + proxsensor_refresh(false /* palm */, true /* lap */); + } }