HID: asus: Add support for Fn keys on Asus ROG G752
[muen/linux.git] / drivers / hid / hid-asus.c
index 50c294be8324ab803450c00165717962e1603d13..27651f50738eae08d1d091e2a1a06d8a65ee70ac 100644 (file)
@@ -67,6 +67,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define QUIRK_USE_KBD_BACKLIGHT                BIT(5)
 #define QUIRK_T100_KEYBOARD            BIT(6)
 #define QUIRK_T100CHI                  BIT(7)
+#define QUIRK_G752_KEYBOARD            BIT(8)
 
 #define I2C_KEYBOARD_QUIRKS                    (QUIRK_FIX_NOTEBOOK_REPORT | \
                                                 QUIRK_NO_INIT_REPORTS | \
@@ -670,6 +671,11 @@ static void asus_remove(struct hid_device *hdev)
        hid_hw_stop(hdev);
 }
 
+static const __u8 asus_g752_fixed_rdesc[] = {
+        0x19, 0x00,                    /*   Usage Minimum (0x00)       */
+        0x2A, 0xFF, 0x00,              /*   Usage Maximum (0xFF)       */
+};
+
 static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
                unsigned int *rsize)
 {
@@ -708,6 +714,27 @@ static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
                rdesc[391] = 0xff;
                rdesc[402] = 0x00;
        }
+       if (drvdata->quirks & QUIRK_G752_KEYBOARD &&
+                *rsize == 75 && rdesc[61] == 0x15 && rdesc[62] == 0x00) {
+               /* report is missing usage mninum and maximum */
+               __u8 *new_rdesc;
+               size_t new_size = *rsize + sizeof(asus_g752_fixed_rdesc);
+
+               new_rdesc = devm_kzalloc(&hdev->dev, new_size, GFP_KERNEL);
+               if (new_rdesc == NULL)
+                       return rdesc;
+
+               hid_info(hdev, "Fixing up Asus G752 keyb report descriptor\n");
+               /* copy the valid part */
+               memcpy(new_rdesc, rdesc, 61);
+               /* insert missing part */
+               memcpy(new_rdesc + 61, asus_g752_fixed_rdesc, sizeof(asus_g752_fixed_rdesc));
+               /* copy remaining data */
+               memcpy(new_rdesc + 61 + sizeof(asus_g752_fixed_rdesc), rdesc + 61, *rsize - 61);
+
+               *rsize = new_size;
+               rdesc = new_rdesc;
+       }
 
        return rdesc;
 }
@@ -721,6 +748,8 @@ static const struct hid_device_id asus_devices[] = {
                USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
                USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2), QUIRK_USE_KBD_BACKLIGHT },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
+               USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD3), QUIRK_G752_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
                USB_DEVICE_ID_ASUSTEK_T100_KEYBOARD),
          QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES },