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