Instead of calling asus_map_key_clear() function in each case, we now set a temporary value and clear it after default. Patch was checked by checkpatch and adjusted accordingly. Signed-off-by: Johan Boger <jb@xxxxx> --- drivers/hid/hid-asus.c | 144 ++++++++++++++++++++++++++--------------- 1 file changed, 93 insertions(+), 51 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 08c9a9a60ae4..9c2080cd1de3 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -339,7 +339,7 @@ static int asus_raw_event(struct hid_device *hdev, /* * Skip these report ID, the device emits a continuous stream associated * with the AURA mode it is in which looks like an 'echo'. - */ + */ if (report->id == FEATURE_KBD_LED_REPORT_ID1 || report->id == FEATURE_KBD_LED_REPORT_ID2) { return -1; @@ -349,7 +349,7 @@ static int asus_raw_event(struct hid_device *hdev, * G14 and G15 send these codes on some keypresses with no * discernable reason for doing so. We'll filter them out to avoid * unmapped warning messages later. - */ + */ if (data[1] == 0xea || data[1] == 0xec || data[1] == 0x02 || data[1] == 0x8a || data[1] == 0x9e) { return -1; @@ -359,10 +359,9 @@ static int asus_raw_event(struct hid_device *hdev, /* * G713 and G733 send these codes on some keypresses, depending on * the key pressed it can trigger a shutdown event if not caught. - */ - if(data[0] == 0x02 && data[1] == 0x30) { + */ + if (data[0] == 0x02 && data[1] == 0x30) return -1; - } } } @@ -371,11 +370,10 @@ static int asus_raw_event(struct hid_device *hdev, /* * CLAYMORE II keyboard sends this packet when it goes to sleep * this causes the whole system to go into suspend. - */ + */ - if(size == 2 && data[0] == 0x02 && data[1] == 0x00) { + if (size == 2 && data[0] == 0x02 && data[1] == 0x00) return -1; - } } return 0; @@ -393,7 +391,7 @@ static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size /* * The report ID should be set from the incoming buffer due to LED and key * interfaces having different pages - */ + */ ret = hid_hw_raw_request(hdev, buf[0], dmabuf, buf_size, HID_FEATURE_REPORT, HID_REQ_SET_REPORT); @@ -828,6 +826,7 @@ static int asus_input_mapping(struct hid_device *hdev, int *max) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); + int clear_key; if (drvdata->quirks & QUIRK_SKIP_INPUT_MAPPING) { /* Don't map anything from the HID report. @@ -852,50 +851,73 @@ static int asus_input_mapping(struct hid_device *hdev, /* ASUS-specific keyboard hotkeys and led backlight */ if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR) { switch (usage->hid & HID_USAGE) { - case 0x10: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; - case 0x20: asus_map_key_clear(KEY_BRIGHTNESSUP); break; - case 0x35: asus_map_key_clear(KEY_DISPLAY_OFF); break; - case 0x6c: asus_map_key_clear(KEY_SLEEP); break; - case 0x7c: asus_map_key_clear(KEY_MICMUTE); break; - case 0x82: asus_map_key_clear(KEY_CAMERA); break; - case 0x88: asus_map_key_clear(KEY_RFKILL); break; - case 0xb5: asus_map_key_clear(KEY_CALC); break; - case 0xc4: asus_map_key_clear(KEY_KBDILLUMUP); break; - case 0xc5: asus_map_key_clear(KEY_KBDILLUMDOWN); break; + case 0x10: + clear_key = KEY_BRIGHTNESSDOWN; break; + case 0x20: + clear_key = KEY_BRIGHTNESSUP; break; + case 0x35: + clear_key = KEY_DISPLAY_OFF; break; + case 0x6c: + clear_key = KEY_SLEEP; break; + case 0x7c: + clear_key = KEY_MICMUTE; break; + case 0x82: + clear_key = KEY_CAMERA; break; + case 0x88: + clear_key = KEY_RFKILL; break; + case 0xb5: + clear_key = KEY_CALC; break; + case 0xc4: + clear_key = KEY_KBDILLUMUP; break; + case 0xc5: + clear_key = KEY_KBDILLUMDOWN; break; /* ASUS touchpad toggle */ - case 0x6b: asus_map_key_clear(KEY_F21); break; + case 0x6b: + clear_key = KEY_F21; break; /* ROG key */ - case 0x38: asus_map_key_clear(KEY_PROG1); break; + case 0x38: + clear_key = KEY_PROG1; break; /* Fn+C ASUS Splendid */ - case 0xba: asus_map_key_clear(KEY_PROG2); break; + case 0xba: + clear_key = KEY_PROG2; break; /* Fn+Space Power4Gear Hybrid */ - case 0x5c: asus_map_key_clear(KEY_PROG3); break; + case 0x5c: + clear_key = KEY_PROG3; break; /* Fn+F5 "fan" symbol on FX503VD */ - case 0x99: asus_map_key_clear(KEY_PROG4); break; + case 0x99: + clear_key = KEY_PROG4; break; /* Fn+F5 "fan" symbol on N-Key keyboard */ - case 0xae: asus_map_key_clear(KEY_PROG4); break; + case 0xae: + clear_key = KEY_PROG4; break; /* Fn+Ret "Calc" symbol on N-Key keyboard */ - case 0x92: asus_map_key_clear(KEY_CALC); break; + case 0x92: + clear_key = KEY_CALC; break; /* Fn+Left Aura mode previous on N-Key keyboard */ - case 0xb2: asus_map_key_clear(KEY_PROG2); break; + case 0xb2: + clear_key = KEY_PROG2; break; /* Fn+Right Aura mode next on N-Key keyboard */ - case 0xb3: asus_map_key_clear(KEY_PROG3); break; + case 0xb3: + clear_key = KEY_PROG3; break; default: /* ASUS lazily declares 256 usages, ignore the rest, - * as some make the keyboard appear as a pointer device. */ + * as some make the keyboard appear as a pointer device. + */ return -1; } + /* Clear temp key */ + asus_map_key_clear(clear_key); + /* * Check and enable backlight only on devices with UsagePage == * 0xff31 to avoid initializing the keyboard firmware multiple @@ -907,31 +929,52 @@ static int asus_input_mapping(struct hid_device *hdev, set_bit(EV_REP, hi->input->evbit); return 1; + } if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { switch (usage->hid & HID_USAGE) { - case 0xff01: asus_map_key_clear(BTN_1); break; - case 0xff02: asus_map_key_clear(BTN_2); break; - case 0xff03: asus_map_key_clear(BTN_3); break; - case 0xff04: asus_map_key_clear(BTN_4); break; - case 0xff05: asus_map_key_clear(BTN_5); break; - case 0xff06: asus_map_key_clear(BTN_6); break; - case 0xff07: asus_map_key_clear(BTN_7); break; - case 0xff08: asus_map_key_clear(BTN_8); break; - case 0xff09: asus_map_key_clear(BTN_9); break; - case 0xff0a: asus_map_key_clear(BTN_A); break; - case 0xff0b: asus_map_key_clear(BTN_B); break; - case 0x00f1: asus_map_key_clear(KEY_WLAN); break; - case 0x00f2: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; - case 0x00f3: asus_map_key_clear(KEY_BRIGHTNESSUP); break; - case 0x00f4: asus_map_key_clear(KEY_DISPLAY_OFF); break; - case 0x00f7: asus_map_key_clear(KEY_CAMERA); break; - case 0x00f8: asus_map_key_clear(KEY_PROG1); break; + case 0xff01: + clear_key = BTN_1; break; + case 0xff02: + clear_key = BTN_2; break; + case 0xff03: + clear_key = BTN_3; break; + case 0xff04: + clear_key = BTN_4; break; + case 0xff05: + clear_key = BTN_5; break; + case 0xff06: + clear_key = BTN_6; break; + case 0xff07: + clear_key = BTN_7; break; + case 0xff08: + clear_key = BTN_8; break; + case 0xff09: + clear_key = BTN_9; break; + case 0xff0a: + clear_key = BTN_A; break; + case 0xff0b: + clear_key = BTN_B; break; + case 0x00f1: + clear_key = KEY_WLAN; break; + case 0x00f2: + clear_key = KEY_BRIGHTNESSDOWN; break; + case 0x00f3: + clear_key = KEY_BRIGHTNESSUP; break; + case 0x00f4: + clear_key = KEY_DISPLAY_OFF; break; + case 0x00f7: + clear_key = KEY_CAMERA; break; + case 0x00f8: + clear_key = KEY_PROG1; break; default: return 0; } + /* Clear temp key */ + asus_map_key_clear(clear_key); + set_bit(EV_REP, hi->input->evbit); return 1; } @@ -1100,11 +1143,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) goto err_stop_hw; } - if (drvdata->tp) { + if (drvdata->tp) drvdata->input->name = "Asus TouchPad"; - } else { + else drvdata->input->name = "Asus Keyboard"; - } if (drvdata->tp) { ret = asus_start_multitouch(hdev); @@ -1131,8 +1173,8 @@ static void asus_remove(struct hid_device *hdev) } static const __u8 asus_g752_fixed_rdesc[] = { - 0x19, 0x00, /* Usage Minimum (0x00) */ - 0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */ + 0x19, 0x00, /* Usage Minimum (0x00) */ + 0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */ }; static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, -- 2.30.2