Skip to content

Commit

Permalink
Silicon/Rockchip: Add 8563-based RTC support
Browse files Browse the repository at this point in the history
Uses Pcf8563RealTimeClockLib, which is compatible with the HYM8563 chip used on many Rockchip platforms.
  • Loading branch information
mariobalanica committed Aug 2, 2023
1 parent a5fdc7c commit 1ca239f
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** @file
*
* Pcf8563RealTimeClockLib initializer for Rockchip platforms.
*
* Copyright (c) 2023, Mario Bălănică <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/

#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Protocol/RockchipI2cMasterProtocol.h>

STATIC
VOID
EFIAPI
RockchipI2cMasterRegistrationEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_HANDLE *Handles;
UINTN NumHandles;
ROCKCHIP_I2C_MASTER_PROTOCOL *RockchipI2cMaster;
UINTN Index;

Handles = NULL;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gRockchipI2cMasterProtocolGuid,
NULL,
&NumHandles,
&Handles
);
if (EFI_ERROR(Status)) {
if (Status != EFI_NOT_FOUND) {
DEBUG((DEBUG_WARN, "%a: Failed to locate gRockchipI2cMasterProtocolGuid. Status=%r\n",
__FUNCTION__, Status));
}
return;
}

for (Index = 0; Index < NumHandles; Index++) {
Status = gBS->HandleProtocol (
Handles[Index],
&gRockchipI2cMasterProtocolGuid,
(VOID **)&RockchipI2cMaster
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to get RockchipI2cMaster: %r\n", __FUNCTION__, Status));
continue;
}

if (RockchipI2cMaster->Bus != FixedPcdGet8 (PcdRtc8563Bus)) {
continue;
}

Status = gBS->InstallMultipleProtocolInterfaces (
&Handles[Index],
&gPcf8563RealTimeClockLibI2cMasterProtocolGuid,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to install gPcf8563RealTimeClockLibI2cMasterProtocolGuid: %r\n",
__FUNCTION__, Status));
continue;
}

gBS->CloseEvent (Event);
}

FreePool (Handles);
}

EFI_STATUS
EFIAPI
Rtc8563PlatformDxeInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
VOID *Registration = NULL;

EfiCreateProtocolNotifyEvent (
&gRockchipI2cMasterProtocolGuid,
TPL_CALLBACK,
RockchipI2cMasterRegistrationEvent,
NULL,
&Registration
);

return EFI_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#/** @file
#
# Pcf8563RealTimeClockLib initializer for Rockchip platforms.
#
# Copyright (c) 2023, Mario Bălănică <[email protected]>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#**/

[Defines]
INF_VERSION = 0x00010019
BASE_NAME = RtcPlatformDxe
FILE_GUID = b4d6e6b1-b2a0-4c79-8bf1-3af8c485ec3d
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = Rtc8563PlatformDxeInitialize

[Sources.common]
Rtc8563PlatformDxe.c

[Packages]
MdePkg/MdePkg.dec
Silicon/Rockchip/RockchipPkg.dec
Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec

[LibraryClasses]
UefiDriverEntryPoint
UefiLib
UefiBootServicesTableLib
MemoryAllocationLib
DebugLib

[Protocols]
gRockchipI2cMasterProtocolGuid ## CONSUMES
gPcf8563RealTimeClockLibI2cMasterProtocolGuid ## PRODUCES

[Pcd]
gRockchipTokenSpaceGuid.PcdRtc8563Bus

[Depex]
TRUE
3 changes: 3 additions & 0 deletions edk2-rockchip/Silicon/Rockchip/FvMainModules.fdf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
INF Silicon/Rockchip/Drivers/I2c/I2cDxe/I2cDxe.inf
!if $(RK_860X_REGULATOR_ENABLE) == TRUE
INF Silicon/Rockchip/Drivers/I2c/Rk860xRegulatorDxe/Rk860xRegulatorDxe.inf
!endif
!if $(RK_RTC8563_ENABLE) == TRUE
INF Silicon/Rockchip/Drivers/Rtc8563PlatformDxe/Rtc8563PlatformDxe.inf
!endif
# INF Silicon/Rockchip/Drivers/I2c/I2cDemoDxe/I2cDemoDxe.inf

Expand Down
9 changes: 7 additions & 2 deletions edk2-rockchip/Silicon/Rockchip/Rockchip.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@
ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
#RealTimeClockLib|Silicon/Rockchip/Library/Rk808RealTimeClockLib/Rk808RealTimeClockLib.inf
#RealTimeClockLib|Silicon/Rockchip/Library/VirtualRealTimeClockLib/RealTimeClockLib.inf

# UART libraries
# SerialPortLib|Silicon/Rockchip/Library/SerialPortLib/SerialPortLib.inf # Modified
Expand Down Expand Up @@ -448,7 +446,11 @@ FspiLib|Silicon/Rockchip/Library/FspiLib/FspiLib.inf
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf {
<LibraryClasses>
!if $(RK_RTC8563_ENABLE) == TRUE
RealTimeClockLib|Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf
!else
RealTimeClockLib|EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf
!endif
}
EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf {
Expand Down Expand Up @@ -518,6 +520,9 @@ FspiLib|Silicon/Rockchip/Library/FspiLib/FspiLib.inf
Silicon/Rockchip/Drivers/I2c/I2cDxe/I2cDxe.inf
!if $(RK_860X_REGULATOR_ENABLE) == TRUE
Silicon/Rockchip/Drivers/I2c/Rk860xRegulatorDxe/Rk860xRegulatorDxe.inf
!endif
!if $(RK_RTC8563_ENABLE) == TRUE
Silicon/Rockchip/Drivers/Rtc8563PlatformDxe/Rtc8563PlatformDxe.inf
!endif
# Silicon/Rockchip/Drivers/I2c/I2cDemoDxe/I2cDemoDxe.inf

Expand Down
1 change: 1 addition & 0 deletions edk2-rockchip/Silicon/Rockchip/RockchipPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
gRockchipTokenSpaceGuid.PcdRk860xRegulatorTags|{ 0x0 }|VOID*|0x0200000B
gRockchipTokenSpaceGuid.PcdRk860xRegulatorMinVoltages|{ 0x0 }|VOID*|0x0200000C
gRockchipTokenSpaceGuid.PcdRk860xRegulatorMaxVoltages|{ 0x0 }|VOID*|0x0200000D
gRockchipTokenSpaceGuid.PcdRtc8563Bus|0|UINT8|0x0200000E

gRockchipTokenSpaceGuid.PcdRkSdmmcBaseAddress|0x0|UINT32|0x40000030

Expand Down

0 comments on commit 1ca239f

Please sign in to comment.