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