From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mx.groups.io with SMTP id smtpd.web11.6796.1617881971782841959 for ; Thu, 08 Apr 2021 04:39:32 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=srNqyz4z; spf=pass (domain: akeo.ie, ip: 209.85.128.47, mailfrom: pete@akeo.ie) Received: by mail-wm1-f47.google.com with SMTP id p22so1032762wmc.3 for ; Thu, 08 Apr 2021 04:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QDBEcTgx5DMti0KmWTY/1iZ59lA2s3dPXFD32uqeUDo=; b=srNqyz4zYcj8P+0LDdFoBUZgfaBS/YL12N/MksIjdtoAAPspwl1iU5mxLGNGrc0O8e Fq9e2g0yTT4d0lYG+D/OF3iHHhmAuwhGc21k6bHJa38XP4Ivg1ukqqF87BPZDK2xLpBL EB4nj+cMLpyBDOty2yJR/WF5kE6rnAaqRXda2TeA5IIrY0/WDXSOeKKBsPyxPIrO2TCj v4IxzjnUT11x/hugheWa6q1+x5shtBRo3aMcJyif9CcbWPeIR8Q2SpC7MFz7YqxsPNCA wsNqAZn+4kHVzdHOy4+sDK4IsyhNfwXfjhylqNXfk8P4ejqOt10pZbk7C5iPzzWrUocn 52NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QDBEcTgx5DMti0KmWTY/1iZ59lA2s3dPXFD32uqeUDo=; b=kB4dXyLZGnZ4PfZPsNbTbKMT/laoLHAFb4qs7K1Das50VM6IzZq4GmFLyQHSzRhKWq 6VG7peo1HQVowbu0uzYMT74gfpHzISG8eq1t0dGtf3fQyxwPsVl/YnJSDDHvnZbOFmwH Nr7Va5ZapFyCyuzbORiMmdN1uqL3SYtxYHha5GDwCr/VDHInyCRGdeIR4Y3dINgMyZSv qFTnIr5uwhLC3uujwD4563csO7goL/xtNi6M64Tph+9rBgkmGQY/aNUe18h2UrCRwoRS lC66YW3auN/P8pt6KYG66Te1rr2rBls8kos7qad4FCHscH3PI5a8OEmbj8sN6thLYjHB C4CQ== X-Gm-Message-State: AOAM532kHl4ftA49Sswdg/OGiQn/LgPlGKNrJ3PzSrw90p8M3wsNU3je Jyk5rrkuaucpjc+sB+L66UBNnzr8HMnEJA== X-Google-Smtp-Source: ABdhPJywNIDE7PDjHVTG5nhIc2OZaMRiBZaJJT5sGNRN+Ff+Y+xAyEpL64uc52ZZ8IGiBApHwb72eg== X-Received: by 2002:a7b:c3c1:: with SMTP id t1mr8125300wmj.154.1617881970193; Thu, 08 Apr 2021 04:39:30 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.65.130]) by smtp.gmail.com with ESMTPSA id y17sm16692870wrw.1.2021.04.08.04.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 04:39:29 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org Subject: [edk2-platforms][PATCH v2 1/1] Platform/RaspberryPi: Fix mini UART clock divisor calculation Date: Thu, 8 Apr 2021 12:39:18 +0100 Message-Id: <20210408113918.514-1-pete@akeo.ie> X-Mailer: git-send-email 2.30.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Mario B=C4=83l=C4=83nic=C4=83 =0D The VPU clock divisor has changed in this commit: https://github.com/raspbe= rrypi/firmware/commit/1e5456a,=0D thus breaking the mini UART clock divisor calculation on the Pi 4.=0D =0D Fix this by reading the core clock from the mailbox instead.=0D =0D Signed-off-by: Mario B=C4=83l=C4=83nic=C4=83 =0D ---=0D Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 15 = +++------------=0D Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 4 = ----=0D Platform/RaspberryPi/RPi4/RPi4.dsc | 6 = ++++--=0D 3 files changed, 7 insertions(+), 18 deletions(-)=0D =0D diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortL= ib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D index 5e83bbf022eb..d2f983bf0a9f 100644=0D --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c=0D @@ -34,25 +34,16 @@ SerialPortGetDivisor (=0D UINT32 SerialBaudRate=0D )=0D {=0D - UINT64 BaseClockRate;=0D + UINT32 BaseClockRate;=0D UINT32 Divisor;=0D =0D - //=0D - // On the Raspberry Pi, the clock to use for the 16650-compatible UART=0D - // is the base clock divided by the 12.12 fixed point VPU clock divisor.= =0D - //=0D - BaseClockRate =3D (UINT64)PcdGet32 (PcdSerialClockRate);=0D -#if (RPI_MODEL =3D=3D 4)=0D - Divisor =3D MmioRead32(BCM2836_CM_BASE + BCM2836_CM_VPU_CLOCK_DIVISOR) &= 0xFFFFFF;=0D - if (Divisor !=3D 0)=0D - BaseClockRate =3D (BaseClockRate << 12) / Divisor;=0D -#endif=0D + BaseClockRate =3D PcdGet32 (PcdSerialClockRate);=0D =0D //=0D // As per the BCM2xxx datasheets:=0D // baudrate =3D system_clock_freq / (8 * (divisor + 1)).=0D //=0D - Divisor =3D (UINT32)BaseClockRate / (SerialBaudRate * 8);=0D + Divisor =3D BaseClockRate / (SerialBaudRate * 8);=0D if (Divisor !=3D 0) {=0D Divisor--;=0D }=0D diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHe= lper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper= .S=0D index 58351e4fb8cc..7008aaf8aa4c 100644=0D --- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S= =0D +++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S= =0D @@ -85,13 +85,11 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D adr x2, mBoardRevision=0D str w0, [x2]=0D =0D -#if (RPI_MODEL =3D=3D 3)=0D run .Lclkinfo_buffer=0D =0D ldr w0, .Lfrequency=0D adr x2, _gPcd_BinaryPatch_PcdSerialClockRate=0D str w0, [x2]=0D -#endif=0D =0D ret=0D =0D @@ -135,7 +133,6 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D .long 0 // end tag=0D .set .Lrevinfo_size, . - .Lrevinfo_buffer=0D =0D -#if (RPI_MODEL =3D=3D 3)=0D .align 4=0D .Lclkinfo_buffer:=0D .long .Lclkinfo_size=0D @@ -148,7 +145,6 @@ ASM_FUNC (ArmPlatformPeiBootAction)=0D .long 0 // frequency=0D .long 0 // end tag=0D .set .Lclkinfo_size, . - .Lclkinfo_buffer=0D -#endif=0D =0D //UINTN=0D //ArmPlatformGetPrimaryCoreMpId (=0D diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc=0D index 2c05c31118d2..ff802d8347ea 100644=0D --- a/Platform/RaspberryPi/RPi4/RPi4.dsc=0D +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc=0D @@ -429,7 +429,6 @@ [PcdsFixedAtBuild.common]=0D gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4=0D - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1000000000=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8=0D gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200=0D @@ -465,6 +464,9 @@ [PcdsFixedAtBuild.common]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"EDK2"=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE=0D =0D +[PcdsPatchableInModule]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000=0D +=0D [PcdsDynamicHii.common.DEFAULT]=0D =0D #=0D @@ -621,7 +623,7 @@ [Components.common]=0D MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf=0D MdeModulePkg/Universal/SerialDxe/SerialDxe.inf {=0D =0D - SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortLib.inf=0D + SerialPortLib|Platform/RaspberryPi/Library/DualSerialPortLib/DualSer= ialPortDxeLib.inf=0D }=0D Platform/RaspberryPi/Drivers/DisplayDxe/DisplayDxe.inf=0D EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.inf=0D -- 2.29.2.windows.2=0D