Skip to content

Commit 2c82a7b

Browse files
flukejonesJiri Kosina
authored andcommitted
HID: asus: make asus_kbd_init() generic, remove rog_nkey_led_init()
Some of the n-key stuff is old and outdated, so make asus_kbd_init() generic to use with other report ID and remove rog_nkey_led_init(). Signed-off-by: Luke D. Jones <luke@ljones.dev> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 59d2f5b commit 2c82a7b

1 file changed

Lines changed: 18 additions & 52 deletions

File tree

drivers/hid/hid-asus.c

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu
386386
return ret;
387387
}
388388

389-
static int asus_kbd_init(struct hid_device *hdev)
389+
static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
390390
{
391-
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,
392392
0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
393393
int ret;
394394

@@ -400,9 +400,10 @@ static int asus_kbd_init(struct hid_device *hdev)
400400
}
401401

402402
static int asus_kbd_get_functions(struct hid_device *hdev,
403-
unsigned char *kbd_func)
403+
unsigned char *kbd_func,
404+
u8 report_id)
404405
{
405-
const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 };
406+
const u8 buf[] = { report_id, 0x05, 0x20, 0x31, 0x00, 0x08 };
406407
u8 *readbuf;
407408
int ret;
408409

@@ -431,51 +432,6 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
431432
return ret;
432433
}
433434

434-
static int rog_nkey_led_init(struct hid_device *hdev)
435-
{
436-
const u8 buf_init_start[] = { FEATURE_KBD_LED_REPORT_ID1, 0xB9 };
437-
u8 buf_init2[] = { FEATURE_KBD_LED_REPORT_ID1, 0x41, 0x53, 0x55, 0x53, 0x20,
438-
0x54, 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
439-
u8 buf_init3[] = { FEATURE_KBD_LED_REPORT_ID1,
440-
0x05, 0x20, 0x31, 0x00, 0x08 };
441-
int ret;
442-
443-
hid_info(hdev, "Asus initialise N-KEY Device");
444-
/* The first message is an init start */
445-
ret = asus_kbd_set_report(hdev, buf_init_start, sizeof(buf_init_start));
446-
if (ret < 0) {
447-
hid_warn(hdev, "Asus failed to send init start command: %d\n", ret);
448-
return ret;
449-
}
450-
/* Followed by a string */
451-
ret = asus_kbd_set_report(hdev, buf_init2, sizeof(buf_init2));
452-
if (ret < 0) {
453-
hid_warn(hdev, "Asus failed to send init command 1.0: %d\n", ret);
454-
return ret;
455-
}
456-
/* Followed by a string */
457-
ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3));
458-
if (ret < 0) {
459-
hid_warn(hdev, "Asus failed to send init command 1.1: %d\n", ret);
460-
return ret;
461-
}
462-
463-
/* begin second report ID with same data */
464-
buf_init2[0] = FEATURE_KBD_LED_REPORT_ID2;
465-
buf_init3[0] = FEATURE_KBD_LED_REPORT_ID2;
466-
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 2.0: %d\n", ret);
470-
return ret;
471-
}
472-
ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3));
473-
if (ret < 0)
474-
hid_warn(hdev, "Asus failed to send init command 2.1: %d\n", ret);
475-
476-
return ret;
477-
}
478-
479435
static void asus_schedule_work(struct asus_kbd_leds *led)
480436
{
481437
unsigned long flags;
@@ -558,17 +514,27 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
558514
int ret;
559515

560516
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
561-
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);
562528
if (ret < 0)
563529
return ret;
564530
} else {
565531
/* Initialize keyboard */
566-
ret = asus_kbd_init(hdev);
532+
ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
567533
if (ret < 0)
568534
return ret;
569535

570536
/* Get keyboard functions */
571-
ret = asus_kbd_get_functions(hdev, &kbd_func);
537+
ret = asus_kbd_get_functions(hdev, &kbd_func, FEATURE_KBD_REPORT_ID);
572538
if (ret < 0)
573539
return ret;
574540

0 commit comments

Comments
 (0)