Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1 | /* |
| 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 |
| 8 | * Copyright (c) 2007 Paul Walmsley |
| 9 | * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the Free |
| 15 | * Software Foundation; either version 2 of the License, or (at your option) |
| 16 | * any later version. |
| 17 | */ |
| 18 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 21 | #include <linux/device.h> |
| 22 | #include <linux/hid.h> |
| 23 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 25 | #include <linux/usb.h> |
| 26 | |
| 27 | #include "hid-ids.h" |
| 28 | |
| 29 | #define APPLE_RDESC_JIS 0x0001 |
| 30 | #define APPLE_IGNORE_MOUSE 0x0002 |
| 31 | #define APPLE_HAS_FN 0x0004 |
| 32 | #define APPLE_HIDDEV 0x0008 |
| 33 | #define APPLE_ISO_KEYBOARD 0x0010 |
| 34 | #define APPLE_MIGHTYMOUSE 0x0020 |
| 35 | #define APPLE_INVERT_HWHEEL 0x0040 |
| 36 | #define APPLE_IGNORE_HIDINPUT 0x0080 |
| 37 | #define APPLE_NUMLOCK_EMULATION 0x0100 |
| 38 | |
| 39 | #define APPLE_FLAG_FKEY 0x01 |
| 40 | |
| 41 | static unsigned int fnmode = 1; |
| 42 | module_param(fnmode, uint, 0644); |
| 43 | MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " |
| 44 | "[1] = fkeyslast, 2 = fkeysfirst)"); |
| 45 | |
Stefan Glasenhardt | 54a6593 | 2010-01-05 23:30:30 +0100 | [diff] [blame] | 46 | static unsigned int iso_layout = 1; |
| 47 | module_param(iso_layout, uint, 0644); |
| 48 | MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. " |
| 49 | "(0 = disabled, [1] = enabled)"); |
| 50 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 51 | struct apple_sc { |
| 52 | unsigned long quirks; |
| 53 | unsigned int fn_on; |
| 54 | DECLARE_BITMAP(pressed_fn, KEY_CNT); |
| 55 | DECLARE_BITMAP(pressed_numlock, KEY_CNT); |
| 56 | }; |
| 57 | |
| 58 | struct apple_key_translation { |
| 59 | u16 from; |
| 60 | u16 to; |
| 61 | u8 flags; |
| 62 | }; |
| 63 | |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 64 | static const struct apple_key_translation macbookair_fn_keys[] = { |
| 65 | { KEY_BACKSPACE, KEY_DELETE }, |
| 66 | { KEY_ENTER, KEY_INSERT }, |
| 67 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, |
| 68 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, |
| 69 | { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY }, |
| 70 | { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY }, |
| 71 | { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, |
| 72 | { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, |
| 73 | { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY }, |
| 74 | { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY }, |
| 75 | { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, |
| 76 | { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, |
| 77 | { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY }, |
| 78 | { KEY_UP, KEY_PAGEUP }, |
| 79 | { KEY_DOWN, KEY_PAGEDOWN }, |
| 80 | { KEY_LEFT, KEY_HOME }, |
| 81 | { KEY_RIGHT, KEY_END }, |
| 82 | { } |
| 83 | }; |
| 84 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 85 | static const struct apple_key_translation apple_fn_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 86 | { KEY_BACKSPACE, KEY_DELETE }, |
Henrik Rydberg | 437184a | 2008-11-04 13:31:38 +0100 | [diff] [blame] | 87 | { KEY_ENTER, KEY_INSERT }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 88 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, |
| 89 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, |
Henrik Rydberg | 437184a | 2008-11-04 13:31:38 +0100 | [diff] [blame] | 90 | { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY }, |
| 91 | { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 92 | { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, |
| 93 | { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, |
| 94 | { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, |
| 95 | { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, |
| 96 | { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY }, |
| 97 | { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY }, |
| 98 | { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, |
| 99 | { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, |
| 100 | { KEY_UP, KEY_PAGEUP }, |
| 101 | { KEY_DOWN, KEY_PAGEDOWN }, |
| 102 | { KEY_LEFT, KEY_HOME }, |
| 103 | { KEY_RIGHT, KEY_END }, |
| 104 | { } |
| 105 | }; |
| 106 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 107 | static const struct apple_key_translation powerbook_fn_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 108 | { KEY_BACKSPACE, KEY_DELETE }, |
| 109 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, |
| 110 | { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, |
| 111 | { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY }, |
| 112 | { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, |
| 113 | { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, |
| 114 | { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY }, |
| 115 | { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY }, |
| 116 | { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY }, |
| 117 | { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY }, |
| 118 | { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY }, |
| 119 | { KEY_UP, KEY_PAGEUP }, |
| 120 | { KEY_DOWN, KEY_PAGEDOWN }, |
| 121 | { KEY_LEFT, KEY_HOME }, |
| 122 | { KEY_RIGHT, KEY_END }, |
| 123 | { } |
| 124 | }; |
| 125 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 126 | static const struct apple_key_translation powerbook_numlock_keys[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 127 | { KEY_J, KEY_KP1 }, |
| 128 | { KEY_K, KEY_KP2 }, |
| 129 | { KEY_L, KEY_KP3 }, |
| 130 | { KEY_U, KEY_KP4 }, |
| 131 | { KEY_I, KEY_KP5 }, |
| 132 | { KEY_O, KEY_KP6 }, |
| 133 | { KEY_7, KEY_KP7 }, |
| 134 | { KEY_8, KEY_KP8 }, |
| 135 | { KEY_9, KEY_KP9 }, |
| 136 | { KEY_M, KEY_KP0 }, |
| 137 | { KEY_DOT, KEY_KPDOT }, |
| 138 | { KEY_SLASH, KEY_KPPLUS }, |
| 139 | { KEY_SEMICOLON, KEY_KPMINUS }, |
| 140 | { KEY_P, KEY_KPASTERISK }, |
| 141 | { KEY_MINUS, KEY_KPEQUAL }, |
| 142 | { KEY_0, KEY_KPSLASH }, |
| 143 | { KEY_F6, KEY_NUMLOCK }, |
| 144 | { KEY_KPENTER, KEY_KPENTER }, |
| 145 | { KEY_BACKSPACE, KEY_BACKSPACE }, |
| 146 | { } |
| 147 | }; |
| 148 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 149 | static const struct apple_key_translation apple_iso_keyboard[] = { |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 150 | { KEY_GRAVE, KEY_102ND }, |
| 151 | { KEY_102ND, KEY_GRAVE }, |
| 152 | { } |
| 153 | }; |
| 154 | |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 155 | static const struct apple_key_translation *apple_find_translation( |
| 156 | const struct apple_key_translation *table, u16 from) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 157 | { |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 158 | const struct apple_key_translation *trans; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 159 | |
| 160 | /* Look for the translation */ |
| 161 | for (trans = table; trans->from; trans++) |
| 162 | if (trans->from == from) |
| 163 | return trans; |
| 164 | |
| 165 | return NULL; |
| 166 | } |
| 167 | |
| 168 | static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, |
| 169 | struct hid_usage *usage, __s32 value) |
| 170 | { |
| 171 | struct apple_sc *asc = hid_get_drvdata(hid); |
Jiri Kosina | a4bc692 | 2010-11-03 10:42:02 -0400 | [diff] [blame] | 172 | const struct apple_key_translation *trans, *table; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 173 | |
| 174 | if (usage->code == KEY_FN) { |
| 175 | asc->fn_on = !!value; |
| 176 | input_event(input, usage->type, usage->code, value); |
| 177 | return 1; |
| 178 | } |
| 179 | |
| 180 | if (fnmode) { |
| 181 | int do_translate; |
| 182 | |
Jiri Kosina | a4bc692 | 2010-11-03 10:42:02 -0400 | [diff] [blame] | 183 | if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && |
| 184 | hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) |
| 185 | table = macbookair_fn_keys; |
Joshua V. Dillon | 5d922ba | 2011-08-05 12:05:22 -0700 | [diff] [blame^] | 186 | else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI && |
| 187 | hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) |
| 188 | table = macbookair_fn_keys; |
Jiri Kosina | a4bc692 | 2010-11-03 10:42:02 -0400 | [diff] [blame] | 189 | else if (hid->product < 0x21d || hid->product >= 0x300) |
| 190 | table = powerbook_fn_keys; |
| 191 | else |
| 192 | table = apple_fn_keys; |
| 193 | |
| 194 | trans = apple_find_translation (table, usage->code); |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 195 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 196 | if (trans) { |
| 197 | if (test_bit(usage->code, asc->pressed_fn)) |
| 198 | do_translate = 1; |
| 199 | else if (trans->flags & APPLE_FLAG_FKEY) |
| 200 | do_translate = (fnmode == 2 && asc->fn_on) || |
| 201 | (fnmode == 1 && !asc->fn_on); |
| 202 | else |
| 203 | do_translate = asc->fn_on; |
| 204 | |
| 205 | if (do_translate) { |
| 206 | if (value) |
| 207 | set_bit(usage->code, asc->pressed_fn); |
| 208 | else |
| 209 | clear_bit(usage->code, asc->pressed_fn); |
| 210 | |
| 211 | input_event(input, usage->type, trans->to, |
| 212 | value); |
| 213 | |
| 214 | return 1; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if (asc->quirks & APPLE_NUMLOCK_EMULATION && |
| 219 | (test_bit(usage->code, asc->pressed_numlock) || |
| 220 | test_bit(LED_NUML, input->led))) { |
| 221 | trans = apple_find_translation(powerbook_numlock_keys, |
| 222 | usage->code); |
| 223 | |
| 224 | if (trans) { |
| 225 | if (value) |
| 226 | set_bit(usage->code, |
| 227 | asc->pressed_numlock); |
| 228 | else |
| 229 | clear_bit(usage->code, |
| 230 | asc->pressed_numlock); |
| 231 | |
| 232 | input_event(input, usage->type, trans->to, |
| 233 | value); |
| 234 | } |
| 235 | |
| 236 | return 1; |
| 237 | } |
| 238 | } |
| 239 | |
Stefan Glasenhardt | 54a6593 | 2010-01-05 23:30:30 +0100 | [diff] [blame] | 240 | if (iso_layout) { |
| 241 | if (asc->quirks & APPLE_ISO_KEYBOARD) { |
| 242 | trans = apple_find_translation(apple_iso_keyboard, usage->code); |
| 243 | if (trans) { |
| 244 | input_event(input, usage->type, trans->to, value); |
| 245 | return 1; |
| 246 | } |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int apple_event(struct hid_device *hdev, struct hid_field *field, |
| 254 | struct hid_usage *usage, __s32 value) |
| 255 | { |
| 256 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 257 | |
| 258 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || |
| 259 | !usage->type) |
| 260 | return 0; |
| 261 | |
| 262 | if ((asc->quirks & APPLE_INVERT_HWHEEL) && |
| 263 | usage->code == REL_HWHEEL) { |
| 264 | input_event(field->hidinput->input, usage->type, usage->code, |
| 265 | -value); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | if ((asc->quirks & APPLE_HAS_FN) && |
| 270 | hidinput_apple_event(hdev, field->hidinput->input, |
| 271 | usage, value)) |
| 272 | return 1; |
| 273 | |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * MacBook JIS keyboard has wrong logical maximum |
| 280 | */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 281 | static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 282 | unsigned int *rsize) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 283 | { |
| 284 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 285 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 286 | if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 && |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 287 | rdesc[53] == 0x65 && rdesc[59] == 0x65) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 288 | hid_info(hdev, |
| 289 | "fixing up MacBook JIS keyboard report descriptor\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 290 | rdesc[53] = rdesc[59] = 0xe7; |
| 291 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 292 | return rdesc; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void apple_setup_input(struct input_dev *input) |
| 296 | { |
Paul Collins | b2ddd54 | 2009-03-07 17:07:15 +1300 | [diff] [blame] | 297 | const struct apple_key_translation *trans; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 298 | |
| 299 | set_bit(KEY_NUMLOCK, input->keybit); |
| 300 | |
| 301 | /* Enable all needed keys */ |
| 302 | for (trans = apple_fn_keys; trans->from; trans++) |
| 303 | set_bit(trans->to, input->keybit); |
| 304 | |
| 305 | for (trans = powerbook_fn_keys; trans->from; trans++) |
| 306 | set_bit(trans->to, input->keybit); |
| 307 | |
| 308 | for (trans = powerbook_numlock_keys; trans->from; trans++) |
| 309 | set_bit(trans->to, input->keybit); |
| 310 | |
| 311 | for (trans = apple_iso_keyboard; trans->from; trans++) |
| 312 | set_bit(trans->to, input->keybit); |
| 313 | } |
| 314 | |
| 315 | static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 316 | struct hid_field *field, struct hid_usage *usage, |
| 317 | unsigned long **bit, int *max) |
| 318 | { |
| 319 | if (usage->hid == (HID_UP_CUSTOM | 0x0003)) { |
| 320 | /* The fn key on Apple USB keyboards */ |
| 321 | set_bit(EV_REP, hi->input->evbit); |
| 322 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); |
| 323 | apple_setup_input(hi->input); |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | /* we want the hid layer to go through standard path (set and ignore) */ |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 332 | struct hid_field *field, struct hid_usage *usage, |
| 333 | unsigned long **bit, int *max) |
| 334 | { |
| 335 | struct apple_sc *asc = hid_get_drvdata(hdev); |
| 336 | |
| 337 | if (asc->quirks & APPLE_MIGHTYMOUSE) { |
| 338 | if (usage->hid == HID_GD_Z) |
| 339 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
| 340 | else if (usage->code == BTN_1) |
| 341 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2); |
| 342 | else if (usage->code == BTN_2) |
| 343 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1); |
| 344 | } |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static int apple_probe(struct hid_device *hdev, |
| 350 | const struct hid_device_id *id) |
| 351 | { |
| 352 | unsigned long quirks = id->driver_data; |
| 353 | struct apple_sc *asc; |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 354 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 355 | int ret; |
| 356 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 357 | asc = kzalloc(sizeof(*asc), GFP_KERNEL); |
| 358 | if (asc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 359 | hid_err(hdev, "can't alloc apple descriptor\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 360 | return -ENOMEM; |
| 361 | } |
| 362 | |
| 363 | asc->quirks = quirks; |
| 364 | |
| 365 | hid_set_drvdata(hdev, asc); |
| 366 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 367 | ret = hid_parse(hdev); |
| 368 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 369 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 370 | goto err_free; |
| 371 | } |
| 372 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 373 | if (quirks & APPLE_HIDDEV) |
| 374 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 375 | if (quirks & APPLE_IGNORE_HIDINPUT) |
| 376 | connect_mask &= ~HID_CONNECT_HIDINPUT; |
| 377 | |
| 378 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 379 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 380 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 381 | goto err_free; |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | err_free: |
| 386 | kfree(asc); |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | static void apple_remove(struct hid_device *hdev) |
| 391 | { |
| 392 | hid_hw_stop(hdev); |
| 393 | kfree(hid_get_drvdata(hdev)); |
| 394 | } |
| 395 | |
| 396 | static const struct hid_device_id apple_devices[] = { |
Peter Korsgaard | 0f492f2 | 2008-10-06 11:15:34 +0200 | [diff] [blame] | 397 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL), |
| 398 | .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 399 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4), |
| 400 | .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, |
| 401 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE), |
| 402 | .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL }, |
| 403 | |
| 404 | { 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] | 405 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 406 | { 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] | 407 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 408 | { 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] | 409 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 410 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO), |
| 411 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 412 | APPLE_ISO_KEYBOARD }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 413 | { 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] | 414 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 415 | { 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] | 416 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 417 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO), |
| 418 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 419 | APPLE_ISO_KEYBOARD }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 420 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS), |
| 421 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 422 | APPLE_RDESC_JIS }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 423 | { 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] | 424 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 425 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO), |
| 426 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 427 | APPLE_ISO_KEYBOARD }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 428 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS), |
| 429 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 430 | APPLE_RDESC_JIS }, |
Ryan Finnie | fef3f57 | 2009-03-05 10:18:01 +0100 | [diff] [blame] | 431 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI), |
| 432 | .driver_data = APPLE_HAS_FN }, |
| 433 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO), |
| 434 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 435 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS), |
| 436 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 437 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI), |
| 438 | .driver_data = APPLE_HAS_FN }, |
| 439 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO), |
| 440 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 441 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS), |
| 442 | .driver_data = APPLE_HAS_FN }, |
| 443 | { 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] | 444 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 445 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 446 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 447 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS), |
| 448 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 449 | APPLE_RDESC_JIS }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 450 | { 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] | 451 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 452 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO), |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 453 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
| 454 | APPLE_ISO_KEYBOARD }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 455 | { 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] | 456 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
| 457 | { 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] | 458 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 459 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 460 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 461 | { 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] | 462 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 463 | { 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] | 464 | .driver_data = APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 465 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO), |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 466 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 467 | { 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] | 468 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Henrik Rydberg | a96d6ef | 2008-11-04 20:03:45 +0100 | [diff] [blame] | 469 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), |
| 470 | .driver_data = APPLE_HAS_FN }, |
| 471 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), |
| 472 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 473 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), |
| 474 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Edgar (gimli) Hucek | 99b9f75 | 2010-11-03 10:36:18 -0400 | [diff] [blame] | 475 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI), |
| 476 | .driver_data = APPLE_HAS_FN }, |
| 477 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO), |
| 478 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 479 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS), |
| 480 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
| 481 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), |
| 482 | .driver_data = APPLE_HAS_FN }, |
| 483 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), |
| 484 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 485 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), |
| 486 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 487 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), |
| 488 | .driver_data = APPLE_HAS_FN }, |
| 489 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), |
| 490 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 491 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), |
| 492 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Joshua V. Dillon | 5d922ba | 2011-08-05 12:05:22 -0700 | [diff] [blame^] | 493 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI), |
| 494 | .driver_data = APPLE_HAS_FN }, |
| 495 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO), |
| 496 | .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, |
| 497 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS), |
| 498 | .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, |
Christian Schuerer-Waldheim | 23aeb61 | 2010-01-06 14:49:57 +0100 | [diff] [blame] | 499 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), |
| 500 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
| 501 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), |
| 502 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | |
| 503 | APPLE_ISO_KEYBOARD }, |
| 504 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS), |
| 505 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 506 | { 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] | 507 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 508 | { 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] | 509 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 510 | |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 511 | { } |
| 512 | }; |
| 513 | MODULE_DEVICE_TABLE(hid, apple_devices); |
| 514 | |
| 515 | static struct hid_driver apple_driver = { |
| 516 | .name = "apple", |
| 517 | .id_table = apple_devices, |
| 518 | .report_fixup = apple_report_fixup, |
| 519 | .probe = apple_probe, |
| 520 | .remove = apple_remove, |
| 521 | .event = apple_event, |
| 522 | .input_mapping = apple_input_mapping, |
| 523 | .input_mapped = apple_input_mapped, |
| 524 | }; |
| 525 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 526 | static int __init apple_init(void) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 527 | { |
| 528 | int ret; |
| 529 | |
| 530 | ret = hid_register_driver(&apple_driver); |
| 531 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 532 | pr_err("can't register apple driver\n"); |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 533 | |
| 534 | return ret; |
| 535 | } |
| 536 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 537 | static void __exit apple_exit(void) |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 538 | { |
| 539 | hid_unregister_driver(&apple_driver); |
| 540 | } |
| 541 | |
| 542 | module_init(apple_init); |
| 543 | module_exit(apple_exit); |
| 544 | MODULE_LICENSE("GPL"); |