Lines Matching +full:max +full:- +full:fingers

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
5 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net)
7 * Copyright (C) 2005-2008 Stelian Pop (stelian@popies.net)
8 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
10 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
12 * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de)
26 * 0 <= x <= (xsensors - 1) * xfact
27 * 0 <= y <= (ysensors - 1) * yfact
179 * enum atp_status_bits - status bit meanings
262 struct usb_device *udev = dev->udev; in atp_geyser_init()
270 dev_err(&dev->intf->dev, "Out of memory\n"); in atp_geyser_init()
271 return -ENOMEM; in atp_geyser_init()
285 dev_err(&dev->intf->dev, "Failed to read mode from device.\n"); in atp_geyser_init()
286 ret = -EIO; in atp_geyser_init()
304 dev_err(&dev->intf->dev, "Failed to request geyser raw mode\n"); in atp_geyser_init()
305 ret = -EIO; in atp_geyser_init()
326 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); in atp_reinit()
328 dev_err(&dev->intf->dev, in atp_reinit()
334 int fact, int *z, int *fingers) in atp_calculate_abs() argument
339 * Use offset to point xy_sensors at the first value in dev->xy_acc in atp_calculate_abs()
340 * for whichever dimension we're looking at this particular go-round. in atp_calculate_abs()
342 int *xy_sensors = dev->xy_acc + offset; in atp_calculate_abs()
348 *fingers = 0; in atp_calculate_abs()
357 * two fingers with no gap will be detected. Also, my in atp_calculate_abs()
367 * - Jason Parekh <jasonparekh@gmail.com> in atp_calculate_abs()
371 (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { in atp_calculate_abs()
372 (*fingers)++; in atp_calculate_abs()
374 } else if (i > 0 && (xy_sensors[i - 1] - xy_sensors[i] > threshold)) { in atp_calculate_abs()
379 if (*fingers < 1) /* No need to continue if no fingers are found. */ in atp_calculate_abs()
391 memset(dev->smooth, 0, 4 * sizeof(dev->smooth[0])); in atp_calculate_abs()
394 dev->smooth[i + 4] = xy_sensors[i] << ATP_SCALE; in atp_calculate_abs()
395 memset(&dev->smooth[nb_sensors + 4], 0, 4 * sizeof(dev->smooth[0])); in atp_calculate_abs()
399 dev->smooth_tmp[0] = (dev->smooth[0] + dev->smooth[1]) / 2; in atp_calculate_abs()
403 dev->smooth_tmp[i] = (dev->smooth[i - 1] + in atp_calculate_abs()
404 dev->smooth[i] * 2 + in atp_calculate_abs()
405 dev->smooth[i + 1]) / 4; in atp_calculate_abs()
408 dev->smooth_tmp[i] = (dev->smooth[i - 1] + dev->smooth[i]) / 2; in atp_calculate_abs()
410 memcpy(dev->smooth, dev->smooth_tmp, sizeof(dev->smooth)); in atp_calculate_abs()
418 if ((dev->smooth[i] >> ATP_SCALE) > 0) { in atp_calculate_abs()
419 pcum += dev->smooth[i] * i; in atp_calculate_abs()
420 psum += dev->smooth[i]; in atp_calculate_abs()
432 static inline void atp_report_fingers(struct input_dev *input, int fingers) in atp_report_fingers() argument
434 input_report_key(input, BTN_TOOL_FINGER, fingers == 1); in atp_report_fingers()
435 input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2); in atp_report_fingers()
436 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); in atp_report_fingers()
447 struct atp *dev = urb->context; in atp_status_check()
448 struct usb_interface *intf = dev->intf; in atp_status_check()
450 switch (urb->status) { in atp_status_check()
454 case -EOVERFLOW: in atp_status_check()
455 if (!dev->overflow_warned) { in atp_status_check()
456 dev_warn(&intf->dev, in atp_status_check()
458 dev->info->datalen, dev->urb->actual_length); in atp_status_check()
459 dev->overflow_warned = true; in atp_status_check()
462 case -ECONNRESET: in atp_status_check()
463 case -ENOENT: in atp_status_check()
464 case -ESHUTDOWN: in atp_status_check()
466 dev_dbg(&intf->dev, in atp_status_check()
468 urb->status); in atp_status_check()
472 dev_dbg(&intf->dev, in atp_status_check()
474 urb->status); in atp_status_check()
479 if (dev->urb->actual_length != dev->info->datalen) { in atp_status_check()
482 dev->data[0], dev->urb->actual_length); in atp_status_check()
494 for (i = dev->info->xsensors; i < ATP_XSENSORS; i++) { in atp_detect_size()
495 if (dev->xy_cur[i]) { in atp_detect_size()
497 dev_info(&dev->intf->dev, in atp_detect_size()
500 input_set_abs_params(dev->input, ABS_X, 0, in atp_detect_size()
501 (dev->info->xsensors_17 - 1) * in atp_detect_size()
502 dev->info->xfact - 1, in atp_detect_size()
503 dev->info->fuzz, 0); in atp_detect_size()
519 int key, fingers; in atp_complete_geyser_1_2() local
520 struct atp *dev = urb->context; in atp_complete_geyser_1_2()
529 if (dev->info == &geyser2_info) { in atp_complete_geyser_1_2()
530 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); in atp_complete_geyser_1_2()
534 * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ... in atp_complete_geyser_1_2()
535 * '-' is an unused value. in atp_complete_geyser_1_2()
540 dev->xy_cur[i] = dev->data[j]; in atp_complete_geyser_1_2()
541 dev->xy_cur[i + 1] = dev->data[j + 1]; in atp_complete_geyser_1_2()
546 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j]; in atp_complete_geyser_1_2()
547 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1]; in atp_complete_geyser_1_2()
552 dev->xy_cur[i + 0] = dev->data[5 * i + 2]; in atp_complete_geyser_1_2()
553 dev->xy_cur[i + 8] = dev->data[5 * i + 4]; in atp_complete_geyser_1_2()
554 dev->xy_cur[i + 16] = dev->data[5 * i + 42]; in atp_complete_geyser_1_2()
556 dev->xy_cur[i + 24] = dev->data[5 * i + 44]; in atp_complete_geyser_1_2()
559 dev->xy_cur[ATP_XSENSORS + i] = dev->data[5 * i + 1]; in atp_complete_geyser_1_2()
560 dev->xy_cur[ATP_XSENSORS + i + 8] = dev->data[5 * i + 3]; in atp_complete_geyser_1_2()
564 dbg_dump("sample", dev->xy_cur); in atp_complete_geyser_1_2()
566 if (!dev->valid) { in atp_complete_geyser_1_2()
568 dev->valid = true; in atp_complete_geyser_1_2()
569 dev->x_old = dev->y_old = -1; in atp_complete_geyser_1_2()
572 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); in atp_complete_geyser_1_2()
575 if (unlikely(!dev->size_detect_done)) { in atp_complete_geyser_1_2()
577 dev->size_detect_done = true; in atp_complete_geyser_1_2()
584 signed char change = dev->xy_old[i] - dev->xy_cur[i]; in atp_complete_geyser_1_2()
585 dev->xy_acc[i] -= change; in atp_complete_geyser_1_2()
588 if (dev->xy_acc[i] < 0) in atp_complete_geyser_1_2()
589 dev->xy_acc[i] = 0; in atp_complete_geyser_1_2()
592 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); in atp_complete_geyser_1_2()
594 dbg_dump("accumulator", dev->xy_acc); in atp_complete_geyser_1_2()
597 dev->info->xfact, &x_z, &x_f); in atp_complete_geyser_1_2()
599 dev->info->yfact, &y_z, &y_f); in atp_complete_geyser_1_2()
600 key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON; in atp_complete_geyser_1_2()
602 fingers = max(x_f, y_f); in atp_complete_geyser_1_2()
604 if (x && y && fingers == dev->fingers_old) { in atp_complete_geyser_1_2()
605 if (dev->x_old != -1) { in atp_complete_geyser_1_2()
606 x = (dev->x_old * 7 + x) >> 3; in atp_complete_geyser_1_2()
607 y = (dev->y_old * 7 + y) >> 3; in atp_complete_geyser_1_2()
608 dev->x_old = x; in atp_complete_geyser_1_2()
609 dev->y_old = y; in atp_complete_geyser_1_2()
616 input_report_key(dev->input, BTN_TOUCH, 1); in atp_complete_geyser_1_2()
617 input_report_abs(dev->input, ABS_X, x); in atp_complete_geyser_1_2()
618 input_report_abs(dev->input, ABS_Y, y); in atp_complete_geyser_1_2()
619 input_report_abs(dev->input, ABS_PRESSURE, in atp_complete_geyser_1_2()
621 atp_report_fingers(dev->input, fingers); in atp_complete_geyser_1_2()
623 dev->x_old = x; in atp_complete_geyser_1_2()
624 dev->y_old = y; in atp_complete_geyser_1_2()
628 dev->x_old = dev->y_old = -1; in atp_complete_geyser_1_2()
629 dev->fingers_old = 0; in atp_complete_geyser_1_2()
630 input_report_key(dev->input, BTN_TOUCH, 0); in atp_complete_geyser_1_2()
631 input_report_abs(dev->input, ABS_PRESSURE, 0); in atp_complete_geyser_1_2()
632 atp_report_fingers(dev->input, 0); in atp_complete_geyser_1_2()
635 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); in atp_complete_geyser_1_2()
638 if (fingers != dev->fingers_old) in atp_complete_geyser_1_2()
639 dev->x_old = dev->y_old = -1; in atp_complete_geyser_1_2()
640 dev->fingers_old = fingers; in atp_complete_geyser_1_2()
642 input_report_key(dev->input, BTN_LEFT, key); in atp_complete_geyser_1_2()
643 input_sync(dev->input); in atp_complete_geyser_1_2()
646 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); in atp_complete_geyser_1_2()
648 dev_err(&dev->intf->dev, in atp_complete_geyser_1_2()
659 int key, fingers; in atp_complete_geyser_3_4() local
660 struct atp *dev = urb->context; in atp_complete_geyser_3_4()
671 * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ... in atp_complete_geyser_3_4()
672 * '-' is an unused value. in atp_complete_geyser_3_4()
677 dev->xy_cur[i] = dev->data[j + 1]; in atp_complete_geyser_3_4()
678 dev->xy_cur[i + 1] = dev->data[j + 2]; in atp_complete_geyser_3_4()
682 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; in atp_complete_geyser_3_4()
683 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; in atp_complete_geyser_3_4()
686 dbg_dump("sample", dev->xy_cur); in atp_complete_geyser_3_4()
689 if (dev->data[dev->info->datalen - 1] & ATP_STATUS_BASE_UPDATE) { in atp_complete_geyser_3_4()
693 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); in atp_complete_geyser_3_4()
699 dev->xy_acc[i] = dev->xy_cur[i] - dev->xy_old[i]; in atp_complete_geyser_3_4()
701 /* this is a round-robin value, so couple with that */ in atp_complete_geyser_3_4()
702 if (dev->xy_acc[i] > 127) in atp_complete_geyser_3_4()
703 dev->xy_acc[i] -= 256; in atp_complete_geyser_3_4()
705 if (dev->xy_acc[i] < -127) in atp_complete_geyser_3_4()
706 dev->xy_acc[i] += 256; in atp_complete_geyser_3_4()
709 if (dev->xy_acc[i] < 0) in atp_complete_geyser_3_4()
710 dev->xy_acc[i] = 0; in atp_complete_geyser_3_4()
713 dbg_dump("accumulator", dev->xy_acc); in atp_complete_geyser_3_4()
716 dev->info->xfact, &x_z, &x_f); in atp_complete_geyser_3_4()
718 dev->info->yfact, &y_z, &y_f); in atp_complete_geyser_3_4()
720 key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON; in atp_complete_geyser_3_4()
722 fingers = max(x_f, y_f); in atp_complete_geyser_3_4()
724 if (x && y && fingers == dev->fingers_old) { in atp_complete_geyser_3_4()
725 if (dev->x_old != -1) { in atp_complete_geyser_3_4()
726 x = (dev->x_old * 7 + x) >> 3; in atp_complete_geyser_3_4()
727 y = (dev->y_old * 7 + y) >> 3; in atp_complete_geyser_3_4()
728 dev->x_old = x; in atp_complete_geyser_3_4()
729 dev->y_old = y; in atp_complete_geyser_3_4()
736 input_report_key(dev->input, BTN_TOUCH, 1); in atp_complete_geyser_3_4()
737 input_report_abs(dev->input, ABS_X, x); in atp_complete_geyser_3_4()
738 input_report_abs(dev->input, ABS_Y, y); in atp_complete_geyser_3_4()
739 input_report_abs(dev->input, ABS_PRESSURE, in atp_complete_geyser_3_4()
741 atp_report_fingers(dev->input, fingers); in atp_complete_geyser_3_4()
743 dev->x_old = x; in atp_complete_geyser_3_4()
744 dev->y_old = y; in atp_complete_geyser_3_4()
748 dev->x_old = dev->y_old = -1; in atp_complete_geyser_3_4()
749 dev->fingers_old = 0; in atp_complete_geyser_3_4()
750 input_report_key(dev->input, BTN_TOUCH, 0); in atp_complete_geyser_3_4()
751 input_report_abs(dev->input, ABS_PRESSURE, 0); in atp_complete_geyser_3_4()
752 atp_report_fingers(dev->input, 0); in atp_complete_geyser_3_4()
755 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); in atp_complete_geyser_3_4()
758 if (fingers != dev->fingers_old) in atp_complete_geyser_3_4()
759 dev->x_old = dev->y_old = -1; in atp_complete_geyser_3_4()
760 dev->fingers_old = fingers; in atp_complete_geyser_3_4()
762 input_report_key(dev->input, BTN_LEFT, key); in atp_complete_geyser_3_4()
763 input_sync(dev->input); in atp_complete_geyser_3_4()
777 dev->idlecount++; in atp_complete_geyser_3_4()
778 if (dev->idlecount == 10) { in atp_complete_geyser_3_4()
779 dev->x_old = dev->y_old = -1; in atp_complete_geyser_3_4()
780 dev->idlecount = 0; in atp_complete_geyser_3_4()
781 schedule_work(&dev->work); in atp_complete_geyser_3_4()
786 dev->idlecount = 0; in atp_complete_geyser_3_4()
789 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); in atp_complete_geyser_3_4()
791 dev_err(&dev->intf->dev, in atp_complete_geyser_3_4()
800 if (usb_submit_urb(dev->urb, GFP_KERNEL)) in atp_open()
801 return -EIO; in atp_open()
803 dev->open = true; in atp_open()
811 usb_kill_urb(dev->urb); in atp_close()
812 cancel_work_sync(&dev->work); in atp_close()
813 dev->open = false; in atp_close()
818 if (dev->info != &fountain_info) { in atp_handle_geyser()
821 return -EIO; in atp_handle_geyser()
823 dev_info(&dev->intf->dev, "Geyser mode initialized.\n"); in atp_handle_geyser()
838 int i, error = -ENOMEM; in atp_probe()
839 const struct atp_info *info = (const struct atp_info *)id->driver_info; in atp_probe()
842 /* use only the first interrupt-in endpoint */ in atp_probe()
843 iface_desc = iface->cur_altsetting; in atp_probe()
844 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { in atp_probe()
845 endpoint = &iface_desc->endpoint[i].desc; in atp_probe()
848 int_in_endpointAddr = endpoint->bEndpointAddress; in atp_probe()
853 dev_err(&iface->dev, "Could not find int-in endpoint\n"); in atp_probe()
854 return -EIO; in atp_probe()
861 dev_err(&iface->dev, "Out of memory\n"); in atp_probe()
865 dev->udev = udev; in atp_probe()
866 dev->intf = iface; in atp_probe()
867 dev->input = input_dev; in atp_probe()
868 dev->info = info; in atp_probe()
869 dev->overflow_warned = false; in atp_probe()
871 dev->urb = usb_alloc_urb(0, GFP_KERNEL); in atp_probe()
872 if (!dev->urb) in atp_probe()
875 dev->data = usb_alloc_coherent(dev->udev, dev->info->datalen, GFP_KERNEL, in atp_probe()
876 &dev->urb->transfer_dma); in atp_probe()
877 if (!dev->data) in atp_probe()
880 usb_fill_int_urb(dev->urb, udev, in atp_probe()
882 dev->data, dev->info->datalen, in atp_probe()
883 dev->info->callback, dev, 1); in atp_probe()
889 usb_make_path(udev, dev->phys, sizeof(dev->phys)); in atp_probe()
890 strlcat(dev->phys, "/input0", sizeof(dev->phys)); in atp_probe()
892 input_dev->name = "appletouch"; in atp_probe()
893 input_dev->phys = dev->phys; in atp_probe()
894 usb_to_input_id(dev->udev, &input_dev->id); in atp_probe()
895 input_dev->dev.parent = &iface->dev; in atp_probe()
899 input_dev->open = atp_open; in atp_probe()
900 input_dev->close = atp_close; in atp_probe()
902 set_bit(EV_ABS, input_dev->evbit); in atp_probe()
905 (dev->info->xsensors - 1) * dev->info->xfact - 1, in atp_probe()
906 dev->info->fuzz, 0); in atp_probe()
908 (dev->info->ysensors - 1) * dev->info->yfact - 1, in atp_probe()
909 dev->info->fuzz, 0); in atp_probe()
912 set_bit(EV_KEY, input_dev->evbit); in atp_probe()
913 set_bit(BTN_TOUCH, input_dev->keybit); in atp_probe()
914 set_bit(BTN_TOOL_FINGER, input_dev->keybit); in atp_probe()
915 set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); in atp_probe()
916 set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); in atp_probe()
917 set_bit(BTN_LEFT, input_dev->keybit); in atp_probe()
919 INIT_WORK(&dev->work, atp_reinit); in atp_probe()
921 error = input_register_device(dev->input); in atp_probe()
931 usb_free_coherent(dev->udev, dev->info->datalen, in atp_probe()
932 dev->data, dev->urb->transfer_dma); in atp_probe()
934 usb_free_urb(dev->urb); in atp_probe()
948 usb_kill_urb(dev->urb); in atp_disconnect()
949 input_unregister_device(dev->input); in atp_disconnect()
950 usb_free_coherent(dev->udev, dev->info->datalen, in atp_disconnect()
951 dev->data, dev->urb->transfer_dma); in atp_disconnect()
952 usb_free_urb(dev->urb); in atp_disconnect()
955 dev_info(&iface->dev, "input: appletouch disconnected\n"); in atp_disconnect()
966 if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL)) in atp_recover()
967 return -EIO; in atp_recover()
976 usb_kill_urb(dev->urb); in atp_suspend()
984 if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL)) in atp_resume()
985 return -EIO; in atp_resume()