[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / hid / hid-cypress.c
blob62e9cb10e88cffe7d9310bf6d839fb81ed114378
1 /*
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) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
19 #include <linux/device.h>
20 #include <linux/hid.h>
21 #include <linux/input.h>
22 #include <linux/module.h>
24 #include "hid-ids.h"
26 #define CP_RDESC_SWAPPED_MIN_MAX 0x01
27 #define CP_2WHEEL_MOUSE_HACK 0x02
28 #define CP_2WHEEL_MOUSE_HACK_ON 0x04
31 * Some USB barcode readers from cypress have usage min and usage max in
32 * the wrong order
34 static void cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
35 unsigned int rsize)
37 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
38 unsigned int i;
40 if (!(quirks & CP_RDESC_SWAPPED_MIN_MAX))
41 return;
43 for (i = 0; i < rsize - 4; i++)
44 if (rdesc[i] == 0x29 && rdesc[i + 2] == 0x19) {
45 __u8 tmp;
47 rdesc[i] = 0x19;
48 rdesc[i + 2] = 0x29;
49 tmp = rdesc[i + 3];
50 rdesc[i + 3] = rdesc[i + 1];
51 rdesc[i + 1] = tmp;
55 static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
56 struct hid_field *field, struct hid_usage *usage,
57 unsigned long **bit, int *max)
59 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
61 if (!(quirks & CP_2WHEEL_MOUSE_HACK))
62 return 0;
64 if (usage->type == EV_REL && usage->code == REL_WHEEL)
65 set_bit(REL_HWHEEL, *bit);
66 if (usage->hid == 0x00090005)
67 return -1;
69 return 0;
72 static int cp_event(struct hid_device *hdev, struct hid_field *field,
73 struct hid_usage *usage, __s32 value)
75 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
77 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
78 !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK))
79 return 0;
81 if (usage->hid == 0x00090005) {
82 if (value)
83 quirks |= CP_2WHEEL_MOUSE_HACK_ON;
84 else
85 quirks &= ~CP_2WHEEL_MOUSE_HACK_ON;
86 hid_set_drvdata(hdev, (void *)quirks);
87 return 1;
90 if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) {
91 struct input_dev *input = field->hidinput->input;
93 input_event(input, usage->type, REL_HWHEEL, value);
94 return 1;
97 return 0;
100 static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
102 unsigned long quirks = id->driver_data;
103 int ret;
105 hid_set_drvdata(hdev, (void *)quirks);
107 ret = hid_parse(hdev);
108 if (ret) {
109 dev_err(&hdev->dev, "parse failed\n");
110 goto err_free;
113 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
114 if (ret) {
115 dev_err(&hdev->dev, "hw start failed\n");
116 goto err_free;
119 return 0;
120 err_free:
121 return ret;
124 static const struct hid_device_id cp_devices[] = {
125 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1),
126 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
127 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2),
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 = {
136 .name = "cypress",
137 .id_table = cp_devices,
138 .report_fixup = cp_report_fixup,
139 .input_mapped = cp_input_mapped,
140 .event = cp_event,
141 .probe = cp_probe,
144 static int __init cp_init(void)
146 return hid_register_driver(&cp_driver);
149 static void __exit cp_exit(void)
151 hid_unregister_driver(&cp_driver);
154 module_init(cp_init);
155 module_exit(cp_exit);
156 MODULE_LICENSE("GPL");