From: "Jeremy Linton" <jeremy.linton@arm.com>
To: devel@edk2.groups.io
Cc: ardb+tianocore@kernel.org, quic_llindhol@quicinc.com,
Jeremy Linton <jeremy.linton@arm.com>
Subject: [edk2-devel] [RFC 4/6] Silicon/Maxim: Fix runtime issues
Date: Wed, 10 Jan 2024 18:04:24 -0600 [thread overview]
Message-ID: <20240111000426.2735007-5-jeremy.linton@arm.com> (raw)
In-Reply-To: <20240111000426.2735007-1-jeremy.linton@arm.com>
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.linton@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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-01-11 0:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 0:04 [edk2-devel] [RFC 0/6] RasberryPi: RTC HAT support Jeremy Linton
2024-01-11 0:04 ` [edk2-devel] [RFC 1/6] Silicon/Bcm283x: Document the I2C registers Jeremy Linton
2024-01-11 0:04 ` [edk2-devel] [RFC 2/6] Silicon/Bcm283x: Add core I2C drivers Jeremy Linton
2024-01-11 0:04 ` [edk2-devel] [RFC 3/6] Platform/RasberryPi: Create I2C driver bound to RTC Jeremy Linton
2024-01-11 0:04 ` Jeremy Linton [this message]
2024-01-11 0:04 ` [edk2-devel] [RFC 5/6] Platform/RasberryPi: Add I2C1 to uefi runtime memory map Jeremy Linton
2024-01-11 0:04 ` [edk2-devel] [RFC 6/6] Platform/RaspberryPi: Add menu and build options for HW RTC Jeremy Linton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240111000426.2735007-5-jeremy.linton@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox