drivers/hid/hid-waltop.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hid/hid-waltop.c
Extension
.c
Size
39671 bytes
Lines
747
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

if (*rsize == SLIM_TABLET_5_8_INCH_RDESC_ORIG_SIZE) {
			*rsize = sizeof(slim_tablet_5_8_inch_rdesc_fixed);
			return slim_tablet_5_8_inch_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH:
		if (*rsize == SLIM_TABLET_12_1_INCH_RDESC_ORIG_SIZE) {
			*rsize = sizeof(slim_tablet_12_1_inch_rdesc_fixed);
			return slim_tablet_12_1_inch_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_Q_PAD:
		if (*rsize == Q_PAD_RDESC_ORIG_SIZE) {
			*rsize = sizeof(q_pad_rdesc_fixed);
			return q_pad_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_PID_0038:
		if (*rsize == PID_0038_RDESC_ORIG_SIZE) {
			*rsize = sizeof(pid_0038_rdesc_fixed);
			return pid_0038_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH:
		if (*rsize == MEDIA_TABLET_10_6_INCH_RDESC_ORIG_SIZE) {
			*rsize = sizeof(media_tablet_10_6_inch_rdesc_fixed);
			return media_tablet_10_6_inch_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH:
		if (*rsize == MEDIA_TABLET_14_1_INCH_RDESC_ORIG_SIZE) {
			*rsize = sizeof(media_tablet_14_1_inch_rdesc_fixed);
			return media_tablet_14_1_inch_rdesc_fixed;
		}
		break;
	case USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET:
		if (*rsize == SIRIUS_BATTERY_FREE_TABLET_RDESC_ORIG_SIZE) {
			*rsize = sizeof(sirius_battery_free_tablet_rdesc_fixed);
			return sirius_battery_free_tablet_rdesc_fixed;
		}
		break;
	}
	return rdesc;
}

static int waltop_raw_event(struct hid_device *hdev, struct hid_report *report,
		     u8 *data, int size)
{
	/* If this is a pen input report */
	if (report->type == HID_INPUT_REPORT && report->id == 16 && size >= 8) {
		/*
		 * Ignore reported pressure when a barrel button is pressed,
		 * because it is rarely correct.
		 */

		/* If a barrel button is pressed */
		if ((data[1] & 0xF) > 1) {
			/* Report zero pressure */
			data[6] = 0;
			data[7] = 0;
		}
	}

	/* If this is a pen input report of Sirius Battery Free Tablet */
	if (hdev->product == USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET &&
	    report->type == HID_INPUT_REPORT &&
	    report->id == 16 &&
	    size == 10) {
		/*
		 * The tablet reports tilt as roughly sin(a)*21 (18 means 60
		 * degrees).
		 *
		 * This array stores angles as radians * 100, corresponding to
		 * reported values up to 60 degrees, as expected by userspace.
		 */
		static const s8 tilt_to_radians[] = {
			0, 5, 10, 14, 19, 24, 29, 34, 40, 45,
			50, 56, 62, 68, 74, 81, 88, 96, 105
		};

		s8 tilt_x = (s8)data[8];
		s8 tilt_y = (s8)data[9];
		s8 sign_x = tilt_x >= 0 ? 1 : -1;
		s8 sign_y = tilt_y >= 0 ? 1 : -1;

		tilt_x *= sign_x;
		tilt_y *= sign_y;

		/*
		 * Reverse the Y Tilt direction to match the HID standard and

Annotation

Implementation Notes