Now that we have a generic Bcm I2C driver lets instantiate one against a possible RTC hat on the pi4.
Signed-off-by: Jeremy Linton <jeremy.lin...@arm.com> --- .../Drivers/BcmI2CPlatform/BcmI2CPlatform.c | 127 ++++++++++++++++++ .../Drivers/BcmI2CPlatform/BcmI2CPlatform.inf | 54 ++++++++ 2 files changed, 181 insertions(+) create mode 100644 Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c create mode 100644 Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf diff --git a/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c new file mode 100644 index 0000000000..11f927b848 --- /dev/null +++ b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c @@ -0,0 +1,127 @@ +/** @file + Brcm/Rpi I2C DXE platform driver. + + Copyright 2018-2020 NXP + Sourced and reworked from edk2/NXP I2C stack + Copyright 2022 Arm, Jeremy Linton + + SPDX-License-Identifier: BSD-2-Clause-Patent + + This thing binds a I2C driver to a RTC.. + +**/ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <IndustryStandard/Bcm2836.h> + +#include <Protocol/NonDiscoverableDevice.h> + +typedef struct { + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR StartDesc; + UINT8 EndDesc; +} ADDRESS_SPACE_DESCRIPTOR; + +#define BCM_I2C_NUM_CONTROLLERS 1 //actually 6 on the bcm2711, hack for now + +STATIC ADDRESS_SPACE_DESCRIPTOR mI2cDesc[BCM_I2C_NUM_CONTROLLERS]; + +STATIC +EFI_STATUS +RegisterDevice ( + IN EFI_GUID *TypeGuid, + IN ADDRESS_SPACE_DESCRIPTOR *Desc, + OUT EFI_HANDLE *Handle + ) +{ + NON_DISCOVERABLE_DEVICE *Device; + EFI_STATUS Status; + + Device = (NON_DISCOVERABLE_DEVICE *)AllocateZeroPool (sizeof (*Device)); + if (Device == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Device->Type = TypeGuid; + Device->DmaType = NonDiscoverableDeviceDmaTypeNonCoherent; + Device->Resources = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Desc; + + Status = gBS->InstallMultipleProtocolInterfaces (Handle, + &gEdkiiNonDiscoverableDeviceProtocolGuid, Device, + NULL); + if (EFI_ERROR (Status)) { + goto FreeDevice; + } + return EFI_SUCCESS; + +FreeDevice: + FreePool (Device); + + return Status; +} + +VOID +PopulateI2cInformation ( + IN VOID + ) +{ + UINT32 Index; + + for (Index = 0; Index < ARRAY_SIZE (mI2cDesc); Index++) { + mI2cDesc[Index].StartDesc.Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; + mI2cDesc[Index].StartDesc.Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + mI2cDesc[Index].StartDesc.ResType = ACPI_ADDRESS_SPACE_TYPE_MEM; + mI2cDesc[Index].StartDesc.GenFlag = 0; + mI2cDesc[Index].StartDesc.SpecificFlag = 0; + mI2cDesc[Index].StartDesc.AddrSpaceGranularity = 32; + mI2cDesc[Index].StartDesc.AddrRangeMin = BCM2836_I2C1_BASE_ADDRESS; + mI2cDesc[Index].StartDesc.AddrRangeMax = mI2cDesc[Index].StartDesc.AddrRangeMin + BCM2836_I2C1_LENGTH; + mI2cDesc[Index].StartDesc.AddrTranslationOffset = 0; + mI2cDesc[Index].StartDesc.AddrLen = BCM2836_I2C1_LENGTH; + + mI2cDesc[Index].EndDesc = ACPI_END_TAG_DESCRIPTOR; + } +} + +EFI_STATUS +EFIAPI +BcmI2CPlatformDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + Handle = NULL; + + PopulateI2cInformation (); + + if (PcdGet32 (PcdHwRtc)) + { + DEBUG ((DEBUG_ERROR, "RTC I2C enable\n")); + // If we don't register this, the second rtc won't get enabled + // leaving the emulator in place. + Status = RegisterDevice (&gBcmNonDiscoverableI2cMasterGuid, + &mI2cDesc[0], &Handle); + ASSERT_EFI_ERROR (Status); + + // + // Install the DS1307 I2C Master protocol on this handle so the RTC driver + // can identify it as the I2C master it can invoke directly. + // + Status = gBS->InstallProtocolInterface (&Handle, + &gDs1307RealTimeClockLibI2cMasterProtocolGuid, + EFI_NATIVE_INTERFACE, NULL); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_ERROR, "RTC I2C disabled\n")); + } + + return EFI_SUCCESS; +} diff --git a/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf new file mode 100644 index 0000000000..aa5c1b51b2 --- /dev/null +++ b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf @@ -0,0 +1,54 @@ +## @file +# +# Component description file for Bcm/Rpi I2C driver. +# +# Copyright 2018-2020 NXP +# Sourced and reworked from edk2/NXP I2C stack +# Copyright 2022 Arm, Jeremy Linton +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001A + BASE_NAME = BcmI2CPlatformDxe + FILE_GUID = 1a23fe23-39bc-4bee-859d-ecb5bbb60484 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = BcmI2CPlatformDxeEntryPoint + +[Sources] + BcmI2CPlatform.c + +[Packages] + ArmPkg/ArmPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.dec + Silicon/Broadcom/Bcm283x/Bcm283x.dec + Platform/RaspberryPi/RaspberryPi.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Guids] + gBcmNonDiscoverableI2cMasterGuid + +[Protocols] + gEdkiiNonDiscoverableDeviceProtocolGuid ## PRODUCES + gDs1307RealTimeClockLibI2cMasterProtocolGuid ## PRODUCES + +[Pcd] + gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress + gRaspberryPiTokenSpaceGuid.PcdHwRtc + +[Depex] + gRaspberryPiConfigAppliedProtocolGuid -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113560): https://edk2.groups.io/g/devel/message/113560 Mute This Topic: https://groups.io/mt/103653099/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-