^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2005-2008 Stelian Pop (stelian@popies.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Note: We try to keep the touchpad aspect ratio while still doing only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * simple arithmetics:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * 0 <= x <= (xsensors - 1) * xfact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * 0 <= y <= (ysensors - 1) * yfact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct atp_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int xsensors; /* number of X sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int xsensors_17; /* 17" models have more sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int ysensors; /* number of Y sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int xfact; /* X multiplication factor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int yfact; /* Y multiplication factor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int datalen; /* size of USB transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void (*callback)(struct urb *); /* callback function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int fuzz; /* fuzz touchpad generates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static void atp_complete_geyser_1_2(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void atp_complete_geyser_3_4(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const struct atp_info fountain_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .xsensors = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .xsensors_17 = 26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .ysensors = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .xfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .yfact = 43,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .datalen = 81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .callback = atp_complete_geyser_1_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .fuzz = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static const struct atp_info geyser1_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .xsensors = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .xsensors_17 = 26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .ysensors = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .xfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .yfact = 43,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .datalen = 81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .callback = atp_complete_geyser_1_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .fuzz = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static const struct atp_info geyser2_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .xsensors = 15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .xsensors_17 = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .ysensors = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .xfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .yfact = 43,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .datalen = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .callback = atp_complete_geyser_1_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .fuzz = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static const struct atp_info geyser3_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .xsensors = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .ysensors = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .xfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .yfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .datalen = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .callback = atp_complete_geyser_3_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .fuzz = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const struct atp_info geyser4_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .xsensors = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .ysensors = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .xfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .yfact = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .datalen = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .callback = atp_complete_geyser_3_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .fuzz = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define ATP_DEVICE(prod, info) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) USB_DEVICE_ID_MATCH_INT_CLASS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .idVendor = 0x05ac, /* Apple */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .idProduct = (prod), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .bInterfaceClass = 0x03, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .bInterfaceProtocol = 0x02, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .driver_info = (unsigned long) &info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Table of devices (Product IDs) that work with this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * (The names come from Info.plist in AppleUSBTrackpad.kext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * According to Info.plist Geyser IV is the same as Geyser III.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static const struct usb_device_id atp_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* PowerBooks Feb 2005, iBooks G4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ATP_DEVICE(0x020e, fountain_info), /* FOUNTAIN ANSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ATP_DEVICE(0x020f, fountain_info), /* FOUNTAIN ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ATP_DEVICE(0x030a, fountain_info), /* FOUNTAIN TP ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ATP_DEVICE(0x030b, geyser1_info), /* GEYSER 1 TP ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* PowerBooks Oct 2005 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ATP_DEVICE(0x0214, geyser2_info), /* GEYSER 2 ANSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ATP_DEVICE(0x0215, geyser2_info), /* GEYSER 2 ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ATP_DEVICE(0x0216, geyser2_info), /* GEYSER 2 JIS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* Core Duo MacBook & MacBook Pro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ATP_DEVICE(0x0217, geyser3_info), /* GEYSER 3 ANSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ATP_DEVICE(0x0218, geyser3_info), /* GEYSER 3 ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ATP_DEVICE(0x0219, geyser3_info), /* GEYSER 3 JIS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* Core2 Duo MacBook & MacBook Pro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ATP_DEVICE(0x021a, geyser4_info), /* GEYSER 4 ANSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ATP_DEVICE(0x021b, geyser4_info), /* GEYSER 4 ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ATP_DEVICE(0x021c, geyser4_info), /* GEYSER 4 JIS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* Core2 Duo MacBook3,1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ATP_DEVICE(0x0229, geyser4_info), /* GEYSER 4 HF ANSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ATP_DEVICE(0x022a, geyser4_info), /* GEYSER 4 HF ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ATP_DEVICE(0x022b, geyser4_info), /* GEYSER 4 HF JIS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) MODULE_DEVICE_TABLE(usb, atp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* maximum number of sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define ATP_XSENSORS 26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define ATP_YSENSORS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * The largest possible bank of sensors with additional buffer of 4 extra values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * on either side, for an array of smoothed sensor values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define ATP_SMOOTHSIZE 34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* maximum pressure this driver will report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define ATP_PRESSURE 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define ATP_THRESHOLD 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * How far we'll bitshift our sensor values before averaging them. Mitigates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * rounding errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define ATP_SCALE 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Geyser initialization constants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define ATP_GEYSER_MODE_READ_REQUEST_ID 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define ATP_GEYSER_MODE_WRITE_REQUEST_ID 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #define ATP_GEYSER_MODE_REQUEST_VALUE 0x300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define ATP_GEYSER_MODE_REQUEST_INDEX 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define ATP_GEYSER_MODE_VENDOR_VALUE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * enum atp_status_bits - status bit meanings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * These constants represent the meaning of the status bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * (only Geyser 3/4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @ATP_STATUS_BUTTON: The button was pressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @ATP_STATUS_BASE_UPDATE: Update of the base values (untouched pad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * @ATP_STATUS_FROM_RESET: Reset previously performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) enum atp_status_bits {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ATP_STATUS_BUTTON = BIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ATP_STATUS_BASE_UPDATE = BIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ATP_STATUS_FROM_RESET = BIT(4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Structure to hold all of our device specific stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct atp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct usb_device *udev; /* usb device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct usb_interface *intf; /* usb interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct urb *urb; /* usb request block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) u8 *data; /* transferred data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct input_dev *input; /* input dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) const struct atp_info *info; /* touchpad model */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) bool open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) bool valid; /* are the samples valid? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) bool size_detect_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) bool overflow_warned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int fingers_old; /* last reported finger count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int x_old; /* last reported x/y, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int y_old; /* used for smoothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int smooth[ATP_SMOOTHSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int smooth_tmp[ATP_SMOOTHSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int idlecount; /* number of empty packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define dbg_dump(msg, tab) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (debug > 1) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int __i; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) printk(KERN_DEBUG "appletouch: %s", msg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) printk(" %02x", tab[__i]); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) printk("\n"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define dprintk(format, a...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (debug) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) printk(KERN_DEBUG format, ##a); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) MODULE_AUTHOR("Johannes Berg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) MODULE_AUTHOR("Stelian Pop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) MODULE_AUTHOR("Frank Arnold");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) MODULE_AUTHOR("Michael Hanselmann");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) MODULE_AUTHOR("Sven Anders");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * Make the threshold a module parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int threshold = ATP_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) module_param(threshold, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) " (the trackpad has many of these sensors)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) " less than this value.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) MODULE_PARM_DESC(debug, "Activate debugging output");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * By default newer Geyser devices send standard USB HID mouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * packets (Report ID 2). This code changes device mode, so it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * sends raw sensor reports (Report ID 5).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int atp_geyser_init(struct atp *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct usb_device *udev = dev->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) data = kmalloc(8, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) dev_err(&dev->intf->dev, "Out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ATP_GEYSER_MODE_READ_REQUEST_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ATP_GEYSER_MODE_REQUEST_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ATP_GEYSER_MODE_REQUEST_INDEX, data, 8, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (size != 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) dprintk("atp_geyser_init: read error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) dprintk("appletouch[%d]: %d\n", i, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) dev_err(&dev->intf->dev, "Failed to read mode from device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Apply the mode switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) data[0] = ATP_GEYSER_MODE_VENDOR_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ATP_GEYSER_MODE_WRITE_REQUEST_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ATP_GEYSER_MODE_REQUEST_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ATP_GEYSER_MODE_REQUEST_INDEX, data, 8, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (size != 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dprintk("atp_geyser_init: write error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) dprintk("appletouch[%d]: %d\n", i, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dev_err(&dev->intf->dev, "Failed to request geyser raw mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * Reinitialise the device. This usually stops stream of empty packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * coming from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static void atp_reinit(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct atp *dev = container_of(work, struct atp, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) dprintk("appletouch: putting appletouch to sleep (reinit)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) atp_geyser_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) "atp_reinit: usb_submit_urb failed with error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int atp_calculate_abs(struct atp *dev, int offset, int nb_sensors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int fact, int *z, int *fingers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) int i, pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * Use offset to point xy_sensors at the first value in dev->xy_acc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * for whichever dimension we're looking at this particular go-round.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int *xy_sensors = dev->xy_acc + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* values to calculate mean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int pcum = 0, psum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int is_increasing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) *fingers = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) for (i = 0; i < nb_sensors; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (xy_sensors[i] < threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (is_increasing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) is_increasing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * Makes the finger detection more versatile. For example,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * two fingers with no gap will be detected. Also, my
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * tests show it less likely to have intermittent loss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * of multiple finger readings while moving around (scrolling).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * Changes the multiple finger detection to counting humps on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * sensors (transitions from nonincreasing to increasing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * instead of counting transitions from low sensors (no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * finger reading) to high sensors (finger above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * sensor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * - Jason Parekh <jasonparekh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) } else if (i < 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) (*fingers)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) is_increasing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) } else if (i > 0 && (xy_sensors[i - 1] - xy_sensors[i] > threshold)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) is_increasing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (*fingers < 1) /* No need to continue if no fingers are found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * Use a smoothed version of sensor data for movement calculations, to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * combat noise without needing to rely so heavily on a threshold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * This improves tracking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * The smoothed array is bigger than the original so that the smoothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * doesn't result in edge values being truncated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) memset(dev->smooth, 0, 4 * sizeof(dev->smooth[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* Pull base values, scaled up to help avoid truncation errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) for (i = 0; i < nb_sensors; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev->smooth[i + 4] = xy_sensors[i] << ATP_SCALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) memset(&dev->smooth[nb_sensors + 4], 0, 4 * sizeof(dev->smooth[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) for (pass = 0; pass < 4; pass++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* Handle edge. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) dev->smooth_tmp[0] = (dev->smooth[0] + dev->smooth[1]) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /* Average values with neighbors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) for (i = 1; i < nb_sensors + 7; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) dev->smooth_tmp[i] = (dev->smooth[i - 1] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev->smooth[i] * 2 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) dev->smooth[i + 1]) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Handle other edge. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dev->smooth_tmp[i] = (dev->smooth[i - 1] + dev->smooth[i]) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) memcpy(dev->smooth, dev->smooth_tmp, sizeof(dev->smooth));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) for (i = 0; i < nb_sensors + 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * Skip values if they're small enough to be truncated to 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * by scale. Mostly noise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if ((dev->smooth[i] >> ATP_SCALE) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) pcum += dev->smooth[i] * i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) psum += dev->smooth[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (psum > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *z = psum >> ATP_SCALE; /* Scale down pressure output. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return pcum * fact / psum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static inline void atp_report_fingers(struct input_dev *input, int fingers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) input_report_key(input, BTN_TOOL_FINGER, fingers == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* Check URB status and for correct length of data package */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #define ATP_URB_STATUS_SUCCESS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) #define ATP_URB_STATUS_ERROR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) #define ATP_URB_STATUS_ERROR_FATAL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int atp_status_check(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct atp *dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct usb_interface *intf = dev->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) case -EOVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (!dev->overflow_warned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) dev_warn(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) "appletouch: OVERFLOW with data length %d, actual length is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) dev->info->datalen, dev->urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) dev->overflow_warned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* This urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) dev_dbg(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) "atp_complete: urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return ATP_URB_STATUS_ERROR_FATAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) dev_dbg(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) "atp_complete: nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return ATP_URB_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* drop incomplete datasets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (dev->urb->actual_length != dev->info->datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) dprintk("appletouch: incomplete data package"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) " (first byte: %d, length: %d).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) dev->data[0], dev->urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return ATP_URB_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return ATP_URB_STATUS_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static void atp_detect_size(struct atp *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* 17" Powerbooks have extra X sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) for (i = dev->info->xsensors; i < ATP_XSENSORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (dev->xy_cur[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) dev_info(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) "appletouch: 17\" model detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) input_set_abs_params(dev->input, ABS_X, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) (dev->info->xsensors_17 - 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) dev->info->xfact - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) dev->info->fuzz, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * USB interrupt callback functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* Interrupt function for older touchpads: FOUNTAIN/GEYSER1/GEYSER2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static void atp_complete_geyser_1_2(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int x, y, x_z, y_z, x_f, y_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) int retval, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int key, fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct atp *dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) int status = atp_status_check(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (status == ATP_URB_STATUS_ERROR_FATAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) else if (status == ATP_URB_STATUS_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* reorder the sensors values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (dev->info == &geyser2_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * The values are laid out like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * '-' is an unused value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /* read X values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) for (i = 0, j = 19; i < 20; i += 2, j += 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dev->xy_cur[i] = dev->data[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) dev->xy_cur[i + 1] = dev->data[j + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* read Y values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) for (i = 0, j = 1; i < 9; i += 2, j += 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) dev->xy_cur[ATP_XSENSORS + i] = dev->data[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* X values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) dev->xy_cur[i + 0] = dev->data[5 * i + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) dev->xy_cur[i + 8] = dev->data[5 * i + 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dev->xy_cur[i + 16] = dev->data[5 * i + 42];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (i < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) dev->xy_cur[i + 24] = dev->data[5 * i + 44];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* Y values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) dev->xy_cur[ATP_XSENSORS + i] = dev->data[5 * i + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) dev->xy_cur[ATP_XSENSORS + i + 8] = dev->data[5 * i + 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) dbg_dump("sample", dev->xy_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (!dev->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* first sample */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) dev->valid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /* Store first sample */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* Perform size detection, if not done already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (unlikely(!dev->size_detect_done)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) atp_detect_size(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) dev->size_detect_done = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* accumulate the change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) signed char change = dev->xy_old[i] - dev->xy_cur[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) dev->xy_acc[i] -= change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* prevent down drifting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (dev->xy_acc[i] < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) dev->xy_acc[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) dbg_dump("accumulator", dev->xy_acc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) x = atp_calculate_abs(dev, 0, ATP_XSENSORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) dev->info->xfact, &x_z, &x_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) y = atp_calculate_abs(dev, ATP_XSENSORS, ATP_YSENSORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dev->info->yfact, &y_z, &y_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) fingers = max(x_f, y_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (x && y && fingers == dev->fingers_old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (dev->x_old != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) x = (dev->x_old * 7 + x) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) y = (dev->y_old * 7 + y) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) dev->x_old = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) dev->y_old = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (debug > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) printk(KERN_DEBUG "appletouch: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) "X: %3d Y: %3d Xz: %3d Yz: %3d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) x, y, x_z, y_z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) input_report_key(dev->input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) input_report_abs(dev->input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) input_report_abs(dev->input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) input_report_abs(dev->input, ABS_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) min(ATP_PRESSURE, x_z + y_z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) atp_report_fingers(dev->input, fingers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) dev->x_old = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) dev->y_old = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) } else if (!x && !y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) dev->fingers_old = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) input_report_key(dev->input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) input_report_abs(dev->input, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) atp_report_fingers(dev->input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* reset the accumulator on release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (fingers != dev->fingers_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) dev->fingers_old = fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) input_report_key(dev->input, BTN_LEFT, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) input_sync(dev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) "atp_complete: usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /* Interrupt function for older touchpads: GEYSER3/GEYSER4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static void atp_complete_geyser_3_4(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int x, y, x_z, y_z, x_f, y_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int retval, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int key, fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct atp *dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) int status = atp_status_check(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (status == ATP_URB_STATUS_ERROR_FATAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) else if (status == ATP_URB_STATUS_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* Reorder the sensors values:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * The values are laid out like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * '-' is an unused value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) /* read X values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) for (i = 0, j = 19; i < 20; i += 2, j += 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) dev->xy_cur[i] = dev->data[j + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) dev->xy_cur[i + 1] = dev->data[j + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /* read Y values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) for (i = 0, j = 1; i < 9; i += 2, j += 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) dbg_dump("sample", dev->xy_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /* Just update the base values (i.e. touchpad in untouched state) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (dev->data[dev->info->datalen - 1] & ATP_STATUS_BASE_UPDATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dprintk("appletouch: updated base values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* calculate the change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) dev->xy_acc[i] = dev->xy_cur[i] - dev->xy_old[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /* this is a round-robin value, so couple with that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (dev->xy_acc[i] > 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) dev->xy_acc[i] -= 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (dev->xy_acc[i] < -127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) dev->xy_acc[i] += 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /* prevent down drifting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (dev->xy_acc[i] < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) dev->xy_acc[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) dbg_dump("accumulator", dev->xy_acc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) x = atp_calculate_abs(dev, 0, ATP_XSENSORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) dev->info->xfact, &x_z, &x_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) y = atp_calculate_abs(dev, ATP_XSENSORS, ATP_YSENSORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) dev->info->yfact, &y_z, &y_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) fingers = max(x_f, y_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (x && y && fingers == dev->fingers_old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (dev->x_old != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) x = (dev->x_old * 7 + x) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) y = (dev->y_old * 7 + y) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) dev->x_old = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) dev->y_old = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (debug > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) printk(KERN_DEBUG "appletouch: X: %3d Y: %3d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) "Xz: %3d Yz: %3d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) x, y, x_z, y_z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) input_report_key(dev->input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) input_report_abs(dev->input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) input_report_abs(dev->input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) input_report_abs(dev->input, ABS_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) min(ATP_PRESSURE, x_z + y_z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) atp_report_fingers(dev->input, fingers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) dev->x_old = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) dev->y_old = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) } else if (!x && !y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) dev->fingers_old = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) input_report_key(dev->input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) input_report_abs(dev->input, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) atp_report_fingers(dev->input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* reset the accumulator on release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (fingers != dev->fingers_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) dev->fingers_old = fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) input_report_key(dev->input, BTN_LEFT, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) input_sync(dev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) * Geysers 3/4 will continue to send packets continually after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * the first touch unless reinitialised. Do so if it's been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * idle for a while in order to avoid waking the kernel up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * several hundred times a second.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * Button must not be pressed when entering suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * otherwise we will never release the button.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (!x && !y && !key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) dev->idlecount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (dev->idlecount == 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) dev->x_old = dev->y_old = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) dev->idlecount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) schedule_work(&dev->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* Don't resubmit urb here, wait for reinit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev->idlecount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) "atp_complete: usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) static int atp_open(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) struct atp *dev = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (usb_submit_urb(dev->urb, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) dev->open = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static void atp_close(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct atp *dev = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) usb_kill_urb(dev->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) cancel_work_sync(&dev->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) dev->open = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) static int atp_handle_geyser(struct atp *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (dev->info != &fountain_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) /* switch to raw sensor mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (atp_geyser_init(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) dev_info(&dev->intf->dev, "Geyser mode initialized.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) static int atp_probe(struct usb_interface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct atp *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct usb_device *udev = interface_to_usbdev(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct usb_host_interface *iface_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct usb_endpoint_descriptor *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) int int_in_endpointAddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) int i, error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) const struct atp_info *info = (const struct atp_info *)id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* set up the endpoint information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) /* use only the first interrupt-in endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) iface_desc = iface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) endpoint = &iface_desc->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* we found an interrupt in endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) int_in_endpointAddr = endpoint->bEndpointAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (!int_in_endpointAddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) dev_err(&iface->dev, "Could not find int-in endpoint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* allocate memory for our device state and initialize it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) dev = kzalloc(sizeof(struct atp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!dev || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) dev_err(&iface->dev, "Out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) goto err_free_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) dev->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) dev->intf = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) dev->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) dev->info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) dev->overflow_warned = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) dev->urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (!dev->urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) goto err_free_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) dev->data = usb_alloc_coherent(dev->udev, dev->info->datalen, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) &dev->urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (!dev->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) usb_fill_int_urb(dev->urb, udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) usb_rcvintpipe(udev, int_in_endpointAddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) dev->data, dev->info->datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) dev->info->callback, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) error = atp_handle_geyser(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) goto err_free_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) usb_make_path(udev, dev->phys, sizeof(dev->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) strlcat(dev->phys, "/input0", sizeof(dev->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) input_dev->name = "appletouch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) input_dev->phys = dev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) usb_to_input_id(dev->udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) input_dev->dev.parent = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) input_set_drvdata(input_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) input_dev->open = atp_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) input_dev->close = atp_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) set_bit(EV_ABS, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) input_set_abs_params(input_dev, ABS_X, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) (dev->info->xsensors - 1) * dev->info->xfact - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) dev->info->fuzz, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) input_set_abs_params(input_dev, ABS_Y, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) (dev->info->ysensors - 1) * dev->info->yfact - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) dev->info->fuzz, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) set_bit(BTN_TOUCH, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) set_bit(BTN_TOOL_FINGER, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) set_bit(BTN_LEFT, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) INIT_WORK(&dev->work, atp_reinit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) error = input_register_device(dev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) goto err_free_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /* save our data pointer in this interface device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) usb_set_intfdata(iface, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) err_free_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) usb_free_coherent(dev->udev, dev->info->datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) dev->data, dev->urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) err_free_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) usb_free_urb(dev->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) err_free_devs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) usb_set_intfdata(iface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) static void atp_disconnect(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct atp *dev = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) usb_set_intfdata(iface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) usb_kill_urb(dev->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) input_unregister_device(dev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) usb_free_coherent(dev->udev, dev->info->datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) dev->data, dev->urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) usb_free_urb(dev->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) dev_info(&iface->dev, "input: appletouch disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) static int atp_recover(struct atp *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) error = atp_handle_geyser(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static int atp_suspend(struct usb_interface *iface, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) struct atp *dev = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) usb_kill_urb(dev->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) static int atp_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct atp *dev = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) static int atp_reset_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct atp *dev = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return atp_recover(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) static struct usb_driver atp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) .name = "appletouch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) .probe = atp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) .disconnect = atp_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) .suspend = atp_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) .resume = atp_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) .reset_resume = atp_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) .id_table = atp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) module_usb_driver(atp_driver);