Now that the i2c drivers, config setup, and DS1307 driver are
in place, lets add the drivers to the build. We also add a menu
item to enable/disable it since the device I have:

https://www.amazon.com/Makerfire%C2%AE-Raspberry-Module-DS1307-Battery/dp/B00ZOXWHK4

Doesn't utilize the HAT protocol so it cannot be detected.

Signed-off-by: Jeremy Linton <jeremy.lin...@arm.com>
---
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 22 ++++++++++++++
 .../Drivers/ConfigDxe/ConfigDxe.inf           |  1 +
 .../Drivers/ConfigDxe/ConfigDxeHii.uni        |  6 ++++
 .../Drivers/ConfigDxe/ConfigDxeHii.vfr        | 16 ++++++++++
 Platform/RaspberryPi/Include/ConfigVars.h     |  4 +++
 Platform/RaspberryPi/RPi3/RPi3.dsc            |  7 +++++
 Platform/RaspberryPi/RPi4/RPi4.dsc            | 30 +++++++++++++++++++
 Platform/RaspberryPi/RPi4/RPi4.fdf            | 19 ++++++++++++
 Platform/RaspberryPi/RaspberryPi.dec          |  2 ++
 9 files changed, 107 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c 
b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index fec8f63ea8..0397941a06 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -319,6 +319,16 @@ SetupVariables (
       ASSERT_EFI_ERROR (Status);
     }
 
