Linux Audio

Check our new training course

Loading...
v4.6
 
  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
  6 *  Copyright (c) 2012 Nikolai Kondrashov
 
  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
 22/*
 23 * See EasyPen i405X description, device and HID report descriptors at
 24 * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_i405X
 
 
 25 */
 26
 27/* Original EasyPen i405X report descriptor size */
 28#define EASYPEN_I405X_RDESC_ORIG_SIZE	476
 29
 30/* Fixed EasyPen i405X report descriptor */
 31static __u8 easypen_i405x_rdesc_fixed[] = {
 32	0x06, 0x00, 0xFF, /*  Usage Page (FF00h),             */
 33	0x09, 0x01,       /*  Usage (01h),                    */
 34	0xA1, 0x01,       /*  Collection (Application),       */
 35	0x85, 0x05,       /*    Report ID (5),                */
 36	0x09, 0x01,       /*    Usage (01h),                  */
 37	0x15, 0x80,       /*    Logical Minimum (-128),       */
 38	0x25, 0x7F,       /*    Logical Maximum (127),        */
 39	0x75, 0x08,       /*    Report Size (8),              */
 40	0x95, 0x07,       /*    Report Count (7),             */
 41	0xB1, 0x02,       /*    Feature (Variable),           */
 42	0xC0,             /*  End Collection,                 */
 43	0x05, 0x0D,       /*  Usage Page (Digitizer),         */
 44	0x09, 0x02,       /*  Usage (Pen),                    */
 45	0xA1, 0x01,       /*  Collection (Application),       */
 46	0x85, 0x10,       /*    Report ID (16),               */
 47	0x09, 0x20,       /*    Usage (Stylus),               */
 48	0xA0,             /*    Collection (Physical),        */
 49	0x14,             /*      Logical Minimum (0),        */
 50	0x25, 0x01,       /*      Logical Maximum (1),        */
 51	0x75, 0x01,       /*      Report Size (1),            */
 52	0x09, 0x42,       /*      Usage (Tip Switch),         */
 53	0x09, 0x44,       /*      Usage (Barrel Switch),      */
 54	0x09, 0x46,       /*      Usage (Tablet Pick),        */
 55	0x95, 0x03,       /*      Report Count (3),           */
 56	0x81, 0x02,       /*      Input (Variable),           */
 57	0x95, 0x04,       /*      Report Count (4),           */
 58	0x81, 0x03,       /*      Input (Constant, Variable), */
 59	0x09, 0x32,       /*      Usage (In Range),           */
 60	0x95, 0x01,       /*      Report Count (1),           */
 61	0x81, 0x02,       /*      Input (Variable),           */
 62	0x75, 0x10,       /*      Report Size (16),           */
 63	0x95, 0x01,       /*      Report Count (1),           */
 64	0xA4,             /*      Push,                       */
 65	0x05, 0x01,       /*      Usage Page (Desktop),       */
 66	0x55, 0xFD,       /*      Unit Exponent (-3),         */
 67	0x65, 0x13,       /*      Unit (Inch),                */
 68	0x34,             /*      Physical Minimum (0),       */
 69	0x09, 0x30,       /*      Usage (X),                  */
 70	0x46, 0x7C, 0x15, /*      Physical Maximum (5500),    */
 71	0x26, 0x00, 0x37, /*      Logical Maximum (14080),    */
 72	0x81, 0x02,       /*      Input (Variable),           */
 73	0x09, 0x31,       /*      Usage (Y),                  */
 74	0x46, 0xA0, 0x0F, /*      Physical Maximum (4000),    */
 75	0x26, 0x00, 0x28, /*      Logical Maximum (10240),    */
 76	0x81, 0x02,       /*      Input (Variable),           */
 77	0xB4,             /*      Pop,                        */
 78	0x09, 0x30,       /*      Usage (Tip Pressure),       */
 79	0x26, 0xFF, 0x03, /*      Logical Maximum (1023),     */
 80	0x81, 0x02,       /*      Input (Variable),           */
 81	0xC0,             /*    End Collection,               */
 82	0xC0              /*  End Collection                  */
 83};
 84
 85/*
 86 * See MousePen i608X description, device and HID report descriptors at
 87 * http://sf.net/apps/mediawiki/digimend/?title=KYE_MousePen_i608X
 88 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 89
 90/* Original MousePen i608X report descriptor size */
 91#define MOUSEPEN_I608X_RDESC_ORIG_SIZE	476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 92
 93/* Fixed MousePen i608X report descriptor */
 94static __u8 mousepen_i608x_rdesc_fixed[] = {
 95	0x06, 0x00, 0xFF, /*  Usage Page (FF00h),             */
 96	0x09, 0x01,       /*  Usage (01h),                    */
 97	0xA1, 0x01,       /*  Collection (Application),       */
 98	0x85, 0x05,       /*    Report ID (5),                */
 99	0x09, 0x01,       /*    Usage (01h),                  */
100	0x15, 0x80,       /*    Logical Minimum (-128),       */
101	0x25, 0x7F,       /*    Logical Maximum (127),        */
102	0x75, 0x08,       /*    Report Size (8),              */
103	0x95, 0x07,       /*    Report Count (7),             */
104	0xB1, 0x02,       /*    Feature (Variable),           */
105	0xC0,             /*  End Collection,                 */
106	0x05, 0x0D,       /*  Usage Page (Digitizer),         */
107	0x09, 0x02,       /*  Usage (Pen),                    */
108	0xA1, 0x01,       /*  Collection (Application),       */
109	0x85, 0x10,       /*    Report ID (16),               */
110	0x09, 0x20,       /*    Usage (Stylus),               */
111	0xA0,             /*    Collection (Physical),        */
112	0x14,             /*      Logical Minimum (0),        */
113	0x25, 0x01,       /*      Logical Maximum (1),        */
114	0x75, 0x01,       /*      Report Size (1),            */
115	0x09, 0x42,       /*      Usage (Tip Switch),         */
116	0x09, 0x44,       /*      Usage (Barrel Switch),      */
117	0x09, 0x46,       /*      Usage (Tablet Pick),        */
118	0x95, 0x03,       /*      Report Count (3),           */
119	0x81, 0x02,       /*      Input (Variable),           */
120	0x95, 0x04,       /*      Report Count (4),           */
121	0x81, 0x03,       /*      Input (Constant, Variable), */
122	0x09, 0x32,       /*      Usage (In Range),           */
123	0x95, 0x01,       /*      Report Count (1),           */
124	0x81, 0x02,       /*      Input (Variable),           */
125	0x75, 0x10,       /*      Report Size (16),           */
126	0x95, 0x01,       /*      Report Count (1),           */
127	0xA4,             /*      Push,                       */
128	0x05, 0x01,       /*      Usage Page (Desktop),       */
129	0x55, 0xFD,       /*      Unit Exponent (-3),         */
130	0x65, 0x13,       /*      Unit (Inch),                */
131	0x34,             /*      Physical Minimum (0),       */
132	0x09, 0x30,       /*      Usage (X),                  */
133	0x46, 0x40, 0x1F, /*      Physical Maximum (8000),    */
134	0x26, 0x00, 0x50, /*      Logical Maximum (20480),    */
135	0x81, 0x02,       /*      Input (Variable),           */
136	0x09, 0x31,       /*      Usage (Y),                  */
137	0x46, 0x70, 0x17, /*      Physical Maximum (6000),    */
138	0x26, 0x00, 0x3C, /*      Logical Maximum (15360),    */
139	0x81, 0x02,       /*      Input (Variable),           */
140	0xB4,             /*      Pop,                        */
141	0x09, 0x30,       /*      Usage (Tip Pressure),       */
142	0x26, 0xFF, 0x03, /*      Logical Maximum (1023),     */
143	0x81, 0x02,       /*      Input (Variable),           */
144	0xC0,             /*    End Collection,               */
145	0xC0,             /*  End Collection,                 */
146	0x05, 0x01,       /*  Usage Page (Desktop),           */
147	0x09, 0x02,       /*  Usage (Mouse),                  */
148	0xA1, 0x01,       /*  Collection (Application),       */
149	0x85, 0x11,       /*    Report ID (17),               */
150	0x09, 0x01,       /*    Usage (Pointer),              */
151	0xA0,             /*    Collection (Physical),        */
152	0x14,             /*      Logical Minimum (0),        */
153	0xA4,             /*      Push,                       */
154	0x05, 0x09,       /*      Usage Page (Button),        */
155	0x75, 0x01,       /*      Report Size (1),            */
156	0x19, 0x01,       /*      Usage Minimum (01h),        */
157	0x29, 0x03,       /*      Usage Maximum (03h),        */
158	0x25, 0x01,       /*      Logical Maximum (1),        */
159	0x95, 0x03,       /*      Report Count (3),           */
160	0x81, 0x02,       /*      Input (Variable),           */
161	0x95, 0x05,       /*      Report Count (5),           */
162	0x81, 0x01,       /*      Input (Constant),           */
163	0xB4,             /*      Pop,                        */
164	0x95, 0x01,       /*      Report Count (1),           */
165	0xA4,             /*      Push,                       */
166	0x55, 0xFD,       /*      Unit Exponent (-3),         */
167	0x65, 0x13,       /*      Unit (Inch),                */
168	0x34,             /*      Physical Minimum (0),       */
169	0x75, 0x10,       /*      Report Size (16),           */
170	0x09, 0x30,       /*      Usage (X),                  */
171	0x46, 0x40, 0x1F, /*      Physical Maximum (8000),    */
172	0x26, 0x00, 0x50, /*      Logical Maximum (20480),    */
173	0x81, 0x02,       /*      Input (Variable),           */
174	0x09, 0x31,       /*      Usage (Y),                  */
175	0x46, 0x70, 0x17, /*      Physical Maximum (6000),    */
176	0x26, 0x00, 0x3C, /*      Logical Maximum (15360),    */
177	0x81, 0x02,       /*      Input (Variable),           */
178	0xB4,             /*      Pop,                        */
179	0x75, 0x08,       /*      Report Size (8),            */
180	0x09, 0x38,       /*      Usage (Wheel),              */
181	0x15, 0xFF,       /*      Logical Minimum (-1),       */
182	0x25, 0x01,       /*      Logical Maximum (1),        */
183	0x81, 0x06,       /*      Input (Variable, Relative), */
184	0x81, 0x01,       /*      Input (Constant),           */
185	0xC0,             /*    End Collection,               */
186	0xC0              /*  End Collection                  */
187};
188
189/*
190 * See EasyPen M610X description, device and HID report descriptors at
191 * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_M610X
192 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
194/* Original EasyPen M610X report descriptor size */
195#define EASYPEN_M610X_RDESC_ORIG_SIZE	476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
197/* Fixed EasyPen M610X report descriptor */
198static __u8 easypen_m610x_rdesc_fixed[] = {
199	0x06, 0x00, 0xFF,             /*  Usage Page (FF00h),             */
200	0x09, 0x01,                   /*  Usage (01h),                    */
201	0xA1, 0x01,                   /*  Collection (Application),       */
202	0x85, 0x05,                   /*    Report ID (5),                */
203	0x09, 0x01,                   /*    Usage (01h),                  */
204	0x15, 0x80,                   /*    Logical Minimum (-128),       */
205	0x25, 0x7F,                   /*    Logical Maximum (127),        */
206	0x75, 0x08,                   /*    Report Size (8),              */
207	0x95, 0x07,                   /*    Report Count (7),             */
208	0xB1, 0x02,                   /*    Feature (Variable),           */
209	0xC0,                         /*  End Collection,                 */
210	0x05, 0x0D,                   /*  Usage Page (Digitizer),         */
211	0x09, 0x02,                   /*  Usage (Pen),                    */
212	0xA1, 0x01,                   /*  Collection (Application),       */
213	0x85, 0x10,                   /*    Report ID (16),               */
214	0x09, 0x20,                   /*    Usage (Stylus),               */
215	0xA0,                         /*    Collection (Physical),        */
216	0x14,                         /*      Logical Minimum (0),        */
217	0x25, 0x01,                   /*      Logical Maximum (1),        */
218	0x75, 0x01,                   /*      Report Size (1),            */
219	0x09, 0x42,                   /*      Usage (Tip Switch),         */
220	0x09, 0x44,                   /*      Usage (Barrel Switch),      */
221	0x09, 0x46,                   /*      Usage (Tablet Pick),        */
222	0x95, 0x03,                   /*      Report Count (3),           */
223	0x81, 0x02,                   /*      Input (Variable),           */
224	0x95, 0x04,                   /*      Report Count (4),           */
225	0x81, 0x03,                   /*      Input (Constant, Variable), */
226	0x09, 0x32,                   /*      Usage (In Range),           */
227	0x95, 0x01,                   /*      Report Count (1),           */
228	0x81, 0x02,                   /*      Input (Variable),           */
229	0x75, 0x10,                   /*      Report Size (16),           */
230	0x95, 0x01,                   /*      Report Count (1),           */
231	0xA4,                         /*      Push,                       */
232	0x05, 0x01,                   /*      Usage Page (Desktop),       */
233	0x55, 0xFD,                   /*      Unit Exponent (-3),         */
234	0x65, 0x13,                   /*      Unit (Inch),                */
235	0x34,                         /*      Physical Minimum (0),       */
236	0x09, 0x30,                   /*      Usage (X),                  */
237	0x46, 0x10, 0x27,             /*      Physical Maximum (10000),   */
238	0x27, 0x00, 0xA0, 0x00, 0x00, /*      Logical Maximum (40960),    */
239	0x81, 0x02,                   /*      Input (Variable),           */
240	0x09, 0x31,                   /*      Usage (Y),                  */
241	0x46, 0x6A, 0x18,             /*      Physical Maximum (6250),    */
242	0x26, 0x00, 0x64,             /*      Logical Maximum (25600),    */
243	0x81, 0x02,                   /*      Input (Variable),           */
244	0xB4,                         /*      Pop,                        */
245	0x09, 0x30,                   /*      Usage (Tip Pressure),       */
246	0x26, 0xFF, 0x03,             /*      Logical Maximum (1023),     */
247	0x81, 0x02,                   /*      Input (Variable),           */
248	0xC0,                         /*    End Collection,               */
249	0xC0,                         /*  End Collection,                 */
250	0x05, 0x0C,                   /*  Usage Page (Consumer),          */
251	0x09, 0x01,                   /*  Usage (Consumer Control),       */
252	0xA1, 0x01,                   /*  Collection (Application),       */
253	0x85, 0x12,                   /*    Report ID (18),               */
254	0x14,                         /*    Logical Minimum (0),          */
255	0x25, 0x01,                   /*    Logical Maximum (1),          */
256	0x75, 0x01,                   /*    Report Size (1),              */
257	0x95, 0x04,                   /*    Report Count (4),             */
258	0x0A, 0x1A, 0x02,             /*    Usage (AC Undo),              */
259	0x0A, 0x79, 0x02,             /*    Usage (AC Redo Or Repeat),    */
260	0x0A, 0x2D, 0x02,             /*    Usage (AC Zoom In),           */
261	0x0A, 0x2E, 0x02,             /*    Usage (AC Zoom Out),          */
262	0x81, 0x02,                   /*    Input (Variable),             */
263	0x95, 0x01,                   /*    Report Count (1),             */
264	0x75, 0x14,                   /*    Report Size (20),             */
265	0x81, 0x03,                   /*    Input (Constant, Variable),   */
266	0x75, 0x20,                   /*    Report Size (32),             */
267	0x81, 0x03,                   /*    Input (Constant, Variable),   */
268	0xC0                          /*  End Collection                  */
269};
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
272/* Original PenSketch M912 report descriptor size */
273#define PENSKETCH_M912_RDESC_ORIG_SIZE	482
 
 
 
 
 
 
 
 
 
 
 
 
 
