hid-magicmouse.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/device.h>
  15. #include <linux/hid.h>
  16. #include <linux/input/mt.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include "hid-ids.h"
  20. static bool emulate_3button = true;
  21. module_param(emulate_3button, bool, 0644);
  22. MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
  23. static int middle_button_start = -350;
  24. static int middle_button_stop = +350;
  25. static bool emulate_scroll_wheel = true;
  26. module_param(emulate_scroll_wheel, bool, 0644);
  27. MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
  28. static unsigned int scroll_speed = 32;
  29. static int param_set_scroll_speed(const char *val,
  30. const struct kernel_param *kp) {
  31. unsigned long speed;
  32. if (!val || kstrtoul(val, 0, &speed) || speed > 63)
  33. return -EINVAL;
  34. scroll_speed = speed;
  35. return 0;
  36. }
  37. module_param_call(scroll_speed, param_set_scroll_speed, param_get_uint, &scroll_speed, 0644);
  38. MODULE_PARM_DESC(scroll_speed, "Scroll speed, value from 0 (slow) to 63 (fast)");
  39. static bool scroll_acceleration = false;
  40. module_param(scroll_acceleration, bool, 0644);
  41. MODULE_PARM_DESC(scroll_acceleration, "Accelerate sequential scroll events");
  42. static bool report_undeciphered;
  43. module_param(report_undeciphered, bool, 0644);
  44. MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
  45. #define TRACKPAD_REPORT_ID 0x28
  46. #define MOUSE_REPORT_ID 0x29
  47. #define DOUBLE_REPORT_ID 0xf7
  48. /* These definitions are not precise, but they're close enough. (Bits
  49. * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
  50. * to be some kind of bit mask -- 0x20 may be a near-field reading,
  51. * and 0x40 is actual contact, and 0x10 may be a start/stop or change
  52. * indication.)
  53. */
  54. #define TOUCH_STATE_MASK 0xf0
  55. #define TOUCH_STATE_NONE 0x00
  56. #define TOUCH_STATE_START 0x30
  57. #define TOUCH_STATE_DRAG 0x40
  58. #define SCROLL_ACCEL_DEFAULT 7
  59. /* Touch surface information. Dimension is in hundredths of a mm, min and max
  60. * are in units. */
  61. #define MOUSE_DIMENSION_X (float)9056
  62. #define MOUSE_MIN_X -1100
  63. #define MOUSE_MAX_X 1258
  64. #define MOUSE_RES_X ((MOUSE_MAX_X - MOUSE_MIN_X) / (MOUSE_DIMENSION_X / 100))
  65. #define MOUSE_DIMENSION_Y (float)5152
  66. #define MOUSE_MIN_Y -1589
  67. #define MOUSE_MAX_Y 2047
  68. #define MOUSE_RES_Y ((MOUSE_MAX_Y - MOUSE_MIN_Y) / (MOUSE_DIMENSION_Y / 100))
  69. #define TRACKPAD_DIMENSION_X (float)13000
  70. #define TRACKPAD_MIN_X -2909
  71. #define TRACKPAD_MAX_X 3167
  72. #define TRACKPAD_RES_X \
  73. ((TRACKPAD_MAX_X - TRACKPAD_MIN_X) / (TRACKPAD_DIMENSION_X / 100))
  74. #define TRACKPAD_DIMENSION_Y (float)11000
  75. #define TRACKPAD_MIN_Y -2456
  76. #define TRACKPAD_MAX_Y 2565
  77. #define TRACKPAD_RES_Y \
  78. ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
  79. /**
  80. * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  81. * @input: Input device through which we report events.
  82. * @quirks: Currently unused.
  83. * @ntouches: Number of touches in most recent touch report.
  84. * @scroll_accel: Number of consecutive scroll motions.
  85. * @scroll_jiffies: Time of last scroll motion.
  86. * @touches: Most recent data for a touch, indexed by tracking ID.
  87. * @tracking_ids: Mapping of current touch input data to @touches.
  88. */
  89. struct magicmouse_sc {
  90. struct input_dev *input;
  91. unsigned long quirks;
  92. int ntouches;
  93. int scroll_accel;
  94. unsigned long scroll_jiffies;
  95. struct {
  96. short x;
  97. short y;
  98. short scroll_x;
  99. short scroll_y;
  100. u8 size;
  101. } touches[16];
  102. int tracking_ids[16];
  103. };
  104. static int magicmouse_firm_touch(struct magicmouse_sc *msc)
  105. {
  106. int touch = -1;
  107. int ii;
  108. /* If there is only one "firm" touch, set touch to its
  109. * tracking ID.
  110. */
  111. for (ii = 0; ii < msc->ntouches; ii++) {
  112. int idx = msc->tracking_ids[ii];
  113. if (msc->touches[idx].size < 8) {
  114. /* Ignore this touch. */
  115. } else if (touch >= 0) {
  116. touch = -1;
  117. break;
  118. } else {
  119. touch = idx;
  120. }
  121. }
  122. return touch;
  123. }
  124. static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
  125. {
  126. int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
  127. test_bit(BTN_RIGHT, msc->input->key) << 1 |
  128. test_bit(BTN_MIDDLE, msc->input->key) << 2;
  129. if (emulate_3button) {
  130. int id;
  131. /* If some button was pressed before, keep it held
  132. * down. Otherwise, if there's exactly one firm
  133. * touch, use that to override the mouse's guess.
  134. */
  135. if (state == 0) {
  136. /* The button was released. */
  137. } else if (last_state != 0) {
  138. state = last_state;
  139. } else if ((id = magicmouse_firm_touch(msc)) >= 0) {
  140. int x = msc->touches[id].x;
  141. if (x < middle_button_start)
  142. state = 1;
  143. else if (x > middle_button_stop)
  144. state = 2;
  145. else
  146. state = 4;
  147. } /* else: we keep the mouse's guess */
  148. input_report_key(msc->input, BTN_MIDDLE, state & 4);
  149. }
  150. input_report_key(msc->input, BTN_LEFT, state & 1);
  151. input_report_key(msc->input, BTN_RIGHT, state & 2);
  152. if (state != last_state)
  153. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  154. }
  155. static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
  156. {
  157. struct input_dev *input = msc->input;
  158. int id, x, y, size, orientation, touch_major, touch_minor, state, down;
  159. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  160. id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
  161. x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
  162. y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
  163. size = tdata[5] & 0x3f;
  164. orientation = (tdata[6] >> 2) - 32;
  165. touch_major = tdata[3];
  166. touch_minor = tdata[4];
  167. state = tdata[7] & TOUCH_STATE_MASK;
  168. down = state != TOUCH_STATE_NONE;
  169. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  170. id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
  171. x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  172. y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  173. size = tdata[6] & 0x3f;
  174. orientation = (tdata[7] >> 2) - 32;
  175. touch_major = tdata[4];
  176. touch_minor = tdata[5];
  177. state = tdata[8] & TOUCH_STATE_MASK;
  178. down = state != TOUCH_STATE_NONE;
  179. }
  180. /* Store tracking ID and other fields. */
  181. msc->tracking_ids[raw_id] = id;
  182. msc->touches[id].x = x;
  183. msc->touches[id].y = y;
  184. msc->touches[id].size = size;
  185. /* If requested, emulate a scroll wheel by detecting small
  186. * vertical touch motions.
  187. */
  188. if (emulate_scroll_wheel) {
  189. unsigned long now = jiffies;
  190. int step_x = msc->touches[id].scroll_x - x;
  191. int step_y = msc->touches[id].scroll_y - y;
  192. /* Calculate and apply the scroll motion. */
  193. switch (state) {
  194. case TOUCH_STATE_START:
  195. msc->touches[id].scroll_x = x;
  196. msc->touches[id].scroll_y = y;
  197. /* Reset acceleration after half a second. */
  198. if (scroll_acceleration && time_before(now,
  199. msc->scroll_jiffies + HZ / 2))
  200. msc->scroll_accel = max_t(int,
  201. msc->scroll_accel - 1, 1);
  202. else
  203. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  204. break;
  205. case TOUCH_STATE_DRAG:
  206. step_x /= (64 - (int)scroll_speed) * msc->scroll_accel;
  207. if (step_x != 0) {
  208. msc->touches[id].scroll_x -= step_x *
  209. (64 - scroll_speed) * msc->scroll_accel;
  210. msc->scroll_jiffies = now;
  211. input_report_rel(input, REL_HWHEEL, -step_x);
  212. }
  213. step_y /= (64 - (int)scroll_speed) * msc->scroll_accel;
  214. if (step_y != 0) {
  215. msc->touches[id].scroll_y -= step_y *
  216. (64 - scroll_speed) * msc->scroll_accel;
  217. msc->scroll_jiffies = now;
  218. input_report_rel(input, REL_WHEEL, step_y);
  219. }
  220. break;
  221. }
  222. }
  223. if (down)
  224. msc->ntouches++;
  225. input_mt_slot(input, id);
  226. input_mt_report_slot_state(input, MT_TOOL_FINGER, down);
  227. /* Generate the input events for this touch. */
  228. if (down) {
  229. input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2);
  230. input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2);
  231. input_report_abs(input, ABS_MT_ORIENTATION, -orientation);
  232. input_report_abs(input, ABS_MT_POSITION_X, x);
  233. input_report_abs(input, ABS_MT_POSITION_Y, y);
  234. if (report_undeciphered) {
  235. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
  236. input_event(input, EV_MSC, MSC_RAW, tdata[7]);
  237. else /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  238. input_event(input, EV_MSC, MSC_RAW, tdata[8]);
  239. }
  240. }
  241. }
  242. static int magicmouse_raw_event(struct hid_device *hdev,
  243. struct hid_report *report, u8 *data, int size)
  244. {
  245. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  246. struct input_dev *input = msc->input;
  247. int x = 0, y = 0, ii, clicks = 0, npoints;
  248. switch (data[0]) {
  249. case TRACKPAD_REPORT_ID:
  250. /* Expect four bytes of prefix, and N*9 bytes of touch data. */
  251. if (size < 4 || ((size - 4) % 9) != 0)
  252. return 0;
  253. npoints = (size - 4) / 9;
  254. if (npoints > 15) {
  255. hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
  256. size);
  257. return 0;
  258. }
  259. msc->ntouches = 0;
  260. for (ii = 0; ii < npoints; ii++)
  261. magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
  262. clicks = data[1];
  263. /* The following bits provide a device specific timestamp. They
  264. * are unused here.
  265. *
  266. * ts = data[1] >> 6 | data[2] << 2 | data[3] << 10;
  267. */
  268. break;
  269. case MOUSE_REPORT_ID:
  270. /* Expect six bytes of prefix, and N*8 bytes of touch data. */
  271. if (size < 6 || ((size - 6) % 8) != 0)
  272. return 0;
  273. npoints = (size - 6) / 8;
  274. if (npoints > 15) {
  275. hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
  276. size);
  277. return 0;
  278. }
  279. msc->ntouches = 0;
  280. for (ii = 0; ii < npoints; ii++)
  281. magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
  282. /* When emulating three-button mode, it is important
  283. * to have the current touch information before
  284. * generating a click event.
  285. */
  286. x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22;
  287. y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22;
  288. clicks = data[3];
  289. /* The following bits provide a device specific timestamp. They
  290. * are unused here.
  291. *
  292. * ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
  293. */
  294. break;
  295. case DOUBLE_REPORT_ID:
  296. /* Sometimes the trackpad sends two touch reports in one
  297. * packet.
  298. */
  299. magicmouse_raw_event(hdev, report, data + 2, data[1]);
  300. magicmouse_raw_event(hdev, report, data + 2 + data[1],
  301. size - 2 - data[1]);
  302. break;
  303. default:
  304. return 0;
  305. }
  306. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  307. magicmouse_emit_buttons(msc, clicks & 3);
  308. input_report_rel(input, REL_X, x);
  309. input_report_rel(input, REL_Y, y);
  310. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  311. input_report_key(input, BTN_MOUSE, clicks & 1);
  312. input_mt_report_pointer_emulation(input, true);
  313. }
  314. input_sync(input);
  315. return 1;
  316. }
  317. static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
  318. {
  319. int error;
  320. __set_bit(EV_KEY, input->evbit);
  321. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  322. __set_bit(BTN_LEFT, input->keybit);
  323. __set_bit(BTN_RIGHT, input->keybit);
  324. if (emulate_3button)
  325. __set_bit(BTN_MIDDLE, input->keybit);
  326. __set_bit(EV_REL, input->evbit);
  327. __set_bit(REL_X, input->relbit);
  328. __set_bit(REL_Y, input->relbit);
  329. if (emulate_scroll_wheel) {
  330. __set_bit(REL_WHEEL, input->relbit);
  331. __set_bit(REL_HWHEEL, input->relbit);
  332. }
  333. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  334. /* input->keybit is initialized with incorrect button info
  335. * for Magic Trackpad. There really is only one physical
  336. * button (BTN_LEFT == BTN_MOUSE). Make sure we don't
  337. * advertise buttons that don't exist...
  338. */
  339. __clear_bit(BTN_RIGHT, input->keybit);
  340. __clear_bit(BTN_MIDDLE, input->keybit);
  341. __set_bit(BTN_MOUSE, input->keybit);
  342. __set_bit(BTN_TOOL_FINGER, input->keybit);
  343. __set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
  344. __set_bit(BTN_TOOL_TRIPLETAP, input->keybit);
  345. __set_bit(BTN_TOOL_QUADTAP, input->keybit);
  346. __set_bit(BTN_TOOL_QUINTTAP, input->keybit);
  347. __set_bit(BTN_TOUCH, input->keybit);
  348. __set_bit(INPUT_PROP_POINTER, input->propbit);
  349. __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
  350. }
  351. __set_bit(EV_ABS, input->evbit);
  352. error = input_mt_init_slots(input, 16, 0);
  353. if (error)
  354. return error;
  355. input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2,
  356. 4, 0);
  357. input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255 << 2,
  358. 4, 0);
  359. input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0);
  360. /* Note: Touch Y position from the device is inverted relative
  361. * to how pointer motion is reported (and relative to how USB
  362. * HID recommends the coordinates work). This driver keeps
  363. * the origin at the same position, and just uses the additive
  364. * inverse of the reported Y.
  365. */
  366. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  367. input_set_abs_params(input, ABS_MT_POSITION_X,
  368. MOUSE_MIN_X, MOUSE_MAX_X, 4, 0);
  369. input_set_abs_params(input, ABS_MT_POSITION_Y,
  370. MOUSE_MIN_Y, MOUSE_MAX_Y, 4, 0);
  371. input_abs_set_res(input, ABS_MT_POSITION_X,
  372. MOUSE_RES_X);
  373. input_abs_set_res(input, ABS_MT_POSITION_Y,
  374. MOUSE_RES_Y);
  375. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  376. input_set_abs_params(input, ABS_X, TRACKPAD_MIN_X,
  377. TRACKPAD_MAX_X, 4, 0);
  378. input_set_abs_params(input, ABS_Y, TRACKPAD_MIN_Y,
  379. TRACKPAD_MAX_Y, 4, 0);
  380. input_set_abs_params(input, ABS_MT_POSITION_X,
  381. TRACKPAD_MIN_X, TRACKPAD_MAX_X, 4, 0);
  382. input_set_abs_params(input, ABS_MT_POSITION_Y,
  383. TRACKPAD_MIN_Y, TRACKPAD_MAX_Y, 4, 0);
  384. input_abs_set_res(input, ABS_X, TRACKPAD_RES_X);
  385. input_abs_set_res(input, ABS_Y, TRACKPAD_RES_Y);
  386. input_abs_set_res(input, ABS_MT_POSITION_X,
  387. TRACKPAD_RES_X);
  388. input_abs_set_res(input, ABS_MT_POSITION_Y,
  389. TRACKPAD_RES_Y);
  390. }
  391. input_set_events_per_packet(input, 60);
  392. if (report_undeciphered) {
  393. __set_bit(EV_MSC, input->evbit);
  394. __set_bit(MSC_RAW, input->mscbit);
  395. }
  396. return 0;
  397. }
  398. static int magicmouse_input_mapping(struct hid_device *hdev,
  399. struct hid_input *hi, struct hid_field *field,
  400. struct hid_usage *usage, unsigned long **bit, int *max)
  401. {
  402. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  403. if (!msc->input)
  404. msc->input = hi->input;
  405. /* Magic Trackpad does not give relative data after switching to MT */
  406. if (hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD &&
  407. field->flags & HID_MAIN_ITEM_RELATIVE)
  408. return -1;
  409. return 0;
  410. }
  411. static int magicmouse_input_configured(struct hid_device *hdev,
  412. struct hid_input *hi)
  413. {
  414. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  415. int ret;
  416. ret = magicmouse_setup_input(msc->input, hdev);
  417. if (ret) {
  418. hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
  419. /* clean msc->input to notify probe() of the failure */
  420. msc->input = NULL;
  421. return ret;
  422. }
  423. return 0;
  424. }
  425. static int magicmouse_probe(struct hid_device *hdev,
  426. const struct hid_device_id *id)
  427. {
  428. const u8 feature[] = { 0xd7, 0x01 };
  429. u8 *buf;
  430. struct magicmouse_sc *msc;
  431. struct hid_report *report;
  432. int ret;
  433. msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL);
  434. if (msc == NULL) {
  435. hid_err(hdev, "can't alloc magicmouse descriptor\n");
  436. return -ENOMEM;
  437. }
  438. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  439. msc->quirks = id->driver_data;
  440. hid_set_drvdata(hdev, msc);
  441. ret = hid_parse(hdev);
  442. if (ret) {
  443. hid_err(hdev, "magicmouse hid parse failed\n");
  444. return ret;
  445. }
  446. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  447. if (ret) {
  448. hid_err(hdev, "magicmouse hw start failed\n");
  449. return ret;
  450. }
  451. if (!msc->input) {
  452. hid_err(hdev, "magicmouse input not registered\n");
  453. ret = -ENOMEM;
  454. goto err_stop_hw;
  455. }
  456. if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
  457. report = hid_register_report(hdev, HID_INPUT_REPORT,
  458. MOUSE_REPORT_ID, 0);
  459. else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  460. report = hid_register_report(hdev, HID_INPUT_REPORT,
  461. TRACKPAD_REPORT_ID, 0);
  462. report = hid_register_report(hdev, HID_INPUT_REPORT,
  463. DOUBLE_REPORT_ID, 0);
  464. }
  465. if (!report) {
  466. hid_err(hdev, "unable to register touch report\n");
  467. ret = -ENOMEM;
  468. goto err_stop_hw;
  469. }
  470. report->size = 6;
  471. buf = kmemdup(feature, sizeof(feature), GFP_KERNEL);
  472. if (!buf) {
  473. ret = -ENOMEM;
  474. goto err_stop_hw;
  475. }
  476. /*
  477. * Some devices repond with 'invalid report id' when feature
  478. * report switching it into multitouch mode is sent to it.
  479. *
  480. * This results in -EIO from the _raw low-level transport callback,
  481. * but there seems to be no other way of switching the mode.
  482. * Thus the super-ugly hacky success check below.
  483. */
  484. ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(feature),
  485. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  486. kfree(buf);
  487. if (ret != -EIO && ret != sizeof(feature)) {
  488. hid_err(hdev, "unable to request touch data (%d)\n", ret);
  489. goto err_stop_hw;
  490. }
  491. return 0;
  492. err_stop_hw:
  493. hid_hw_stop(hdev);
  494. return ret;
  495. }
  496. static const struct hid_device_id magic_mice[] = {
  497. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  498. USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 },
  499. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  500. USB_DEVICE_ID_APPLE_MAGICTRACKPAD), .driver_data = 0 },
  501. { }
  502. };
  503. MODULE_DEVICE_TABLE(hid, magic_mice);
  504. static struct hid_driver magicmouse_driver = {
  505. .name = "magicmouse",
  506. .id_table = magic_mice,
  507. .probe = magicmouse_probe,
  508. .raw_event = magicmouse_raw_event,
  509. .input_mapping = magicmouse_input_mapping,
  510. .input_configured = magicmouse_input_configured,
  511. };
  512. module_hid_driver(magicmouse_driver);
  513. MODULE_LICENSE("GPL");