public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor_core@ameritech.net>
To: linux-kernel@vger.kernel.org
Cc: Vojtech Pavlik <vojtech@suse.cz>
Subject: [PATCH 14/15] New set of input patches: atkbd reconnect probe
Date: Wed, 21 Apr 2004 01:04:39 -0500	[thread overview]
Message-ID: <200404210104.41573.dtor_core@ameritech.net> (raw)
In-Reply-To: <200404210049.17139.dtor_core@ameritech.net>


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


ChangeSet@1.1915, 2004-04-20 23:59:48-05:00, dtor_core@ameritech.net
  Input: do not modify device's properties when probing for protocol
         extensions on reconnect as it may interfere with reconnect
         process


 logips2pp.c    |  168 ++++++++++++++++++++++++++++++---------------------------
 logips2pp.h    |    5 +
 psmouse-base.c |   78 ++++++++++++++------------
 3 files changed, 137 insertions(+), 114 deletions(-)


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



diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c	Wed Apr 21 00:06:21 2004
+++ b/drivers/input/mouse/logips2pp.c	Wed Apr 21 00:06:21 2004
@@ -89,7 +89,7 @@
  * enabled if we do nothing to it. Of course I put this in because I want it
  * disabled :P
  * 1 - enabled (if previously disabled, also default)
- * 0/2 - disabled 
+ * 0/2 - disabled
  */
 
 static void ps2pp_set_smartscroll(struct psmouse *psmouse)
@@ -103,14 +103,11 @@
 	psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
 	psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
 
-	if (psmouse_smartscroll == 1) 
-		param[0] = 1;
-	else
-	if (psmouse_smartscroll > 2)
-		return;
-
-	/* else leave param[0] == 0 to disable */
-	psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
+	if (psmouse_smartscroll < 2) {
+		/* 0 - disabled, 1 - enabled */
+		param[0] = psmouse_smartscroll;
+		psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
+	}
 }
 
 /*
@@ -128,111 +125,128 @@
 	psmouse_command(psmouse, &param, PSMOUSE_CMD_SETRES);
 }
 
+
+static int is_model_in_list(unsigned char model, int *model_list)
+{
+	int i;
+
+	for (i = 0; model_list[i] != -1; i++)
+		if (model == model_list[i])
+			return 1;
+	return 0;
+}
+
 /*
- * Detect the exact model and features of a PS2++ or PS2T++ Logitech mouse or
- * touchpad.
+ * Set up input device's properties based on the detected mouse model.
  */
 
