blob: 1cb41992aaa1f650f89cbf5ace72bd46786d7abc [file] [log] [blame]
Jiri Slaby8c19a512008-06-18 23:36:49 +02001/*
2 * USB HID quirks support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
Jiri Slaby8c19a512008-06-18 23:36:49 +02008 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
Joe Perches4291ee32010-12-09 19:29:03 -080018#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Jiri Slaby8c19a512008-06-18 23:36:49 +020020#include <linux/device.h>
21#include <linux/hid.h>
22#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Jiri Slaby8c19a512008-06-18 23:36:49 +020024
25#include "hid-ids.h"
26
27#define APPLE_RDESC_JIS 0x0001
28#define APPLE_IGNORE_MOUSE 0x0002
29#define APPLE_HAS_FN 0x0004
30#define APPLE_HIDDEV 0x0008
Alex Henriebd77a0f2017-06-02 09:28:39 -060031/* 0x0010 reserved, was: APPLE_ISO_KEYBOARD */
Jiri Slaby8c19a512008-06-18 23:36:49 +020032#define APPLE_MIGHTYMOUSE 0x0020
33#define APPLE_INVERT_HWHEEL 0x0040
34#define APPLE_IGNORE_HIDINPUT 0x0080
35#define APPLE_NUMLOCK_EMULATION 0x0100
36
37#define APPLE_FLAG_FKEY 0x01
38
Alex Henriebd77a0f2017-06-02 09:28:39 -060039#define HID_COUNTRY_INTERNATIONAL_ISO 13
40
Jiri Slaby8c19a512008-06-18 23:36:49 +020041static unsigned int fnmode = 1;
42module_param(fnmode, uint, 0644);
43MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
44 "[1] = fkeyslast, 2 = fkeysfirst)");
45
Stefan Glasenhardt54a65932010-01-05 23:30:30 +010046static unsigned int iso_layout = 1;
47module_param(iso_layout, uint, 0644);
48MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
49 "(0 = disabled, [1] = enabled)");
50
Jiri Kosinaa94c79b2013-10-14 16:07:42 +020051static unsigned int swap_opt_cmd;
Nanno Langstraat43c83142013-10-14 16:07:15 +020052module_param(swap_opt_cmd, uint, 0644);
53MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
54 "(For people who want to keep Windows PC keyboard muscle memory. "
55 "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
56
Jiri Slaby8c19a512008-06-18 23:36:49 +020057struct apple_sc {
58 unsigned long quirks;
59 unsigned int fn_on;
60 DECLARE_BITMAP(pressed_fn, KEY_CNT);
61 DECLARE_BITMAP(pressed_numlock, KEY_CNT);
62};
63
64struct apple_key_translation {
65 u16 from;
66 u16 to;
67 u8 flags;
68};
69
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -040070static const struct apple_key_translation macbookair_fn_keys[] = {
71 { KEY_BACKSPACE, KEY_DELETE },
72 { KEY_ENTER, KEY_INSERT },
73 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
74 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
75 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
76 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
77 { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
78 { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
79 { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY },
80 { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY },
81 { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
82 { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
83 { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY },
84 { KEY_UP, KEY_PAGEUP },
85 { KEY_DOWN, KEY_PAGEDOWN },
86 { KEY_LEFT, KEY_HOME },
87 { KEY_RIGHT, KEY_END },
88 { }
89};
90
Paul Collinsb2ddd542009-03-07 17:07:15 +130091static const struct apple_key_translation apple_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +020092 { KEY_BACKSPACE, KEY_DELETE },
Henrik Rydberg437184a2008-11-04 13:31:38 +010093 { KEY_ENTER, KEY_INSERT },
Jiri Slaby8c19a512008-06-18 23:36:49 +020094 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
95 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
Henrik Rydberg437184a2008-11-04 13:31:38 +010096 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
97 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
Jiri Slaby8c19a512008-06-18 23:36:49 +020098 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
99 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
100 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
101 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
102 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
103 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
104 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
105 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
106 { KEY_UP, KEY_PAGEUP },
107 { KEY_DOWN, KEY_PAGEDOWN },
108 { KEY_LEFT, KEY_HOME },
109 { KEY_RIGHT, KEY_END },
110 { }
111};
112
Paul Collinsb2ddd542009-03-07 17:07:15 +1300113static const struct apple_key_translation powerbook_fn_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200114 { KEY_BACKSPACE, KEY_DELETE },
115 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
116 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
117 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
118 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
119 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
120 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
121 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
122 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
123 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
124 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
125 { KEY_UP, KEY_PAGEUP },
126 { KEY_DOWN, KEY_PAGEDOWN },
127 { KEY_LEFT, KEY_HOME },
128 { KEY_RIGHT, KEY_END },
129 { }
130};
131
Paul Collinsb2ddd542009-03-07 17:07:15 +1300132static const struct apple_key_translation powerbook_numlock_keys[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200133 { KEY_J, KEY_KP1 },
134 { KEY_K, KEY_KP2 },
135 { KEY_L, KEY_KP3 },
136 { KEY_U, KEY_KP4 },
137 { KEY_I, KEY_KP5 },
138 { KEY_O, KEY_KP6 },
139 { KEY_7, KEY_KP7 },
140 { KEY_8, KEY_KP8 },
141 { KEY_9, KEY_KP9 },
142 { KEY_M, KEY_KP0 },
143 { KEY_DOT, KEY_KPDOT },
144 { KEY_SLASH, KEY_KPPLUS },
145 { KEY_SEMICOLON, KEY_KPMINUS },
146 { KEY_P, KEY_KPASTERISK },
147 { KEY_MINUS, KEY_KPEQUAL },
148 { KEY_0, KEY_KPSLASH },
149 { KEY_F6, KEY_NUMLOCK },
150 { KEY_KPENTER, KEY_KPENTER },
151 { KEY_BACKSPACE, KEY_BACKSPACE },
152 { }
153};
154
Paul Collinsb2ddd542009-03-07 17:07:15 +1300155static const struct apple_key_translation apple_iso_keyboard[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200156 { KEY_GRAVE, KEY_102ND },
157 { KEY_102ND, KEY_GRAVE },
158 { }
159};
160
Nanno Langstraat43c83142013-10-14 16:07:15 +0200161static const struct apple_key_translation swapped_option_cmd_keys[] = {
162 { KEY_LEFTALT, KEY_LEFTMETA },
163 { KEY_LEFTMETA, KEY_LEFTALT },
164 { KEY_RIGHTALT, KEY_RIGHTMETA },
165 { KEY_RIGHTMETA,KEY_RIGHTALT },
166 { }
167};
168
Paul Collinsb2ddd542009-03-07 17:07:15 +1300169static const struct apple_key_translation *apple_find_translation(
170 const struct apple_key_translation *table, u16 from)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200171{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300172 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200173
174 /* Look for the translation */
175 for (trans = table; trans->from; trans++)
176 if (trans->from == from)
177 return trans;
178
179 return NULL;
180}
181
182static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
183 struct hid_usage *usage, __s32 value)
184{
185 struct apple_sc *asc = hid_get_drvdata(hid);
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400186 const struct apple_key_translation *trans, *table;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200187
188 if (usage->code == KEY_FN) {
189 asc->fn_on = !!value;
190 input_event(input, usage->type, usage->code, value);
191 return 1;
192 }
193
194 if (fnmode) {
195 int do_translate;
196
Jiri Kosinaa4bc6922010-11-03 10:42:02 -0400197 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
198 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
199 table = macbookair_fn_keys;
200 else if (hid->product < 0x21d || hid->product >= 0x300)
201 table = powerbook_fn_keys;
202 else
203 table = apple_fn_keys;
204
205 trans = apple_find_translation (table, usage->code);
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400206
Jiri Slaby8c19a512008-06-18 23:36:49 +0200207 if (trans) {
208 if (test_bit(usage->code, asc->pressed_fn))
209 do_translate = 1;
210 else if (trans->flags & APPLE_FLAG_FKEY)
211 do_translate = (fnmode == 2 && asc->fn_on) ||
212 (fnmode == 1 && !asc->fn_on);
213 else
214 do_translate = asc->fn_on;
215
216 if (do_translate) {
217 if (value)
218 set_bit(usage->code, asc->pressed_fn);
219 else
220 clear_bit(usage->code, asc->pressed_fn);
221
222 input_event(input, usage->type, trans->to,
223 value);
224
225 return 1;
226 }
227 }
228
229 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
230 (test_bit(usage->code, asc->pressed_numlock) ||
231 test_bit(LED_NUML, input->led))) {
232 trans = apple_find_translation(powerbook_numlock_keys,
233 usage->code);
234
235 if (trans) {
236 if (value)
237 set_bit(usage->code,
238 asc->pressed_numlock);
239 else
240 clear_bit(usage->code,
241 asc->pressed_numlock);
242
243 input_event(input, usage->type, trans->to,
244 value);
245 }
246
247 return 1;
248 }
249 }
250
Benedikt Bergenthal9f1f4632012-04-18 12:22:40 +0200251 if (iso_layout) {
Alex Henriebd77a0f2017-06-02 09:28:39 -0600252 if (hid->country == HID_COUNTRY_INTERNATIONAL_ISO) {
Stefan Glasenhardt54a65932010-01-05 23:30:30 +0100253 trans = apple_find_translation(apple_iso_keyboard, usage->code);
254 if (trans) {
255 input_event(input, usage->type, trans->to, value);
256 return 1;
257 }
Jiri Slaby8c19a512008-06-18 23:36:49 +0200258 }
259 }
260
Nanno Langstraat43c83142013-10-14 16:07:15 +0200261 if (swap_opt_cmd) {
262 trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
263 if (trans) {
264 input_event(input, usage->type, trans->to, value);
265 return 1;
266 }
267 }
268
Jiri Slaby8c19a512008-06-18 23:36:49 +0200269 return 0;
270}
271
272static int apple_event(struct hid_device *hdev, struct hid_field *field,
273 struct hid_usage *usage, __s32 value)
274{
275 struct apple_sc *asc = hid_get_drvdata(hdev);
276
277 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
278 !usage->type)
279 return 0;
280
281 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
282 usage->code == REL_HWHEEL) {
283 input_event(field->hidinput->input, usage->type, usage->code,
284 -value);
285 return 1;
286 }
287
288 if ((asc->quirks & APPLE_HAS_FN) &&
289 hidinput_apple_event(hdev, field->hidinput->input,
290 usage, value))
291 return 1;
292
293
294 return 0;
295}
296
297/*
298 * MacBook JIS keyboard has wrong logical maximum
299 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400300static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
301 unsigned int *rsize)
Jiri Slaby8c19a512008-06-18 23:36:49 +0200302{
303 struct apple_sc *asc = hid_get_drvdata(hdev);
304
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400305 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
Jiri Slaby8c19a512008-06-18 23:36:49 +0200306 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
Joe Perches4291ee32010-12-09 19:29:03 -0800307 hid_info(hdev,
308 "fixing up MacBook JIS keyboard report descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200309 rdesc[53] = rdesc[59] = 0xe7;
310 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400311 return rdesc;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200312}
313
314static void apple_setup_input(struct input_dev *input)
315{
Paul Collinsb2ddd542009-03-07 17:07:15 +1300316 const struct apple_key_translation *trans;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200317
318 set_bit(KEY_NUMLOCK, input->keybit);
319
320 /* Enable all needed keys */
321 for (trans = apple_fn_keys; trans->from; trans++)
322 set_bit(trans->to, input->keybit);
323
324 for (trans = powerbook_fn_keys; trans->from; trans++)
325 set_bit(trans->to, input->keybit);
326
327 for (trans = powerbook_numlock_keys; trans->from; trans++)
328 set_bit(trans->to, input->keybit);
329
330 for (trans = apple_iso_keyboard; trans->from; trans++)
331 set_bit(trans->to, input->keybit);
332}
333
334static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
335 struct hid_field *field, struct hid_usage *usage,
336 unsigned long **bit, int *max)
337{
Sean O'Brienee345492018-08-27 13:02:15 -0700338 if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
339 usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200340 /* The fn key on Apple USB keyboards */
341 set_bit(EV_REP, hi->input->evbit);
342 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
343 apple_setup_input(hi->input);
344 return 1;
345 }
346
347 /* we want the hid layer to go through standard path (set and ignore) */
348 return 0;
349}
350
351static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
352 struct hid_field *field, struct hid_usage *usage,
353 unsigned long **bit, int *max)
354{
355 struct apple_sc *asc = hid_get_drvdata(hdev);
356
357 if (asc->quirks & APPLE_MIGHTYMOUSE) {
358 if (usage->hid == HID_GD_Z)
359 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
360 else if (usage->code == BTN_1)
361 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
362 else if (usage->code == BTN_2)
363 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
364 }
365
366 return 0;
367}
368
369static int apple_probe(struct hid_device *hdev,
370 const struct hid_device_id *id)
371{
372 unsigned long quirks = id->driver_data;
373 struct apple_sc *asc;
Jiri Slaby93c10132008-06-27 00:04:24 +0200374 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200375 int ret;
376
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200377 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200378 if (asc == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800379 hid_err(hdev, "can't alloc apple descriptor\n");
Jiri Slaby8c19a512008-06-18 23:36:49 +0200380 return -ENOMEM;
381 }
382
383 asc->quirks = quirks;
384
385 hid_set_drvdata(hdev, asc);
386
Jiri Slaby8c19a512008-06-18 23:36:49 +0200387 ret = hid_parse(hdev);
388 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800389 hid_err(hdev, "parse failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200390 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200391 }
392
Jiri Slaby93c10132008-06-27 00:04:24 +0200393 if (quirks & APPLE_HIDDEV)
394 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
395 if (quirks & APPLE_IGNORE_HIDINPUT)
396 connect_mask &= ~HID_CONNECT_HIDINPUT;
397
398 ret = hid_hw_start(hdev, connect_mask);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200399 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800400 hid_err(hdev, "hw start failed\n");
Benjamin Tissoiresabf832b2013-07-24 19:38:04 +0200401 return ret;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200402 }
403
404 return 0;
Jiri Slaby8c19a512008-06-18 23:36:49 +0200405}
406
407static const struct hid_device_id apple_devices[] = {
Jiri Slaby8c19a512008-06-18 23:36:49 +0200408 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
409 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
410
411 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200412 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200413 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200414 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200415 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200416 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200417 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600418 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200419 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200420 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200421 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200422 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200423 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600424 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200425 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
426 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200427 APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200428 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200429 .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_GEYSER4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600431 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200432 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
433 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200434 APPLE_RDESC_JIS },
Ryan Finniefef3f572009-03-05 10:18:01 +0100435 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
436 .driver_data = APPLE_HAS_FN },
437 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600438 .driver_data = APPLE_HAS_FN },
Ryan Finniefef3f572009-03-05 10:18:01 +0100439 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
440 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200441 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
442 .driver_data = APPLE_HAS_FN },
443 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600444 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200445 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
446 .driver_data = APPLE_HAS_FN },
447 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200448 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200449 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600450 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200451 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
452 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200453 APPLE_RDESC_JIS },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400454 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
455 .driver_data = APPLE_HAS_FN },
456 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600457 .driver_data = APPLE_HAS_FN },
Dan Bastone4a4c8792011-07-31 07:40:49 -0400458 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
459 .driver_data = APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100460 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200461 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100462 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600463 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Andreas Kristad734bc2011-10-28 18:50:39 +0200464 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600465 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Alexey Kaminsky0a97e1e2012-04-23 18:02:18 +0200466 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
467 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
468 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Huei-Horng Yobd4a7ce2014-02-06 17:40:34 +0800469 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
470 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
471 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jan Scholzee8a1a02008-11-26 15:33:45 +0100472 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
Jiri Slaby8c19a512008-06-18 23:36:49 +0200473 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jean-Gabriel Gill-Coutureb5d94272016-07-11 17:41:26 +0200474 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
475 .driver_data = APPLE_HAS_FN },
Sean O'Brienee345492018-08-27 13:02:15 -0700476 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
477 .driver_data = APPLE_HAS_FN },
478 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
479 .driver_data = APPLE_HAS_FN },
480 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
481 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200483 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200484 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600485 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200486 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200487 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200488 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200489 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200490 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600491 .driver_data = APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200492 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200493 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100494 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
495 .driver_data = APPLE_HAS_FN },
496 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600497 .driver_data = APPLE_HAS_FN },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +0100498 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
499 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400500 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
501 .driver_data = APPLE_HAS_FN },
502 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600503 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400504 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
505 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
506 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
507 .driver_data = APPLE_HAS_FN },
508 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600509 .driver_data = APPLE_HAS_FN },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -0400510 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
511 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Andy Botting47340bd2011-03-12 20:27:22 -0800512 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
513 .driver_data = APPLE_HAS_FN },
514 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600515 .driver_data = APPLE_HAS_FN },
Andy Botting47340bd2011-03-12 20:27:22 -0800516 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
517 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700518 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
519 .driver_data = APPLE_HAS_FN },
520 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600521 .driver_data = APPLE_HAS_FN },
Joshua V. Dillon5d922ba2011-08-05 12:05:22 -0700522 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
523 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900524 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
525 .driver_data = APPLE_HAS_FN },
526 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600527 .driver_data = APPLE_HAS_FN },
Nobuhiro Iwamatsud762cc22011-10-01 15:54:53 +0900528 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
529 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300530 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
531 .driver_data = APPLE_HAS_FN },
532 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600533 .driver_data = APPLE_HAS_FN },
Gökçen Eraslan213f9da2011-10-22 22:39:06 +0300534 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
535 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700536 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
537 .driver_data = APPLE_HAS_FN },
538 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600539 .driver_data = APPLE_HAS_FN },
Ryan Bourgeoisb2e6ad72012-07-10 09:43:33 -0700540 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
541 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700542 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
543 .driver_data = APPLE_HAS_FN },
544 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600545 .driver_data = APPLE_HAS_FN },
Dirk Hohndel8d80da92012-10-30 11:11:48 -0700546 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
547 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700548 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
549 .driver_data = APPLE_HAS_FN },
550 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600551 .driver_data = APPLE_HAS_FN },
Dmitry Torokhov9d9a04e2013-07-01 11:46:27 -0700552 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
553 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700554 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI),
555 .driver_data = APPLE_HAS_FN },
556 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600557 .driver_data = APPLE_HAS_FN },
Henrik Rydberga4a2c542015-07-24 14:45:05 -0700558 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
559 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100560 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
561 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
562 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
Alex Henriebd77a0f2017-06-02 09:28:39 -0600563 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +0100564 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
565 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200566 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200567 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200568 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
Jiri Slabyb4d8e472008-10-22 14:47:18 +0200569 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
Jiri Slaby8c19a512008-06-18 23:36:49 +0200570
Jiri Slaby8c19a512008-06-18 23:36:49 +0200571 { }
572};
573MODULE_DEVICE_TABLE(hid, apple_devices);
574
575static struct hid_driver apple_driver = {
576 .name = "apple",
577 .id_table = apple_devices,
578 .report_fixup = apple_report_fixup,
579 .probe = apple_probe,
Jiri Slaby8c19a512008-06-18 23:36:49 +0200580 .event = apple_event,
581 .input_mapping = apple_input_mapping,
582 .input_mapped = apple_input_mapped,
583};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700584module_hid_driver(apple_driver);
Jiri Slaby8c19a512008-06-18 23:36:49 +0200585
Jiri Slaby8c19a512008-06-18 23:36:49 +0200586MODULE_LICENSE("GPL");