public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vojtech Pavlik <vojtech@suse.cz>
To: torvalds@osdl.org, akpm@osdl.org, vojtech@ucw.cz,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/39] input: Synaptics driver cleanup
Date: Mon, 7 Jun 2004 13:55:52 +0200	[thread overview]
Message-ID: <1086609352170@twilight.ucw.cz> (raw)
In-Reply-To: <10866093522124@twilight.ucw.cz>

You can pull this changeset from:
	bk://kernel.bkbits.net/vojtech/input-for-linus

===================================================================

ChangeSet@1.1371.753.11, 2004-04-23 02:28:25-05:00, dtor_core@ameritech.net
  Input: synaptics driver cleanup
         - pack all button data in 2 bytes instead of 48
         - adjust the way we extract button data
         - query extended capabilities if SYN_EXT_CAP_REQUESTS >= 1
           (was == 1) according to Synaptics' addendum to the interfacing
           guide
         - do not announce or report BTN_BACK/BTN_FORWARD unless touchpad
           has SYN_CAP_FOUR_BUTTON in its capability flags


 synaptics.c |  137 +++++++++++++++++++++++++-----------------------------------
 synaptics.h |   19 ++------
 2 files changed, 65 insertions(+), 91 deletions(-)

===================================================================

diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
--- a/drivers/input/mouse/synaptics.c	2004-06-07 13:13:32 +02:00
+++ b/drivers/input/mouse/synaptics.c	2004-06-07 13:13:32 +02:00
@@ -118,17 +118,31 @@
 
 	if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
 		return -1;
-	priv->capabilities = (cap[0]<<16) | (cap[1]<<8) | cap[2];
+	priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
 	priv->ext_cap = 0;
 	if (!SYN_CAP_VALID(priv->capabilities))
 		return -1;
 
-	if (SYN_EXT_CAP_REQUESTS(priv->capabilities)) {
+	/*
+	 * Unless capExtended is set the rest of the flags should be ignored
+	 */
+	if (!SYN_CAP_EXTENDED(priv->capabilities))
+		priv->capabilities = 0;
+
+	if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
 		if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
 			printk(KERN_ERR "Synaptics claims to have extended capabilities,"
 			       " but I'm not able to read them.");
-		} else
-			priv->ext_cap = (cap[0]<<16) | (cap[1]<<8) | cap[2];
+		} else {
+			priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
+
+			/*
+			 * if nExtBtn is greater than 8 it should be considered
+			 * invalid and treated as 0
+			 */
+			if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
+				priv->ext_cap &= 0xff0fff;
+		}
 	}
 	return 0;
 }
@@ -167,11 +181,10 @@
 
 	if (SYN_CAP_EXTENDED(priv->capabilities)) {
 		printk(KERN_INFO " Touchpad has extended capability bits\n");
-		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
-		    SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) <= 8)
+		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap))
 			printk(KERN_INFO " -> %d multi-buttons, i.e. besides standard buttons\n",
 			       (int)(SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)));
-		else if (SYN_CAP_FOUR_BUTTON(priv->capabilities))
+		if (SYN_CAP_FOUR_BUTTON(priv->capabilities))
 			printk(KERN_INFO " -> four buttons\n");
 		if (SYN_CAP_MULTIFINGER(priv->capabilities))
 			printk(KERN_INFO " -> multifinger detection\n");
@@ -312,6 +325,8 @@
 
 static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
 {
+	int i;
+
 	set_bit(EV_ABS, dev->evbit);
 	set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0);
 	set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0);
@@ -326,32 +341,15 @@
 
 	set_bit(BTN_LEFT, dev->keybit);
 	set_bit(BTN_RIGHT, dev->keybit);