274
275/* Fixed PenSketch M912 report descriptor */
276static __u8 pensketch_m912_rdesc_fixed[] = {
277	0x05, 0x01,                   /*  Usage Page (Desktop),           */
278	0x08,                         /*  Usage (00h),                    */
279	0xA1, 0x01,                   /*  Collection (Application),       */
280	0x85, 0x05,                   /*    Report ID (5),                */
281	0x06, 0x00, 0xFF,             /*    Usage Page (FF00h),           */
282	0x09, 0x01,                   /*    Usage (01h),                  */
283	0x15, 0x81,                   /*    Logical Minimum (-127),       */
284	0x25, 0x7F,                   /*    Logical Maximum (127),        */
285	0x75, 0x08,                   /*    Report Size (8),              */
286	0x95, 0x07,                   /*    Report Count (7),             */
287	0xB1, 0x02,                   /*    Feature (Variable),           */
288	0xC0,                         /*  End Collection,                 */
289	0x05, 0x0D,                   /*  Usage Page (Digitizer),         */
290	0x09, 0x02,                   /*  Usage (Pen),                    */
291	0xA1, 0x01,                   /*  Collection (Application),       */
292	0x85, 0x10,                   /*    Report ID (16),               */
293	0x09, 0x20,                   /*    Usage (Stylus),               */
294	0xA0,                         /*    Collection (Physical),        */
295	0x09, 0x42,                   /*      Usage (Tip Switch),         */
296	0x09, 0x44,                   /*      Usage (Barrel Switch),      */
297	0x09, 0x46,                   /*      Usage (Tablet Pick),        */
298	0x14,                         /*      Logical Minimum (0),        */
299	0x25, 0x01,                   /*      Logical Maximum (1),        */
300	0x75, 0x01,                   /*      Report Size (1),            */
301	0x95, 0x03,                   /*      Report Count (3),           */
302	0x81, 0x02,                   /*      Input (Variable),           */
303	0x95, 0x04,                   /*      Report Count (4),           */
304	0x81, 0x03,                   /*      Input (Constant, Variable), */
305	0x09, 0x32,                   /*      Usage (In Range),           */
306	0x95, 0x01,                   /*      Report Count (1),           */
307	0x81, 0x02,                   /*      Input (Variable),           */
308	0x75, 0x10,                   /*      Report Size (16),           */
309	0x95, 0x01,                   /*      Report Count (1),           */
310	0xA4,                         /*      Push,                       */
311	0x05, 0x01,                   /*      Usage Page (Desktop),       */
312	0x55, 0xFD,                   /*      Unit Exponent (-3),         */
313	0x65, 0x13,                   /*      Unit (Inch),                */
314	0x14,                         /*      Logical Minimum (0),        */
315	0x34,                         /*      Physical Minimum (0),       */
316	0x09, 0x30,                   /*      Usage (X),                  */
317	0x27, 0x00, 0xF0, 0x00, 0x00, /*      Logical Maximum (61440),    */
318	0x46, 0xE0, 0x2E,             /*      Physical Maximum (12000),   */
 
 
 
 
319	0x81, 0x02,                   /*      Input (Variable),           */
320	0x09, 0x31,                   /*      Usage (Y),                  */
321	0x27, 0x00, 0xB4, 0x00, 0x00, /*      Logical Maximum (46080),    */
322	0x46, 0x28, 0x23,             /*      Physical Maximum (9000),    */
323	0x81, 0x02,                   /*      Input (Variable),           */
324	0xB4,                         /*      Pop,                        */
 
325	0x09, 0x30,                   /*      Usage (Tip Pressure),       */
326	0x14,                         /*      Logical Minimum (0),        */
327	0x26, 0xFF, 0x07,             /*      Logical Maximum (2047),     */
328	0x81, 0x02,                   /*      Input (Variable),           */
329	0xC0,                         /*    End Collection,               */
330	0xC0,                         /*  End Collection,                 */
331	0x05, 0x0D,                   /*  Usage Page (Digitizer),         */
332	0x09, 0x21,                   /*  Usage (Puck),                   */
333	0xA1, 0x01,                   /*  Collection (Application),       */
334	0x85, 0x11,                   /*    Report ID (17),               */
335	0x09, 0x21,                   /*    Usage (Puck),                 */
336	0xA0,                         /*    Collection (Physical),        */
337	0x05, 0x09,                   /*      Usage Page (Button),        */
338	0x75, 0x01,                   /*      Report Size (1),            */
339	0x19, 0x01,                   /*      Usage Minimum (01h),        */
340	0x29, 0x03,                   /*      Usage Maximum (03h),        */
341	0x14,                         /*      Logical Minimum (0),        */
342	0x25, 0x01,                   /*      Logical Maximum (1),        */
 
343	0x95, 0x03,                   /*      Report Count (3),           */
344	0x81, 0x02,                   /*      Input (Variable),           */
345	0x95, 0x04,                   /*      Report Count (4),           */
346	0x81, 0x01,                   /*      Input (Constant),           */
 
 
347	0x95, 0x01,                   /*      Report Count (1),           */
348	0x0B, 0x32, 0x00, 0x0D, 0x00, /*      Usage (Digitizer In Range), */
349	0x14,                         /*      Logical Minimum (0),        */
350	0x25, 0x01,                   /*      Logical Maximum (1),        */
351	0x81, 0x02,                   /*      Input (Variable),           */
352	0xA4,                         /*      Push,                       */
353	0x05, 0x01,                   /*      Usage Page (Desktop),       */
354	0x75, 0x10,                   /*      Report Size (16),           */
355	0x95, 0x01,                   /*      Report Count (1),           */
356	0x55, 0xFD,                   /*      Unit Exponent (-3),         */
357	0x65, 0x13,                   /*      Unit (Inch),                */
358	0x14,                         /*      Logical Minimum (0),        */
359	0x34,                         /*      Physical Minimum (0),       */
360	0x09, 0x30,                   /*      Usage (X),                  */
361	0x27, 0x00, 0xF0, 0x00, 0x00, /*      Logical Maximum (61440),    */
362	0x46, 0xE0, 0x2E,             /*      Physical Maximum (12000),   */
 
 
 
 
363	0x81, 0x02,                   /*      Input (Variable),           */
364	0x09, 0x31,                   /*      Usage (Y),                  */
365	0x27, 0x00, 0xB4, 0x00, 0x00, /*      Logical Maximum (46080),    */
366	0x46, 0x28, 0x23,             /*      Physical Maximum (9000),    */
367	0x81, 0x02,                   /*      Input (Variable),           */
 
368	0x09, 0x38,                   /*      Usage (Wheel),              */
 
369	0x75, 0x08,                   /*      Report Size (8),            */
370	0x95, 0x01,                   /*      Report Count (1),           */
371	0x15, 0xFF,                   /*      Logical Minimum (-1),       */
372	0x25, 0x01,                   /*      Logical Maximum (1),        */
373	0x34,                         /*      Physical Minimum (0),       */
374	0x44,                         /*      Physical Maximum (0),       */
375	0x81, 0x06,                   /*      Input (Variable, Relative), */
376	0xB4,                         /*      Pop,                        */
377	0xC0,                         /*    End Collection,               */
378	0xC0,                         /*  End Collection,                 */
379	0x05, 0x0C,                   /*  Usage Page (Consumer),          */
380	0x09, 0x01,                   /*  Usage (Consumer Control),       */
381	0xA1, 0x01,                   /*  Collection (Application),       */
382	0x85, 0x12,                   /*    Report ID (18),               */
383	0x14,                         /*    Logical Minimum (0),          */
384	0x25, 0x01,                   /*    Logical Maximum (1),          */
385	0x75, 0x01,                   /*    Report Size (1),              */
386	0x95, 0x08,                   /*    Report Count (8),             */
387	0x05, 0x0C,                   /*    Usage Page (Consumer),        */
388	0x0A, 0x6A, 0x02,             /*    Usage (AC Delete),            */
389	0x0A, 0x1A, 0x02,             /*    Usage (AC Undo),              */
390	0x0A, 0x01, 0x02,             /*    Usage (AC New),               */
391	0x0A, 0x2F, 0x02,             /*    Usage (AC Zoom),              */
392	0x0A, 0x25, 0x02,             /*    Usage (AC Forward),           */
393	0x0A, 0x24, 0x02,             /*    Usage (AC Back),              */
394	0x0A, 0x2D, 0x02,             /*    Usage (AC Zoom In),           */
395	0x0A, 0x2E, 0x02,             /*    Usage (AC Zoom Out),          */
396	0x81, 0x02,                   /*    Input (Variable),             */
397	0x95, 0x30,                   /*    Report Count (48),            */
398	0x81, 0x03,                   /*    Input (Constant, Variable),   */
399	0xC0                          /*  End Collection                  */
400};
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
403		unsigned int *rsize, int offset, const char *device_name) {
 
404	/*
405	 * the fixup that need to be done:
406	 *   - change Usage Maximum in the Comsumer Control
407	 *     (report ID 3) to a reasonable value
408	 */
409	if (*rsize >= offset + 31 &&
410	    /* Usage Page (Consumer Devices) */
411	    rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
412	    /* Usage (Consumer Control) */
413	    rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
414	    /*   Usage Maximum > 12287 */
415	    rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
416		hid_info(hdev, "fixing up %s report descriptor\n", device_name);
417		rdesc[offset + 12] = 0x2f;
418	}
419	return rdesc;
420}
421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
423		unsigned int *rsize)
424{
425	switch (hdev->product) {
426	case USB_DEVICE_ID_KYE_ERGO_525V:
427		/* the fixups that need to be done:
428		 *   - change led usage page to button for extra buttons
429		 *   - report size 8 count 1 must be size 1 count 8 for button
430		 *     bitfield
431		 *   - change the button usage range to 4-7 for the extra
432		 *     buttons
433		 */
434		if (*rsize >= 75 &&
435			rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
436			rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
437			rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
438			rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
439			rdesc[73] == 0x95 && rdesc[74] == 0x01) {
440			hid_info(hdev,
441				 "fixing up Kye/Genius Ergo Mouse "
442				 "report descriptor\n");
443			rdesc[62] = 0x09;
444			rdesc[64] = 0x04;
445			rdesc[66] = 0x07;
446			rdesc[72] = 0x01;
447			rdesc[74] = 0x08;
448		}
449		break;
450	case USB_DEVICE_ID_KYE_EASYPEN_I405X:
451		if (*rsize == EASYPEN_I405X_RDESC_ORIG_SIZE) {
452			rdesc = easypen_i405x_rdesc_fixed;
453			*rsize = sizeof(easypen_i405x_rdesc_fixed);
454		}
455		break;
456	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
457	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
458		if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
459			rdesc = mousepen_i608x_rdesc_fixed;
460			*rsize = sizeof(mousepen_i608x_rdesc_fixed);
461		}
462		break;
463	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
464		if (*rsize == EASYPEN_M610X_RDESC_ORIG_SIZE) {
465			rdesc = easypen_m610x_rdesc_fixed;
466			*rsize = sizeof(easypen_m610x_rdesc_fixed);
467		}
468		break;
469	case USB_DEVICE_ID_KYE_PENSKETCH_M912:
470		if (*rsize == PENSKETCH_M912_RDESC_ORIG_SIZE) {
471			rdesc = pensketch_m912_rdesc_fixed;
472			*rsize = sizeof(pensketch_m912_rdesc_fixed);
473		}
474		break;
475	case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
476		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
477					"Genius Gila Gaming Mouse");
478		break;
 
 
 
 
479	case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
480		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
481					"Genius Gx Imperator Keyboard");
482		break;
483	case USB_DEVICE_ID_GENIUS_MANTICORE:
484		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
485					"Genius Manticore Keyboard");
 
 
 
 
 
 
 
 
 
 
 
