From patchwork Tue Jan 9 01:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Drake X-Patchwork-Id: 10150825 X-Patchwork-Delegate: andy.shevchenko@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA2BA60210 for ; Tue, 9 Jan 2018 01:20:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D03FE285B9 for ; Tue, 9 Jan 2018 01:20:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4B5C286B8; Tue, 9 Jan 2018 01:20:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B4A2285B9 for ; Tue, 9 Jan 2018 01:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934145AbeAIBUt (ORCPT ); Mon, 8 Jan 2018 20:20:49 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:46119 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934142AbeAIBUq (ORCPT ); Mon, 8 Jan 2018 20:20:46 -0500 Received: by mail-oi0-f66.google.com with SMTP id d124so5299056oib.13 for ; Mon, 08 Jan 2018 17:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessm-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=/86DZdO0Kk2BurHKVfZmsk6pvWViu4o4E6She+dPiv4=; b=Y/0/EFAcKPdsEPsh78gljDH99qOR0yvAreGZ7IbjXO5/r+6gCbEdXFneXN4NTfeQR4 tSGyT0b3L6qbozShzRvVF0VpVKqDzaJqB9/U/16DKSOXloX7EIkAudtY3dWHNP4G5fzq +xnxDhsLwZJdeliLX2z7MeP0EyUEn0aMbctXYIbKRjSyC2j/AL478v7mnBwBbxmW1HGL MwYLTNYF4SgrbM+Gx2cM4QiBA6tA6kTuWGZQqb/VxJnpLxnvYLU0DSdCGNMBprOvkZ5h ugqNPnYF1lNV5hMiylyg0N2GutjrtzjYOPiaFCOlbOJ68jAjJ7csRnpzyvU2VTrCbW3t hxpQ== 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; bh=/86DZdO0Kk2BurHKVfZmsk6pvWViu4o4E6She+dPiv4=; b=RVnbYik3pFeaiphd4vXNzENhr+JlrALMJXC6WZ719F7SqMf+OrLJ8DqNrjjUJDILz0 XJpWyOzax0byBG0wMYY6LZRhAWjHi5PNQ50T/jalfTQOw4mxU3leaoKaMjNrHGZttbJ9 f/rCtHc/+q/382ZST6BNgWJJOxcWQTFEOLFF0FKKP8jii82dFhgw3LyolJwOcfxR7eEZ o28LRtKcD5xbzvpM6wKqsiKQY5uKA+lT18LA0NqajA6xq4Po/3+HGib9CHTkhGNVxnxS iwYjF/6/SdluHruqs89UGZXBAz+NvemLzbEZzsOiZCYNiZITAcSOf7LiAHfjKK63LQKH Dpzg== X-Gm-Message-State: AKwxytd01rGtnymKMhvXvdoemeV6C6KnareXeBaP8kyn6VhYVwyINCUn ULjpVxlGgDzgW3QlW+QxSmfOaw== X-Google-Smtp-Source: ACJfBot7au1t4b6/tS9FYcYcNArBT7SyJu1bPAcMl39qp7u96cCIVdMz4zDWzcuBpGNgkt3o1enRZw== X-Received: by 10.157.49.57 with SMTP id e54mr9164960otc.185.1515460845796; Mon, 08 Jan 2018 17:20:45 -0800 (PST) Received: from limbo.local ([186.77.195.233]) by smtp.gmail.com with ESMTPSA id c1sm6621128otc.54.2018.01.08.17.20.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 17:20:45 -0800 (PST) From: Daniel Drake To: jikos@kernel.org, benjamin.tissoires@redhat.com Cc: linux-input@vger.kernel.org, linux@endlessm.com, carlo@endlessm.com, corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Subject: [PATCH] HID: asus: only support backlight when it's not driven by WMI Date: Mon, 8 Jan 2018 19:20:42 -0600 Message-Id: <20180109012042.13947-1-drake@endlessm.com> X-Mailer: git-send-email 2.14.1 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Asus GL502VSK has the same 0B05:1837 keyboard as we've seen in several Republic of Gamers laptops. However, in this model, the keybard backlight control exposed by hid-asus has no effect on the keyboard backlight. Instead, the keyboard backlight is correctly driven by asus-wmi. With two keyboard backlight devices available (and only the acer-wmi one working), GNOME is picking the wrong one to drive in the UI. Avoid this problem by not creating the backlight interface when we detect a WMI-driven keyboard backlight. We have also tested Asus GL702VMK which does have the hid-asus backlight present, and it still works fine with this patch (WMI method call returns UNSUPPORTED_METHOD). Signed-off-by: Daniel Drake --- drivers/hid/Kconfig | 1 + drivers/hid/hid-asus.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 779c5ae47f36..6d95abc9d8a1 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -149,6 +149,7 @@ config HID_APPLEIR config HID_ASUS tristate "Asus" depends on LEDS_CLASS + depends on ACPI_WMI ---help--- Support for Asus notebook built-in keyboard and touchpad via i2c, and the Asus Republic of Gamers laptop keyboard special keys. diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 1bb7b63b3150..e6830946b4a4 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -26,6 +26,7 @@ * any later version. */ +#include #include #include #include @@ -78,6 +79,12 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define TRKID_SGN ((TRKID_MAX + 1) >> 1) +#define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" +#define ASUS_WMI_METHODID_DSTS2 0x53545344 /* Device STatuS #2*/ +#define ASUS_WMI_DEVID_KBD_BACKLIGHT 0x00050021 +#define ASUS_WMI_UNSUPPORTED_METHOD 0xFFFFFFFE +#define ASUS_WMI_DSTS_PRESENCE_BIT 0x00010000 + struct asus_kbd_leds { struct led_classdev cdev; struct hid_device *hdev; @@ -330,6 +337,48 @@ static void asus_kbd_backlight_work(struct work_struct *work) hid_err(led->hdev, "Asus failed to set keyboard backlight: %d\n", ret); } +/* WMI-based keyboard backlight LED control (via asus-wmi driver) takes + * precedence. We only activate HID-based backlight control when the + * WMI control is not available. + */ +static bool asus_kbd_wmi_led_control_present(struct hid_device *hdev) +{ + u32 args[] = { ASUS_WMI_DEVID_KBD_BACKLIGHT, 0 }; + struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + acpi_status status; + union acpi_object *obj; + u32 value; + + status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, + ASUS_WMI_METHODID_DSTS2, + &input, &output); + + if (ACPI_FAILURE(status)) { + hid_dbg(hdev, "WMI backlight method failed: %d", status); + return false; + } + + obj = (union acpi_object *)output.pointer; + if (!obj || obj->type != ACPI_TYPE_INTEGER) { + hid_dbg(hdev, "WMI backlight method unexpected return type"); + kfree(obj); + return false; + } + + value = (u32) obj->integer.value; + kfree(obj); + + hid_dbg(hdev, "WMI backlight check: method returned %x", value); + + if (value == ASUS_WMI_UNSUPPORTED_METHOD) { + hid_dbg(hdev, "WMI backlight method unsupported"); + return false; + } + + return !!(value & ASUS_WMI_DSTS_PRESENCE_BIT); +} + static int asus_kbd_register_leds(struct hid_device *hdev) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); @@ -417,7 +466,9 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) drvdata->input = input; - if (drvdata->enable_backlight && asus_kbd_register_leds(hdev)) + if (drvdata->enable_backlight && + !asus_kbd_wmi_led_control_present(hdev) && + asus_kbd_register_leds(hdev)) hid_warn(hdev, "Failed to initialize backlight.\n"); return 0;