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