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