Commit 463a4f76 authored by Dmitry Torokhov's avatar Dmitry Torokhov
Browse files

Input: i8042 - don't use negation to mark AUX data



Currently i8042_command() negates data coming from the AUX port
of keyboard controller; this is not a very reliable indicator.
Change i8042_command() to fail if response to I8042_CMD_AUX_LOOP
is not coming from AUX channel and get rid of negation.

Based on patch by Vojtech Pavlik.

Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 7b4019d0
Loading
Loading
Loading
Loading
+32 −28
Original line number Diff line number Diff line
@@ -191,41 +191,45 @@ static int i8042_flush(void)
static int i8042_command(unsigned char *param, int command)
{
	unsigned long flags;
	int retval = 0, i = 0;
	int i, retval, auxerr = 0;

	if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
		return -1;

	spin_lock_irqsave(&i8042_lock, flags);

	retval = i8042_wait_write();
	if (!retval) {
	if ((retval = i8042_wait_write()))
		goto out;

	dbg("%02x -> i8042 (command)", command & 0xff);
	i8042_write_command(command & 0xff);
	}

	if (!retval)
	for (i = 0; i < ((command >> 12) & 0xf); i++) {
			if ((retval = i8042_wait_write())) break;
		if ((retval = i8042_wait_write()))
			goto out;
		dbg("%02x -> i8042 (parameter)", param[i]);
		i8042_write_data(param[i]);
	}

	if (!retval)
	for (i = 0; i < ((command >> 8) & 0xf); i++) {
			if ((retval = i8042_wait_read())) break;
			if (i8042_read_status() & I8042_STR_AUXDATA)
				param[i] = ~i8042_read_data();
			else
		if ((retval = i8042_wait_read()))
			goto out;

		if (command == I8042_CMD_AUX_LOOP &&
		    !(i8042_read_status() & I8042_STR_AUXDATA)) {
			retval = auxerr = -1;
			goto out;
		}

		param[i] = i8042_read_data();
		dbg("%02x <- i8042 (return)", param[i]);
	}

	spin_unlock_irqrestore(&i8042_lock, flags);

	if (retval)
		dbg("     -- i8042 (timeout)");
		dbg("     -- i8042 (%s)", auxerr ? "auxerr" : "timeout");

 out:
	spin_unlock_irqrestore(&i8042_lock, flags);
	return retval;
}

@@ -507,17 +511,17 @@ static int i8042_set_mux_mode(unsigned int mode, unsigned char *mux_version)
 */

	param = 0xf0;
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x0f)
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xf0)
		return -1;
	param = mode ? 0x56 : 0xf6;
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0xa9 : 0x09))
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0x56 : 0xf6))
		return -1;
	param = mode ? 0xa4 : 0xa5;
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0x5b : 0x5a))
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0xa4 : 0xa5))
		return -1;

	if (mux_version)
		*mux_version = ~param;
		*mux_version = param;

	return 0;
}
@@ -619,7 +623,7 @@ static int __init i8042_check_aux(void)
 */

	param = 0x5a;
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xa5) {
	if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x5a) {

/*
 * External connection test - filters out AT-soldered PS/2 i8042's