Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
846 giacomo 1
/*
2
 * $Id: hid-input.c,v 1.1 2004-09-13 15:04:47 giacomo Exp $
3
 *
4
 *  Copyright (c) 2000-2001 Vojtech Pavlik
5
 *
6
 *  USB HID to Linux Input mapping
7
 */
8
 
9
/*
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
 *
24
 * Should you need to contact me, the author, you can do so either by
25
 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26
 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27
 */
28
 
29
#include <linuxcomp.h> 
30
 
31
#include <linux/module.h>
32
#include <linux/slab.h>
33
#include <linux/kernel.h>
34
#include <linux/input.h>
35
#include <linux/usb.h>
36
 
37
#include "hid.h"
38
 
39
#define unk     KEY_UNKNOWN
40
 
41
static unsigned char hid_keyboard[256] = {
42
          0,  0,  0,  0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
43
         50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44,  2,  3,
44
          4,  5,  6,  7,  8,  9, 10, 11, 28,  1, 14, 15, 57, 12, 13, 26,
45
         27, 43, 84, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
46
         65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
47
        105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
48
         72, 73, 82, 83, 86,127,116,117, 85, 89, 90, 91, 92, 93, 94, 95,
49
        120,121,122,123,134,138,130,132,128,129,131,137,133,135,136,113,
50
        115,114,unk,unk,unk,124,unk,181,182,183,184,185,186,187,188,189,
51
        190,191,192,193,194,195,196,197,198,unk,unk,unk,unk,unk,unk,unk,
52
        unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
53
        unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
54
        unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
55
        unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
56
         29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
57
        150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk
58
};
59
 
60
static struct {
61
        __s32 x;
62
        __s32 y;
63
}  hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
64
 
65
static struct input_dev *find_input(struct hid_device *hid, struct hid_field *field)
66
{
67
        struct list_head *lh;
68
        struct hid_input *hidinput;
69
 
70
        list_for_each (lh, &hid->inputs) {
71
                int i;
72
 
73
                hidinput = list_entry(lh, struct hid_input, list);
74
 
75
                if (! hidinput->report)
76
                        continue;
77
 
78
                for (i = 0; i < hidinput->report->maxfield; i++)
79
                        if (hidinput->report->field[i] == field)
80
                                return &hidinput->input;
81
        }
82
 
83
        /* Assume we only have one input and use it */
84
        if (!list_empty(&hid->inputs)) {
85
                hidinput = list_entry(hid->inputs.next, struct hid_input, list);
86
                return &hidinput->input;
87
        }
88
 
89
        /* This is really a bug */
90
        return NULL;
91
}
92
 
93
static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
94
                                     struct hid_usage *usage)
