Linux Audio

Check our new training course

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