drivers/hid/bpf/progs/Huion__Dial-2.bpf.c

Source file repositories/reference/linux-study-clean/drivers/hid/bpf/progs/Huion__Dial-2.bpf.c

File Facts

System
Linux kernel
Corpus path
drivers/hid/bpf/progs/Huion__Dial-2.bpf.c
Extension
.c
Size
23562 bytes
Lines
637
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

struct pad_report {
				__u8 report_id;
				__u8 btn_stylus;
				__u8 x;
				__u8 y;
				__u8 buttons;
				__u8 dial_1;
				__u8 dial_2;
			} __attribute__((packed)) *pad_report;
			__u8 dial_1 = 0, dial_2 = 0;

			/* Dial report */
			if (data[1] == 0xf1) {
				__u8 d = 0;

				if (data[5] == 2)
					d = 0xff;
				else
					d = data[5];

				if (data[3] == 1)
					dial_1 = d;
				else
					dial_2 = d;
			} else {
				/* data[4] are the buttons, mapped correctly */
				last_button_state = data[4];
				dial_1 = 0; // dial
				dial_2 = 0;
			}

			pad_report = (struct pad_report *)data;

			pad_report->report_id = PAD_REPORT_ID;
			pad_report->btn_stylus = 0;
			pad_report->x = 0;
			pad_report->y = 0;
			pad_report->buttons = last_button_state;
			pad_report->dial_1 = dial_1;
			pad_report->dial_2 = dial_2;

			return sizeof(struct pad_report);
		}

		/* Pen reports need nothing done */
	}

	return 0;
}

HID_BPF_OPS(inspiroy_dial2) = {
	.hid_device_event = (void *)dial_2_fix_events,
	.hid_rdesc_fixup = (void *)dial_2_fix_rdesc,
};

SEC("syscall")
int probe(struct hid_bpf_probe_args *ctx)
{
	switch (ctx->rdesc_size) {
	case PAD_REPORT_DESCRIPTOR_LENGTH:
	case PEN_REPORT_DESCRIPTOR_LENGTH:
	case VENDOR_REPORT_DESCRIPTOR_LENGTH:
		ctx->retval = 0;
		break;
	default:
		ctx->retval = -EINVAL;
	}

	return 0;
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes