From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id E9E05780091 for ; Thu, 11 Jan 2024 00:04:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=QgdQWG2Pu6njcJreV0DtLfgsrIT5Gpffin1kAPNi0Io=; 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=1704931474; v=1; b=v/TkjGAknp1Lu4yjN0vKvMDEEqCw8w/6p0AE1tze4pqQU0UnW8sQkDf9ikzNyEvguBBiIj16 scWZXG62vcSYJSx9zkoM/RNDz1bUs3i+3J1MFF7DE4z6xwn7wFfNqTHZCXqOYLMFtOhFKaGVUgt 30Dr+FSx9F+NBW5bcF8096cQ= X-Received: by 127.0.0.2 with SMTP id m2opYY7687511xBCyyTlCxTV; Wed, 10 Jan 2024 16:04:34 -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: kNBBxiGv4nkmgQUTkYtuh6O3x7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="v/TkjGAk"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 --- .../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/Platfor= m/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_I= 2C_DIV, ClockRate ); //was 5dc which assumes a 150Mhz clock, when we are = usually at 500Mhz? + } } =20 =20 diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platf= orm/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/Pl= atform/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 Hardwar= e RTC" +#string STR_ADVANCED_ENABLEHWRTC_HELP #language en-US "A DS1307 hardw= are 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 As= set Tag" =20 diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Pl= atform/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_RUNTI= ME_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_RUNTI= ME_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_PROM= PT), + help =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_HELP= ), + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUI= RED, + option text =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_DISA= BLE), value =3D 0, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_ADVANCED_ENABLEHWRTC_ENAB= LE), 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/Raspber= ryPi/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/RP= i3/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"|gConfigDxeFormS= etGuid|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/RP= i4/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-U= S" =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"|gConfigDxeFormS= etGuid|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/Virtu= alRealTimeClockLib.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 { + + FILE_GUID =3D 9d539f19-5fb6-4088-a81d-aaeb90446751 + + RealTimeClockLib|Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.in= f + } 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/RP= i4/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/R= ealTimeClockRuntimeDxe.inf +# FILE DRIVER =3D 9d539f19-5fb6-4088-a81d-aaeb90446751 { +# SECTION PE32 =3D EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock= RuntimeDxe.inf +# SECTION PE32 =3D $(INF_OUTPUT)Build/RPi4/DEBUG_GCC5/AARCH64/RealT= imeClock_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)/../../9d5= 39f19-5fb6-4088-a81d-aaeb90446751/OUTPUT/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/../../9d539f19-5fb= 6-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/= RaspberryPi.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, 0xD= 3, 0x63, 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} gRaspberryPiEventResetGuid =3D {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD= 3, 0x63, 0xB4, 0xB4, 0xE4, 0xD4, 0xB4}} gConfigDxeFormSetGuid =3D {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x= 63, 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} + gBcmNonDiscoverableI2cMasterGuid =3D { 0x16066c21, 0x0ca6, 0x4f44, {0x= 82, 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 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-