95
{
96
        struct input_dev *input = &hidinput->input;
97
        struct hid_device *device = hidinput->input.private;
98
        int max;
99
        int is_abs = 0;
100
        unsigned long *bit;
101
 
102
        switch (usage->hid & HID_USAGE_PAGE) {
103
 
104
                case HID_UP_KEYBOARD:
105
 
106
                        set_bit(EV_REP, input->evbit);
107
                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
108
 
109
                        if ((usage->hid & HID_USAGE) < 256) {
110
                                if (!(usage->code = hid_keyboard[usage->hid & HID_USAGE]))
111
                                        return;
112
                                clear_bit(usage->code, bit);
113
                        } else
114
                                usage->code = KEY_UNKNOWN;
115
 
116
                        break;
117
 
118
                case HID_UP_BUTTON:
119
 
120
                        usage->code = ((usage->hid - 1) & 0xf) + 0x100;
121
                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
122
 
123
                        switch (field->application) {
124
                                case HID_GD_GAMEPAD:  usage->code += 0x10;
125
                                case HID_GD_JOYSTICK: usage->code += 0x10;
126
                                case HID_GD_MOUSE:    usage->code += 0x10; break;
127
                                default:
128
                                        if (field->physical == HID_GD_POINTER)
129
                                                usage->code += 0x10;
130
                                        break;
131
                        }
132
                        break;
133
 
134
                case HID_UP_GENDESK:
135
 
136
                        if ((usage->hid & 0xf0) == 0x80) {      /* SystemControl */
137
                                switch (usage->hid & 0xf) {
138
                                        case 0x1: usage->code = KEY_POWER;  break;
139
                                        case 0x2: usage->code = KEY_SLEEP;  break;
140
                                        case 0x3: usage->code = KEY_WAKEUP; break;
141
                                        default: usage->code = KEY_UNKNOWN; break;
142
                                }
143
                                usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
144
                                break;
145
                        }
146
 
147
                        usage->code = usage->hid & 0xf;
148
 
149
                        if (field->report_size == 1) {
150
                                usage->code = BTN_MISC;
151
                                usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
152
                                break;
153
                        }
154
 
155
                        if (field->flags & HID_MAIN_ITEM_RELATIVE) {
156
                                usage->type = EV_REL; bit = input->relbit; max = REL_MAX;
157
                                break;
158
                        }
159
 
160
                        usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
161
 
162
                        if (usage->hid == HID_GD_HATSWITCH) {
163
                                usage->code = ABS_HAT0X;
164
                                usage->hat_min = field->logical_minimum;
165
                                usage->hat_max = field->logical_maximum;
166
                        }
167
                        break;
168
 
169
                case HID_UP_LED:
170
 
171
                        usage->code = (usage->hid - 1) & 0xf;
172
                        usage->type = EV_LED; bit = input->ledbit; max = LED_MAX;
173
                        break;
174
 
175
                case HID_UP_DIGITIZER:
176
 
177
                        switch (usage->hid & 0xff) {
178
 
179
                                case 0x30: /* TipPressure */
180
 
181
                                        if (!test_bit(BTN_TOUCH, input->keybit)) {
182
                                                device->quirks |= HID_QUIRK_NOTOUCH;
183
                                                set_bit(EV_KEY, input->evbit);
184
                                                set_bit(BTN_TOUCH, input->keybit);
185
                                        }
186
                                        usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
187
                                        usage->code = ABS_PRESSURE;
188
                                        clear_bit(usage->code, bit);
189
                                        break;
190
 
191
                                case 0x32: /* InRange */
192
 
193
                                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
194
                                        switch (field->physical & 0xff) {
195
                                                case 0x21: usage->code = BTN_TOOL_MOUSE; break;
196
                                                case 0x22: usage->code = BTN_TOOL_FINGER; break;
197
                                                default: usage->code = BTN_TOOL_PEN; break;
198
                                        }
199
                                        break;
200
 
201
                                case 0x3c: /* Invert */
202
 
203
                                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
204
                                        usage->code = BTN_TOOL_RUBBER;
205
                                        clear_bit(usage->code, bit);
206
                                        break;
207
 
208
                                case 0x33: /* Touch */
209
                                case 0x42: /* TipSwitch */
210
                                case 0x43: /* TipSwitch2 */
211
 
212
                                        device->quirks &= ~HID_QUIRK_NOTOUCH;
213
                                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
214
                                        usage->code = BTN_TOUCH;
215
                                        clear_bit(usage->code, bit);
216
                                        break;
217
 
218
                                case 0x44: /* BarrelSwitch */
219
 
220
                                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
221
                                        usage->code = BTN_STYLUS;
222
                                        clear_bit(usage->code, bit);
223
                                        break;
224
 
225
                                default:  goto unknown;
226
                        }
227
                        break;
228
 
229
                case HID_UP_CONSUMER:   /* USB HUT v1.1, pages 56-62 */
230
 
231
                        set_bit(EV_REP, input->evbit);
232
                        switch (usage->hid & HID_USAGE) {
233
                                case 0x000: usage->code = 0; break;
234
                                case 0x034: usage->code = KEY_SLEEP;            break;
235
                                case 0x036: usage->code = BTN_MISC;             break;
236
                                case 0x08a: usage->code = KEY_WWW;              break;
237
                                case 0x095: usage->code = KEY_HELP;             break;
238
 
239
                                case 0x0b0: usage->code = KEY_PLAY;             break;
240
                                case 0x0b1: usage->code = KEY_PAUSE;            break;
241
                                case 0x0b2: usage->code = KEY_RECORD;           break;
242
                                case 0x0b3: usage->code = KEY_FASTFORWARD;      break;
243
                                case 0x0b4: usage->code = KEY_REWIND;           break;
244
                                case 0x0b5: usage->code = KEY_NEXTSONG;         break;
245
                                case 0x0b6: usage->code = KEY_PREVIOUSSONG;     break;
246
                                case 0x0b7: usage->code = KEY_STOPCD;           break;
247
                                case 0x0b8: usage->code = KEY_EJECTCD;          break;
248
                                case 0x0cd: usage->code = KEY_PLAYPAUSE;        break;
249
                                case 0x0e0: is_abs = 1;
250
                                            usage->code = ABS_VOLUME;
251
                                            break;
252
                                case 0x0e2: usage->code = KEY_MUTE;             break;
253
                                case 0x0e5: usage->code = KEY_BASSBOOST;        break;
254
                                case 0x0e9: usage->code = KEY_VOLUMEUP;         break;
255
                                case 0x0ea: usage->code = KEY_VOLUMEDOWN;       break;
256
 
257
                                case 0x183: usage->code = KEY_CONFIG;           break;
258
                                case 0x18a: usage->code = KEY_MAIL;             break;
259
                                case 0x192: usage->code = KEY_CALC;             break;
260
                                case 0x194: usage->code = KEY_FILE;             break;
261
                                case 0x21a: usage->code = KEY_UNDO;             break;
262
                                case 0x21b: usage->code = KEY_COPY;             break;
263
                                case 0x21c: usage->code = KEY_CUT;              break;
264
                                case 0x21d: usage->code = KEY_PASTE;            break;
265
 
266
                                case 0x221: usage->code = KEY_FIND;             break;
267
                                case 0x223: usage->code = KEY_HOMEPAGE;         break;
268
                                case 0x224: usage->code = KEY_BACK;             break;
269
                                case 0x225: usage->code = KEY_FORWARD;          break;
270
                                case 0x226: usage->code = KEY_STOP;             break;
271
                                case 0x227: usage->code = KEY_REFRESH;          break;
272
                                case 0x22a: usage->code = KEY_BOOKMARKS;        break;
273
 
274
                                default:    usage->code = KEY_UNKNOWN;          break;
275
                        }
276
 
277
                        if (is_abs) {
278
                                usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
279
                        } else  {
280
                                usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
281
                        }
282
                        break;
283
 
284
                case HID_UP_HPVENDOR:   /* Reported on a Dutch layout HP5308 */
285
 
286
                        set_bit(EV_REP, input->evbit);
287
                        switch (usage->hid & HID_USAGE) {
288
                                case 0x021: usage->code = KEY_PRINT;            break;
289
                                case 0x070: usage->code = KEY_HP;               break;
290
                                case 0x071: usage->code = KEY_CAMERA;           break;
291
                                case 0x072: usage->code = KEY_SOUND;            break;
292
                                case 0x073: usage->code = KEY_QUESTION;         break;
293
 
294
                                case 0x080: usage->code = KEY_EMAIL;            break;
295
                                case 0x081: usage->code = KEY_CHAT;             break;
296
                                case 0x082: usage->code = KEY_SEARCH;           break;
297
                                case 0x083: usage->code = KEY_CONNECT;          break;
298
                                case 0x084: usage->code = KEY_FINANCE;          break;
299
                                case 0x085: usage->code = KEY_SPORT;            break;
300
                                case 0x086: usage->code = KEY_SHOP;             break;
301
 
302
                                default:    usage->code = KEY_UNKNOWN;          break;
303
 
304
                        }
305
 
306
                        usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
307
                        break;
308
 
309
                case HID_UP_PID:
310
 
311
                        usage->type = EV_FF; bit = input->ffbit; max = FF_MAX;
312
 
313
                        switch(usage->hid & HID_USAGE) {
314
                                case 0x26: set_bit(FF_CONSTANT, input->ffbit); break;
315
                                case 0x27: set_bit(FF_RAMP,     input->ffbit); break;
316
                                case 0x28: set_bit(FF_CUSTOM,   input->ffbit); break;
317
                                case 0x30: set_bit(FF_SQUARE,   input->ffbit);
318
                                           set_bit(FF_PERIODIC, input->ffbit); break;
319
                                case 0x31: set_bit(FF_SINE,     input->ffbit);
320
                                           set_bit(FF_PERIODIC, input->ffbit); break;
321
                                case 0x32: set_bit(FF_TRIANGLE, input->ffbit);
322
                                           set_bit(FF_PERIODIC, input->ffbit); break;
323
                                case 0x33: set_bit(FF_SAW_UP,   input->ffbit);
324
                                           set_bit(FF_PERIODIC, input->ffbit); break;
325
                                case 0x34: set_bit(FF_SAW_DOWN, input->ffbit);
326
                                           set_bit(FF_PERIODIC, input->ffbit); break;
327
                                case 0x40: set_bit(FF_SPRING,   input->ffbit); break;
328
                                case 0x41: set_bit(FF_DAMPER,   input->ffbit); break;
329
                                case 0x42: set_bit(FF_INERTIA , input->ffbit); break;
330
                                case 0x43: set_bit(FF_FRICTION, input->ffbit); break;
331
                                case 0x7e: usage->code = FF_GAIN;       break;
332
                                case 0x83:  /* Simultaneous Effects Max */
333
                                        input->ff_effects_max = (field->value[0]);
334
                                        dbg("Maximum Effects - %d",input->ff_effects_max);
335
                                        break;
336
                                case 0x98:  /* Device Control */
337
                                        usage->code = FF_AUTOCENTER;    break;
338
                                case 0xa4:  /* Safety Switch */
339
                                        usage->code = BTN_DEAD;
340
                                        bit = input->keybit;
341
                                        usage->type = EV_KEY;
342
                                        max = KEY_MAX;
343
                                        dbg("Safety Switch Report\n");
344
                                        break;
345
                                case 0x9f: /* Device Paused */
346
                                case 0xa0: /* Actuators Enabled */
347
                                        dbg("Not telling the input API about ");
348
                                        resolv_usage(usage->hid);
349
                                        return;
350
                        }
351
                        break;
352
                default:
353
                unknown:
354
                        resolv_usage(usage->hid);
355
 
356
                        if (field->report_size == 1) {
357
 
358
                                if (field->report->type == HID_OUTPUT_REPORT) {
359
                                        usage->code = LED_MISC;
360
                                        usage->type = EV_LED; bit = input->ledbit; max = LED_MAX;
361
                                        break;
362
                                }
363
 
364
                                usage->code = BTN_MISC;
365
                                usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
366
                                break;
367
                        }
368
 
369
                        if (field->flags & HID_MAIN_ITEM_RELATIVE) {
370
                                usage->code = REL_MISC;
371
                                usage->type = EV_REL; bit = input->relbit; max = REL_MAX;
372
                                break;
373
                        }
374
 
375
                        usage->code = ABS_MISC;
376
                        usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
377
                        break;
378
        }
379
 
380
        set_bit(usage->type, input->evbit);
381
        if ((usage->type == EV_REL)
382
                        && (device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK)
383
                        && (usage->code == REL_WHEEL)) {
384
                set_bit(REL_HWHEEL, bit);
385
        }
386
 
387
        while (usage->code <= max && test_and_set_bit(usage->code, bit)) {
388
                usage->code = find_next_zero_bit(bit, max + 1, usage->code);
389
        }
390
 
391
        if (usage->code > max)
392
                return;
393
 
394
        if (usage->type == EV_ABS) {
395
                int a = field->logical_minimum;
396
                int b = field->logical_maximum;
397
 
398
                if ((device->quirks & HID_QUIRK_BADPAD) && (usage->code == ABS_X || usage->code == ABS_Y)) {
399
                        a = field->logical_minimum = 0;
400
                        b = field->logical_maximum = 255;
401
                }
402
 
403
                input->absmin[usage->code] = a;
404
                input->absmax[usage->code] = b;
405
                input->absfuzz[usage->code] = 0;
406
                input->absflat[usage->code] = 0;
407
 
408
                if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK) {
409
                        input->absfuzz[usage->code] = (b - a) >> 8;
410
                        input->absflat[usage->code] = (b - a) >> 4;
411
                }
412
        }
