drivers/hid/hid-redragon.c

Source file repositories/reference/linux-study-clean/drivers/hid/hid-redragon.c

File Facts

System
Linux kernel
Corpus path
drivers/hid/hid-redragon.c
Extension
.c
Size
1498 bytes
Lines
64
Domain
Driver Families
Bucket
drivers/hid
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>

#include "hid-ids.h"


/*
 * The Redragon Asura keyboard sends an incorrect HID descriptor.
 * At byte 100 it contains
 *
 *   0x81, 0x00
 *
 * which is Input (Data, Arr, Abs), but it should be
 *
 *   0x81, 0x02
 *
 * which is Input (Data, Var, Abs), which is consistent with the way
 * key codes are generated.
 */

static const __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
	unsigned int *rsize)
{
	if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
		dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
		rdesc[101] = 0x02;
	}

	return rdesc;
}

static const struct hid_device_id redragon_devices[] = {
	{HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
	{}
};

MODULE_DEVICE_TABLE(hid, redragon_devices);

static struct hid_driver redragon_driver = {
	.name = "redragon",
	.id_table = redragon_devices,
	.report_fixup = redragon_report_fixup
};

module_hid_driver(redragon_driver);

MODULE_DESCRIPTION("HID driver for Redragon keyboards");
MODULE_LICENSE("GPL");

Annotation

Implementation Notes