2 * HID driver for some cypress "special" devices
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2008 Jiri Slaby
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <linux/device.h>
19 #include <linux/hid.h>
20 #include <linux/input.h>
21 #include <linux/module.h>
25 #define CP_RDESC_SWAPPED_MIN_MAX 0x01
26 #define CP_2WHEEL_MOUSE_HACK 0x02
27 #define CP_2WHEEL_MOUSE_HACK_ON 0x04
29 #define VA_INVAL_LOGICAL_BOUNDARY 0x08
32 * Some USB barcode readers from cypress have usage min and usage max in
35 static __u8 *cp_rdesc_fixup(struct hid_device *hdev, __u8 *rdesc,
43 for (i = 0; i < *rsize - 4; i++)
44 if (rdesc[i] == 0x29 && rdesc[i + 2] == 0x19) {
47 swap(rdesc[i + 3], rdesc[i + 1]);
52 static __u8 *va_logical_boundary_fixup(struct hid_device *hdev, __u8 *rdesc,
56 * Varmilo VA104M (with VID Cypress and device ID 07B1) incorrectly
57 * reports Logical Minimum of its Consumer Control device as 572
58 * (0x02 0x3c). Fix this by setting its Logical Minimum to zero.
61 rdesc[0] == 0x05 && rdesc[1] == 0x0c &&
62 rdesc[2] == 0x09 && rdesc[3] == 0x01 &&
63 rdesc[6] == 0x19 && rdesc[7] == 0x00 &&
64 rdesc[11] == 0x16 && rdesc[12] == 0x3c && rdesc[13] == 0x02) {
66 "fixing up varmilo VA104M consumer control report descriptor\n");
73 static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
76 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
78 if (quirks & CP_RDESC_SWAPPED_MIN_MAX)
79 rdesc = cp_rdesc_fixup(hdev, rdesc, rsize);
80 if (quirks & VA_INVAL_LOGICAL_BOUNDARY)
81 rdesc = va_logical_boundary_fixup(hdev, rdesc, rsize);
86 static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
87 struct hid_field *field, struct hid_usage *usage,
88 unsigned long **bit, int *max)
90 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
92 if (!(quirks & CP_2WHEEL_MOUSE_HACK))
95 if (usage->type == EV_REL && usage->code == REL_WHEEL)
96 set_bit(REL_HWHEEL, *bit);
97 if (usage->hid == 0x00090005)
103 static int cp_event(struct hid_device *hdev, struct hid_field *field,
104 struct hid_usage *usage, __s32 value)
106 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
108 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
109 !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK))
112 if (usage->hid == 0x00090005) {
114 quirks |= CP_2WHEEL_MOUSE_HACK_ON;
116 quirks &= ~CP_2WHEEL_MOUSE_HACK_ON;
117 hid_set_drvdata(hdev, (void *)quirks);
121 if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) {
122 struct input_dev *input = field->hidinput->input;
124 input_event(input, usage->type, REL_HWHEEL, value);
131 static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
133 unsigned long quirks = id->driver_data;
136 hid_set_drvdata(hdev, (void *)quirks);
138 ret = hid_parse(hdev);
140 hid_err(hdev, "parse failed\n");
144 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
146 hid_err(hdev, "hw start failed\n");
155 static const struct hid_device_id cp_devices[] = {
156 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1),
157 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
158 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2),
159 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
160 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3),
161 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
162 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4),
163 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
164 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE),
165 .driver_data = CP_2WHEEL_MOUSE_HACK },
166 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_VARMILO_VA104M_07B1),
167 .driver_data = VA_INVAL_LOGICAL_BOUNDARY },
170 MODULE_DEVICE_TABLE(hid, cp_devices);
172 static struct hid_driver cp_driver = {
174 .id_table = cp_devices,
175 .report_fixup = cp_report_fixup,
176 .input_mapped = cp_input_mapped,
180 module_hid_driver(cp_driver);
182 MODULE_LICENSE("GPL");