Skip to content

Commit fec6e52

Browse files
committed
Input: synaptics - add multi-finger and semi-mt support
The Synaptics 2.7 series of touchpads support a mode for reporting two sets of X/Y/Pressure data (advanced gesture mode). By default, these devices report only single finger data, depriving userspace of the nowadays ubiquitous two-finger scroll gesture. Enabling advanced gesture mode also enables the multi-finger report, although the device does not claim that capability. Up to three fingers can be reported this way. While two or three fingers are touching, the normal packet is prepended by a reduced finger packet of lower resolution. From the two packets (which do not represent the actual fingers), the bounding rectangle of the individual contacts can be extracted. This information is sufficient to perform scaling gestures and a limited form of rotation gesture. The behavior has been coined semi-mt capability, and is signaled to userspace via the INPUT_PROP_SEMI_MT device property. Work to decode the advanced gesture packet: Takashi Iwai. Cleanup and testing of the original patch: Chase Douglas. Minor cleanup and testing: Chris Bagwell. Finalization and semi-mt support: Henrik Rydberg. Reported-by: Tobyn Bertram Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Chase Douglas <chase.douglas@canonical.com> Signed-off-by: Chris Bagwell <chris@cnpbagwell.com> Acked-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
1 parent c14890a commit fec6e52

2 files changed

Lines changed: 88 additions & 3 deletions

File tree

‎drivers/input/mouse/synaptics.c‎

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <linux/module.h>
2727
#include <linux/dmi.h>
28-
#include <linux/input.h>
28+
#include <linux/input/mt.h>
2929
#include <linux/serio.h>
3030
#include <linux/libps2.h>
3131
#include <linux/slab.h>
@@ -279,6 +279,25 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
279279
synaptics_mode_cmd(psmouse, priv->mode);
280280
}
281281

282+
static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
283+
{
284+
static unsigned char param = 0xc8;
285+
struct synaptics_data *priv = psmouse->private;
286+
287+
if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
288+
return 0;
289+
290+
if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
291+
return -1;
292+
if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
293+
return -1;
294+
295+
/* Advanced gesture mode also sends multi finger data */
296+
priv->capabilities |= BIT(1);
297+
298+
return 0;
299+
}
300+
282301
/*****************************************************************************
283302
* Synaptics pass-through PS/2 port support
284303
****************************************************************************/
@@ -380,7 +399,9 @@ static void synaptics_pt_create(struct psmouse *psmouse)
380399
* Functions to interpret the absolute mode packets
381400
****************************************************************************/
382401

383-
static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw)
402+
static int synaptics_parse_hw_state(const unsigned char buf[],
403+
struct synaptics_data *priv,
404+
struct synaptics_hw_state *hw)
384405
{
385406
memset(hw, 0, sizeof(struct synaptics_hw_state));
386407

@@ -397,6 +418,14 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data
397418
((buf[0] & 0x04) >> 1) |
398419
((buf[3] & 0x04) >> 2));
399420

421+
if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
422+
/* Gesture packet: (x, y, z) at half resolution */
423+
priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
424+
priv->mt.y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
425+
priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
426+
return 1;
427+
}
428+
400429
hw->left = (buf[0] & 0x01) ? 1 : 0;
401430
hw->right = (buf[0] & 0x02) ? 1 : 0;
402431

