Skip to contentSkip to conversation

Make mousedev.c report all events to user space immediately

PATCH Applied Peter Osterlund 3 participants 9 messages Jan 30, 2005 – Feb 4, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Make mousedev.c report all events to user space immediately

mousedev_packet() incorrectly clears list->ready when called with "tail == head - 1". The effect is that the last mouse event from the hardware isn't reported to user space until another hardware mouse event arrives. This can make the left mouse button get stuck when tapping on a touchpad. When this happens, the button doesn't unstick until the next time you interact with the touchpad.

---

 linux-petero/drivers/input/mousedev.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/input/mousedev.c renamed from drivers/input/mousedev.c~mousedev-ready-fix +2 -2
diff -puN drivers/input/mousedev.c~mousedev-ready-fix drivers/input/mousedev.c
@@ -467,10 +467,10 @@ static void mousedev_packet(struct mouse
 	}
 
 	if (!p->dx && !p->dy && !p->dz) {
-		if (list->tail != list->head)
-			list->tail = (list->tail + 1) % PACKET_QUEUE_LEN;
 		if (list->tail == list->head)
 			list->ready = 0;
+		else
+			list->tail = (list->tail + 1) % PACKET_QUEUE_LEN;
 	}
 
 	spin_unlock_irqrestore(&list->packet_lock, flags);

_

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#1 lore raw

PATCH 2/4 Enable hardware tapping for ALPS touchpads

When hardware tapping is disabled on an ALPS touchpad, the touchpad generates exactly the same data for a single tap and a fast double tap. The effect is that the second tap in the double tap sequence is lost.

To fix this problem, this patch enables hardware tapping and converts the resulting tap and gesture bits to standard finger pressure values (z), which is what mousedev.c and the userspace X driver expects.

---

 linux-petero/drivers/input/mouse/alps.c |   53 +++++++++++++++++++++++++-------
 linux-petero/drivers/input/mouse/alps.h |    4 ++
 2 files changed, 47 insertions(+), 10 deletions(-)
