I am new to UEFI and I am attempting to talk to an i2c bus on an Up eXtreme board. I have tried following people trying similar things with USB online but gBS->LocateHandleBuffer
does not seem to find the i2c bus. I am led to assume that since i2c behaves differently to USB I may not be able to take the same approach with it, but I have no way of confirming my suspicions.
At this point any tips/pointers would be appreciated.
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE* SystemTable
)
{
EFI_STATUS Status;
EFI_HANDLE* HandleBuffer = NULL;
UINTN HandleCount = 17;
Print(L"HandleCount: %x\n", HandleCount);
Print(L"HandleBuffer: %x\n", HandleBuffer);
UINTN* freq = (UINTN*)23;
EFI_I2C_DEVICE* i2cDescriptor;
EFI_I2C_ENUMERATE_PROTOCOL* enumerateI2c;
Status = gBS->LocateHandleBuffer(ByProtocol,
&gEfiI2cEnumerateProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer);
if (EFI_ERROR(Status)) {
Print(L"ERROR: LocateHandleBuffer.\n");
Print(L"Status: %x\n", (int)Status);
Print(L"HandleCount: %x\n", HandleCount);
Print(L"HandleBuffer: %x\n", HandleBuffer);
return Status;
}
for (UINT8 Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol(HandleBuffer[Index],
&gEfiI2cEnumerateProtocolGuid,
(VOID**)&enumerateI2c);
if (EFI_ERROR(Status)) {
Print(L"ERROR: HandleProtocol.\n");
Print(L"Status: %x\n", (int)Status);
Print(L"HandleCount: %x\n", HandleCount);
Print(L"HandleBuffer: %x\n", HandleBuffer);
FreePool(HandleBuffer);
return Status;
}
Status = enumerateI2c->Enumerate(enumerateI2c, &i2cDescriptor);
Print(L"Starting to enumerate\n");
if (EFI_ERROR(Status)) {
Print(L"ERROR: Enumerate.\n");
Print(L"Status: %x\n", (int)Status);
Print(L"HandleCount: %x\n", HandleCount);
Print(L"HandleBuffer: %x\n", HandleBuffer);
FreePool(HandleBuffer);
return Status;
}
Print(L"Enumeration complete\nGetting Bus frequency\n");
Status = enumerateI2c->GetBusFrequency(enumerateI2c, i2cDescriptor->I2cBusConfiguration, freq);
if (EFI_ERROR(Status)) {
Print(L"ERROR: GetBusFrequency.\n");
Print(L"Status: %x\n", (int)Status);
FreePool(HandleBuffer);
return Status;
}
Print(L"Found Frequency:\n");
Print(L"%d\n", (CHAR16*)freq);
}
FreePool(HandleBuffer);
return EFI_SUCCESS;
}