@@ -452,6 +481,36 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data
452481
hw->left = (buf[0] & 0x01) ? 1 : 0;
453482
hw->right = (buf[0] & 0x02) ? 1 : 0;
454483
}
484+
485+
return 0;
486+
}
487+
488+
static void set_slot(struct input_dev *dev, int slot, bool active, int x, int y)
489+
{
490+
input_mt_slot(dev, slot);
491+
input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
492+
if (active) {
493+
input_report_abs(dev, ABS_MT_POSITION_X, x);
494+
input_report_abs(dev, ABS_MT_POSITION_Y,
495+
YMAX_NOMINAL + YMIN_NOMINAL - y);
496+
}
497+
}
498+
499+
static void synaptics_report_semi_mt_data(struct input_dev *dev,
500+
const struct synaptics_hw_state *a,
501+
const struct synaptics_hw_state *b,
502+
int num_fingers)
503+
{
504+
if (num_fingers >= 2) {
505+
set_slot(dev, 0, true, min(a->x, b->x), min(a->y, b->y));
506+
set_slot(dev, 1, true, max(a->x, b->x), max(a->y, b->y));
507+
} else if (num_fingers == 1) {
508+
set_slot(dev, 0, true, a->x, a->y);
509+
set_slot(dev, 1, false, 0, 0);
510+
} else {
511+
set_slot(dev, 0, false, 0, 0);
512+
set_slot(dev, 1, false, 0, 0);
513+
}
455514
}
456515

457516
/*
@@ -466,7 +525,8 @@ static void synaptics_process_packet(struct psmouse *psmouse)
466525
int finger_width;
467526
int i;
468527

469-
synaptics_parse_hw_state(psmouse->packet, priv, &hw);
528+
if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
529+
return;
470530

471531
if (hw.scroll) {
472532
priv->scroll += hw.scroll;
@@ -512,6 +572,9 @@ static void synaptics_process_packet(struct psmouse *psmouse)
512572
finger_width = 0;
513573
}
514574

575+
if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
576+
synaptics_report_semi_mt_data(dev, &hw, &priv->mt, num_fingers);
577+
515578
/* Post events
516579
* BTN_TOUCH has to be first as mousedev relies on it when doing
517580
* absolute -> relative conversion
@@ -631,6 +694,15 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
631694
YMIN_NOMINAL, priv->y_max ?: YMAX_NOMINAL, 0, 0);
632695
input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
633696

697+
if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
698+
__set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
699+
input_mt_init_slots(dev, 2);
700+
input_set_abs_params(dev, ABS_MT_POSITION_X, XMIN_NOMINAL,
701+
priv->x_max ?: XMAX_NOMINAL, 0, 0);
702+
input_set_abs_params(dev, ABS_MT_POSITION_Y, YMIN_NOMINAL,
703+
priv->y_max ?: YMAX_NOMINAL, 0, 0);
704+
}
705+
634706
if (SYN_CAP_PALMDETECT(priv->capabilities))
635707
input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
636708

@@ -705,6 +777,11 @@ static int synaptics_reconnect(struct psmouse *psmouse)
705777
return -1;
706778
}
707779

780+
if (synaptics_set_advanced_gesture_mode(psmouse)) {
781+
printk(KERN_ERR "Advanced gesture mode reconnect failed.\n");
782+
return -1;
783+
}
784+
708785
return 0;
709786
}
710787

@@ -772,6 +849,11 @@ int synaptics_init(struct psmouse *psmouse)
772849
goto init_fail;
773850
}
774851

852+
if (synaptics_set_advanced_gesture_mode(psmouse)) {
853+
printk(KERN_ERR "Advanced gesture mode init failed.\n");
854+
goto init_fail;
855+
}
856+
775857
priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
776858

777859
printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",

‎drivers/input/mouse/synaptics.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16)
5454
#define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100100)
5555
#define SYN_CAP_MAX_DIMENSIONS(ex0c) ((ex0c) & 0x020000)
56+
#define SYN_CAP_ADV_GESTURE(ex0c) ((ex0c) & 0x080000)
5657

5758
/* synaptics modes query bits */
5859
#define SYN_MODE_ABSOLUTE(m) ((m) & (1 << 7))
@@ -112,6 +113,8 @@ struct synaptics_data {
112113
int scroll;
113114

114115
struct serio *pt_port; /* Pass-through serio port */
116+
117+
struct synaptics_hw_state mt; /* current gesture packet */
115118
};
116119

117120
void synaptics_module_init(void);

0 commit comments

Comments
 (0)