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/synaptics.c | 247 +++++++++++++++++++++++------------ 1 file changed, 161 insertions(+), 86 deletions(-) (limited to 'usr/src/dkms_source_tree/synaptics.c') 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); /* -- cgit v1.2.3