aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-magicmouse.c
diff options
context:
space:
mode:
authorMichael Poole <mdpoole@troilus.org>2010-09-24 07:58:18 -0400
committerJiri Kosina <jkosina@suse.cz>2010-09-24 07:59:13 -0400
commit64eb105d7f92fa48798106ac0d8bf17668eb2524 (patch)
tree2df6c2377c152d657558fb2a39bc9c441f1d9c0d /drivers/hid/hid-magicmouse.c
parenta462230e16acc8664145216da3c928d03556691a (diff)
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>
Diffstat (limited to 'drivers/hid/hid-magicmouse.c')
-rw-r--r--drivers/hid/hid-magicmouse.c81
1 files changed, 18 insertions, 63 deletions
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 8791a084693e..5e1907a51446 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -279,13 +279,6 @@ static int magicmouse_raw_event(struct hid_device *hdev,
279 int x = 0, y = 0, ii, clicks = 0, npoints; 279 int x = 0, y = 0, ii, clicks = 0, npoints;
280 280
281 switch (data[0]) { 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 case TRACKPAD_REPORT_ID: 282 case TRACKPAD_REPORT_ID:
290 /* Expect four bytes of prefix, and N*9 bytes of touch data. */ 283 /* Expect four bytes of prefix, and N*9 bytes of touch data. */
291 if (size < 4 || ((size - 4) % 9) != 0) 284 if (size < 4 || ((size - 4) % 9) != 0)
@@ -343,13 +336,6 @@ static int magicmouse_raw_event(struct hid_device *hdev,
343 magicmouse_raw_event(hdev, report, data + 2 + data[1], 336 magicmouse_raw_event(hdev, report, data + 2 + data[1],
344 size - 2 - data[1]); 337 size - 2 - data[1]);
345 break; 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 default: 339 default:
354 return 0; 340 return 0;
355 } 341 }
@@ -377,36 +363,8 @@ static int magicmouse_raw_event(struct hid_device *hdev,
377 return 1; 363 return 1;
378} 364}
379 365
380static 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
387static 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
394static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev) 366static 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 __set_bit(EV_KEY, input->evbit); 368 __set_bit(EV_KEY, input->evbit);
411 369
412 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { 370 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
@@ -466,11 +424,22 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
466 } 424 }
467} 425}
468 426
427static 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
469static int magicmouse_probe(struct hid_device *hdev, 439static int magicmouse_probe(struct hid_device *hdev,
470 const struct hid_device_id *id) 440 const struct hid_device_id *id)
471{ 441{
472 __u8 feature[] = { 0xd7, 0x01 }; 442 __u8 feature[] = { 0xd7, 0x01 };
473 struct input_dev *input;
474 struct magicmouse_sc *msc; 443 struct magicmouse_sc *msc;
475 struct hid_report *report; 444 struct hid_report *report;
476 int ret; 445 int ret;
@@ -500,8 +469,11 @@ static int magicmouse_probe(struct hid_device *hdev,
500 goto err_free; 469 goto err_free;
501 } 470 }
502 471
503 /* we are handling the input ourselves */ 472 /* We do this after hid-input is done parsing reports so that
504 hidinput_disconnect(hdev); 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 if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) 478 if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
507 report = hid_register_report(hdev, HID_INPUT_REPORT, 479 report = hid_register_report(hdev, HID_INPUT_REPORT,
@@ -528,24 +500,7 @@ static int magicmouse_probe(struct hid_device *hdev,
528 goto err_stop_hw; 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 return 0; 503 return 0;
547err_input:
548 input_free_device(input);
549err_stop_hw: 504err_stop_hw:
550 hid_hw_stop(hdev); 505 hid_hw_stop(hdev);
551err_free: 506err_free:
@@ -558,7 +513,6 @@ static void magicmouse_remove(struct hid_device *hdev)
558 struct magicmouse_sc *msc = hid_get_drvdata(hdev); 513 struct magicmouse_sc *msc = hid_get_drvdata(hdev);
559 514
560 hid_hw_stop(hdev); 515 hid_hw_stop(hdev);
561 input_unregister_device(msc->input);
562 kfree(msc); 516 kfree(msc);
563} 517}
564 518
@@ -577,6 +531,7 @@ static struct hid_driver magicmouse_driver = {
577 .probe = magicmouse_probe, 531 .probe = magicmouse_probe,
578 .remove = magicmouse_remove, 532 .remove = magicmouse_remove,
579 .raw_event = magicmouse_raw_event, 533 .raw_event = magicmouse_raw_event,
534 .input_mapping = magicmouse_input_mapping,
580}; 535};
581 536
582static int __init magicmouse_init(void) 537static int __init magicmouse_init(void)