Bläddra i källkod

Platform/RaspberryPi: Add 'clock-frequency' property for miniuart

Describe the miniuart clock frequency in a _DSD property, so that it can
be read from the Linux driver [1]

The miniuart clock frequency is the core clock frequency on the
Raspberry Pi. It can be modified by the user using the 'core_freq'
property in the config.txt file. So, we fetch it from the underlying
Raspberry Pi firmware.

[1] https://lore.kernel.org/all/20220207232129.402882-1-athierry@redhat.com/

Signed-off-by: Adrien Thierry <athierry@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Adrien Thierry 2 år sedan
förälder
incheckning
b0f3f90372

+ 14 - 0
Platform/RaspberryPi/AcpiTables/Uart.asl

@@ -77,6 +77,20 @@ Device (URTM)
     MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_MINI_UART_OFFSET)
     Return (^RBUF)
   }
+
+  //
+  // Mini Uart Clock Rate will be dynamically updated during boot
+  // 0x4D 0x55 0x43 0x52 0xC 0x1000000 (Value must be > 16777215)
+  //
+  Name (MUCR, 0x1000000)
+
+  Name (_DSD, Package ()
+  {
+    ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package ()
+    {
+      Package (2) { "clock-frequency", MUCR },
+    }
+  })
 }
 
 //

+ 9 - 0
Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c

@@ -44,6 +44,7 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
 STATIC UINT32 mModelFamily = 0;
 STATIC UINT32 mModelInstalledMB = 0;
 STATIC UINT32 mModelRevision = 0;
+STATIC UINT32 mCoreClockRate = 0;
 
 STATIC EFI_MAC_ADDRESS  mMacAddress;
 
@@ -798,6 +799,7 @@ STATIC CONST AML_NAME_OP_REPLACE SsdtEmmcNameOpReplace[] = {
 
 STATIC CONST AML_NAME_OP_REPLACE DsdtNameOpReplace[] = {
   { "URIU", PcdToken (PcdUartInUse) },
+  { "MUCR", PcdToken (PcdMiniUartClockRate) },
   { }
 };
 
@@ -944,6 +946,13 @@ ConfigInitialize (
     DEBUG ((DEBUG_INFO, "Current Raspberry Pi revision %x\n", mModelRevision));
   }
 
+  Status = mFwProtocol->GetClockRate (RPI_MBOX_CLOCK_RATE_CORE, &mCoreClockRate);
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi core clock rate: %r\n", Status));
+  } else {
+    PcdSet32S (PcdMiniUartClockRate, mCoreClockRate);
+  }
+
   Status = SetupVariables ();
   if (Status != EFI_SUCCESS) {
     DEBUG ((DEBUG_ERROR, "Couldn't not setup NV vars: %r\n", Status));

+ 1 - 0
Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf

@@ -95,6 +95,7 @@
   gRaspberryPiTokenSpaceGuid.PcdFanTemp
   gRaspberryPiTokenSpaceGuid.PcdUartInUse
   gRaspberryPiTokenSpaceGuid.PcdXhciPci
+  gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate
 
 [Depex]
   gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid

+ 5 - 0
Platform/RaspberryPi/RPi3/RPi3.dsc

@@ -561,6 +561,11 @@
   #
   gRaspberryPiTokenSpaceGuid.PcdUartInUse|1
 
+  #
+  # Mini-UART clock rate
+  #
+  gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate|250000000
+
 ################################################################################
 #
 # Components Section - list of all EDK II Modules needed by this Platform

+ 5 - 0
Platform/RaspberryPi/RPi4/RPi4.dsc

@@ -580,6 +580,11 @@
   #
   gRaspberryPiTokenSpaceGuid.PcdUartInUse|0
 
+  #
+  # Mini-UART clock rate
+  #
+  gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate|500000000
+
 ################################################################################
 #
 # Components Section - list of all EDK II Modules needed by this Platform

+ 1 - 0
Platform/RaspberryPi/RaspberryPi.dec

@@ -72,3 +72,4 @@
   gRaspberryPiTokenSpaceGuid.PcdMmcEnableDma|0|UINT32|0x0000001F
   gRaspberryPiTokenSpaceGuid.PcdUartInUse|1|UINT32|0x00000021
   gRaspberryPiTokenSpaceGuid.PcdXhciPci|0|UINT32|0x00000022
+  gRaspberryPiTokenSpaceGuid.PcdMiniUartClockRate|0|UINT32|0x00000023