486		break;
487	}
488	return rdesc;
489}
490
491/**
492 * Enable fully-functional tablet mode by setting a special feature report.
493 *
494 * @hdev:	HID device
495 *
496 * The specific report ID and data were discovered by sniffing the
497 * Windows driver traffic.
498 */
499static int kye_tablet_enable(struct hid_device *hdev)
500{
501	struct list_head *list;
502	struct list_head *head;
503	struct hid_report *report;
504	__s32 *value;
505
506	list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
507	list_for_each(head, list) {
508		report = list_entry(head, struct hid_report, list);
509		if (report->id == 5)
510			break;
511	}
512
513	if (head == list) {
514		hid_err(hdev, "tablet-enabling feature report not found\n");
515		return -ENODEV;
516	}
517
518	if (report->maxfield < 1 || report->field[0]->report_count < 7) {
519		hid_err(hdev, "invalid tablet-enabling feature report\n");
520		return -ENODEV;
521	}
522
523	value = report->field[0]->value;
524
 
 
 
 
 
 
 
 
 
525	value[0] = 0x12;
526	value[1] = 0x10;
527	value[2] = 0x11;
528	value[3] = 0x12;
529	value[4] = 0x00;
530	value[5] = 0x00;
531	value[6] = 0x00;
532	hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
533
534	return 0;
535}
536
537static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
538{
539	int ret;
540
541	ret = hid_parse(hdev);
542	if (ret) {
543		hid_err(hdev, "parse failed\n");
544		goto err;
545	}
546
547	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
548	if (ret) {
549		hid_err(hdev, "hw start failed\n");
550		goto err;
551	}
552
553	switch (id->product) {
 
 
 
 
 
 
 
 
 
 
554	case USB_DEVICE_ID_KYE_EASYPEN_I405X:
555	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
556	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
557	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
 
558	case USB_DEVICE_ID_KYE_PENSKETCH_M912:
 
 
 
 
 
559		ret = kye_tablet_enable(hdev);
560		if (ret) {
561			hid_err(hdev, "tablet enabling failed\n");
562			goto enabling_err;
563		}
564		break;
565	case USB_DEVICE_ID_GENIUS_MANTICORE:
566		/*
567		 * The manticore keyboard needs to have all the interfaces
568		 * opened at least once to be fully functional.
569		 */
570		if (hid_hw_open(hdev))
571			hid_hw_close(hdev);
572		break;
573	}
574
575	return 0;
576enabling_err:
577	hid_hw_stop(hdev);
578err:
579	return ret;
580}
581
582static const struct hid_device_id kye_devices[] = {
583	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
584	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
 
 
 
 
 
 
 
 
 
 
585				USB_DEVICE_ID_KYE_EASYPEN_I405X) },
586	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
587				USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
588	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
589				USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
590	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
591				USB_DEVICE_ID_KYE_EASYPEN_M610X) },
592	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
593				USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
594	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
595				USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
596	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
597				USB_DEVICE_ID_GENIUS_MANTICORE) },
598	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
599				USB_DEVICE_ID_KYE_PENSKETCH_M912) },
 
 
 
 
 
 
600	{ }
601};
602MODULE_DEVICE_TABLE(hid, kye_devices);
603
604static struct hid_driver kye_driver = {
605	.name = "kye",
606	.id_table = kye_devices,
607	.probe = kye_probe,
608	.report_fixup = kye_report_fixup,
609};
610module_hid_driver(kye_driver);
611
612MODULE_LICENSE("GPL");
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  HID driver for Kye/Genius devices not fully compliant with HID standard
  4 *
  5 *  Copyright (c) 2009 Jiri Kosina
  6 *  Copyright (c) 2009 Tomas Hanak
  7 *  Copyright (c) 2012 Nikolai Kondrashov
  8 *  Copyright (c) 2023 David Yang
  9 */
 10
 11#include <asm-generic/unaligned.h>
 
 
 
 
 
 
 12#include <linux/device.h>
 13#include <linux/hid.h>
 14#include <linux/module.h>
 15
 16#include "hid-ids.h"
 17
 18/* Data gathered from Database/VID0458_PID????/Vista/TBoard/default.xml in ioTablet driver
 19 *
 20 * TODO:
 21 *   - Add battery and sleep support for EasyPen M406W and MousePen M508WX
 22 *   - Investigate ScrollZ.MiceFMT buttons of EasyPen M406
 23 */
 24
 25static const __u8 easypen_m406_control_rdesc[] = {
 26	0x05, 0x0C,        /*  Usage Page (Consumer),    */
 27	0x09, 0x01,        /*  Usage (Consumer Control), */
 28	0xA1, 0x01,        /*  Collection (Application), */
 29	0x85, 0x12,        /*    Report ID (18),         */
 30	0x0A, 0x45, 0x02,  /*    Usage (AC Rotate),      */
 31	0x09, 0x40,        /*    Usage (Menu),           */
 32	0x0A, 0x2F, 0x02,  /*    Usage (AC Zoom),        */
 33	0x0A, 0x46, 0x02,  /*    Usage (AC Resize),      */
 34	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),        */
 35	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),      */
 36	0x0A, 0x24, 0x02,  /*    Usage (AC Back),        */
 37	0x0A, 0x25, 0x02,  /*    Usage (AC Forward),     */
 38	0x14,              /*    Logical Minimum (0),    */
 39	0x25, 0x01,        /*    Logical Maximum (1),    */
 40	0x75, 0x01,        /*    Report Size (1),        */
 41	0x95, 0x08,        /*    Report Count (8),       */
 42	0x81, 0x02,        /*    Input (Variable),       */
 43	0x95, 0x30,        /*    Report Count (48),      */
 44	0x81, 0x01,        /*    Input (Constant),       */
 45	0xC0               /*  End Collection            */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 46};
 47
 48static const __u8 easypen_m506_control_rdesc[] = {
 49	0x05, 0x0C,        /*  Usage Page (Consumer),    */
 50	0x09, 0x01,        /*  Usage (Consumer Control), */
 51	0xA1, 0x01,        /*  Collection (Application), */
 52	0x85, 0x12,        /*    Report ID (18),         */
 53	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),      */
 54	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),        */
 55	0x0A, 0x2D, 0x02,  /*    Usage (AC Zoom In),     */
 56	0x0A, 0x2E, 0x02,  /*    Usage (AC Zoom Out),    */
 57	0x14,              /*    Logical Minimum (0),    */
 58	0x25, 0x01,        /*    Logical Maximum (1),    */
 59	0x75, 0x01,        /*    Report Size (1),        */
 60	0x95, 0x04,        /*    Report Count (4),       */
 61	0x81, 0x02,        /*    Input (Variable),       */
 62	0x95, 0x34,        /*    Report Count (52),      */
 63	0x81, 0x01,        /*    Input (Constant),       */
 64	0xC0               /*  End Collection            */
 65};
 66
 67static const __u8 easypen_m406w_control_rdesc[] = {
 68	0x05, 0x0C,        /*  Usage Page (Consumer),    */
 69	0x09, 0x01,        /*  Usage (Consumer Control), */
 70	0xA1, 0x01,        /*  Collection (Application), */
 71	0x85, 0x12,        /*    Report ID (18),         */
 72	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),      */
 73	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),        */
 74	0x0A, 0x01, 0x02,  /*    Usage (AC New),         */
 75	0x09, 0x40,        /*    Usage (Menu),           */
 76	0x14,              /*    Logical Minimum (0),    */
 77	0x25, 0x01,        /*    Logical Maximum (1),    */
 78	0x75, 0x01,        /*    Report Size (1),        */
 79	0x95, 0x04,        /*    Report Count (4),       */
 80	0x81, 0x02,        /*    Input (Variable),       */
 81	0x95, 0x34,        /*    Report Count (52),      */
 82	0x81, 0x01,        /*    Input (Constant),       */
 83	0xC0               /*  End Collection            */
 84};
 85
 86static const __u8 easypen_m610x_control_rdesc[] = {
 87	0x05, 0x0C,        /*  Usage Page (Consumer),       */
 88	0x09, 0x01,        /*  Usage (Consumer Control),    */
 89	0xA1, 0x01,        /*  Collection (Application),    */
 90	0x85, 0x12,        /*    Report ID (18),            */
 91	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),           */
 92	0x0A, 0x79, 0x02,  /*    Usage (AC Redo Or Repeat), */
 93	0x0A, 0x2D, 0x02,  /*    Usage (AC Zoom In),        */
 94	0x0A, 0x2E, 0x02,  /*    Usage (AC Zoom Out),       */
 95	0x14,              /*    Logical Minimum (0),       */
 96	0x25, 0x01,        /*    Logical Maximum (1),       */
 97	0x75, 0x01,        /*    Report Size (1),           */
 98	0x95, 0x04,        /*    Report Count (4),          */
 99	0x81, 0x02,        /*    Input (Variable),          */
