Author: cfinck Date: Mon Mar 31 07:40:31 2008 New Revision: 32790
URL: http://svn.reactos.org/svn/reactos?rev=32790&view=rev Log: - Remove much deprecated code for the mouse initialization (had been imported from the ancient psaux.sys driver, which was removed in _r14938_) Do a much simpler initialization instead: * The "Get ID" command was used for detecting whether a mouse is present. But it just handled normal mice, IntelliMice and IntelliMice Explorer, although there can be many more possible values for other mice. (see for example http://www.win.tue.nl/~aeb/linux/kbd/scancodes-13.html#mcf2). Also this command isn't available on all systems. Furthermore we already do a MOUSE_LINE_TEST in i8042BasicDetect, which is the more reliable method to test whether a mouse is plugged in. Therefore this "Get ID" command can be simply removed. * The whole mouse initialization process now boils down to enabling the mouse itself and in the controller * All in all, some more mice should be detected now. - Give i8042IsrWritePort a boolean return value and pass the results of the i8042Write calls - Replace two i8042Write calls for writing to the mouse by one i8042IsrWritePort call where possible - Remove the unused KBD_LINE_TEST define
This change was tested under QEMU, VMware and on one real system.
Modified: trunk/reactos/drivers/input/i8042prt/i8042prt.h trunk/reactos/drivers/input/i8042prt/mouse.c trunk/reactos/drivers/input/i8042prt/pnp.c trunk/reactos/drivers/input/i8042prt/readwrite.c
Modified: trunk/reactos/drivers/input/i8042prt/i8042prt.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/input/i8042prt/i804... ============================================================================== --- trunk/reactos/drivers/input/i8042prt/i8042prt.h [iso-8859-1] (original) +++ trunk/reactos/drivers/input/i8042prt/i8042prt.h [iso-8859-1] Mon Mar 31 07:40:31 2008 @@ -224,7 +224,7 @@
#define KBD_READ_MODE 0x20 #define KBD_WRITE_MODE 0x60 -#define KBD_LINE_TEST 0xAB +#define MOUSE_ENAB 0xA8 #define MOUSE_LINE_TEST 0xA9 #define CTRL_SELF_TEST 0xAA #define CTRL_WRITE_MOUSE 0xD4 @@ -277,7 +277,7 @@ * Mouse commands * --------------------------------------------------*/
-#define MOU_CMD_GET_ID 0xF2 +#define MOU_ENAB 0xF4 #define MOU_CMD_RESET 0xFF
/*----------------------------------------------------- @@ -389,7 +389,7 @@ i8042Flush( IN PPORT_DEVICE_EXTENSION DeviceExtension);
-VOID +BOOLEAN i8042IsrWritePort( IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value,
Modified: trunk/reactos/drivers/input/i8042prt/mouse.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/input/i8042prt/mous... ============================================================================== --- trunk/reactos/drivers/input/i8042prt/mouse.c [iso-8859-1] (original) +++ trunk/reactos/drivers/input/i8042prt/mouse.c [iso-8859-1] Mon Mar 31 07:40:31 2008 @@ -7,6 +7,7 @@ Copyright Jason Filby (jasonfilby@yahoo.com) Copyright Martijn Vernooij (o112w8r02@sneakemail.com) Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org) + Copyright 2008 Colin Finck (mail@colinfinck.de) */
/* INCLUDES ****************************************************************/ @@ -211,8 +212,6 @@ (DeviceExtension->MouseButtonState & ~Mask) | (NewButtonData & Mask); }
-static NTSTATUS OldInitialization(PPORT_DEVICE_EXTENSION); /* FIXME */ - /* Does lastest initializations for the mouse. This method * is called just before connecting the interrupt. */ @@ -220,13 +219,34 @@ i8042MouInitialize( IN PI8042_MOUSE_EXTENSION DeviceExtension) { - PPORT_DEVICE_EXTENSION PortDeviceExtension; - - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - -/* FIXME */ OldInitialization(PortDeviceExtension); - - return STATUS_SUCCESS; + NTSTATUS Status; + UCHAR Value; + + /* Enable the PS/2 mouse port */ + i8042Write(DeviceExtension->Common.PortDeviceExtension, DeviceExtension->Common.PortDeviceExtension->ControlPort, MOUSE_ENAB); + + /* Enable the mouse */ + if(!i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, MOU_ENAB, CTRL_WRITE_MOUSE)) + { + WARN_(I8042PRT, "Failed to enable mouse!\n"); + return STATUS_IO_DEVICE_ERROR; + } + + Status = i8042ReadDataWait(DeviceExtension->Common.PortDeviceExtension, &Value); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Failed to read the response of MOU_ENAB, status 0x%08lx\n", Status); + return Status; + } + + if(Value == MOUSE_ACK) + { + INFO_(I8042PRT, "Mouse was enabled successfully!\n"); + return STATUS_SUCCESS; + } + + WARN_(I8042PRT, "Got 0x%02x instead of 0xFA\n", Value); + return STATUS_IO_DEVICE_ERROR; }
static VOID NTAPI @@ -875,182 +895,3 @@
return TRUE; } - -/**************************************************************************************** - * WARNING: the mouse initialization code has been taken from old ReactOS mouse driver, * - * named psaux.sys, which has been deleted in revision 14938. * - * Coding style and structures are not exactly the same as in the other parts of the * - * i8042prt driver, but code is supposed to work. * - ****************************************************************************************/ - -#define CONTROLLER_COMMAND_MOUSE_ENABLE 0xA8 -#define PSMOUSE_CMD_ENABLE 0x00f4 -#define PSMOUSE_CMD_GETID (0x0200 | MOU_CMD_GET_ID) -#define PSMOUSE_CMD_RESET_BAT (0x0200 | MOU_CMD_RESET) -#define PSMOUSE_RET_ACK MOUSE_ACK -#define PSMOUSE_RET_NAK MOUSE_NACK - -typedef struct _I8042_MOUSE_EXTENSION_OLD -{ - PPORT_DEVICE_EXTENSION PortDeviceExtension; - UCHAR pkt[8]; - UCHAR ack; - ULONG RepliesExpected; -} I8042_MOUSE_EXTENSION_OLD, *PI8042_MOUSE_EXTENSION_OLD; - -/* Sends a byte to the mouse */ -static INT SendByte( - IN PI8042_MOUSE_EXTENSION_OLD DeviceExtension, - IN UCHAR byte) -{ - INT timeout = 100; /* 100 msec */ - UCHAR scancode; - LARGE_INTEGER Millisecond_Timeout; - - Millisecond_Timeout.QuadPart = -10000L; - - DeviceExtension->ack = 0; - - i8042IsrWritePort(DeviceExtension->PortDeviceExtension, byte, CTRL_WRITE_MOUSE); - while ((DeviceExtension->ack == 0) && timeout--) - { - if (i8042ReadKeyboardData(DeviceExtension->PortDeviceExtension, &scancode)) - { - switch(scancode) - { - case PSMOUSE_RET_ACK: - DeviceExtension->ack = 1; - break; - case PSMOUSE_RET_NAK: - DeviceExtension->ack = -1; - break; - default: - DeviceExtension->ack = 1; /* Workaround for mice which don't ACK the Get ID command */ - if (DeviceExtension->RepliesExpected) - DeviceExtension->pkt[--DeviceExtension->RepliesExpected] = scancode; - break; - } - return (INT)(-(DeviceExtension->ack <= 0)); - } - KeDelayExecutionThread(KernelMode, FALSE, &Millisecond_Timeout); - } - return (INT)(-(DeviceExtension->ack <= 0)); -} - -/* Send a PS/2 command to the mouse. */ -static INT SendCommand( - IN PI8042_MOUSE_EXTENSION_OLD DeviceExtension, - IN PUCHAR param, - IN INT command) -{ - LARGE_INTEGER Millisecond_Timeout; - UCHAR scancode; - INT timeout = 500; /* 500 msec */ - UCHAR send = (command >> 12) & 0xf; - UCHAR receive = (command >> 8) & 0xf; - UCHAR i; - - Millisecond_Timeout.QuadPart = -10000L; - - DeviceExtension->RepliesExpected = receive; - if (command == PSMOUSE_CMD_RESET_BAT) - timeout = 2000; /* 2 sec */ - - if (command & 0xff) - if (SendByte(DeviceExtension, command & 0xff)) - return (INT)(DeviceExtension->RepliesExpected = 0) - 1; - - for (i = 0; i < send; i++) - if (SendByte(DeviceExtension, param[i])) - return (INT)(DeviceExtension->RepliesExpected = 0) - 1; - - while (DeviceExtension->RepliesExpected && timeout--) - { - if (DeviceExtension->RepliesExpected == 1 && command == PSMOUSE_CMD_RESET_BAT) - timeout = 100; - - if (DeviceExtension->RepliesExpected == 1 && command == PSMOUSE_CMD_GETID && - DeviceExtension->pkt[1] != 0xab && DeviceExtension->pkt[1] != 0xac) - { - DeviceExtension->RepliesExpected = 0; - break; - } - - if (i8042ReadKeyboardData(DeviceExtension->PortDeviceExtension, &scancode)) - { - DeviceExtension->pkt[--DeviceExtension->RepliesExpected] = scancode; - } - - KeDelayExecutionThread (KernelMode, FALSE, &Millisecond_Timeout); - } - - for (i = 0; i < receive; i++) - param[i] = DeviceExtension->pkt[(receive - 1) - i]; - - if (DeviceExtension->RepliesExpected) - return (int)(DeviceExtension->RepliesExpected = 0) - 1; - - return 0; -} - -/* Detect if mouse is just a standard ps/2 mouse */ -static BOOLEAN TestMouse( - IN PI8042_MOUSE_EXTENSION_OLD DeviceExtension) -{ - UCHAR param[4]; - - param[0] = param[1] = 0xa5; - - /* - * First, we check if it's a mouse. It should send 0x00 or 0x03 - * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer. - */ - if(SendCommand(DeviceExtension, param, PSMOUSE_CMD_GETID)) - return -1; - - if(param[0] != 0x00 && param[0] != 0x03 && param[0] != 0x04) - return -1; - - /* - * Then we reset and disable the mouse so that it doesn't generate events. - */ - - return TRUE; -} - -/* Initialize the PS/2 mouse support */ -static BOOLEAN SetupMouse( - IN PI8042_MOUSE_EXTENSION_OLD DeviceExtension) -{ - LARGE_INTEGER Millisecond_Timeout; - - Millisecond_Timeout.QuadPart = -10000L; - - /* setup */ - DeviceExtension->RepliesExpected = 0; - DeviceExtension->ack = 0; - - /* Enable the PS/2 mouse port */ - i8042Write(DeviceExtension->PortDeviceExtension, DeviceExtension->PortDeviceExtension->ControlPort, CONTROLLER_COMMAND_MOUSE_ENABLE); - - if (TestMouse(DeviceExtension)) - { - TRACE_(I8042PRT, "Detected Mouse\n"); - - if (SendCommand(DeviceExtension, NULL, PSMOUSE_CMD_ENABLE)) - WARN_(I8042PRT, "Failed to enable mouse!\n"); - } - - return TRUE; -} - -static NTSTATUS OldInitialization( - IN PPORT_DEVICE_EXTENSION PortDeviceExtension) -{ - I8042_MOUSE_EXTENSION_OLD DeviceExtension; - - RtlZeroMemory(&DeviceExtension, sizeof(I8042_MOUSE_EXTENSION_OLD)); - DeviceExtension.PortDeviceExtension = PortDeviceExtension; - SetupMouse(&DeviceExtension); - return STATUS_SUCCESS; -}
Modified: trunk/reactos/drivers/input/i8042prt/pnp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/input/i8042prt/pnp.... ============================================================================== --- trunk/reactos/drivers/input/i8042prt/pnp.c [iso-8859-1] (original) +++ trunk/reactos/drivers/input/i8042prt/pnp.c [iso-8859-1] Mon Mar 31 07:40:31 2008 @@ -179,8 +179,7 @@
i8042Flush(DeviceExtension);
- if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_WRITE_MOUSE) - ||!i8042Write(DeviceExtension, DeviceExtension->DataPort, MOU_CMD_RESET)) + if(!i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE)) { WARN_(I8042PRT, "Failed to write reset command to mouse\n"); goto failure; @@ -383,10 +382,7 @@ KIRQL Irql;
Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); - - i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_WRITE_MOUSE); - i8042Write(DeviceExtension, DeviceExtension->DataPort, MOU_CMD_RESET); - + i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE); KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); }
Modified: trunk/reactos/drivers/input/i8042prt/readwrite.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/input/i8042prt/read... ============================================================================== --- trunk/reactos/drivers/input/i8042prt/readwrite.c [iso-8859-1] (original) +++ trunk/reactos/drivers/input/i8042prt/readwrite.c [iso-8859-1] Mon Mar 31 07:40:31 2008 @@ -34,7 +34,7 @@ } }
-VOID +BOOLEAN i8042IsrWritePort( IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value, @@ -42,9 +42,9 @@ { if (SelectCmd) if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd)) - return; - - i8042Write(DeviceExtension, DeviceExtension->DataPort, Value); + return FALSE; + + return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value); }
/*