hid-magicmouse.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * Apple "Magic" Wireless Mouse driver
  3. *
  4. * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org>
  5. * Copyright (c) 2010 Chase Douglas <chase.douglas@canonical.com>
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/hid.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/usb.h>
  18. #include "hid-ids.h"
  19. static bool emulate_3button = true;
  20. module_param(emulate_3button, bool, 0644);
  21. MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
  22. static int middle_button_start = -350;
  23. static int middle_button_stop = +350;
  24. static bool emulate_scroll_wheel = true;
  25. module_param(emulate_scroll_wheel, bool, 0644);
  26. MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
  27. static unsigned int scroll_speed = 32;
  28. static int param_set_scroll_speed(const char *val, struct kernel_param *kp) {
  29. unsigned long speed;
  30. if (!val || strict_strtoul(val, 0, &speed) || speed > 63)
  31. return -EINVAL;
  32. scroll_speed = speed;
  33. return 0;
  34. }
  35. module_param_call(scroll_speed, param_set_scroll_speed, param_get_uint, &scroll_speed, 0644);
  36. MODULE_PARM_DESC(scroll_speed, "Scroll speed, value from 0 (slow) to 63 (fast)");
  37. static bool scroll_acceleration = false;
  38. module_param(scroll_acceleration, bool, 0644);
  39. MODULE_PARM_DESC(scroll_acceleration, "Accelerate sequential scroll events");
  40. static bool report_touches = true;
  41. module_param(report_touches, bool, 0644);
  42. MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
  43. static bool report_undeciphered;
  44. module_param(report_undeciphered, bool, 0644);
  45. MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
  46. #define TRACKPAD_REPORT_ID 0x28
  47. #define MOUSE_REPORT_ID 0x29
  48. #define DOUBLE_REPORT_ID 0xf7
  49. /* These definitions are not precise, but they're close enough. (Bits
  50. * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
  51. * to be some kind of bit mask -- 0x20 may be a near-field reading,
  52. * and 0x40 is actual contact, and 0x10 may be a start/stop or change
  53. * indication.)
  54. */
  55. #define TOUCH_STATE_MASK 0xf0
  56. #define TOUCH_STATE_NONE 0x00
  57. #define TOUCH_STATE_START 0x30
  58. #define TOUCH_STATE_DRAG 0x40
  59. #define SCROLL_ACCEL_DEFAULT 7
  60. /* Single touch emulation should only begin when no touches are currently down.
  61. * This is true when single_touch_id is equal to NO_TOUCHES. If multiple touches
  62. * are down and the touch providing for single touch emulation is lifted,
  63. * single_touch_id is equal to SINGLE_TOUCH_UP. While single touch emulation is
  64. * occuring, single_touch_id corresponds with the tracking id of the touch used.
  65. */
  66. #define NO_TOUCHES -1
  67. #define SINGLE_TOUCH_UP -2
  68. /**
  69. * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  70. * @input: Input device through which we report events.
  71. * @quirks: Currently unused.
  72. * @ntouches: Number of touches in most recent touch report.
  73. * @scroll_accel: Number of consecutive scroll motions.
  74. * @scroll_jiffies: Time of last scroll motion.
  75. * @touches: Most recent data for a touch, indexed by tracking ID.
  76. * @tracking_ids: Mapping of current touch input data to @touches.
  77. */
  78. struct magicmouse_sc {
  79. struct input_dev *input;
  80. unsigned long quirks;
  81. int ntouches;
  82. int scroll_accel;
  83. unsigned long scroll_jiffies;
  84. struct {
  85. short x;
  86. short y;
  87. short scroll_x;
  88. short scroll_y;
  89. u8 size;
  90. } touches[16];
  91. int tracking_ids[16];
  92. int single_touch_id;
  93. };
  94. static int magicmouse_firm_touch(struct magicmouse_sc *msc)
  95. {
  96. int touch = -1;
  97. int ii;
  98. /* If there is only one "firm" touch, set touch to its
  99. * tracking ID.
  100. */
  101. for (ii = 0; ii < msc->ntouches; ii++) {
  102. int idx = msc->tracking_ids[ii];
  103. if (msc->touches[idx].size < 8) {
  104. /* Ignore this touch. */
  105. } else if (touch >= 0) {
  106. touch = -1;
  107. break;
  108. } else {
  109. touch = idx;
  110. }
  111. }
  112. return touch;
  113. }
  114. static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
  115. {
  116. int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
  117. test_bit(BTN_RIGHT, msc->input->key) << 1 |
  118. test_bit(BTN_MIDDLE, msc->input->key) << 2;
  119. if (emulate_3button) {
  120. int id;
  121. /* If some button was pressed before, keep it held
  122. * down. Otherwise, if there's exactly one firm
  123. * touch, use that to override the mouse's guess.
  124. */
  125. if (state == 0) {
  126. /* The button was released. */
  127. } else if (last_state != 0) {
  128. state = last_state;
  129. } else if ((id = magicmouse_firm_touch(msc)) >= 0) {
  130. int x = msc->touches[id].x;
  131. if (x < middle_button_start)
  132. state = 1;
  133. else if (x > middle_button_stop)
  134. state = 2;
  135. else
  136. state = 4;
  137. } /* else: we keep the mouse's guess */
  138. input_report_key(msc->input, BTN_MIDDLE, state & 4);
  139. }
  140. input_report_key(msc->input, BTN_LEFT, state & 1);
  141. input_report_key(msc->input, BTN_RIGHT, state & 2);
  142. if (state != last_state)
  143. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  144. }
  145. static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
  146. {
  147. struct input_dev *input = msc->input;
  148. int id, x, y, size, orientation, touch_major, touch_minor, state, down;
  149. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  150. id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
  151. x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
  152. y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
  153. size = tdata[5] & 0x3f;
  154. orientation = (tdata[6] >> 2) - 32;
  155. touch_major = tdata[3];
  156. touch_minor = tdata[4];
  157. state = tdata[7] & TOUCH_STATE_MASK;
  158. down = state != TOUCH_STATE_NONE;
  159. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  160. id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
  161. x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  162. y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  163. size = tdata[6] & 0x3f;
  164. orientation = (tdata[7] >> 2) - 32;
  165. touch_major = tdata[4];
  166. touch_minor = tdata[5];
  167. state = tdata[8] & TOUCH_STATE_MASK;
  168. down = state != TOUCH_STATE_NONE;
  169. }
  170. /* Store tracking ID and other fields. */
  171. msc->tracking_ids[raw_id] = id;
  172. msc->touches[id].x = x;
  173. msc->touches[id].y = y;
  174. msc->touches[id].size = size;
  175. /* If requested, emulate a scroll wheel by detecting small
  176. * vertical touch motions.
  177. */
  178. if (emulate_scroll_wheel) {
  179. unsigned long now = jiffies;
  180. int step_x = msc->touches[id].scroll_x - x;
  181. int step_y = msc->touches[id].scroll_y - y;
  182. /* Calculate and apply the scroll motion. */
  183. switch (state) {
  184. case TOUCH_STATE_START:
  185. msc->touches[id].scroll_x = x;
  186. msc->touches[id].scroll_y = y;
  187. /* Reset acceleration after half a second. */
  188. if (scroll_acceleration && time_before(now,
  189. msc->scroll_jiffies + HZ / 2))
  190. msc->scroll_accel = max_t(int,
  191. msc->scroll_accel - 1, 1);
  192. else
  193. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  194. break;
  195. case TOUCH_STATE_DRAG:
  196. step_x /= (64 - (int)scroll_speed) * msc->scroll_accel;
  197. if (step_x != 0) {
  198. msc->touches[id].scroll_x -= step_x *
  199. (64 - scroll_speed) * msc->scroll_accel;
  200. msc->scroll_jiffies = now;
  201. input_report_rel(input, REL_HWHEEL, -step_x);
  202. }
  203. step_y /= (64 - (int)scroll_speed) * msc->scroll_accel;
  204. if (step_y != 0) {
  205. msc->touches[id].scroll_y -= step_y *
  206. (64 - scroll_speed) * msc->scroll_accel;
  207. msc->scroll_jiffies = now;
  208. input_report_rel(input, REL_WHEEL, step_y);
  209. }
  210. break;
  211. }
  212. }
  213. if (down) {
  214. msc->ntouches++;
  215. if (msc->single_touch_id == NO_TOUCHES)
  216. msc->single_touch_id = id;
  217. } else if (msc->single_touch_id == id)
  218. msc->single_touch_id = SINGLE_TOUCH_UP;
  219. /* Generate the input events for this touch. */
  220. if (report_touches && down) {
  221. input_report_abs(input, ABS_MT_TRACKING_ID, id);
  222. input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major);
  223. input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor);
  224. input_report_abs(input, ABS_MT_ORIENTATION, orientation);
  225. input_report_abs(input, ABS_MT_POSITION_X, x);
  226. input_report_abs(input, ABS_MT_POSITION_Y, y);
  227. if (report_undeciphered) {
  228. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
  229. input_event(input, EV_MSC, MSC_RAW, tdata[7]);
  230. else /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  231. input_event(input, EV_MSC, MSC_RAW, tdata[8]);
  232. }
  233. input_mt_sync(input);
  234. }
  235. }
  236. static int magicmouse_raw_event(struct hid_device *hdev,
  237. struct hid_report *report, u8 *data, int size)
  238. {
  239. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  240. struct input_dev *input = msc->input;
  241. int x = 0, y = 0, ii, clicks = 0, npoints;
  242. switch (data[0]) {
  243. case 0x10:
  244. if (size != 6)
  245. return 0;
  246. x = (__s16)(data[2] | data[3] << 8);
  247. y = (__s16)(data[4] | data[5] << 8);
  248. clicks = data[1];
  249. break;
  250. case TRACKPAD_REPORT_ID:
  251. /* Expect four bytes of prefix, and N*9 bytes of touch data. */
  252. if (size < 4 || ((size - 4) % 9) != 0)
  253. return 0;
  254. npoints = (size - 4) / 9;
  255. msc->ntouches = 0;
  256. for (ii = 0; ii < npoints; ii++)
  257. magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
  258. /* We don't need an MT sync here because trackpad emits a
  259. * BTN_TOUCH event in a new frame when all touches are released.
  260. */
  261. if (msc->ntouches == 0)
  262. msc->single_touch_id = NO_TOUCHES;
  263. clicks = data[1];
  264. /* The following bits provide a device specific timestamp. They
  265. * are unused here.
  266. *
  267. * ts = data[1] >> 6 | data[2] << 2 | data[3] << 10;
  268. */
  269. break;
  270. case MOUSE_REPORT_ID:
  271. /* Expect six bytes of prefix, and N*8 bytes of touch data. */
  272. if (size < 6 || ((size - 6) % 8) != 0)
  273. return 0;
  274. npoints = (size - 6) / 8;
  275. msc->ntouches = 0;
  276. for (ii = 0; ii < npoints; ii++)
  277. magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
  278. if (report_touches && msc->ntouches == 0)
  279. input_mt_sync(input);
  280. /* When emulating three-button mode, it is important
  281. * to have the current touch information before
  282. * generating a click event.
  283. */
  284. x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22;
  285. y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22;
  286. clicks = data[3];
  287. /* The following bits provide a device specific timestamp. They
  288. * are unused here.
  289. *
  290. * ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
  291. */
  292. break;
  293. case DOUBLE_REPORT_ID:
  294. /* Sometimes the trackpad sends two touch reports in one
  295. * packet.
  296. */
  297. magicmouse_raw_event(hdev, report, data + 2, data[1]);
  298. magicmouse_raw_event(hdev, report, data + 2 + data[1],
  299. size - 2 - data[1]);
  300. break;
  301. case 0x20: /* Theoretically battery status (0-100), but I have
  302. * never seen it -- maybe it is only upon request.
  303. */
  304. case 0x60: /* Unknown, maybe laser on/off. */
  305. case 0x61: /* Laser reflection status change.
  306. * data[1]: 0 = spotted, 1 = lost
  307. */
  308. default:
  309. return 0;
  310. }
  311. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  312. magicmouse_emit_buttons(msc, clicks & 3);
  313. input_report_rel(input, REL_X, x);
  314. input_report_rel(input, REL_Y, y);
  315. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  316. input_report_key(input, BTN_MOUSE, clicks & 1);
  317. input_report_key(input, BTN_TOUCH, msc->ntouches > 0);
  318. input_report_key(input, BTN_TOOL_FINGER, msc->ntouches == 1);
  319. input_report_key(input, BTN_TOOL_DOUBLETAP, msc->ntouches == 2);
  320. input_report_key(input, BTN_TOOL_TRIPLETAP, msc->ntouches == 3);
  321. input_report_key(input, BTN_TOOL_QUADTAP, msc->ntouches == 4);
  322. if (msc->single_touch_id >= 0) {
  323. input_report_abs(input, ABS_X,
  324. msc->touches[msc->single_touch_id].x);
  325. input_report_abs(input, ABS_Y,
  326. msc->touches[msc->single_touch_id].y);
  327. }
  328. }
  329. input_sync(input);
  330. return 1;
  331. }
  332. static int magicmouse_input_open(struct input_dev *dev)
  333. {
  334. struct hid_device *hid = input_get_drvdata(dev);
  335. return hid->ll_driver->open(hid);
  336. }
  337. static void magicmouse_input_close(struct input_dev *dev)
  338. {
  339. struct hid_device *hid = input_get_drvdata(dev);
  340. hid->ll_driver->close(hid);
  341. }
  342. static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
  343. {
  344. input_set_drvdata(input, hdev);
  345. input->event = hdev->ll_driver->hidinput_input_event;
  346. input->open = magicmouse_input_open;
  347. input->close = magicmouse_input_close;
  348. input->name = hdev->name;
  349. input->phys = hdev->phys;
  350. input->uniq = hdev->uniq;
  351. input->id.bustype = hdev->bus;
  352. input->id.vendor = hdev->vendor;
  353. input->id.product = hdev->product;
  354. input->id.version = hdev->version;
  355. input->dev.parent = hdev->dev.parent;
  356. __set_bit(EV_KEY, input->evbit);
  357. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  358. __set_bit(BTN_LEFT, input->keybit);
  359. __set_bit(BTN_RIGHT, input->keybit);
  360. if (emulate_3button)
  361. __set_bit(BTN_MIDDLE, input->keybit);
  362. __set_bit(EV_REL, input->evbit);
  363. __set_bit(REL_X, input->relbit);
  364. __set_bit(REL_Y, input->relbit);
  365. if (emulate_scroll_wheel) {
  366. __set_bit(REL_WHEEL, input->relbit);
  367. __set_bit(REL_HWHEEL, input->relbit);
  368. }
  369. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  370. __set_bit(BTN_MOUSE, input->keybit);
  371. __set_bit(BTN_TOOL_FINGER, input->keybit);
  372. __set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
  373. __set_bit(BTN_TOOL_TRIPLETAP, input->keybit);
  374. __set_bit(BTN_TOOL_QUADTAP, input->keybit);
  375. __set_bit(BTN_TOUCH, input->keybit);
  376. }
  377. if (report_touches) {
  378. __set_bit(EV_ABS, input->evbit);
  379. input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
  380. input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0);
  381. input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0);
  382. input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0);
  383. /* Note: Touch Y position from the device is inverted relative
  384. * to how pointer motion is reported (and relative to how USB
  385. * HID recommends the coordinates work). This driver keeps
  386. * the origin at the same position, and just uses the additive
  387. * inverse of the reported Y.
  388. */
  389. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  390. input_set_abs_params(input, ABS_MT_POSITION_X, -1100,
  391. 1358, 4, 0);
  392. input_set_abs_params(input, ABS_MT_POSITION_Y, -1589,
  393. 2047, 4, 0);
  394. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  395. input_set_abs_params(input, ABS_X, -2909, 3167, 4, 0);
  396. input_set_abs_params(input, ABS_Y, -2456, 2565, 4, 0);
  397. input_set_abs_params(input, ABS_MT_POSITION_X, -2909,
  398. 3167, 4, 0);
  399. input_set_abs_params(input, ABS_MT_POSITION_Y, -2456,
  400. 2565, 4, 0);
  401. }
  402. }
  403. if (report_undeciphered) {
  404. __set_bit(EV_MSC, input->evbit);
  405. __set_bit(MSC_RAW, input->mscbit);
  406. }
  407. }
  408. static int magicmouse_probe(struct hid_device *hdev,
  409. const struct hid_device_id *id)
  410. {
  411. __u8 feature[] = { 0xd7, 0x01 };
  412. struct input_dev *input;
  413. struct magicmouse_sc *msc;
  414. struct hid_report *report;
  415. int ret;
  416. msc = kzalloc(sizeof(*msc), GFP_KERNEL);
  417. if (msc == NULL) {
  418. dev_err(&hdev->dev, "can't alloc magicmouse descriptor\n");
  419. return -ENOMEM;
  420. }
  421. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  422. msc->quirks = id->driver_data;
  423. hid_set_drvdata(hdev, msc);
  424. msc->single_touch_id = NO_TOUCHES;
  425. ret = hid_parse(hdev);
  426. if (ret) {
  427. dev_err(&hdev->dev, "magicmouse hid parse failed\n");
  428. goto err_free;
  429. }
  430. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  431. if (ret) {
  432. dev_err(&hdev->dev, "magicmouse hw start failed\n");
  433. goto err_free;
  434. }
  435. /* we are handling the input ourselves */
  436. hidinput_disconnect(hdev);
  437. if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
  438. report = hid_register_report(hdev, HID_INPUT_REPORT,
  439. MOUSE_REPORT_ID);
  440. else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  441. report = hid_register_report(hdev, HID_INPUT_REPORT,
  442. TRACKPAD_REPORT_ID);
  443. report = hid_register_report(hdev, HID_INPUT_REPORT,
  444. DOUBLE_REPORT_ID);
  445. }
  446. if (!report) {
  447. dev_err(&hdev->dev, "unable to register touch report\n");
  448. ret = -ENOMEM;
  449. goto err_stop_hw;
  450. }
  451. report->size = 6;
  452. ret = hdev->hid_output_raw_report(hdev, feature, sizeof(feature),
  453. HID_FEATURE_REPORT);
  454. if (ret != sizeof(feature)) {
  455. dev_err(&hdev->dev, "unable to request touch data (%d)\n",
  456. ret);
  457. goto err_stop_hw;
  458. }
  459. input = input_allocate_device();
  460. if (!input) {
  461. dev_err(&hdev->dev, "can't alloc input device\n");
  462. ret = -ENOMEM;
  463. goto err_stop_hw;
  464. }
  465. magicmouse_setup_input(input, hdev);
  466. ret = input_register_device(input);
  467. if (ret) {
  468. dev_err(&hdev->dev, "input device registration failed\n");
  469. goto err_input;
  470. }
  471. msc->input = input;
  472. return 0;
  473. err_input:
  474. input_free_device(input);
  475. err_stop_hw:
  476. hid_hw_stop(hdev);
  477. err_free:
  478. kfree(msc);
  479. return ret;
  480. }
  481. static void magicmouse_remove(struct hid_device *hdev)
  482. {
  483. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  484. hid_hw_stop(hdev);
  485. input_unregister_device(msc->input);
  486. kfree(msc);
  487. }
  488. static const struct hid_device_id magic_mice[] = {
  489. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  490. USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 },
  491. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  492. USB_DEVICE_ID_APPLE_MAGICTRACKPAD), .driver_data = 0 },
  493. { }
  494. };
  495. MODULE_DEVICE_TABLE(hid, magic_mice);
  496. static struct hid_driver magicmouse_driver = {
  497. .name = "magicmouse",
  498. .id_table = magic_mice,
  499. .probe = magicmouse_probe,
  500. .remove = magicmouse_remove,
  501. .raw_event = magicmouse_raw_event,
  502. };
  503. static int __init magicmouse_init(void)
  504. {
  505. int ret;
  506. ret = hid_register_driver(&magicmouse_driver);
  507. if (ret)
  508. printk(KERN_ERR "can't register magicmouse driver\n");
  509. return ret;
  510. }
  511. static void __exit magicmouse_exit(void)
  512. {
  513. hid_unregister_driver(&magicmouse_driver);
  514. }
  515. module_init(magicmouse_init);
  516. module_exit(magicmouse_exit);
  517. MODULE_LICENSE("GPL");