/** @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
};\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
//\r
// Locate I2C Master Protocol\r
//\r
- Status = gBS->OpenProtocol ( \r
+ Status = gBS->OpenProtocol (\r
Controller,\r
&gEfiI2cMasterProtocolGuid,\r
(VOID **)&I2cMaster,\r
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
&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
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
// 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
NULL\r
);\r
}\r
- \r
+\r
//\r
// Leave critical section\r
//\r
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
// 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
//\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
if(!IsListEmpty (EntryHeader)) {\r
I2cHostRequestEnable (I2cHostContext);\r
}\r
- \r
+\r
return Status;\r
}\r
\r
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
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
//\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
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
//\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
// 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
&DeviceHandleBuffer\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Disconnect the driver specified by ImageHandle from all\r
- // the devices in the handle database.\r
- //\r
- for (Index = 0; Index < DeviceHandleCount; Index++) {\r
- Status = gBS->DisconnectController (\r
- DeviceHandleBuffer[Index],\r
- ImageHandle,\r
- NULL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Disconnect the driver specified by ImageHandle from all\r
+ // the devices in the handle database.\r
+ //\r
+ for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+ Status = gBS->DisconnectController (\r
+ DeviceHandleBuffer[Index],\r
+ ImageHandle,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
}\r
}\r
\r