-static int ps2pp_detect_model(struct psmouse *psmouse, unsigned char *param)
+static void ps2pp_set_properties(struct psmouse *psmouse, unsigned char protocol,
+				 unsigned char model, unsigned char buttons)
 {
-	int i;
 	static int logitech_4btn[] = { 12, 40, 41, 42, 43, 52, 73, 80, -1 };
 	static int logitech_wheel[] = { 52, 53, 75, 76, 80, 81, 83, 88, 112, -1 };
-	static int logitech_ps2pp[] = { 12, 13, 40, 41, 42, 43, 50, 51, 52, 53, 73, 75,
-						76, 80, 81, 83, 88, 96, 97, 112, -1 };
 	static int logitech_mx[] = { 61, 112, -1 };
 
 	psmouse->vendor = "Logitech";
-	psmouse->model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
+	psmouse->model = model;
 
-	if (param[1] < 3)
+	if (buttons < 3)
 		clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
-	if (param[1] < 2)
+	if (buttons < 2)
 		clear_bit(BTN_RIGHT, psmouse->dev.keybit);
 
-	psmouse->type = PSMOUSE_PS2;
+	if (protocol == PSMOUSE_PS2PP) {
 
-	for (i = 0; logitech_ps2pp[i] != -1; i++)
-		if (logitech_ps2pp[i] == psmouse->model)
-			psmouse->type = PSMOUSE_PS2PP;
-
-	if (psmouse->type == PSMOUSE_PS2PP) {
-
-		for (i = 0; logitech_4btn[i] != -1; i++)
-			if (logitech_4btn[i] == psmouse->model)
-				set_bit(BTN_SIDE, psmouse->dev.keybit);
-
-		for (i = 0; logitech_wheel[i] != -1; i++)
-			if (logitech_wheel[i] == psmouse->model) {
-				set_bit(REL_WHEEL, psmouse->dev.relbit);
-				psmouse->name = "Wheel Mouse";
-			}
+		if (is_model_in_list(model, logitech_4btn))
+			set_bit(BTN_SIDE, psmouse->dev.keybit);
+
+		if (is_model_in_list(model, logitech_wheel)) {
+			set_bit(REL_WHEEL, psmouse->dev.relbit);
+			psmouse->name = "Wheel Mouse";
+		}
+
+		if (is_model_in_list(model, logitech_mx)) {
+			set_bit(BTN_SIDE, psmouse->dev.keybit);
+			set_bit(BTN_EXTRA, psmouse->dev.keybit);
+			set_bit(BTN_BACK, psmouse->dev.keybit);
+			set_bit(BTN_FORWARD, psmouse->dev.keybit);
+			set_bit(BTN_TASK, psmouse->dev.keybit);
+			psmouse->name = "MX Mouse";
+		}
+	}
+
+	if (protocol == PSMOUSE_PS2TPP) {
+		set_bit(REL_WHEEL, psmouse->dev.relbit);
+		set_bit(REL_HWHEEL, psmouse->dev.relbit);
+		psmouse->name = "TouchPad 3";
+	}
+}
 
-		for (i = 0; logitech_mx[i] != -1; i++)
-			if (logitech_mx[i]  == psmouse->model) {
-				set_bit(BTN_SIDE, psmouse->dev.keybit);
-				set_bit(BTN_EXTRA, psmouse->dev.keybit);
-				set_bit(BTN_BACK, psmouse->dev.keybit);
-				set_bit(BTN_FORWARD, psmouse->dev.keybit);
-				set_bit(BTN_TASK, psmouse->dev.keybit);
-				psmouse->name = "MX Mouse";
-			}
 
 /*
- * Do Logitech PS2++ / PS2T++ magic init.
+ * Logitech magic init. Detect whether the mouse is a Logitech one
+ * and its exact model and try turning on extended protocol for ones
+ * that support it.
  */
 
-		if (psmouse->model == 97) { /* TouchPad 3 */
+int ps2pp_init(struct psmouse *psmouse, int set_properties)
+{
+	static int logitech_ps2pp[] = { 12, 13, 40, 41, 42, 43, 50, 51, 52, 53, 73, 75,
+					76, 80, 81, 83, 88, 96, 97, 112, -1 };
+	unsigned char param[4];
+	unsigned char protocol = PSMOUSE_PS2;
+	unsigned char model, buttons;
 
-			set_bit(REL_WHEEL, psmouse->dev.relbit);
-			set_bit(REL_HWHEEL, psmouse->dev.relbit);
+	param[0] = 0;
+	psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
+	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
+	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
+	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
+	param[1] = 0;
+	psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO);
 
-			param[0] = 0x11; param[1] = 0x04; param[2] = 0x68; /* Unprotect RAM */
+	if (param[1] != 0) {
+		model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
+		buttons = param[1];
+/*
+ * Do Logitech PS2++ / PS2T++ magic init.
+ */
+		if (model == 97) { /* Touch Pad 3 */
+
+			/* Unprotect RAM */
+			param[0] = 0x11; param[1] = 0x04; param[2] = 0x68;
 			psmouse_command(psmouse, param, 0x30d1);
-			param[0] = 0x11; param[1] = 0x05; param[2] = 0x0b; /* Enable features */
+			/* Enable features */
+			param[0] = 0x11; param[1] = 0x05; param[2] = 0x0b;
 			psmouse_command(psmouse, param, 0x30d1);
-			param[0] = 0x11; param[1] = 0x09; param[2] = 0xc3; /* Enable PS2++ */
+			/* Enable PS2++ */
+			param[0] = 0x11; param[1] = 0x09; param[2] = 0xc3;
 			psmouse_command(psmouse, param, 0x30d1);
 
 			param[0] = 0;
 			if (!psmouse_command(psmouse, param, 0x13d1) &&
-				param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) {
-				psmouse->name = "TouchPad 3";
-				return PSMOUSE_PS2TPP;
+			    param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) {
+				protocol = PSMOUSE_PS2TPP;
 			}
 
-		} else {
+		} else if (is_model_in_list(model, logitech_ps2pp)) {
 
 			param[0] = param[1] = param[2] = 0;
 			ps2pp_cmd(psmouse, param, 0x39); /* Magic knock */
 			ps2pp_cmd(psmouse, param, 0xDB);
 
-			if ((param[0] & 0x78) == 0x48 && (param[1] & 0xf3) == 0xc2 &&
-				(param[2] & 3) == ((param[1] >> 2) & 3)) {
-					ps2pp_set_smartscroll(psmouse);
-					return PSMOUSE_PS2PP;
+			if ((param[0] & 0x78) == 0x48 &&
+			    (param[1] & 0xf3) == 0xc2 &&
+			    (param[2] & 0x03) == ((param[1] >> 2) & 3)) {
+				ps2pp_set_smartscroll(psmouse);
+				protocol = PSMOUSE_PS2PP;
 			}
 		}
-	}
-
-	return 0;
-}
 
-/*
- * Logitech magic init.
- */
-int ps2pp_detect(struct psmouse *psmouse)
-{
-	unsigned char param[4];
-
-	param[0] = 0;
-	psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
-	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
-	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
-	psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
-	param[1] = 0;
-	psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO);
+		if (set_properties)
+			ps2pp_set_properties(psmouse, protocol, model, buttons);
+	}
 
-	return param[1] != 0 ? ps2pp_detect_model(psmouse, param) : 0;
+	return protocol;
 }
 
