hid-apple.c 20 KB

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