+    Size = sizeof (UINT32);
+    Status = gRT->GetVariable (L"HwRtc",
+                               &gConfigDxeFormSetGuid,
+                               NULL, &Size, &Var32);
+    if (EFI_ERROR (Status)) {
+      Status = PcdSet32S (PcdHwRtc, PcdGet32 (PcdHwRtc));
+      ASSERT_EFI_ERROR (Status);
+    }
+
+
   } else {
     /*
      * Disable PCIe and XHCI
@@ -716,6 +726,18 @@ ApplyVariables (
     GpioPinFuncSet (33, GPIO_FSEL_ALT3);
   }
 
+  // Assure I2C1 is selected on header
+  if (PcdGet32 (PcdHwRtc)) {
+    UINT32 ClockRate;
+    DEBUG ((DEBUG_INFO, "Enable SDA1\n"));
+    GpioPinFuncSet (2, GPIO_FSEL_ALT0);
+    GpioPinFuncSet (3, GPIO_FSEL_ALT0);
+
+    mFwProtocol->GetClockRate (RPI_MBOX_CLOCK_RATE_CORE, &ClockRate);
+    ClockRate/=50000; //50Khz slow it down a bit initially
+
+    MmioWrite32 (BCM2836_I2C1_OFFSET + BCM2836_SOC_REGISTERS + 
BCM2835_I2C_DIV, ClockRate ); //was 5dc which assumes a 150Mhz clock, when we 
are usually at 500Mhz?
+  }
 }
 
 
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf 
b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
index e422e5ba5c..4c213174ce 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
@@ -98,6 +98,7 @@
   gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate
   gRaspberryPiTokenSpaceGuid.PcdXhciReload
   gRaspberryPiTokenSpaceGuid.PcdEnableGpio
+  gRaspberryPiTokenSpaceGuid.PcdHwRtc
 
 [Depex]
   gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni 
b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
index fb06d46a61..8da143d519 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
@@ -72,6 +72,12 @@
 #string STR_ADVANCED_ENABLEGPIO_DISABLE #language en-US "Disabled"
 #string STR_ADVANCED_ENABLEGPIO_ENABLE  #language en-US "Enable"
 
+#string STR_ADVANCED_ENABLEHWRTC_PROMPT  #language en-US "Enable Hardware RTC"
+#string STR_ADVANCED_ENABLEHWRTC_HELP    #language en-US "A DS1307 hardware 
real time clock is attached on I2C1."
+#string STR_ADVANCED_ENABLEHWRTC_DISABLE #language en-US "Disabled"
+#string STR_ADVANCED_ENABLEHWRTC_ENABLE  #language en-US "Enable"
+
+
 #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag"
 #string STR_ADVANCED_ASSET_TAG_HELP   #language en-US "Set the system Asset 
Tag"
 
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr 
b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
index 04eb0a15a2..b7146b7e8c 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
@@ -71,6 +71,11 @@ formset
       name  = EnableGpio,
       guid  = CONFIGDXE_FORM_SET_GUID;
 
+    efivarstore ADVANCED_ENABLEHWRTC_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = HwRtc,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
     efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
       attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
       name  = SystemTableMode,
@@ -259,6 +264,17 @@ formset
             option text = STRING_TOKEN(STR_ADVANCED_ENABLEGPIO_ENABLE), value 
= 1, flags = 0;
           endoneof;
         endif;
+
+        grayoutif ideqval SystemTableMode.Mode == SYSTEM_TABLE_MODE_DT;
+          oneof varid = HwRtc.Value,
+              prompt      = STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_PROMPT),
+              help        = STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_HELP),
+              flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+              option text = STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_DISABLE), 
value = 0, flags = DEFAULT;
+              option text = STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_ENABLE), 
value = 1, flags = 0;
+          endoneof;
+        endif;
+
 #endif
         string varid = AssetTag.AssetTag,
             prompt  = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
diff --git a/Platform/RaspberryPi/Include/ConfigVars.h 
b/Platform/RaspberryPi/Include/ConfigVars.h
index 43a39891d4..69dda96051 100644
--- a/Platform/RaspberryPi/Include/ConfigVars.h
+++ b/Platform/RaspberryPi/Include/ConfigVars.h
@@ -84,6 +84,10 @@ typedef struct {
   UINT32 Value;
 } ADVANCED_ENABLEGPIO_VARSTORE_DATA;
 
+typedef struct {
+  UINT32 Value;
+} ADVANCED_ENABLEHWRTC_VARSTORE_DATA;
+
 typedef struct {
 #define SYSTEM_TABLE_MODE_ACPI 0
 #define SYSTEM_TABLE_MODE_BOTH 1
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc 
b/Platform/RaspberryPi/RPi3/RPi3.dsc
index 55da7d5870..10d57c5e03 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -541,6 +541,13 @@
   #
   
gRaspberryPiTokenSpaceGuid.PcdEnableGpio|L"EnableGpio"|gConfigDxeFormSetGuid|0x0|1
 
+  # Utilize RTC on I2C1
+  #
+  # 0  - No
+  # 1  - Yes
+  #
+  gRaspberryPiTokenSpaceGuid.PcdHwRtc|L"HwRtc"|gConfigDxeFormSetGuid|0x0|0
+
   #
   # Common UEFI ones.
   #
diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc 
b/Platform/RaspberryPi/RPi4/RPi4.dsc
index a49b3433ac..170e45ae7e 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -368,6 +368,12 @@
   # Default platform supported RFC 4646 languages: (American) English
   gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLangCodes|"en-US"
 
+  #
+  # RTC Pcds
+  #
+  gDs1307RtcLibTokenSpaceGuid.PcdI2cSlaveAddress|0x68
+  gDs1307RtcLibTokenSpaceGuid.PcdI2cBusFrequency|100000
+
 [LibraryClasses.common]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
   ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
@@ -562,6 +568,14 @@
   #
   
gRaspberryPiTokenSpaceGuid.PcdEnableGpio|L"EnableGpio"|gConfigDxeFormSetGuid|0x0|0
 
+  # Utilize RTC on I2C1
+  #
+  # 0  - No
+  # 1  - Yes
+  #
+  gRaspberryPiTokenSpaceGuid.PcdHwRtc|L"HwRtc"|gConfigDxeFormSetGuid|0x0|0
+
+
   #
   # Common UEFI ones.
   #
@@ -659,6 +673,15 @@
     <LibraryClasses>
       
RealTimeClockLib|EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf
   }
+  # Oh, confusing, we now have two runtime variable support drivers...
+  # Do the virtual one by default, but if the hardware RTC is configured then
+  # SOM the BcmI2CPlatform driver, which activates this one.
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf {
+    <Defines>
+       FILE_GUID = 9d539f19-5fb6-4088-a81d-aaeb90446751
+    <LibraryClasses>
+     RealTimeClockLib|Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf
+  }
   EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
 
   MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
@@ -782,6 +805,13 @@
   MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf
 
   #
+  # RTC support
+  #
+  Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf
+  Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf
+  Silicon/Broadcom/Drivers/I2cDxe/I2cDxe.inf
+
+
   # UEFI application (Shell Embedded Boot Loader)
   #
   ShellPkg/Application/Shell/Shell.inf {
diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf 
b/Platform/RaspberryPi/RPi4/RPi4.fdf
index 8169277615..989d99a49f 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.fdf
+++ b/Platform/RaspberryPi/RPi4/RPi4.fdf
@@ -288,6 +288,17 @@ READ_LOCK_STATUS   = TRUE
   #
   INF MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf
 
+  #
+  # I2C/RTC
+  #
+  INF Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf
+  INF Silicon/Broadcom/Drivers/I2cDxe/I2cDxe.inf
+  INF RuleOverride = RTC_RUNTIME 
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+#  FILE DRIVER = 9d539f19-5fb6-4088-a81d-aaeb90446751 {
+#    SECTION  PE32 = 
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+#    SECTION  PE32 =  
$(INF_OUTPUT)Build/RPi4/DEBUG_GCC5/AARCH64/RealTimeClock_9d539f19-5fb6-4088-a81d-aaeb90446751.efi
+#  }
+
   #
   # SCSI Bus and Disk Driver
   #
@@ -415,6 +426,14 @@ READ_LOCK_STATUS   = TRUE
     UI           STRING="$(MODULE_NAME)" Optional
   }
 
+[Rule.Common.DXE_RUNTIME_DRIVER.RTC_RUNTIME]
+  FILE DRIVER = 9d539f19-5fb6-4088-a81d-aaeb90446751 {
+    DXE_DEPEX    DXE_DEPEX              Optional 
$(INF_OUTPUT)/../../9d539f19-5fb6-4088-a81d-aaeb90446751/OUTPUT/$(MODULE_NAME).depex
+    PE32         PE32                   
$(INF_OUTPUT)/../../9d539f19-5fb6-4088-a81d-aaeb90446751/OUTPUT/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+
 [Rule.Common.UEFI_APPLICATION]
   FILE APPLICATION = $(NAMED_GUID) {
     UI     STRING ="$(MODULE_NAME)"     Optional
diff --git a/Platform/RaspberryPi/RaspberryPi.dec 
b/Platform/RaspberryPi/RaspberryPi.dec
index cc56b436cf..9cf33c366b 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -26,6 +26,7 @@
   gRaspberryPiTokenSpaceGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 0x63, 
0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
   gRaspberryPiEventResetGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 0x63, 
0xB4, 0xB4, 0xE4, 0xD4, 0xB4}}
   gConfigDxeFormSetGuid = {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63, 
0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
+  gBcmNonDiscoverableI2cMasterGuid = { 0x16066c21, 0x0ca6, 0x4f44, {0x82, 
0xd9, 0xbe, 0x06, 0x96, 0x12, 0x0e, 0xfb}}
 
 [PcdsFixedAtBuild.common]
   #
@@ -75,3 +76,4 @@
   gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate|0|UINT32|0x00000023
   gRaspberryPiTokenSpaceGuid.PcdXhciReload|0|UINT32|0x00000024
   gRaspberryPiTokenSpaceGuid.PcdEnableGpio|0|UINT32|0x00000025
+  gRaspberryPiTokenSpaceGuid.PcdHwRtc|0|UINT32|0x00000026
-- 
2.43.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113563): https://edk2.groups.io/g/devel/message/113563
Mute This Topic: https://groups.io/mt/103653102/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to