Input: appletouch - handle geyser 3/4 status bits

Implement support for status bits on Geyser 3/4.

Signed-off-by: Sven Anders <anders@anduras.de>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
Sven Anders 2008-08-08 16:31:33 -04:00 committed by Dmitry Torokhov
parent d83d213d9f
commit 82a196f481

View file

@ -136,12 +136,28 @@ MODULE_DEVICE_TABLE(usb, atp_table);
#define ATP_GEYSER_MODE_REQUEST_INDEX 0 #define ATP_GEYSER_MODE_REQUEST_INDEX 0
#define ATP_GEYSER_MODE_VENDOR_VALUE 0x04 #define ATP_GEYSER_MODE_VENDOR_VALUE 0x04
/**
* enum atp_status_bits - status bit meanings
*
* These constants represent the meaning of the status bits.
* (only Geyser 3/4)
*
* @ATP_STATUS_BUTTON: The button was pressed
* @ATP_STATUS_BASE_UPDATE: Update of the base values (untouched pad)
* @ATP_STATUS_FROM_RESET: Reset previously performed
*/
enum atp_status_bits {
ATP_STATUS_BUTTON = BIT(0),
ATP_STATUS_BASE_UPDATE = BIT(2),
ATP_STATUS_FROM_RESET = BIT(4),
};
/* Structure to hold all of our device specific stuff */ /* Structure to hold all of our device specific stuff */
struct atp { struct atp {
char phys[64]; char phys[64];
struct usb_device *udev; /* usb device */ struct usb_device *udev; /* usb device */
struct urb *urb; /* usb request block */ struct urb *urb; /* usb request block */
signed char *data; /* transferred data */ u8 *data; /* transferred data */
struct input_dev *input; /* input dev */ struct input_dev *input; /* input dev */
enum atp_touchpad_type type; /* type of touchpad */ enum atp_touchpad_type type; /* type of touchpad */
bool open; bool open;
@ -251,8 +267,6 @@ static void atp_reinit(struct work_struct *work)
int retval; int retval;
dprintk("appletouch: putting appletouch to sleep (reinit)\n"); dprintk("appletouch: putting appletouch to sleep (reinit)\n");
dev->idlecount = 0;
atp_geyser_init(udev); atp_geyser_init(udev);
retval = usb_submit_urb(dev->urb, GFP_ATOMIC); retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
@ -488,7 +502,7 @@ static void atp_complete_geyser_1_2(struct urb *urb)
ATP_XFACT, &x_z, &x_f); ATP_XFACT, &x_z, &x_f);
y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
ATP_YFACT, &y_z, &y_f); ATP_YFACT, &y_z, &y_f);
key = dev->data[dev->datalen - 1] & 1; key = dev->data[dev->datalen - 1] & ATP_STATUS_BUTTON;
if (x && y) { if (x && y) {
if (dev->x_old != -1) { if (dev->x_old != -1) {
@ -568,34 +582,38 @@ static void atp_complete_geyser_3_4(struct urb *urb)
dbg_dump("sample", dev->xy_cur); dbg_dump("sample", dev->xy_cur);
if (!dev->valid) { /* Just update the base values (i.e. touchpad in untouched state) */
/* first sample */ if (dev->data[dev->datalen - 1] & ATP_STATUS_BASE_UPDATE) {
dev->valid = true;
dev->x_old = dev->y_old = -1;
memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
dprintk(KERN_DEBUG "appletouch: updated base values\n");
memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
goto exit; goto exit;
} }
for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
/* accumulate the change */ /* calculate the change */
signed char change = dev->xy_old[i] - dev->xy_cur[i]; dev->xy_acc[i] = dev->xy_cur[i] - dev->xy_old[i];
dev->xy_acc[i] -= change;
/* this is a round-robin value, so couple with that */
if (dev->xy_acc[i] > 127)
dev->xy_acc[i] -= 256;
if (dev->xy_acc[i] < -127)
dev->xy_acc[i] += 256;
/* prevent down drifting */ /* prevent down drifting */
if (dev->xy_acc[i] < 0) if (dev->xy_acc[i] < 0)
dev->xy_acc[i] = 0; dev->xy_acc[i] = 0;
} }
memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
dbg_dump("accumulator", dev->xy_acc); dbg_dump("accumulator", dev->xy_acc);
x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS, x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS,
ATP_XFACT, &x_z, &x_f); ATP_XFACT, &x_z, &x_f);
y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
ATP_YFACT, &y_z, &y_f); ATP_YFACT, &y_z, &y_f);
key = dev->data[dev->datalen - 1] & 1; key = dev->data[dev->datalen - 1] & ATP_STATUS_BUTTON;
if (x && y) { if (x && y) {
if (dev->x_old != -1) { if (dev->x_old != -1) {
@ -647,7 +665,8 @@ static void atp_complete_geyser_3_4(struct urb *urb)
if (!x && !y && !key) { if (!x && !y && !key) {
dev->idlecount++; dev->idlecount++;
if (dev->idlecount == 10) { if (dev->idlecount == 10) {
dev->valid = false; dev->x_old = dev->y_old = -1;
dev->idlecount = 0;
schedule_work(&dev->work); schedule_work(&dev->work);
/* Don't resubmit urb here, wait for reinit */ /* Don't resubmit urb here, wait for reinit */
return; return;
@ -879,8 +898,6 @@ static int atp_suspend(struct usb_interface *iface, pm_message_t message)
struct atp *dev = usb_get_intfdata(iface); struct atp *dev = usb_get_intfdata(iface);
usb_kill_urb(dev->urb); usb_kill_urb(dev->urb);
dev->valid = false;
return 0; return 0;
} }