From patchwork Thu Dec 3 21:20:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elia Devito X-Patchwork-Id: 11949613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FA0DC4361A for ; Thu, 3 Dec 2020 21:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 556B62223E for ; Thu, 3 Dec 2020 21:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727450AbgLCVWN (ORCPT ); Thu, 3 Dec 2020 16:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbgLCVWN (ORCPT ); Thu, 3 Dec 2020 16:22:13 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F5EC061A51; Thu, 3 Dec 2020 13:21:32 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id g185so5285060wmf.3; Thu, 03 Dec 2020 13:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aKeMXOH+eJz7j+HhXLNdNRBb9s9T/2sajZT9nLh+WJ4=; b=VKWs5J1DwItm0Gz458sdJheb1IOXNbPp+TSvfpRljk3gBdmeeoz7MjXgkAG5RHXLtI 8g4kFhieLcva3WewYfBDNjmjyIJ2zOIzhdSnZBMe2xVN1O5PZXKfUEF4DI8+JrMd7veU /tDZPdaVon3HkCUhB82jWtimVkh+tjpRwF7z6C/I/YeHz+s7BQ8XH7Sganmj5Kyi4T9r pl8XMmRmOE/q0Cpyk+yAWX0zw9Hf0fEsiognhqmqU1Tm7aw1h+LQPgSZ8EOUr8icn0xX xxLoyiuASEMgVWrdL0rfwgj5E14Djd1vrGYt0DVFMm7evHSVwRL8GYjiDzfXjSoq4ipj NE9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aKeMXOH+eJz7j+HhXLNdNRBb9s9T/2sajZT9nLh+WJ4=; b=TvwbNlOW94HAliEfYSscRcLhCQAhFLA2qg73VZ1lKC9gjHJ1GRA/htFaoujB07xPVq 64Rc9MwPqEjcgsS9HYSXQolwiez22Tv2lMPW/TcDyThblY3zlmUeveztdKijcIzbzAc2 jQHUKOpIq+9d9/fHK5bcjM1Iph6IdAcFNUCDDr6npjBfB4auZ7ugHmsy3GxQsT6A4Adg pUdvKypJ5eTZwr4xFxy1UZEnyDnA7F0CV6g2f81yehv3f8MyKT7uTXrnOxYuhLKpyh5L Gs+EjKYzVOPkESjNj4FqkegnDjyfIbDjaEsvlpHL5G0eHH0irvXCCSTVhXSDEdAv/w50 EYSw== X-Gm-Message-State: AOAM533HkiSrAAWVN7K/BKX/Ye0WprZRVPnfZ3Amcpni5KYpKOEUg/w2 IPitN2D6rplCwPvj8ZI3RWI= X-Google-Smtp-Source: ABdhPJwfgUeIXfND4K1NcXP0WxqZVqBuJ18v6DD/Bif3lF6m5+XnOi8h+0pKXV0O/npg1JfYbBtOnQ== X-Received: by 2002:a1c:7e87:: with SMTP id z129mr751718wmc.176.1607030491372; Thu, 03 Dec 2020 13:21:31 -0800 (PST) Received: from localhost.localdomain (host-79-13-10-171.retail.telecomitalia.it. [79.13.10.171]) by smtp.gmail.com with ESMTPSA id q16sm853280wrn.13.2020.12.03.13.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 13:21:30 -0800 (PST) From: Elia Devito Cc: Elia Devito , Alex Hung , Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] intel-hid: add support for SW_TABLET_MODE Date: Thu, 3 Dec 2020 22:20:01 +0100 Message-Id: <20201203212000.35898-1-eliadevito@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <69f340f6-4301-6546-f14a-47d90208d44b@redhat.com> References: <69f340f6-4301-6546-f14a-47d90208d44b@redhat.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE, implement this with DMI based allow-list to be sure to activate support only on models that effectively have it. Signed-off-by: Elia Devito --- v2: patch reworked according to received feedbacks drivers/platform/x86/intel-hid.c | 98 ++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/drivers/platform/x86/intel-hid.c b/drivers/platform/x86/intel-hid.c index 86261970bd8f..fed24d4f28b8 100644 --- a/drivers/platform/x86/intel-hid.c +++ b/drivers/platform/x86/intel-hid.c @@ -15,6 +15,9 @@ #include #include +/* When NOT in tablet mode, VGBS returns with the flag 0x40 */ +#define TABLET_MODE_FLAG 0x40 + MODULE_LICENSE("GPL"); MODULE_AUTHOR("Alex Hung"); @@ -89,9 +92,26 @@ static const struct dmi_system_id button_array_table[] = { { } }; +/* + * Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE, + * these need to be compared via a DMI based authorization list because some + * models have unreliable VGBS return which could cause incorrect + * SW_TABLET_MODE report. + */ +static const struct dmi_system_id dmi_vgbs_allow_list[] = { + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Convertible 15-df0xxx"), + }, + }, + { } +}; + struct intel_hid_priv { struct input_dev *input_dev; struct input_dev *array; + struct input_dev *switches; bool wakeup_mode; }; @@ -347,6 +367,38 @@ static int intel_button_array_input_setup(struct platform_device *device) return input_register_device(priv->array); } +static int intel_hid_switches_setup(struct platform_device *device) +{ + struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); + + /* Setup input device for switches */ + priv->switches = devm_input_allocate_device(&device->dev); + if (!priv->switches) + return -ENOMEM; + + __set_bit(EV_SW, priv->switches->evbit); + __set_bit(SW_TABLET_MODE, priv->switches->swbit); + + priv->switches->name = "Intel HID switches"; + priv->switches->id.bustype = BUS_HOST; + return input_register_device(priv->switches); +} + +static void detect_tablet_mode(struct platform_device *device) +{ + struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); + acpi_handle handle = ACPI_HANDLE(&device->dev); + unsigned long long vgbs; + int m; + + if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_VGBS_FN, &vgbs)) + return; + + m = !(vgbs & TABLET_MODE_FLAG); + input_report_switch(priv->switches, SW_TABLET_MODE, m); + input_sync(priv->switches); +} + static void notify_handler(acpi_handle handle, u32 event, void *context) { struct platform_device *device = context; @@ -363,6 +415,13 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) if (event == 0xce) goto wakeup; + /* + * Switch events will wake the device and report the new switch + * position to the input subsystem. + */ + if (priv->switches && (event == 0xcc || event == 0xcd)) + goto wakeup; + /* Wake up on 5-button array events only. */ if (event == 0xc0 || !priv->array) return; @@ -374,6 +433,21 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) wakeup: pm_wakeup_hard_event(&device->dev); + + if (priv->switches) { + if (event == 0xcc) { + input_report_switch(priv->switches, SW_TABLET_MODE, 1); + input_sync(priv->switches); + return; + } + + if (event == 0xcd) { + input_report_switch(priv->switches, SW_TABLET_MODE, 0); + input_sync(priv->switches); + return; + } + } + return; } @@ -398,6 +472,20 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) } } + if (priv->switches) { + if (event == 0xcc) { + input_report_switch(priv->switches, SW_TABLET_MODE, 1); + input_sync(priv->switches); + return; + } + + if (event == 0xcd) { + input_report_switch(priv->switches, SW_TABLET_MODE, 0); + input_sync(priv->switches); + return; + } + } + /* 0xC0 is for HID events, other values are for 5 button array */ if (event != 0xc0) { if (!priv->array || @@ -485,6 +573,16 @@ static int intel_hid_probe(struct platform_device *device) pr_err("Failed to setup Intel 5 button array hotkeys\n"); } + /* Setup switches for devices that we know VGBS return correctly */ + if (dmi_check_system(dmi_vgbs_allow_list)) { + dev_info(&device->dev, "platform supports switches\n"); + err = intel_hid_switches_setup(device); + if (err) + pr_err("Failed to setup Intel HID switches\n"); + else + detect_tablet_mode(device); + } + status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler, From patchwork Thu Dec 3 21:21:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elia Devito X-Patchwork-Id: 11949615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 470E5C4361A for ; Thu, 3 Dec 2020 21:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E749922225 for ; Thu, 3 Dec 2020 21:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729710AbgLCVW4 (ORCPT ); Thu, 3 Dec 2020 16:22:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728460AbgLCVW4 (ORCPT ); Thu, 3 Dec 2020 16:22:56 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A1C5C061A4F; Thu, 3 Dec 2020 13:22:15 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id t4so3306560wrr.12; Thu, 03 Dec 2020 13:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zIwz4kMfc7t6lpkiBG3igVGFEHaTI3leni+rbGlAWBA=; b=aSZwLsCbG02upmomplwSwSwedmZwwjJ2J87bLrAIO2GcFJzaQG+0Wb01avh4sbV1aX JfvWpiwdBCQcMxEvBPoxM/0LuYCwrVhKqlbgu96pCocW9svi2FZLekGsHO3eHpKB/K2g aav//ckZ9MWBuzXHVjzeKEVHsaEua3v4ncxjzReJp/Cx4WGRI4yR7ckO2MMvmUwENBmr cSfLo3HFhIAlIp9sTbwcJPpl4mMnO1ojInMvdGkKmFJVdtchjmv/LzgXTYx6blA+9Nle tc9ddsfdFUAdZ+qJAhFyREKHi9kxaJ5YprVQ4X0/MlaiqPeoYlqsYcy9EZemEHr6YK83 9sNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zIwz4kMfc7t6lpkiBG3igVGFEHaTI3leni+rbGlAWBA=; b=pnuegFjuHOWRdz7tw5wSdqpUcXexxe85TCpZHfIzx9xLn2ZOpk4i6mZeEI3/a6PMec TYKczmlPxPr3L/O0B+aRvkd2dvqSJBrX+qSs/GT7O267V08H6p9YmPMfqQ96v2I0t3vx 5np1D/FDyMT6f7ifBi2DWUWQtcnHSEb/Bjpgz5dmw6GotFZCCilqVJhMOjEq3C+8irhZ c3r4S8uNyyuUUEJN5tG1T8eEvXRjYXEH9Fku7TDd6ZvmXFRvC8x2DHJbiTtF/Gd8OVbQ b4PZtWjc5FTFKMXvwDNUIQDtGsBwDxAgkEuUXBAM1D3b4QFk2XKCpOGPDkb90Fr6msJu /srA== X-Gm-Message-State: AOAM530Aqlkn6KsLg63357AW+TGWud20/+8nC7OPgABXPFwe1HgnhxrN 6M5Mejq+ytN0AB+k9/K0q8U= X-Google-Smtp-Source: ABdhPJxEMlsjN43WtUPneFgokIswrABxZVUkEZcg7hyOpI93SFaEgx8MPhjl9LgAeabPO6eB45gY7Q== X-Received: by 2002:a5d:60cb:: with SMTP id x11mr1307927wrt.0.1607030534225; Thu, 03 Dec 2020 13:22:14 -0800 (PST) Received: from localhost.localdomain (host-79-13-10-171.retail.telecomitalia.it. [79.13.10.171]) by smtp.gmail.com with ESMTPSA id g78sm633649wme.33.2020.12.03.13.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 13:22:13 -0800 (PST) From: Elia Devito Cc: Elia Devito , Alex Hung , Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] intel-hid: add alternative method to enable switches Date: Thu, 3 Dec 2020 22:21:49 +0100 Message-Id: <20201203212148.36039-1-eliadevito@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <69f340f6-4301-6546-f14a-47d90208d44b@redhat.com> References: <69f340f6-4301-6546-f14a-47d90208d44b@redhat.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Some convertible have unreliable VGBS return, in these cases we enable support when receiving the first event. Signed-off-by: Elia Devito --- drivers/platform/x86/intel-hid.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/platform/x86/intel-hid.c b/drivers/platform/x86/intel-hid.c index fed24d4f28b8..3cc8f8ac48b2 100644 --- a/drivers/platform/x86/intel-hid.c +++ b/drivers/platform/x86/intel-hid.c @@ -404,6 +404,19 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) struct platform_device *device = context; struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); unsigned long long ev_index; + int err; + + /* + * Some convertible have unreliable VGBS return which could cause incorrect + * SW_TABLET_MODE report, in these cases we enable support when receiving + * the first event instead of during driver setup. + */ + if (!priv->switches && (event == 0xcc || event == 0xcd)) { + dev_info(&device->dev, "switch event received, enable switches supports\n"); + err = intel_hid_switches_setup(device); + if (err) + pr_err("Failed to setup Intel HID switches\n"); + } if (priv->wakeup_mode) { /*