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