diff -Nru a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
--- a/drivers/input/mouse/logips2pp.h	Wed Apr 21 00:06:21 2004
+++ b/drivers/input/mouse/logips2pp.h	Wed Apr 21 00:06:21 2004
@@ -10,8 +10,9 @@
 
 #ifndef _LOGIPS2PP_H
 #define _LOGIPS2PP_H
-struct psmouse;
+
 void ps2pp_process_packet(struct psmouse *psmouse);
 void ps2pp_set_800dpi(struct psmouse *psmouse);
-int ps2pp_detect(struct psmouse *psmouse);
+int ps2pp_init(struct psmouse *psmouse, int set_properties);
+
 #endif
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c	Wed Apr 21 00:06:21 2004
+++ b/drivers/input/mouse/psmouse-base.c	Wed Apr 21 00:06:21 2004
@@ -410,22 +410,21 @@
  * the mouse may have.
  */
 
-static int psmouse_extensions(struct psmouse *psmouse, unsigned int max_proto)
+static int psmouse_extensions(struct psmouse *psmouse,
+			      unsigned int max_proto, int set_properties)
 {
 	int synaptics_hardware = 0;
 
-	psmouse->vendor = "Generic";
-	psmouse->name = "Mouse";
-	psmouse->model = 0;
-	psmouse->protocol_handler = psmouse_process_byte;
-
 /*
  * Try Synaptics TouchPad
  */
 	if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse)) {
 		synaptics_hardware = 1;
-		psmouse->vendor = "Synaptics";
-		psmouse->name = "TouchPad";
+
+		if (set_properties) {
+			psmouse->vendor = "Synaptics";
+			psmouse->name = "TouchPad";
+		}
 
 		if (max_proto > PSMOUSE_IMEX) {
 			if (synaptics_init(psmouse) == 0)
@@ -444,33 +443,44 @@
 	}
 
 	if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse)) {
-		set_bit(BTN_EXTRA, psmouse->dev.keybit);
-		set_bit(BTN_SIDE, psmouse->dev.keybit);
-		set_bit(REL_WHEEL, psmouse->dev.relbit);
 
-		psmouse->vendor = "Genius";
-		psmouse->name = "Wheel Mouse";
+		if (set_properties) {
+			set_bit(BTN_EXTRA, psmouse->dev.keybit);
+			set_bit(BTN_SIDE, psmouse->dev.keybit);
+			set_bit(REL_WHEEL, psmouse->dev.relbit);
+			psmouse->vendor = "Genius";
+			psmouse->name = "Wheel Mouse";
+		}
+
 		return PSMOUSE_GENPS;
 	}
 
 	if (max_proto > PSMOUSE_IMEX) {
-		int type = ps2pp_detect(psmouse);
-		if (type)
+		int type = ps2pp_init(psmouse, set_properties);
+		if (type > PSMOUSE_PS2)
 			return type;
 	}
 
 	if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse)) {
-		set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+		if (set_properties) {
+			set_bit(REL_WHEEL, psmouse->dev.relbit);
+			if (!psmouse->name)
+				psmouse->name = "Wheel Mouse";
+		}
 
 		if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse)) {
-			set_bit(BTN_SIDE, psmouse->dev.keybit);
-			set_bit(BTN_EXTRA, psmouse->dev.keybit);
 
-			psmouse->name = "Explorer Mouse";
+			if (!set_properties) {
+				set_bit(BTN_SIDE, psmouse->dev.keybit);
+				set_bit(BTN_EXTRA, psmouse->dev.keybit);
+				if (!psmouse->name)
+					psmouse->name = "Explorer Mouse";
+			}
+
 			return PSMOUSE_IMEX;
 		}
 