drivers/input/mouse/alps.c renamed from drivers/input/mouse/alps.c~alps-hwtaps +43 -10
diff -puN drivers/input/mouse/alps.c~alps-hwtaps drivers/input/mouse/alps.c
@@ -78,10 +78,12 @@ struct alps_model_info {
 
 static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
 {
+	struct alps_data *priv = psmouse->private;
 	unsigned char *packet = psmouse->packet;
 	struct input_dev *dev = &psmouse->dev;
 	int x, y, z;
 	int left = 0, right = 0, middle = 0;
+	int ges, fin;
 
 	input_regs(dev, regs);
 
@@ -123,6 +125,27 @@ static void alps_process_packet(struct p
 		return;
 	}
 
+	ges = packet[2] & 1;		    /* gesture bit */
+	fin = packet[2] & 2;		    /* finger bit */
+
+	/* Convert hardware tap to a reasonable Z value */
+	if (ges && !fin)
+		z = 40;
+
+	/*
+	 * A "tap and drag" operation is reported by the hardware as a transition
+	 * from (!fin && ges) to (fin && ges). This should be translated to the
+	 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
+	 */
+	if (ges && fin && !priv->prev_fin) {
+		input_report_abs(dev, ABS_X, x);
+		input_report_abs(dev, ABS_Y, y);
+		input_report_abs(dev, ABS_PRESSURE, 0);
+		input_report_key(dev, BTN_TOOL_FINGER, 0);
+		input_sync(dev);
+	}
+	priv->prev_fin = fin;
+
 	if (z > 30) input_report_key(dev, BTN_TOUCH, 1);
 	if (z < 25) input_report_key(dev, BTN_TOUCH, 0);
 
@@ -133,7 +156,6 @@ static void alps_process_packet(struct p
 	input_report_abs(dev, ABS_PRESSURE, z);
 	input_report_key(dev, BTN_TOOL_FINGER, z > 0);
 
-	left  |= (packet[2]     ) & 1;
 	left  |= (packet[3]     ) & 1;
 	right |= (packet[3] >> 1) & 1;
 	if (packet[0] == 0xff) {
@@ -335,7 +357,7 @@ static int alps_reconnect(struct psmouse
 		return -1;
 
 	if (param[0] & 0x04)
-		alps_tap_mode(psmouse, 0);
+		alps_tap_mode(psmouse, 1);
 
 	if (alps_absolute_mode(psmouse)) {
 		printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
@@ -351,40 +373,47 @@ static int alps_reconnect(struct psmouse
 static void alps_disconnect(struct psmouse *psmouse)
 {
 	psmouse_reset(psmouse);
+	kfree(psmouse->private);
 }
 
 int alps_init(struct psmouse *psmouse)
 {
+	struct alps_data *priv;
 	unsigned char param[4];
 	int model;
 
+	psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL);
+	if (!priv)
+		goto init_fail;
+	memset(priv, 0, sizeof(struct alps_data));
+
 	if ((model = alps_get_model(psmouse)) < 0)
-		return -1;
+		goto init_fail;
 
 	printk(KERN_INFO "ALPS Touchpad (%s) detected\n",
 		model == ALPS_MODEL_GLIDEPOINT ? "Glidepoint" : "Dualpoint");
 
 	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 1))
-		return -1;
+		goto init_fail;
 
 	if (alps_get_status(psmouse, param)) {
 		printk(KERN_ERR "alps.c: touchpad status report request failed\n");
-		return -1;
+		goto init_fail;
 	}
 
 	if (param[0] & 0x04) {
-		printk(KERN_INFO "  Disabling hardware tapping\n");
-		if (alps_tap_mode(psmouse, 0))
-			printk(KERN_WARNING "alps.c: Failed to disable hardware tapping\n");
+		printk(KERN_INFO "  Enabling hardware tapping\n");
+		if (alps_tap_mode(psmouse, 1))
+			printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
 	}
 
 	if (alps_absolute_mode(psmouse)) {
 		printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
-		return -1;
+		goto init_fail;
 	}
 
 	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 0))
-		return -1;
+		goto init_fail;
 
 	psmouse->dev.evbit[LONG(EV_REL)] |= BIT(EV_REL);
 	psmouse->dev.relbit[LONG(REL_X)] |= BIT(REL_X);
@@ -408,6 +437,10 @@ int alps_init(struct psmouse *psmouse)
 	psmouse->pktsize = 6;
 
 	return 0;
+
+init_fail:
+	kfree(priv);
+	return -1;
 }
 
 int alps_detect(struct psmouse *psmouse, int set_properties)
drivers/input/mouse/alps.h renamed from drivers/input/mouse/alps.h~alps-hwtaps +4 -0
diff -puN drivers/input/mouse/alps.h~alps-hwtaps drivers/input/mouse/alps.h
@@ -14,4 +14,8 @@
 int alps_detect(struct psmouse *psmouse, int set_properties);
 int alps_init(struct psmouse *psmouse);
 
+struct alps_data {
+	int prev_fin;			    /* Finger bit from previous packet */
+};
+
 #endif

_

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#2 lore raw

PATCH 3/4 Fix "pointer jumps to corner of screen" problem on ALPS Glidepoint touchpads.

Only parse a "z == 127" packet as a relative Dualpoint stick packet if the touchpad actually is a Dualpoint device. The Glidepoint models don't have a stick, and can report z == 127 for a very wide finger. If such a packet is parsed as a stick packet, the mouse pointer will typically jump to one corner of the screen.

---

 linux-petero/drivers/input/mouse/alps.c |   20 ++++++++++----------
 linux-petero/drivers/input/mouse/alps.h |    1 +
 2 files changed, 11 insertions(+), 10 deletions(-)
drivers/input/mouse/alps.c renamed from drivers/input/mouse/alps.c~alps-glidepoint-has-no-stick +10 -10
diff -puN drivers/input/mouse/alps.c~alps-glidepoint-has-no-stick drivers/input/mouse/alps.c
@@ -109,7 +109,8 @@ static void alps_process_packet(struct p
 	y = (packet[4] & 0x7f) | ((packet[3] & 0x70)<<(7-4));
 	z = packet[5];
 
-	if (z == 127) {	/* DualPoint stick is relative, not absolute */
+	if ((priv->model == ALPS_MODEL_DUALPOINT) && (z == 127)) {
+		/* DualPoint stick, relative packet */
 		if (x > 383)
 			x = x - 768;
 		if (y > 255)
@@ -344,13 +345,13 @@ static int alps_tap_mode(struct psmouse 
 
 static int alps_reconnect(struct psmouse *psmouse)
 {
-	int model;
+	struct alps_data *priv = psmouse->private;
 	unsigned char param[4];
 
-	if ((model = alps_get_model(psmouse)) < 0)
+	if ((priv->model = alps_get_model(psmouse)) < 0)
 		return -1;
 
-	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 1))
+	if (priv->model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 1))
 		return -1;
 
 	if (alps_get_status(psmouse, param))
@@ -364,7 +365,7 @@ static int alps_reconnect(struct psmouse
 		return -1;
 	}
 
-	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 0))
+	if (priv->model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 0))
 		return -1;
 
 	return 0;
@@ -380,20 +381,19 @@ int alps_init(struct psmouse *psmouse)
 {
 	struct alps_data *priv;
 	unsigned char param[4];
-	int model;
 
 	psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL);
 	if (!priv)
 		goto init_fail;
 	memset(priv, 0, sizeof(struct alps_data));
 
-	if ((model = alps_get_model(psmouse)) < 0)
+	if ((priv->model = alps_get_model(psmouse)) < 0)
 		goto init_fail;
 
 	printk(KERN_INFO "ALPS Touchpad (%s) detected\n",
-		model == ALPS_MODEL_GLIDEPOINT ? "Glidepoint" : "Dualpoint");
+		priv->model == ALPS_MODEL_GLIDEPOINT ? "Glidepoint" : "Dualpoint");
 
