Skip to content

Commit bc5fbae

Browse files
author
Jiri Kosina
committed
Merge branch 'for-6.10/asus' into for-linus
- initial support for ROG Ally and ROG X13 devices (Luke D. Jones) - other small assorted cleanups of hid-asus driver (Luke D. Jones)
2 parents 6d6d81a + e901f10 commit bc5fbae

File tree

2 files changed

+54
-80
lines changed

2 files changed

+54
-80
lines changed

drivers/hid/hid-asus.c

Lines changed: 52 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -335,36 +335,20 @@ static int asus_raw_event(struct hid_device *hdev,
335335
if (drvdata->quirks & QUIRK_MEDION_E1239T)
336336
return asus_e1239t_event(drvdata, data, size);
337337

338-
if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) {
338+
/*
339+
* Skip these report ID, the device emits a continuous stream associated
340+
* with the AURA mode it is in which looks like an 'echo'.
341+
*/
342+
if (report->id == FEATURE_KBD_LED_REPORT_ID1 || report->id == FEATURE_KBD_LED_REPORT_ID2)
343+
return -1;
344+
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
339345
/*
340-
* Skip these report ID, the device emits a continuous stream associated
341-
* with the AURA mode it is in which looks like an 'echo'.
346+
* G713 and G733 send these codes on some keypresses, depending on
347+
* the key pressed it can trigger a shutdown event if not caught.
342348
*/
343-
if (report->id == FEATURE_KBD_LED_REPORT_ID1 ||
344-
report->id == FEATURE_KBD_LED_REPORT_ID2) {
349+
if (data[0] == 0x02 && data[1] == 0x30) {
345350
return -1;
346-
/* Additional report filtering */
347-
} else if (report->id == FEATURE_KBD_REPORT_ID) {
348-
/*
349-
* G14 and G15 send these codes on some keypresses with no
350-
* discernable reason for doing so. We'll filter them out to avoid
351-
* unmapped warning messages later.
352-
*/
353-
if (data[1] == 0xea || data[1] == 0xec || data[1] == 0x02 ||
354-
data[1] == 0x8a || data[1] == 0x9e) {
355-
return -1;
356-
}
357351
}
358-
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
359-
/*
360-
* G713 and G733 send these codes on some keypresses, depending on
361-
* the key pressed it can trigger a shutdown event if not caught.
362-
*/
363-
if(data[0] == 0x02 && data[1] == 0x30) {
364-
return -1;
365-
}
366-
}
367-
368352
}
369353

370354
if (drvdata->quirks & QUIRK_ROG_CLAYMORE_II_KEYBOARD) {
@@ -402,9 +386,9 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu
402386
return ret;
403387
}
404388

405-
static int asus_kbd_init(struct hid_device *hdev)
389+
static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
406390
{
407-
const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
391+
const u8 buf[] = { report_id, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
408392
0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
409393
int ret;
410394

@@ -416,9 +400,10 @@ static int asus_kbd_init(struct hid_device *hdev)
416400
}
417401

418402
static int asus_kbd_get_functions(struct hid_device *hdev,
419-
unsigned char *kbd_func)
403+
unsigned char *kbd_func,
404+
u8 report_id)
420405
{
421-
const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 };
406+
const u8 buf[] = { report_id, 0x05, 0x20, 0x31, 0x00, 0x08 };
422407
u8 *readbuf;
423408
int ret;
424409

@@ -447,51 +432,6 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
447432
return ret;
448433
}
449434

