From 5bd76821fca3d6422a586b691436583224158b01 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 16 Nov 2010 14:25:19 +0100 Subject: Experimental mainline MT support This patchset is in flux, and a cooperative effort between Takashi Iwai, Chase Douglas, Chris Bagwell and myself. Signed-off-by: Henrik Rydberg --- usr/src/dkms_source_tree/Makefile | 2 +- usr/src/dkms_source_tree/input-mt.c | 307 +++++++++++++++++++++++++++++++++++ usr/src/dkms_source_tree/input-mt.h | 56 +++++++ usr/src/dkms_source_tree/synaptics.c | 247 ++++++++++++++++++---------- usr/src/dkms_source_tree/synaptics.h | 10 +- 5 files changed, 534 insertions(+), 88 deletions(-) create mode 100644 usr/src/dkms_source_tree/input-mt.c create mode 100644 usr/src/dkms_source_tree/input-mt.h (limited to 'usr/src/dkms_source_tree') diff --git a/usr/src/dkms_source_tree/Makefile b/usr/src/dkms_source_tree/Makefile index 8a48755..e543a38 100644 --- a/usr/src/dkms_source_tree/Makefile +++ b/usr/src/dkms_source_tree/Makefile @@ -6,7 +6,7 @@ obj-m += psmouse.o -psmouse-objs := psmouse-base.o synaptics.o +psmouse-objs := psmouse-base.o synaptics.o input-mt.o psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o psmouse-$(CONFIG_MOUSE_PS2_ELANTECH) += elantech.o diff --git a/usr/src/dkms_source_tree/input-mt.c b/usr/src/dkms_source_tree/input-mt.c new file mode 100644 index 0000000..236360f --- /dev/null +++ b/usr/src/dkms_source_tree/input-mt.c @@ -0,0 +1,307 @@ +/* + * Input Multitouch Library + * + * Copyright (c) 2008-2010 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include "input-mt.h" + + +#define TRKID_BITS 16 +#define TRKID_MAX ((1 << TRKID_BITS) - 1) +#define TRKID_SGN (1 << (TRKID_BITS - 1)) + +static int trkid; // destined for input_dev + +int input_mt_create_slots_new(struct input_dev *dev, unsigned int num_slots) +{ + int ret; + + ret = input_mt_create_slots(dev, num_slots); + if (ret) + return ret; + + input_set_abs_params(dev, ABS_MT_TRACKING_ID, 0, TRKID_MAX, 0, 0); + + return 0; +} + +/** + * input_mt_report_state() - report contact state + * @dev: input device with allocated MT slots + * @active: true if contact is active, false otherwise + * + * Reports an active touch via ABS_MT_TRACKING_ID. If active is + * true and the slot is currently inactive, a new tracking id is + * assigned to the slot. + */ +void input_mt_report_state(struct input_dev *dev, bool active) +{ + int id = -1; + + if (dev->mt && active) { + id = input_mt_get_value(&dev->mt[dev->slot], ABS_MT_TRACKING_ID); + if (id < 0) + id = trkid++ & TRKID_MAX; + } + + input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id); +} + +/** + * input_mt_report_emulation() - common pointer emulation + * @dev: input device with allocated MT slots + * + * Performs legacy emulation emulation via BTN_TOUCH, etc. + */ +void input_mt_report_emulation(struct input_dev *dev) +{ + struct input_mt_slot *oldest = 0; + int oldid = -1; + int count = 0; + int i; + + for (i = 0; i < dev->mtsize; ++i) { + struct input_mt_slot *slot = &dev->mt[i]; + int id = input_mt_get_value(slot, ABS_MT_TRACKING_ID); + + if (id < 0) + continue; + + if (!oldest || ((id - oldid) & TRKID_SGN)) { + oldest = slot; + oldid = id; + } + count++; + } + + input_event(dev, EV_KEY, BTN_TOUCH, count > 0); + input_event(dev, EV_KEY, BTN_TOOL_FINGER, count == 1); + input_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, count == 2); + input_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, count == 3); + input_event(dev, EV_KEY, BTN_TOOL_QUADTAP, count > 3); + + if (oldest) { + int x = input_mt_get_value(oldest, ABS_MT_POSITION_X); + int y = input_mt_get_value(oldest, ABS_MT_POSITION_Y); + int p = input_mt_get_value(oldest, ABS_MT_PRESSURE); + + input_event(dev, EV_ABS, ABS_X, x); + input_event(dev, EV_ABS, ABS_Y, y); + input_event(dev, EV_ABS, ABS_PRESSURE, p); + } else { + input_event(dev, EV_ABS,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 3, 1, 0, 2, 7, + 8, 13, 2, 3, 0, 1, 3, 4, 10, 13, 1, 3, 2, 0, 0, 7, + 10, 13, 0, 3, 2, 1, 2, 4, 11, 13, 1, 3, 0, 2, 0, 6, + 11, 13, 0, 3, 1, 2, 3, 5, 8, 14, 2, 1, 3, 0, 1, 7, + 8, 14, 2, 0, 3, 1, 3, 4, 9, 14, 1, 2, 3, 0, 0, 7, + 9, 14, 0, 2, 3, 1, 1, 4, 11, 14, 1, 0, 3, 2, 0, 5, + 11, 14, 0, 1, 3, 2, 2, 5, 8, 15, 2, 1, 0, 3, 1, 6, + 8, 15, 2, 0, 1, 3, 2, 4, 9, 15, 1, 2, 0, 3, 0, 6, + 9, 15, 0, 2, 1, 3, 1, 4, 10, 15, 1, 0, 2, 3, 0, 5, + 10, 15, 0, 1, 2, 3, +}; + +/* generated by mtdev-kernel - do not edit */ +static const int match_index[][5] = { + { 0, 0, 1, 3, 6 }, + { 10, 10, 12, 18, 30 }, + { 50, 50, 54, 62, 92 }, + { 164, 164, 170, 194, 230 }, + { 398, 398, 406, 454, 598 }, + { 790 } +}; + +static void set_dist(u32 *dist, + const struct trk_coord *b1, const struct trk_coord *e1, + const struct trk_coord *b2, const struct trk_coord *e2) +{ + const struct trk_coord *p, *q; + + for (p = b1; p != e1; p++) + for (q = b2; q != e2; q++) + *dist++ = abs(q->x - p->x) + abs(q->y - p->y); +} + +const u8 *match_four(const struct trk_coord *old, int nslot, + const struct trk_coord *pos, int npos) +{ + u32 d[16], obj, t; + const u8 *p, *b, *e; + const int *at; + + set_dist(d, old, old + nslot, pos, pos + npos); + + at = &match_index[nslot][npos]; + b = &match_data[at[0]]; + e = &match_data[at[1]]; + + obj = UINT_MAX, p = b; + + switch (min(nslot, npos)) { + case 1: + for (; b != e; b += npos) { + t = d[*b++]; + if (t < obj) + obj = t, p = b; + } + break; + case 2: + for (; b != e; b += npos) { + t = d[*b++], t += d[*b++]; + if (t < obj) + obj = t, p = b; + } + break; + case 3: + for (; b != e; b += npos) { + t = d[*b++], t += d[*b++], t += d[*b++]; + if (t < obj) + obj = t, p = b; + } + break; + case 4: + for (; b != e; b += npos) { + t = d[*b++], t += d[*b++], t += d[*b++], t += d[*b++]; + if (t < obj) + obj = t, p = b; + } + break; + } + + return p; +} + +/** + * input_mt_assign_slots_by_coord() - perform a best-match assignment + * @dev: input device with allocated MT slots + * @slots: the slot assignment to be filled + * @coords: the coordinate array to match + * @num_coords: number of coordinates + * + * Performs a best match against the current contacts and returns + * the slot assignment list. New contacts are assigned to unused + * slots. + * + * Returns zero on success, or negative error in case of failure. + */ +int input_mt_assign_slots_by_coord(struct input_dev *dev, int *slots, + const struct trk_coord *coords, + int num_coords) +{ + struct trk_coord old[4]; + int old2slot[4], nold, i; + const u8 *p; + + if (!dev->mt) + return -ENXIO; + if (dev->mtsize < 2 || dev->mtsize > 4) + return -ENXIO; + if (num_coords > dev->mtsize) + return -EINVAL; + if (num_coords < 1) + return 0; + + nold = 0; + for (i = 0; i < dev->mtsize; i++) { + const struct input_mt_slot *mt = &dev->mt[i]; + if (input_mt_get_value(mt, ABS_MT_TRACKING_ID) < 0) + continue; + old[nold].x = input_mt_get_value(mt, ABS_MT_POSITION_X); + old[nold].y = input_mt_get_value(mt, ABS_MT_POSITION_Y); + old2slot[nold++] = i; + } + + p = match_four(old, nold, coords, num_coords); + + for (i = 0; i < dev->mtsize; i++) + if (input_mt_get_value(&dev->mt[i], ABS_MT_TRACKING_ID) < 0) + old2slot[nold++] = i; + + for (i = 0; i < num_coords; i++) + slots[i] = old2slot[p[i]]; + + return 0; +} + + +/** + * input_mt_sync_slot_complement() - send touchup for remaining slots + * @dev: input device with allocated MT slots + * @slots: the slot assignment to be filled + * @coords: the coordinate array to match + * @num_coords: number of coordinates + * + * Performs a best match against the current contacts and returns + * the slot assignment list. New contacts are assigned to unused + * slots. + * + * Returns zero on success, or negative error in case of failure. + */ +void input_mt_sync_slot_complement(struct input_dev *dev, + const int *slots, int num_slots) +{ + unsigned long mask = 0; + int i; + + for (i = 0; i < num_slots; i++) + mask |= BIT(slots[i]); + + for (i = 0; i < dev->mtsize; i++) { + if (mask & BIT(i)) + continue; + input_mt_slot(dev, i); + input_mt_report_state(dev, false); + } +} diff --git a/usr/src/dkms_source_tree/input-mt.h b/usr/src/dkms_source_tree/input-mt.h new file mode 100644 index 0000000..fdee06e --- /dev/null +++ b/usr/src/dkms_source_tree/input-mt.h @@ -0,0 +1,56 @@ +#ifndef _INPUT_MT_H +#define _INPUT_MT_H + +/* + * Input Multitouch Library + * + * Copyright (c) 2010 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include + +/** + * struct trk_coord - contact coordinate + * @x: horizontal coordinate + * @y: vertical coordinate + */ +struct trk_coord { + int x; + int y; +}; + +int input_mt_create_slots_new(struct input_dev *dev, unsigned int num_slots); + +int input_mt_assign_slots_by_coord(struct input_dev *dev, int *slots, + const struct trk_coord *coords, + int num_coords); + +void input_mt_sync_slot_complement(struct input_dev *dev, + const int *slots, int num_slots); + +void input_mt_report_state(struct input_dev *dev, bool active); +void input_mt_report_emulation(struct input_dev *dev); + +static inline int input_mt_get_value(const struct input_mt_slot *slot, + unsigned code) +{ + return slot->abs[code - ABS_MT_FIRST]; +} + +static inline bool input_mt_get_state(struct input_dev *dev, int slot) +{ + return dev->mt && + input_mt_get_value(&dev->mt[slot], ABS_MT_TRACKING_ID) >= 0; +} + +static inline void input_abs_set_res(struct input_dev *dev, + unsigned int axis, int val) +{ + dev->absres[axis] = val; +} + +#endif diff --git a/usr/src/dkms_source_tree/synaptics.c b/usr/src/dkms_source_tree/synaptics.c index ae9891c..c19d39f 100644 --- a/usr/src/dkms_source_tree/synaptics.c +++ b/usr/src/dkms_source_tree/synaptics.c @@ -279,6 +279,24 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate) synaptics_mode_cmd(psmouse, priv->mode); } +static int synaptics_set_multitouch_mode(struct psmouse *psmouse) +{ + static unsigned char param = 0xc8; + struct synaptics_data *priv = psmouse->private; + + if (!SYN_CAP_MULTITOUCH(priv->ext_cap_0c)) + return 0; + + if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL)) + return -1; + if (ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE)) + return -1; + + priv->multitouch = 1; + printk(KERN_INFO "Synaptics: Multitouch mode enabled\n"); + return 0; +} + /***************************************************************************** * Synaptics pass-through PS/2 port support ****************************************************************************/ @@ -294,7 +312,29 @@ static int synaptics_pt_write(struct serio *serio, unsigned char c) return 0; } -static inline int synaptics_is_pt_packet(unsigned char *buf) +static int synaptics_pt_start(struct serio *serio) +{ + struct psmouse *parent = serio_get_drvdata(serio->parent); + struct synaptics_data *priv = parent->private; + + serio_pause_rx(parent->ps2dev.serio); + priv->pt_port = serio; + serio_continue_rx(parent->ps2dev.serio); + + return 0; +} + +static void synaptics_pt_stop(struct serio *serio) +{ + struct psmouse *parent = serio_get_drvdata(serio->parent); + struct synaptics_data *priv = parent->private; + + serio_pause_rx(parent->ps2dev.serio); + priv->pt_port = NULL; + serio_continue_rx(parent->ps2dev.serio); +} + +static int synaptics_is_pt_packet(unsigned char *buf) { return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; } @@ -315,9 +355,8 @@ static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet static void synaptics_pt_activate(struct psmouse *psmouse) { - struct serio *ptport = psmouse->ps2dev.serio->child; - struct psmouse *child = serio_get_drvdata(ptport); struct synaptics_data *priv = psmouse->private; + struct psmouse *child = serio_get_drvdata(priv->pt_port); /* adjust the touchpad to child's choice of protocol */ if (child) { @@ -345,6 +384,8 @@ static void synaptics_pt_create(struct psmouse *psmouse) strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); serio->write = synaptics_pt_write; + serio->start = synaptics_pt_start; + serio->stop = synaptics_pt_stop; serio->parent = psmouse->ps2dev.serio; psmouse->pt_activate = synaptics_pt_activate; @@ -357,62 +398,38 @@ static void synaptics_pt_create(struct psmouse *psmouse) * Functions to interpret the absolute mode packets ****************************************************************************/ -/* left and right clickpad button ranges; - * the gap between them is interpreted as a middle-button click - */ -#define CLICKPAD_LEFT_BTN_X \ - ((XMAX_NOMINAL - XMIN_NOMINAL) * 2 / 5 + XMIN_NOMINAL) -#define CLICKPAD_RIGHT_BTN_X \ - ((XMAX_NOMINAL - XMIN_NOMINAL) * 3 / 5 + XMIN_NOMINAL) - -/* handle clickpad events */ -static void clickpad_process_packet(struct synaptics_data *priv, - struct synaptics_hw_state *hw) -{ - /* clickpad mode reports Y range from 0 to YMAX_NOMINAL, - * where the area Y < YMIN_NOMINAL is used as click buttons - */ - if (hw->y < YMIN_NOMINAL) { - /* button area */ - hw->z = 0; /* don't move pointer */ - /* clickpad reports only the middle button, and we need - * to fake left/right buttons depending on the touch position - */ - if (hw->middle) { /* clicked? */ - hw->middle = 0; - if (hw->x < CLICKPAD_LEFT_BTN_X) - hw->left = 1; - else if (hw->x > CLICKPAD_RIGHT_BTN_X) - hw->right = 1; - else - hw->middle = 1; - } - } else if (hw->middle) { - /* dragging */ - hw->left = priv->prev_hw.left; - hw->right = priv->prev_hw.right; - hw->middle = priv->prev_hw.middle; - } - priv->prev_hw = *hw; -} - -static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw) +static int synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw) { memset(hw, 0, sizeof(struct synaptics_hw_state)); if (SYN_MODEL_NEWABS(priv->model_id)) { - hw->x = (((buf[3] & 0x10) << 8) | - ((buf[1] & 0x0f) << 8) | - buf[4]); - hw->y = (((buf[3] & 0x20) << 7) | - ((buf[1] & 0xf0) << 4) | - buf[5]); - - hw->z = buf[2]; hw->w = (((buf[0] & 0x30) >> 2) | ((buf[0] & 0x04) >> 1) | ((buf[3] & 0x04) >> 2)); + if (priv->multitouch && hw->w == 2) { + /* Multitouch data is half normal resolution */ + hw->x = (((buf[4] & 0x0f) << 8) | + buf[1]) << 1; + hw->y = (((buf[4] & 0xf0) << 4) | + buf[2]) << 1; + + hw->z = ((buf[3] & 0x30) | + (buf[5] & 0x0f)) << 1; + + /* Only look at x, y, and z for MT */ + return 1; + } else { + hw->x = (((buf[3] & 0x10) << 8) | + ((buf[1] & 0x0f) << 8) | + buf[4]); + hw->y = (((buf[3] & 0x20) << 7) | + ((buf[1] & 0xf0) << 4) | + buf[5]); + + hw->z = buf[2]; + } + hw->left = (buf[0] & 0x01) ? 1 : 0; hw->right = (buf[0] & 0x02) ? 1 : 0; @@ -468,6 +485,8 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data hw->left = (buf[0] & 0x01) ? 1 : 0; hw->right = (buf[0] & 0x02) ? 1 : 0; } + + return 0; } /* @@ -482,10 +501,11 @@ static void synaptics_process_packet(struct psmouse *psmouse) int finger_width; int i; - synaptics_parse_hw_state(psmouse->packet, priv, &hw); - - if (SYN_CAP_CLICKPAD(priv->ext_cap)) - clickpad_process_packet(priv, &hw); + if (synaptics_parse_hw_state(psmouse->packet, priv, &hw)) { + priv->mt_pkt = 1; + priv->mt = hw; + return; + } if (hw.scroll) { priv->scroll += hw.scroll; @@ -513,7 +533,8 @@ static void synaptics_process_packet(struct psmouse *psmouse) if (SYN_CAP_EXTENDED(priv->capabilities)) { switch (hw.w) { case 0 ... 1: - if (SYN_CAP_MULTIFINGER(priv->capabilities)) + if (SYN_CAP_MULTIFINGER(priv->capabilities) || + priv->multitouch) num_fingers = hw.w + 2; break; case 2: @@ -531,28 +552,64 @@ static void synaptics_process_packet(struct psmouse *psmouse) finger_width = 0; } - /* Post events - * BTN_TOUCH has to be first as mousedev relies on it when doing - * absolute -> relative conversion - */ - if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); - if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); + if (priv->multitouch) { + struct trk_coord pos[2]; + int slots[2]; + int npos; + + pos[0].x = hw.x; + pos[0].y = YMAX_NOMINAL + YMIN_NOMINAL - hw.y; + pos[1].x = priv->mt.x; + pos[1].y = YMAX_NOMINAL + YMIN_NOMINAL - priv->mt.y; + npos = priv->mt_pkt ? 2 : 1; + input_mt_assign_slots_by_coord(dev, slots, pos, npos); + + for (i = 0; i < npos; i++) { + int x = pos[i].x; + int y = pos[i].y; + int z = i == 0 ? hw.z : priv->mt.z; + int s = z > 0 && x > 1; + + input_mt_slot(dev, slots[i]); + input_mt_report_state(dev, s); + + if (s) { + input_report_abs(dev, ABS_MT_POSITION_X, x); + input_report_abs(dev, ABS_MT_POSITION_Y, y); + input_report_abs(dev, ABS_MT_PRESSURE, z); + } + } - if (hw.z > 0) { - input_report_abs(dev, ABS_X, hw.x); - input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y); + input_mt_sync_slot_complement(dev, slots, npos); + input_mt_report_emulation(dev); + } else { + + /* Post events + * BTN_TOUCH has to be first as mousedev relies on it when doing + * absolute -> relative conversion + */ + if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); + if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); + + if (hw.z > 0) { + input_report_abs(dev, ABS_X, hw.x); + input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y); + } + input_report_abs(dev, ABS_PRESSURE, hw.z); + + input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); + + if (SYN_CAP_MULTIFINGER(priv->capabilities) || priv->multitouch) { + input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); + input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); + } } - input_report_abs(dev, ABS_PRESSURE, hw.z); - input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); - input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); input_report_key(dev, BTN_LEFT, hw.left); input_report_key(dev, BTN_RIGHT, hw.right); - if (SYN_CAP_MULTIFINGER(priv->capabilities)) { - input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); - input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); - } + if (SYN_CAP_PALMDETECT(priv->capabilities)) + input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) input_report_key(dev, BTN_MIDDLE, hw.middle); @@ -566,6 +623,8 @@ static void synaptics_process_packet(struct psmouse *psmouse) input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i)); input_sync(dev); + + priv->mt_pkt = 0; } static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type) @@ -618,9 +677,10 @@ static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse) if (unlikely(priv->pkt_type == SYN_NEWABS)) priv->pkt_type = synaptics_detect_pkt_type(psmouse); - if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) { - if (psmouse->ps2dev.serio->child) - synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet); + if (SYN_CAP_PASS_THROUGH(priv->capabilities) && + synaptics_is_pt_packet(psmouse->packet)) { + if (priv->pt_port) + synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); } else synaptics_process_packet(psmouse); @@ -644,7 +704,18 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) input_set_abs_params(dev, ABS_Y, YMIN_NOMINAL, priv->y_max ?: YMAX_NOMINAL, 0, 0); input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); - __set_bit(ABS_TOOL_WIDTH, dev->absbit); + + if (priv->multitouch) { + input_mt_create_slots_new(dev, 2); + input_set_abs_params(dev, ABS_MT_POSITION_X, XMIN_NOMINAL, + priv->x_max ?: XMAX_NOMINAL, 0, 0); + input_set_abs_params(dev, ABS_MT_POSITION_Y, YMIN_NOMINAL, + priv->y_max ?: YMAX_NOMINAL, 0, 0); + input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0); + } + + if (SYN_CAP_PALMDETECT(priv->capabilities)) + input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); __set_bit(EV_KEY, dev->evbit); __set_bit(BTN_TOUCH, dev->keybit); @@ -652,7 +723,7 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) __set_bit(BTN_LEFT, dev->keybit); __set_bit(BTN_RIGHT, dev->keybit); - if (SYN_CAP_MULTIFINGER(priv->capabilities)) { + if (SYN_CAP_MULTIFINGER(priv->capabilities) | priv->multitouch) { __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); } @@ -673,8 +744,8 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) __clear_bit(REL_X, dev->relbit); __clear_bit(REL_Y, dev->relbit); - dev->absres[ABS_X] = priv->x_res; - dev->absres[ABS_Y] = priv->y_res; + input_abs_set_res(dev, ABS_X, priv->x_res); + input_abs_set_res(dev, ABS_Y, priv->y_res); if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { /* Clickpads report only left button */ @@ -716,6 +787,11 @@ static int synaptics_reconnect(struct psmouse *psmouse) return -1; } + if (synaptics_set_multitouch_mode(psmouse)) { + printk(KERN_ERR "Unable to initialize Synaptics Multitouch.\n"); + return -1; + } + return 0; } @@ -769,7 +845,7 @@ int synaptics_init(struct psmouse *psmouse) psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); if (!priv) - return -1; + return -ENOMEM; psmouse_reset(psmouse); @@ -783,6 +859,11 @@ int synaptics_init(struct psmouse *psmouse) goto init_fail; } + if (synaptics_set_multitouch_mode(psmouse)) { + printk(KERN_ERR "Unable to initialize Synaptics Multitouch.\n"); + goto init_fail; + } + priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n", @@ -790,12 +871,6 @@ int synaptics_init(struct psmouse *psmouse) SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c); - if (SYN_CAP_CLICKPAD(priv->ext_cap)) { - printk(KERN_INFO "Synaptics: Clickpad mode enabled\n"); - /* force to enable the middle button */ - priv->capabilities |= (1 << 18); - } - set_input_params(psmouse->dev, priv); /* diff --git a/usr/src/dkms_source_tree/synaptics.h b/usr/src/dkms_source_tree/synaptics.h index 80907d0..c3653e1 100644 --- a/usr/src/dkms_source_tree/synaptics.h +++ b/usr/src/dkms_source_tree/synaptics.h @@ -6,6 +6,8 @@ * the Free Software Foundation. */ +#include "input-mt.h" + #ifndef _SYNAPTICS_H #define _SYNAPTICS_H @@ -53,6 +55,7 @@ #define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16) #define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100100) #define SYN_CAP_MAX_DIMENSIONS(ex0c) ((ex0c) & 0x020000) +#define SYN_CAP_MULTITOUCH(ex0c) ((ex0c) & 0x080000) /* synaptics modes query bits */ #define SYN_MODE_ABSOLUTE(m) ((m) & (1 << 7)) @@ -110,7 +113,12 @@ struct synaptics_data { unsigned char pkt_type; /* packet type - old, new, etc */ unsigned char mode; /* current mode byte */ int scroll; - struct synaptics_hw_state prev_hw; + + struct serio *pt_port; /* Pass-through serio port */ + + int multitouch; /* device provides MT data */ + int mt_pkt; /* received MT packet */ + struct synaptics_hw_state mt; /* current MT packet */ }; void synaptics_module_init(void); -- cgit v1.2.3