26 {
"eng;en", L
"I2c Host Driver" },
92 OUT CHAR16 **DriverName
97 This->SupportedLanguages,
98 mI2cHostDriverNameTable,
100 (BOOLEAN)(This != &gI2cHostComponentName2)
179 OUT CHAR16 **ControllerName
182 return EFI_UNSUPPORTED;
242 Status =
gBS->OpenProtocol (
245 (VOID **)&I2cBusConfigurationManagement,
246 This->DriverBindingHandle,
248 EFI_OPEN_PROTOCOL_BY_DRIVER
250 if (EFI_ERROR (Status)) {
260 This->DriverBindingHandle,
267 Status =
gBS->OpenProtocol (
269 &gEfiI2cMasterProtocolGuid,
271 This->DriverBindingHandle,
273 EFI_OPEN_PROTOCOL_GET_PROTOCOL
275 if (EFI_ERROR (Status)) {
331 I2cHostContext =
NULL;
332 I2cBusConfigurationManagement =
NULL;
337 Status =
gBS->OpenProtocol (
340 (VOID **)&I2cBusConfigurationManagement,
341 This->DriverBindingHandle,
343 EFI_OPEN_PROTOCOL_BY_DRIVER
345 if (EFI_ERROR (Status)) {
346 DEBUG ((DEBUG_ERROR,
"I2cHost: Open I2C bus configuration error, Status = %r\n", Status));
353 Status =
gBS->OpenProtocol (
355 &gEfiI2cMasterProtocolGuid,
357 This->DriverBindingHandle,
359 EFI_OPEN_PROTOCOL_GET_PROTOCOL
361 if (EFI_ERROR (Status)) {
362 DEBUG ((DEBUG_ERROR,
"I2cHost: Open I2C master error, Status = %r\n", Status));
370 if (I2cHostContext ==
NULL) {
371 DEBUG ((DEBUG_ERROR,
"I2cHost: there is no enough memory to allocate.\n"));
372 Status = EFI_OUT_OF_RESOURCES;
379 I2cHostContext->Signature = I2C_HOST_SIGNATURE;
380 I2cHostContext->I2cMaster = I2cMaster;
381 I2cHostContext->I2cBusConfigurationManagement = I2cBusConfigurationManagement;
382 I2cHostContext->I2cBusConfiguration = (
UINTN)-1;
388 Status = I2cMaster->
Reset (I2cMaster);
389 if (EFI_ERROR (Status)) {
390 DEBUG ((DEBUG_ERROR,
"I2cHost: I2C controller reset failed!\n"));
397 Status =
gBS->CreateEvent (
402 &I2cHostContext->I2cEvent
404 if (EFI_ERROR (Status)) {
405 DEBUG ((DEBUG_ERROR,
"I2cHost: create complete event error, Status = %r\n", Status));
412 Status =
gBS->CreateEvent (
417 &I2cHostContext->I2cBusConfigurationEvent
419 if (EFI_ERROR (Status)) {
420 DEBUG ((DEBUG_ERROR,
"I2cHost: create bus available event error, Status = %r\n", Status));
433 Status =
gBS->InstallMultipleProtocolInterfaces (
436 &I2cHostContext->I2cHost,
440 if (EFI_ERROR (Status)) {
441 DEBUG ((DEBUG_ERROR,
"I2cHost: Start() function failed, Status = %r\n", Status));
442 if (I2cBusConfigurationManagement !=
NULL) {
446 This->DriverBindingHandle,
451 if ((I2cHostContext !=
NULL) && (I2cHostContext->I2cEvent !=
NULL)) {
452 gBS->CloseEvent (I2cHostContext->I2cEvent);
453 I2cHostContext->I2cEvent =
NULL;
456 if ((I2cHostContext !=
NULL) && (I2cHostContext->I2cBusConfigurationEvent !=
NULL)) {
457 gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);
458 I2cHostContext->I2cBusConfigurationEvent =
NULL;
464 if (I2cHostContext !=
NULL) {
516 if (TplPrevious > TPL_I2C_SYNC) {
517 DEBUG ((DEBUG_ERROR,
"I2cHost: TPL %d is too high in Stop.\n", TplPrevious));
518 return EFI_DEVICE_ERROR;
521 Status =
gBS->OpenProtocol (
525 This->DriverBindingHandle,
527 EFI_OPEN_PROTOCOL_GET_PROTOCOL
530 if (EFI_ERROR (Status)) {
531 return EFI_DEVICE_ERROR;
534 I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (I2cHost);
539 TplPrevious =
gBS->RaiseTPL (TPL_I2C_SYNC);
544 Status = EFI_DEVICE_ERROR;
545 if ( (!I2cHostContext->I2cBusConfigurationManagementPending)
551 Status =
gBS->UninstallMultipleProtocolInterfaces (
562 gBS->RestoreTPL (TplPrevious);
563 if (!EFI_ERROR (Status)) {
567 This->DriverBindingHandle,
574 if (I2cHostContext->I2cBusConfigurationEvent !=
NULL) {
575 gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);
576 I2cHostContext->I2cBusConfigurationEvent =
NULL;
579 if (I2cHostContext->I2cEvent !=
NULL) {
580 gBS->CloseEvent (I2cHostContext->I2cEvent);
581 I2cHostContext->I2cEvent =
NULL;
620 I2cMaster = I2cHostContext->I2cMaster;
621 ASSERT (I2cMaster !=
NULL);
625 I2cHostContext->I2cBusConfigurationManagementPending =
FALSE;
630 if (EFI_ERROR (I2cHostContext->Status)) {
640 I2cHostContext->I2cBusConfiguration = (
UINTN)-1;
651 EntryHeader = &I2cHostContext->RequestList;
653 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);
658 I2cHostContext->I2cBusConfiguration = I2cRequest->I2cBusConfiguration;
665 I2cRequest->SlaveAddress,
666 I2cRequest->RequestPacket,
667 I2cHostContext->I2cEvent,
668 &I2cHostContext->Status
671 if (EFI_ERROR (Status)) {
672 DEBUG ((DEBUG_ERROR,
"I2cHostI2cBusConfigurationAvailable: Error starting I2C operation, %r\n", Status));
700 EntryHeader = &I2cHostContext->RequestList;
702 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);
707 if (
NULL != I2cRequest->Status ) {
708 *I2cRequest->Status = Status;
714 if (
NULL != I2cRequest->Event ) {
715 gBS->SignalEvent (I2cRequest->Event);
722 FreePool (I2cRequest->RequestPacket);
790 UINTN I2cBusConfiguration;
801 Status = EFI_NOT_READY;
803 I2cBusConfigurationManagement = I2cHostContext->I2cBusConfigurationManagement;
808 EntryHeader = &I2cHostContext->RequestList;
810 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);
812 I2cBusConfiguration = I2cRequest->I2cBusConfiguration;
814 if (I2cHostContext->I2cBusConfiguration != I2cBusConfiguration ) {
818 I2cHostContext->I2cBusConfigurationManagementPending =
TRUE;
822 Status = I2cBusConfigurationManagement->EnableI2cBusConfiguration (
823 I2cBusConfigurationManagement,
825 I2cHostContext->I2cBusConfigurationEvent,
826 &I2cHostContext->Status
832 TplPrevious =
gBS->RaiseTPL (TPL_I2C_SYNC);
843 gBS->RestoreTPL (TplPrevious);
929 BOOLEAN FirstRequest;
930 UINTN RequestPacketSize;
934 FirstRequest =
FALSE;
937 if (RequestPacket ==
NULL) {
938 return EFI_INVALID_PARAMETER;
959 return EFI_NOT_FOUND;
962 I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (This);
968 Status =
gBS->CreateEvent (
975 if (EFI_ERROR (Status)) {
985 if ((TplPrevious > TPL_I2C_SYNC) || ((Event ==
NULL) && (TplPrevious > TPL_CALLBACK))) {
986 DEBUG ((DEBUG_ERROR,
"ERROR - TPL %d is too high!\n", TplPrevious));
987 return EFI_INVALID_PARAMETER;
994 if (I2cRequest ==
NULL) {
995 DEBUG ((DEBUG_ERROR,
"WARNING - Failed to allocate I2C_REQUEST!\n"));
996 return EFI_OUT_OF_RESOURCES;
1002 I2cRequest->Signature = I2C_REQUEST_SIGNATURE;
1003 I2cRequest->I2cBusConfiguration = I2cBusConfiguration;
1004 I2cRequest->SlaveAddress = SlaveAddress;
1005 I2cRequest->Event = (Event ==
NULL) ? SyncEvent : Event;
1006 I2cRequest->Status = I2cStatus;
1013 ASSERT (I2cRequest->RequestPacket !=
NULL);
1014 CopyMem (I2cRequest->RequestPacket, RequestPacket, RequestPacketSize);
1019 gBS->RaiseTPL (TPL_I2C_SYNC);
1021 FirstRequest =
IsListEmpty (&I2cHostContext->RequestList);
1026 InsertTailList (&I2cHostContext->RequestList, &I2cRequest->Link);
1031 gBS->RestoreTPL (TplPrevious);
1040 if (Event !=
NULL) {
1052 Status =
gBS->CheckEvent (SyncEvent);
1053 }
while (Status == EFI_NOT_READY);
1058 Status = I2cHostContext->Status;
1063 if (I2cStatus !=
NULL) {
1064 *I2cStatus = Status;
1070 if (SyncEvent !=
NULL) {
1071 gBS->CloseEvent (SyncEvent);
1102 &gI2cHostDriverBinding,
1104 &gI2cHostComponentName,
1105 &gI2cHostComponentName2
1131 UINTN DeviceHandleCount;
1141 Status =
gBS->LocateHandleBuffer (
1149 if (!EFI_ERROR (Status)) {
1154 for (Index = 0; Index < DeviceHandleCount; Index++) {
1155 Status =
gBS->DisconnectController (
1156 DeviceHandleBuffer[Index],
1160 if (EFI_ERROR (Status)) {
1169 Status =
gBS->UninstallMultipleProtocolInterfaces (
1171 &gEfiDriverBindingProtocolGuid,
1172 &gI2cHostDriverBinding,
1186 Status =
gBS->HandleProtocol (
1188 &gEfiComponentNameProtocolGuid,
1189 (VOID **)&ComponentName
1191 if (!EFI_ERROR (Status)) {
1192 gBS->UninstallProtocolInterface (
1194 &gEfiComponentNameProtocolGuid,
1199 Status =
gBS->HandleProtocol (
1201 &gEfiComponentName2ProtocolGuid,
1202 (VOID **)&ComponentName2
1204 if (!EFI_ERROR (Status)) {
1205 gBS->UninstallProtocolInterface (
1207 &gEfiComponentName2ProtocolGuid,
1218 if (DeviceHandleBuffer !=
NULL) {
1219 gBS->FreePool (DeviceHandleBuffer);
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
UINT32 EFIAPI BitFieldRead32(IN UINT32 Operand, IN UINTN StartBit, IN UINTN EndBit)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_GUID gEfiI2cBusConfigurationManagementProtocolGuid
EFI_STATUS EFIAPI I2cHostDriverStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS I2cHostRequestComplete(I2C_HOST_CONTEXT *I2cHostContext, EFI_STATUS Status)
EFI_STATUS EFIAPI I2cHostUnload(IN EFI_HANDLE ImageHandle)
EFI_STATUS EFIAPI I2cHostComponentNameGetDriverName(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
VOID EFIAPI I2cHostI2cBusConfigurationAvailable(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS I2cHostRequestEnable(I2C_HOST_CONTEXT *I2cHostContext)
EFI_STATUS EFIAPI InitializeI2cHost(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI I2cHostComponentNameGetControllerName(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI I2cHostDriverSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI I2cHostQueueRequest(IN CONST EFI_I2C_HOST_PROTOCOL *This, IN UINTN I2cBusConfiguration, IN UINTN SlaveAddress, IN EFI_EVENT Event OPTIONAL, IN EFI_I2C_REQUEST_PACKET *RequestPacket, OUT EFI_STATUS *I2cStatus OPTIONAL)
EFI_STATUS EFIAPI I2cHostDriverStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
VOID EFIAPI I2cHostRequestCompleteEvent(IN EFI_EVENT Event, IN VOID *Context)
EFI_GUID gEfiI2cHostProtocolGuid
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME_GET_DRIVER_NAME)(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
#define I2C_ADDRESSING_10_BIT
VOID EFIAPI Exit(IN EFI_STATUS Status)
EFI_TPL EFIAPI EfiGetCurrentTpl(VOID)
EFI_STATUS EFIAPI LookupUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable, OUT CHAR16 **UnicodeString, IN BOOLEAN Iso639Language)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_HANDLE DriverBindingHandle
CONST EFI_I2C_CONTROLLER_CAPABILITIES * I2cControllerCapabilities
EFI_I2C_HOST_PROTOCOL_QUEUE_REQUEST QueueRequest
EFI_I2C_MASTER_PROTOCOL_RESET Reset
EFI_I2C_MASTER_PROTOCOL_START_REQUEST StartRequest
CONST EFI_I2C_CONTROLLER_CAPABILITIES * I2cControllerCapabilities