public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: Pete Batard <pete@akeo.ie>, devel@edk2.groups.io
Cc: leif@nuviainc.com, andrey.warkentin@gmail.com
Subject: Re: [edk2-devel] [PATCH edk2-platforms 3/5] Platform/RaspberryPi: fix 16550 divisor calculation logic
Date: Wed, 6 May 2020 12:25:01 +0200	[thread overview]
Message-ID: <6404e95f-cb15-9924-92bc-8b2b4f7c59c7@arm.com> (raw)
In-Reply-To: <956d2e2b-440e-9b04-1af1-a4a6a2dbe6ff@akeo.ie>

On 5/6/20 12:18 PM, Pete Batard wrote:
> One general remark below:
> 
> On 2020.05.05 19:10, Ard Biesheuvel wrote:
>> On 5/5/20 4:50 PM, Ard Biesheuvel wrote:
>>> The 16550 'miniUART' on the Raspberry Pi gets its input clock from
>>> different sources on RPi3 and RPi3. Fix the logic that derives the
>>
>> This should be 'Rpi3 and RPi4'
>>
>>> divisor for the 16550 baud clock on the respective platforms.
>>>
>>> While at it, make the input clock PCD patchable for RPi3 so we can
>>> manipulate it at runtime in a future patch.
> 
> For the sake of harmonization between platforms, wouldn't we want to 
> also declare the PCD patchable on RPi4 as well (even though we obviously 
> aren't going to patch it for the time being)?
> 

I'd prefer not to. That way, we can easily spot problems when the 
patching code is incorporated inadvertently.

> There is some plan of factorizing the DSC content, so if that doesn't 
> hurt us, I'd propose we try to keep the Pi3 and Pi4 version as close as 
> possible.
> 
> This also ties in with my remark for the next patch.
> 
>>>
>>> Co-authored-by: Pete Batard <pete@akeo.ie>
>>> Co-authored-by: Andrei Warkentin <andrey.warkentin@gmail.com>
>>> Co-authored-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
>>> Signed-off-by: Pete Batard <pete@akeo.ie>
>>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
>>> ---
>>>   Platform/RaspberryPi/RPi3/RPi3.dsc |  4 +++-
>>>   Platform/RaspberryPi/RPi4/RPi4.dsc |  2 +-
>>>   Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c 
>>> | 14 ++++++++------
>>>   3 files changed, 12 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc 
>>> b/Platform/RaspberryPi/RPi3/RPi3.dsc
>>> index d7218219fc5a..96b27400eef8 100644
>>> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
>>> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
>>> @@ -409,7 +409,6 @@ [PcdsFixedAtBuild.common]
>>>     gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4
>>> -  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8
>>>     gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200
>>> @@ -441,6 +440,9 @@ [PcdsFixedAtBuild.common]
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"EDK2"
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE
>>> +[PcdsPatchableInModule]
>>> +  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|250000000
>>> +
>>>   [PcdsDynamicHii.common.DEFAULT]
>>>     #
>>> diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc 
>>> b/Platform/RaspberryPi/RPi4/RPi4.dsc
>>> index 4fb015b077e6..5d8bd88d7e34 100644
>>> --- a/Platform/RaspberryPi/RPi4/RPi4.dsc
>>> +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
>>> @@ -420,7 +420,7 @@ [PcdsFixedAtBuild.common]
>>>     gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4
>>> -  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000
>>> +  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1000000000
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27
>>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8
>>>     gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200
>>> diff --git 
>>> a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c 
>>> b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c
>>> index b1d17d3fa04a..5e83bbf022eb 100644
>>> --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c
>>> +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c
>>> @@ -41,18 +41,20 @@ SerialPortGetDivisor (
>>>     // On the Raspberry Pi, the clock to use for the 16650-compatible 
>>> UART
>>>     // is the base clock divided by the 12.12 fixed point VPU clock 
>>> divisor.
>>>     //
>>> -  BaseClockRate = (UINT64)PcdGet32 (PcdSerialClockRate) * 4;
>>> +  BaseClockRate = (UINT64)PcdGet32 (PcdSerialClockRate);
>>> +#if (RPI_MODEL == 4)
>>>     Divisor = MmioRead32(BCM2836_CM_BASE + 
>>> BCM2836_CM_VPU_CLOCK_DIVISOR) & 0xFFFFFF;
>>>     if (Divisor != 0)
>>>       BaseClockRate = (BaseClockRate << 12) / Divisor;
>>> +#endif
>>>     //
>>> -  // Now calculate divisor for baud generator
>>> -  //    Ref_Clk_Rate / Baud_Rate / 16
>>> +  // As per the BCM2xxx datasheets:
>>> +  // baudrate = system_clock_freq / (8 * (divisor + 1)).
>>>     //
>>> -  Divisor = (UINT32)BaseClockRate / (SerialBaudRate * 16);
>>> -  if (((UINT32)BaseClockRate % (SerialBaudRate * 16)) >= 
>>> SerialBaudRate * 8) {
>>> -    Divisor++;
>>> +  Divisor = (UINT32)BaseClockRate / (SerialBaudRate * 8);
>>> +  if (Divisor != 0) {
>>> +    Divisor--;
>>>     }
>>>     return Divisor;
>>>   }
>>>
>>
>>
>> 
>>
> 
> Reviewed-by: Pete Batard <pete@akeo.ie>
> 


  reply	other threads:[~2020-05-06 10:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 14:50 [PATCH edk2-platforms 0/5] Platform/RaspberryPi: fix serialportlib dependency hell Ard Biesheuvel
2020-05-05 14:50 ` [PATCH edk2-platforms 1/5] Platform/RaspberryPi/DualSerialPortLib: split up to ease reuse Ard Biesheuvel
2020-05-06 10:18   ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 2/5] Platform/RaspberryPi: introduce DebugDualSerialPortLib Ard Biesheuvel
2020-05-06 10:18   ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 3/5] Platform/RaspberryPi: fix 16550 divisor calculation logic Ard Biesheuvel
2020-05-05 18:10   ` Ard Biesheuvel
2020-05-06 10:18     ` [edk2-devel] " Pete Batard
2020-05-06 10:25       ` Ard Biesheuvel [this message]
2020-05-05 14:50 ` [PATCH edk2-platforms 4/5] Platform/RaspberryPi3: query firmware for 16550 input clock at boot Ard Biesheuvel
2020-05-05 18:11   ` Ard Biesheuvel
2020-05-06 10:18     ` [edk2-devel] " Pete Batard
2020-05-06 10:31       ` Ard Biesheuvel
2020-05-06 10:38         ` Pete Batard
2020-05-05 14:50 ` [PATCH edk2-platforms 5/5] Platform/RaspberryPi: create DXE phase SerialPortLib version for RPi3 Ard Biesheuvel
2020-05-06 10:19   ` Pete Batard
2020-05-06 16:16 ` [PATCH edk2-platforms 0/5] Platform/RaspberryPi: fix serialportlib dependency hell Ard Biesheuvel

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=6404e95f-cb15-9924-92bc-8b2b4f7c59c7@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