Commit 64eb105d7f92fa48798106ac0d8bf17668eb2524
Committed by
Jiri Kosina
1 parent
a462230e16
Exists in
master
and in
7 other branches
HID: magicmouse: Use hid-input parsing rather than bypassing it
Let the HID core handle input device setup and HID-compliant reports. This driver then only has to worry about the non-standard reports. Signed-off-by: Michael Poole <mdpoole@troilus.org> Acked-by: Chase Douglas <chase.douglas@canonical.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Showing 1 changed file with 18 additions and 63 deletions Side-by-side Diff
drivers/hid/hid-magicmouse.c
... | ... | @@ -279,13 +279,6 @@ |
279 | 279 | int x = 0, y = 0, ii, clicks = 0, npoints; |
280 | 280 | |
281 | 281 | switch (data[0]) { |
282 | - case 0x10: | |
283 | - if (size != 6) | |
284 | - return 0; | |
285 | - x = (__s16)(data[2] | data[3] << 8); | |
286 | - y = (__s16)(data[4] | data[5] << 8); | |
287 | - clicks = data[1]; | |
288 | - break; | |
289 | 282 | case TRACKPAD_REPORT_ID: |
290 | 283 | /* Expect four bytes of prefix, and N*9 bytes of touch data. */ |
291 | 284 | if (size < 4 || ((size - 4) % 9) != 0) |
... | ... | @@ -343,13 +336,6 @@ |
343 | 336 | magicmouse_raw_event(hdev, report, data + 2 + data[1], |
344 | 337 | size - 2 - data[1]); |
345 | 338 | break; |
346 | - case 0x20: /* Theoretically battery status (0-100), but I have | |
347 | - * never seen it -- maybe it is only upon request. | |
348 | - */ | |
349 | - case 0x60: /* Unknown, maybe laser on/off. */ | |
350 | - case 0x61: /* Laser reflection status change. | |
351 | - * data[1]: 0 = spotted, 1 = lost | |
352 | - */ | |
353 | 339 | default: |
354 | 340 | return 0; |
355 | 341 | } |
356 | 342 | |
... | ... | @@ -377,36 +363,8 @@ |
377 | 363 | return 1; |
378 | 364 | } |
379 | 365 | |
380 | -static int magicmouse_input_open(struct input_dev *dev) | |
381 | -{ | |
382 | - struct hid_device *hid = input_get_drvdata(dev); | |
383 | - | |
384 | - return hid->ll_driver->open(hid); | |
385 | -} | |
386 | - | |
387 | -static void magicmouse_input_close(struct input_dev *dev) | |
388 | -{ | |
389 | - struct hid_device *hid = input_get_drvdata(dev); | |
390 | - | |
391 | - hid->ll_driver->close(hid); | |
392 | -} | |
393 | - | |
394 | 366 | static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev) |
395 | 367 | { |
396 | - input_set_drvdata(input, hdev); | |
397 | - input->event = hdev->ll_driver->hidinput_input_event; | |
398 | - input->open = magicmouse_input_open; | |
399 | - input->close = magicmouse_input_close; | |
400 | - | |
401 | - input->name = hdev->name; | |
402 | - input->phys = hdev->phys; | |
403 | - input->uniq = hdev->uniq; | |
404 | - input->id.bustype = hdev->bus; | |
405 | - input->id.vendor = hdev->vendor; | |
406 | - input->id.product = hdev->product; | |
407 | - input->id.version = hdev->version; | |
408 | - input->dev.parent = hdev->dev.parent; | |
409 | - | |
410 | 368 | __set_bit(EV_KEY, input->evbit); |
411 | 369 | |
412 | 370 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { |
413 | 371 | |
... | ... | @@ -466,11 +424,22 @@ |
466 | 424 | } |
467 | 425 | } |
468 | 426 | |
427 | +static int magicmouse_input_mapping(struct hid_device *hdev, | |
428 | + struct hid_input *hi, struct hid_field *field, | |
429 | + struct hid_usage *usage, unsigned long **bit, int *max) | |
430 | +{ | |
431 | + struct magicmouse_sc *msc = hid_get_drvdata(hdev); | |
432 | + | |
433 | + if (!msc->input) | |
434 | + msc->input = hi->input; | |
435 | + | |
436 | + return 0; | |
437 | +} | |
438 | + | |
469 | 439 | static int magicmouse_probe(struct hid_device *hdev, |
470 | 440 | const struct hid_device_id *id) |
471 | 441 | { |
472 | 442 | __u8 feature[] = { 0xd7, 0x01 }; |
473 | - struct input_dev *input; | |
474 | 443 | struct magicmouse_sc *msc; |
475 | 444 | struct hid_report *report; |
476 | 445 | int ret; |
... | ... | @@ -500,8 +469,11 @@ |
500 | 469 | goto err_free; |
501 | 470 | } |
502 | 471 | |
503 | - /* we are handling the input ourselves */ | |
504 | - hidinput_disconnect(hdev); | |
472 | + /* We do this after hid-input is done parsing reports so that | |
473 | + * hid-input uses the most natural button and axis IDs. | |
474 | + */ | |
475 | + if (msc->input) | |
476 | + magicmouse_setup_input(msc->input, hdev); | |
505 | 477 | |
506 | 478 | if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) |
507 | 479 | report = hid_register_report(hdev, HID_INPUT_REPORT, |
508 | 480 | |
... | ... | @@ -528,24 +500,7 @@ |
528 | 500 | goto err_stop_hw; |
529 | 501 | } |
530 | 502 | |
531 | - input = input_allocate_device(); | |
532 | - if (!input) { | |
533 | - dev_err(&hdev->dev, "can't alloc input device\n"); | |
534 | - ret = -ENOMEM; | |
535 | - goto err_stop_hw; | |
536 | - } | |
537 | - magicmouse_setup_input(input, hdev); | |
538 | - | |
539 | - ret = input_register_device(input); | |
540 | - if (ret) { | |
541 | - dev_err(&hdev->dev, "input device registration failed\n"); | |
542 | - goto err_input; | |
543 | - } | |
544 | - msc->input = input; | |
545 | - | |
546 | 503 | return 0; |
547 | -err_input: | |
548 | - input_free_device(input); | |
549 | 504 | err_stop_hw: |
550 | 505 | hid_hw_stop(hdev); |
551 | 506 | err_free: |
... | ... | @@ -558,7 +513,6 @@ |
558 | 513 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); |
559 | 514 | |
560 | 515 | hid_hw_stop(hdev); |
561 | - input_unregister_device(msc->input); | |
562 | 516 | kfree(msc); |
563 | 517 | } |
564 | 518 | |
... | ... | @@ -577,6 +531,7 @@ |
577 | 531 | .probe = magicmouse_probe, |
578 | 532 | .remove = magicmouse_remove, |
579 | 533 | .raw_event = magicmouse_raw_event, |
534 | + .input_mapping = magicmouse_input_mapping, | |
580 | 535 | }; |
581 | 536 | |
582 | 537 | static int __init magicmouse_init(void) |