blob: b34aeed292a28b609d66559b86529674c94a671a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jiri Slaby8c19a512008-06-18 23:36:49 +02002/*
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
Jiri Slaby8c19a512008-06-18 23:36:49 +02009 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10 */
11
12/*
Jiri Slaby8c19a512008-06-18 23:36:49 +020013 */
14
Joe Perches4291ee32010-12-09 19:29:03 -080015#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
Jiri Slaby8c19a512008-06-18 23:36:49 +020017#include <linux/device.h>
18#include <linux/hid.h>
19#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Jiri Slaby8c19a512008-06-18 23:36:49 +020021
22#include "hid-ids.h"
23
José Expósito7f52ece2021-11-18 08:29:54 +010024#define APPLE_RDESC_JIS BIT(0)
25#define APPLE_IGNORE_MOUSE BIT(1)
26#define APPLE_HAS_FN BIT(2)
27/* BIT(3) reserved, was: APPLE_HIDDEV */
28#define APPLE_ISO_TILDE_QUIRK BIT(4)
29#define APPLE_MIGHTYMOUSE BIT(5)
30#define APPLE_INVERT_HWHEEL BIT(6)
31/* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
32#define APPLE_NUMLOCK_EMULATION BIT(8)
Jiri Slaby8c19a512008-06-18 23:36:49 +020033
34#define APPLE_FLAG_FKEY 0x01
35
Alex Henriebd77a0f2017-06-02 09:28:39 -060036#define HID_COUNTRY_INTERNATIONAL_ISO 13
37
Jiri Slaby8c19a512008-06-18 23:36:49 +020038static unsigned int fnmode = 1;
39module_param(fnmode, uint, 0644);
40MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
41 "[1] = fkeyslast, 2 = fkeysfirst)");
42
Alex Henried58cf342021-10-19 01:12:32 -060043static int iso_layout = -1;
44module_param(iso_layout, int, 0644);
45MODULE_PARM_DESC(iso_layout, "Swap the backtick/tilde and greater-than/less-than keys. "
46 "([-1] = auto, 0 = disabled, 1 = enabled)");
Stefan Glasenhardt54a65932010-01-05 23:30:30 +010047
Jiri Kosinaa94c79b2013-10-14 16:07:42 +020048static unsigned int swap_opt_cmd;
Nanno Langstraat43c83142013-10-14 16:07:15 +020049module_param(swap_opt_cmd, uint, 0644);
50MODULE_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
free5lot346338e2020-05-15 13:14:00 +070054static unsigned int swap_fn_leftctrl;
55module_param(swap_fn_leftctrl, uint, 0644);
56MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
57 "(For people who want to keep PC keyboard muscle memory. "
58 "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
59
Jiri Slaby8c19a512008-06-18 23:36:49 +020060struct apple_sc {
61 unsigned long quirks;
62 unsigned int fn_on;
Hans de Goedea5d81642020-06-20 14:32:29 +020063 unsigned int fn_found;
Jiri Slaby8c19a512008-06-18 23:36:49 +020064 DECLARE_BITMAP(pressed_numlock, KEY_CNT);
65};
66
67struct apple_key_translation {
68 u16 from;
69 u16 to;
70 u8 flags;
71};
72
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -040073static const struct apple_key_translation macbookair_fn_keys[] = {
74 { KEY_BACKSPACE, KEY_DELETE },
75 { KEY_ENTER, KEY_INSERT },
76 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
77 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
78 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
79 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
80 { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
81 { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
82 { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY },
83 { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY },
84 { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
85 { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
86 { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY },
87 { KEY_UP, KEY_PAGEUP },
88 { KEY_DOWN, KEY_PAGEDOWN },
89 { KEY_LEFT, KEY_HOME },
90 { KEY_RIGHT, KEY_END },
91 { }
92};
93
Paul Collinsb2ddd542009-03-07 17:07:15 +130094static const struct apple_key_translation apple_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +020095 { KEY_BACKSPACE, KEY_DELETE },
Henrik Rydberg437184a2008-11-04 13:31:38 +010096 { KEY_ENTER, KEY_INSERT },
Jiri Slaby8c19a512008-06-18 23:36:49 +020097 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
98 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
Henrik Rydberg437184a2008-11-04 13:31:38 +010099 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
100 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200101 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
102 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
103 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
104 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
105 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
106 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
107 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
108 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
109 { KEY_UP, KEY_PAGEUP },
110 { KEY_DOWN, KEY_PAGEDOWN },
111 { KEY_LEFT, KEY_HOME },
112 { KEY_RIGHT, KEY_END },
113 { }
114};
115
Paul Collinsb2ddd542009-03-07 17:07:15 +1300116static const struct apple_key_translation powerbook_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200117 { KEY_BACKSPACE, KEY_DELETE },
118 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
119 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
120 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
121 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
122 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
123 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
124 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
125 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
126 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
127 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
128 { KEY_UP, KEY_PAGEUP },
129 { KEY_DOWN, KEY_PAGEDOWN },
130 { KEY_LEFT, KEY_HOME },
131 { KEY_RIGHT, KEY_END },
132 { }
133};
134
Paul Collinsb2ddd542009-03-07 17:07:15 +1300135static const struct apple_key_translation powerbook_numlock_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200136 { KEY_J, KEY_KP1 },
137 { KEY_K, KEY_KP2 },
138 { KEY_L, KEY_KP3 },
139 { KEY_U, KEY_KP4 },
140 { KEY_I, KEY_KP5 },
141 { KEY_O, KEY_KP6 },
142 { KEY_7, KEY_KP7 },
143 { KEY_8, KEY_KP8 },
144 { KEY_9, KEY_KP9 },
145 { KEY_M, KEY_KP0 },
146 { KEY_DOT, KEY_KPDOT },
147 { KEY_SLASH, KEY_KPPLUS },
148 { KEY_SEMICOLON, KEY_KPMINUS },
149 { KEY_P, KEY_KPASTERISK },
150 { KEY_MINUS, KEY_KPEQUAL },
151 { KEY_0, KEY_KPSLASH },
152 { KEY_F6, KEY_NUMLOCK },
153 { KEY_KPENTER, KEY_KPENTER },
154 { KEY_BACKSPACE, KEY_BACKSPACE },
155 { }
156};
157
Paul Collinsb2ddd542009-03-07 17:07:15 +1300158static const struct apple_key_translation apple_iso_keyboard[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200159 { KEY_GRAVE, KEY_102ND },
160 { KEY_102ND, KEY_GRAVE },
161 { }
162};
163
Nanno Langstraat43c83142013-10-14 16:07:15 +0200164static const struct apple_key_translation swapped_option_cmd_keys[] = {
165 { KEY_LEFTALT, KEY_LEFTMETA },
166 { KEY_LEFTMETA, KEY_LEFTALT },
167 { KEY_RIGHTALT, KEY_RIGHTMETA },
168 { KEY_RIGHTMETA,KEY_RIGHTALT },
169 { }
170};
171
free5lot346338e2020-05-15 13:14:00 +0700172static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
173 { KEY_FN, KEY_LEFTCTRL },
174 { }
175};
176
Paul Collinsb2ddd542009-03-07 17:07:15 +1300177static const struct apple_key_translation *apple_find_translation(
178 const struct apple_key_translation *table, u16 from)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200179{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300180 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200181
182 /* Look for the translation */
183 for (trans = table; trans->from; trans++)
184 if (trans->from == from)
185 return trans;
186
187 return NULL;
188}
189
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200190static void input_event_with_scancode(struct input_dev *input,
191 __u8 type, __u16 code, unsigned int hid, __s32 value)
192{
193 if (type == EV_KEY &&
194 (!test_bit(code, input->key)) == value)
195 input_event(input, EV_MSC, MSC_SCAN, hid);
196 input_event(input, type, code, value);
197}
198
Jiri Slaby8c19a512008-06-18 23:36:49 +0200199static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
200 struct hid_usage *usage, __s32 value)
201{
202 struct apple_sc *asc = hid_get_drvdata(hid);
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400203 const struct apple_key_translation *trans, *table;
Joao Morenoaec256d2019-09-03 16:46:32 +0200204 bool do_translate;
205 u16 code = 0;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200206
free5lot346338e2020-05-15 13:14:00 +0700207 u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
208
209 if (usage->code == fn_keycode) {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200210 asc->fn_on = !!value;
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200211 input_event_with_scancode(input, usage->type, KEY_FN,
212 usage->hid, value);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200213 return 1;
214 }
215
216 if (fnmode) {
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400217 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
218 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
219 table = macbookair_fn_keys;
220 else if (hid->product < 0x21d || hid->product >= 0x300)
221 table = powerbook_fn_keys;
222 else
223 table = apple_fn_keys;
224
225 trans = apple_find_translation (table, usage->code);
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400226
Jiri Slaby8c19a512008-06-18 23:36:49 +0200227 if (trans) {
Joao Morenoaec256d2019-09-03 16:46:32 +0200228 if (test_bit(trans->from, input->key))
229 code = trans->from;
230 else if (test_bit(trans->to, input->key))
231 code = trans->to;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200232
Joao Morenoaec256d2019-09-03 16:46:32 +0200233 if (!code) {
234 if (trans->flags & APPLE_FLAG_FKEY) {
235 switch (fnmode) {
236 case 1:
237 do_translate = !asc->fn_on;
238 break;
239 case 2:
240 do_translate = asc->fn_on;
241 break;
242 default:
243 /* should never happen */
244 do_translate = false;
245 }
246 } else {
247 do_translate = asc->fn_on;
248 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200249
Joao Morenoaec256d2019-09-03 16:46:32 +0200250 code = do_translate ? trans->to : trans->from;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200251 }
Joao Morenoaec256d2019-09-03 16:46:32 +0200252
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200253 input_event_with_scancode(input, usage->type, code,
254 usage->hid, value);
Joao Morenoaec256d2019-09-03 16:46:32 +0200255 return 1;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200256 }
257
258 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
259 (test_bit(usage->code, asc->pressed_numlock) ||
260 test_bit(LED_NUML, input->led))) {
261 trans = apple_find_translation(powerbook_numlock_keys,
262 usage->code);
263
264 if (trans) {
265 if (value)
266 set_bit(usage->code,
267 asc->pressed_numlock);
268 else
269 clear_bit(usage->code,
270 asc->pressed_numlock);
271
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200272 input_event_with_scancode(input, usage->type,
273 trans->to, usage->hid, value);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200274 }
275
276 return 1;
277 }
278 }
279
Alex Henried58cf342021-10-19 01:12:32 -0600280 if (iso_layout > 0 || (iso_layout < 0 && (asc->quirks & APPLE_ISO_TILDE_QUIRK) &&
281 hid->country == HID_COUNTRY_INTERNATIONAL_ISO)) {
282 trans = apple_find_translation(apple_iso_keyboard, usage->code);
283 if (trans) {
284 input_event_with_scancode(input, usage->type,
285 trans->to, usage->hid, value);
286 return 1;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200287 }
288 }
289
Nanno Langstraat43c83142013-10-14 16:07:15 +0200290 if (swap_opt_cmd) {
291 trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
292 if (trans) {
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200293 input_event_with_scancode(input, usage->type,
294 trans->to, usage->hid, value);
Nanno Langstraat43c83142013-10-14 16:07:15 +0200295 return 1;
296 }
297 }
298
free5lot346338e2020-05-15 13:14:00 +0700299 if (swap_fn_leftctrl) {
300 trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
301 if (trans) {
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200302 input_event_with_scancode(input, usage->type,
303 trans->to, usage->hid, value);
free5lot346338e2020-05-15 13:14:00 +0700304 return 1;
305 }
306 }
307
Jiri Slaby8c19a512008-06-18 23:36:49 +0200308 return 0;
309}
310
311static int apple_event(struct hid_device *hdev, struct hid_field *field,
312 struct hid_usage *usage, __s32 value)
313{
314 struct apple_sc *asc = hid_get_drvdata(hdev);
315
316 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
317 !usage->type)
318 return 0;
319
320 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
321 usage->code == REL_HWHEEL) {
Vincent Lefevre3b41fb42021-07-22 03:25:44 +0200322 input_event_with_scancode(field->hidinput->input, usage->type,
323 usage->code, usage->hid, -value);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200324 return 1;
325 }
326
327 if ((asc->quirks & APPLE_HAS_FN) &&
328 hidinput_apple_event(hdev, field->hidinput->input,
329 usage, value))
330 return 1;
331
332
333 return 0;
334}
335
336/*
337 * MacBook JIS keyboard has wrong logical maximum
Mizuho Mori67fd71b2021-07-29 20:03:25 +0900338 * Magic Keyboard JIS has wrong logical maximum
Jiri Slaby8c19a512008-06-18 23:36:49 +0200339 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400340static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
341 unsigned int *rsize)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200342{
343 struct apple_sc *asc = hid_get_drvdata(hdev);
344
Mizuho Mori67fd71b2021-07-29 20:03:25 +0900345 if(*rsize >=71 && rdesc[70] == 0x65 && rdesc[64] == 0x65) {
346 hid_info(hdev,
347 "fixing up Magic Keyboard JIS report descriptor\n");
348 rdesc[64] = rdesc[70] = 0xe7;
349 }
350
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400351 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
Jiri Slaby8c19a512008-06-18 23:36:49 +0200352 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
Joe Perches4291ee32010-12-09 19:29:03 -0800353 hid_info(hdev,
354 "fixing up MacBook JIS keyboard report descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200355 rdesc[53] = rdesc[59] = 0xe7;
356 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400357 return rdesc;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200358}
359
360static void apple_setup_input(struct input_dev *input)
361{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300362 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200363
364 set_bit(KEY_NUMLOCK, input->keybit);
365
366 /* Enable all needed keys */
367 for (trans = apple_fn_keys; trans->from; trans++)
368 set_bit(trans->to, input->keybit);
369
370 for (trans = powerbook_fn_keys; trans->from; trans++)
371 set_bit(trans->to, input->keybit);
372
373 for (trans = powerbook_numlock_keys; trans->from; trans++)
374 set_bit(trans->to, input->keybit);
375
376 for (trans = apple_iso_keyboard; trans->from; trans++)
377 set_bit(trans->to, input->keybit);
free5lot346338e2020-05-15 13:14:00 +0700378
379 if (swap_fn_leftctrl) {
380 for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
381 set_bit(trans->to, input->keybit);
382 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200383}
384
385static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
386 struct hid_field *field, struct hid_usage *usage,
387 unsigned long **bit, int *max)
388{
Hans de Goedea5d81642020-06-20 14:32:29 +0200389 struct apple_sc *asc = hid_get_drvdata(hdev);
390
Sean O'Brienee345492018-08-27 13:02:15 -0700391 if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
Mansour Behabadie433be92020-01-29 17:26:31 +1100392 usage->hid == (HID_UP_MSVENDOR | 0x0003) ||
393 usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200394 /* The fn key on Apple USB keyboards */
395 set_bit(EV_REP, hi->input->evbit);
396 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
Hans de Goedea5d81642020-06-20 14:32:29 +0200397 asc->fn_found = true;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200398 apple_setup_input(hi->input);
399 return 1;
400 }
401
402 /* we want the hid layer to go through standard path (set and ignore) */
403 return 0;
404}
405
406static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
407 struct hid_field *field, struct hid_usage *usage,
408 unsigned long **bit, int *max)
409{
410 struct apple_sc *asc = hid_get_drvdata(hdev);
411
412 if (asc->quirks & APPLE_MIGHTYMOUSE) {
413 if (usage->hid == HID_GD_Z)
414 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
415 else if (usage->code == BTN_1)
416 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
417 else if (usage->code == BTN_2)
418 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
419 }
420
421 return 0;
422}
423
Hans de Goedea5d81642020-06-20 14:32:29 +0200424static int apple_input_configured(struct hid_device *hdev,
425 struct hid_input *hidinput)
426{
427 struct apple_sc *asc = hid_get_drvdata(hdev);
428
429 if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
430 hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
José Expósitoa5fe7862021-11-18 08:29:53 +0100431 asc->quirks &= ~APPLE_HAS_FN;
Hans de Goedea5d81642020-06-20 14:32:29 +0200432 }
433
434 return 0;
435}
436
Jiri Slaby8c19a512008-06-18 23:36:49 +0200437static int apple_probe(struct hid_device *hdev,
438 const struct hid_device_id *id)
439{
440 unsigned long quirks = id->driver_data;
441 struct apple_sc *asc;
442 int ret;
443
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200444 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200445 if (asc == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800446 hid_err(hdev, "can't alloc apple descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200447 return -ENOMEM;
448 }
449
450 asc->quirks = quirks;
451
452 hid_set_drvdata(hdev, asc);
453
Jiri Slaby8c19a512008-06-18 23:36:49 +0200454 ret = hid_parse(hdev);
455 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800456 hid_err(hdev, "parse failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200457 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200458 }
459
Alexander F. Lentcc840942021-09-16 15:38:40 -0400460 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200461 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800462 hid_err(hdev, "hw start failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200463 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200464 }
465
466 return 0;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200467}
468
469static const struct hid_device_id apple_devices[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200470 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
471 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
472
473 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200474 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200475 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200476 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200477 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200478 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200479 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600480 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200481 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200482 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200483 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200484 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200485 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600486 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200487 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
488 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200489 APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200490 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200491 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200492 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600493 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200494 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
495 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200496 APPLE_RDESC_JIS },
Ryan Finniefef3f572009-03-05 10:18:01 +0100497 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
498 .driver_data = APPLE_HAS_FN },
499 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600500 .driver_data = APPLE_HAS_FN },
Ryan Finniefef3f572009-03-05 10:18:01 +0100501 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
502 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200503 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
504 .driver_data = APPLE_HAS_FN },
505 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600506 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200507 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
508 .driver_data = APPLE_HAS_FN },
509 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200510 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200511 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600512 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200513 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
514 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200515 APPLE_RDESC_JIS },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400516 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
517 .driver_data = APPLE_HAS_FN },
Haochen Tongebe0b42a2021-07-18 01:04:31 +0800518 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
519 .driver_data = APPLE_HAS_FN },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400520 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600521 .driver_data = APPLE_HAS_FN },
BALATON Zoltan4c945422020-07-20 22:53:46 +0200522 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
523 .driver_data = APPLE_HAS_FN },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400524 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
525 .driver_data = APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100526 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200527 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100528 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
Alex Henried58cf342021-10-19 01:12:32 -0600529 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
530 APPLE_ISO_TILDE_QUIRK },
Andreas Kristad734bc2011-10-28 18:50:39 +0200531 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
Alex Henried58cf342021-10-19 01:12:32 -0600532 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
533 APPLE_ISO_TILDE_QUIRK },
Alexey Kaminsky0a97e1e2012-04-23 18:02:18 +0200534 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
535 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
536 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Huei-Horng Yobd4a7ce2014-02-06 17:40:34 +0800537 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
538 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
539 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100540 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200541 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Alex Henrie371a9dc2021-10-08 01:37:00 -0600542 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
Alex Henried58cf342021-10-19 01:12:32 -0600543 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Alex Henrie371a9dc2021-10-08 01:37:00 -0600544 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
Alex Henried58cf342021-10-19 01:12:32 -0600545 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Alex Henrie371a9dc2021-10-08 01:37:00 -0600546 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
Alex Henried58cf342021-10-19 01:12:32 -0600547 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Alex Henrie371a9dc2021-10-08 01:37:00 -0600548 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
Alex Henried58cf342021-10-19 01:12:32 -0600549 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200550 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200551 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200552 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600553 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200554 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200555 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200556 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200557 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200558 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600559 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200560 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200561 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100562 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
563 .driver_data = APPLE_HAS_FN },
564 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600565 .driver_data = APPLE_HAS_FN },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100566 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
567 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400568 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
569 .driver_data = APPLE_HAS_FN },
570 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600571 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400572 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
573 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
574 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
575 .driver_data = APPLE_HAS_FN },
576 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600577 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400578 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
579 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Andy Botting47340bd2011-03-12 20:27:22 -0800580 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
581 .driver_data = APPLE_HAS_FN },
582 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600583 .driver_data = APPLE_HAS_FN },
Andy Botting47340bd2011-03-12 20:27:22 -0800584 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
585 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700586 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
587 .driver_data = APPLE_HAS_FN },
588 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600589 .driver_data = APPLE_HAS_FN },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700590 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
591 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900592 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
593 .driver_data = APPLE_HAS_FN },
594 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600595 .driver_data = APPLE_HAS_FN },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900596 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
597 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300598 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
599 .driver_data = APPLE_HAS_FN },
600 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600601 .driver_data = APPLE_HAS_FN },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300602 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
603 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700604 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
605 .driver_data = APPLE_HAS_FN },
606 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600607 .driver_data = APPLE_HAS_FN },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700608 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
609 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700610 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
611 .driver_data = APPLE_HAS_FN },
612 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600613 .driver_data = APPLE_HAS_FN },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700614 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
615 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700616 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
617 .driver_data = APPLE_HAS_FN },
618 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600619 .driver_data = APPLE_HAS_FN },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700620 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
621 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700622 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI),
623 .driver_data = APPLE_HAS_FN },
624 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600625 .driver_data = APPLE_HAS_FN },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700626 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
627 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100628 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
629 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
630 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
Alex Henried58cf342021-10-19 01:12:32 -0600631 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
632 APPLE_ISO_TILDE_QUIRK },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100633 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
634 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200635 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200636 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200637 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200638 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Alex Henrie0cd3be52021-10-08 01:37:01 -0600639 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
Alex Henried58cf342021-10-19 01:12:32 -0600640 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Alex Henrie0cd3be52021-10-08 01:37:01 -0600641 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
Alex Henried58cf342021-10-19 01:12:32 -0600642 .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200643
Jiri Slaby8c19a512008-06-18 23:36:49 +0200644 { }
645};
646MODULE_DEVICE_TABLE(hid, apple_devices);
647
648static struct hid_driver apple_driver = {
649 .name = "apple",
650 .id_table = apple_devices,
651 .report_fixup = apple_report_fixup,
652 .probe = apple_probe,
Jiri Slaby8c19a512008-06-18 23:36:49 +0200653 .event = apple_event,
654 .input_mapping = apple_input_mapping,
655 .input_mapped = apple_input_mapped,
Hans de Goedea5d81642020-06-20 14:32:29 +0200656 .input_configured = apple_input_configured,
Jiri Slaby8c19a512008-06-18 23:36:49 +0200657};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700658module_hid_driver(apple_driver);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200659
Jiri Slaby8c19a512008-06-18 23:36:49 +0200660MODULE_LICENSE("GPL");