413
 
414
        if (usage->hat_min != usage->hat_max) {
415
                int i;
416
                for (i = usage->code; i < usage->code + 2 && i <= max; i++) {
417
                        input->absmax[i] = 1;
418
                        input->absmin[i] = -1;
419
                        input->absfuzz[i] = 0;
420
                        input->absflat[i] = 0;
421
                }
422
                set_bit(usage->code + 1, input->absbit);
423
        }
424
}
425
 
426
void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, struct pt_regs *regs)
427
{
428
        struct input_dev *input = find_input(hid, field);
429
        int *quirks = &hid->quirks;
430
 
431
        if (!input)
432
                return;
433
 
434
        input_regs(input, regs);
435
 
436
        if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK)
437
                        && (usage->code == BTN_BACK)) {
438
                if (value)
439
                        hid->quirks |= HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
440
                else
441
                        hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
442
                return;
443
        }
444
        if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON)
445
                        && (usage->code == REL_WHEEL)) {
446
                input_event(input, usage->type, REL_HWHEEL, value);
447
                return;
448
        }
449
 
450
        if (usage->hat_min != usage->hat_max) {
451
                value = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1;
452
                if (value < 0 || value > 8) value = 0;
453
                input_event(input, usage->type, usage->code    , hid_hat_to_axis[value].x);
454
                input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[value].y);
