hid-magicmouse.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Apple "Magic" Wireless Mouse driver
  4. *
  5. * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org>
  6. * Copyright (c) 2010 Chase Douglas <chase.douglas@canonical.com>
  7. */
  8. /*
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/device.h>
  12. #include <linux/hid.h>
  13. #include <linux/input/mt.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/workqueue.h>
  17. #include "hid-ids.h"
  18. static bool emulate_3button = true;
  19. module_param(emulate_3button, bool, 0644);
  20. MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
  21. static int middle_button_start = -350;
  22. static int middle_button_stop = +350;
  23. static bool emulate_scroll_wheel = true;
  24. module_param(emulate_scroll_wheel, bool, 0644);
  25. MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
  26. static unsigned int scroll_speed = 32;
  27. static int param_set_scroll_speed(const char *val,
  28. const struct kernel_param *kp) {
  29. unsigned long speed;
  30. if (!val || kstrtoul(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_undeciphered;
  41. module_param(report_undeciphered, bool, 0644);
  42. MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
  43. #define TRACKPAD2_2021_BT_VERSION 0x110
  44. #define TRACKPAD_2024_BT_VERSION 0x314
  45. #define TRACKPAD_REPORT_ID 0x28
  46. #define TRACKPAD2_USB_REPORT_ID 0x02
  47. #define TRACKPAD2_BT_REPORT_ID 0x31
  48. #define MOUSE_REPORT_ID 0x29
  49. #define MOUSE2_REPORT_ID 0x12
  50. #define DOUBLE_REPORT_ID 0xf7
  51. #define USB_BATTERY_TIMEOUT_SEC 60
  52. /* These definitions are not precise, but they're close enough. (Bits
  53. * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
  54. * to be some kind of bit mask -- 0x20 may be a near-field reading,
  55. * and 0x40 is actual contact, and 0x10 may be a start/stop or change
  56. * indication.)
  57. */
  58. #define TOUCH_STATE_MASK 0xf0
  59. #define TOUCH_STATE_NONE 0x00
  60. #define TOUCH_STATE_START 0x30
  61. #define TOUCH_STATE_DRAG 0x40
  62. /* Number of high-resolution events for each low-resolution detent. */
  63. #define SCROLL_HR_STEPS 10
  64. #define SCROLL_HR_MULT (120 / SCROLL_HR_STEPS)
  65. #define SCROLL_HR_THRESHOLD 90 /* units */
  66. #define SCROLL_ACCEL_DEFAULT 7
  67. /* Touch surface information. Dimension is in hundredths of a mm, min and max
  68. * are in units. */
  69. #define MOUSE_DIMENSION_X (float)9056
  70. #define MOUSE_MIN_X -1100
  71. #define MOUSE_MAX_X 1258
  72. #define MOUSE_RES_X ((MOUSE_MAX_X - MOUSE_MIN_X) / (MOUSE_DIMENSION_X / 100))
  73. #define MOUSE_DIMENSION_Y (float)5152
  74. #define MOUSE_MIN_Y -1589
  75. #define MOUSE_MAX_Y 2047
  76. #define MOUSE_RES_Y ((MOUSE_MAX_Y - MOUSE_MIN_Y) / (MOUSE_DIMENSION_Y / 100))
  77. #define TRACKPAD_DIMENSION_X (float)13000
  78. #define TRACKPAD_MIN_X -2909
  79. #define TRACKPAD_MAX_X 3167
  80. #define TRACKPAD_RES_X \
  81. ((TRACKPAD_MAX_X - TRACKPAD_MIN_X) / (TRACKPAD_DIMENSION_X / 100))
  82. #define TRACKPAD_DIMENSION_Y (float)11000
  83. #define TRACKPAD_MIN_Y -2456
  84. #define TRACKPAD_MAX_Y 2565
  85. #define TRACKPAD_RES_Y \
  86. ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
  87. #define TRACKPAD2_DIMENSION_X (float)16000
  88. #define TRACKPAD2_MIN_X -3678
  89. #define TRACKPAD2_MAX_X 3934
  90. #define TRACKPAD2_RES_X \
  91. ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
  92. #define TRACKPAD2_DIMENSION_Y (float)11490
  93. #define TRACKPAD2_MIN_Y -2478
  94. #define TRACKPAD2_MAX_Y 2587
  95. #define TRACKPAD2_RES_Y \
  96. ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
  97. /**
  98. * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  99. * @input: Input device through which we report events.
  100. * @quirks: Currently unused.
  101. * @ntouches: Number of touches in most recent touch report.
  102. * @scroll_accel: Number of consecutive scroll motions.
  103. * @scroll_jiffies: Time of last scroll motion.
  104. * @touches: Most recent data for a touch, indexed by tracking ID.
  105. * @tracking_ids: Mapping of current touch input data to @touches.
  106. * @hdev: Pointer to the underlying HID device.
  107. * @work: Workqueue to handle initialization retry for quirky devices.
  108. * @battery_timer: Timer for obtaining battery level information.
  109. */
  110. struct magicmouse_sc {
  111. struct input_dev *input;
  112. unsigned long quirks;
  113. int ntouches;
  114. int scroll_accel;
  115. unsigned long scroll_jiffies;
  116. struct {
  117. short x;
  118. short y;
  119. short scroll_x;
  120. short scroll_y;
  121. short scroll_x_hr;
  122. short scroll_y_hr;
  123. u8 size;
  124. bool scroll_x_active;
  125. bool scroll_y_active;
  126. } touches[16];
  127. int tracking_ids[16];
  128. struct hid_device *hdev;
  129. struct delayed_work work;
  130. struct timer_list battery_timer;
  131. };
  132. static int magicmouse_firm_touch(struct magicmouse_sc *msc)
  133. {
  134. int touch = -1;
  135. int ii;
  136. /* If there is only one "firm" touch, set touch to its
  137. * tracking ID.
  138. */
  139. for (ii = 0; ii < msc->ntouches; ii++) {
  140. int idx = msc->tracking_ids[ii];
  141. if (msc->touches[idx].size < 8) {
  142. /* Ignore this touch. */
  143. } else if (touch >= 0) {
  144. touch = -1;
  145. break;
  146. } else {
  147. touch = idx;
  148. }
  149. }
  150. return touch;
  151. }
  152. static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
  153. {
  154. int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
  155. test_bit(BTN_RIGHT, msc->input->key) << 1 |
  156. test_bit(BTN_MIDDLE, msc->input->key) << 2;
  157. if (emulate_3button) {
  158. int id;
  159. /* If some button was pressed before, keep it held
  160. * down. Otherwise, if there's exactly one firm
  161. * touch, use that to override the mouse's guess.
  162. */
  163. if (state == 0) {
  164. /* The button was released. */
  165. } else if (last_state != 0) {
  166. state = last_state;
  167. } else if ((id = magicmouse_firm_touch(msc)) >= 0) {
  168. int x = msc->touches[id].x;
  169. if (x < middle_button_start)
  170. state = 1;
  171. else if (x > middle_button_stop)
  172. state = 2;
  173. else
  174. state = 4;
  175. } /* else: we keep the mouse's guess */
  176. input_report_key(msc->input, BTN_MIDDLE, state & 4);
  177. }
  178. input_report_key(msc->input, BTN_LEFT, state & 1);
  179. input_report_key(msc->input, BTN_RIGHT, state & 2);
  180. if (state != last_state)
  181. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  182. }
  183. static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
  184. {
  185. struct input_dev *input = msc->input;
  186. int id, x, y, size, orientation, touch_major, touch_minor, state, down;
  187. int pressure = 0;
  188. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
  189. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  190. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
  191. id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
  192. x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
  193. y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
  194. size = tdata[5] & 0x3f;
  195. orientation = (tdata[6] >> 2) - 32;
  196. touch_major = tdata[3];
  197. touch_minor = tdata[4];
  198. state = tdata[7] & TOUCH_STATE_MASK;
  199. down = state != TOUCH_STATE_NONE;
  200. } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  201. input->id.product ==
  202. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  203. id = tdata[8] & 0xf;
  204. x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  205. y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  206. size = tdata[6];
  207. orientation = (tdata[8] >> 5) - 4;
  208. touch_major = tdata[4];
  209. touch_minor = tdata[5];
  210. pressure = tdata[7];
  211. state = tdata[3] & 0xC0;
  212. down = state == 0x80;
  213. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  214. id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
  215. x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  216. y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  217. size = tdata[6] & 0x3f;
  218. orientation = (tdata[7] >> 2) - 32;
  219. touch_major = tdata[4];
  220. touch_minor = tdata[5];
  221. state = tdata[8] & TOUCH_STATE_MASK;
  222. down = state != TOUCH_STATE_NONE;
  223. }
  224. /* Store tracking ID and other fields. */
  225. msc->tracking_ids[raw_id] = id;
  226. msc->touches[id].x = x;
  227. msc->touches[id].y = y;
  228. msc->touches[id].size = size;
  229. /* If requested, emulate a scroll wheel by detecting small
  230. * vertical touch motions.
  231. */
  232. if (emulate_scroll_wheel &&
  233. input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
  234. input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  235. unsigned long now = jiffies;
  236. int step_x = msc->touches[id].scroll_x - x;
  237. int step_y = msc->touches[id].scroll_y - y;
  238. int step_hr =
  239. max_t(int,
  240. ((64 - (int)scroll_speed) * msc->scroll_accel) /
  241. SCROLL_HR_STEPS,
  242. 1);
  243. int step_x_hr = msc->touches[id].scroll_x_hr - x;
  244. int step_y_hr = msc->touches[id].scroll_y_hr - y;
  245. /* Calculate and apply the scroll motion. */
  246. switch (state) {
  247. case TOUCH_STATE_START:
  248. msc->touches[id].scroll_x = x;
  249. msc->touches[id].scroll_y = y;
  250. msc->touches[id].scroll_x_hr = x;
  251. msc->touches[id].scroll_y_hr = y;
  252. msc->touches[id].scroll_x_active = false;
  253. msc->touches[id].scroll_y_active = false;
  254. /* Reset acceleration after half a second. */
  255. if (scroll_acceleration && time_before(now,
  256. msc->scroll_jiffies + HZ / 2))
  257. msc->scroll_accel = max_t(int,
  258. msc->scroll_accel - 1, 1);
  259. else
  260. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  261. break;
  262. case TOUCH_STATE_DRAG:
  263. step_x /= (64 - (int)scroll_speed) * msc->scroll_accel;
  264. if (step_x != 0) {
  265. msc->touches[id].scroll_x -= step_x *
  266. (64 - scroll_speed) * msc->scroll_accel;
  267. msc->scroll_jiffies = now;
  268. input_report_rel(input, REL_HWHEEL, -step_x);
  269. }
  270. step_y /= (64 - (int)scroll_speed) * msc->scroll_accel;
  271. if (step_y != 0) {
  272. msc->touches[id].scroll_y -= step_y *
  273. (64 - scroll_speed) * msc->scroll_accel;
  274. msc->scroll_jiffies = now;
  275. input_report_rel(input, REL_WHEEL, step_y);
  276. }
  277. if (!msc->touches[id].scroll_x_active &&
  278. abs(step_x_hr) > SCROLL_HR_THRESHOLD) {
  279. msc->touches[id].scroll_x_active = true;
  280. msc->touches[id].scroll_x_hr = x;
  281. step_x_hr = 0;
  282. }
  283. step_x_hr /= step_hr;
  284. if (step_x_hr != 0 &&
  285. msc->touches[id].scroll_x_active) {
  286. msc->touches[id].scroll_x_hr -= step_x_hr *
  287. step_hr;
  288. input_report_rel(input,
  289. REL_HWHEEL_HI_RES,
  290. -step_x_hr * SCROLL_HR_MULT);
  291. }
  292. if (!msc->touches[id].scroll_y_active &&
  293. abs(step_y_hr) > SCROLL_HR_THRESHOLD) {
  294. msc->touches[id].scroll_y_active = true;
  295. msc->touches[id].scroll_y_hr = y;
  296. step_y_hr = 0;
  297. }
  298. step_y_hr /= step_hr;
  299. if (step_y_hr != 0 &&
  300. msc->touches[id].scroll_y_active) {
  301. msc->touches[id].scroll_y_hr -= step_y_hr *
  302. step_hr;
  303. input_report_rel(input,
  304. REL_WHEEL_HI_RES,
  305. step_y_hr * SCROLL_HR_MULT);
  306. }
  307. break;
  308. }
  309. }
  310. if (down)
  311. msc->ntouches++;
  312. input_mt_slot(input, id);
  313. input_mt_report_slot_state(input, MT_TOOL_FINGER, down);
  314. /* Generate the input events for this touch. */
  315. if (down) {
  316. input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2);
  317. input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2);
  318. input_report_abs(input, ABS_MT_ORIENTATION, -orientation);
  319. input_report_abs(input, ABS_MT_POSITION_X, x);
  320. input_report_abs(input, ABS_MT_POSITION_Y, y);
  321. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  322. input->id.product ==
  323. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)
  324. input_report_abs(input, ABS_MT_PRESSURE, pressure);
  325. if (report_undeciphered) {
  326. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
  327. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  328. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC)
  329. input_event(input, EV_MSC, MSC_RAW, tdata[7]);
  330. else if (input->id.product !=
  331. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
  332. input->id.product !=
  333. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)
  334. input_event(input, EV_MSC, MSC_RAW, tdata[8]);
  335. }
  336. }
  337. }
  338. static int magicmouse_raw_event(struct hid_device *hdev,
  339. struct hid_report *report, u8 *data, int size)
  340. {
  341. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  342. struct input_dev *input = msc->input;
  343. int x = 0, y = 0, ii, clicks = 0, npoints;
  344. switch (data[0]) {
  345. case TRACKPAD_REPORT_ID:
  346. case TRACKPAD2_BT_REPORT_ID:
  347. /* Expect four bytes of prefix, and N*9 bytes of touch data. */
  348. if (size < 4 || ((size - 4) % 9) != 0)
  349. return 0;
  350. npoints = (size - 4) / 9;
  351. if (npoints > 15) {
  352. hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
  353. size);
  354. return 0;
  355. }
  356. msc->ntouches = 0;
  357. for (ii = 0; ii < npoints; ii++)
  358. magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
  359. clicks = data[1];
  360. /* The following bits provide a device specific timestamp. They
  361. * are unused here.
  362. *
  363. * ts = data[1] >> 6 | data[2] << 2 | data[3] << 10;
  364. */
  365. break;
  366. case TRACKPAD2_USB_REPORT_ID:
  367. /* Expect twelve bytes of prefix and N*9 bytes of touch data. */
  368. if (size < 12 || ((size - 12) % 9) != 0)
  369. return 0;
  370. npoints = (size - 12) / 9;
  371. if (npoints > 15) {
  372. hid_warn(hdev, "invalid size value (%d) for TRACKPAD2_USB_REPORT_ID\n",
  373. size);
  374. return 0;
  375. }
  376. msc->ntouches = 0;
  377. for (ii = 0; ii < npoints; ii++)
  378. magicmouse_emit_touch(msc, ii, data + ii * 9 + 12);
  379. clicks = data[1];
  380. break;
  381. case MOUSE_REPORT_ID:
  382. /* Expect six bytes of prefix, and N*8 bytes of touch data. */
  383. if (size < 6 || ((size - 6) % 8) != 0)
  384. return 0;
  385. npoints = (size - 6) / 8;
  386. if (npoints > 15) {
  387. hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
  388. size);
  389. return 0;
  390. }
  391. msc->ntouches = 0;
  392. for (ii = 0; ii < npoints; ii++)
  393. magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
  394. /* When emulating three-button mode, it is important
  395. * to have the current touch information before
  396. * generating a click event.
  397. */
  398. x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22;
  399. y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22;
  400. clicks = data[3];
  401. /* The following bits provide a device specific timestamp. They
  402. * are unused here.
  403. *
  404. * ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
  405. */
  406. break;
  407. case MOUSE2_REPORT_ID:
  408. /* Size is either 8 or (14 + 8 * N) */
  409. if (size != 8 && (size < 14 || (size - 14) % 8 != 0))
  410. return 0;
  411. npoints = (size - 14) / 8;
  412. if (npoints > 15) {
  413. hid_warn(hdev, "invalid size value (%d) for MOUSE2_REPORT_ID\n",
  414. size);
  415. return 0;
  416. }
  417. msc->ntouches = 0;
  418. for (ii = 0; ii < npoints; ii++)
  419. magicmouse_emit_touch(msc, ii, data + ii * 8 + 14);
  420. /* When emulating three-button mode, it is important
  421. * to have the current touch information before
  422. * generating a click event.
  423. */
  424. x = (int)((data[3] << 24) | (data[2] << 16)) >> 16;
  425. y = (int)((data[5] << 24) | (data[4] << 16)) >> 16;
  426. clicks = data[1];
  427. /* The following bits provide a device specific timestamp. They
  428. * are unused here.
  429. *
  430. * ts = data[11] >> 6 | data[12] << 2 | data[13] << 10;
  431. */
  432. break;
  433. case DOUBLE_REPORT_ID:
  434. /* Sometimes the trackpad sends two touch reports in one
  435. * packet.
  436. */
  437. magicmouse_raw_event(hdev, report, data + 2, data[1]);
  438. magicmouse_raw_event(hdev, report, data + 2 + data[1],
  439. size - 2 - data[1]);
  440. return 0;
  441. default:
  442. return 0;
  443. }
  444. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
  445. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  446. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
  447. magicmouse_emit_buttons(msc, clicks & 3);
  448. input_report_rel(input, REL_X, x);
  449. input_report_rel(input, REL_Y, y);
  450. } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  451. input->id.product ==
  452. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  453. input_mt_sync_frame(input);
  454. input_report_key(input, BTN_MOUSE, clicks & 1);
  455. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  456. input_report_key(input, BTN_MOUSE, clicks & 1);
  457. input_mt_report_pointer_emulation(input, true);
  458. }
  459. input_sync(input);
  460. return 1;
  461. }
  462. static int magicmouse_event(struct hid_device *hdev, struct hid_field *field,
  463. struct hid_usage *usage, __s32 value)
  464. {
  465. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  466. if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  467. msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) &&
  468. field->report->id == MOUSE2_REPORT_ID) {
  469. /*
  470. * magic_mouse_raw_event has done all the work. Skip hidinput.
  471. *
  472. * Specifically, hidinput may modify BTN_LEFT and BTN_RIGHT,
  473. * breaking emulate_3button.
  474. */
  475. return 1;
  476. }
  477. return 0;
  478. }
  479. static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
  480. {
  481. int error;
  482. int mt_flags = 0;
  483. __set_bit(EV_KEY, input->evbit);
  484. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
  485. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  486. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
  487. __set_bit(BTN_LEFT, input->keybit);
  488. __set_bit(BTN_RIGHT, input->keybit);
  489. if (emulate_3button)
  490. __set_bit(BTN_MIDDLE, input->keybit);
  491. __set_bit(EV_REL, input->evbit);
  492. __set_bit(REL_X, input->relbit);
  493. __set_bit(REL_Y, input->relbit);
  494. if (emulate_scroll_wheel) {
  495. __set_bit(REL_WHEEL, input->relbit);
  496. __set_bit(REL_HWHEEL, input->relbit);
  497. __set_bit(REL_WHEEL_HI_RES, input->relbit);
  498. __set_bit(REL_HWHEEL_HI_RES, input->relbit);
  499. }
  500. } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  501. input->id.product ==
  502. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  503. /* If the trackpad has been connected to a Mac, the name is
  504. * automatically personalized, e.g., "José Expósito's Trackpad".
  505. * When connected through Bluetooth, the personalized name is
  506. * reported, however, when connected through USB the generic
  507. * name is reported.
  508. * Set the device name to ensure the same driver settings get
  509. * loaded, whether connected through bluetooth or USB.
  510. */
  511. if (hdev->vendor == BT_VENDOR_ID_APPLE) {
  512. if (input->id.version == TRACKPAD2_2021_BT_VERSION)
  513. input->name = "Apple Inc. Magic Trackpad 2021";
  514. else if (input->id.version == TRACKPAD_2024_BT_VERSION) {
  515. input->name = "Apple Inc. Magic Trackpad USB-C";
  516. } else {
  517. input->name = "Apple Inc. Magic Trackpad";
  518. }
  519. } else { /* USB_VENDOR_ID_APPLE */
  520. input->name = hdev->name;
  521. }
  522. __clear_bit(EV_MSC, input->evbit);
  523. __clear_bit(BTN_0, input->keybit);
  524. __clear_bit(BTN_RIGHT, input->keybit);
  525. __clear_bit(BTN_MIDDLE, input->keybit);
  526. __set_bit(BTN_MOUSE, input->keybit);
  527. __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
  528. __set_bit(BTN_TOOL_FINGER, input->keybit);
  529. mt_flags = INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED |
  530. INPUT_MT_TRACK;
  531. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  532. /* input->keybit is initialized with incorrect button info
  533. * for Magic Trackpad. There really is only one physical
  534. * button (BTN_LEFT == BTN_MOUSE). Make sure we don't
  535. * advertise buttons that don't exist...
  536. */
  537. __clear_bit(BTN_RIGHT, input->keybit);
  538. __clear_bit(BTN_MIDDLE, input->keybit);
  539. __set_bit(BTN_MOUSE, input->keybit);
  540. __set_bit(BTN_TOOL_FINGER, input->keybit);
  541. __set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
  542. __set_bit(BTN_TOOL_TRIPLETAP, input->keybit);
  543. __set_bit(BTN_TOOL_QUADTAP, input->keybit);
  544. __set_bit(BTN_TOOL_QUINTTAP, input->keybit);
  545. __set_bit(BTN_TOUCH, input->keybit);
  546. __set_bit(INPUT_PROP_POINTER, input->propbit);
  547. __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
  548. }
  549. __set_bit(EV_ABS, input->evbit);
  550. error = input_mt_init_slots(input, 16, mt_flags);
  551. if (error)
  552. return error;
  553. input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2,
  554. 4, 0);
  555. input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255 << 2,
  556. 4, 0);
  557. /* Note: Touch Y position from the device is inverted relative
  558. * to how pointer motion is reported (and relative to how USB
  559. * HID recommends the coordinates work). This driver keeps
  560. * the origin at the same position, and just uses the additive
  561. * inverse of the reported Y.
  562. */
  563. if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
  564. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  565. input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
  566. input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0);
  567. input_set_abs_params(input, ABS_MT_POSITION_X,
  568. MOUSE_MIN_X, MOUSE_MAX_X, 4, 0);
  569. input_set_abs_params(input, ABS_MT_POSITION_Y,
  570. MOUSE_MIN_Y, MOUSE_MAX_Y, 4, 0);
  571. input_abs_set_res(input, ABS_MT_POSITION_X,
  572. MOUSE_RES_X);
  573. input_abs_set_res(input, ABS_MT_POSITION_Y,
  574. MOUSE_RES_Y);
  575. } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  576. input->id.product ==
  577. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  578. input_set_abs_params(input, ABS_MT_PRESSURE, 0, 253, 0, 0);
  579. input_set_abs_params(input, ABS_PRESSURE, 0, 253, 0, 0);
  580. input_set_abs_params(input, ABS_MT_ORIENTATION, -3, 4, 0, 0);
  581. input_set_abs_params(input, ABS_X, TRACKPAD2_MIN_X,
  582. TRACKPAD2_MAX_X, 0, 0);
  583. input_set_abs_params(input, ABS_Y, TRACKPAD2_MIN_Y,
  584. TRACKPAD2_MAX_Y, 0, 0);
  585. input_set_abs_params(input, ABS_MT_POSITION_X,
  586. TRACKPAD2_MIN_X, TRACKPAD2_MAX_X, 0, 0);
  587. input_set_abs_params(input, ABS_MT_POSITION_Y,
  588. TRACKPAD2_MIN_Y, TRACKPAD2_MAX_Y, 0, 0);
  589. input_abs_set_res(input, ABS_X, TRACKPAD2_RES_X);
  590. input_abs_set_res(input, ABS_Y, TRACKPAD2_RES_Y);
  591. input_abs_set_res(input, ABS_MT_POSITION_X, TRACKPAD2_RES_X);
  592. input_abs_set_res(input, ABS_MT_POSITION_Y, TRACKPAD2_RES_Y);
  593. } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  594. input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0);
  595. input_set_abs_params(input, ABS_X, TRACKPAD_MIN_X,
  596. TRACKPAD_MAX_X, 4, 0);
  597. input_set_abs_params(input, ABS_Y, TRACKPAD_MIN_Y,
  598. TRACKPAD_MAX_Y, 4, 0);
  599. input_set_abs_params(input, ABS_MT_POSITION_X,
  600. TRACKPAD_MIN_X, TRACKPAD_MAX_X, 4, 0);
  601. input_set_abs_params(input, ABS_MT_POSITION_Y,
  602. TRACKPAD_MIN_Y, TRACKPAD_MAX_Y, 4, 0);
  603. input_abs_set_res(input, ABS_X, TRACKPAD_RES_X);
  604. input_abs_set_res(input, ABS_Y, TRACKPAD_RES_Y);
  605. input_abs_set_res(input, ABS_MT_POSITION_X,
  606. TRACKPAD_RES_X);
  607. input_abs_set_res(input, ABS_MT_POSITION_Y,
  608. TRACKPAD_RES_Y);
  609. }
  610. input_set_events_per_packet(input, 60);
  611. if (report_undeciphered &&
  612. input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
  613. input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
  614. __set_bit(EV_MSC, input->evbit);
  615. __set_bit(MSC_RAW, input->mscbit);
  616. }
  617. /*
  618. * hid-input may mark device as using autorepeat, but neither
  619. * the trackpad, nor the mouse actually want it.
  620. */
  621. __clear_bit(EV_REP, input->evbit);
  622. return 0;
  623. }
  624. static int magicmouse_input_mapping(struct hid_device *hdev,
  625. struct hid_input *hi, struct hid_field *field,
  626. struct hid_usage *usage, unsigned long **bit, int *max)
  627. {
  628. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  629. if (!msc->input)
  630. msc->input = hi->input;
  631. /* Magic Trackpad does not give relative data after switching to MT */
  632. if ((hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD ||
  633. hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  634. hi->input->id.product ==
  635. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
  636. field->flags & HID_MAIN_ITEM_RELATIVE)
  637. return -1;
  638. return 0;
  639. }
  640. static int magicmouse_input_configured(struct hid_device *hdev,
  641. struct hid_input *hi)
  642. {
  643. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  644. int ret;
  645. if (!msc->input) {
  646. hid_err(hdev, "magicmouse setup input failed (no input)");
  647. return -EINVAL;
  648. }
  649. ret = magicmouse_setup_input(msc->input, hdev);
  650. if (ret) {
  651. hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
  652. /* clean msc->input to notify probe() of the failure */
  653. msc->input = NULL;
  654. return ret;
  655. }
  656. return 0;
  657. }
  658. static int magicmouse_enable_multitouch(struct hid_device *hdev)
  659. {
  660. const u8 *feature;
  661. const u8 feature_mt[] = { 0xD7, 0x01 };
  662. const u8 feature_mt_mouse2[] = { 0xF1, 0x02, 0x01 };
  663. const u8 feature_mt_trackpad2_usb[] = { 0x02, 0x01 };
  664. const u8 feature_mt_trackpad2_bt[] = { 0xF1, 0x02, 0x01 };
  665. u8 *buf;
  666. int ret;
  667. int feature_size;
  668. switch (hdev->product) {
  669. case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2:
  670. case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC:
  671. switch (hdev->vendor) {
  672. case BT_VENDOR_ID_APPLE:
  673. feature_size = sizeof(feature_mt_trackpad2_bt);
  674. feature = feature_mt_trackpad2_bt;
  675. break;
  676. default: /* USB_VENDOR_ID_APPLE */
  677. feature_size = sizeof(feature_mt_trackpad2_usb);
  678. feature = feature_mt_trackpad2_usb;
  679. }
  680. break;
  681. case USB_DEVICE_ID_APPLE_MAGICMOUSE2:
  682. case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC:
  683. feature_size = sizeof(feature_mt_mouse2);
  684. feature = feature_mt_mouse2;
  685. break;
  686. default:
  687. feature_size = sizeof(feature_mt);
  688. feature = feature_mt;
  689. }
  690. buf = kmemdup(feature, feature_size, GFP_KERNEL);
  691. if (!buf)
  692. return -ENOMEM;
  693. ret = hid_hw_raw_request(hdev, buf[0], buf, feature_size,
  694. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  695. kfree(buf);
  696. return ret;
  697. }
  698. static void magicmouse_enable_mt_work(struct work_struct *work)
  699. {
  700. struct magicmouse_sc *msc =
  701. container_of(work, struct magicmouse_sc, work.work);
  702. int ret;
  703. ret = magicmouse_enable_multitouch(msc->hdev);
  704. if (ret < 0)
  705. hid_err(msc->hdev, "unable to request touch data (%d)\n", ret);
  706. }
  707. static bool is_usb_magicmouse2(__u32 vendor, __u32 product)
  708. {
  709. if (vendor != USB_VENDOR_ID_APPLE)
  710. return false;
  711. return product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  712. product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC;
  713. }
  714. static bool is_usb_magictrackpad2(__u32 vendor, __u32 product)
  715. {
  716. if (vendor != USB_VENDOR_ID_APPLE)
  717. return false;
  718. return product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
  719. product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC;
  720. }
  721. static int magicmouse_fetch_battery(struct hid_device *hdev)
  722. {
  723. #ifdef CONFIG_HID_BATTERY_STRENGTH
  724. struct hid_report_enum *report_enum;
  725. struct hid_report *report;
  726. if (!hdev->battery ||
  727. (!is_usb_magicmouse2(hdev->vendor, hdev->product) &&
  728. !is_usb_magictrackpad2(hdev->vendor, hdev->product)))
  729. return -1;
  730. report_enum = &hdev->report_enum[hdev->battery_report_type];
  731. report = report_enum->report_id_hash[hdev->battery_report_id];
  732. if (!report || report->maxfield < 1)
  733. return -1;
  734. if (hdev->battery_capacity == hdev->battery_max)
  735. return -1;
  736. hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
  737. return 0;
  738. #else
  739. return -1;
  740. #endif
  741. }
  742. static void magicmouse_battery_timer_tick(struct timer_list *t)
  743. {
  744. struct magicmouse_sc *msc = timer_container_of(msc, t, battery_timer);
  745. struct hid_device *hdev = msc->hdev;
  746. if (magicmouse_fetch_battery(hdev) == 0) {
  747. mod_timer(&msc->battery_timer,
  748. jiffies + secs_to_jiffies(USB_BATTERY_TIMEOUT_SEC));
  749. }
  750. }
  751. static int magicmouse_probe(struct hid_device *hdev,
  752. const struct hid_device_id *id)
  753. {
  754. struct magicmouse_sc *msc;
  755. struct hid_report *report;
  756. int ret;
  757. msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL);
  758. if (msc == NULL) {
  759. hid_err(hdev, "can't alloc magicmouse descriptor\n");
  760. return -ENOMEM;
  761. }
  762. msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
  763. msc->hdev = hdev;
  764. INIT_DEFERRABLE_WORK(&msc->work, magicmouse_enable_mt_work);
  765. msc->quirks = id->driver_data;
  766. hid_set_drvdata(hdev, msc);
  767. ret = hid_parse(hdev);
  768. if (ret) {
  769. hid_err(hdev, "magicmouse hid parse failed\n");
  770. return ret;
  771. }
  772. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  773. if (ret) {
  774. hid_err(hdev, "magicmouse hw start failed\n");
  775. return ret;
  776. }
  777. if (is_usb_magicmouse2(id->vendor, id->product) ||
  778. is_usb_magictrackpad2(id->vendor, id->product)) {
  779. timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0);
  780. mod_timer(&msc->battery_timer,
  781. jiffies + secs_to_jiffies(USB_BATTERY_TIMEOUT_SEC));
  782. magicmouse_fetch_battery(hdev);
  783. }
  784. if (is_usb_magicmouse2(id->vendor, id->product) ||
  785. (is_usb_magictrackpad2(id->vendor, id->product) &&
  786. hdev->type != HID_TYPE_USBMOUSE))
  787. return 0;
  788. if (!msc->input) {
  789. hid_err(hdev, "magicmouse input not registered\n");
  790. ret = -ENOMEM;
  791. goto err_stop_hw;
  792. }
  793. switch (id->product) {
  794. case USB_DEVICE_ID_APPLE_MAGICMOUSE:
  795. report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE_REPORT_ID, 0);
  796. break;
  797. case USB_DEVICE_ID_APPLE_MAGICMOUSE2:
  798. case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC:
  799. report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE2_REPORT_ID, 0);
  800. break;
  801. case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2:
  802. case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC:
  803. switch (id->vendor) {
  804. case BT_VENDOR_ID_APPLE:
  805. report = hid_register_report(hdev, HID_INPUT_REPORT,
  806. TRACKPAD2_BT_REPORT_ID, 0);
  807. break;
  808. default:
  809. report = hid_register_report(hdev, HID_INPUT_REPORT,
  810. TRACKPAD2_USB_REPORT_ID, 0);
  811. }
  812. break;
  813. default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  814. report = hid_register_report(hdev, HID_INPUT_REPORT,
  815. TRACKPAD_REPORT_ID, 0);
  816. report = hid_register_report(hdev, HID_INPUT_REPORT,
  817. DOUBLE_REPORT_ID, 0);
  818. }
  819. if (!report) {
  820. hid_err(hdev, "unable to register touch report\n");
  821. ret = -ENOMEM;
  822. goto err_stop_hw;
  823. }
  824. report->size = 6;
  825. /*
  826. * Some devices repond with 'invalid report id' when feature
  827. * report switching it into multitouch mode is sent to it.
  828. *
  829. * This results in -EIO from the _raw low-level transport callback,
  830. * but there seems to be no other way of switching the mode.
  831. * Thus the super-ugly hacky success check below.
  832. */
  833. ret = magicmouse_enable_multitouch(hdev);
  834. if (ret != -EIO && ret < 0) {
  835. hid_err(hdev, "unable to request touch data (%d)\n", ret);
  836. goto err_stop_hw;
  837. }
  838. if (ret == -EIO && (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
  839. id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC)) {
  840. schedule_delayed_work(&msc->work, msecs_to_jiffies(500));
  841. }
  842. return 0;
  843. err_stop_hw:
  844. if (is_usb_magicmouse2(id->vendor, id->product) ||
  845. is_usb_magictrackpad2(id->vendor, id->product))
  846. timer_delete_sync(&msc->battery_timer);
  847. hid_hw_stop(hdev);
  848. return ret;
  849. }
  850. static void magicmouse_remove(struct hid_device *hdev)
  851. {
  852. struct magicmouse_sc *msc = hid_get_drvdata(hdev);
  853. if (msc) {
  854. cancel_delayed_work_sync(&msc->work);
  855. if (is_usb_magicmouse2(hdev->vendor, hdev->product) ||
  856. is_usb_magictrackpad2(hdev->vendor, hdev->product))
  857. timer_delete_sync(&msc->battery_timer);
  858. }
  859. hid_hw_stop(hdev);
  860. }
  861. static const __u8 *magicmouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  862. unsigned int *rsize)
  863. {
  864. /*
  865. * Change the usage from:
  866. * 0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1) 0
  867. * 0x09, 0x0b, // Usage (Vendor Usage 0x0b) 3
  868. * To:
  869. * 0x05, 0x01, // Usage Page (Generic Desktop) 0
  870. * 0x09, 0x02, // Usage (Mouse) 2
  871. */
  872. if ((is_usb_magicmouse2(hdev->vendor, hdev->product) ||
  873. is_usb_magictrackpad2(hdev->vendor, hdev->product)) &&
  874. *rsize >= 83 && rdesc[46] == 0x84 && rdesc[58] == 0x85) {
  875. hid_info(hdev,
  876. "fixing up magicmouse battery report descriptor\n");
  877. *rsize = *rsize - 1;
  878. rdesc = rdesc + 1;
  879. rdesc[0] = 0x05;
  880. rdesc[1] = 0x01;
  881. rdesc[2] = 0x09;
  882. rdesc[3] = 0x02;
  883. }
  884. return rdesc;
  885. }
  886. static const struct hid_device_id magic_mice[] = {
  887. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  888. USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 },
  889. { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
  890. USB_DEVICE_ID_APPLE_MAGICMOUSE2), .driver_data = 0 },
  891. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
  892. USB_DEVICE_ID_APPLE_MAGICMOUSE2), .driver_data = 0 },
  893. { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
  894. USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC), .driver_data = 0 },
  895. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
  896. USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC), .driver_data = 0 },
  897. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  898. USB_DEVICE_ID_APPLE_MAGICTRACKPAD), .driver_data = 0 },
  899. { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
  900. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2), .driver_data = 0 },
  901. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
  902. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2), .driver_data = 0 },
  903. { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
  904. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
  905. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
  906. USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
  907. { }
  908. };
  909. MODULE_DEVICE_TABLE(hid, magic_mice);
  910. static struct hid_driver magicmouse_driver = {
  911. .name = "magicmouse",
  912. .id_table = magic_mice,
  913. .probe = magicmouse_probe,
  914. .remove = magicmouse_remove,
  915. .report_fixup = magicmouse_report_fixup,
  916. .raw_event = magicmouse_raw_event,
  917. .event = magicmouse_event,
  918. .input_mapping = magicmouse_input_mapping,
  919. .input_configured = magicmouse_input_configured,
  920. };
  921. module_hid_driver(magicmouse_driver);
  922. MODULE_DESCRIPTION("Apple \"Magic\" Wireless Mouse driver");
  923. MODULE_LICENSE("GPL");