blob: 899c71200bd92a9efec7b66cd76cb2157bd891b3 [file] [log] [blame]
Jiri Slaby8c19a512008-06-18 23:36:49 +02001/*
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
Joe Perches4291ee32010-12-09 19:29:03 -080019#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
Jiri Slaby8c19a512008-06-18 23:36:49 +020021#include <linux/device.h>
22#include <linux/hid.h>
23#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Jiri Slaby8c19a512008-06-18 23:36:49 +020025#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
41static unsigned int fnmode = 1;
42module_param(fnmode, uint, 0644);
43MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
44 "[1] = fkeyslast, 2 = fkeysfirst)");
45
Stefan Glasenhardt54a65932010-01-05 23:30:30 +010046static unsigned int iso_layout = 1;
47module_param(iso_layout, uint, 0644);
48MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
49 "(0 = disabled, [1] = enabled)");
50
Jiri Slaby8c19a512008-06-18 23:36:49 +020051struct 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
58struct apple_key_translation {
59 u16 from;
60 u16 to;
61 u8 flags;
62};
63
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -040064static 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
Paul Collinsb2ddd542009-03-07 17:07:15 +130085static const struct apple_key_translation apple_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +020086 { KEY_BACKSPACE, KEY_DELETE },
Henrik Rydberg437184a2008-11-04 13:31:38 +010087 { KEY_ENTER, KEY_INSERT },
Jiri Slaby8c19a512008-06-18 23:36:49 +020088 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
89 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
Henrik Rydberg437184a2008-11-04 13:31:38 +010090 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
91 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
Jiri Slaby8c19a512008-06-18 23:36:49 +020092 { 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
Paul Collinsb2ddd542009-03-07 17:07:15 +1300107static const struct apple_key_translation powerbook_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200108 { KEY_BACKSPACE, KEY_DELETE },
109 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
110 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
111 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
112 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
113 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
114 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
115 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
116 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
117 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
118 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
119 { KEY_UP, KEY_PAGEUP },
120 { KEY_DOWN, KEY_PAGEDOWN },
121 { KEY_LEFT, KEY_HOME },
122 { KEY_RIGHT, KEY_END },
123 { }
124};
125
Paul Collinsb2ddd542009-03-07 17:07:15 +1300126static const struct apple_key_translation powerbook_numlock_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200127 { KEY_J, KEY_KP1 },
128 { KEY_K, KEY_KP2 },
129 { KEY_L, KEY_KP3 },
130 { KEY_U, KEY_KP4 },
131 { KEY_I, KEY_KP5 },
132 { KEY_O, KEY_KP6 },
133 { KEY_7, KEY_KP7 },
134 { KEY_8, KEY_KP8 },
135 { KEY_9, KEY_KP9 },
136 { KEY_M, KEY_KP0 },
137 { KEY_DOT, KEY_KPDOT },
138 { KEY_SLASH, KEY_KPPLUS },
139 { KEY_SEMICOLON, KEY_KPMINUS },
140 { KEY_P, KEY_KPASTERISK },
141 { KEY_MINUS, KEY_KPEQUAL },
142 { KEY_0, KEY_KPSLASH },
143 { KEY_F6, KEY_NUMLOCK },
144 { KEY_KPENTER, KEY_KPENTER },
145 { KEY_BACKSPACE, KEY_BACKSPACE },
146 { }
147};
148
Paul Collinsb2ddd542009-03-07 17:07:15 +1300149static const struct apple_key_translation apple_iso_keyboard[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200150 { KEY_GRAVE, KEY_102ND },
151 { KEY_102ND, KEY_GRAVE },
152 { }
153};
154
Paul Collinsb2ddd542009-03-07 17:07:15 +1300155static const struct apple_key_translation *apple_find_translation(
156 const struct apple_key_translation *table, u16 from)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200157{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300158 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200159
160 /* Look for the translation */
161 for (trans = table; trans->from; trans++)
162 if (trans->from == from)
163 return trans;
164
165 return NULL;
166}
167
168static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
169 struct hid_usage *usage, __s32 value)
170{
171 struct apple_sc *asc = hid_get_drvdata(hid);
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400172 const struct apple_key_translation *trans, *table;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200173
174 if (usage->code == KEY_FN) {
175 asc->fn_on = !!value;
176 input_event(input, usage->type, usage->code, value);
177 return 1;
178 }
179
180 if (fnmode) {
181 int do_translate;
182
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400183 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
184 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
185 table = macbookair_fn_keys;
186 else if (hid->product < 0x21d || hid->product >= 0x300)
187 table = powerbook_fn_keys;
188 else
189 table = apple_fn_keys;
190
191 trans = apple_find_translation (table, usage->code);
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400192
Jiri Slaby8c19a512008-06-18 23:36:49 +0200193 if (trans) {
194 if (test_bit(usage->code, asc->pressed_fn))
195 do_translate = 1;
196 else if (trans->flags & APPLE_FLAG_FKEY)
197 do_translate = (fnmode == 2 && asc->fn_on) ||
198 (fnmode == 1 && !asc->fn_on);
199 else
200 do_translate = asc->fn_on;
201
202 if (do_translate) {
203 if (value)
204 set_bit(usage->code, asc->pressed_fn);
205 else
206 clear_bit(usage->code, asc->pressed_fn);
207
208 input_event(input, usage->type, trans->to,
209 value);
210
211 return 1;
212 }
213 }
214
215 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
216 (test_bit(usage->code, asc->pressed_numlock) ||
217 test_bit(LED_NUML, input->led))) {
218 trans = apple_find_translation(powerbook_numlock_keys,
219 usage->code);
220
221 if (trans) {
222 if (value)
223 set_bit(usage->code,
224 asc->pressed_numlock);
225 else
226 clear_bit(usage->code,
227 asc->pressed_numlock);
228
229 input_event(input, usage->type, trans->to,
230 value);
231 }
232
233 return 1;
234 }
235 }
236
Stefan Glasenhardt54a65932010-01-05 23:30:30 +0100237 if (iso_layout) {
238 if (asc->quirks & APPLE_ISO_KEYBOARD) {
239 trans = apple_find_translation(apple_iso_keyboard, usage->code);
240 if (trans) {
241 input_event(input, usage->type, trans->to, value);
242 return 1;
243 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200244 }
245 }
246
247 return 0;
248}
249
250static int apple_event(struct hid_device *hdev, struct hid_field *field,
251 struct hid_usage *usage, __s32 value)
252{
253 struct apple_sc *asc = hid_get_drvdata(hdev);
254
255 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
256 !usage->type)
257 return 0;
258
259 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
260 usage->code == REL_HWHEEL) {
261 input_event(field->hidinput->input, usage->type, usage->code,
262 -value);
263 return 1;
264 }
265
266 if ((asc->quirks & APPLE_HAS_FN) &&
267 hidinput_apple_event(hdev, field->hidinput->input,
268 usage, value))
269 return 1;
270
271
272 return 0;
273}
274
275/*
276 * MacBook JIS keyboard has wrong logical maximum
277 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400278static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
279 unsigned int *rsize)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200280{
281 struct apple_sc *asc = hid_get_drvdata(hdev);
282
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400283 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
Jiri Slaby8c19a512008-06-18 23:36:49 +0200284 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
Joe Perches4291ee32010-12-09 19:29:03 -0800285 hid_info(hdev,
286 "fixing up MacBook JIS keyboard report descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200287 rdesc[53] = rdesc[59] = 0xe7;
288 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400289 return rdesc;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200290}
291
292static void apple_setup_input(struct input_dev *input)
293{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300294 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200295
296 set_bit(KEY_NUMLOCK, input->keybit);
297
298 /* Enable all needed keys */
299 for (trans = apple_fn_keys; trans->from; trans++)
300 set_bit(trans->to, input->keybit);
301
302 for (trans = powerbook_fn_keys; trans->from; trans++)
303 set_bit(trans->to, input->keybit);
304
305 for (trans = powerbook_numlock_keys; trans->from; trans++)
306 set_bit(trans->to, input->keybit);
307
308 for (trans = apple_iso_keyboard; trans->from; trans++)
309 set_bit(trans->to, input->keybit);
310}
311
312static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
313 struct hid_field *field, struct hid_usage *usage,
314 unsigned long **bit, int *max)
315{
316 if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
317 /* The fn key on Apple USB keyboards */
318 set_bit(EV_REP, hi->input->evbit);
319 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
320 apple_setup_input(hi->input);
321 return 1;
322 }
323
324 /* we want the hid layer to go through standard path (set and ignore) */
325 return 0;
326}
327
328static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
329 struct hid_field *field, struct hid_usage *usage,
330 unsigned long **bit, int *max)
331{
332 struct apple_sc *asc = hid_get_drvdata(hdev);
333
334 if (asc->quirks & APPLE_MIGHTYMOUSE) {
335 if (usage->hid == HID_GD_Z)
336 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
337 else if (usage->code == BTN_1)
338 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
339 else if (usage->code == BTN_2)
340 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
341 }
342
343 return 0;
344}
345
346static int apple_probe(struct hid_device *hdev,
347 const struct hid_device_id *id)
348{
349 unsigned long quirks = id->driver_data;
350 struct apple_sc *asc;
Jiri Slaby93c10132008-06-27 00:04:24 +0200351 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200352 int ret;
353
Jiri Slaby8c19a512008-06-18 23:36:49 +0200354 asc = kzalloc(sizeof(*asc), GFP_KERNEL);
355 if (asc == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800356 hid_err(hdev, "can't alloc apple descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200357 return -ENOMEM;
358 }
359
360 asc->quirks = quirks;
361
362 hid_set_drvdata(hdev, asc);
363
Jiri Slaby8c19a512008-06-18 23:36:49 +0200364 ret = hid_parse(hdev);
365 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800366 hid_err(hdev, "parse failed\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200367 goto err_free;
368 }
369
Jiri Slaby93c10132008-06-27 00:04:24 +0200370 if (quirks & APPLE_HIDDEV)
371 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
372 if (quirks & APPLE_IGNORE_HIDINPUT)
373 connect_mask &= ~HID_CONNECT_HIDINPUT;
374
375 ret = hid_hw_start(hdev, connect_mask);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200376 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800377 hid_err(hdev, "hw start failed\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200378 goto err_free;
379 }
380
381 return 0;
382err_free:
383 kfree(asc);
384 return ret;
385}
386
387static void apple_remove(struct hid_device *hdev)
388{
389 hid_hw_stop(hdev);
390 kfree(hid_get_drvdata(hdev));
391}
392
393static const struct hid_device_id apple_devices[] = {
Peter Korsgaard0f492f22008-10-06 11:15:34 +0200394 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL),
395 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200396 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4),
397 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
398 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
399 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
400
401 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200402 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200403 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200404 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200405 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200406 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200407 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
408 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200409 APPLE_ISO_KEYBOARD },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200410 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200411 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200412 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200413 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200414 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
415 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200416 APPLE_ISO_KEYBOARD },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200417 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
418 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200419 APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200420 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200421 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200422 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
423 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200424 APPLE_ISO_KEYBOARD },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200425 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
426 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200427 APPLE_RDESC_JIS },
Ryan Finniefef3f572009-03-05 10:18:01 +0100428 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
429 .driver_data = APPLE_HAS_FN },
430 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
431 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
432 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
433 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200434 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
435 .driver_data = APPLE_HAS_FN },
436 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
437 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
438 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
439 .driver_data = APPLE_HAS_FN },
440 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200441 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200442 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200443 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200444 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
445 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200446 APPLE_RDESC_JIS },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400447 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
448 .driver_data = APPLE_HAS_FN },
449 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
450 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
451 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
452 .driver_data = APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100453 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200454 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100455 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200456 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
457 APPLE_ISO_KEYBOARD },
Andreas Kristad734bc2011-10-28 18:50:39 +0200458 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
459 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
460 APPLE_ISO_KEYBOARD },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100461 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200462 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
463 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200464 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200465 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200466 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200467 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200468 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200469 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200470 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200471 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200472 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200473 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200474 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100475 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
476 .driver_data = APPLE_HAS_FN },
477 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
478 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
479 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
480 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400481 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
482 .driver_data = APPLE_HAS_FN },
483 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
484 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
485 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
486 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
487 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
488 .driver_data = APPLE_HAS_FN },
489 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
490 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
491 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
492 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Andy Botting47340bd2011-03-12 20:27:22 -0800493 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
494 .driver_data = APPLE_HAS_FN },
495 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
496 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
497 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
498 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700499 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
500 .driver_data = APPLE_HAS_FN },
501 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
502 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
503 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
504 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900505 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
506 .driver_data = APPLE_HAS_FN },
507 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
508 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
509 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
510 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300511 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
512 .driver_data = APPLE_HAS_FN },
513 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
514 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
515 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
516 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700517 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
518 .driver_data = APPLE_HAS_FN },
519 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
520 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
521 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
522 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100523 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
524 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
525 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
526 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
527 APPLE_ISO_KEYBOARD },
528 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
529 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200530 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200531 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200532 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200533 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200534
Jiri Slaby8c19a512008-06-18 23:36:49 +0200535 { }
536};
537MODULE_DEVICE_TABLE(hid, apple_devices);
538
539static struct hid_driver apple_driver = {
540 .name = "apple",
541 .id_table = apple_devices,
542 .report_fixup = apple_report_fixup,
543 .probe = apple_probe,
544 .remove = apple_remove,
545 .event = apple_event,
546 .input_mapping = apple_input_mapping,
547 .input_mapped = apple_input_mapped,
548};
549
Peter Huewea24f4232009-07-02 19:08:38 +0200550static int __init apple_init(void)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200551{
552 int ret;
553
554 ret = hid_register_driver(&apple_driver);
555 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800556 pr_err("can't register apple driver\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200557
558 return ret;
559}
560
Peter Huewea24f4232009-07-02 19:08:38 +0200561static void __exit apple_exit(void)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200562{
563 hid_unregister_driver(&apple_driver);
564}
565
566module_init(apple_init);
567module_exit(apple_exit);
568MODULE_LICENSE("GPL");