-	set_bit(BTN_FORWARD, dev->keybit);
-	set_bit(BTN_BACK, dev->keybit);
-	if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)) {
-		switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
-		default:
-			/*
-			 * if nExtBtn is greater than 8 it should be considered
-			 * invalid and treated as 0
-			 */
-			break;
-		case 8:
-			set_bit(BTN_7, dev->keybit);
-			set_bit(BTN_6, dev->keybit);
-		case 6:
-			set_bit(BTN_5, dev->keybit);
-			set_bit(BTN_4, dev->keybit);
-		case 4:
-			set_bit(BTN_3, dev->keybit);
-			set_bit(BTN_2, dev->keybit);
-		case 2:
-			set_bit(BTN_1, dev->keybit);
-			set_bit(BTN_0, dev->keybit);
-			break;
-		}
+
+	if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+		set_bit(BTN_FORWARD, dev->keybit);
+		set_bit(BTN_BACK, dev->keybit);
 	}
 
+	for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
+		set_bit(BTN_0 + i, dev->keybit);
+
 	clear_bit(EV_REL, dev->evbit);
 	clear_bit(REL_X, dev->relbit);
 	clear_bit(REL_Y, dev->relbit);
@@ -385,8 +383,8 @@
 	if (old_priv.identity != priv->identity ||
 	    old_priv.model_id != priv->model_id ||
 	    old_priv.capabilities != priv->capabilities ||
-    	    old_priv.ext_cap != priv->ext_cap)
-    		return -1;
+	    old_priv.ext_cap != priv->ext_cap)
+		return -1;
 
 	if (synaptics_set_mode(psmouse, 0)) {
 		printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
@@ -432,8 +430,8 @@
 
 	priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
 
-	if (SYN_CAP_EXTENDED(priv->capabilities) && SYN_CAP_PASS_THROUGH(priv->capabilities))
-       		synaptics_pt_create(psmouse);
+	if (SYN_CAP_PASS_THROUGH(priv->capabilities))
+		synaptics_pt_create(psmouse);
 
 	print_ident(priv);
 	set_input_params(&psmouse->dev, priv);
@@ -471,17 +469,14 @@
 
 		hw->left  = (buf[0] & 0x01) ? 1 : 0;
 		hw->right = (buf[0] & 0x02) ? 1 : 0;
-		if (SYN_CAP_EXTENDED(priv->capabilities) &&
-		    (SYN_CAP_FOUR_BUTTON(priv->capabilities))) {
-			hw->up = ((buf[3] & 0x01)) ? 1 : 0;
-			if (hw->left)
-				hw->up = !hw->up;
-			hw->down = ((buf[3] & 0x02)) ? 1 : 0;
-			if (hw->right)
-				hw->down = !hw->down;
+
+		if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+			hw->up   = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
+			hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
 		}
+
 		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
-		    ((buf[3] & 2) ? !hw->right : hw->right)) {
+		    ((buf[0] ^ buf[3]) & 0x02)) {
 			switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
 			default:
 				/*
@@ -490,17 +485,17 @@
 				 */
 				break;
 			case 8:
-				hw->b7 = ((buf[5] & 0x08)) ? 1 : 0;
-				hw->b6 = ((buf[4] & 0x08)) ? 1 : 0;
+				hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
+				hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
 			case 6:
-				hw->b5 = ((buf[5] & 0x04)) ? 1 : 0;
-				hw->b4 = ((buf[4] & 0x04)) ? 1 : 0;
+				hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
+				hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
 			case 4:
-				hw->b3 = ((buf[5] & 0x02)) ? 1 : 0;
-				hw->b2 = ((buf[4] & 0x02)) ? 1 : 0;
+				hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
+				hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
 			case 2:
-				hw->b1 = ((buf[5] & 0x01)) ? 1 : 0;
-				hw->b0 = ((buf[4] & 0x01)) ? 1 : 0;
+				hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
+				hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
 			}
 		}
 	} else {
@@ -525,6 +520,7 @@
 	struct synaptics_hw_state hw;
 	int num_fingers;
 	int finger_width;
+	int i;
 
 	synaptics_parse_hw_state(psmouse->packet, priv, &hw);
 
@@ -570,32 +566,17 @@
 	input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
 	input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
 
-	input_report_key(dev, BTN_LEFT,    hw.left);
-	input_report_key(dev, BTN_RIGHT,   hw.right);
-	input_report_key(dev, BTN_FORWARD, hw.up);
-	input_report_key(dev, BTN_BACK,    hw.down);
-	if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap))
-		switch(SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
-		default:
-			/*
-			 * if nExtBtn is greater than 8 it should be considered
-			 * invalid and treated as 0
-			 */
-			break;
-		case 8:
-			input_report_key(dev, BTN_7,       hw.b7);
-			input_report_key(dev, BTN_6,       hw.b6);
-		case 6:
-			input_report_key(dev, BTN_5,       hw.b5);
-			input_report_key(dev, BTN_4,       hw.b4);
-		case 4:
-			input_report_key(dev, BTN_3,       hw.b3);
-			input_report_key(dev, BTN_2,       hw.b2);
-		case 2:
-			input_report_key(dev, BTN_1,       hw.b1);
-			input_report_key(dev, BTN_0,       hw.b0);
-			break;
-		}
+	input_report_key(dev, BTN_LEFT, hw.left);
+	input_report_key(dev, BTN_RIGHT, hw.right);
+
+	if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+		input_report_key(dev, BTN_FORWARD, hw.up);
+		input_report_key(dev, BTN_BACK, hw.down);
+	}
+
+	for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
+		input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
+
 	input_sync(dev);
 }
 
