hid-apple.c 19 KB

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