hid-apple.c 21 KB

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