]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/I2c/I2cDxe/I2cHost.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / I2c / I2cDxe / I2cHost.c
index 0cc8e33842833c846e8adfa28665cac382954403..79c0916946772350dfc9cc4b078f139c99153a38 100644 (file)
@@ -1,15 +1,10 @@
 /** @file\r
-  This file implements I2C Host Protocol which provides callers with the ability to \r
+  This file implements I2C Host Protocol which provides callers with the ability to\r
   do I/O transactions to all of the devices on the I2C bus.\r
 \r
-  Copyright (c) 2013 - 2014, 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) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -25,7 +20,7 @@ EFI_DRIVER_BINDING_PROTOCOL gI2cHostDriverBinding = {
 };\r
 \r
 //\r
-// Driver name table \r
+// Driver name table\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mI2cHostDriverNameTable[] = {\r
   { "eng;en", L"I2c Host Driver" },\r
@@ -355,7 +350,7 @@ I2cHostDriverStart (
   //\r
   // Locate I2C Master Protocol\r
   //\r
-  Status = gBS->OpenProtocol ( \r
+  Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiI2cMasterProtocolGuid,\r
                   (VOID **)&I2cMaster,\r
@@ -424,7 +419,7 @@ I2cHostDriverStart (
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "I2cHost: create bus available event error, Status = %r\n", Status));\r
     goto Exit;\r
-  }  \r
+  }\r
 \r
   //\r
   // Build the I2C host protocol for the current I2C controller\r
@@ -450,9 +445,9 @@ Exit:
                       &gEfiI2cBusConfigurationManagementProtocolGuid,\r
                       This->DriverBindingHandle,\r
                       Controller\r
-                      );      \r
+                      );\r
     }\r
-    \r
+\r
     if ((I2cHostContext != NULL) && (I2cHostContext->I2cEvent != NULL)) {\r
       gBS->CloseEvent (I2cHostContext->I2cEvent);\r
       I2cHostContext->I2cEvent = NULL;\r
@@ -512,7 +507,7 @@ I2cHostDriverStop (
   IN  EFI_HANDLE                        *ChildHandleBuffer\r
   )\r
 {\r
-  EFI_STATUS                  Status;  \r
+  EFI_STATUS                  Status;\r
   I2C_HOST_CONTEXT            *I2cHostContext;\r
   EFI_I2C_HOST_PROTOCOL       *I2cHost;\r
   EFI_TPL                     TplPrevious;\r
@@ -542,14 +537,14 @@ I2cHostDriverStop (
   // Raise TPL for critical section\r
   //\r
   TplPrevious = gBS->RaiseTPL (TPL_I2C_SYNC);\r
-  \r
+\r
   //\r
   // If there is pending request or pending bus configuration, do not stop\r
   //\r
   Status = EFI_DEVICE_ERROR;\r
   if (( !I2cHostContext->I2cBusConfigurationManagementPending )\r
     && IsListEmpty (&I2cHostContext->RequestList)) {\r
-    \r
+\r
     //\r
     //  Remove the I2C host protocol\r
     //\r
@@ -560,7 +555,7 @@ I2cHostDriverStop (
                     NULL\r
                     );\r
   }\r
-  \r
+\r
   //\r
   // Leave critical section\r
   //\r
@@ -580,12 +575,12 @@ I2cHostDriverStop (
       gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);\r
       I2cHostContext->I2cBusConfigurationEvent = NULL;\r
     }\r
-    \r
+\r
     if (I2cHostContext->I2cEvent != NULL) {\r
       gBS->CloseEvent (I2cHostContext->I2cEvent);\r
       I2cHostContext->I2cEvent = NULL;\r
     }\r
-    \r
+\r
     FreePool (I2cHostContext);\r
   }\r
 \r
@@ -643,7 +638,7 @@ I2cHostI2cBusConfigurationAvailable (
     // Force next operation to enable the I2C bus configuration\r
     //\r
     I2cHostContext->I2cBusConfiguration = (UINTN) -1;\r
-    \r
+\r
     //\r
     // Do not continue current I2C request\r
     //\r
@@ -665,13 +660,17 @@ I2cHostI2cBusConfigurationAvailable (
   //\r
   // Start an I2C operation on the host, the status is returned by I2cHostContext->Status\r
   //\r
-  Status = I2cMaster->StartRequest ( \r
+  Status = I2cMaster->StartRequest (\r
                         I2cMaster,\r
                         I2cRequest->SlaveAddress,\r
                         I2cRequest->RequestPacket,\r
                         I2cHostContext->I2cEvent,\r
                         &I2cHostContext->Status\r
                         );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG((DEBUG_ERROR, "I2cHostI2cBusConfigurationAvailable: Error starting I2C operation, %r\n", Status));\r
+  }\r
 }\r
 \r
 /**\r
@@ -729,7 +728,7 @@ I2cHostRequestComplete (
   if(!IsListEmpty (EntryHeader)) {\r
     I2cHostRequestEnable (I2cHostContext);\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -891,8 +890,6 @@ I2cHostRequestEnable (
                               completion status\r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
-  @retval EFI_ABORTED           The request did not complete because the driver\r
-                                was shutdown.\r
   @retval EFI_BAD_BUFFER_SIZE   The WriteBytes or ReadBytes buffer size is too large.\r
   @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the operation.\r
                                 This could indicate the slave device is not present.\r
@@ -939,7 +936,7 @@ I2cHostQueueRequest (
   if (RequestPacket == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if ((SlaveAddress & I2C_ADDRESSING_10_BIT) != 0) {\r
     //\r
     // 10-bit address, bits 0-9 are used for 10-bit I2C slave addresses,\r
@@ -967,7 +964,7 @@ I2cHostQueueRequest (
     //\r
     // For synchronous transaction, register an event used to wait for finishing synchronous transaction\r
     //\r
-    Status = gBS->CreateEvent ( \r
+    Status = gBS->CreateEvent (\r
                 0,\r
                 TPL_I2C_SYNC,\r
                 NULL,\r
@@ -978,7 +975,7 @@ I2cHostQueueRequest (
       return Status;\r
     }\r
   }\r
\r
+\r
   //\r
   // TPL should be at or below TPL_NOTIFY.\r
   // For synchronous requests this routine must be called at or below TPL_CALLBACK.\r
@@ -1012,15 +1009,16 @@ I2cHostQueueRequest (
   //\r
   RequestPacketSize = sizeof (UINTN) + RequestPacket->OperationCount * sizeof (EFI_I2C_OPERATION);\r
   I2cRequest->RequestPacket = AllocateZeroPool (RequestPacketSize);\r
+  ASSERT (I2cRequest->RequestPacket != NULL);\r
   CopyMem (I2cRequest->RequestPacket, RequestPacket, RequestPacketSize);\r
 \r
   //\r
   // Synchronize with the other threads\r
   //\r
   gBS->RaiseTPL ( TPL_I2C_SYNC );\r
-  \r
+\r
   FirstRequest = IsListEmpty (&I2cHostContext->RequestList);\r
-  \r
+\r
   //\r
   // Insert new I2C request in the list\r
   //\r
@@ -1030,7 +1028,7 @@ I2cHostQueueRequest (
   // Release the thread synchronization\r
   //\r
   gBS->RestoreTPL (TplPrevious);\r
-  \r
+\r
   if (FirstRequest) {\r
     //\r
     // Start the first I2C request, then the subsequent of I2C request will continue\r