-		psmouse->name = "Wheel Mouse";
 		return PSMOUSE_IMPS;
 	}
 
@@ -520,12 +530,7 @@
 	if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_RESET_DIS))
 		printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", psmouse->serio->phys);
 
-/*
- * And here we try to determine if it has any extensions over the
- * basic PS/2 3-button mouse.
- */
-
-	return psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto);
+	return 0;
 }
 
 /*
@@ -663,7 +668,6 @@
 	psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
 	psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
 	psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
-
 	psmouse->state = PSMOUSE_CMD_MODE;
 	psmouse->serio = serio;
 	psmouse->dev.private = psmouse;
@@ -675,13 +679,21 @@
 		return;
 	}
 
-	if (psmouse_probe(psmouse) <= 0) {
+	if (psmouse_probe(psmouse) < 0) {
 		serio_close(serio);
 		kfree(psmouse);
 		serio->private = NULL;
 		return;
 	}
 
+	psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
+	if (!psmouse->vendor)
+		psmouse->vendor = "Generic";
+	if (!psmouse->name)
+		psmouse->name = "Mouse";
+	if (!psmouse->protocol_handler)
+		psmouse->protocol_handler = psmouse_process_byte;
+
 	sprintf(psmouse->devname, "%s %s %s",
 		psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
 	sprintf(psmouse->phys, "%s/input0",
@@ -715,28 +727,24 @@
 {
 	struct psmouse *psmouse = serio->private;
 	struct serio_dev *dev = serio->dev;
-	int old_type;
 
 	if (!dev || !psmouse) {
 		printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n");
 		return -1;
 	}
 
-	old_type = psmouse->type;
-
 	psmouse->state = PSMOUSE_CMD_MODE;
-	psmouse->type = psmouse->acking = 0;
-	psmouse->cmdcnt = psmouse->pktcnt = psmouse->out_of_sync = 0;
+	psmouse->acking = psmouse->cmdcnt = psmouse->pktcnt = psmouse->out_of_sync = 0;
 	if (psmouse->reconnect) {
 	       if (psmouse->reconnect(psmouse))
 			return -1;
-	} else if (psmouse_probe(psmouse) != old_type)
+	} else if (psmouse_probe(psmouse) < 0 ||
+		   psmouse->type != psmouse_extensions(psmouse, psmouse_max_proto, 0))
 		return -1;
 
 	/* ok, the device type (and capabilities) match the old one,
 	 * we can continue using it, complete intialization
 	 */
