platform/x86: intel-vbtn: Eval VBDL after registering our notifier
authorHans de Goede <hdegoede@redhat.com>
Fri, 15 Jan 2021 16:18:50 +0000 (17:18 +0100)
committerHans de Goede <hdegoede@redhat.com>
Mon, 25 Jan 2021 20:34:36 +0000 (21:34 +0100)
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 <eliadevito@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210115161850.117614-4-hdegoede@redhat.com
drivers/platform/x86/intel-vbtn.c

index 852cb07c3dfdaebab2911ff196a3d415fe427e8f..8a8017f9ca9136691c5689022b98b5b7ef4b14a2 100644 (file)
@@ -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