From nobody Fri Dec 19 17:42:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113563+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113563+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1704931471; cv=none; d=zohomail.com; s=zohoarc; b=Z6lkTNovOqO9RoFZL8m0xnYrpFwGoaUS2fXxKi7DB5rdg1OIBPA9egOX0k/XzmgWtmGpp2Xzr7UFRRExsRkoJiE568ad5rNnHawLKjswwPxfLccMgBujAY98ATrrn/RNujZsDpKNcYEYV+7oBFta5wdonuSNisSO+yGH2uHMGqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704931471; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=B8x1pW+K038zRFYGAu2Vi/U0pDsO4LIHt2La1CFGaoE=; b=L/kGynLszX2djZBTL8jeSa0BfA0lGMeMpoNaGavUOyIi6W2bq3xOfk9Krs2tbmj0S5q/tJfkBLfpDsCMSDJbl1qj+2w3O2t+Oj2Ypo9noz/EHzJ2xGl/TX+1u5fYgXAhrNNQmLH30aVvm2oSD0Ip+colUGW5BJkSbCIQ8wTshlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113563+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1704931471977984.999281121938; Wed, 10 Jan 2024 16:04:31 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=fDqfESuvC+LAfZcut9jfY+qHSQRCkEzzI/yC/38zr6g=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704931471; v=1; b=rCqcwCWcOU3yg0notRAmy8VjrBClnL01I5yrvdFlp8Te1UKHUPtZTXhf3zcPX1g2X54qzj/r a1cDJnw/u2/W2tvPi21cQzi6TITW2j7LEMGyJ9S401uU5cuufGDCakrk2JtZEqV7Ewnvsweziti ESip+VDLa5GhIhKfDJTQOGVI= X-Received: by 127.0.0.2 with SMTP id nHBbYY1788612xVVWnYq1NuQ; Wed, 10 Jan 2024 16:04:31 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9467.1704931469122767513 for ; Wed, 10 Jan 2024 16:04:30 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA29F1576; Wed, 10 Jan 2024 16:05:15 -0800 (PST) X-Received: from u200865.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 943983F5A1; Wed, 10 Jan 2024 16:04:29 -0800 (PST) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, quic_llindhol@quicinc.com, Jeremy Linton Subject: [edk2-devel] [RFC 6/6] Platform/RaspberryPi: Add menu and build options for HW RTC Date: Wed, 10 Jan 2024 18:04:26 -0600 Message-ID: <20240111000426.2735007-7-jeremy.linton@arm.com> In-Reply-To: <20240111000426.2735007-1-jeremy.linton@arm.com> References: <20240111000426.2735007-1-jeremy.linton@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jeremy.linton@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: sWXKCyUDaVntPYrmqvQxvFHhx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1704931473389100022 Content-Type: text/plain; charset="utf-8" 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/B= 00ZOXWHK4 Doesn't utilize the HAT protocol so it cannot be detected. Signed-off-by: Jeremy Linton --- .../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); } =20 + Size =3D sizeof (UINT32); + Status =3D gRT->GetVariable (L"HwRtc", + &gConfigDxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + Status =3D PcdSet32S (PcdHwRtc, PcdGet32 (PcdHwRtc)); + ASSERT_EFI_ERROR (Status); + } + + } else { /* * Disable PCIe and XHCI @@ -716,6 +726,18 @@ ApplyVariables ( GpioPinFuncSet (33, GPIO_FSEL_ALT3); } =20 + // 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/=3D50000; //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 usua= lly at 500Mhz? + } } =20 =20 diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/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 =20 [Depex] gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/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" =20 +#string STR_ADVANCED_ENABLEHWRTC_PROMPT #language en-US "Enable Hardware = RTC" +#string STR_ADVANCED_ENABLEHWRTC_HELP #language en-US "A DS1307 hardwar= e 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 Asse= t Tag" =20 diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/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 =3D EnableGpio, guid =3D CONFIGDXE_FORM_SET_GUID; =20 + efivarstore ADVANCED_ENABLEHWRTC_VARSTORE_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, + name =3D HwRtc, + guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA, attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, name =3D SystemTableMode, @@ -259,6 +264,17 @@ formset option text =3D STRING_TOKEN(STR_ADVANCED_ENABLEGPIO_ENABLE), = value =3D 1, flags =3D 0; endoneof; endif; + + grayoutif ideqval SystemTableMode.Mode =3D=3D SYSTEM_TABLE_MODE_DT; + oneof varid =3D HwRtc.Value, + prompt =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_PROMPT= ), + help =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_HELP), + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D, + option text =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_DISABL= E), value =3D 0, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_ENABLE= ), value =3D 1, flags =3D 0; + endoneof; + endif; + #endif string varid =3D AssetTag.AssetTag, prompt =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT), diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/Raspberry= Pi/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; =20 +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"|gConfigDxeFormSet= Guid|0x0|1 =20 + # 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" =20 + # + # 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"|gConfigDxeFormSet= Guid|0x0|0 =20 + # Utilize RTC on I2C1 + # + # 0 - No + # 1 - Yes + # + gRaspberryPiTokenSpaceGuid.PcdHwRtc|L"HwRtc"|gConfigDxeFormSetGuid|0x0|0 + + # # Common UEFI ones. # @@ -659,6 +673,15 @@ RealTimeClockLib|EmbeddedPkg/Library/VirtualRealTimeClockLib/Virtual= RealTimeClockLib.inf } + # Oh, confusing, we now have two runtime variable support drivers... + # Do the virtual one by default, but if the hardware RTC is configured t= hen + # SOM the BcmI2CPlatform driver, which activates this one. + EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf { + + FILE_GUID =3D 9d539f19-5fb6-4088-a81d-aaeb90446751 + + RealTimeClockLib|Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf + } EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf =20 MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf @@ -782,6 +805,13 @@ MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf =20 # + # 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 =3D TRUE # INF MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf =20 + # + # I2C/RTC + # + INF Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf + INF Silicon/Broadcom/Drivers/I2cDxe/I2cDxe.inf + INF RuleOverride =3D RTC_RUNTIME EmbeddedPkg/RealTimeClockRuntimeDxe/Rea= lTimeClockRuntimeDxe.inf +# FILE DRIVER =3D 9d539f19-5fb6-4088-a81d-aaeb90446751 { +# SECTION PE32 =3D EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRu= ntimeDxe.inf +# SECTION PE32 =3D $(INF_OUTPUT)Build/RPi4/DEBUG_GCC5/AARCH64/RealTim= eClock_9d539f19-5fb6-4088-a81d-aaeb90446751.efi +# } + # # SCSI Bus and Disk Driver # @@ -415,6 +426,14 @@ READ_LOCK_STATUS =3D TRUE UI STRING=3D"$(MODULE_NAME)" Optional } =20 +[Rule.Common.DXE_RUNTIME_DRIVER.RTC_RUNTIME] + FILE DRIVER =3D 9d539f19-5fb6-4088-a81d-aaeb90446751 { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/../../9d539= f19-5fb6-4088-a81d-aaeb90446751/OUTPUT/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/../../9d539f19-5fb6-= 4088-a81d-aaeb90446751/OUTPUT/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + + [Rule.Common.UEFI_APPLICATION] FILE APPLICATION =3D $(NAMED_GUID) { UI STRING =3D"$(MODULE_NAME)" Optional diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index cc56b436cf..9cf33c366b 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -26,6 +26,7 @@ gRaspberryPiTokenSpaceGuid =3D {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3,= 0x63, 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} gRaspberryPiEventResetGuid =3D {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3,= 0x63, 0xB4, 0xB4, 0xE4, 0xD4, 0xB4}} gConfigDxeFormSetGuid =3D {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63= , 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} + gBcmNonDiscoverableI2cMasterGuid =3D { 0x16066c21, 0x0ca6, 0x4f44, {0x82= , 0xd9, 0xbe, 0x06, 0x96, 0x12, 0x0e, 0xfb}} =20 [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 --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-