From patchwork Fri Jan 15 16:18:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12023197 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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 CD281C433DB for ; Fri, 15 Jan 2021 16:20:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 914DC238A0 for ; Fri, 15 Jan 2021 16:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726475AbhAOQUW (ORCPT ); Fri, 15 Jan 2021 11:20:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43624 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbhAOQUW (ORCPT ); Fri, 15 Jan 2021 11:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610727535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=tp/61DcshJ1UVwzarIX8rW6yr7gLDQGpiZ7jjqyFuc8=; b=PL8IZCXnJQOmDh1YtVdtb57OOO6FUlkBbnHC3Ww6Y0IxZFjVNJ3mmrIyzR5mlTpc1HdNJw s27ulgAj/ikMAm9eymm5YSI8TeMB+nHhdgCmfagBg3k5K9Sa6z/h6A+8B6pTCOatjx4pmc lQcqd8pp7r48ywb/R41nNNF2GFD3KNo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-348-doZUmSbsPPKcrZPRHVig5g-1; Fri, 15 Jan 2021 11:18:53 -0500 X-MC-Unique: doZUmSbsPPKcrZPRHVig5g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 943A5AFA83; Fri, 15 Jan 2021 16:18:52 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 769A261D2D; Fri, 15 Jan 2021 16:18:51 +0000 (UTC) From: Hans de Goede To: Mark Gross Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, Elia Devito Subject: [PATCH 1/4] platform/x86: intel-vbtn: Rework wakeup handling in notify_handler() Date: Fri, 15 Jan 2021 17:18:47 +0100 Message-Id: <20210115161850.117614-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Rework the wakeup path inside notify_handler() to special case the buttons (KE_KEY) case instead of the switches case. In case of a button wake event we want to skip reporting this, mirroring how the drivers/acpi/button.c code skips the reporting in the wakeup case (suspended flag set) too. The reason to skip reporting in this case is that some Linux desktop-environments will immediately resuspend if we report an evdev event for the power-button press on wakeup. Before this commit the skipping of the button-press was done in a round-about way: In case of a wakeup the regular sparse_keymap_report_event() would always be skipped by an early return, and then to avoid not reporting switch changes on wakeup there was a special KE_SW path with a duplicate sparse_keymap_report_event() call. This commit refactors the wakeup handling to explicitly skip the reporting for button wake events, while using the regular reporting path for non button (switches) wakeup events. No intentional functional impact. Cc: Elia Devito Signed-off-by: Hans de Goede --- drivers/platform/x86/intel-vbtn.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c index 30a9062d2b4b..e1bb37a03ba3 100644 --- a/drivers/platform/x86/intel-vbtn.c +++ b/drivers/platform/x86/intel-vbtn.c @@ -131,22 +131,17 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) if (priv->wakeup_mode) { ke = sparse_keymap_entry_from_scancode(priv->input_dev, event); - if (ke) { - pm_wakeup_hard_event(&device->dev); - - /* - * Switch events like tablet mode will wake the device - * and report the new switch position to the input - * subsystem. - */ - if (ke->type == KE_SW) - sparse_keymap_report_event(priv->input_dev, - event, - val, - 0); + if (!ke) + goto out_unknown; + + pm_wakeup_hard_event(&device->dev); + + /* + * Skip reporting an evdev event for button wake events, + * mirroring how the drivers/acpi/button.c code skips this too. + */ + if (ke->type == KE_KEY) return; - } - goto out_unknown; } /* From patchwork Fri Jan 15 16:18:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12023199 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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 DCBB2C433DB for ; Fri, 15 Jan 2021 16:20:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DC9C238EB for ; Fri, 15 Jan 2021 16:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727679AbhAOQU0 (ORCPT ); Fri, 15 Jan 2021 11:20:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20402 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbhAOQUY (ORCPT ); Fri, 15 Jan 2021 11:20:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610727536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xeYu7O/WG3ASZ/NoUK2sFogKJnJnG93QniEAjxTgej4=; b=epTOh+cfSrNWpc2mFHwkfp2dm85QCtSbUjPuTW1k2ZeDBDDptTys9XxJDCmJu0uV8JZwwP OMpaUmAxu6eKc88obLC9w9rctL+Q6PFoz2nq3BPh3YLvEmF5CIwYQRe0cinD92klsAL8M7 2GtcPJEMsY9amfsK6XZQ4f83dnn1HgM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-AJWA6FfgMgeH18JmkBPU5Q-1; Fri, 15 Jan 2021 11:18:55 -0500 X-MC-Unique: AJWA6FfgMgeH18JmkBPU5Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0095802B46; Fri, 15 Jan 2021 16:18:53 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAD125C276; Fri, 15 Jan 2021 16:18:52 +0000 (UTC) From: Hans de Goede To: Mark Gross Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, Elia Devito Subject: [PATCH 2/4] platform/x86: intel-vbtn: Create 2 separate input-devs for buttons and switches Date: Fri, 15 Jan 2021 17:18:48 +0100 Message-Id: <20210115161850.117614-2-hdegoede@redhat.com> In-Reply-To: <20210115161850.117614-1-hdegoede@redhat.com> References: <20210115161850.117614-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Create 2 separate input-devs for buttons and switches, this is a preparation for dynamically registering the switches-input device for devices which are not on the switches allow-list, but do make Notify() calls with an event value from the switches sparse-keymap. This also brings the intel-vbtn driver inline with the intel-hid driver which is doing the same thing. Cc: Elia Devito Signed-off-by: Hans de Goede --- Note that checkpatch will complain about the 2 assignments of ke inside if-s. I know those are generally something to be avoided but in this case using them leads to much cleaner code. --- drivers/platform/x86/intel-vbtn.c | 98 +++++++++++++++++++------------ 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c index e1bb37a03ba3..04725173d087 100644 --- a/drivers/platform/x86/intel-vbtn.c +++ b/drivers/platform/x86/intel-vbtn.c @@ -44,6 +44,7 @@ static const struct key_entry intel_vbtn_keymap[] = { { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN } }, /* volume-down key release */ { KE_KEY, 0xC8, { KEY_ROTATE_LOCK_TOGGLE } }, /* rotate-lock key press */ { KE_KEY, 0xC9, { KEY_ROTATE_LOCK_TOGGLE } }, /* rotate-lock key release */ + { KE_END } }; static const struct key_entry intel_vbtn_switchmap[] = { @@ -51,14 +52,15 @@ static const struct key_entry intel_vbtn_switchmap[] = { { KE_SW, 0xCB, { .sw = { SW_DOCK, 0 } } }, /* Undocked */ { KE_SW, 0xCC, { .sw = { SW_TABLET_MODE, 1 } } }, /* Tablet */ { KE_SW, 0xCD, { .sw = { SW_TABLET_MODE, 0 } } }, /* Laptop */ + { KE_END } }; #define KEYMAP_LEN \ (ARRAY_SIZE(intel_vbtn_keymap) + ARRAY_SIZE(intel_vbtn_switchmap) + 1) struct intel_vbtn_priv { - struct key_entry keymap[KEYMAP_LEN]; - struct input_dev *input_dev; + struct input_dev *buttons_dev; + struct input_dev *switches_dev; bool has_buttons; bool has_switches; bool wakeup_mode; @@ -77,48 +79,62 @@ static void detect_tablet_mode(struct platform_device *device) return; m = !(vgbs & VGBS_TABLET_MODE_FLAGS); - input_report_switch(priv->input_dev, SW_TABLET_MODE, m); + input_report_switch(priv->switches_dev, SW_TABLET_MODE, m); m = (vgbs & VGBS_DOCK_MODE_FLAG) ? 1 : 0; - input_report_switch(priv->input_dev, SW_DOCK, m); + input_report_switch(priv->switches_dev, SW_DOCK, m); } +/* + * Note this unconditionally creates the 2 input_dev-s and sets up + * the sparse-keymaps. Only the registration is conditional on + * have_buttons / have_switches. This is done so that the notify + * handler can always call sparse_keymap_entry_from_scancode() + * on the input_dev-s do determine the event type. + */ static int intel_vbtn_input_setup(struct platform_device *device) { struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev); - int ret, keymap_len = 0; + int ret; - if (priv->has_buttons) { - memcpy(&priv->keymap[keymap_len], intel_vbtn_keymap, - ARRAY_SIZE(intel_vbtn_keymap) * - sizeof(struct key_entry)); - keymap_len += ARRAY_SIZE(intel_vbtn_keymap); - } + priv->buttons_dev = devm_input_allocate_device(&device->dev); + if (!priv->buttons_dev) + return -ENOMEM; - if (priv->has_switches) { - memcpy(&priv->keymap[keymap_len], intel_vbtn_switchmap, - ARRAY_SIZE(intel_vbtn_switchmap) * - sizeof(struct key_entry)); - keymap_len += ARRAY_SIZE(intel_vbtn_switchmap); - } + ret = sparse_keymap_setup(priv->buttons_dev, intel_vbtn_keymap, NULL); + if (ret) + return ret; - priv->keymap[keymap_len].type = KE_END; + priv->buttons_dev->dev.parent = &device->dev; + priv->buttons_dev->name = "Intel Virtual Buttons"; + priv->buttons_dev->id.bustype = BUS_HOST; + + if (priv->has_buttons) { + ret = input_register_device(priv->buttons_dev); + if (ret) + return ret; + } - priv->input_dev = devm_input_allocate_device(&device->dev); - if (!priv->input_dev) + priv->switches_dev = devm_input_allocate_device(&device->dev); + if (!priv->switches_dev) return -ENOMEM; - ret = sparse_keymap_setup(priv->input_dev, priv->keymap, NULL); + ret = sparse_keymap_setup(priv->switches_dev, intel_vbtn_switchmap, NULL); if (ret) return ret; - priv->input_dev->dev.parent = &device->dev; - priv->input_dev->name = "Intel Virtual Button driver"; - priv->input_dev->id.bustype = BUS_HOST; + priv->switches_dev->dev.parent = &device->dev; + priv->switches_dev->name = "Intel Virtual Switches"; + priv->switches_dev->id.bustype = BUS_HOST; - if (priv->has_switches) + if (priv->has_switches) { detect_tablet_mode(device); - return input_register_device(priv->input_dev); + ret = input_register_device(priv->switches_dev); + if (ret) + return ret; + } + + return 0; } static void notify_handler(acpi_handle handle, u32 event, void *context) @@ -127,13 +143,27 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev); unsigned int val = !(event & 1); /* Even=press, Odd=release */ const struct key_entry *ke, *ke_rel; + struct input_dev *input_dev; bool autorelease; - if (priv->wakeup_mode) { - ke = sparse_keymap_entry_from_scancode(priv->input_dev, event); - if (!ke) - goto out_unknown; + if ((ke = sparse_keymap_entry_from_scancode(priv->buttons_dev, event))) { + if (!priv->has_buttons) { + dev_warn(&device->dev, "Warning: received a button event on a device without buttons, please report this.\n"); + return; + } + input_dev = priv->buttons_dev; + } else if ((ke = sparse_keymap_entry_from_scancode(priv->switches_dev, event))) { + if (!priv->has_switches) { + dev_warn(&device->dev, "Warning: received a switches event on a device without switchess, please report this.\n"); + return; + } + input_dev = priv->switches_dev; + } else { + dev_dbg(&device->dev, "unknown event index 0x%x\n", event); + return; + } + if (priv->wakeup_mode) { pm_wakeup_hard_event(&device->dev); /* @@ -148,14 +178,10 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) * Even press events are autorelease if there is no corresponding odd * release event, or if the odd event is KE_IGNORE. */ - ke_rel = sparse_keymap_entry_from_scancode(priv->input_dev, event | 1); + ke_rel = sparse_keymap_entry_from_scancode(input_dev, event | 1); autorelease = val && (!ke_rel || ke_rel->type == KE_IGNORE); - if (sparse_keymap_report_event(priv->input_dev, event, val, autorelease)) - return; - -out_unknown: - dev_dbg(&device->dev, "unknown event index 0x%x\n", event); + sparse_keymap_report_event(input_dev, event, val, autorelease); } static bool intel_vbtn_has_buttons(acpi_handle handle) From patchwork Fri Jan 15 16:18:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12023201 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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 E1787C43331 for ; Fri, 15 Jan 2021 16:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8984238EE for ; Fri, 15 Jan 2021 16:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726669AbhAOQU1 (ORCPT ); Fri, 15 Jan 2021 11:20:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30989 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbhAOQU0 (ORCPT ); Fri, 15 Jan 2021 11:20:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610727540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n/IyGGyAtzldC2xck5zJKauolrnnq/fedN1dZDSs/RU=; b=FaaZ4s79haiVGwkfdwM6zJrH3T0cdYxjSYh0QJvC1EmMbzxVW4SVhfVmsOKSX2JS7lXlBR Tvet4cUwK3wEO1zj/izSTQM9vRSQJ1+x7GXwsUknFUpYBzoDhW1Tbxqj4/UXxCyQtiXUP+ 2sWT9s9T2PJ7CJ3BypP2PbP3aAonhjk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-mV29elQvM1GnAx_yCcavlQ-1; Fri, 15 Jan 2021 11:18:56 -0500 X-MC-Unique: mV29elQvM1GnAx_yCcavlQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A294100E424; Fri, 15 Jan 2021 16:18:55 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4393B5C276; Fri, 15 Jan 2021 16:18:54 +0000 (UTC) From: Hans de Goede To: Mark Gross Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, Elia Devito Subject: [PATCH 3/4] platform/x86: intel-vbtn: Add alternative method to enable switches Date: Fri, 15 Jan 2021 17:18:49 +0100 Message-Id: <20210115161850.117614-3-hdegoede@redhat.com> In-Reply-To: <20210115161850.117614-1-hdegoede@redhat.com> References: <20210115161850.117614-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Some 2-in-1s have a broken VGBS method, so we cannot get an initial state for the switches from them. Reporting the wrong initial state for SW_TABLET_MODE causes serious problems (touchpad and/or keyboard events being ignored by userspace when reporting SW_TABLET_MODE=1), so on these devices we cannot register an input-dev for the switches at probe time. We can however register an input-dev for the switches as soon as we receive the first switches event, because then we will know the state. Note this mirrors the behavior of recent changs to the intel-hid driver which also registers a separate switches input-dev on receiving the first event on machines with a broken VGBS method. Cc: Elia Devito Signed-off-by: Hans de Goede --- drivers/platform/x86/intel-vbtn.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c index 04725173d087..852cb07c3dfd 100644 --- a/drivers/platform/x86/intel-vbtn.c +++ b/drivers/platform/x86/intel-vbtn.c @@ -145,6 +145,7 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) const struct key_entry *ke, *ke_rel; struct input_dev *input_dev; bool autorelease; + int ret; if ((ke = sparse_keymap_entry_from_scancode(priv->buttons_dev, event))) { if (!priv->has_buttons) { @@ -154,8 +155,12 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) input_dev = priv->buttons_dev; } else if ((ke = sparse_keymap_entry_from_scancode(priv->switches_dev, event))) { if (!priv->has_switches) { - dev_warn(&device->dev, "Warning: received a switches event on a device without switchess, please report this.\n"); - return; + dev_info(&device->dev, "Registering Intel Virtual Switches input-dev after receiving a switch event\n"); + ret = input_register_device(priv->switches_dev); + if (ret) + return; + + priv->has_switches = true; } input_dev = priv->switches_dev; } else { From patchwork Fri Jan 15 16:18:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12023203 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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 A0C61C4321A for ; Fri, 15 Jan 2021 16:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 794DB2395A for ; Fri, 15 Jan 2021 16:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728704AbhAOQU3 (ORCPT ); Fri, 15 Jan 2021 11:20:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51993 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbhAOQU3 (ORCPT ); Fri, 15 Jan 2021 11:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610727542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XmnlWSG9j841vqLme9jhs1RsEHFzRjpKiyCDixbZvSc=; b=fxeDg7Uyypd4mFz6XtjYzYBjViahd6LWh0YlNTt+uHIFjZ2N6Ke6JJs/Rio060Rj8iks+V qdGX8dmnwF1b1y7Yizs1AQt/UCZXdvIrAagyRKwJ61kSv1c+O9KhzulcRolTPyjlHPFDFg lrhSfe+xZDbzpdT3RGZBBnC5oIzxghc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-jde5AtoPNSaWKDQ02PcAnw-1; Fri, 15 Jan 2021 11:18:58 -0500 X-MC-Unique: jde5AtoPNSaWKDQ02PcAnw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C111B107ACF8; Fri, 15 Jan 2021 16:18:56 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id A56505F9C5; Fri, 15 Jan 2021 16:18:55 +0000 (UTC) From: Hans de Goede To: Mark Gross Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, Elia Devito Subject: [PATCH 4/4] platform/x86: intel-vbtn: Eval VBDL after registering our notifier Date: Fri, 15 Jan 2021 17:18:50 +0100 Message-Id: <20210115161850.117614-4-hdegoede@redhat.com> In-Reply-To: <20210115161850.117614-1-hdegoede@redhat.com> References: <20210115161850.117614-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The VBDL ACPI method enables button/switch reporting through the intel-vbtn device. In some cases the embedded-controller (EC) might call Notify() on the intel-vbtn device immediately after the the VBDL call to make sure that the OS is synced with the EC's button and switch state. If we register our notify_handler after evaluating VBDL this means that we might miss the Notify() calls made by the EC to sync the state. E.g. the HP Stream x360 Convertible PC 11 has a VGBS method which always returns 0, independent of the actual SW_TABLET_MODE state of the device; and immediately after the VBDL call it calls Notify(0xCD) or Notify(0xCC) to report the actual state. Move the evaluation of VBDL to after registering our notify_handler so that we don't miss any events. Cc: Elia Devito Signed-off-by: Hans de Goede --- drivers/platform/x86/intel-vbtn.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c index 852cb07c3dfd..8a8017f9ca91 100644 --- a/drivers/platform/x86/intel-vbtn.c +++ b/drivers/platform/x86/intel-vbtn.c @@ -189,14 +189,6 @@ static void notify_handler(acpi_handle handle, u32 event, void *context) sparse_keymap_report_event(input_dev, event, val, autorelease); } -static bool intel_vbtn_has_buttons(acpi_handle handle) -{ - acpi_status status; - - status = acpi_evaluate_object(handle, "VBDL", NULL, NULL); - return ACPI_SUCCESS(status); -} - /* * There are several laptops (non 2-in-1) models out there which support VGBS, * but simply always return 0, which we translate to SW_TABLET_MODE=1. This in @@ -271,7 +263,7 @@ static int intel_vbtn_probe(struct platform_device *device) acpi_status status; int err; - has_buttons = intel_vbtn_has_buttons(handle); + has_buttons = acpi_has_method(handle, "VBDL"); has_switches = intel_vbtn_has_switches(handle); if (!has_buttons && !has_switches) { @@ -300,6 +292,12 @@ static int intel_vbtn_probe(struct platform_device *device) if (ACPI_FAILURE(status)) return -EBUSY; + if (has_buttons) { + status = acpi_evaluate_object(handle, "VBDL", NULL, NULL); + if (ACPI_FAILURE(status)) + dev_err(&device->dev, "Error VBDL failed with ACPI status %d\n", status); + } + device_init_wakeup(&device->dev, true); /* * In order for system wakeup to work, the EC GPE has to be marked as