-	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 1))
+	if (priv->model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 1))
 		goto init_fail;
 
 	if (alps_get_status(psmouse, param)) {
@@ -412,7 +412,7 @@ int alps_init(struct psmouse *psmouse)
 		goto init_fail;
 	}
 
-	if (model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 0))
+	if (priv->model == ALPS_MODEL_DUALPOINT && alps_passthrough_mode(psmouse, 0))
 		goto init_fail;
 
 	psmouse->dev.evbit[LONG(EV_REL)] |= BIT(EV_REL);
drivers/input/mouse/alps.h renamed from drivers/input/mouse/alps.h~alps-glidepoint-has-no-stick +1 -0
diff -puN drivers/input/mouse/alps.h~alps-glidepoint-has-no-stick drivers/input/mouse/alps.h
@@ -15,6 +15,7 @@ int alps_detect(struct psmouse *psmouse,
 int alps_init(struct psmouse *psmouse);
 
 struct alps_data {
+	int model;			    /* Glidepoint or Dualpoint */
 	int prev_fin;			    /* Finger bit from previous packet */
 };
 

_

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#3 lore raw

PATCH 4/4 Add support for Synaptics touchpad scroll wheels

Some Synaptics touchpads have a middle mouse button that also works as a scroll wheel. Scroll data is reported as packets with w == 2 and the scroll amount in byte 1, treated as a signed character. For some reason, the smallest possible wheel movement is reported as a scroll amount of 4 units. This amount is typically spread out over more than one packet, so the driver has to accumulate scroll delta values to correctly deal with this.

---

 linux-petero/drivers/input/mouse/synaptics.c |   28 +++++++++++++++++++++++++--
 linux-petero/drivers/input/mouse/synaptics.h |    2 +
 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/input/mouse/synaptics.c renamed from drivers/input/mouse/synaptics.c~synaptics-scroll-wheel +26 -2
diff -puN drivers/input/mouse/synaptics.c~synaptics-scroll-wheel drivers/input/mouse/synaptics.c
@@ -322,8 +322,11 @@ static void synaptics_parse_hw_state(uns
 		hw->left  = (buf[0] & 0x01) ? 1 : 0;
 		hw->right = (buf[0] & 0x02) ? 1 : 0;
 
-		if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
+		if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
 			hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
+			if (hw->w == 2)
+				hw->scroll = (signed char)(buf[1]);
+		}
 
 		if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
 			hw->up   = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
@@ -379,6 +382,26 @@ static void synaptics_process_packet(str
 
 	synaptics_parse_hw_state(psmouse->packet, priv, &hw);
 
+	if (hw.scroll) {
+		priv->scroll += hw.scroll;
+
+		while (priv->scroll >= 4) {
+			input_report_key(dev, BTN_BACK, !hw.down);
+			input_sync(dev);
+			input_report_key(dev, BTN_BACK, hw.down);
+			input_sync(dev);
+			priv->scroll -= 4;
+		}
+		while (priv->scroll <= -4) {
+			input_report_key(dev, BTN_FORWARD, !hw.up);
+			input_sync(dev);
+			input_report_key(dev, BTN_FORWARD, hw.up);
+			input_sync(dev);
+			priv->scroll += 4;
+		}
+		return;
+	}
+
 	if (hw.z > 0) {
 		num_fingers = 1;
 		finger_width = 5;
@@ -528,7 +551,8 @@ static void set_input_params(struct inpu
 	if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
 		set_bit(BTN_MIDDLE, dev->keybit);
 
-	if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+	if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
+	    SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
 		set_bit(BTN_FORWARD, dev->keybit);
 		set_bit(BTN_BACK, dev->keybit);
 	}
drivers/input/mouse/synaptics.h renamed from drivers/input/mouse/synaptics.h~synaptics-scroll-wheel +2 -0
diff -puN drivers/input/mouse/synaptics.h~synaptics-scroll-wheel drivers/input/mouse/synaptics.h
@@ -92,6 +92,7 @@ struct synaptics_hw_state {
 	unsigned int up:1;
 	unsigned int down:1;
 	unsigned char ext_buttons;
+	signed char scroll;
 };
 
 struct synaptics_data {
@@ -103,6 +104,7 @@ struct synaptics_data {
 
 	unsigned char pkt_type;			/* packet type - old, new, etc */
 	unsigned char mode;			/* current mode byte */
+	int scroll;
 };
 
 #endif /* _SYNAPTICS_H */

_

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#4 lore raw

Re: [PATCH 4/4] Add support for Synaptics touchpad scroll wheels

Quoted 10 lines · Peter Osterlund

Some Synaptics touchpads have a middle mouse button that also works as a scroll wheel. Scroll data is reported as packets with w == 2 and the scroll amount in byte 1, treated as a signed character. For some reason, the smallest possible wheel movement is reported as a scroll amount of 4 units. This amount is typically spread out over more than one packet, so the driver has to accumulate scroll delta values to correctly deal with this.

---

Thanks, applied.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#5 lore raw

Re: [PATCH 3/4] Fix "pointer jumps to corner of screen" problem on ALPS Glidepoint touchpads.

In reply to Peter Osterlund
Quoted 5 lines · Peter Osterlund

Only parse a "z == 127" packet as a relative Dualpoint stick packet if the touchpad actually is a Dualpoint device. The Glidepoint models don't have a stick, and can report z == 127 for a very wide finger. If such a packet is parsed as a stick packet, the mouse pointer will typically jump to one corner of the screen.

I remember reading specs of a touchpad (can't remember if it was ALPS or Synaptics) (driver) which could do "palm detection" (basically ignoring events when a large part of the hand accidentally touched/pressed the pad, FWICS).

Signature · 7 lines
Giuseppe "Oblomov" Bilotta

Can't you see
It all makes perfect sense
Expressed in dollar and cents
Pounds shillings and pence
                  (Roger Waters)
#6 lore raw

Re: [PATCH 3/4] Fix "pointer jumps to corner of screen" problem on ALPS Glidepoint touchpads.

Quoted 11 lines · Giuseppe Bilotta
Quoted 5 lines · Peter Osterlund

Only parse a "z == 127" packet as a relative Dualpoint stick packet if the touchpad actually is a Dualpoint device. The Glidepoint models don't have a stick, and can report z == 127 for a very wide finger. If such a packet is parsed as a stick packet, the mouse pointer will typically jump to one corner of the screen.

I remember reading specs of a touchpad (can't remember if it was ALPS or Synaptics) (driver) which could do "palm detection" (basically ignoring events when a large part of the hand accidentally touched/pressed the pad, FWICS).

Some synaptics touchpads can do palm detection in firmware, but the software driver has to decide if the corresponding events shall be ignored or not.

Anyway, this is unrelated to the patch. Without this patch, the packet from the touchpad will be parsed incorrectly as a very big stick motion, so a higher level driver (such as the X driver) can't really see that there might be a palm touching the pad.

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#7 lore raw

Re: [PATCH 3/4] Fix "pointer jumps to corner of screen" problem on ALPS Glidepoint touchpads.

In reply to Peter Osterlund
Quoted 7 lines · Peter Osterlund

Only parse a "z == 127" packet as a relative Dualpoint stick packet if the touchpad actually is a Dualpoint device. The Glidepoint models don't have a stick, and can report z == 127 for a very wide finger. If such a packet is parsed as a stick packet, the mouse pointer will typically jump to one corner of the screen.

Doesn't apply without 2/4, sorry. Please resend it.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#8 lore raw
In reply to Peter Osterlund
Quoted 8 lines · Peter Osterlund

mousedev_packet() incorrectly clears list->ready when called with "tail == head - 1". The effect is that the last mouse event from the hardware isn't reported to user space until another hardware mouse event arrives. This can make the left mouse button get stuck when tapping on a touchpad. When this happens, the button doesn't unstick until the next time you interact with the touchpad.

Thanks, applied. Btw, I'm missing your patch 2/4 - it got lost somewhere.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR