From patchwork Mon Oct 26 14:45:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11857421 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 CA8D86A2 for ; Mon, 26 Oct 2020 14:49:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B96E622265 for ; Mon, 26 Oct 2020 14:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782036AbgJZOtp (ORCPT ); Mon, 26 Oct 2020 10:49:45 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.3]:61761 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1782025AbgJZOto (ORCPT ); Mon, 26 Oct 2020 10:49:44 -0400 Received: from [100.112.129.88] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-a.us-west-2.aws.symcld.net id 9E/8C-32453-502E69F5; Mon, 26 Oct 2020 14:49:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplleJIrShJLcpLzFFi42LJePGQR5f10bR 4g82vGS0OnTvAbHF40QtGi6/fbrNbvDk+ncnizO2FTBY3P31jtVi95wWzA7vHrIZeNo+ds+6y e/zatobFY/nBaUwe7/ddZfP4vEkugC2KNTMvKb8igTVj5c3CgkW8FWs+/mFqYNzC3cXIxSEk8 J9RYtaFu2wQzhtGiWmPJzN3MXJysAloS2zZ8gsowcEhIiAj8WGtJ0gNs8ArRokdL7+ygMSFBc Ildtw1BSlnEVCV2PC2hwnE5hWwkZjcsYIRxJYQkJd42rscbCQnUM2ZrscsILaQgIrE/QdL2CD qBSVOznwCFmcGqm/eOpsZwpaQOPjiBTPIKgkBBYkHV5ghRiZILHt5h3kCo8AsJN2zkHTPQtK9 gJF5FaNFUlFmekZJbmJmjq6hgYGuoaGRrqGxga6RoaVeYpVuol5psW55anGJrpFeYnmxXnFlb nJOil5easkmRmCcpBQ03d7B+O/1B71DjJIcTEqivMf2TYsX4kvKT6nMSCzOiC8qzUktPsQow8 GhJMFb8gAoJ1iUmp5akZaZA4xZmLQEB4+SCO9qkDRvcUFibnFmOkTqFKMxx86j8xYxc2yeu3Q RsxBLXn5eqpQ472mQUgGQ0ozSPLhBsFRyiVFWSpiXkYGBQYinILUoN7MEVf4VozgHo5Iw7y+Q KTyZeSVw+4BRCPSFCG9bxRSQU0oSEVJSDUyWn5ZtvXxWw6CbJ+593ocTuq8Kt+zY9Y8/WOPrh x8O7jqn9kSVRUQuzpL1PrT3zINgVh7VBRt8Hp5QEe5L/JddsetDZpTCy4aFv4sXsq+8+rSpU8 Z9T66NQI7togNd7YetN3/Jmekhqpilqrt//Rq5vIlJojuVMrq9gstf2r9/sNz9jdbtxJJ0g99 1scdvdL7hef3LMqOyzOMkp+18/S0sNhUKXlO8zi49I3SddWX/1+W+Qo63py7TkFnn9XLa4nWb HqXfFmv3+JRuvThfLcFj25wI80VLfJddEtGXes1TF3Sqad8x1zqZSHYr32Nr19z+bvI+csq1Z UsZ//49vHTLRx2vw68ZGuNC27a7yusosRRnJBpqMRcVJwIAUE7AY6ADAAA= X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-24.tower-336.messagelabs.com!1603723779!1294!1 X-Originating-IP: [104.232.225.12] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.60.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3239 invoked from network); 26 Oct 2020 14:49:40 -0000 Received: from unknown (HELO lenovo.com) (104.232.225.12) by server-24.tower-336.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Oct 2020 14:49:40 -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 91C0E5F3C616F138D18A; Mon, 26 Oct 2020 10:49:39 -0400 (EDT) Received: from localhost.localdomain.com (10.64.83.193) 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; Mon, 26 Oct 2020 07:49:36 -0700 From: Mark Pearson To: CC: , , , , , , , "Nitin Joshi" Subject: [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Date: Mon, 26 Oct 2020 10:45:10 -0400 Message-ID: <20201026144512.621479-1-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.64.83.193] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Add infrastructure needed to support lap and palmrest proximity sensors. These sensors are used for identifying thermal mode changes and modifying WWAN transmitter power. Reviewed-by: Nitin Joshi Signed-off-by: Mark Pearson Reviewed-by: Hans de Goede --- Changes in v2: - Update Input message Changes in v3: - Added missing patch history notes 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 Mon Oct 26 14:45:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11857425 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 05ADF6A2 for ; Mon, 26 Oct 2020 14:49:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBBD422263 for ; Mon, 26 Oct 2020 14:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782041AbgJZOtv (ORCPT ); Mon, 26 Oct 2020 10:49:51 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.1]:54889 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1782039AbgJZOtu (ORCPT ); Mon, 26 Oct 2020 10:49:50 -0400 Received: from [100.112.131.142] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-a.us-west-2.aws.symcld.net id BC/75-04725-C02E69F5; Mon, 26 Oct 2020 14:49:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFIsWRWlGSWpSXmKPExsWSLveKTZfn0bR 4g5/b2SwOnTvAbHF40QtGi6/fbrNbvDk+ncnizO2FTBY3P31jtVi95wWzA7vHrIZeNo+ds+6y e/zatobFY/nBaUwe7/ddZfP4vEkugC2KNTMvKb8igTVjx4V2loKzihXzfm9namD8INPFyMUhJ PCfUWLvwxtMXYwcQM4bRomDzl2MnBxsAtoSW7b8YgMJiwjISHxY6wlSzizwilFix8uvLCA1wg IBEnN2TQezWQRUJU6v+s8IYvMK2Eh0v1nNDGJLCMhLPO1dDmZzCthKzL4wG8wWEgiTmLB6GQt EvaDEyZlPwGxmoPrmrRA1zAISEgdfvGAGuUFCQEHiwRWokQkSy17eYZ7AKDALSfcsJN2zkHQv YGRexWieVJSZnlGSm5iZo2toYKBraGika2hkqWtsrJdYpZuoV1qsW55aXKJrpJdYXqxXXJmbn JOil5dasokRGCUpBY2KOxgvvP6gd4hRkoNJSZT32L5p8UJ8SfkplRmJxRnxRaU5qcWHGGU4OJ QkeEseAOUEi1LTUyvSMnOAEQuTluDgURLhXQ2S5i0uSMwtzkyHSJ1iVJQS5z0NkhAASWSU5sG 1wZLEJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvL9ApvBk5pXATQdGGNDNIrxtFVNAFpck IqSkGpi4hd+95zsl7vSl5/SjRqHLh+amrbk56c/s+spz55/4c5xhtnylw3uj58hzkx5JH7td5 fYvq7oPF3vZ1iv3RrvPvLC4fn5A2px1D5gnipU95Vx59JBCqvm55tgzeguv/GJw3jN327+EMC OFh59fTc/X5FDOCjb/2vLoa1z+rh159n8ZFfznztG8xlz/Q/+rveTyJ6FPUm6+jmE/ey1V5oL MqhkLhOInlSqd0uvMy2hLD/k7pS7q348PU76be75+Zf7K/PexLz90N1u8OPPijFbku3/++ZyB Hu90Hrf+Y3j0naEh8dqGPb8MFDp/MD70nNTvVdVnu2e7wsuqqIPvDrDs+DanoGWrm/Tv7ENOq uablViKMxINtZiLihMB8QS5ao0DAAA= X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-16.tower-336.messagelabs.com!1603723786!238994!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 22717 invoked from network); 26 Oct 2020 14:49:47 -0000 Received: from unknown (HELO lenovo.com) (103.30.234.6) by server-16.tower-336.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Oct 2020 14:49:47 -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 1A278C3312EAE9B7A35B; Mon, 26 Oct 2020 22:49:43 +0800 (CST) Received: from localhost.localdomain.com (10.64.83.193) 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; Mon, 26 Oct 2020 07:49:39 -0700 From: Mark Pearson To: CC: , , , , , , , "Nitin Joshi" Subject: [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor Date: Mon, 26 Oct 2020 10:45:11 -0400 Message-ID: <20201026144512.621479-2-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201026144512.621479-1-markpearson@lenovo.com> References: <20201026144512.621479-1-markpearson@lenovo.com> MIME-Version: 1.0 X-Originating-IP: [10.64.83.193] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use input device event support for notifying userspace of palm sensor state changes Co-developed-by: Nitin Joshi Signed-off-by: Nitin Joshi Signed-off-by: Mark Pearson --- Changes in V2: - Update commit message to be correct Changes in V3: - remove unnecessary global state variable - clean up error handling code - set dangling pointer to null drivers/platform/x86/thinkpad_acpi.c | 95 +++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index eae3579f106f..3cb07c12a705 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 palmsensor_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 */ + palmsensor_refresh(); return true; default: @@ -9918,6 +9919,92 @@ 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; + +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 palmsensor_refresh(void) +{ + bool state; + int err; + + if (has_palmsensor) { + err = palmsensor_get(&has_palmsensor, &state); + if (err) + return; + input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, state); + input_sync(tpacpi_sw_dev); + } +} + +static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) +{ + int palm_err, err; + bool palm_state; + + palm_err = palmsensor_get(&has_palmsensor, &palm_state); + /* If support isn't available (ENODEV) then quit, but don't return an error */ + if (palm_err == -ENODEV) + return 1; + + /* Otherwise, if there was an error return it */ + if (palm_err && (palm_err != ENODEV)) + 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; + + input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY); + input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state); + err = input_register_device(tpacpi_sw_dev); + if (err) { + input_free_device(tpacpi_sw_dev); + tpacpi_sw_dev = NULL; + return 0; + } + } + return 1; +} + +static void proxsensor_exit(void) +{ + input_unregister_device(tpacpi_sw_dev); +} + +static struct ibm_struct proxsensor_driver_data = { + .name = "proximity-sensor", + .exit = proxsensor_exit, +}; /**************************************************************************** **************************************************************************** * @@ -10411,6 +10498,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 Mon Oct 26 14:45:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 11857429 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 30CF592C for ; Mon, 26 Oct 2020 14:49:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 222E122265 for ; Mon, 26 Oct 2020 14:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782042AbgJZOtx (ORCPT ); Mon, 26 Oct 2020 10:49:53 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.3]:51819 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1782039AbgJZOtx (ORCPT ); Mon, 26 Oct 2020 10:49:53 -0400 Received: from [100.112.3.43] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-b.us-east-1.aws.symcld.net id ED/98-43594-E02E69F5; Mon, 26 Oct 2020 14:49:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFIsWRWlGSWpSXmKPExsWSLveKTZfv0bR 4g/adKhaHzh1gtji86AWjxddvt9kt3hyfzmRx5vZCJoubn76xWqze84LZgd1jVkMvm8fOWXfZ PX5tW8PisfzgNCaP9/uusnl83iQXwBbFmpmXlF+RwJpxaf5u5oL/MhXdO2cxNjDekOhi5OIQE vjPKNH8ZyUThPOGUaKx/SJ7FyMnB5uAtsSWLb/Yuhg5OEQEZCQ+rPUEqWEWeMUosePlVxaQGm EBf4lD+3uZQGwWAVWJ4+t/MYLYvAI2EpeWPQabIyEgL/G0dzkziM0pYCsx+8JsMFtIIExiwup lLBD1ghInZz4Bs5mB6pu3QtQwC0hIHHzxghnkBgkBBYkHV5ghRiZILHt5h3kCo8AsJN2zkHTP QtK9gJF5FaNpUlFmekZJbmJmjq6hgYGuoaGRrpGumaVeYpVukl5psW5qYnGJrqFeYnmxXnFlb nJOil5easkmRmCUpBQwue5g/P36g94hRkkOJiVR3mP7psUL8SXlp1RmJBZnxBeV5qQWH2KU4e BQkuAteQCUEyxKTU+tSMvMAUYsTFqCg0dJhHc1SJq3uCAxtzgzHSJ1ilFRSpz3NEhCACSRUZo H1wZLEpcYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfP+ApnCk5lXAjcdGF1AN4vwtlVMAVlc koiQkmpgatjuHfrrc9e3oKedrdWijwUdJR5t7vmWfHvr/LiyZZ++mbx407dXeqlxqL9Xg9riz 91m6scfqUy5rpEuVc7zxPG9UGfCrgr2u4pW/g3ZJ/5efrrV+vL3iKzeLwVHS+Y3eilbf9m2gC 2o8eApxxwlxm1L9cs37D1StDR+LW/x03zOz1Jc/4x9/+1de+Gp5S7Bd69uhHfM173Qs3wXwxN fyVlTVhp+1bl4zcG1MmfH94Bj1d/UjojlLnayEb5SsnLxusbbMyazHFP8slPX2bn12ftkLVlZ l1UPk+KDuDNiaxPTeHYwbtL74PeLP2mWmmlE4zOJt4YJhz85TG8x6ZvpskmR0/2M3+yOSN6nd +c7KbEUZyQaajEXFScCAKr3KKGNAwAA X-Env-Sender: markpearson@lenovo.com X-Msg-Ref: server-16.tower-395.messagelabs.com!1603723787!862649!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 12103 invoked from network); 26 Oct 2020 14:49:50 -0000 Received: from unknown (HELO lenovo.com) (103.30.234.6) by server-16.tower-395.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Oct 2020 14:49:50 -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 01A5D85408E67CAF4860; Mon, 26 Oct 2020 22:49:45 +0800 (CST) Received: from localhost.localdomain.com (10.64.83.193) 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; Mon, 26 Oct 2020 07:49:42 -0700 From: Mark Pearson To: CC: , , , , , , , "Nitin Joshi" Subject: [PATCH v3 3/3] platform/x86: thinkpad_acpi: Add support for lap sensor Date: Mon, 26 Oct 2020 10:45:12 -0400 Message-ID: <20201026144512.621479-3-markpearson@lenovo.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201026144512.621479-1-markpearson@lenovo.com> References: <20201026144512.621479-1-markpearson@lenovo.com> MIME-Version: 1.0 X-Originating-IP: [10.64.83.193] X-ClientProxiedBy: reswpmail04.lenovo.com (10.62.32.23) To reswpmail04.lenovo.com (10.62.32.23) Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use input device event support for notifying userspace of lap mode sensor state changes. Reviewed-by: Nitin Joshi Signed-off-by: Mark Pearson --- Changes in V2: - Update commit message to be correct Changes in V3: - Update lap sensor code with same fixes applied to palm sensor code. - Correct error handling in init so returns an error if one encountered. drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 3cb07c12a705..fe438a5e1dbe 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9928,6 +9928,22 @@ static struct ibm_struct dytc_driver_data = { struct input_dev *tpacpi_sw_dev; bool has_palmsensor; +bool has_lapsensor; + +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) { @@ -9958,21 +9974,40 @@ static void palmsensor_refresh(void) } } +static void lapsensor_refresh(void) +{ + bool state; + int err; + + if (has_lapsensor) { + err = lapsensor_get(&has_lapsensor, &state); + if (err) + return; + input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, state); + input_sync(tpacpi_sw_dev); + } +} + static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) { - int palm_err, err; - bool palm_state; + int palm_err, lap_err, err; + bool palm_state, lap_state; palm_err = palmsensor_get(&has_palmsensor, &palm_state); - /* If support isn't available (ENODEV) then quit, but don't return an error */ - if (palm_err == -ENODEV) + lap_err = lapsensor_get(&has_lapsensor, &lap_state); + /* + * If support isn't available (ENODEV) for both devices then quit, but + * don't return an error. + */ + if ((palm_err == -ENODEV) && (lap_err == -ENODEV)) return 1; - /* Otherwise, if there was an error return it */ if (palm_err && (palm_err != ENODEV)) return palm_err; + if (lap_err && (lap_err != ENODEV)) + return lap_err; - if (has_palmsensor) { + if (has_palmsensor || has_lapsensor) { tpacpi_sw_dev = input_allocate_device(); if (!tpacpi_sw_dev) return -ENOMEM; @@ -9984,8 +10019,14 @@ static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm) tpacpi_sw_dev->id.version = TPACPI_HKEY_INPUT_VERSION; tpacpi_sw_dev->dev.parent = &tpacpi_pdev->dev; - input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY); - input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state); + if (has_palmsensor) { + input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY); + input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state); + } + if (has_lapsensor) { + input_set_capability(tpacpi_sw_dev, EV_SW, SW_LAP_PROXIMITY); + input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, lap_state); + } err = input_register_device(tpacpi_sw_dev); if (err) { input_free_device(tpacpi_sw_dev); @@ -10053,8 +10094,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(); + lapsensor_refresh(); + } }