18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * HID driver for Redragon keyboards 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2017 Robert Munteanu 58c2ecf20Sopenharmony_ci * SPDX-License-Identifier: GPL-2.0+ 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 108c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License as published by the Free 118c2ecf20Sopenharmony_ci * Software Foundation; either version 2 of the License, or (at your option) 128c2ecf20Sopenharmony_ci * any later version. 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/device.h> 168c2ecf20Sopenharmony_ci#include <linux/hid.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include "hid-ids.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * The Redragon Asura keyboard sends an incorrect HID descriptor. 248c2ecf20Sopenharmony_ci * At byte 100 it contains 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * 0x81, 0x00 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * which is Input (Data, Arr, Abs), but it should be 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * 0x81, 0x02 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * which is Input (Data, Var, Abs), which is consistent with the way 338c2ecf20Sopenharmony_ci * key codes are generated. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc, 378c2ecf20Sopenharmony_ci unsigned int *rsize) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) { 408c2ecf20Sopenharmony_ci dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n"); 418c2ecf20Sopenharmony_ci rdesc[101] = 0x02; 428c2ecf20Sopenharmony_ci } 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci return rdesc; 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic const struct hid_device_id redragon_devices[] = { 488c2ecf20Sopenharmony_ci {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)}, 498c2ecf20Sopenharmony_ci {} 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, redragon_devices); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic struct hid_driver redragon_driver = { 558c2ecf20Sopenharmony_ci .name = "redragon", 568c2ecf20Sopenharmony_ci .id_table = redragon_devices, 578c2ecf20Sopenharmony_ci .report_fixup = redragon_report_fixup 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cimodule_hid_driver(redragon_driver); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 63