]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/hid/hid-kye.c
HID: kye: Rename MousePen i608X v2 macro
[mirror_ubuntu-artful-kernel.git] / drivers / hid / hid-kye.c
CommitLineData
79422741
JK
1/*
2 * HID driver for Kye/Genius devices not fully compliant with HID standard
3 *
4 * Copyright (c) 2009 Jiri Kosina
5 * Copyright (c) 2009 Tomas Hanak
22ca20b2 6 * Copyright (c) 2012 Nikolai Kondrashov
79422741
JK
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/device.h>
17#include <linux/hid.h>
18#include <linux/module.h>
19
20#include "hid-ids.h"
21
22ca20b2
NK
22/* Original EasyPen i405X report descriptor size */
23#define EASYPEN_I405X_RDESC_ORIG_SIZE 476
24
25/* Fixed EasyPen i405X report descriptor */
26static __u8 easypen_i405x_rdesc_fixed[] = {
27 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
28 0x09, 0x01, /* Usage (01h), */
29 0xA1, 0x01, /* Collection (Application), */
30 0x85, 0x05, /* Report ID (5), */
31 0x09, 0x01, /* Usage (01h), */
32 0x15, 0x80, /* Logical Minimum (-128), */
33 0x25, 0x7F, /* Logical Maximum (127), */
34 0x75, 0x08, /* Report Size (8), */
35 0x95, 0x07, /* Report Count (7), */
36 0xB1, 0x02, /* Feature (Variable), */
37 0xC0, /* End Collection, */
38 0x05, 0x0D, /* Usage Page (Digitizer), */
39 0x09, 0x02, /* Usage (Pen), */
40 0xA1, 0x01, /* Collection (Application), */
41 0x85, 0x10, /* Report ID (16), */
42 0x09, 0x20, /* Usage (Stylus), */
43 0xA0, /* Collection (Physical), */
44 0x14, /* Logical Minimum (0), */
45 0x25, 0x01, /* Logical Maximum (1), */
46 0x75, 0x01, /* Report Size (1), */
47 0x09, 0x42, /* Usage (Tip Switch), */
48 0x09, 0x44, /* Usage (Barrel Switch), */
49 0x09, 0x46, /* Usage (Tablet Pick), */
50 0x95, 0x03, /* Report Count (3), */
51 0x81, 0x02, /* Input (Variable), */
52 0x95, 0x04, /* Report Count (4), */
53 0x81, 0x03, /* Input (Constant, Variable), */
54 0x09, 0x32, /* Usage (In Range), */
55 0x95, 0x01, /* Report Count (1), */
56 0x81, 0x02, /* Input (Variable), */
57 0x75, 0x10, /* Report Size (16), */
58 0x95, 0x01, /* Report Count (1), */
59 0xA4, /* Push, */
60 0x05, 0x01, /* Usage Page (Desktop), */
61 0x55, 0xFD, /* Unit Exponent (-3), */
62 0x65, 0x13, /* Unit (Inch), */
63 0x34, /* Physical Minimum (0), */
64 0x09, 0x30, /* Usage (X), */
65 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
66 0x26, 0x00, 0x37, /* Logical Maximum (14080), */
67 0x81, 0x02, /* Input (Variable), */
68 0x09, 0x31, /* Usage (Y), */
69 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
70 0x26, 0x00, 0x28, /* Logical Maximum (10240), */
71 0x81, 0x02, /* Input (Variable), */
72 0xB4, /* Pop, */
73 0x09, 0x30, /* Usage (Tip Pressure), */
74 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
75 0x81, 0x02, /* Input (Variable), */
76 0xC0, /* End Collection, */
77 0xC0 /* End Collection */
78};
79
22ca20b2
NK
80/* Original MousePen i608X report descriptor size */
81#define MOUSEPEN_I608X_RDESC_ORIG_SIZE 476
82
83/* Fixed MousePen i608X report descriptor */
84static __u8 mousepen_i608x_rdesc_fixed[] = {
85 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
86 0x09, 0x01, /* Usage (01h), */
87 0xA1, 0x01, /* Collection (Application), */
88 0x85, 0x05, /* Report ID (5), */
89 0x09, 0x01, /* Usage (01h), */
90 0x15, 0x80, /* Logical Minimum (-128), */
91 0x25, 0x7F, /* Logical Maximum (127), */
92 0x75, 0x08, /* Report Size (8), */
93 0x95, 0x07, /* Report Count (7), */
94 0xB1, 0x02, /* Feature (Variable), */
95 0xC0, /* End Collection, */
96 0x05, 0x0D, /* Usage Page (Digitizer), */
97 0x09, 0x02, /* Usage (Pen), */
98 0xA1, 0x01, /* Collection (Application), */
99 0x85, 0x10, /* Report ID (16), */
100 0x09, 0x20, /* Usage (Stylus), */
101 0xA0, /* Collection (Physical), */
102 0x14, /* Logical Minimum (0), */
103 0x25, 0x01, /* Logical Maximum (1), */
104 0x75, 0x01, /* Report Size (1), */
105 0x09, 0x42, /* Usage (Tip Switch), */
106 0x09, 0x44, /* Usage (Barrel Switch), */
107 0x09, 0x46, /* Usage (Tablet Pick), */
108 0x95, 0x03, /* Report Count (3), */
109 0x81, 0x02, /* Input (Variable), */
110 0x95, 0x04, /* Report Count (4), */
111 0x81, 0x03, /* Input (Constant, Variable), */
112 0x09, 0x32, /* Usage (In Range), */
113 0x95, 0x01, /* Report Count (1), */
114 0x81, 0x02, /* Input (Variable), */
115 0x75, 0x10, /* Report Size (16), */
116 0x95, 0x01, /* Report Count (1), */
117 0xA4, /* Push, */
118 0x05, 0x01, /* Usage Page (Desktop), */
119 0x55, 0xFD, /* Unit Exponent (-3), */
120 0x65, 0x13, /* Unit (Inch), */
121 0x34, /* Physical Minimum (0), */
122 0x09, 0x30, /* Usage (X), */
123 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
124 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
125 0x81, 0x02, /* Input (Variable), */
126 0x09, 0x31, /* Usage (Y), */
127 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
128 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
129 0x81, 0x02, /* Input (Variable), */
130 0xB4, /* Pop, */
131 0x09, 0x30, /* Usage (Tip Pressure), */
132 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
133 0x81, 0x02, /* Input (Variable), */
134 0xC0, /* End Collection, */
135 0xC0, /* End Collection, */
136 0x05, 0x01, /* Usage Page (Desktop), */
137 0x09, 0x02, /* Usage (Mouse), */
138 0xA1, 0x01, /* Collection (Application), */
139 0x85, 0x11, /* Report ID (17), */
140 0x09, 0x01, /* Usage (Pointer), */
141 0xA0, /* Collection (Physical), */
142 0x14, /* Logical Minimum (0), */
143 0xA4, /* Push, */
144 0x05, 0x09, /* Usage Page (Button), */
145 0x75, 0x01, /* Report Size (1), */
146 0x19, 0x01, /* Usage Minimum (01h), */
147 0x29, 0x03, /* Usage Maximum (03h), */
148 0x25, 0x01, /* Logical Maximum (1), */
149 0x95, 0x03, /* Report Count (3), */
150 0x81, 0x02, /* Input (Variable), */
151 0x95, 0x05, /* Report Count (5), */
152 0x81, 0x01, /* Input (Constant), */
153 0xB4, /* Pop, */
154 0x95, 0x01, /* Report Count (1), */
155 0xA4, /* Push, */
156 0x55, 0xFD, /* Unit Exponent (-3), */
157 0x65, 0x13, /* Unit (Inch), */
158 0x34, /* Physical Minimum (0), */
159 0x75, 0x10, /* Report Size (16), */
160 0x09, 0x30, /* Usage (X), */
161 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
162 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
163 0x81, 0x02, /* Input (Variable), */
164 0x09, 0x31, /* Usage (Y), */
165 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
166 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
167 0x81, 0x02, /* Input (Variable), */
168 0xB4, /* Pop, */
169 0x75, 0x08, /* Report Size (8), */
170 0x09, 0x38, /* Usage (Wheel), */
171 0x15, 0xFF, /* Logical Minimum (-1), */
172 0x25, 0x01, /* Logical Maximum (1), */
173 0x81, 0x06, /* Input (Variable, Relative), */
174 0x81, 0x01, /* Input (Constant), */
175 0xC0, /* End Collection, */
176 0xC0 /* End Collection */
177};
178
22ca20b2
NK
179/* Original EasyPen M610X report descriptor size */
180#define EASYPEN_M610X_RDESC_ORIG_SIZE 476
181
182/* Fixed EasyPen M610X report descriptor */
183static __u8 easypen_m610x_rdesc_fixed[] = {
184 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
185 0x09, 0x01, /* Usage (01h), */
186 0xA1, 0x01, /* Collection (Application), */
187 0x85, 0x05, /* Report ID (5), */
188 0x09, 0x01, /* Usage (01h), */
189 0x15, 0x80, /* Logical Minimum (-128), */
190 0x25, 0x7F, /* Logical Maximum (127), */
191 0x75, 0x08, /* Report Size (8), */
192 0x95, 0x07, /* Report Count (7), */
193 0xB1, 0x02, /* Feature (Variable), */
194 0xC0, /* End Collection, */
195 0x05, 0x0D, /* Usage Page (Digitizer), */
196 0x09, 0x02, /* Usage (Pen), */
197 0xA1, 0x01, /* Collection (Application), */
198 0x85, 0x10, /* Report ID (16), */
199 0x09, 0x20, /* Usage (Stylus), */
200 0xA0, /* Collection (Physical), */
201 0x14, /* Logical Minimum (0), */
202 0x25, 0x01, /* Logical Maximum (1), */
203 0x75, 0x01, /* Report Size (1), */
204 0x09, 0x42, /* Usage (Tip Switch), */
205 0x09, 0x44, /* Usage (Barrel Switch), */
206 0x09, 0x46, /* Usage (Tablet Pick), */
207 0x95, 0x03, /* Report Count (3), */
208 0x81, 0x02, /* Input (Variable), */
209 0x95, 0x04, /* Report Count (4), */
210 0x81, 0x03, /* Input (Constant, Variable), */
211 0x09, 0x32, /* Usage (In Range), */
212 0x95, 0x01, /* Report Count (1), */
213 0x81, 0x02, /* Input (Variable), */
214 0x75, 0x10, /* Report Size (16), */
215 0x95, 0x01, /* Report Count (1), */
216 0xA4, /* Push, */
217 0x05, 0x01, /* Usage Page (Desktop), */
218 0x55, 0xFD, /* Unit Exponent (-3), */
219 0x65, 0x13, /* Unit (Inch), */
220 0x34, /* Physical Minimum (0), */
221 0x09, 0x30, /* Usage (X), */
222 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
223 0x27, 0x00, 0xA0, 0x00, 0x00, /* Logical Maximum (40960), */
224 0x81, 0x02, /* Input (Variable), */
225 0x09, 0x31, /* Usage (Y), */
226 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
227 0x26, 0x00, 0x64, /* Logical Maximum (25600), */
228 0x81, 0x02, /* Input (Variable), */
229 0xB4, /* Pop, */
230 0x09, 0x30, /* Usage (Tip Pressure), */
231 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
232 0x81, 0x02, /* Input (Variable), */
233 0xC0, /* End Collection, */
234 0xC0, /* End Collection, */
235 0x05, 0x0C, /* Usage Page (Consumer), */
236 0x09, 0x01, /* Usage (Consumer Control), */
237 0xA1, 0x01, /* Collection (Application), */
238 0x85, 0x12, /* Report ID (18), */
239 0x14, /* Logical Minimum (0), */
240 0x25, 0x01, /* Logical Maximum (1), */
241 0x75, 0x01, /* Report Size (1), */
242 0x95, 0x04, /* Report Count (4), */
243 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
244 0x0A, 0x79, 0x02, /* Usage (AC Redo Or Repeat), */
245 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
246 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
247 0x81, 0x02, /* Input (Variable), */
248 0x95, 0x01, /* Report Count (1), */
249 0x75, 0x14, /* Report Size (20), */
250 0x81, 0x03, /* Input (Constant, Variable), */
251 0x75, 0x20, /* Report Size (32), */
252 0x81, 0x03, /* Input (Constant, Variable), */
253 0xC0 /* End Collection */
254};
255
feb6faf1
MP
256
257/* Original PenSketch M912 report descriptor size */
258#define PENSKETCH_M912_RDESC_ORIG_SIZE 482
259
260/* Fixed PenSketch M912 report descriptor */
261static __u8 pensketch_m912_rdesc_fixed[] = {
262 0x05, 0x01, /* Usage Page (Desktop), */
263 0x08, /* Usage (00h), */
264 0xA1, 0x01, /* Collection (Application), */
265 0x85, 0x05, /* Report ID (5), */
266 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
267 0x09, 0x01, /* Usage (01h), */
268 0x15, 0x81, /* Logical Minimum (-127), */
269 0x25, 0x7F, /* Logical Maximum (127), */
270 0x75, 0x08, /* Report Size (8), */
271 0x95, 0x07, /* Report Count (7), */
272 0xB1, 0x02, /* Feature (Variable), */
273 0xC0, /* End Collection, */
274 0x05, 0x0D, /* Usage Page (Digitizer), */
275 0x09, 0x02, /* Usage (Pen), */
276 0xA1, 0x01, /* Collection (Application), */
277 0x85, 0x10, /* Report ID (16), */
278 0x09, 0x20, /* Usage (Stylus), */
279 0xA0, /* Collection (Physical), */
280 0x09, 0x42, /* Usage (Tip Switch), */
281 0x09, 0x44, /* Usage (Barrel Switch), */
282 0x09, 0x46, /* Usage (Tablet Pick), */
283 0x14, /* Logical Minimum (0), */
284 0x25, 0x01, /* Logical Maximum (1), */
285 0x75, 0x01, /* Report Size (1), */
286 0x95, 0x03, /* Report Count (3), */
287 0x81, 0x02, /* Input (Variable), */
288 0x95, 0x04, /* Report Count (4), */
289 0x81, 0x03, /* Input (Constant, Variable), */
290 0x09, 0x32, /* Usage (In Range), */
291 0x95, 0x01, /* Report Count (1), */
292 0x81, 0x02, /* Input (Variable), */
293 0x75, 0x10, /* Report Size (16), */
294 0x95, 0x01, /* Report Count (1), */
295 0xA4, /* Push, */
296 0x05, 0x01, /* Usage Page (Desktop), */
297 0x55, 0xFD, /* Unit Exponent (-3), */
298 0x65, 0x13, /* Unit (Inch), */
299 0x14, /* Logical Minimum (0), */
300 0x34, /* Physical Minimum (0), */
301 0x09, 0x30, /* Usage (X), */
302 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
303 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
304 0x81, 0x02, /* Input (Variable), */
305 0x09, 0x31, /* Usage (Y), */
306 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
307 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
308 0x81, 0x02, /* Input (Variable), */
309 0xB4, /* Pop, */
310 0x09, 0x30, /* Usage (Tip Pressure), */
311 0x14, /* Logical Minimum (0), */
312 0x26, 0xFF, 0x07, /* Logical Maximum (2047), */
313 0x81, 0x02, /* Input (Variable), */
314 0xC0, /* End Collection, */
315 0xC0, /* End Collection, */
316 0x05, 0x0D, /* Usage Page (Digitizer), */
317 0x09, 0x21, /* Usage (Puck), */
318 0xA1, 0x01, /* Collection (Application), */
319 0x85, 0x11, /* Report ID (17), */
320 0x09, 0x21, /* Usage (Puck), */
321 0xA0, /* Collection (Physical), */
322 0x05, 0x09, /* Usage Page (Button), */
323 0x75, 0x01, /* Report Size (1), */
324 0x19, 0x01, /* Usage Minimum (01h), */
325 0x29, 0x03, /* Usage Maximum (03h), */
326 0x14, /* Logical Minimum (0), */
327 0x25, 0x01, /* Logical Maximum (1), */
328 0x95, 0x03, /* Report Count (3), */
329 0x81, 0x02, /* Input (Variable), */
330 0x95, 0x04, /* Report Count (4), */
331 0x81, 0x01, /* Input (Constant), */
332 0x95, 0x01, /* Report Count (1), */
333 0x0B, 0x32, 0x00, 0x0D, 0x00, /* Usage (Digitizer In Range), */
334 0x14, /* Logical Minimum (0), */
335 0x25, 0x01, /* Logical Maximum (1), */
336 0x81, 0x02, /* Input (Variable), */
337 0xA4, /* Push, */
338 0x05, 0x01, /* Usage Page (Desktop), */
339 0x75, 0x10, /* Report Size (16), */
340 0x95, 0x01, /* Report Count (1), */
341 0x55, 0xFD, /* Unit Exponent (-3), */
342 0x65, 0x13, /* Unit (Inch), */
343 0x14, /* Logical Minimum (0), */
344 0x34, /* Physical Minimum (0), */
345 0x09, 0x30, /* Usage (X), */
346 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
347 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
348 0x81, 0x02, /* Input (Variable), */
349 0x09, 0x31, /* Usage (Y), */
350 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
351 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
352 0x81, 0x02, /* Input (Variable), */
353 0x09, 0x38, /* Usage (Wheel), */
354 0x75, 0x08, /* Report Size (8), */
355 0x95, 0x01, /* Report Count (1), */
356 0x15, 0xFF, /* Logical Minimum (-1), */
357 0x25, 0x01, /* Logical Maximum (1), */
358 0x34, /* Physical Minimum (0), */
359 0x44, /* Physical Maximum (0), */
360 0x81, 0x06, /* Input (Variable, Relative), */
361 0xB4, /* Pop, */
362 0xC0, /* End Collection, */
363 0xC0, /* End Collection, */
364 0x05, 0x0C, /* Usage Page (Consumer), */
365 0x09, 0x01, /* Usage (Consumer Control), */
366 0xA1, 0x01, /* Collection (Application), */
367 0x85, 0x12, /* Report ID (18), */
368 0x14, /* Logical Minimum (0), */
369 0x25, 0x01, /* Logical Maximum (1), */
370 0x75, 0x01, /* Report Size (1), */
371 0x95, 0x08, /* Report Count (8), */
372 0x05, 0x0C, /* Usage Page (Consumer), */
373 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
374 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
375 0x0A, 0x01, 0x02, /* Usage (AC New), */
376 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
377 0x0A, 0x25, 0x02, /* Usage (AC Forward), */
378 0x0A, 0x24, 0x02, /* Usage (AC Back), */
379 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
380 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
381 0x81, 0x02, /* Input (Variable), */
382 0x95, 0x30, /* Report Count (48), */
383 0x81, 0x03, /* Input (Constant, Variable), */
384 0xC0 /* End Collection */
385};
386
0adb9c2c
BT
387static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
388 unsigned int *rsize, int offset, const char *device_name) {
389 /*
390 * the fixup that need to be done:
391 * - change Usage Maximum in the Comsumer Control
392 * (report ID 3) to a reasonable value
393 */
394 if (*rsize >= offset + 31 &&
395 /* Usage Page (Consumer Devices) */
396 rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
397 /* Usage (Consumer Control) */
398 rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
399 /* Usage Maximum > 12287 */
400 rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
401 hid_info(hdev, "fixing up %s report descriptor\n", device_name);
402 rdesc[offset + 12] = 0x2f;
403 }
404 return rdesc;
405}
406
73e4008d
NK
407static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
408 unsigned int *rsize)
79422741 409{
22ca20b2
NK
410 switch (hdev->product) {
411 case USB_DEVICE_ID_KYE_ERGO_525V:
412 /* the fixups that need to be done:
413 * - change led usage page to button for extra buttons
414 * - report size 8 count 1 must be size 1 count 8 for button
415 * bitfield
416 * - change the button usage range to 4-7 for the extra
417 * buttons
418 */
4ab25786 419 if (*rsize >= 75 &&
22ca20b2
NK
420 rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
421 rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
422 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
423 rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
424 rdesc[73] == 0x95 && rdesc[74] == 0x01) {
425 hid_info(hdev,
426 "fixing up Kye/Genius Ergo Mouse "
427 "report descriptor\n");
428 rdesc[62] = 0x09;
429 rdesc[64] = 0x04;
430 rdesc[66] = 0x07;
431 rdesc[72] = 0x01;
432 rdesc[74] = 0x08;
433 }
434 break;
435 case USB_DEVICE_ID_KYE_EASYPEN_I405X:
436 if (*rsize == EASYPEN_I405X_RDESC_ORIG_SIZE) {
437 rdesc = easypen_i405x_rdesc_fixed;
438 *rsize = sizeof(easypen_i405x_rdesc_fixed);
439 }
440 break;
441 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
102750b8 442 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
22ca20b2
NK
443 if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
444 rdesc = mousepen_i608x_rdesc_fixed;
445 *rsize = sizeof(mousepen_i608x_rdesc_fixed);
446 }
447 break;
448 case USB_DEVICE_ID_KYE_EASYPEN_M610X:
449 if (*rsize == EASYPEN_M610X_RDESC_ORIG_SIZE) {
450 rdesc = easypen_m610x_rdesc_fixed;
451 *rsize = sizeof(easypen_m610x_rdesc_fixed);
452 }
453 break;
feb6faf1
MP
454 case USB_DEVICE_ID_KYE_PENSKETCH_M912:
455 if (*rsize == PENSKETCH_M912_RDESC_ORIG_SIZE) {
456 rdesc = pensketch_m912_rdesc_fixed;
457 *rsize = sizeof(pensketch_m912_rdesc_fixed);
458 }
459 break;
3685c18e 460 case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
0adb9c2c
BT
461 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
462 "Genius Gila Gaming Mouse");
463 break;
464 case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
465 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
466 "Genius Gx Imperator Keyboard");
0a5f99cf 467 break;
4a2c94c9
BT
468 case USB_DEVICE_ID_GENIUS_MANTICORE:
469 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
470 "Genius Manticore Keyboard");
3685c18e 471 break;
79422741 472 }
73e4008d 473 return rdesc;
79422741
JK
474}
475
22ca20b2
NK
476/**
477 * Enable fully-functional tablet mode by setting a special feature report.
478 *
479 * @hdev: HID device
480 *
481 * The specific report ID and data were discovered by sniffing the
482 * Windows driver traffic.
483 */
484static int kye_tablet_enable(struct hid_device *hdev)
485{
486 struct list_head *list;
487 struct list_head *head;
488 struct hid_report *report;
489 __s32 *value;
490
491 list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
492 list_for_each(head, list) {
493 report = list_entry(head, struct hid_report, list);
494 if (report->id == 5)
495 break;
496 }
497
498 if (head == list) {
499 hid_err(hdev, "tablet-enabling feature report not found\n");
500 return -ENODEV;
501 }
502
503 if (report->maxfield < 1 || report->field[0]->report_count < 7) {
504 hid_err(hdev, "invalid tablet-enabling feature report\n");
505 return -ENODEV;
506 }
507
508 value = report->field[0]->value;
509
510 value[0] = 0x12;
511 value[1] = 0x10;
512 value[2] = 0x11;
513 value[3] = 0x12;
514 value[4] = 0x00;
515 value[5] = 0x00;
516 value[6] = 0x00;
d8814272 517 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
22ca20b2
NK
518
519 return 0;
520}
521
522static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
523{
524 int ret;
525
526 ret = hid_parse(hdev);
527 if (ret) {
528 hid_err(hdev, "parse failed\n");
529 goto err;
530 }
531
532 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
533 if (ret) {
534 hid_err(hdev, "hw start failed\n");
535 goto err;
536 }
537
538 switch (id->product) {
539 case USB_DEVICE_ID_KYE_EASYPEN_I405X:
540 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
102750b8 541 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
22ca20b2 542 case USB_DEVICE_ID_KYE_EASYPEN_M610X:
feb6faf1 543 case USB_DEVICE_ID_KYE_PENSKETCH_M912:
22ca20b2
NK
544 ret = kye_tablet_enable(hdev);
545 if (ret) {
546 hid_err(hdev, "tablet enabling failed\n");
547 goto enabling_err;
548 }
549 break;
8a396321
BT
550 case USB_DEVICE_ID_GENIUS_MANTICORE:
551 /*
552 * The manticore keyboard needs to have all the interfaces
553 * opened at least once to be fully functional.
554 */
555 if (hid_hw_open(hdev))
556 hid_hw_close(hdev);
557 break;
22ca20b2
NK
558 }
559
560 return 0;
561enabling_err:
562 hid_hw_stop(hdev);
563err:
564 return ret;
565}
566
79422741
JK
567static const struct hid_device_id kye_devices[] = {
568 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
22ca20b2
NK
569 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
570 USB_DEVICE_ID_KYE_EASYPEN_I405X) },
571 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
572 USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
2bacedad 573 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
102750b8 574 USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2) },
22ca20b2
NK
575 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
576 USB_DEVICE_ID_KYE_EASYPEN_M610X) },
3685c18e
BT
577 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
578 USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
0adb9c2c
BT
579 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
580 USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
4a2c94c9
BT
581 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
582 USB_DEVICE_ID_GENIUS_MANTICORE) },
feb6faf1
MP
583 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
584 USB_DEVICE_ID_KYE_PENSKETCH_M912) },
79422741
JK
585 { }
586};
587MODULE_DEVICE_TABLE(hid, kye_devices);
588
589static struct hid_driver kye_driver = {
590 .name = "kye",
591 .id_table = kye_devices,
22ca20b2 592 .probe = kye_probe,
79422741
JK
593 .report_fixup = kye_report_fixup,
594};
f425458e 595module_hid_driver(kye_driver);
79422741 596
79422741 597MODULE_LICENSE("GPL");