1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for some cypress "special" devices
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
8 * Copyright (c) 2006-2007 Jiri Kosina
9 * Copyright (c) 2008 Jiri Slaby
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/input.h>
18 #include <linux/module.h>
22 #define CP_RDESC_SWAPPED_MIN_MAX 0x01
23 #define CP_2WHEEL_MOUSE_HACK 0x02
24 #define CP_2WHEEL_MOUSE_HACK_ON 0x04
27 * Some USB barcode readers from cypress have usage min and usage max in
30 static __u8
*cp_report_fixup(struct hid_device
*hdev
, __u8
*rdesc
,
33 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
36 if (!(quirks
& CP_RDESC_SWAPPED_MIN_MAX
))
42 for (i
= 0; i
< *rsize
- 4; i
++)
43 if (rdesc
[i
] == 0x29 && rdesc
[i
+ 2] == 0x19) {
46 swap(rdesc
[i
+ 3], rdesc
[i
+ 1]);
51 static int cp_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
52 struct hid_field
*field
, struct hid_usage
*usage
,
53 unsigned long **bit
, int *max
)
55 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
57 if (!(quirks
& CP_2WHEEL_MOUSE_HACK
))
60 if (usage
->type
== EV_REL
&& usage
->code
== REL_WHEEL
)
61 set_bit(REL_HWHEEL
, *bit
);
62 if (usage
->hid
== 0x00090005)
68 static int cp_event(struct hid_device
*hdev
, struct hid_field
*field
,
69 struct hid_usage
*usage
, __s32 value
)
71 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
73 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
) || !field
->hidinput
||
74 !usage
->type
|| !(quirks
& CP_2WHEEL_MOUSE_HACK
))
77 if (usage
->hid
== 0x00090005) {
79 quirks
|= CP_2WHEEL_MOUSE_HACK_ON
;
81 quirks
&= ~CP_2WHEEL_MOUSE_HACK_ON
;
82 hid_set_drvdata(hdev
, (void *)quirks
);
86 if (usage
->code
== REL_WHEEL
&& (quirks
& CP_2WHEEL_MOUSE_HACK_ON
)) {
87 struct input_dev
*input
= field
->hidinput
->input
;
89 input_event(input
, usage
->type
, REL_HWHEEL
, value
);
96 static int cp_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
98 unsigned long quirks
= id
->driver_data
;
101 hid_set_drvdata(hdev
, (void *)quirks
);
103 ret
= hid_parse(hdev
);
105 hid_err(hdev
, "parse failed\n");
109 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
111 hid_err(hdev
, "hw start failed\n");
120 static const struct hid_device_id cp_devices
[] = {
121 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_1
),
122 .driver_data
= CP_RDESC_SWAPPED_MIN_MAX
},
123 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_2
),
124 .driver_data
= CP_RDESC_SWAPPED_MIN_MAX
},
125 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_3
),
126 .driver_data
= CP_RDESC_SWAPPED_MIN_MAX
},
127 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_4
),
128 .driver_data
= CP_RDESC_SWAPPED_MIN_MAX
},
129 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_MOUSE
),
130 .driver_data
= CP_2WHEEL_MOUSE_HACK
},
133 MODULE_DEVICE_TABLE(hid
, cp_devices
);
135 static struct hid_driver cp_driver
= {
137 .id_table
= cp_devices
,
138 .report_fixup
= cp_report_fixup
,
139 .input_mapped
= cp_input_mapped
,
143 module_hid_driver(cp_driver
);
145 MODULE_LICENSE("GPL");