100	0x95, 0x34,        /*    Report Count (52),         */
101	0x81, 0x01,        /*    Input (Constant),          */
102	0xC0               /*  End Collection               */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103};
104
105static const __u8 pensketch_m912_control_rdesc[] = {
106	0x05, 0x0C,        /*  Usage Page (Consumer),        */
107	0x09, 0x01,        /*  Usage (Consumer Control),     */
108	0xA1, 0x01,        /*  Collection (Application),     */
109	0x85, 0x12,        /*    Report ID (18),             */
110	0x14,              /*    Logical Minimum (0),        */
111	0x25, 0x01,        /*    Logical Maximum (1),        */
112	0x75, 0x01,        /*    Report Size (1),            */
113	0x95, 0x08,        /*    Report Count (8),           */
114	0x05, 0x0C,        /*    Usage Page (Consumer),      */
115	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),          */
116	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),            */
117	0x0A, 0x01, 0x02,  /*    Usage (AC New),             */
118	0x0A, 0x2F, 0x02,  /*    Usage (AC Zoom),            */
119	0x0A, 0x25, 0x02,  /*    Usage (AC Forward),         */
120	0x0A, 0x24, 0x02,  /*    Usage (AC Back),            */
121	0x0A, 0x2D, 0x02,  /*    Usage (AC Zoom In),         */
122	0x0A, 0x2E, 0x02,  /*    Usage (AC Zoom Out),        */
123	0x81, 0x02,        /*    Input (Variable),           */
124	0x95, 0x30,        /*    Report Count (48),          */
125	0x81, 0x03,        /*    Input (Constant, Variable), */
126	0xC0               /*  End Collection                */
127};
128
129static const __u8 mousepen_m508wx_control_rdesc[] = {
130	0x05, 0x0C,        /*  Usage Page (Consumer),    */
131	0x09, 0x01,        /*  Usage (Consumer Control), */
132	0xA1, 0x01,        /*  Collection (Application), */
133	0x85, 0x12,        /*    Report ID (18),         */
134	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),        */
135	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),      */
136	0x0A, 0x2D, 0x02,  /*    Usage (AC Zoom In),     */
137	0x0A, 0x2E, 0x02,  /*    Usage (AC Zoom Out),    */
138	0x14,              /*    Logical Minimum (0),    */
139	0x25, 0x01,        /*    Logical Maximum (1),    */
140	0x75, 0x01,        /*    Report Size (1),        */
141	0x95, 0x04,        /*    Report Count (4),       */
142	0x81, 0x02,        /*    Input (Variable),       */
143	0x95, 0x34,        /*    Report Count (52),      */
144	0x81, 0x01,        /*    Input (Constant),       */
145	0xC0               /*  End Collection            */
146};
147
148static const __u8 mousepen_m508x_control_rdesc[] = {
149	0x05, 0x0C,        /*  Usage Page (Consumer),        */
150	0x09, 0x01,        /*  Usage (Consumer Control),     */
151	0xA1, 0x01,        /*  Collection (Application),     */
152	0x85, 0x12,        /*    Report ID (18),             */
153	0x0A, 0x01, 0x02,  /*    Usage (AC New),             */
154	0x09, 0x40,        /*    Usage (Menu),               */
155	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),          */
156	0x0A, 0x1A, 0x02,  /*    Usage (AC Undo),            */
157	0x14,              /*    Logical Minimum (0),        */
158	0x25, 0x01,        /*    Logical Maximum (1),        */
159	0x75, 0x01,        /*    Report Size (1),            */
160	0x95, 0x04,        /*    Report Count (4),           */
161	0x81, 0x02,        /*    Input (Variable),           */
162	0x81, 0x01,        /*    Input (Constant),           */
163	0x15, 0xFF,        /*    Logical Minimum (-1),       */
164	0x95, 0x10,        /*    Report Count (16),          */
165	0x81, 0x01,        /*    Input (Constant),           */
166	0x0A, 0x35, 0x02,  /*    Usage (AC Scroll),          */
167	0x0A, 0x2F, 0x02,  /*    Usage (AC Zoom),            */
168	0x0A, 0x38, 0x02,  /*    Usage (AC Pan),             */
169	0x75, 0x08,        /*    Report Size (8),            */
170	0x95, 0x03,        /*    Report Count (3),           */
171	0x81, 0x06,        /*    Input (Variable, Relative), */
172	0x95, 0x01,        /*    Report Count (1),           */
173	0x81, 0x01,        /*    Input (Constant),           */
174	0xC0               /*  End Collection                */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175};
176
177static const __u8 easypen_m406xe_control_rdesc[] = {
178	0x05, 0x0C,        /*  Usage Page (Consumer),          */
179	0x09, 0x01,        /*  Usage (Consumer Control),       */
180	0xA1, 0x01,        /*  Collection (Application),       */
181	0x85, 0x12,        /*      Report ID (18),             */
182	0x14,              /*      Logical Minimum (0),        */
183	0x25, 0x01,        /*      Logical Maximum (1),        */
184	0x75, 0x01,        /*      Report Size (1),            */
185	0x95, 0x04,        /*      Report Count (4),           */
186	0x0A, 0x79, 0x02,  /*      Usage (AC Redo Or Repeat),  */
187	0x0A, 0x1A, 0x02,  /*      Usage (AC Undo),            */
188	0x0A, 0x2D, 0x02,  /*      Usage (AC Zoom In),         */
189	0x0A, 0x2E, 0x02,  /*      Usage (AC Zoom Out),        */
190	0x81, 0x02,        /*      Input (Variable),           */
191	0x95, 0x34,        /*      Report Count (52),          */
192	0x81, 0x03,        /*      Input (Constant, Variable), */
193	0xC0               /*  End Collection                  */
194};
195
196static const __u8 pensketch_t609a_control_rdesc[] = {
197	0x05, 0x0C,        /*  Usage Page (Consumer),    */
198	0x09, 0x01,        /*  Usage (Consumer Control), */
199	0xA1, 0x01,        /*  Collection (Application), */
200	0x85, 0x12,        /*    Report ID (18),         */
201	0x0A, 0x6A, 0x02,  /*    Usage (AC Delete),      */
202	0x14,              /*    Logical Minimum (0),    */
203	0x25, 0x01,        /*    Logical Maximum (1),    */
204	0x75, 0x01,        /*    Report Size (1),        */
205	0x95, 0x08,        /*    Report Count (8),       */
206	0x81, 0x02,        /*    Input (Variable),       */
207	0x95, 0x37,        /*    Report Count (55),      */
208	0x81, 0x01,        /*    Input (Constant),       */
209	0xC0               /*  End Collection            */
210};
211
212/* Fix indexes in kye_tablet_fixup if you change this */
213static const __u8 kye_tablet_rdesc[] = {
214	0x06, 0x00, 0xFF,             /*  Usage Page (FF00h),             */
215	0x09, 0x01,                   /*  Usage (01h),                    */
216	0xA1, 0x01,                   /*  Collection (Application),       */
217	0x85, 0x05,                   /*    Report ID (5),                */
 
218	0x09, 0x01,                   /*    Usage (01h),                  */
219	0x15, 0x81,                   /*    Logical Minimum (-127),       */
220	0x25, 0x7F,                   /*    Logical Maximum (127),        */
221	0x75, 0x08,                   /*    Report Size (8),              */
222	0x95, 0x07,                   /*    Report Count (7),             */
223	0xB1, 0x02,                   /*    Feature (Variable),           */
224	0xC0,                         /*  End Collection,                 */
225	0x05, 0x0D,                   /*  Usage Page (Digitizer),         */
226	0x09, 0x01,                   /*  Usage (Digitizer),              */
227	0xA1, 0x01,                   /*  Collection (Application),       */
228	0x85, 0x10,                   /*    Report ID (16),               */
229	0x09, 0x20,                   /*    Usage (Stylus),               */
230	0xA0,                         /*    Collection (Physical),        */
231	0x09, 0x42,                   /*      Usage (Tip Switch),         */
232	0x09, 0x44,                   /*      Usage (Barrel Switch),      */
233	0x09, 0x46,                   /*      Usage (Tablet Pick),        */
234	0x14,                         /*      Logical Minimum (0),        */
235	0x25, 0x01,                   /*      Logical Maximum (1),        */
236	0x75, 0x01,                   /*      Report Size (1),            */
237	0x95, 0x03,                   /*      Report Count (3),           */
238	0x81, 0x02,                   /*      Input (Variable),           */
239	0x95, 0x04,                   /*      Report Count (4),           */
240	0x81, 0x01,                   /*      Input (Constant),           */
241	0x09, 0x32,                   /*      Usage (In Range),           */
242	0x95, 0x01,                   /*      Report Count (1),           */
243	0x81, 0x02,                   /*      Input (Variable),           */
244	0x75, 0x10,                   /*      Report Size (16),           */
 
245	0xA4,                         /*      Push,                       */
246	0x05, 0x01,                   /*      Usage Page (Desktop),       */
 
 
 
 
247	0x09, 0x30,                   /*      Usage (X),                  */
248	0x27, 0xFF, 0x7F, 0x00, 0x00, /*      Logical Maximum (32767),    */
249	0x34,                         /*      Physical Minimum (0),       */
250	0x47, 0x00, 0x00, 0x00, 0x00, /*      Physical Maximum (0),       */
251	0x65, 0x11,                   /*      Unit (Centimeter),          */
252	0x55, 0x00,                   /*      Unit Exponent (0),          */
253	0x75, 0x10,                   /*      Report Size (16),           */
254	0x81, 0x02,                   /*      Input (Variable),           */
255	0x09, 0x31,                   /*      Usage (Y),                  */
256	0x27, 0xFF, 0x7F, 0x00, 0x00, /*      Logical Maximum (32767),    */
257	0x47, 0x00, 0x00, 0x00, 0x00, /*      Physical Maximum (0),       */
258	0x81, 0x02,                   /*      Input (Variable),           */
259	0xB4,                         /*      Pop,                        */
260	0x05, 0x0D,                   /*      Usage Page (Digitizer),     */
261	0x09, 0x30,                   /*      Usage (Tip Pressure),       */
262	0x27, 0xFF, 0x07, 0x00, 0x00, /*      Logical Maximum (2047),     */
 
263	0x81, 0x02,                   /*      Input (Variable),           */
264	0xC0,                         /*    End Collection,               */
265	0xC0,                         /*  End Collection,                 */
266	0x05, 0x0D,                   /*  Usage Page (Digitizer),         */
267	0x09, 0x21,                   /*  Usage (Puck),                   */
268	0xA1, 0x01,                   /*  Collection (Application),       */
269	0x85, 0x11,                   /*    Report ID (17),               */
270	0x09, 0x21,                   /*    Usage (Puck),                 */
271	0xA0,                         /*    Collection (Physical),        */
272	0x05, 0x09,                   /*      Usage Page (Button),        */
 
273	0x19, 0x01,                   /*      Usage Minimum (01h),        */
274	0x29, 0x03,                   /*      Usage Maximum (03h),        */
275	0x14,                         /*      Logical Minimum (0),        */
276	0x25, 0x01,                   /*      Logical Maximum (1),        */
277	0x75, 0x01,                   /*      Report Size (1),            */
278	0x95, 0x03,                   /*      Report Count (3),           */
279	0x81, 0x02,                   /*      Input (Variable),           */
280	0x95, 0x04,                   /*      Report Count (4),           */
281	0x81, 0x01,                   /*      Input (Constant),           */
282	0x05, 0x0D,                   /*      Usage Page (Digitizer),     */
283	0x09, 0x32,                   /*      Usage (In Range),           */
284	0x95, 0x01,                   /*      Report Count (1),           */
 
 
 
285	0x81, 0x02,                   /*      Input (Variable),           */
 
286	0x05, 0x01,                   /*      Usage Page (Desktop),       */
287	0xA4,                         /*      Push,                       */
 
 
 
 
 
288	0x09, 0x30,                   /*      Usage (X),                  */
289	0x27, 0xFF, 0x7F, 0x00, 0x00, /*      Logical Maximum (32767),    */
290	0x34,                         /*      Physical Minimum (0),       */
291	0x47, 0x00, 0x00, 0x00, 0x00, /*      Physical Maximum (0),       */
292	0x65, 0x11,                   /*      Unit (Centimeter),          */
293	0x55, 0x00,                   /*      Unit Exponent (0),          */
294	0x75, 0x10,                   /*      Report Size (16),           */
295	0x81, 0x02,                   /*      Input (Variable),           */
296	0x09, 0x31,                   /*      Usage (Y),                  */
297	0x27, 0xFF, 0x7F, 0x00, 0x00, /*      Logical Maximum (32767),    */
298	0x47, 0x00, 0x00, 0x00, 0x00, /*      Physical Maximum (0),       */
299	0x81, 0x02,                   /*      Input (Variable),           */
300	0xB4,                         /*      Pop,                        */
301	0x09, 0x38,                   /*      Usage (Wheel),              */
302	0x15, 0xFF,                   /*      Logical Minimum (-1),       */
303	0x75, 0x08,                   /*      Report Size (8),            */
304	0x95, 0x01,                   /*      Report Count (1),           */
 
 
 
 
305	0x81, 0x06,                   /*      Input (Variable, Relative), */
306	0x81, 0x01,                   /*      Input (Constant),           */
307	0xC0,                         /*    End Collection,               */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308	0xC0                          /*  End Collection                  */
309};
310
311static const struct kye_tablet_info {
312	__u32 product;
313	__s32 x_logical_maximum;
314	__s32 y_logical_maximum;
315	__s32 pressure_logical_maximum;
316	__s32 x_physical_maximum;
317	__s32 y_physical_maximum;
318	__s8 unit_exponent;
319	__s8 unit;
320	bool has_punk;
321	unsigned int control_rsize;
322	const __u8 *control_rdesc;
323} kye_tablets_info[] = {
324	{USB_DEVICE_ID_KYE_EASYPEN_M406,  /* 0x5005 */
325		15360, 10240, 1023,    6,   4,  0, 0x13, false,
326		sizeof(easypen_m406_control_rdesc), easypen_m406_control_rdesc},
327	{USB_DEVICE_ID_KYE_EASYPEN_M506,  /* 0x500F */
328		24576, 20480, 1023,    6,   5,  0, 0x13, false,
329		sizeof(easypen_m506_control_rdesc), easypen_m506_control_rdesc},
330	{USB_DEVICE_ID_KYE_EASYPEN_I405X,  /* 0x5010 */
331		14080, 10240, 1023,   55,  40, -1, 0x13, false},
332	{USB_DEVICE_ID_KYE_MOUSEPEN_I608X,  /* 0x5011 */
333		20480, 15360, 2047,    8,   6,  0, 0x13,  true},
334	{USB_DEVICE_ID_KYE_EASYPEN_M406W,  /* 0x5012 */
335		15360, 10240, 1023,    6,   4,  0, 0x13, false,
336		sizeof(easypen_m406w_control_rdesc), easypen_m406w_control_rdesc},
337	{USB_DEVICE_ID_KYE_EASYPEN_M610X,  /* 0x5013 */
338		40960, 25600, 1023, 1000, 625, -2, 0x13, false,
339		sizeof(easypen_m610x_control_rdesc), easypen_m610x_control_rdesc},
340	{USB_DEVICE_ID_KYE_EASYPEN_340,  /* 0x5014 */
341		10240,  7680, 1023,    4,   3,  0, 0x13, false},
342	{USB_DEVICE_ID_KYE_PENSKETCH_M912,  /* 0x5015 */
343		61440, 46080, 2047,   12,   9,  0, 0x13,  true,
344		sizeof(pensketch_m912_control_rdesc), pensketch_m912_control_rdesc},
345	{USB_DEVICE_ID_KYE_MOUSEPEN_M508WX,  /* 0x5016 */
346		40960, 25600, 2047,    8,   5,  0, 0x13,  true,
347		sizeof(mousepen_m508wx_control_rdesc), mousepen_m508wx_control_rdesc},
348	{USB_DEVICE_ID_KYE_MOUSEPEN_M508X,  /* 0x5017 */
349		40960, 25600, 2047,    8,   5,  0, 0x13,  true,
350		sizeof(mousepen_m508x_control_rdesc), mousepen_m508x_control_rdesc},
351	{USB_DEVICE_ID_KYE_EASYPEN_M406XE,  /* 0x5019 */
352		15360, 10240, 1023,    6,   4,  0, 0x13, false,
353		sizeof(easypen_m406xe_control_rdesc), easypen_m406xe_control_rdesc},
354	{USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2,  /* 0x501A */
355		40960, 30720, 2047,    8,   6,  0, 0x13,  true},
356	{USB_DEVICE_ID_KYE_PENSKETCH_T609A,  /* 0x501B */
357		43520, 28160, 1023,   85,  55, -1, 0x13, false,
358		sizeof(pensketch_t609a_control_rdesc), pensketch_t609a_control_rdesc},
359	{}
360};
361
362static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
363		unsigned int *rsize, int offset, const char *device_name)
364{
365	/*
366	 * the fixup that need to be done:
367	 *   - change Usage Maximum in the Consumer Control
368	 *     (report ID 3) to a reasonable value
369	 */
370	if (*rsize >= offset + 31 &&
371	    /* Usage Page (Consumer Devices) */
372	    rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
373	    /* Usage (Consumer Control) */
374	    rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
375	    /*   Usage Maximum > 12287 */
376	    rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
377		hid_info(hdev, "fixing up %s report descriptor\n", device_name);
378		rdesc[offset + 12] = 0x2f;
379	}
380	return rdesc;
381}
382
383/*
384 * Fix tablet descriptor of so-called "DataFormat 2".
385 *
386 * Though we may achieve a usable descriptor from original vendor-defined one,
387 * some problems exist:
388 *  - Their Logical Maximum never exceed 32767 (7F FF), though device do report
389 *    values greater than that;
390 *  - Physical Maximums are arbitrarily filled (always equal to Logical
391 *    Maximum);
392 *  - Detail for control buttons are not provided (a vendor-defined Usage Page
393 *    with fixed content).
394 *
395 * Thus we use a pre-defined parameter table rather than digging it from
396 * original descriptor.
397 *
398 * We may as well write a fallback routine for unrecognized kye tablet, but it's
399 * clear kye are unlikely to produce new models in the foreseeable future, so we
400 * simply enumerate all possible models.
401 */
402static __u8 *kye_tablet_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
403{
404	const struct kye_tablet_info *info;
405	unsigned int newsize;
406
407	if (*rsize < sizeof(kye_tablet_rdesc)) {
408		hid_warn(hdev,
409			 "tablet report size too small, or kye_tablet_rdesc unexpectedly large\n");
410		return rdesc;
411	}
412
413	for (info = kye_tablets_info; info->product; info++) {
414		if (hdev->product == info->product)
415			break;
416	}
417
418	if (!info->product) {
419		hid_err(hdev, "tablet unknown, someone forget to add kye_tablet_info entry?\n");
420		return rdesc;
421	}
422
423	newsize = info->has_punk ? sizeof(kye_tablet_rdesc) : 112;
424	memcpy(rdesc, kye_tablet_rdesc, newsize);
425
426	put_unaligned_le32(info->x_logical_maximum, rdesc + 66);
427	put_unaligned_le32(info->x_physical_maximum, rdesc + 72);
428	rdesc[77] = info->unit;
429	rdesc[79] = info->unit_exponent;
430	put_unaligned_le32(info->y_logical_maximum, rdesc + 87);
431	put_unaligned_le32(info->y_physical_maximum, rdesc + 92);
432	put_unaligned_le32(info->pressure_logical_maximum, rdesc + 104);
433
434	if (info->has_punk) {
435		put_unaligned_le32(info->x_logical_maximum, rdesc + 156);
436		put_unaligned_le32(info->x_physical_maximum, rdesc + 162);
437		rdesc[167] = info->unit;
438		rdesc[169] = info->unit_exponent;
439		put_unaligned_le32(info->y_logical_maximum, rdesc + 177);
440		put_unaligned_le32(info->y_physical_maximum, rdesc + 182);
441	}
442
443	if (info->control_rsize) {
444		if (newsize + info->control_rsize > *rsize)
445			hid_err(hdev, "control rdesc unexpectedly large");
446		else {
447			memcpy(rdesc + newsize, info->control_rdesc, info->control_rsize);
448			newsize += info->control_rsize;
449		}
450	}
451
452	*rsize = newsize;
453	return rdesc;
454}
455
456static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
457		unsigned int *rsize)
458{
459	switch (hdev->product) {
460	case USB_DEVICE_ID_KYE_ERGO_525V:
461		/* the fixups that need to be done:
462		 *   - change led usage page to button for extra buttons
463		 *   - report size 8 count 1 must be size 1 count 8 for button
464		 *     bitfield
465		 *   - change the button usage range to 4-7 for the extra
466		 *     buttons
467		 */
468		if (*rsize >= 75 &&
469			rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
470			rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
471			rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
472			rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
473			rdesc[73] == 0x95 && rdesc[74] == 0x01) {
474			hid_info(hdev,
475				 "fixing up Kye/Genius Ergo Mouse "
476				 "report descriptor\n");
477			rdesc[62] = 0x09;
478			rdesc[64] = 0x04;
479			rdesc[66] = 0x07;
480			rdesc[72] = 0x01;
481			rdesc[74] = 0x08;
482		}
483		break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484	case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
485		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
486					"Genius Gila Gaming Mouse");
487		break;
488	case USB_DEVICE_ID_GENIUS_MANTICORE:
489		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
490					"Genius Manticore Keyboard");
491		break;
492	case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
493		rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
494					"Genius Gx Imperator Keyboard");
495		break;
496	case USB_DEVICE_ID_KYE_EASYPEN_M406:
497	case USB_DEVICE_ID_KYE_EASYPEN_M506:
498	case USB_DEVICE_ID_KYE_EASYPEN_I405X:
499	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
500	case USB_DEVICE_ID_KYE_EASYPEN_M406W:
501	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
502	case USB_DEVICE_ID_KYE_EASYPEN_340:
503	case USB_DEVICE_ID_KYE_PENSKETCH_M912:
504	case USB_DEVICE_ID_KYE_MOUSEPEN_M508WX:
505	case USB_DEVICE_ID_KYE_MOUSEPEN_M508X:
506	case USB_DEVICE_ID_KYE_EASYPEN_M406XE:
507	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
508	case USB_DEVICE_ID_KYE_PENSKETCH_T609A:
509		rdesc = kye_tablet_fixup(hdev, rdesc, rsize);
510		break;
511	}
512	return rdesc;
513}
514
 
 
 
 
 
 
 
 
515static int kye_tablet_enable(struct hid_device *hdev)
516{
517	struct list_head *list;
518	struct list_head *head;
519	struct hid_report *report;
520	__s32 *value;
521
522	list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
523	list_for_each(head, list) {
524		report = list_entry(head, struct hid_report, list);
525		if (report->id == 5)
526			break;
527	}
528
529	if (head == list) {
530		hid_err(hdev, "tablet-enabling feature report not found\n");
531		return -ENODEV;
532	}
533
534	if (report->maxfield < 1 || report->field[0]->report_count < 7) {
535		hid_err(hdev, "invalid tablet-enabling feature report\n");
536		return -ENODEV;
537	}
538
539	value = report->field[0]->value;
540
541	/*
542	 * The code is for DataFormat 2 of config xml. They have no obvious
543	 * meaning (at least not configurable in Windows driver) except enabling
544	 * fully-functional tablet mode (absolute positioning). Otherwise, the
545	 * tablet acts like a relative mouse.
546	 *
547	 * Though there're magic codes for DataFormat 3 and 4, no devices use
548	 * these DataFormats.
549	 */
550	value[0] = 0x12;
551	value[1] = 0x10;
552	value[2] = 0x11;
553	value[3] = 0x12;
554	value[4] = 0x00;
555	value[5] = 0x00;
556	value[6] = 0x00;
557	hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
558
559	return 0;
560}
561
562static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
563{
564	int ret;
565
566	ret = hid_parse(hdev);
567	if (ret) {
568		hid_err(hdev, "parse failed\n");
569		goto err;
570	}
571
572	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
573	if (ret) {
574		hid_err(hdev, "hw start failed\n");
575		goto err;
576	}
577
578	switch (id->product) {
579	case USB_DEVICE_ID_GENIUS_MANTICORE:
580		/*
581		 * The manticore keyboard needs to have all the interfaces
582		 * opened at least once to be fully functional.
583		 */
584		if (hid_hw_open(hdev))
585			hid_hw_close(hdev);
586		break;
587	case USB_DEVICE_ID_KYE_EASYPEN_M406:
588	case USB_DEVICE_ID_KYE_EASYPEN_M506:
589	case USB_DEVICE_ID_KYE_EASYPEN_I405X:
590	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
591	case USB_DEVICE_ID_KYE_EASYPEN_M406W:
592	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
593	case USB_DEVICE_ID_KYE_EASYPEN_340:
594	case USB_DEVICE_ID_KYE_PENSKETCH_M912:
595	case USB_DEVICE_ID_KYE_MOUSEPEN_M508WX:
596	case USB_DEVICE_ID_KYE_MOUSEPEN_M508X:
597	case USB_DEVICE_ID_KYE_EASYPEN_M406XE:
598	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
599	case USB_DEVICE_ID_KYE_PENSKETCH_T609A:
600		ret = kye_tablet_enable(hdev);
601		if (ret) {
602			hid_err(hdev, "tablet enabling failed\n");
603			goto enabling_err;
604		}
605		break;
 
 
 
 
 
 
 
 
606	}
607
608	return 0;
609enabling_err:
610	hid_hw_stop(hdev);
611err:
612	return ret;
613}
614
615static const struct hid_device_id kye_devices[] = {
616	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
617	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
618				USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
619	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
620				USB_DEVICE_ID_GENIUS_MANTICORE) },
621	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
622				USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
623	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
624				USB_DEVICE_ID_KYE_EASYPEN_M406) },
625	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
626				USB_DEVICE_ID_KYE_EASYPEN_M506) },
627	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
628				USB_DEVICE_ID_KYE_EASYPEN_I405X) },
629	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
630				USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
631	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
632				USB_DEVICE_ID_KYE_EASYPEN_M406W) },
633	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
634				USB_DEVICE_ID_KYE_EASYPEN_M610X) },
635	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
636				USB_DEVICE_ID_KYE_EASYPEN_340) },
637	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
638				USB_DEVICE_ID_KYE_PENSKETCH_M912) },
639	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
640				USB_DEVICE_ID_KYE_MOUSEPEN_M508WX) },
641	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
642				USB_DEVICE_ID_KYE_MOUSEPEN_M508X) },
643	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
644				USB_DEVICE_ID_KYE_EASYPEN_M406XE) },
645	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
646				USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2) },
647	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
648				USB_DEVICE_ID_KYE_PENSKETCH_T609A) },
649	{ }
650};
651MODULE_DEVICE_TABLE(hid, kye_devices);
652
653static struct hid_driver kye_driver = {
654	.name = "kye",
655	.id_table = kye_devices,
656	.probe = kye_probe,
657	.report_fixup = kye_report_fixup,
658};
659module_hid_driver(kye_driver);
660
661MODULE_LICENSE("GPL");