Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE482C61DB3 for ; Thu, 12 Jan 2023 17:52:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E2C3C85351; Thu, 12 Jan 2023 18:52:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="QB64OHgt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95911852E2; Thu, 12 Jan 2023 18:51:59 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1367185351 for ; Thu, 12 Jan 2023 18:51:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9E8E5B81F02; Thu, 12 Jan 2023 17:51:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BD2EC433D2; Thu, 12 Jan 2023 17:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673545915; bh=cuCMeKupCLWknHglus4SbXzW5fo7a2MbF5yttzulD/Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QB64OHgtg4VRa/KqWnR+HIoi9lAUWtsA+LV4+XghQ0aLB9476jB0BTfyE3VhCeFRQ BYrWWX8+xXFUb/44HXOi7ZXZ34mM1oSecp6QGTT3z3RDHEdij6Y4Yua8m6Ff1ZRMF4 It85tIcwJBGkqV58Rp0jfUPukkbsNxi79ID42qP74U8eGs0YLHezMPnqHYnFfjN1tj spEylK2kbB5u5l7yHBfSLJXFu8Tfx1mgnBxaTfGHWWlbNSQ+teOSmfpDqa72WpVeRt n6Q1U7fUty5Bu/uZK9DnYneGQvlEbWISkm5IE8mIZtEv7IcPtDq2bHLoPdSMT5fZ7/ 9kczBMI0FOr9A== Received: by pali.im (Postfix) id 4141878C; Thu, 12 Jan 2023 18:51:52 +0100 (CET) Date: Thu, 12 Jan 2023 18:51:52 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Loic Poulain Cc: sbabic@denx.de, festevam@gmail.com, uboot-imx@nxp.com, u-boot@lists.denx.de, LW@karo-electronics.de Subject: Re: [PATCH v4 1/2] serial: mxc: Wait for TX completion before reset Message-ID: <20230112175152.2t4cntouc3zyfkey@pali> References: <20230112171951.2082899-1-loic.poulain@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230112171951.2082899-1-loic.poulain@linaro.org> User-Agent: NeoMutt/20180716 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Thursday 12 January 2023 18:19:50 Loic Poulain wrote: > The u-boot console may show some corrupted characters when > printing in board_init() due to reset or baudrate change > of the UART (probe) before the TX FIFO has been completely > drained. > > To fix this issue, and in case UART is still running, we now > try to flush the FIFO before proceeding to UART reinitialization. > For this we're waiting for Transmitter Complete bit, indicating > that the FIFO and the shift register are empty. > > flushing has a 4ms timeout guard, which is normally more than > enough to consume the FIFO @ low baudrate (9600bps). > > Signed-off-by: Loic Poulain > Tested-by: Lothar Waßmann Acked-by: Pali Rohár > --- >  v2: Add this commit to the series > v3: Fix typo & reordering commits for good bisectabilit > v4: Wait for transfer completion before baudrate change as well > > drivers/serial/serial_mxc.c | 26 +++++++++++++++++++++++++- > 1 file changed, 25 insertions(+), 1 deletion(-) > > diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c > index 82c0d84628..9e5b987994 100644 > --- a/drivers/serial/serial_mxc.c > +++ b/drivers/serial/serial_mxc.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > /* UART Control Register Bit Fields.*/ > #define URXD_CHARRDY (1<<15) > @@ -144,8 +145,22 @@ struct mxc_uart { > u32 ts; > }; > > +static void _mxc_serial_flush(struct mxc_uart *base) > +{ > + unsigned int timeout = 4000; > + > + if (!(readl(&base->cr1) & UCR1_UARTEN) || > + !(readl(&base->cr2) & UCR2_TXEN)) > + return; > + > + while (!(readl(&base->sr2) & USR2_TXDC) && --timeout) > + udelay(1); > +} > + > static void _mxc_serial_init(struct mxc_uart *base, int use_dte) > { > + _mxc_serial_flush(base); > + > writel(0, &base->cr1); > writel(0, &base->cr2); > > @@ -169,6 +184,8 @@ static void _mxc_serial_setbrg(struct mxc_uart *base, unsigned long clk, > { > u32 tmp; > > + _mxc_serial_flush(base); > + > tmp = RFDIV << UFCR_RFDIV_SHF; > if (use_dte) > tmp |= UFCR_DCEDTE; > @@ -252,10 +269,17 @@ static int mxc_serial_init(void) > return 0; > } > > +static int mxc_serial_stop(void) > +{ > + _mxc_serial_flush(mxc_base); > + > + return 0; > +} > + > static struct serial_device mxc_serial_drv = { > .name = "mxc_serial", > .start = mxc_serial_init, > - .stop = NULL, > + .stop = mxc_serial_stop, > .setbrg = mxc_serial_setbrg, > .putc = mxc_serial_putc, > .puts = default_serial_puts, > -- > 2.34.1 >