aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse/appletouch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/mouse/appletouch.c')
-rw-r--r--drivers/input/mouse/appletouch.c113
1 files changed, 76 insertions, 37 deletions
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index e3215267db11..a1804bfdbb8c 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -155,6 +155,8 @@ struct atp {
155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
156 int overflowwarn; /* overflow warning printed? */ 156 int overflowwarn; /* overflow warning printed? */
157 int datalen; /* size of an USB urb transfer */ 157 int datalen; /* size of an USB urb transfer */
158 int idlecount; /* number of empty packets */
159 struct work_struct work;
158}; 160};
159 161
160#define dbg_dump(msg, tab) \ 162#define dbg_dump(msg, tab) \
@@ -208,6 +210,55 @@ static inline int atp_is_geyser_3(struct atp *dev)
208 (productId == GEYSER4_JIS_PRODUCT_ID); 210 (productId == GEYSER4_JIS_PRODUCT_ID);
209} 211}
210 212
213/*
214 * By default Geyser 3 device sends standard USB HID mouse
215 * packets (Report ID 2). This code changes device mode, so it
216 * sends raw sensor reports (Report ID 5).
217 */
218static int atp_geyser3_init(struct usb_device *udev)
219{
220 char data[8];
221 int size;
222
223 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
224 ATP_GEYSER3_MODE_READ_REQUEST_ID,
225 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
226 ATP_GEYSER3_MODE_REQUEST_VALUE,
227 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
228
229 if (size != 8) {
230 err("Could not do mode read request from device"
231 " (Geyser 3 mode)");
232 return -EIO;
233 }
234
235 /* Apply the mode switch */
236 data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE;
237
238 size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
239 ATP_GEYSER3_MODE_WRITE_REQUEST_ID,
240 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
241 ATP_GEYSER3_MODE_REQUEST_VALUE,
242 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
243
244 if (size != 8) {
245 err("Could not do mode write request to device"
246 " (Geyser 3 mode)");
247 return -EIO;
248 }
249 return 0;
250}
251
252/* Reinitialise the device if it's a geyser 3 */
253static void atp_reinit(struct work_struct *work)
254{
255 struct atp *dev = container_of(work, struct atp, work);
256 struct usb_device *udev = dev->udev;
257
258 dev->idlecount = 0;
259 atp_geyser3_init(udev);
260}
261
211static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, 262static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
212 int *z, int *fingers) 263 int *z, int *fingers)
213{ 264{
@@ -277,6 +328,7 @@ static void atp_complete(struct urb* urb)
277{ 328{
278 int x, y, x_z, y_z, x_f, y_f; 329 int x, y, x_z, y_z, x_f, y_f;
279 int retval, i, j; 330 int retval, i, j;
331 int key;
280 struct atp *dev = urb->context; 332 struct atp *dev = urb->context;
281 333
282 switch (urb->status) { 334 switch (urb->status) {
@@ -417,6 +469,7 @@ static void atp_complete(struct urb* urb)
417 ATP_XFACT, &x_z, &x_f); 469 ATP_XFACT, &x_z, &x_f);
418 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, 470 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
419 ATP_YFACT, &y_z, &y_f); 471 ATP_YFACT, &y_z, &y_f);
472 key = dev->data[dev->datalen - 1] & 1;
420 473
421 if (x && y) { 474 if (x && y) {
422 if (dev->x_old != -1) { 475 if (dev->x_old != -1) {
@@ -439,8 +492,8 @@ static void atp_complete(struct urb* urb)
439 } 492 }
440 dev->x_old = x; 493 dev->x_old = x;
441 dev->y_old = y; 494 dev->y_old = y;
442 } 495
443 else if (!x && !y) { 496 } else if (!x && !y) {
444 497
445 dev->x_old = dev->y_old = -1; 498 dev->x_old = dev->y_old = -1;
446 input_report_key(dev->input, BTN_TOUCH, 0); 499 input_report_key(dev->input, BTN_TOUCH, 0);
@@ -449,11 +502,21 @@ static void atp_complete(struct urb* urb)
449 502
450 /* reset the accumulator on release */ 503 /* reset the accumulator on release */
451 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); 504 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
452 }
453 505
454 input_report_key(dev->input, BTN_LEFT, 506 /* Geyser 3 will continue to send packets continually after
455 !!dev->data[dev->datalen - 1]); 507 the first touch unless reinitialised. Do so if it's been
508 idle for a while in order to avoid waking the kernel up
509 several hundred times a second */
510 if (!key && atp_is_geyser_3(dev)) {
511 dev->idlecount++;
512 if (dev->idlecount == 10) {
513 dev->valid = 0;
514 schedule_work(&dev->work);
515 }
516 }
517 }
456 518
519 input_report_key(dev->input, BTN_LEFT, key);
457 input_sync(dev->input); 520 input_sync(dev->input);
458 521
459exit: 522exit:
@@ -480,6 +543,7 @@ static void atp_close(struct input_dev *input)
480 struct atp *dev = input_get_drvdata(input); 543 struct atp *dev = input_get_drvdata(input);
481 544
482 usb_kill_urb(dev->urb); 545 usb_kill_urb(dev->urb);
546 cancel_work_sync(&dev->work);
483 dev->open = 0; 547 dev->open = 0;
484} 548}
485 549
@@ -528,40 +592,10 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
528 dev->datalen = 81; 592 dev->datalen = 81;
529 593
530 if (atp_is_geyser_3(dev)) { 594 if (atp_is_geyser_3(dev)) {
531 /* 595 /* switch to raw sensor mode */
532 * By default Geyser 3 device sends standard USB HID mouse 596 if (atp_geyser3_init(udev))
533 * packets (Report ID 2). This code changes device mode, so it
534 * sends raw sensor reports (Report ID 5).
535 */
536 char data[8];
537 int size;
538
539 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
540 ATP_GEYSER3_MODE_READ_REQUEST_ID,
541 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
542 ATP_GEYSER3_MODE_REQUEST_VALUE,
543 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
544
545 if (size != 8) {
546 err("Could not do mode read request from device"
547 " (Geyser 3 mode)");
548 goto err_free_devs; 597 goto err_free_devs;
549 }
550
551 /* Apply the mode switch */
552 data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE;
553
554 size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
555 ATP_GEYSER3_MODE_WRITE_REQUEST_ID,
556 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
557 ATP_GEYSER3_MODE_REQUEST_VALUE,
558 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
559 598
560 if (size != 8) {
561 err("Could not do mode write request to device"
562 " (Geyser 3 mode)");
563 goto err_free_devs;
564 }
565 printk("appletouch Geyser 3 inited.\n"); 599 printk("appletouch Geyser 3 inited.\n");
566 } 600 }
567 601
@@ -636,6 +670,8 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
636 /* save our data pointer in this interface device */ 670 /* save our data pointer in this interface device */
637 usb_set_intfdata(iface, dev); 671 usb_set_intfdata(iface, dev);
638 672
673 INIT_WORK(&dev->work, atp_reinit);
674
639 return 0; 675 return 0;
640 676
641 err_free_buffer: 677 err_free_buffer:
@@ -669,14 +705,17 @@ static void atp_disconnect(struct usb_interface *iface)
669static int atp_suspend(struct usb_interface *iface, pm_message_t message) 705static int atp_suspend(struct usb_interface *iface, pm_message_t message)
670{ 706{
671 struct atp *dev = usb_get_intfdata(iface); 707 struct atp *dev = usb_get_intfdata(iface);
708
672 usb_kill_urb(dev->urb); 709 usb_kill_urb(dev->urb);
673 dev->valid = 0; 710 dev->valid = 0;
711
674 return 0; 712 return 0;
675} 713}
676 714
677static int atp_resume(struct usb_interface *iface) 715static int atp_resume(struct usb_interface *iface)
678{ 716{
679 struct atp *dev = usb_get_intfdata(iface); 717 struct atp *dev = usb_get_intfdata(iface);
718
680 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) 719 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
681 return -EIO; 720 return -EIO;
682 721