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 27396740051 for ; Thu, 11 Jan 2024 15:02:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=qHknHMkLczFU+zmOugL1SXJ/td526z8UIB74G3OZk2o=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1704985351; v=1; b=SW1WsZ+B1HpWRg1pTo01vx1qZbtbkO5Z1kRUydSx+ISNX5qAXzDnuck6vrArx2Vf9MgUtBw1 3WV9NLxjlKSMbMl65eyzxpgh2XbGv16xAS2vDtVZ4/BrmGJgjXVUlKlxIgOMFjY/UHI1Pof9Vku x9JFEPY5N6OVH1HFgWH85MJk= X-Received: by 127.0.0.2 with SMTP id 9OFaYY7687511x0fgKCE2VpF; Thu, 11 Jan 2024 07:02:31 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.13342.1704985351016606997 for ; Thu, 11 Jan 2024 07:02:31 -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 618742F4; Thu, 11 Jan 2024 07:03:16 -0800 (PST) X-Received: from [192.168.20.13] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 597003F5A1; Thu, 11 Jan 2024 07:02:30 -0800 (PST) Message-ID: Date: Thu, 11 Jan 2024 09:02:29 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [edk2-devel] [PATCH 1/5] Platform/RaspberryPi/DualSerialPortLib: Always configure the pl011 To: Ard Biesheuvel Cc: devel@edk2.groups.io, ardb+tianocore@kernel.org, quic_llindhol@quicinc.com References: <20240110235227.2734271-1-jeremy.linton@arm.com> <20240110235227.2734271-2-jeremy.linton@arm.com> From: "Jeremy Linton" In-Reply-To: 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: 4JeqrZC84921YDnXHwHHA9Qox7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed 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=SW1WsZ+B; 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 Hi, On 1/11/24 01:46, Ard Biesheuvel wrote: > Hi Jeremy, >=20 > Thanks for the patches. Thanks for looking at them! >=20 >=20 > On Thu, 11 Jan 2024 at 00:52, Jeremy Linton wrote= : >> >> The rpi's config.txt controls which uart (pl011, or miniuart) is >> selected as the console. TFA and edk2 follow its lead, but if the >> miniuart is selected as the primary and the machine is booted in ACPI >> mode the baud/etc is never configured for the pl011. The linux kernel >> won't reconfigure it either as its listed as a "SBSA" uart, so it >> simply won't work. >> >> This re-enables BT on the pl011 in ACPI mode, and it somewhat starts >> to work again. >> >> Signed-off-by: Jeremy Linton >> --- >> .../DualSerialPortLib/DualSerialPortLib.c | 37 +++++++++++-------- >> 1 file changed, 22 insertions(+), 15 deletions(-) >> >> diff --git a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPo= rtLib.c b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.= c >> index d2f983bf0a..79545d93d6 100644 >> --- a/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c >> +++ b/Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c >> @@ -76,6 +76,8 @@ SerialPortInitialize ( >> EFI_PARITY_TYPE Parity; >> UINT8 DataBits; >> EFI_STOP_BITS_TYPE StopBits; >> + RETURN_STATUS Ret; >> + UINTN Timeout; >=20 > What is this for? IIRC, its as you see, being used below to avoid an infinite loop when=20 the miniuart doesn't become ready. That shouldn't be possible with this=20 set, so its a safety change. But IIRC, the infinite loop can be triggered by trying to enable the=20 miniuart early, when its not the console, before the config dxe is run=20 to turn the clock/regulator on. Which is what I was originally trying to=20 do in this patch by configuring both uarts unconditionally. >=20 >=20 >> >> // >> // First thing we need to do is determine which of PL011 or miniUART= is selected >> @@ -85,23 +87,27 @@ SerialPortInitialize ( >> UsePl011UartSet =3D TRUE; >> } >> >> - if (UsePl011Uart) { >> - BaudRate =3D FixedPcdGet64 (PcdUartDefaultBaudRate); >> + // always init the pl011 on the pi4, linux expects a SBSA uart to be = at 115200 >> + // this means we need to set the baud/etc even if we arn't using it a= s a console ^ I should probably fix the spelling issues there too. >> + if ((UsePl011Uart) || (RPI_MODEL =3D=3D 4)) { >> ReceiveFifoDepth =3D 0; // Use default FIFO depth >> + BaudRate =3D FixedPcdGet64 (PcdUartDefaultBaudRate); >=20 > Shouldn't we hardcode 115200 here if !UsePl011Uart? Probably? For spec compliance for sure. Although the BT as I mentioned is flaky, it will scan and connect to=20 things like keyboards/mice and sorta work, although it may drop the=20 connections/etc. A2dp devices are a no-go. But, running the port faster=20 than 115200 seems to at least extend how long it works. So, presumably=20 part of the problem is that the BT wants to bump the baud rate and reset=20 the device, neither of which it can do in ACPI mode at the moment. And=20 for clarity it does some of this in DT mode too, so its not entirely=20 just baud rate and reset problems. I spent a fair bit of time a year+=20 back trying to get the BT to work reliably in just DT mode with mainline=20 on the miniuart as well as on the pl011 where it sorta works and moved=20 on to other things before solving the problem. So, I guess I can hard-code it here, at least then we are spec compliant. >=20 >> Parity =3D (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity); >> DataBits =3D FixedPcdGet8 (PcdUartDefaultDataBits); >> StopBits =3D (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStop= Bits); >> >> - return PL011UartInitializePort ( >> - PL011_UART_REGISTER_BASE, >> - PL011UartClockGetFreq(), >> - &BaudRate, >> - &ReceiveFifoDepth, >> - &Parity, >> - &DataBits, >> - &StopBits >> - ); >> - } else { >> + Ret =3D PL011UartInitializePort ( >> + PL011_UART_REGISTER_BASE, >> + PL011UartClockGetFreq(), >> + &BaudRate, >> + &ReceiveFifoDepth, >> + &Parity, >> + &DataBits, >> + &StopBits >> + ); >> + } >> + >> + if (!UsePl011Uart) { >> SerialRegisterBase =3D MINI_UART_REGISTER_BASE; >> Divisor =3D SerialPortGetDivisor (PcdGet32 (PcdSerialBaudRate)); >> >> @@ -127,7 +133,8 @@ SerialPortInitialize ( >> // Wait for the serial port to be ready. >> // Verify that both the transmit FIFO and the shift register are e= mpty. >> // >> - while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (= B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXR= DY)); >> + Timeout =3D 1000; >> + while (((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & = (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TX= RDY)) && (Timeout--)); >> >> // >> // Configure baud rate >> @@ -158,9 +165,9 @@ SerialPortInitialize ( >> // Put Modem Control Register(MCR) into its reset state of 0x00. >> // >> SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00); >> - >> - return RETURN_SUCCESS; >> + Ret =3D RETURN_SUCCESS; >> } >> + return Ret; >> } >> >> /** >> -- >> 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 (#113621): https://edk2.groups.io/g/devel/message/113621 Mute This Topic: https://groups.io/mt/103652853/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-