-	psmouse->type = old_type;
 	psmouse_initialize(psmouse);
 
 	if (psmouse->ptport) {

  parent reply	other threads:[~2004-04-21  6:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-21  5:49 [PATCH 0/15] New set of input patches Dmitry Torokhov
2004-04-21  5:50 ` [PATCH 1/15] New set of input patches: synaptics cleanup Dmitry Torokhov
2004-04-21  5:51 ` [PATCH 2/15] New set of input patches: synaptics middle button support Dmitry Torokhov
2004-04-21  5:51 ` [PATCH 3/15] New set of input patches: dont change max proto Dmitry Torokhov
2004-04-21  5:52 ` [PATCH 4/15] New set of input patches: lkkbd whitespace Dmitry Torokhov
2004-04-21 11:39   ` Jan-Benedict Glaw
2004-04-21 12:40     ` [New-PATCH] lkkbd: Current version Jan-Benedict Glaw
2004-04-22  7:27   ` [PATCH 4/15] New set of input patches: lkkbd whitespace Vojtech Pavlik
2004-04-21  5:53 ` [PATCH 5/15] New set of input patches: lkkbd simplify checks Dmitry Torokhov
2004-04-21 11:34   ` Jan-Benedict Glaw
2004-04-21  5:54 ` [PATCH 6/15] New set of input patches: atkbd soften accusation Dmitry Torokhov
2004-04-21 14:13   ` Giuseppe Bilotta
2004-04-21  5:56 ` [PATCH 7/15] New set of input patches: atkbd trailing whitespace Dmitry Torokhov
2004-04-21  5:57 ` [PATCH 8/15] New set of input patches: atkbd - use bitfields Dmitry Torokhov
2004-04-22  7:31   ` Vojtech Pavlik
2004-04-22  7:41     ` Dmitry Torokhov
2004-04-22  7:58       ` Vojtech Pavlik
2004-04-25  6:25     ` Pavel Machek
2004-04-21  5:58 ` [PATCH 9/15] New set of input patches: atkbd timeout complaints Dmitry Torokhov
2004-04-22  7:32   ` Vojtech Pavlik
2004-04-22  7:43     ` Dmitry Torokhov
2004-04-21  6:00 ` [PATCH 10/15] New set of input patches: psmouse rescan on hotplug Dmitry Torokhov
2004-04-21  6:01 ` [PATCH 11/15] New set of input patches: psmouse reconnect after error Dmitry Torokhov
2004-04-21  6:01 ` [PATCH 12/15] New set of input patches: psmouse add protocol_handler Dmitry Torokhov
2004-04-21  6:02 ` [PATCH 13/15] New set of input patches: psmouse sliced commands Dmitry Torokhov
2004-04-21  6:04 ` Dmitry Torokhov [this message]
2004-04-21  6:05 ` [PATCH 15/15] New set of input patches: allow disabling psaux Dmitry Torokhov
2004-04-21 12:43 ` [PATCH 0/15] New set of input patches Jan-Benedict Glaw
2004-04-22  6:43 ` [PATCH 16/15] New set of input patches: serio whitespace Dmitry Torokhov
2004-04-22  6:56 ` [PATCH 17/15] New set of input patches: serio open/close optional Dmitry Torokhov
2004-04-22  7:29   ` Dmitry Torokhov

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=200404210104.41573.dtor_core@ameritech.net \
    --to=dtor_core@ameritech.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.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