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