455
                return;
456
        }
457
 
458
        if (usage->hid == (HID_UP_DIGITIZER | 0x003c)) { /* Invert */
459
                *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
460
                return;
461
        }
462
 
463
        if (usage->hid == (HID_UP_DIGITIZER | 0x0032)) { /* InRange */
464
                if (value) {
465
                        input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
466
                        return;
467
                }
468
                input_event(input, usage->type, usage->code, 0);
469
                input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
470
                return;
471
        }
472
 
473
        if (usage->hid == (HID_UP_DIGITIZER | 0x0030) && (*quirks & HID_QUIRK_NOTOUCH)) { /* Pressure */
474
                int a = field->logical_minimum;
475
                int b = field->logical_maximum;
476
                input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
477
        }
478
 
479
        if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */
480
                input->ff_effects_max = value;
481
                dbg("Maximum Effects - %d",input->ff_effects_max);
482
                return;
483
        }
484
        if (usage->hid == (HID_UP_PID | 0x7fUL)) {
485
                dbg("PID Pool Report\n");
486
                return;
487
        }
488
 
489
        if((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UKNOWN */
490
                return;
491
 
492
        input_event(input, usage->type, usage->code, value);
493
 
494
        if ((field->flags & HID_MAIN_ITEM_RELATIVE) && (usage->type == EV_KEY))
495
                input_event(input, usage->type, usage->code, 0);
496
}
497
 
498
void hidinput_report_event(struct hid_device *hid, struct hid_report *report)
499
{
500
        struct list_head *lh;
501
        struct hid_input *hidinput;
502
 
503
        list_for_each (lh, &hid->inputs) {
504
                hidinput = list_entry(lh, struct hid_input, list);
505
                input_sync(&hidinput->input);
506
        }
507
}
508
 
509
static int hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
510
{
511
        struct hid_device *hid = dev->private;
512
        struct hid_field *field = NULL;
513
        int offset;
514
 
515
        if (type == EV_FF)
516
                return hid_ff_event(hid, dev, type, code, value);
517
 
518
        if ((offset = hid_find_field(hid, type, code, &field)) == -1) {
519
                warn("event field not found");
520
                return -1;
521
        }
522
 
523
        hid_set_field(field, offset, value);
524
        hid_submit_report(hid, field->report, USB_DIR_OUT);
525
 
526
        return 0;
527
}
528
 
529
static int hidinput_open(struct input_dev *dev)
530
{
531
        struct hid_device *hid = dev->private;
532
        return hid_open(hid);
533
}
534
 
535
static void hidinput_close(struct input_dev *dev)
536
{
537
        struct hid_device *hid = dev->private;
538
        hid_close(hid);
539
}
540
 
541
/*
542
 * Register the input device; print a message.
543
 * Configure the input layer interface
544
 * Read all reports and initialize the absolute field values.
545
 */
546
 
547
int hidinput_connect(struct hid_device *hid)
548
{
549
        struct usb_device *dev = hid->dev;
550
        struct hid_report_enum *report_enum;
551
        struct hid_report *report;
552
        struct list_head *list;
553
        struct hid_input *hidinput = NULL;
554
        int i, j, k;
555
 
556
        INIT_LIST_HEAD(&hid->inputs);
557
 
558
        for (i = 0; i < hid->maxcollection; i++)
559
                if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
560
                    IS_INPUT_APPLICATION(hid->collection[i].usage))
561
                        break;
562
 
563
        if (i == hid->maxcollection)
564
                return -1;
565
 
566
        for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
567
                report_enum = hid->report_enum + k;
568
                list = report_enum->report_list.next;
569
                while (list != &report_enum->report_list) {
570
                        report = (struct hid_report *) list;
571
 
572
                        if (!report->maxfield)
573
                                continue;
574
 
575
                        if (!hidinput) {
576
                                hidinput = kmalloc(sizeof(*hidinput), GFP_KERNEL);
577
                                if (!hidinput) {
578
                                        err("Out of memory during hid input probe");
579
                                        return -1;
580
                                }
581
                                memset(hidinput, 0, sizeof(*hidinput));
582
 
583
                                list_add_tail(&hidinput->list, &hid->inputs);
584
 
585
                                hidinput->input.private = hid;
586
                                hidinput->input.event = hidinput_input_event;
587
                                hidinput->input.open = hidinput_open;
588
                                hidinput->input.close = hidinput_close;
589
 
590
                                hidinput->input.name = hid->name;
591
                                hidinput->input.phys = hid->phys;
592
                                hidinput->input.uniq = hid->uniq;
593
                                hidinput->input.id.bustype = BUS_USB;
594
                                hidinput->input.id.vendor = dev->descriptor.idVendor;
595
                                hidinput->input.id.product = dev->descriptor.idProduct;
596
                                hidinput->input.id.version = dev->descriptor.bcdDevice;
597
                        }
598
 
599
                        for (i = 0; i < report->maxfield; i++)
600
                                for (j = 0; j < report->field[i]->maxusage; j++)
601
                                        hidinput_configure_usage(hidinput, report->field[i],
602
                                                                 report->field[i]->usage + j);
603
 
604
                        if (hid->quirks & HID_QUIRK_MULTI_INPUT) {
605
                                /* This will leave hidinput NULL, so that it
606
                                 * allocates another one if we have more inputs on
607
                                 * the same interface. Some devices (e.g. Happ's
608
                                 * UGCI) cram a lot of unrelated inputs into the
609
                                 * same interface. */
610
                                hidinput->report = report;
611
                                input_register_device(&hidinput->input);
612
                                hidinput = NULL;
613
                        }
614
 
615
                        list = list->next;
616
                }
617
        }
618
 
619
        /* This only gets called when we are a single-input (most of the
620
         * time). IOW, not a HID_QUIRK_MULTI_INPUT. The hid_ff_init() is
621
         * only useful in this case, and not for multi-input quirks. */
622
        if (hidinput) {
623
                hid_ff_init(hid);
624
                input_register_device(&hidinput->input);
625
        }
626
 
627
        return 0;
628
}
629
 
630
void hidinput_disconnect(struct hid_device *hid)
631
{
632
        struct list_head *lh, *next;
633
        struct hid_input *hidinput;
634
 
635
        list_for_each_safe (lh, next, &hid->inputs) {
636
                hidinput = list_entry(lh, struct hid_input, list);
637
                input_unregister_device(&hidinput->input);
638
                list_del(&hidinput->list);
639
                kfree(hidinput);
640
        }
641
}