1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * USB HID quirks support for Linux
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 * Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/device.h>
19 #include <linux/hid.h>
20 #include <linux/jiffies.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/timer.h>
24 #include <linux/string.h>
28 #define APPLE_RDESC_JIS BIT(0)
29 #define APPLE_IGNORE_MOUSE BIT(1)
30 #define APPLE_HAS_FN BIT(2)
31 /* BIT(3) reserved, was: APPLE_HIDDEV */
32 #define APPLE_ISO_TILDE_QUIRK BIT(4)
33 #define APPLE_MIGHTYMOUSE BIT(5)
34 #define APPLE_INVERT_HWHEEL BIT(6)
35 /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
36 #define APPLE_NUMLOCK_EMULATION BIT(8)
37 #define APPLE_RDESC_BATTERY BIT(9)
38 #define APPLE_BACKLIGHT_CTL BIT(10)
39 #define APPLE_IS_NON_APPLE BIT(11)
41 #define APPLE_FLAG_FKEY 0x01
43 #define HID_COUNTRY_INTERNATIONAL_ISO 13
44 #define APPLE_BATTERY_TIMEOUT_MS 60000
46 static unsigned int fnmode = 3;
47 module_param(fnmode, uint, 0644);
48 MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
49 "1 = fkeyslast, 2 = fkeysfirst, [3] = auto)");
51 static int iso_layout = -1;
52 module_param(iso_layout, int, 0644);
53 MODULE_PARM_DESC(iso_layout, "Swap the backtick/tilde and greater-than/less-than keys. "
54 "([-1] = auto, 0 = disabled, 1 = enabled)");
56 static unsigned int swap_opt_cmd;
57 module_param(swap_opt_cmd, uint, 0644);
58 MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
59 "(For people who want to keep Windows PC keyboard muscle memory. "
60 "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
62 static unsigned int swap_fn_leftctrl;
63 module_param(swap_fn_leftctrl, uint, 0644);
64 MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
65 "(For people who want to keep PC keyboard muscle memory. "
66 "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
68 struct apple_non_apple_keyboard {
72 struct apple_sc_backlight {
73 struct led_classdev cdev;
74 struct hid_device *hdev;
75 unsigned short backlight_off, backlight_on_min, backlight_on_max;
79 struct hid_device *hdev;
82 unsigned int fn_found;
83 DECLARE_BITMAP(pressed_numlock, KEY_CNT);
84 struct timer_list battery_timer;
85 struct apple_sc_backlight *backlight;
88 struct apple_key_translation {
94 static const struct apple_key_translation magic_keyboard_alu_fn_keys[] = {
95 { KEY_BACKSPACE, KEY_DELETE },
96 { KEY_ENTER, KEY_INSERT },
97 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
98 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
99 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
100 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
101 { KEY_F6, KEY_NUMLOCK, 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 },
115 static const struct apple_key_translation magic_keyboard_2015_fn_keys[] = {
116 { KEY_BACKSPACE, KEY_DELETE },
117 { KEY_ENTER, KEY_INSERT },
118 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
119 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
120 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
121 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
122 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
123 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
124 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
125 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
126 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
127 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
128 { KEY_UP, KEY_PAGEUP },
129 { KEY_DOWN, KEY_PAGEDOWN },
130 { KEY_LEFT, KEY_HOME },
131 { KEY_RIGHT, KEY_END },
135 struct apple_backlight_config_report {
138 u16 backlight_off, backlight_on_min, backlight_on_max;
141 struct apple_backlight_set_report {
149 static const struct apple_key_translation apple2021_fn_keys[] = {
150 { KEY_BACKSPACE, KEY_DELETE },
151 { KEY_ENTER, KEY_INSERT },
152 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
153 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
154 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
155 { KEY_F4, KEY_SEARCH, APPLE_FLAG_FKEY },
156 { KEY_F5, KEY_MICMUTE, APPLE_FLAG_FKEY },
157 { KEY_F6, KEY_SLEEP, APPLE_FLAG_FKEY },
158 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
159 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
160 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
161 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
162 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
163 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
164 { KEY_UP, KEY_PAGEUP },
165 { KEY_DOWN, KEY_PAGEDOWN },
166 { KEY_LEFT, KEY_HOME },
167 { KEY_RIGHT, KEY_END },
171 static const struct apple_key_translation macbookair_fn_keys[] = {
172 { KEY_BACKSPACE, KEY_DELETE },
173 { KEY_ENTER, KEY_INSERT },
174 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
175 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
176 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
177 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
178 { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
179 { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
180 { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY },
181 { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY },
182 { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
183 { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
184 { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY },
185 { KEY_UP, KEY_PAGEUP },
186 { KEY_DOWN, KEY_PAGEDOWN },
187 { KEY_LEFT, KEY_HOME },
188 { KEY_RIGHT, KEY_END },
192 static const struct apple_key_translation macbookpro_no_esc_fn_keys[] = {
193 { KEY_BACKSPACE, KEY_DELETE },
194 { KEY_ENTER, KEY_INSERT },
195 { KEY_GRAVE, KEY_ESC },
206 { KEY_MINUS, KEY_F11 },
207 { KEY_EQUAL, KEY_F12 },
208 { KEY_UP, KEY_PAGEUP },
209 { KEY_DOWN, KEY_PAGEDOWN },
210 { KEY_LEFT, KEY_HOME },
211 { KEY_RIGHT, KEY_END },
215 static const struct apple_key_translation macbookpro_dedicated_esc_fn_keys[] = {
216 { KEY_BACKSPACE, KEY_DELETE },
217 { KEY_ENTER, KEY_INSERT },
228 { KEY_MINUS, KEY_F11 },
229 { KEY_EQUAL, KEY_F12 },
230 { KEY_UP, KEY_PAGEUP },
231 { KEY_DOWN, KEY_PAGEDOWN },
232 { KEY_LEFT, KEY_HOME },
233 { KEY_RIGHT, KEY_END },
237 static const struct apple_key_translation apple_fn_keys[] = {
238 { KEY_BACKSPACE, KEY_DELETE },
239 { KEY_ENTER, KEY_INSERT },
240 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
241 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
242 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
243 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
244 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
245 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
246 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
247 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
248 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
249 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
250 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
251 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
252 { KEY_UP, KEY_PAGEUP },
253 { KEY_DOWN, KEY_PAGEDOWN },
254 { KEY_LEFT, KEY_HOME },
255 { KEY_RIGHT, KEY_END },
259 static const struct apple_key_translation powerbook_fn_keys[] = {
260 { KEY_BACKSPACE, KEY_DELETE },
261 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
262 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
263 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
264 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
265 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
266 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
267 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
268 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
269 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
270 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
271 { KEY_UP, KEY_PAGEUP },
272 { KEY_DOWN, KEY_PAGEDOWN },
273 { KEY_LEFT, KEY_HOME },
274 { KEY_RIGHT, KEY_END },
278 static const struct apple_key_translation powerbook_numlock_keys[] = {
289 { KEY_DOT, KEY_KPDOT },
290 { KEY_SLASH, KEY_KPPLUS },
291 { KEY_SEMICOLON, KEY_KPMINUS },
292 { KEY_P, KEY_KPASTERISK },
293 { KEY_MINUS, KEY_KPEQUAL },
294 { KEY_0, KEY_KPSLASH },
295 { KEY_F6, KEY_NUMLOCK },
296 { KEY_KPENTER, KEY_KPENTER },
297 { KEY_BACKSPACE, KEY_BACKSPACE },
301 static const struct apple_key_translation apple_iso_keyboard[] = {
302 { KEY_GRAVE, KEY_102ND },
303 { KEY_102ND, KEY_GRAVE },
307 static const struct apple_key_translation swapped_option_cmd_keys[] = {
308 { KEY_LEFTALT, KEY_LEFTMETA },
309 { KEY_LEFTMETA, KEY_LEFTALT },
310 { KEY_RIGHTALT, KEY_RIGHTMETA },
311 { KEY_RIGHTMETA,KEY_RIGHTALT },
315 static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
316 { KEY_FN, KEY_LEFTCTRL },
320 static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
321 { "SONiX USB DEVICE" },
327 static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
331 for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
332 char *non_apple = non_apple_keyboards[i].name;
334 if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
341 static inline void apple_setup_key_translation(struct input_dev *input,
342 const struct apple_key_translation *table)
344 const struct apple_key_translation *trans;
346 for (trans = table; trans->from; trans++)
347 set_bit(trans->to, input->keybit);
350 static const struct apple_key_translation *apple_find_translation(
351 const struct apple_key_translation *table, u16 from)
353 const struct apple_key_translation *trans;
355 /* Look for the translation */
356 for (trans = table; trans->from; trans++)
357 if (trans->from == from)
363 static void input_event_with_scancode(struct input_dev *input,
364 __u8 type, __u16 code, unsigned int hid, __s32 value)
366 if (type == EV_KEY &&
367 (!test_bit(code, input->key)) == value)
368 input_event(input, EV_MSC, MSC_SCAN, hid);
369 input_event(input, type, code, value);
372 static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
373 struct hid_usage *usage, __s32 value)
375 struct apple_sc *asc = hid_get_drvdata(hid);
376 const struct apple_key_translation *trans, *table;
379 unsigned int real_fnmode;
381 u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
383 if (usage->code == fn_keycode) {
384 asc->fn_on = !!value;
385 input_event_with_scancode(input, usage->type, KEY_FN,
391 real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
393 real_fnmode = fnmode;
397 if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
398 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
399 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
400 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ||
401 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ||
402 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ||
403 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ||
404 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ||
405 hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS)
406 table = magic_keyboard_alu_fn_keys;
407 else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ||
408 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015)
409 table = magic_keyboard_2015_fn_keys;
410 else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
411 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
412 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
413 table = apple2021_fn_keys;
414 else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
415 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
416 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
417 table = macbookpro_no_esc_fn_keys;
418 else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
419 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
420 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
421 table = macbookpro_dedicated_esc_fn_keys;
422 else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
423 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
424 table = apple_fn_keys;
425 else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
426 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
427 table = macbookair_fn_keys;
428 else if (hid->product < 0x21d || hid->product >= 0x300)
429 table = powerbook_fn_keys;
431 table = apple_fn_keys;
433 trans = apple_find_translation (table, usage->code);
436 if (test_bit(trans->from, input->key))
438 else if (test_bit(trans->to, input->key))
442 if (trans->flags & APPLE_FLAG_FKEY) {
443 switch (real_fnmode) {
445 do_translate = !asc->fn_on;
448 do_translate = asc->fn_on;
451 /* should never happen */
452 do_translate = false;
455 do_translate = asc->fn_on;
458 code = do_translate ? trans->to : trans->from;
461 input_event_with_scancode(input, usage->type, code,
466 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
467 (test_bit(usage->code, asc->pressed_numlock) ||
468 test_bit(LED_NUML, input->led))) {
469 trans = apple_find_translation(powerbook_numlock_keys,
475 asc->pressed_numlock);
477 clear_bit(usage->code,
478 asc->pressed_numlock);
480 input_event_with_scancode(input, usage->type,
481 trans->to, usage->hid, value);
488 if (iso_layout > 0 || (iso_layout < 0 && (asc->quirks & APPLE_ISO_TILDE_QUIRK) &&
489 hid->country == HID_COUNTRY_INTERNATIONAL_ISO)) {
490 trans = apple_find_translation(apple_iso_keyboard, usage->code);
492 input_event_with_scancode(input, usage->type,
493 trans->to, usage->hid, value);
499 trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
501 input_event_with_scancode(input, usage->type,
502 trans->to, usage->hid, value);
507 if (swap_fn_leftctrl) {
508 trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
510 input_event_with_scancode(input, usage->type,
511 trans->to, usage->hid, value);
519 static int apple_event(struct hid_device *hdev, struct hid_field *field,
520 struct hid_usage *usage, __s32 value)
522 struct apple_sc *asc = hid_get_drvdata(hdev);
524 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
528 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
529 usage->code == REL_HWHEEL) {
530 input_event_with_scancode(field->hidinput->input, usage->type,
531 usage->code, usage->hid, -value);
535 if ((asc->quirks & APPLE_HAS_FN) &&
536 hidinput_apple_event(hdev, field->hidinput->input,
544 static int apple_fetch_battery(struct hid_device *hdev)
546 #ifdef CONFIG_HID_BATTERY_STRENGTH
547 struct apple_sc *asc = hid_get_drvdata(hdev);
548 struct hid_report_enum *report_enum;
549 struct hid_report *report;
551 if (!(asc->quirks & APPLE_RDESC_BATTERY) || !hdev->battery)
554 report_enum = &hdev->report_enum[hdev->battery_report_type];
555 report = report_enum->report_id_hash[hdev->battery_report_id];
557 if (!report || report->maxfield < 1)
560 if (hdev->battery_capacity == hdev->battery_max)
563 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
570 static void apple_battery_timer_tick(struct timer_list *t)
572 struct apple_sc *asc = from_timer(asc, t, battery_timer);
573 struct hid_device *hdev = asc->hdev;
575 if (apple_fetch_battery(hdev) == 0) {
576 mod_timer(&asc->battery_timer,
577 jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
582 * MacBook JIS keyboard has wrong logical maximum
583 * Magic Keyboard JIS has wrong logical maximum
585 static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
588 struct apple_sc *asc = hid_get_drvdata(hdev);
590 if(*rsize >=71 && rdesc[70] == 0x65 && rdesc[64] == 0x65) {
592 "fixing up Magic Keyboard JIS report descriptor\n");
593 rdesc[64] = rdesc[70] = 0xe7;
596 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
597 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
599 "fixing up MacBook JIS keyboard report descriptor\n");
600 rdesc[53] = rdesc[59] = 0xe7;
604 * Change the usage from:
605 * 0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1) 0
606 * 0x09, 0x0b, // Usage (Vendor Usage 0x0b) 3
608 * 0x05, 0x01, // Usage Page (Generic Desktop) 0
609 * 0x09, 0x06, // Usage (Keyboard) 2
611 if ((asc->quirks & APPLE_RDESC_BATTERY) && *rsize == 83 &&
612 rdesc[46] == 0x84 && rdesc[58] == 0x85) {
614 "fixing up Magic Keyboard battery report descriptor\n");
616 rdesc = kmemdup(rdesc + 1, *rsize, GFP_KERNEL);
629 static void apple_setup_input(struct input_dev *input)
631 set_bit(KEY_NUMLOCK, input->keybit);
633 /* Enable all needed keys */
634 apple_setup_key_translation(input, apple_fn_keys);
635 apple_setup_key_translation(input, powerbook_fn_keys);
636 apple_setup_key_translation(input, powerbook_numlock_keys);
637 apple_setup_key_translation(input, apple_iso_keyboard);
638 apple_setup_key_translation(input, magic_keyboard_alu_fn_keys);
639 apple_setup_key_translation(input, magic_keyboard_2015_fn_keys);
640 apple_setup_key_translation(input, apple2021_fn_keys);
641 apple_setup_key_translation(input, macbookpro_no_esc_fn_keys);
642 apple_setup_key_translation(input, macbookpro_dedicated_esc_fn_keys);
644 if (swap_fn_leftctrl)
645 apple_setup_key_translation(input, swapped_fn_leftctrl_keys);
648 static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
649 struct hid_field *field, struct hid_usage *usage,
650 unsigned long **bit, int *max)
652 struct apple_sc *asc = hid_get_drvdata(hdev);
654 if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
655 usage->hid == (HID_UP_MSVENDOR | 0x0003) ||
656 usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) {
657 /* The fn key on Apple USB keyboards */
658 set_bit(EV_REP, hi->input->evbit);
659 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
660 asc->fn_found = true;
661 apple_setup_input(hi->input);
665 /* we want the hid layer to go through standard path (set and ignore) */
669 static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
670 struct hid_field *field, struct hid_usage *usage,
671 unsigned long **bit, int *max)
673 struct apple_sc *asc = hid_get_drvdata(hdev);
675 if (asc->quirks & APPLE_MIGHTYMOUSE) {
676 if (usage->hid == HID_GD_Z)
677 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
678 else if (usage->code == BTN_1)
679 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
680 else if (usage->code == BTN_2)
681 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
687 static int apple_input_configured(struct hid_device *hdev,
688 struct hid_input *hidinput)
690 struct apple_sc *asc = hid_get_drvdata(hdev);
692 if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
693 hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
694 asc->quirks &= ~APPLE_HAS_FN;
697 if (apple_is_non_apple_keyboard(hdev)) {
698 hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
699 asc->quirks |= APPLE_IS_NON_APPLE;
705 static bool apple_backlight_check_support(struct hid_device *hdev)
709 struct hid_report *report;
711 list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
712 for (i = 0; i < report->maxfield; i++) {
713 hid = report->field[i]->usage->hid;
714 if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
722 static int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
725 struct apple_backlight_set_report *rep;
727 rep = kmalloc(sizeof(*rep), GFP_KERNEL);
731 rep->report_id = 0xB0;
733 rep->backlight = value;
736 ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
737 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
743 static int apple_backlight_led_set(struct led_classdev *led_cdev,
744 enum led_brightness brightness)
746 struct apple_sc_backlight *backlight = container_of(led_cdev,
747 struct apple_sc_backlight, cdev);
749 return apple_backlight_set(backlight->hdev, brightness, 0);
752 static int apple_backlight_init(struct hid_device *hdev)
755 struct apple_sc *asc = hid_get_drvdata(hdev);
756 struct apple_backlight_config_report *rep;
758 if (!apple_backlight_check_support(hdev))
761 rep = kmalloc(0x200, GFP_KERNEL);
765 ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
766 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
768 hid_err(hdev, "backlight request failed: %d\n", ret);
769 goto cleanup_and_exit;
771 if (ret < 8 || rep->version != 1) {
772 hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
774 goto cleanup_and_exit;
777 hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
778 rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
780 asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
781 if (!asc->backlight) {
783 goto cleanup_and_exit;
786 asc->backlight->hdev = hdev;
787 asc->backlight->cdev.name = "apple::kbd_backlight";
788 asc->backlight->cdev.max_brightness = rep->backlight_on_max;
789 asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
791 ret = apple_backlight_set(hdev, 0, 0);
793 hid_err(hdev, "backlight set request failed: %d\n", ret);
794 goto cleanup_and_exit;
797 ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
804 static int apple_probe(struct hid_device *hdev,
805 const struct hid_device_id *id)
807 unsigned long quirks = id->driver_data;
808 struct apple_sc *asc;
811 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
813 hid_err(hdev, "can't alloc apple descriptor\n");
818 asc->quirks = quirks;
820 hid_set_drvdata(hdev, asc);
822 ret = hid_parse(hdev);
824 hid_err(hdev, "parse failed\n");
828 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
830 hid_err(hdev, "hw start failed\n");
834 timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
835 mod_timer(&asc->battery_timer,
836 jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
837 apple_fetch_battery(hdev);
839 if (quirks & APPLE_BACKLIGHT_CTL)
840 apple_backlight_init(hdev);
845 static void apple_remove(struct hid_device *hdev)
847 struct apple_sc *asc = hid_get_drvdata(hdev);
849 del_timer_sync(&asc->battery_timer);
854 static const struct hid_device_id apple_devices[] = {
855 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
856 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
858 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
859 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
860 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
861 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
862 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
863 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
864 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
865 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
866 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
867 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
868 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
869 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
870 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
871 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
872 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
873 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
875 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
876 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
877 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
878 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
879 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
880 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
882 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
883 .driver_data = APPLE_HAS_FN },
884 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
885 .driver_data = APPLE_HAS_FN },
886 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
887 .driver_data = APPLE_HAS_FN },
888 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
889 .driver_data = APPLE_HAS_FN },
890 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
891 .driver_data = APPLE_HAS_FN },
892 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
893 .driver_data = APPLE_HAS_FN },
894 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
895 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
896 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
897 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
898 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
899 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
901 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
902 .driver_data = APPLE_HAS_FN },
903 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
904 .driver_data = APPLE_HAS_FN },
905 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
906 .driver_data = APPLE_HAS_FN },
907 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
908 .driver_data = APPLE_HAS_FN },
909 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
910 .driver_data = APPLE_HAS_FN },
911 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
912 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
913 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
914 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
915 APPLE_ISO_TILDE_QUIRK },
916 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
917 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
918 APPLE_ISO_TILDE_QUIRK },
919 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
920 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
921 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
922 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
923 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
924 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
925 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
926 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
927 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
928 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
929 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
930 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
931 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
932 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
933 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
934 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
935 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
936 .driver_data = APPLE_HAS_FN },
937 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
938 .driver_data = APPLE_HAS_FN },
939 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
940 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
941 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
942 .driver_data = APPLE_HAS_FN },
943 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
944 .driver_data = APPLE_HAS_FN },
945 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
946 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
947 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
948 .driver_data = APPLE_HAS_FN },
949 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
950 .driver_data = APPLE_HAS_FN },
951 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
952 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
953 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
954 .driver_data = APPLE_HAS_FN },
955 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
956 .driver_data = APPLE_HAS_FN },
957 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
958 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
959 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
960 .driver_data = APPLE_HAS_FN },
961 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
962 .driver_data = APPLE_HAS_FN },
963 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
964 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
965 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
966 .driver_data = APPLE_HAS_FN },
967 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
968 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
969 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
970 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
971 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
972 .driver_data = APPLE_HAS_FN },
973 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
974 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
975 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
976 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
977 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
978 .driver_data = APPLE_HAS_FN },
979 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
980 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
981 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
982 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
983 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
984 .driver_data = APPLE_HAS_FN },
985 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
986 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
987 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
988 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
989 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
990 .driver_data = APPLE_HAS_FN },
991 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
992 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
993 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
994 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
995 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
996 .driver_data = APPLE_HAS_FN },
997 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
998 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
999 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
1000 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
1001 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
1002 .driver_data = APPLE_HAS_FN },
1003 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
1004 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1005 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
1006 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
1007 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI),
1008 .driver_data = APPLE_HAS_FN },
1009 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO),
1010 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1011 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
1012 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
1013 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K),
1014 .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1015 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132),
1016 .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1017 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680),
1018 .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1019 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213),
1020 .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1021 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K),
1022 .driver_data = APPLE_HAS_FN },
1023 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223),
1024 .driver_data = APPLE_HAS_FN },
1025 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K),
1026 .driver_data = APPLE_HAS_FN },
1027 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F),
1028 .driver_data = APPLE_HAS_FN },
1029 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
1030 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
1031 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
1032 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
1033 APPLE_ISO_TILDE_QUIRK },
1034 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
1035 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
1036 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
1037 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
1038 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
1039 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
1040 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
1041 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
1042 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
1043 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1044 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
1045 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
1046 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
1047 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1048 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
1049 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
1050 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
1051 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1055 MODULE_DEVICE_TABLE(hid, apple_devices);
1057 static struct hid_driver apple_driver = {
1059 .id_table = apple_devices,
1060 .report_fixup = apple_report_fixup,
1061 .probe = apple_probe,
1062 .remove = apple_remove,
1063 .event = apple_event,
1064 .input_mapping = apple_input_mapping,
1065 .input_mapped = apple_input_mapped,
1066 .input_configured = apple_input_configured,
1068 module_hid_driver(apple_driver);
1070 MODULE_LICENSE("GPL");