]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
MdeModulePkg/UsbMouse: Fix few typos
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseDxe / UsbMouse.c
index 205e92b2cbd46094bfd6fe500ce53ce77329ded7..9861c32d4971a9c38471337948b571aa731801cd 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   USB Mouse Driver that manages USB mouse and produces Simple Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -115,7 +109,7 @@ USBMouseDriverBindingSupported (
 /**\r
   Starts the mouse device with this driver.\r
 \r
-  This function consumes USB I/O Portocol, intializes USB mouse device,\r
+  This function consumes USB I/O Protocol, initializes USB mouse device,\r
   installs Simple Pointer Protocol, and submits Asynchronous Interrupt\r
   Transfer to manage the USB mouse device.\r
 \r
@@ -188,6 +182,16 @@ USBMouseDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
+\r
+  //\r
+  // Report Status Code here since USB mouse will be detected next.\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT),\r
+    UsbMouseDevice->DevicePath\r
+    );\r
+\r
   //\r
   // Get interface & endpoint descriptor\r
   //\r
@@ -199,7 +203,7 @@ USBMouseDriverBindingStart (
   EndpointNumber = UsbMouseDevice->InterfaceDescriptor.NumEndpoints;\r
 \r
   //\r
-  // Traverse endpoints to find interrupt endpoint\r
+  // Traverse endpoints to find interrupt endpoint IN\r
   //\r
   Found = FALSE;\r
   for (Index = 0; Index < EndpointNumber; Index++) {\r
@@ -209,7 +213,8 @@ USBMouseDriverBindingStart (
              &EndpointDescriptor\r
              );\r
 \r
-    if ((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) {\r
+    if (((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) &&\r
+        ((EndpointDescriptor.EndpointAddress & USB_ENDPOINT_DIR_IN) != 0)) {\r
       //\r
       // We only care interrupt endpoint here\r
       //\r
@@ -221,12 +226,28 @@ USBMouseDriverBindingStart (
 \r
   if (!Found) {\r
     //\r
+    // Report Status Code to indicate that there is no USB mouse\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED)\r
+      );\r
+    //\r
     // No interrupt endpoint found, then return unsupported.\r
     //\r
     Status = EFI_UNSUPPORTED;\r
     goto ErrorExit;\r
   }\r
 \r
+  //\r
+  // Report Status Code here since USB mouse has be detected.\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_DETECTED),\r
+    UsbMouseDevice->DevicePath\r
+    );\r
+\r
   Status = InitializeUsbMouseDevice (UsbMouseDevice);\r
   if (EFI_ERROR (Status)) {\r
     //\r
@@ -309,7 +330,7 @@ USBMouseDriverBindingStart (
            );\r
     goto ErrorExit;\r
   }\r
-  \r
+\r
   UsbMouseDevice->ControllerNameTable = NULL;\r
   AddUnicodeString2 (\r
     "eng",\r
@@ -526,8 +547,6 @@ InitializeUsbMouseDevice (
   EFI_STATUS                Status;\r
   EFI_USB_HID_DESCRIPTOR    *MouseHidDesc;\r
   UINT8                     *ReportDesc;\r
-  UINT8                     ReportId;\r
-  UINT8                     Duration;\r
   EFI_USB_CONFIG_DESCRIPTOR ConfigDesc;\r
   VOID                      *Buf;\r
   UINT32                    TransferResult;\r
@@ -572,7 +591,7 @@ InitializeUsbMouseDevice (
 \r
   Total = 0;\r
   Start = FALSE;\r
-  Head  = (USB_DESC_HEAD *)Buf;  \r
+  Head  = (USB_DESC_HEAD *)Buf;\r
   MouseHidDesc = NULL;\r
 \r
   //\r
@@ -679,23 +698,6 @@ InitializeUsbMouseDevice (
     }\r
   }\r
 \r
-  //\r
-  // ReportId is zero, which means the idle rate applies to all input reports.\r
-  //\r
-  ReportId = 0;\r
-  //\r
-  // Duration is zero, which means the duration is infinite.\r
-  // so the endpoint will inhibit reporting forever,\r
-  // and only reporting when a change is detected in the report data.\r
-  //\r
-  Duration = 0;\r
-  UsbSetIdleRequest (\r
-    UsbIo,\r
-    UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
-    ReportId,\r
-    Duration\r
-    );\r
-\r
   FreePool (Buf);\r
   FreePool (ReportDesc);\r
 \r
@@ -775,7 +777,7 @@ OnMouseInterruptComplete (
 \r
     //\r
     // Delete & Submit this interrupt again\r
-    // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt. \r
+    // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.\r
     //\r
     UsbIo->UsbAsyncInterruptTransfer (\r
              UsbIo,\r
@@ -804,8 +806,6 @@ OnMouseInterruptComplete (
     return EFI_SUCCESS;\r
   }\r
 \r
-  UsbMouseDevice->StateChanged = TRUE;\r
-\r
   //\r
   // Check mouse Data\r
   // USB HID Specification specifies following data format:\r
@@ -818,6 +818,12 @@ OnMouseInterruptComplete (
   // 2       0 to 7  Y displacement\r
   // 3 to n  0 to 7  Device specific (optional)\r
   //\r
+  if (DataLength < 3) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  UsbMouseDevice->StateChanged = TRUE;\r
+\r
   UsbMouseDevice->State.LeftButton  = (BOOLEAN) ((*(UINT8 *) Data & BIT0) != 0);\r
   UsbMouseDevice->State.RightButton = (BOOLEAN) ((*(UINT8 *) Data & BIT1) != 0);\r
   UsbMouseDevice->State.RelativeMovementX += *((INT8 *) Data + 1);\r
@@ -832,16 +838,16 @@ OnMouseInterruptComplete (
 \r
 /**\r
   Retrieves the current state of a pointer device.\r
-    \r
-  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.                                   \r
+\r
+  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
   @param  MouseState            A pointer to the state information on the pointer device.\r
-                                \r
+\r
   @retval EFI_SUCCESS           The state of the pointer device was returned in State.\r
   @retval EFI_NOT_READY         The state of the pointer device has not changed since the last call to\r
-                                GetState().                                                           \r
+                                GetState().\r
   @retval EFI_DEVICE_ERROR      A device error occurred while attempting to retrieve the pointer device's\r
-                                current state.                                                           \r
-  @retval EFI_INVALID_PARAMETER MouseState is NULL.                                                           \r
+                                current state.\r
+  @retval EFI_INVALID_PARAMETER MouseState is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -885,13 +891,13 @@ GetMouseState (
 }\r
 \r
 \r
-/**                                                                 \r
+/**\r
   Resets the pointer device hardware.\r
-  \r
+\r
   @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
   @param  ExtendedVerification  Indicates that the driver may perform a more exhaustive\r
                                 verification operation of the device during reset.\r
-                                \r
+\r
   @retval EFI_SUCCESS           The device was reset.\r
   @retval EFI_DEVICE_ERROR      The device is not functioning correctly and could not be reset.\r
 \r
@@ -930,7 +936,7 @@ UsbMouseReset (
 \r
   @param  Event        Event to be signaled when there's input from mouse.\r
   @param  Context      Points to USB_MOUSE_DEV instance.\r
\r
+\r
 **/\r
 VOID\r
 EFIAPI\r