The Ds1307 is ideally a runtime RTC but its use of the I2C
protocol might make it better if it updated the I2C_MASTER_PROTOCOL
callbacks it uses, although... hmmm maybe think about this
a bit more.

Signed-off-by: Jeremy Linton <jeremy.lin...@arm.com>
---
 .../Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.c | 36 +++++++++++++++++--
 .../Library/Ds1307RtcLib/Ds1307RtcLib.inf     |  7 +++-
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.c 
b/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.c
index 444e011248..ede890448f 100644
--- a/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.c
+++ b/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.c
@@ -18,14 +18,40 @@
 #include <Library/RealTimeClockLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiLib.h>
+#include <Library/UefiRuntimeLib.h>
 #include <Protocol/I2cMaster.h>
 
 #include "Ds1307Rtc.h"
 
 STATIC VOID                       *mDriverEventRegistration;
 STATIC EFI_HANDLE                 mI2cMasterHandle;
+STATIC EFI_EVENT                  mRtcVirtualAddrChangeEvent;
 STATIC EFI_I2C_MASTER_PROTOCOL    *mI2cMaster;
 
+
+/**
+  Fixup internal data so that EFI can be call in virtual mode.
+  Call the passed in Child Notify event and convert any pointers in
+  lib to virtual mode.
+
+  @param[in]    Event   The Event that is being processed
+  @param[in]    Context Event Context
+**/
+VOID
+EFIAPI
+LibRtcVirtualNotifyEvent (
+  IN EFI_EVENT        Event,
+  IN VOID             *Context
+  )
+{
+  EfiConvertPointer (0x0, (VOID **)&mI2cMaster->SetBusFrequency);
+  EfiConvertPointer (0x0, (VOID **)&mI2cMaster->Reset);
+  EfiConvertPointer (0x0, (VOID **)&mI2cMaster->StartRequest);
+  EfiConvertPointer (0x0, (VOID **)&mI2cMaster->I2cControllerCapabilities);
+  EfiConvertPointer (0x0, (VOID **)&mI2cMaster);
+}
+
+
 /**
   Read RTC register.
   Data Read-Slave Transmitter Mode
@@ -54,7 +80,7 @@ RtcRead (
 
   Req.OperationCount = 2;
 
-  Req.SetAddressOp.Flags = 0;
+  Req.SetAddressOp.Flags = 0; //I2C_FLAG_WRITE
   Req.SetAddressOp.LengthInBytes = sizeof (RtcRegAddr);
   Req.SetAddressOp.Buffer = &RtcRegAddr;
 
@@ -98,7 +124,7 @@ RtcWrite (
   Buffer[0] = RtcRegAddr;
   Buffer[1] = Val;
 
-  Req.SetAddressOp.Flags = 0;
+  Req.SetAddressOp.Flags = 0; //I2C_FLAG_WRITE
   Req.SetAddressOp.LengthInBytes = sizeof (Buffer);
   Req.SetAddressOp.Buffer = Buffer;
 
@@ -375,5 +401,11 @@ LibRtcInitialize (
     NULL,
     &mDriverEventRegistration);
 
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+                  LibRtcVirtualNotifyEvent, NULL,
+                  &gEfiEventVirtualAddressChangeGuid,
+                  &mRtcVirtualAddrChangeEvent);
+  ASSERT_EFI_ERROR (Status);
+
   return EFI_SUCCESS;
 }
diff --git a/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf 
b/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf
index b92f658bfc..9d8cf16d28 100644
--- a/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf
+++ b/Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf
@@ -28,6 +28,9 @@
   UefiBootServicesTableLib
   UefiLib
 
+[Guids]
+  gEfiEventVirtualAddressChangeGuid
+
 [Protocols]
   gEfiI2cMasterProtocolGuid                          ## CONSUMES
   gDs1307RealTimeClockLibI2cMasterProtocolGuid       ## CONSUMES
@@ -36,5 +39,7 @@
   gDs1307RtcLibTokenSpaceGuid.PcdI2cSlaveAddress
   gDs1307RtcLibTokenSpaceGuid.PcdI2cBusFrequency
 
+# 2.15 EDK II INF, .. the generic (i.e depex).. are not permitted
+# yet it ANDs this into the parent's depex
 [Depex]
-  gDs1307RealTimeClockLibI2cMasterProtocolGuid
+  gDs1307RealTimeClockLibI2cMasterProtocolGuid AND gEfiI2cMasterProtocolGuid
-- 
2.43.0



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


Reply via email to