450-
static int rog_nkey_led_init(struct hid_device *hdev)
451-
{
452-
const u8 buf_init_start[] = { FEATURE_KBD_LED_REPORT_ID1, 0xB9 };
453-
u8 buf_init2[] = { FEATURE_KBD_LED_REPORT_ID1, 0x41, 0x53, 0x55, 0x53, 0x20,
454-
0x54, 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
455-
u8 buf_init3[] = { FEATURE_KBD_LED_REPORT_ID1,
456-
0x05, 0x20, 0x31, 0x00, 0x08 };
457-
int ret;
458-
459-
hid_info(hdev, "Asus initialise N-KEY Device");
460-
/* The first message is an init start */
461-
ret = asus_kbd_set_report(hdev, buf_init_start, sizeof(buf_init_start));
462-
if (ret < 0) {
463-
hid_warn(hdev, "Asus failed to send init start command: %d\n", ret);
464-
return ret;
465-
}
466-
/* Followed by a string */
467-
ret = asus_kbd_set_report(hdev, buf_init2, sizeof(buf_init2));
468-
if (ret < 0) {
469-
hid_warn(hdev, "Asus failed to send init command 1.0: %d\n", ret);
470-
return ret;
471-
}
472-
/* Followed by a string */
473-
ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3));
474-
if (ret < 0) {
475-
hid_warn(hdev, "Asus failed to send init command 1.1: %d\n", ret);
476-
return ret;
477-
}
478-
479-
/* begin second report ID with same data */
480-
buf_init2[0] = FEATURE_KBD_LED_REPORT_ID2;
481-
buf_init3[0] = FEATURE_KBD_LED_REPORT_ID2;
482-
483-
ret = asus_kbd_set_report(hdev, buf_init2, sizeof(buf_init2));
484-
if (ret < 0) {
485-
hid_warn(hdev, "Asus failed to send init command 2.0: %d\n", ret);
486-
return ret;
487-
}
488-
ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3));
489-
if (ret < 0)
490-
hid_warn(hdev, "Asus failed to send init command 2.1: %d\n", ret);
491-
492-
return ret;
493-
}
494-
495435
static void asus_schedule_work(struct asus_kbd_leds *led)
496436
{
497437
unsigned long flags;
@@ -574,17 +514,27 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
574514
int ret;
575515

576516
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
577-
ret = rog_nkey_led_init(hdev);
517+
/* Initialize keyboard */
518+
ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
519+
if (ret < 0)
520+
return ret;
521+
522+
/* The LED endpoint is initialised in two HID */
523+
ret = asus_kbd_init(hdev, FEATURE_KBD_LED_REPORT_ID1);
524+
if (ret < 0)
525+
return ret;
526+
527+
ret = asus_kbd_init(hdev, FEATURE_KBD_LED_REPORT_ID2);
578528
if (ret < 0)
579529
return ret;
580530
} else {
581531
/* Initialize keyboard */
582-
ret = asus_kbd_init(hdev);
532+
ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
583533
if (ret < 0)
584534
return ret;
585535

586536
/* Get keyboard functions */
587-
ret = asus_kbd_get_functions(hdev, &kbd_func);
537+
ret = asus_kbd_get_functions(hdev, &kbd_func, FEATURE_KBD_REPORT_ID);
588538
if (ret < 0)
589539
return ret;
590540

@@ -897,7 +847,10 @@ static int asus_input_mapping(struct hid_device *hdev,
897847
case 0xb3: asus_map_key_clear(KEY_PROG3); break; /* Fn+Left next aura */
898848
case 0x6a: asus_map_key_clear(KEY_F13); break; /* Screenpad toggle */
899849
case 0x4b: asus_map_key_clear(KEY_F14); break; /* Arrows/Pg-Up/Dn toggle */
900-
850+
case 0xa5: asus_map_key_clear(KEY_F15); break; /* ROG Ally left back */
851+
case 0xa6: asus_map_key_clear(KEY_F16); break; /* ROG Ally QAM button */
852+
case 0xa7: asus_map_key_clear(KEY_F17); break; /* ROG Ally ROG long-press */
853+
case 0xa8: asus_map_key_clear(KEY_F18); break; /* ROG Ally ROG long-press-release */
901854

902855
default:
903856
/* ASUS lazily declares 256 usages, ignore the rest,
@@ -1250,6 +1203,19 @@ static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
12501203
rdesc[205] = 0x01;
12511204
}
12521205

1206+
/* match many more n-key devices */
1207+
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
1208+
for (int i = 0; i < *rsize + 1; i++) {
1209+
/* offset to the count from 0x5a report part always 14 */
1210+
if (rdesc[i] == 0x85 && rdesc[i + 1] == 0x5a &&
1211+
rdesc[i + 14] == 0x95 && rdesc[i + 15] == 0x05) {
1212+
hid_info(hdev, "Fixing up Asus N-Key report descriptor\n");
1213+
rdesc[i + 15] = 0x01;
1214+
break;
1215+
}
1216+
}
1217+
}
1218+
12531219
return rdesc;
12541220
}
12551221

@@ -1276,6 +1242,12 @@ static const struct hid_device_id asus_devices[] = {
12761242
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
12771243
USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD3),
12781244
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
1245+
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
1246+
USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR),
1247+
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
1248+
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
1249+
USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY),
1250+
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
12791251
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
12801252
USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD),
12811253
QUIRK_ROG_CLAYMORE_II_KEYBOARD },
@@ -1319,4 +1291,4 @@ static struct hid_driver asus_driver = {
13191291
};
13201292
module_hid_driver(asus_driver);
13211293

1322-
MODULE_LICENSE("GPL");
1294+
MODULE_LICENSE("GPL");

drivers/hid/hid-ids.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD 0x1866
209209
#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2 0x19b6
210210
#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD3 0x1a30
211+
#define USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR 0x18c6
212+
#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY 0x1abe
211213
#define USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD 0x196b
212214
#define USB_DEVICE_ID_ASUSTEK_FX503VD_KEYBOARD 0x1869
213215

0 commit comments

Comments
 (0)