diff -Nru a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
--- a/drivers/input/mouse/synaptics.h	2004-06-07 13:13:32 +02:00
+++ b/drivers/input/mouse/synaptics.h	2004-06-07 13:13:32 +02:00
@@ -50,7 +50,7 @@
 #define SYN_CAP_MULTIFINGER(c)		((c) & (1 << 1))
 #define SYN_CAP_PALMDETECT(c)		((c) & (1 << 0))
 #define SYN_CAP_VALID(c)		((((c) & 0x00ff00) >> 8) == 0x47)
-#define SYN_EXT_CAP_REQUESTS(c)		((((c) & 0x700000) >> 20) == 1)
+#define SYN_EXT_CAP_REQUESTS(c)		(((c) & 0x700000) >> 20)
 #define SYN_CAP_MULTI_BUTTON_NO(ec)	(((ec) & 0x00f000) >> 12)
 
 /* synaptics modes query bits */
@@ -86,18 +86,11 @@
 	int y;
 	int z;
 	int w;
-	int left;
-	int right;
-	int up;
-	int down;
-	int b0;
-	int b1;
-	int b2;
-	int b3;
-	int b4;
-	int b5;
-	int b6;
-	int b7;
+	unsigned int left:1;
+	unsigned int right:1;
+	unsigned int up:1;
+	unsigned int down:1;
+	unsigned char ext_buttons;
 };
 
 struct synaptics_data {


  reply	other threads:[~2004-06-07 11:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-07 11:50 [patches] Input update Vojtech Pavlik
2004-06-07 11:55 ` [PATCH 1/39] input: Fix a workaround for USB Legacy detected as MUX in i8042.c Vojtech Pavlik
2004-06-07 11:55   ` [PATCH 2/39] input: Profusion/ServerWorks chipset workaround in i8042.c for Ingo Molnar Vojtech Pavlik
2004-06-07 11:55     ` [PATCH 3/39] input: Fix emulation of mouse reset (0xff) command Vojtech Pavlik
2004-06-07 11:55       ` Vojtech Pavlik [this message]
2004-06-07 11:55         ` [PATCH 5/39] input: Support Synaptics touchpads that have separate middle button Vojtech Pavlik
2004-06-07 11:55           ` [PATCH 6/39] input: Pass psmouse_extensions as a parameter Vojtech Pavlik
2004-06-07 11:55             ` [PATCH 7/39] input: Soften ACK warning in atkbd Vojtech Pavlik
2004-06-07 11:55               ` [PATCH 8/39] input: Fix trailing whitespace " Vojtech Pavlik
2004-06-07 11:55                 ` [PATCH 9/39] input: Remove unneeded fields in atkbd structure, convert to bitfields Vojtech Pavlik
2004-06-07 11:55                   ` [PATCH 10/39] input: Do not process scancodes in atkbd until fully initialized Vojtech Pavlik
2004-06-07 11:55                     ` [PATCH 11/39] input: Use reconnect instead of rescan in psmouse if possible Vojtech Pavlik
2004-06-07 11:55                       ` [PATCH 12/39] input: Move reconnect after errors to generic code in psmouse Vojtech Pavlik
2004-06-07 11:55                         ` [PATCH 13/39] input: Add protocol_handler to psmouse structure Vojtech Pavlik
2004-06-07 11:55                           ` [PATCH 14/39] input: Add psmouse_sliced_command Vojtech Pavlik
2004-06-07 11:55                             ` [PATCH 15/39] input: Do not modify device's properties when probing for protocol extensions Vojtech Pavlik
2004-06-07 11:55                               ` [PATCH 16/39] input: Allow disabling legacy psaux device Vojtech Pavlik
2004-06-07 11:55                                 ` [PATCH 17/39] input: Serio trailing whitespace fixes Vojtech Pavlik
2004-06-07 11:55                                   ` [PATCH 18/39] input: Make serio open and close methods optional Vojtech Pavlik
2004-06-07 11:55                                     ` [PATCH 19/39] input: Trailing whitespace fixes Vojtech Pavlik
2004-06-07 11:55                                       ` [PATCH 20/39] input: Create input_set_abs_params() Vojtech Pavlik
2004-06-07 11:55                                         ` [PATCH 21/39] input: Microtouch USB driver update Vojtech Pavlik
2004-06-07 11:55                                           ` [PATCH 22/39] input: Trailing whitespace fixes in drivers/input/serio Vojtech Pavlik
2004-06-07 11:55                                             ` [PATCH 23/39] input: kbd98io_interrupt should return irqreturn_t Vojtech Pavlik
2004-06-07 11:55                                               ` [PATCH 24/39] input: kbd98_interrupt " Vojtech Pavlik
2004-06-07 11:55                                                 ` [PATCH 25/39] input: Various fixes for H3600 touchscreen driver Vojtech Pavlik
2004-06-07 11:55                                                   ` [PATCH 26/39] input: Twidjoy module fixes Vojtech Pavlik
2004-06-07 11:55                                                     ` [PATCH 27/39] input: Trailing whitespace fixes in drivers/input/keyboard Vojtech Pavlik
2004-06-07 11:55                                                       ` [PATCH 28/39] input: Power - add MODULE_LICENSE Vojtech Pavlik
2004-06-07 11:55                                                         ` [PATCH 29/39] input: Trailing whitespace fixes in drivers/input/joystick Vojtech Pavlik
2004-06-07 11:55                                                           ` [PATCH 30/39] input: Trailing whitespace fixes in drivers/input/gameport Vojtech Pavlik
2004-06-07 11:55                                                             ` [PATCH 31/39] input: Trailing whitespace fixes in drivers/input Vojtech Pavlik
2004-06-07 11:55                                                               ` [PATCH 32/39] input: Do not call synaptics_init unless we are ready to do full mouse setup Vojtech Pavlik
2004-06-07 11:55                                                                 ` [PATCH 33/39] input: Split i8042 interrupt handling into an IRQ handler and a tasklet [excluded later] Vojtech Pavlik
2004-06-07 11:55                                                                   ` [PATCH 34/39] input: i8042 - kill the timer only after removing interrupt handler Vojtech Pavlik
2004-06-07 11:55                                                                     ` [PATCH 35/39] input: Mousedev - better multiplex absolute and relative devices Vojtech Pavlik
2004-06-07 11:55                                                                       ` [PATCH 36/39] input: Fix an oops at opentime of /dev/input/event devices Vojtech Pavlik
2004-06-07 11:55                                                                         ` [PATCH 37/39] input: Check for IM Explorer mice even if IMPS check failed Vojtech Pavlik
2004-06-07 11:55                                                                           ` [PATCH 38/39] input: Fix oops in hiddev Vojtech Pavlik
2004-06-07 11:55                                                                             ` [PATCH 39/39] input: Exclude tasklet changes to i8042.c Vojtech Pavlik
2004-06-07 13:07                                         ` [PATCH 20/39] input: Create input_set_abs_params() Jan-Benedict Glaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1086609352170@twilight.ucw.cz \
    --to=vojtech@suse.cz \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=vojtech@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox