2727#include <linux/hid.h>
2828#include <linux/module.h>
2929#include <linux/platform_data/x86/asus-wmi.h>
30- #include <linux/platform_data/x86/asus-wmi-leds-ids.h>
3130#include <linux/input/mt.h>
3231#include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */
3332#include <linux/power_supply.h>
@@ -103,7 +102,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
103102#define TRKID_SGN ((TRKID_MAX + 1) >> 1)
104103
105104struct asus_kbd_leds {
106- struct led_classdev cdev ;
105+ struct asus_hid_listener listener ;
107106 struct hid_device * hdev ;
108107 struct work_struct work ;
109108 unsigned int brightness ;
@@ -495,11 +494,11 @@ static void asus_schedule_work(struct asus_kbd_leds *led)
495494 spin_unlock_irqrestore (& led -> lock , flags );
496495}
497496
498- static void asus_kbd_backlight_set (struct led_classdev * led_cdev ,
499- enum led_brightness brightness )
497+ static void asus_kbd_backlight_set (struct asus_hid_listener * listener ,
498+ int brightness )
500499{
501- struct asus_kbd_leds * led = container_of (led_cdev , struct asus_kbd_leds ,
502- cdev );
500+ struct asus_kbd_leds * led = container_of (listener , struct asus_kbd_leds ,
501+ listener );
503502 unsigned long flags ;
504503
505504 spin_lock_irqsave (& led -> lock , flags );
@@ -509,20 +508,6 @@ static void asus_kbd_backlight_set(struct led_classdev *led_cdev,
509508 asus_schedule_work (led );
510509}
511510
512- static enum led_brightness asus_kbd_backlight_get (struct led_classdev * led_cdev )
513- {
514- struct asus_kbd_leds * led = container_of (led_cdev , struct asus_kbd_leds ,
515- cdev );
516- enum led_brightness brightness ;
517- unsigned long flags ;
518-
519- spin_lock_irqsave (& led -> lock , flags );
520- brightness = led -> brightness ;
521- spin_unlock_irqrestore (& led -> lock , flags );
522-
523- return brightness ;
524- }
525-
526511static void asus_kbd_backlight_work (struct work_struct * work )
527512{
528513 struct asus_kbd_leds * led = container_of (work , struct asus_kbd_leds , work );
@@ -539,34 +524,6 @@ static void asus_kbd_backlight_work(struct work_struct *work)
539524 hid_err (led -> hdev , "Asus failed to set keyboard backlight: %d\n" , ret );
540525}
541526
542- /* WMI-based keyboard backlight LED control (via asus-wmi driver) takes
543- * precedence. We only activate HID-based backlight control when the
544- * WMI control is not available.
545- */
546- static bool asus_kbd_wmi_led_control_present (struct hid_device * hdev )
547- {
548- struct asus_drvdata * drvdata = hid_get_drvdata (hdev );
549- u32 value ;
550- int ret ;
551-
552- if (!IS_ENABLED (CONFIG_ASUS_WMI ))
553- return false;
554-
555- if (drvdata -> quirks & QUIRK_ROG_NKEY_KEYBOARD &&
556- dmi_check_system (asus_use_hid_led_dmi_ids )) {
557- hid_info (hdev , "using HID for asus::kbd_backlight\n" );
558- return false;
559- }
560-
561- ret = asus_wmi_evaluate_method (ASUS_WMI_METHODID_DSTS ,
562- ASUS_WMI_DEVID_KBD_BACKLIGHT , 0 , & value );
563- hid_dbg (hdev , "WMI backlight check: rc %d value %x" , ret , value );
564- if (ret )
565- return false;
566-
567- return !!(value & ASUS_WMI_DSTS_PRESENCE_BIT );
568- }
569-
570527/*
571528 * We don't care about any other part of the string except the version section.
572529 * Example strings: FGA80100.RC72LA.312_T01, FGA80100.RC71LS.318_T01
@@ -706,14 +663,11 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
706663 drvdata -> kbd_backlight -> removed = false;
707664 drvdata -> kbd_backlight -> brightness = 0 ;
708665 drvdata -> kbd_backlight -> hdev = hdev ;
709- drvdata -> kbd_backlight -> cdev .name = "asus::kbd_backlight" ;
710- drvdata -> kbd_backlight -> cdev .max_brightness = 3 ;
711- drvdata -> kbd_backlight -> cdev .brightness_set = asus_kbd_backlight_set ;
712- drvdata -> kbd_backlight -> cdev .brightness_get = asus_kbd_backlight_get ;
666+ drvdata -> kbd_backlight -> listener .brightness_set = asus_kbd_backlight_set ;
713667 INIT_WORK (& drvdata -> kbd_backlight -> work , asus_kbd_backlight_work );
714668 spin_lock_init (& drvdata -> kbd_backlight -> lock );
715669
716- ret = devm_led_classdev_register ( & hdev -> dev , & drvdata -> kbd_backlight -> cdev );
670+ ret = asus_hid_register_listener ( & drvdata -> kbd_backlight -> listener );
717671 if (ret < 0 ) {
718672 /* No need to have this still around */
719673 devm_kfree (& hdev -> dev , drvdata -> kbd_backlight );
@@ -1102,7 +1056,7 @@ static int __maybe_unused asus_resume(struct hid_device *hdev) {
11021056
11031057 if (drvdata -> kbd_backlight ) {
11041058 const u8 buf [] = { FEATURE_KBD_REPORT_ID , 0xba , 0xc5 , 0xc4 ,
1105- drvdata -> kbd_backlight -> cdev . brightness };
1059+ drvdata -> kbd_backlight -> brightness };
11061060 ret = asus_kbd_set_report (hdev , buf , sizeof (buf ));
11071061 if (ret < 0 ) {
11081062 hid_err (hdev , "Asus failed to set keyboard backlight: %d\n" , ret );
@@ -1228,7 +1182,6 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
12281182 }
12291183
12301184 if (is_vendor && (drvdata -> quirks & QUIRK_USE_KBD_BACKLIGHT ) &&
1231- !asus_kbd_wmi_led_control_present (hdev ) &&
12321185 asus_kbd_register_leds (hdev ))
12331186 hid_warn (hdev , "Failed to initialize backlight.\n" );
12341187
@@ -1275,6 +1228,8 @@ static void asus_remove(struct hid_device *hdev)
12751228 unsigned long flags ;
12761229
12771230 if (drvdata -> kbd_backlight ) {
1231+ asus_hid_unregister_listener (& drvdata -> kbd_backlight -> listener );
1232+
12781233 spin_lock_irqsave (& drvdata -> kbd_backlight -> lock , flags );
12791234 drvdata -> kbd_backlight -> removed = true;
12801235 spin_unlock_irqrestore (& drvdata -> kbd_backlight -> lock , flags );
0 commit comments