diff mbox series

[v3,2/2] HID: asus: only support backlight when it's not driven by WMI

Message ID 20181009064056.17478-2-drake@endlessm.com (mailing list archive)
State Accepted, archived
Delegated to: Andy Shevchenko
Headers show
Series [v3,1/2] platform/x86: asus-wmi: export function for evaluating WMI methods | expand

Commit Message

Daniel Drake Oct. 9, 2018, 6:40 a.m. UTC
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).

A direct "depends on ASUS_WMI" is intentionally avoided so that HID_ASUS
users who have ASUS_WMI=n will not quietly lose their HID_ASUS driver on
a kernel upgrade.

Signed-off-by: Daniel Drake <drake@endlessm.com>
---

Notes:
    v2: use asus-wmi driver to check WMI device status
    
    v3: avoid "depends on ASUS_WMI"

 drivers/hid/Kconfig    |  1 +
 drivers/hid/hid-asus.c | 24 +++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

Comments

Benjamin Tissoires Oct. 9, 2018, 8:16 a.m. UTC | #1
On Tue, Oct 9, 2018 at 8:41 AM Daniel Drake <drake@endlessm.com> wrote:
>
> 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).
>
> A direct "depends on ASUS_WMI" is intentionally avoided so that HID_ASUS
> users who have ASUS_WMI=n will not quietly lose their HID_ASUS driver on
> a kernel upgrade.
>
> Signed-off-by: Daniel Drake <drake@endlessm.com>
> ---

For the HID part:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

>
> Notes:
>     v2: use asus-wmi driver to check WMI device status
>
>     v3: avoid "depends on ASUS_WMI"
>
>  drivers/hid/Kconfig    |  1 +
>  drivers/hid/hid-asus.c | 24 +++++++++++++++++++++++-
>  2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> index 61e1953ff921..4287dfe2e58e 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 m || ASUS_WMI != m
>         ---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 88a5672f42cd..c42af8511b38 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
> @@ -26,6 +26,7 @@
>   * any later version.
>   */
>
> +#include <linux/asus-wmi.h>
>  #include <linux/dmi.h>
>  #include <linux/hid.h>
>  #include <linux/module.h>
> @@ -349,6 +350,25 @@ 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 value;
> +       int ret;
> +
> +       ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS2,
> +                                      ASUS_WMI_DEVID_KBD_BACKLIGHT, 0, &value);
> +       hid_dbg(hdev, "WMI backlight check: rc %d value %x", ret, value);
> +
> +       if (ret != 0)
> +               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);
> @@ -436,7 +456,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;
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 61e1953ff921..4287dfe2e58e 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 m || ASUS_WMI != m
 	---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 88a5672f42cd..c42af8511b38 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -26,6 +26,7 @@ 
  * any later version.
  */
 
+#include <linux/asus-wmi.h>
 #include <linux/dmi.h>
 #include <linux/hid.h>
 #include <linux/module.h>
@@ -349,6 +350,25 @@  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 value;
+	int ret;
+
+	ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS2,
+				       ASUS_WMI_DEVID_KBD_BACKLIGHT, 0, &value);
+	hid_dbg(hdev, "WMI backlight check: rc %d value %x", ret, value);
+
+	if (ret != 0)
+		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);
@@ -436,7 +456,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;