Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 2 | /* |
| 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 Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 9 | * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> |
| 10 | */ |
| 11 | |
| 12 | /* |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 16 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 17 | #include <linux/device.h> |
| 18 | #include <linux/hid.h> |
| 19 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 21 | |
| 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 Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 28 | /* 0x0010 reserved, was: APPLE_ISO_KEYBOARD */ |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 29 | #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 Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 36 | #define HID_COUNTRY_INTERNATIONAL_ISO 13 |
| 37 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 38 | static unsigned int fnmode = 1; |
| 39 | module_param(fnmode, uint, 0644); |
| 40 | MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " |
| 41 | "[1] = fkeyslast, 2 = fkeysfirst)"); |
| 42 | |
Stefan Glasenhardt | 54a6593 | 2010-01-05 23:30:30 +0100 | [diff] [blame] | 43 | static unsigned int iso_layout = 1; |
| 44 | module_param(iso_layout, uint, 0644); |
| 45 | MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. " |
| 46 | "(0 = disabled, [1] = enabled)"); |
| 47 | |
Jiri Kosina | a94c79b | 2013-10-14 16:07:42 +0200 | [diff] [blame] | 48 | static unsigned int swap_opt_cmd; |
Nanno Langstraat | 43c8314 | 2013-10-14 16:07:15 +0200 | [diff] [blame] | 49 | module_param(swap_opt_cmd, uint, 0644); |
| 50 | MODULE_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 | |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 54 | static unsigned int swap_fn_leftctrl; |
| 55 | module_param(swap_fn_leftctrl, uint, 0644); |
| 56 | MODULE_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 Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 60 | struct apple_sc { |
| 61 | unsigned long quirks; |
| 62 | unsigned int fn_on; |
Hans de Goede | a5d8164 | 2020-06-20 14:32:29 +0200 | [diff] [blame] | 63 | unsigned int fn_found; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 64 | DECLARE_BITMAP(pressed_numlock, KEY_CNT); |
| 65 | }; |
| 66 | |
| 67 | struct apple_key_translation { |
| 68 | u16 from; |
| 69 | u16 to; |
| 70 | u8 flags; |
| 71 | }; |
| 72 | |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 73 | static 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 Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 94 | static const struct apple_key_translation apple_fn_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 95 | { KEY_BACKSPACE, KEY_DELETE }, |
Henrik Rydberg | 437184a | 2008-11-04 13:31:38 +0100 | [diff] [blame] | 96 | { KEY_ENTER, KEY_INSERT }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 97 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, |
| 98 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, |
Henrik Rydberg | 437184a | 2008-11-04 13:31:38 +0100 | [diff] [blame] | 99 | { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY }, |
| 100 | { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 101 | { 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 Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 116 | static const struct apple_key_translation powerbook_fn_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 117 | { 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 Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 135 | static const struct apple_key_translation powerbook_numlock_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 136 | { 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 Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 158 | static const struct apple_key_translation apple_iso_keyboard[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 159 | { KEY_GRAVE, KEY_102ND }, |
| 160 | { KEY_102ND, KEY_GRAVE }, |
| 161 | { } |
| 162 | }; |
| 163 | |
Nanno Langstraat | 43c8314 | 2013-10-14 16:07:15 +0200 | [diff] [blame] | 164 | static 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 | |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 172 | static const struct apple_key_translation swapped_fn_leftctrl_keys[] = { |
| 173 | { KEY_FN, KEY_LEFTCTRL }, |
| 174 | { } |
| 175 | }; |
| 176 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 177 | static const struct apple_key_translation *apple_find_translation( |
| 178 | const struct apple_key_translation *table, u16 from) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 179 | { |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 180 | const struct apple_key_translation *trans; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 181 | |
| 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 Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 190 | static 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 Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 199 | static 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 Kosina | a4bc692 | 2010-11-03 10:42:02 -0400 | [diff] [blame] | 203 | const struct apple_key_translation *trans, *table; |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 204 | bool do_translate; |
| 205 | u16 code = 0; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 206 | |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 207 | u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN); |
| 208 | |
| 209 | if (usage->code == fn_keycode) { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 210 | asc->fn_on = !!value; |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 211 | input_event_with_scancode(input, usage->type, KEY_FN, |
| 212 | usage->hid, value); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 213 | return 1; |
| 214 | } |
| 215 | |
| 216 | if (fnmode) { |
Jiri Kosina | a4bc692 | 2010-11-03 10:42:02 -0400 | [diff] [blame] | 217 | 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) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 226 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 227 | if (trans) { |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 228 | 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 Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 232 | |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 233 | 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 Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 249 | |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 250 | code = do_translate ? trans->to : trans->from; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 251 | } |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 252 | |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 253 | input_event_with_scancode(input, usage->type, code, |
| 254 | usage->hid, value); |
Joao Moreno | aec256d | 2019-09-03 16:46:32 +0200 | [diff] [blame] | 255 | return 1; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 256 | } |
| 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 Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 272 | input_event_with_scancode(input, usage->type, |
| 273 | trans->to, usage->hid, value); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return 1; |
| 277 | } |
| 278 | } |
| 279 | |
Benedikt Bergenthal | 9f1f463 | 2012-04-18 12:22:40 +0200 | [diff] [blame] | 280 | if (iso_layout) { |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 281 | if (hid->country == HID_COUNTRY_INTERNATIONAL_ISO) { |
Stefan Glasenhardt | 54a6593 | 2010-01-05 23:30:30 +0100 | [diff] [blame] | 282 | trans = apple_find_translation(apple_iso_keyboard, usage->code); |
| 283 | if (trans) { |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 284 | input_event_with_scancode(input, usage->type, |
| 285 | trans->to, usage->hid, value); |
Stefan Glasenhardt | 54a6593 | 2010-01-05 23:30:30 +0100 | [diff] [blame] | 286 | return 1; |
| 287 | } |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Nanno Langstraat | 43c8314 | 2013-10-14 16:07:15 +0200 | [diff] [blame] | 291 | if (swap_opt_cmd) { |
| 292 | trans = apple_find_translation(swapped_option_cmd_keys, usage->code); |
| 293 | if (trans) { |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 294 | input_event_with_scancode(input, usage->type, |
| 295 | trans->to, usage->hid, value); |
Nanno Langstraat | 43c8314 | 2013-10-14 16:07:15 +0200 | [diff] [blame] | 296 | return 1; |
| 297 | } |
| 298 | } |
| 299 | |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 300 | if (swap_fn_leftctrl) { |
| 301 | trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code); |
| 302 | if (trans) { |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 303 | input_event_with_scancode(input, usage->type, |
| 304 | trans->to, usage->hid, value); |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 305 | return 1; |
| 306 | } |
| 307 | } |
| 308 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int apple_event(struct hid_device *hdev, struct hid_field *field, |
| 313 | struct hid_usage *usage, __s32 value) |
| 314 | { |
| 315 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 316 | |
| 317 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || |
| 318 | !usage->type) |
| 319 | return 0; |
| 320 | |
| 321 | if ((asc->quirks & APPLE_INVERT_HWHEEL) && |
| 322 | usage->code == REL_HWHEEL) { |
Vincent Lefevre | 3b41fb4 | 2021-07-22 03:25:44 +0200 | [diff] [blame] | 323 | input_event_with_scancode(field->hidinput->input, usage->type, |
| 324 | usage->code, usage->hid, -value); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 325 | return 1; |
| 326 | } |
| 327 | |
| 328 | if ((asc->quirks & APPLE_HAS_FN) && |
| 329 | hidinput_apple_event(hdev, field->hidinput->input, |
| 330 | usage, value)) |
| 331 | return 1; |
| 332 | |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * MacBook JIS keyboard has wrong logical maximum |
Mizuho Mori | 67fd71b | 2021-07-29 20:03:25 +0900 | [diff] [blame^] | 339 | * Magic Keyboard JIS has wrong logical maximum |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 340 | */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 341 | static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 342 | unsigned int *rsize) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 343 | { |
| 344 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 345 | |
Mizuho Mori | 67fd71b | 2021-07-29 20:03:25 +0900 | [diff] [blame^] | 346 | if(*rsize >=71 && rdesc[70] == 0x65 && rdesc[64] == 0x65) { |
| 347 | hid_info(hdev, |
| 348 | "fixing up Magic Keyboard JIS report descriptor\n"); |
| 349 | rdesc[64] = rdesc[70] = 0xe7; |
| 350 | } |
| 351 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 352 | if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 && |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 353 | rdesc[53] == 0x65 && rdesc[59] == 0x65) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 354 | hid_info(hdev, |
| 355 | "fixing up MacBook JIS keyboard report descriptor\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 356 | rdesc[53] = rdesc[59] = 0xe7; |
| 357 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 358 | return rdesc; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void apple_setup_input(struct input_dev *input) |
| 362 | { |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 363 | const struct apple_key_translation *trans; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 364 | |
| 365 | set_bit(KEY_NUMLOCK, input->keybit); |
| 366 | |
| 367 | /* Enable all needed keys */ |
| 368 | for (trans = apple_fn_keys; trans->from; trans++) |
| 369 | set_bit(trans->to, input->keybit); |
| 370 | |
| 371 | for (trans = powerbook_fn_keys; trans->from; trans++) |
| 372 | set_bit(trans->to, input->keybit); |
| 373 | |
| 374 | for (trans = powerbook_numlock_keys; trans->from; trans++) |
| 375 | set_bit(trans->to, input->keybit); |
| 376 | |
| 377 | for (trans = apple_iso_keyboard; trans->from; trans++) |
| 378 | set_bit(trans->to, input->keybit); |
free5lot | 346338e | 2020-05-15 13:14:00 +0700 | [diff] [blame] | 379 | |
| 380 | if (swap_fn_leftctrl) { |
| 381 | for (trans = swapped_fn_leftctrl_keys; trans->from; trans++) |
| 382 | set_bit(trans->to, input->keybit); |
| 383 | } |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 387 | struct hid_field *field, struct hid_usage *usage, |
| 388 | unsigned long **bit, int *max) |
| 389 | { |
Hans de Goede | a5d8164 | 2020-06-20 14:32:29 +0200 | [diff] [blame] | 390 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 391 | |
Sean O'Brien | ee34549 | 2018-08-27 13:02:15 -0700 | [diff] [blame] | 392 | if (usage->hid == (HID_UP_CUSTOM | 0x0003) || |
Mansour Behabadi | e433be9 | 2020-01-29 17:26:31 +1100 | [diff] [blame] | 393 | usage->hid == (HID_UP_MSVENDOR | 0x0003) || |
| 394 | usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 395 | /* The fn key on Apple USB keyboards */ |
| 396 | set_bit(EV_REP, hi->input->evbit); |
| 397 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); |
Hans de Goede | a5d8164 | 2020-06-20 14:32:29 +0200 | [diff] [blame] | 398 | asc->fn_found = true; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 399 | apple_setup_input(hi->input); |
| 400 | return 1; |
| 401 | } |
| 402 | |
| 403 | /* we want the hid layer to go through standard path (set and ignore) */ |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 408 | struct hid_field *field, struct hid_usage *usage, |
| 409 | unsigned long **bit, int *max) |
| 410 | { |
| 411 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 412 | |
| 413 | if (asc->quirks & APPLE_MIGHTYMOUSE) { |
| 414 | if (usage->hid == HID_GD_Z) |
| 415 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
| 416 | else if (usage->code == BTN_1) |
| 417 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2); |
| 418 | else if (usage->code == BTN_2) |
| 419 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1); |
| 420 | } |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Hans de Goede | a5d8164 | 2020-06-20 14:32:29 +0200 | [diff] [blame] | 425 | static int apple_input_configured(struct hid_device *hdev, |
| 426 | struct hid_input *hidinput) |
| 427 | { |
| 428 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 429 | |
| 430 | if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) { |
| 431 | hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n"); |
| 432 | asc->quirks = 0; |
| 433 | } |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 438 | static int apple_probe(struct hid_device *hdev, |
| 439 | const struct hid_device_id *id) |
| 440 | { |
| 441 | unsigned long quirks = id->driver_data; |
| 442 | struct apple_sc *asc; |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 443 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 444 | int ret; |
| 445 | |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 446 | asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 447 | if (asc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 448 | hid_err(hdev, "can't alloc apple descriptor\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 449 | return -ENOMEM; |
| 450 | } |
| 451 | |
| 452 | asc->quirks = quirks; |
| 453 | |
| 454 | hid_set_drvdata(hdev, asc); |
| 455 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 456 | ret = hid_parse(hdev); |
| 457 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 458 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 459 | return ret; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 460 | } |
| 461 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 462 | if (quirks & APPLE_HIDDEV) |
| 463 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 464 | if (quirks & APPLE_IGNORE_HIDINPUT) |
| 465 | connect_mask &= ~HID_CONNECT_HIDINPUT; |
| 466 | |
| 467 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 468 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 469 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 470 | return ret; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | return 0; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static const struct hid_device_id apple_devices[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 477 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE), |
| 478 | .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL }, |
| 479 | |
| 480 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 481 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 482 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 483 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 484 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 485 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 486 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 487 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 488 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 489 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 490 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 491 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 492 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 493 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 494 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS), |
| 495 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 496 | APPLE_RDESC_JIS }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 497 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 498 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 499 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 500 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 501 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS), |
| 502 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 503 | APPLE_RDESC_JIS }, |
Ryan Finnie | fef3f57 | 2009-03-05 10:18:01 +0100 | [diff] [blame] | 504 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI), |
| 505 | .driver_data = APPLE_HAS_FN }, |
| 506 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 507 | .driver_data = APPLE_HAS_FN }, |
Ryan Finnie | fef3f57 | 2009-03-05 10:18:01 +0100 | [diff] [blame] | 508 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS), |
| 509 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 510 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI), |
| 511 | .driver_data = APPLE_HAS_FN }, |
| 512 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 513 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 514 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS), |
| 515 | .driver_data = APPLE_HAS_FN }, |
| 516 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 517 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 518 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 519 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 520 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS), |
| 521 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 522 | APPLE_RDESC_JIS }, |
Dan Bastone | 4a4c879 | 2011-07-31 07:40:49 -0400 | [diff] [blame] | 523 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI), |
| 524 | .driver_data = APPLE_HAS_FN }, |
Haochen Tong | ebe0b42a | 2021-07-18 01:04:31 +0800 | [diff] [blame] | 525 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI), |
| 526 | .driver_data = APPLE_HAS_FN }, |
Dan Bastone | 4a4c879 | 2011-07-31 07:40:49 -0400 | [diff] [blame] | 527 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 528 | .driver_data = APPLE_HAS_FN }, |
BALATON Zoltan | 4c94542 | 2020-07-20 22:53:46 +0200 | [diff] [blame] | 529 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO), |
| 530 | .driver_data = APPLE_HAS_FN }, |
Dan Bastone | 4a4c879 | 2011-07-31 07:40:49 -0400 | [diff] [blame] | 531 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS), |
| 532 | .driver_data = APPLE_HAS_FN }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 533 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI), |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 534 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 535 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 536 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Andreas Krist | ad734bc | 2011-10-28 18:50:39 +0200 | [diff] [blame] | 537 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 538 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Alexey Kaminsky | 0a97e1e | 2012-04-23 18:02:18 +0200 | [diff] [blame] | 539 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, |
| 540 | USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI), |
| 541 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Huei-Horng Yo | bd4a7ce | 2014-02-06 17:40:34 +0800 | [diff] [blame] | 542 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, |
| 543 | USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS), |
| 544 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 545 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 546 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jean-Gabriel Gill-Couture | b5d9427 | 2016-07-11 17:41:26 +0200 | [diff] [blame] | 547 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI), |
| 548 | .driver_data = APPLE_HAS_FN }, |
Sean O'Brien | ee34549 | 2018-08-27 13:02:15 -0700 | [diff] [blame] | 549 | { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI), |
| 550 | .driver_data = APPLE_HAS_FN }, |
| 551 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI), |
| 552 | .driver_data = APPLE_HAS_FN }, |
| 553 | { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI), |
| 554 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 555 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 556 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 557 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 558 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 559 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 560 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 561 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 562 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 563 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 564 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 565 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 566 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Henrik Rydberg | a96d6ef | 2008-11-04 20:03:45 +0100 | [diff] [blame] | 567 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), |
| 568 | .driver_data = APPLE_HAS_FN }, |
| 569 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 570 | .driver_data = APPLE_HAS_FN }, |
Henrik Rydberg | a96d6ef | 2008-11-04 20:03:45 +0100 | [diff] [blame] | 571 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), |
| 572 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 573 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI), |
| 574 | .driver_data = APPLE_HAS_FN }, |
| 575 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 576 | .driver_data = APPLE_HAS_FN }, |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 577 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS), |
| 578 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
| 579 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), |
| 580 | .driver_data = APPLE_HAS_FN }, |
| 581 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 582 | .driver_data = APPLE_HAS_FN }, |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 583 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), |
| 584 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 585 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), |
| 586 | .driver_data = APPLE_HAS_FN }, |
| 587 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 588 | .driver_data = APPLE_HAS_FN }, |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 589 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), |
| 590 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Joshua V. Dillon | 5d922ba | 2011-08-05 12:05:22 -0700 | [diff] [blame] | 591 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI), |
| 592 | .driver_data = APPLE_HAS_FN }, |
| 593 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 594 | .driver_data = APPLE_HAS_FN }, |
Joshua V. Dillon | 5d922ba | 2011-08-05 12:05:22 -0700 | [diff] [blame] | 595 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS), |
| 596 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Nobuhiro Iwamatsu | d762cc2 | 2011-10-01 15:54:53 +0900 | [diff] [blame] | 597 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI), |
| 598 | .driver_data = APPLE_HAS_FN }, |
| 599 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 600 | .driver_data = APPLE_HAS_FN }, |
Nobuhiro Iwamatsu | d762cc2 | 2011-10-01 15:54:53 +0900 | [diff] [blame] | 601 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS), |
| 602 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Gökçen Eraslan | 213f9da | 2011-10-22 22:39:06 +0300 | [diff] [blame] | 603 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI), |
| 604 | .driver_data = APPLE_HAS_FN }, |
| 605 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 606 | .driver_data = APPLE_HAS_FN }, |
Gökçen Eraslan | 213f9da | 2011-10-22 22:39:06 +0300 | [diff] [blame] | 607 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS), |
| 608 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Ryan Bourgeois | b2e6ad7 | 2012-07-10 09:43:33 -0700 | [diff] [blame] | 609 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI), |
| 610 | .driver_data = APPLE_HAS_FN }, |
| 611 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 612 | .driver_data = APPLE_HAS_FN }, |
Ryan Bourgeois | b2e6ad7 | 2012-07-10 09:43:33 -0700 | [diff] [blame] | 613 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS), |
| 614 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Dirk Hohndel | 8d80da9 | 2012-10-30 11:11:48 -0700 | [diff] [blame] | 615 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI), |
| 616 | .driver_data = APPLE_HAS_FN }, |
| 617 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 618 | .driver_data = APPLE_HAS_FN }, |
Dirk Hohndel | 8d80da9 | 2012-10-30 11:11:48 -0700 | [diff] [blame] | 619 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS), |
| 620 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Dmitry Torokhov | 9d9a04e | 2013-07-01 11:46:27 -0700 | [diff] [blame] | 621 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI), |
| 622 | .driver_data = APPLE_HAS_FN }, |
| 623 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 624 | .driver_data = APPLE_HAS_FN }, |
Dmitry Torokhov | 9d9a04e | 2013-07-01 11:46:27 -0700 | [diff] [blame] | 625 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS), |
| 626 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Henrik Rydberg | a4a2c54 | 2015-07-24 14:45:05 -0700 | [diff] [blame] | 627 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI), |
| 628 | .driver_data = APPLE_HAS_FN }, |
| 629 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 630 | .driver_data = APPLE_HAS_FN }, |
Henrik Rydberg | a4a2c54 | 2015-07-24 14:45:05 -0700 | [diff] [blame] | 631 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS), |
| 632 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Christian Schuerer-Waldheim | 23aeb61 | 2010-01-06 14:49:57 +0100 | [diff] [blame] | 633 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), |
| 634 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
| 635 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), |
Alex Henrie | bd77a0f | 2017-06-02 09:28:39 -0600 | [diff] [blame] | 636 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Christian Schuerer-Waldheim | 23aeb61 | 2010-01-06 14:49:57 +0100 | [diff] [blame] | 637 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS), |
| 638 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 639 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 640 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 641 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 642 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 643 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 644 | { } |
| 645 | }; |
| 646 | MODULE_DEVICE_TABLE(hid, apple_devices); |
| 647 | |
| 648 | static struct hid_driver apple_driver = { |
| 649 | .name = "apple", |
| 650 | .id_table = apple_devices, |
| 651 | .report_fixup = apple_report_fixup, |
| 652 | .probe = apple_probe, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 653 | .event = apple_event, |
| 654 | .input_mapping = apple_input_mapping, |
| 655 | .input_mapped = apple_input_mapped, |
Hans de Goede | a5d8164 | 2020-06-20 14:32:29 +0200 | [diff] [blame] | 656 | .input_configured = apple_input_configured, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 657 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 658 | module_hid_driver(apple_driver); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 659 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 660 | MODULE_LICENSE("GPL"); |