blob: d732d1d10cafb7bbafbf27ec59ff17bd5aae2c94 [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
24#define APPLE_RDESC_JIS 0x0001
25#define APPLE_IGNORE_MOUSE 0x0002
26#define APPLE_HAS_FN 0x0004
27#define APPLE_HIDDEV 0x0008
Alex Henriebd77a0f2017-06-02 09:28:39 -060028/* 0x0010 reserved, was: APPLE_ISO_KEYBOARD */
Jiri Slaby8c19a512008-06-18 23:36:49 +020029#define APPLE_MIGHTYMOUSE 0x0020
30#define APPLE_INVERT_HWHEEL 0x0040
31#define APPLE_IGNORE_HIDINPUT 0x0080
32#define APPLE_NUMLOCK_EMULATION 0x0100
33
34#define APPLE_FLAG_FKEY 0x01
35
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
Stefan Glasenhardt54a65932010-01-05 23:30:30 +010043static unsigned int iso_layout = 1;
44module_param(iso_layout, uint, 0644);
45MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
46 "(0 = disabled, [1] = enabled)");
47
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
Jiri Slaby8c19a512008-06-18 23:36:49 +020054struct apple_sc {
55 unsigned long quirks;
56 unsigned int fn_on;
Jiri Slaby8c19a512008-06-18 23:36:49 +020057 DECLARE_BITMAP(pressed_numlock, KEY_CNT);
58};
59
60struct apple_key_translation {
61 u16 from;
62 u16 to;
63 u8 flags;
64};
65
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -040066static const struct apple_key_translation macbookair_fn_keys[] = {
67 { KEY_BACKSPACE, KEY_DELETE },
68 { KEY_ENTER, KEY_INSERT },
69 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
70 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
71 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
72 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
73 { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
74 { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
75 { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY },
76 { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY },
77 { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
78 { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
79 { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY },
80 { KEY_UP, KEY_PAGEUP },
81 { KEY_DOWN, KEY_PAGEDOWN },
82 { KEY_LEFT, KEY_HOME },
83 { KEY_RIGHT, KEY_END },
84 { }
85};
86
Paul Collinsb2ddd542009-03-07 17:07:15 +130087static const struct apple_key_translation apple_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +020088 { KEY_BACKSPACE, KEY_DELETE },
Henrik Rydberg437184a2008-11-04 13:31:38 +010089 { KEY_ENTER, KEY_INSERT },
Jiri Slaby8c19a512008-06-18 23:36:49 +020090 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
91 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
Henrik Rydberg437184a2008-11-04 13:31:38 +010092 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
93 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
Jiri Slaby8c19a512008-06-18 23:36:49 +020094 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
95 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
96 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
97 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
98 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
99 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
100 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
101 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
102 { KEY_UP, KEY_PAGEUP },
103 { KEY_DOWN, KEY_PAGEDOWN },
104 { KEY_LEFT, KEY_HOME },
105 { KEY_RIGHT, KEY_END },
106 { }
107};
108
Paul Collinsb2ddd542009-03-07 17:07:15 +1300109static const struct apple_key_translation powerbook_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200110 { KEY_BACKSPACE, KEY_DELETE },
111 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
112 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
113 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
114 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
115 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
116 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
117 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
118 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
119 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
120 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
121 { KEY_UP, KEY_PAGEUP },
122 { KEY_DOWN, KEY_PAGEDOWN },
123 { KEY_LEFT, KEY_HOME },
124 { KEY_RIGHT, KEY_END },
125 { }
126};
127
Paul Collinsb2ddd542009-03-07 17:07:15 +1300128static const struct apple_key_translation powerbook_numlock_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200129 { KEY_J, KEY_KP1 },
130 { KEY_K, KEY_KP2 },
131 { KEY_L, KEY_KP3 },
132 { KEY_U, KEY_KP4 },
133 { KEY_I, KEY_KP5 },
134 { KEY_O, KEY_KP6 },
135 { KEY_7, KEY_KP7 },
136 { KEY_8, KEY_KP8 },
137 { KEY_9, KEY_KP9 },
138 { KEY_M, KEY_KP0 },
139 { KEY_DOT, KEY_KPDOT },
140 { KEY_SLASH, KEY_KPPLUS },
141 { KEY_SEMICOLON, KEY_KPMINUS },
142 { KEY_P, KEY_KPASTERISK },
143 { KEY_MINUS, KEY_KPEQUAL },
144 { KEY_0, KEY_KPSLASH },
145 { KEY_F6, KEY_NUMLOCK },
146 { KEY_KPENTER, KEY_KPENTER },
147 { KEY_BACKSPACE, KEY_BACKSPACE },
148 { }
149};
150
Paul Collinsb2ddd542009-03-07 17:07:15 +1300151static const struct apple_key_translation apple_iso_keyboard[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200152 { KEY_GRAVE, KEY_102ND },
153 { KEY_102ND, KEY_GRAVE },
154 { }
155};
156
Nanno Langstraat43c83142013-10-14 16:07:15 +0200157static const struct apple_key_translation swapped_option_cmd_keys[] = {
158 { KEY_LEFTALT, KEY_LEFTMETA },
159 { KEY_LEFTMETA, KEY_LEFTALT },
160 { KEY_RIGHTALT, KEY_RIGHTMETA },
161 { KEY_RIGHTMETA,KEY_RIGHTALT },
162 { }
163};
164
Paul Collinsb2ddd542009-03-07 17:07:15 +1300165static const struct apple_key_translation *apple_find_translation(
166 const struct apple_key_translation *table, u16 from)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200167{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300168 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200169
170 /* Look for the translation */
171 for (trans = table; trans->from; trans++)
172 if (trans->from == from)
173 return trans;
174
175 return NULL;
176}
177
178static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
179 struct hid_usage *usage, __s32 value)
180{
181 struct apple_sc *asc = hid_get_drvdata(hid);
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400182 const struct apple_key_translation *trans, *table;
Joao Morenoaec256d2019-09-03 16:46:32 +0200183 bool do_translate;
184 u16 code = 0;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200185
186 if (usage->code == KEY_FN) {
187 asc->fn_on = !!value;
188 input_event(input, usage->type, usage->code, value);
189 return 1;
190 }
191
192 if (fnmode) {
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400193 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
194 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
195 table = macbookair_fn_keys;
196 else if (hid->product < 0x21d || hid->product >= 0x300)
197 table = powerbook_fn_keys;
198 else
199 table = apple_fn_keys;
200
201 trans = apple_find_translation (table, usage->code);
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400202
Jiri Slaby8c19a512008-06-18 23:36:49 +0200203 if (trans) {
Joao Morenoaec256d2019-09-03 16:46:32 +0200204 if (test_bit(trans->from, input->key))
205 code = trans->from;
206 else if (test_bit(trans->to, input->key))
207 code = trans->to;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200208
Joao Morenoaec256d2019-09-03 16:46:32 +0200209 if (!code) {
210 if (trans->flags & APPLE_FLAG_FKEY) {
211 switch (fnmode) {
212 case 1:
213 do_translate = !asc->fn_on;
214 break;
215 case 2:
216 do_translate = asc->fn_on;
217 break;
218 default:
219 /* should never happen */
220 do_translate = false;
221 }
222 } else {
223 do_translate = asc->fn_on;
224 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200225
Joao Morenoaec256d2019-09-03 16:46:32 +0200226 code = do_translate ? trans->to : trans->from;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200227 }
Joao Morenoaec256d2019-09-03 16:46:32 +0200228
229 input_event(input, usage->type, code, value);
230 return 1;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200231 }
232
233 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
234 (test_bit(usage->code, asc->pressed_numlock) ||
235 test_bit(LED_NUML, input->led))) {
236 trans = apple_find_translation(powerbook_numlock_keys,
237 usage->code);
238
239 if (trans) {
240 if (value)
241 set_bit(usage->code,
242 asc->pressed_numlock);
243 else
244 clear_bit(usage->code,
245 asc->pressed_numlock);
246
247 input_event(input, usage->type, trans->to,
248 value);
249 }
250
251 return 1;
252 }
253 }
254
Benedikt Bergenthal9f1f4632012-04-18 12:22:40 +0200255 if (iso_layout) {
Alex Henriebd77a0f2017-06-02 09:28:39 -0600256 if (hid->country == HID_COUNTRY_INTERNATIONAL_ISO) {
Stefan Glasenhardt54a65932010-01-05 23:30:30 +0100257 trans = apple_find_translation(apple_iso_keyboard, usage->code);
258 if (trans) {
259 input_event(input, usage->type, trans->to, value);
260 return 1;
261 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200262 }
263 }
264
Nanno Langstraat43c83142013-10-14 16:07:15 +0200265 if (swap_opt_cmd) {
266 trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
267 if (trans) {
268 input_event(input, usage->type, trans->to, value);
269 return 1;
270 }
271 }
272
Jiri Slaby8c19a512008-06-18 23:36:49 +0200273 return 0;
274}
275
276static int apple_event(struct hid_device *hdev, struct hid_field *field,
277 struct hid_usage *usage, __s32 value)
278{
279 struct apple_sc *asc = hid_get_drvdata(hdev);
280
281 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
282 !usage->type)
283 return 0;
284
285 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
286 usage->code == REL_HWHEEL) {
287 input_event(field->hidinput->input, usage->type, usage->code,
288 -value);
289 return 1;
290 }
291
292 if ((asc->quirks & APPLE_HAS_FN) &&
293 hidinput_apple_event(hdev, field->hidinput->input,
294 usage, value))
295 return 1;
296
297
298 return 0;
299}
300
301/*
302 * MacBook JIS keyboard has wrong logical maximum
303 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400304static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
305 unsigned int *rsize)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200306{
307 struct apple_sc *asc = hid_get_drvdata(hdev);
308
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400309 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
Jiri Slaby8c19a512008-06-18 23:36:49 +0200310 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
Joe Perches4291ee32010-12-09 19:29:03 -0800311 hid_info(hdev,
312 "fixing up MacBook JIS keyboard report descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200313 rdesc[53] = rdesc[59] = 0xe7;
314 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400315 return rdesc;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200316}
317
318static void apple_setup_input(struct input_dev *input)
319{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300320 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200321
322 set_bit(KEY_NUMLOCK, input->keybit);
323
324 /* Enable all needed keys */
325 for (trans = apple_fn_keys; trans->from; trans++)
326 set_bit(trans->to, input->keybit);
327
328 for (trans = powerbook_fn_keys; trans->from; trans++)
329 set_bit(trans->to, input->keybit);
330
331 for (trans = powerbook_numlock_keys; trans->from; trans++)
332 set_bit(trans->to, input->keybit);
333
334 for (trans = apple_iso_keyboard; trans->from; trans++)
335 set_bit(trans->to, input->keybit);
336}
337
338static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
339 struct hid_field *field, struct hid_usage *usage,
340 unsigned long **bit, int *max)
341{
Sean O'Brienee345492018-08-27 13:02:15 -0700342 if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
Mansour Behabadie433be92020-01-29 17:26:31 +1100343 usage->hid == (HID_UP_MSVENDOR | 0x0003) ||
344 usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200345 /* The fn key on Apple USB keyboards */
346 set_bit(EV_REP, hi->input->evbit);
347 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
348 apple_setup_input(hi->input);
349 return 1;
350 }
351
352 /* we want the hid layer to go through standard path (set and ignore) */
353 return 0;
354}
355
356static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
357 struct hid_field *field, struct hid_usage *usage,
358 unsigned long **bit, int *max)
359{
360 struct apple_sc *asc = hid_get_drvdata(hdev);
361
362 if (asc->quirks & APPLE_MIGHTYMOUSE) {
363 if (usage->hid == HID_GD_Z)
364 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
365 else if (usage->code == BTN_1)
366 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
367 else if (usage->code == BTN_2)
368 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
369 }
370
371 return 0;
372}
373
374static int apple_probe(struct hid_device *hdev,
375 const struct hid_device_id *id)
376{
377 unsigned long quirks = id->driver_data;
378 struct apple_sc *asc;
Jiri Slaby93c10132008-06-27 00:04:24 +0200379 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200380 int ret;
381
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200382 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200383 if (asc == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800384 hid_err(hdev, "can't alloc apple descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200385 return -ENOMEM;
386 }
387
388 asc->quirks = quirks;
389
390 hid_set_drvdata(hdev, asc);
391
Jiri Slaby8c19a512008-06-18 23:36:49 +0200392 ret = hid_parse(hdev);
393 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800394 hid_err(hdev, "parse failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200395 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200396 }
397
Jiri Slaby93c10132008-06-27 00:04:24 +0200398 if (quirks & APPLE_HIDDEV)
399 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
400 if (quirks & APPLE_IGNORE_HIDINPUT)
401 connect_mask &= ~HID_CONNECT_HIDINPUT;
402
403 ret = hid_hw_start(hdev, connect_mask);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200404 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800405 hid_err(hdev, "hw start failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200406 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200407 }
408
409 return 0;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200410}
411
412static const struct hid_device_id apple_devices[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200413 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
414 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
415
416 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200417 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200418 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200419 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200420 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200421 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200422 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600423 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200424 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200425 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200426 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200427 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200428 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600429 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200430 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
431 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200432 APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200433 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200434 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200435 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600436 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200437 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
438 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200439 APPLE_RDESC_JIS },
Ryan Finniefef3f572009-03-05 10:18:01 +0100440 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
441 .driver_data = APPLE_HAS_FN },
442 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600443 .driver_data = APPLE_HAS_FN },
Ryan Finniefef3f572009-03-05 10:18:01 +0100444 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
445 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200446 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
447 .driver_data = APPLE_HAS_FN },
448 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600449 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200450 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
451 .driver_data = APPLE_HAS_FN },
452 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200453 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200454 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600455 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200456 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
457 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200458 APPLE_RDESC_JIS },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400459 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
460 .driver_data = APPLE_HAS_FN },
461 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600462 .driver_data = APPLE_HAS_FN },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400463 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
464 .driver_data = APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100465 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200466 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100467 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600468 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Andreas Kristad734bc2011-10-28 18:50:39 +0200469 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600470 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Alexey Kaminsky0a97e1e2012-04-23 18:02:18 +0200471 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
472 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
473 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Huei-Horng Yobd4a7ce2014-02-06 17:40:34 +0800474 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
475 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
476 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100477 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200478 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jean-Gabriel Gill-Coutureb5d94272016-07-11 17:41:26 +0200479 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
480 .driver_data = APPLE_HAS_FN },
Sean O'Brienee345492018-08-27 13:02:15 -0700481 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
482 .driver_data = APPLE_HAS_FN },
483 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
484 .driver_data = APPLE_HAS_FN },
485 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
486 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200487 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200488 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200489 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600490 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200491 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200492 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200493 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200494 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200495 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600496 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200497 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200498 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100499 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
500 .driver_data = APPLE_HAS_FN },
501 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600502 .driver_data = APPLE_HAS_FN },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100503 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
504 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400505 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
506 .driver_data = APPLE_HAS_FN },
507 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600508 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400509 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
510 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
511 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
512 .driver_data = APPLE_HAS_FN },
513 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600514 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400515 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
516 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Andy Botting47340bd2011-03-12 20:27:22 -0800517 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
518 .driver_data = APPLE_HAS_FN },
519 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600520 .driver_data = APPLE_HAS_FN },
Andy Botting47340bd2011-03-12 20:27:22 -0800521 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
522 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700523 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
524 .driver_data = APPLE_HAS_FN },
525 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600526 .driver_data = APPLE_HAS_FN },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700527 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
528 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900529 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
530 .driver_data = APPLE_HAS_FN },
531 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600532 .driver_data = APPLE_HAS_FN },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900533 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
534 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300535 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
536 .driver_data = APPLE_HAS_FN },
537 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600538 .driver_data = APPLE_HAS_FN },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300539 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
540 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700541 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
542 .driver_data = APPLE_HAS_FN },
543 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600544 .driver_data = APPLE_HAS_FN },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700545 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
546 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700547 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
548 .driver_data = APPLE_HAS_FN },
549 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600550 .driver_data = APPLE_HAS_FN },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700551 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
552 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700553 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
554 .driver_data = APPLE_HAS_FN },
555 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600556 .driver_data = APPLE_HAS_FN },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700557 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
558 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700559 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI),
560 .driver_data = APPLE_HAS_FN },
561 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600562 .driver_data = APPLE_HAS_FN },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700563 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
564 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100565 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
566 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
567 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600568 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100569 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
570 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200571 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200572 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200573 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200574 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200575
Jiri Slaby8c19a512008-06-18 23:36:49 +0200576 { }
577};
578MODULE_DEVICE_TABLE(hid, apple_devices);
579
580static struct hid_driver apple_driver = {
581 .name = "apple",
582 .id_table = apple_devices,
583 .report_fixup = apple_report_fixup,
584 .probe = apple_probe,
Jiri Slaby8c19a512008-06-18 23:36:49 +0200585 .event = apple_event,
586 .input_mapping = apple_input_mapping,
587 .input_mapped = apple_input_mapped,
588};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700589module_hid_driver(apple_driver);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200590
Jiri Slaby8c19a512008-06-18 23:36:49 +0200591MODULE_LICENSE("GPL");