HID: hid-apple: add device ID of another wireless aluminium
[linux-2.6.git] / drivers / hid / hid-apple.c
1 /*
2  *  USB HID quirks support for Linux
3  *
4  *  Copyright (c) 1999 Andreas Gal
5  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7  *  Copyright (c) 2006-2007 Jiri Kosina
8  *  Copyright (c) 2007 Paul Walmsley
9  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10  */
11
12 /*
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the Free
15  * Software Foundation; either version 2 of the License, or (at your option)
16  * any later version.
17  */
18
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
21 #include <linux/device.h>
22 #include <linux/hid.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/usb.h>
26
27 #include "hid-ids.h"
28
29 #define APPLE_RDESC_JIS         0x0001
30 #define APPLE_IGNORE_MOUSE      0x0002
31 #define APPLE_HAS_FN            0x0004
32 #define APPLE_HIDDEV            0x0008
33 #define APPLE_ISO_KEYBOARD      0x0010
34 #define APPLE_MIGHTYMOUSE       0x0020
35 #define APPLE_INVERT_HWHEEL     0x0040
36 #define APPLE_IGNORE_HIDINPUT   0x0080
37 #define APPLE_NUMLOCK_EMULATION 0x0100
38
39 #define APPLE_FLAG_FKEY         0x01
40
41 static unsigned int fnmode = 1;
42 module_param(fnmode, uint, 0644);
43 MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
44                 "[1] = fkeyslast, 2 = fkeysfirst)");
45
46 static unsigned int iso_layout = 1;
47 module_param(iso_layout, uint, 0644);
48 MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
49                 "(0 = disabled, [1] = enabled)");
50
51 struct apple_sc {
52         unsigned long quirks;
53         unsigned int fn_on;
54         DECLARE_BITMAP(pressed_fn, KEY_CNT);
55         DECLARE_BITMAP(pressed_numlock, KEY_CNT);
56 };
57
58 struct apple_key_translation {
59         u16 from;
60         u16 to;
61         u8 flags;
62 };
63
64 static const struct apple_key_translation macbookair_fn_keys[] = {
65         { KEY_BACKSPACE, KEY_DELETE },
66         { KEY_ENTER,    KEY_INSERT },
67         { KEY_F1,       KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
68         { KEY_F2,       KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
69         { KEY_F3,       KEY_SCALE,          APPLE_FLAG_FKEY },
70         { KEY_F4,       KEY_DASHBOARD,      APPLE_FLAG_FKEY },
71         { KEY_F6,       KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
72         { KEY_F7,       KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
73         { KEY_F8,       KEY_NEXTSONG,       APPLE_FLAG_FKEY },
74         { KEY_F9,       KEY_MUTE,           APPLE_FLAG_FKEY },
75         { KEY_F10,      KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
76         { KEY_F11,      KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
77         { KEY_F12,      KEY_EJECTCD,        APPLE_FLAG_FKEY },
78         { KEY_UP,       KEY_PAGEUP },
79         { KEY_DOWN,     KEY_PAGEDOWN },
80         { KEY_LEFT,     KEY_HOME },
81         { KEY_RIGHT,    KEY_END },
82         { }
83 };
84
85 static const struct apple_key_translation macbookair4_fn_keys[] = {
86         { KEY_BACKSPACE, KEY_DELETE },
87         { KEY_ENTER,    KEY_INSERT },
88         { KEY_F1,       KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
89         { KEY_F2,       KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
90         { KEY_F3,       KEY_SCALE,          APPLE_FLAG_FKEY },
91         { KEY_F4,       KEY_DASHBOARD,      APPLE_FLAG_FKEY },
92         { KEY_F5,       KEY_KBDILLUMDOWN,   APPLE_FLAG_FKEY },
93         { KEY_F6,       KEY_KBDILLUMUP,     APPLE_FLAG_FKEY },
94         { KEY_F7,       KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
95         { KEY_F8,       KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
96         { KEY_F9,       KEY_NEXTSONG,       APPLE_FLAG_FKEY },
97         { KEY_F10,      KEY_MUTE,           APPLE_FLAG_FKEY },
98         { KEY_F11,      KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
99         { KEY_F12,      KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
100         { KEY_UP,       KEY_PAGEUP },
101         { KEY_DOWN,     KEY_PAGEDOWN },
102         { KEY_LEFT,     KEY_HOME },
103         { KEY_RIGHT,    KEY_END },
104         { }
105 };
106
107 static const struct apple_key_translation apple_fn_keys[] = {
108         { KEY_BACKSPACE, KEY_DELETE },
109         { KEY_ENTER,    KEY_INSERT },
110         { KEY_F1,       KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
111         { KEY_F2,       KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
112         { KEY_F3,       KEY_SCALE,          APPLE_FLAG_FKEY },
113         { KEY_F4,       KEY_DASHBOARD,      APPLE_FLAG_FKEY },
114         { KEY_F5,       KEY_KBDILLUMDOWN,   APPLE_FLAG_FKEY },
115         { KEY_F6,       KEY_KBDILLUMUP,     APPLE_FLAG_FKEY },
116         { KEY_F7,       KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
117         { KEY_F8,       KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
118         { KEY_F9,       KEY_NEXTSONG,       APPLE_FLAG_FKEY },
119         { KEY_F10,      KEY_MUTE,           APPLE_FLAG_FKEY },
120         { KEY_F11,      KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
121         { KEY_F12,      KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
122         { KEY_UP,       KEY_PAGEUP },
123         { KEY_DOWN,     KEY_PAGEDOWN },
124         { KEY_LEFT,     KEY_HOME },
125         { KEY_RIGHT,    KEY_END },
126         { }
127 };
128
129 static const struct apple_key_translation powerbook_fn_keys[] = {
130         { KEY_BACKSPACE, KEY_DELETE },
131         { KEY_F1,       KEY_BRIGHTNESSDOWN,     APPLE_FLAG_FKEY },
132         { KEY_F2,       KEY_BRIGHTNESSUP,       APPLE_FLAG_FKEY },
133         { KEY_F3,       KEY_MUTE,               APPLE_FLAG_FKEY },
134         { KEY_F4,       KEY_VOLUMEDOWN,         APPLE_FLAG_FKEY },
135         { KEY_F5,       KEY_VOLUMEUP,           APPLE_FLAG_FKEY },
136         { KEY_F6,       KEY_NUMLOCK,            APPLE_FLAG_FKEY },
137         { KEY_F7,       KEY_SWITCHVIDEOMODE,    APPLE_FLAG_FKEY },
138         { KEY_F8,       KEY_KBDILLUMTOGGLE,     APPLE_FLAG_FKEY },
139         { KEY_F9,       KEY_KBDILLUMDOWN,       APPLE_FLAG_FKEY },
140         { KEY_F10,      KEY_KBDILLUMUP,         APPLE_FLAG_FKEY },
141         { KEY_UP,       KEY_PAGEUP },
142         { KEY_DOWN,     KEY_PAGEDOWN },
143         { KEY_LEFT,     KEY_HOME },
144         { KEY_RIGHT,    KEY_END },
145         { }
146 };
147
148 static const struct apple_key_translation powerbook_numlock_keys[] = {
149         { KEY_J,        KEY_KP1 },
150         { KEY_K,        KEY_KP2 },
151         { KEY_L,        KEY_KP3 },
152         { KEY_U,        KEY_KP4 },
153         { KEY_I,        KEY_KP5 },
154         { KEY_O,        KEY_KP6 },
155         { KEY_7,        KEY_KP7 },
156         { KEY_8,        KEY_KP8 },
157         { KEY_9,        KEY_KP9 },
158         { KEY_M,        KEY_KP0 },
159         { KEY_DOT,      KEY_KPDOT },
160         { KEY_SLASH,    KEY_KPPLUS },
161         { KEY_SEMICOLON, KEY_KPMINUS },
162         { KEY_P,        KEY_KPASTERISK },
163         { KEY_MINUS,    KEY_KPEQUAL },
164         { KEY_0,        KEY_KPSLASH },
165         { KEY_F6,       KEY_NUMLOCK },
166         { KEY_KPENTER,  KEY_KPENTER },
167         { KEY_BACKSPACE, KEY_BACKSPACE },
168         { }
169 };
170
171 static const struct apple_key_translation apple_iso_keyboard[] = {
172         { KEY_GRAVE,    KEY_102ND },
173         { KEY_102ND,    KEY_GRAVE },
174         { }
175 };
176
177 static const struct apple_key_translation *apple_find_translation(
178                 const struct apple_key_translation *table, u16 from)
179 {
180         const struct apple_key_translation *trans;
181
182         /* Look for the translation */
183         for (trans = table; trans->from; trans++)
184                 if (trans->from == from)
185                         return trans;
186
187         return NULL;
188 }
189
190 static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
191                 struct hid_usage *usage, __s32 value)
192 {
193         struct apple_sc *asc = hid_get_drvdata(hid);
194         const struct apple_key_translation *trans, *table;
195
196         if (usage->code == KEY_FN) {
197                 asc->fn_on = !!value;
198                 input_event(input, usage->type, usage->code, value);
199                 return 1;
200         }
201
202         if (fnmode) {
203                 int do_translate;
204
205                 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
206                                 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
207                         table = macbookair_fn_keys;
208                 else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI &&
209                                 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING6_JIS)
210                         table = macbookair_fn_keys;
211                 else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI &&
212                                 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS)
213                         table = macbookair4_fn_keys;
214                 else if (hid->product < 0x21d || hid->product >= 0x300)
215                         table = powerbook_fn_keys;
216                 else
217                         table = apple_fn_keys;
218
219                 trans = apple_find_translation (table, usage->code);
220
221                 if (trans) {
222                         if (test_bit(usage->code, asc->pressed_fn))
223                                 do_translate = 1;
224                         else if (trans->flags & APPLE_FLAG_FKEY)
225                                 do_translate = (fnmode == 2 && asc->fn_on) ||
226                                         (fnmode == 1 && !asc->fn_on);
227                         else
228                                 do_translate = asc->fn_on;
229
230                         if (do_translate) {
231                                 if (value)
232                                         set_bit(usage->code, asc->pressed_fn);
233                                 else
234                                         clear_bit(usage->code, asc->pressed_fn);
235
236                                 input_event(input, usage->type, trans->to,
237                                                 value);
238
239                                 return 1;
240                         }
241                 }
242
243                 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
244                                 (test_bit(usage->code, asc->pressed_numlock) ||
245                                 test_bit(LED_NUML, input->led))) {
246                         trans = apple_find_translation(powerbook_numlock_keys,
247                                         usage->code);
248
249                         if (trans) {
250                                 if (value)
251                                         set_bit(usage->code,
252                                                         asc->pressed_numlock);
253                                 else
254                                         clear_bit(usage->code,
255                                                         asc->pressed_numlock);
256
257                                 input_event(input, usage->type, trans->to,
258                                                 value);
259                         }
260
261                         return 1;
262                 }
263         }
264
265         if (iso_layout) {
266                 if (asc->quirks & APPLE_ISO_KEYBOARD) {
267                         trans = apple_find_translation(apple_iso_keyboard, usage->code);
268                         if (trans) {
269                                 input_event(input, usage->type, trans->to, value);
270                                 return 1;
271                         }
272                 }
273         }
274
275         return 0;
276 }
277
278 static int apple_event(struct hid_device *hdev, struct hid_field *field,
279                 struct hid_usage *usage, __s32 value)
280 {
281         struct apple_sc *asc = hid_get_drvdata(hdev);
282
283         if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
284                         !usage->type)
285                 return 0;
286
287         if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
288                         usage->code == REL_HWHEEL) {
289                 input_event(field->hidinput->input, usage->type, usage->code,
290                                 -value);
291                 return 1;
292         }
293
294         if ((asc->quirks & APPLE_HAS_FN) &&
295                         hidinput_apple_event(hdev, field->hidinput->input,
296                                 usage, value))
297                 return 1;
298
299
300         return 0;
301 }
302
303 /*
304  * MacBook JIS keyboard has wrong logical maximum
305  */
306 static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
307                 unsigned int *rsize)
308 {
309         struct apple_sc *asc = hid_get_drvdata(hdev);
310
311         if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
312                         rdesc[53] == 0x65 && rdesc[59] == 0x65) {
313                 hid_info(hdev,
314                          "fixing up MacBook JIS keyboard report descriptor\n");
315                 rdesc[53] = rdesc[59] = 0xe7;
316         }
317         return rdesc;
318 }
319
320 static void apple_setup_input(struct input_dev *input)
321 {
322         const struct apple_key_translation *trans;
323
324         set_bit(KEY_NUMLOCK, input->keybit);
325
326         /* Enable all needed keys */
327         for (trans = apple_fn_keys; trans->from; trans++)
328                 set_bit(trans->to, input->keybit);
329
330         for (trans = powerbook_fn_keys; trans->from; trans++)
331                 set_bit(trans->to, input->keybit);
332
333         for (trans = powerbook_numlock_keys; trans->from; trans++)
334                 set_bit(trans->to, input->keybit);
335
336         for (trans = apple_iso_keyboard; trans->from; trans++)
337                 set_bit(trans->to, input->keybit);
338 }
339
340 static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
341                 struct hid_field *field, struct hid_usage *usage,
342                 unsigned long **bit, int *max)
343 {
344         if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
345                 /* The fn key on Apple USB keyboards */
346                 set_bit(EV_REP, hi->input->evbit);
347                 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
348                 apple_setup_input(hi->input);
349                 return 1;
350         }
351
352         /* we want the hid layer to go through standard path (set and ignore) */
353         return 0;
354 }
355
356 static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
357                 struct hid_field *field, struct hid_usage *usage,
358                 unsigned long **bit, int *max)
359 {
360         struct apple_sc *asc = hid_get_drvdata(hdev);
361
362         if (asc->quirks & APPLE_MIGHTYMOUSE) {
363                 if (usage->hid == HID_GD_Z)
364                         hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
365                 else if (usage->code == BTN_1)
366                         hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
367                 else if (usage->code == BTN_2)
368                         hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
369         }
370
371         return 0;
372 }
373
374 static int apple_probe(struct hid_device *hdev,
375                 const struct hid_device_id *id)
376 {
377         unsigned long quirks = id->driver_data;
378         struct apple_sc *asc;
379         unsigned int connect_mask = HID_CONNECT_DEFAULT;
380         int ret;
381
382         asc = kzalloc(sizeof(*asc), GFP_KERNEL);
383         if (asc == NULL) {
384                 hid_err(hdev, "can't alloc apple descriptor\n");
385                 return -ENOMEM;
386         }
387
388         asc->quirks = quirks;
389
390         hid_set_drvdata(hdev, asc);
391
392         ret = hid_parse(hdev);
393         if (ret) {
394                 hid_err(hdev, "parse failed\n");
395                 goto err_free;
396         }
397
398         if (quirks & APPLE_HIDDEV)
399                 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
400         if (quirks & APPLE_IGNORE_HIDINPUT)
401                 connect_mask &= ~HID_CONNECT_HIDINPUT;
402
403         ret = hid_hw_start(hdev, connect_mask);
404         if (ret) {
405                 hid_err(hdev, "hw start failed\n");
406                 goto err_free;
407         }
408
409         return 0;
410 err_free:
411         kfree(asc);
412         return ret;
413 }
414
415 static void apple_remove(struct hid_device *hdev)
416 {
417         hid_hw_stop(hdev);
418         kfree(hid_get_drvdata(hdev));
419 }
420
421 static const struct hid_device_id apple_devices[] = {
422         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL),
423                 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
424         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4),
425                 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
426         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
427                 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
428
429         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
430                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
431         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
432                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
433         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
434                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
435         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
436                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
437                         APPLE_ISO_KEYBOARD },
438         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
439                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
440         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
441                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
442         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
443                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
444                         APPLE_ISO_KEYBOARD },
445         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
446                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
447                         APPLE_RDESC_JIS },
448         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
449                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
450         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
451                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
452                         APPLE_ISO_KEYBOARD },
453         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
454                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
455                         APPLE_RDESC_JIS },
456         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
457                 .driver_data = APPLE_HAS_FN },
458         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
459                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
460         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
461                 .driver_data = APPLE_HAS_FN },
462         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
463                 .driver_data = APPLE_HAS_FN },
464         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
465                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
466         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
467                 .driver_data = APPLE_HAS_FN },
468         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
469                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
470         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
471                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
472         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
473                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
474                         APPLE_RDESC_JIS },
475         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
476                 .driver_data = APPLE_HAS_FN },
477         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
478                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
479         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
480                 .driver_data = APPLE_HAS_FN },
481         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
482                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
483         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
484                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
485                         APPLE_ISO_KEYBOARD },
486         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
487                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
488                         APPLE_ISO_KEYBOARD },
489         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
490                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
491         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
492                 .driver_data = APPLE_HAS_FN },
493         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
494                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
495         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
496                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
497         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
498                 .driver_data = APPLE_HAS_FN },
499         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
500                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
501         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
502                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
503         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
504                 .driver_data = APPLE_HAS_FN },
505         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
506                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
507         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
508                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
509         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
510                 .driver_data = APPLE_HAS_FN },
511         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
512                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
513         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
514                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
515         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
516                 .driver_data = APPLE_HAS_FN },
517         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
518                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
519         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
520                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
521         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
522                 .driver_data = APPLE_HAS_FN },
523         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
524                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
525         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
526                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
527         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
528                 .driver_data = APPLE_HAS_FN },
529         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
530                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
531         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
532                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
533         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
534                 .driver_data = APPLE_HAS_FN },
535         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
536                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
537         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
538                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
539         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
540                 .driver_data = APPLE_HAS_FN },
541         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
542                 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
543         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
544                 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
545         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
546                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
547         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
548                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
549                         APPLE_ISO_KEYBOARD },
550         { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
551                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
552         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
553                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
554         { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
555                 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
556
557         { }
558 };
559 MODULE_DEVICE_TABLE(hid, apple_devices);
560
561 static struct hid_driver apple_driver = {
562         .name = "apple",
563         .id_table = apple_devices,
564         .report_fixup = apple_report_fixup,
565         .probe = apple_probe,
566         .remove = apple_remove,
567         .event = apple_event,
568         .input_mapping = apple_input_mapping,
569         .input_mapped = apple_input_mapped,
570 };
571
572 static int __init apple_init(void)
573 {
574         int ret;
575
576         ret = hid_register_driver(&apple_driver);
577         if (ret)
578                 pr_err("can't register apple driver\n");
579
580         return ret;
581 }
582
583 static void __exit apple_exit(void)
584 {
585         hid_unregister_driver(&apple_driver);
586 }
587
588 module_init(apple_init);
589 module_exit(apple_exit);
590 MODULE_LICENSE("GPL");