- Remove much deprecated code for the mouse initialization (had been imported from...
authorColin Finck <colin@reactos.org>
Mon, 31 Mar 2008 12:40:31 +0000 (12:40 +0000)
committerColin Finck <colin@reactos.org>
Mon, 31 Mar 2008 12:40:31 +0000 (12:40 +0000)
  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.

svn path=/trunk/; revision=32790

reactos/drivers/input/i8042prt/i8042prt.h
reactos/drivers/input/i8042prt/mouse.c
reactos/drivers/input/i8042prt/pnp.c
reactos/drivers/input/i8042prt/readwrite.c

index c96069b..5820180 100644 (file)
@@ -224,7 +224,7 @@ typedef struct _I8042_HOOK_WORKITEM
 
 #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 @@ typedef struct _I8042_HOOK_WORKITEM
  * Mouse commands
  * --------------------------------------------------*/
 
-#define MOU_CMD_GET_ID     0xF2
+#define MOU_ENAB           0xF4
 #define MOU_CMD_RESET      0xFF
 
 /*-----------------------------------------------------
@@ -389,7 +389,7 @@ VOID
 i8042Flush(
        IN PPORT_DEVICE_EXTENSION DeviceExtension);
 
-VOID
+BOOLEAN
 i8042IsrWritePort(
        IN PPORT_DEVICE_EXTENSION DeviceExtension,
        IN UCHAR Value,
index 8a3f703..a53d5b7 100644 (file)
@@ -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 @@ i8042MouHandleButtons(
                (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 @@ NTSTATUS
 i8042MouInitialize(
        IN PI8042_MOUSE_EXTENSION DeviceExtension)
 {
-       PPORT_DEVICE_EXTENSION PortDeviceExtension;
+       NTSTATUS Status;
+       UCHAR Value;
 
-       PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension;
+       /* 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;
+       }
 
-/* FIXME */ OldInitialization(PortDeviceExtension);
+       if(Value == MOUSE_ACK)
+       {
+               INFO_(I8042PRT, "Mouse was enabled successfully!\n");
+               return STATUS_SUCCESS;
+       }
 
-       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 @@ i8042MouInterruptService(
 
        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;
-}
index c70987b..f767e67 100644 (file)
@@ -179,8 +179,7 @@ i8042DetectMouse(
 
        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 @@ EnableInterrupts(
                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);
        }
 
index a01017c..651f713 100644 (file)
@@ -34,7 +34,7 @@ i8042Flush(
        }
 }
 
-VOID
+BOOLEAN
 i8042IsrWritePort(
        IN PPORT_DEVICE_EXTENSION DeviceExtension,
        IN UCHAR Value,
@@ -42,9 +42,9 @@ i8042IsrWritePort(
 {
        if (SelectCmd)
                if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd))
-                       return;
+                       return FALSE;
 
-       i8042Write(DeviceExtension, DeviceExtension->DataPort, Value);
+       return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value);
 }
 
 /*