From patchwork Tue Jan 10 12:41:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 640843 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp2670172pvb; Tue, 10 Jan 2023 04:42:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0sOsaOFUyBzl+iL/6bEMZspFC3GKdnaN++qOiR8qY/E2d63ILcHTGVfHw6KzeJkBD9NpM X-Received: by 2002:a05:6870:9f89:b0:151:ab38:1e75 with SMTP id xm9-20020a0568709f8900b00151ab381e75mr9501914oab.11.1673354549516; Tue, 10 Jan 2023 04:42:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673354549; cv=none; d=google.com; s=arc-20160816; b=t0mtwwocs2u8iLQ56xeFC9JK2RTeIWQDnPj5p/m9MZJHLgvasynnVghXiPbRJHXzW+ JiyMP9haZet+M5iqXmz4xhcoWcjcnkx9+h9IVD3uy5Du7PPEbkl2lSgIjSy/3WhtM141 Dg3vPOPrhuxnME+CISyVTjTFsFPg1Blq7p+ARj4zP+juAG9/PnzL4QsZeddmpIhFzJUT SZh5ciFwV5GB6FxKQVGoJOCDxHy0y1TUd0niFq2UFMOt1NhLCHc5S6Hb49jMPuTbM6bb 8L8IRnl03N9wdr4BV5WUQz7zOYFEtBCbJQi3x99Y5lQkt9dG8aWyzcDwKQ5u5QEPcLjB ndYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E75sBBVwt4L40WGZr9UaKdoE0I/uk49Dn8ZiNWmVifs=; b=J/Z23o1rdb3XuBOMYPopxbXSNaqXVwrSfFIIpet9Utzybcj8M7kVL/LkgV47RxtVuZ Zf06RseLvq89RpetLAks2Dk9al/s4p4AZrMZwKpPUgHhGuu3cn4+O+QXX7mZV0v7ddpD vSe5vetLh736hDiq/glzi21oqQlG627KpiL/I5BuSD5UlXnH8RFEHJU9QW9iA+eoEldd zYIKH8Cg9lGv59+moBHNvx3d5idCgSSgwA760t70W/JPz0DcDk3VZwruorZzAXnVDM3n NuThVXpMvoxFTcMaDCvdv3bUBcFvG29PFXjqWYJM6zDVIZOOSjHGKg8MsQ6Dd6HXrtNX YeMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XGrzObjg; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id v10-20020a4ac90a000000b004ae20f6de86si9703795ooq.5.2023.01.10.04.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 04:42:29 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XGrzObjg; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1477E854BD; Tue, 10 Jan 2023 13:42:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="XGrzObjg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 126CD851E6; Tue, 10 Jan 2023 13:42:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DEDC885477 for ; Tue, 10 Jan 2023 13:41:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=loic.poulain@linaro.org Received: by mail-wr1-x434.google.com with SMTP id bs20so11591259wrb.3 for ; Tue, 10 Jan 2023 04:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E75sBBVwt4L40WGZr9UaKdoE0I/uk49Dn8ZiNWmVifs=; b=XGrzObjgp158XQrAzVPsaq1djwl68mxpAIEVGwYfAtJvZW8ojXcbzqSPpxk18YXuFM h1cSa3Ft5oAeH1Ffbdk5aIK8RSzysx0wAJNK5d5FuATGzigxPWFqesFk6eVC9JB+/uF6 Oe2oayMiN2elO92H1nCnHtzjdLUhdXgj4K4zjv20XK8igMlVF8ZA5Q45kJCrgNd77MG8 VJY82HE8/qNFSHD6lcZYnvIfJgO0DxcANlBIRsHu1nBnMG/80dfrYQCNXNOjoer7JU7I tmAmxuJLOTOz7Sl7Phx/ZqfMV6z6fg5bLHSIlGj/UJyE95dX6B8KiyU39CIH0AgQhUMg Ppgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E75sBBVwt4L40WGZr9UaKdoE0I/uk49Dn8ZiNWmVifs=; b=3P+PDdivNWU7XvfwZ1hyaYxDw/laYerxvfdWJMzli++UooUb2ckFoIem0Ahg6YBrLH +vHiQgXAm6IXMBbrxF/Mo26eyWAc2Pt170EHahYnQRvuHgWmttHSw0h0tN46fQem+8Eg 7Scx5T6/gsSy1EylmPF8ZQh5NrAYFEcmmDiKWWc+6J4IXNQ52yj86X1hTuJMvZDeD1+h Jz5BdbJTs2RXcBun9xZkbMN+isCh6e1bMBxp7kIqJMzX7LJlglLOuLiUyMa+GyhZDcoQ e4E2t8LoO6dGuk9x6cWJGGqgSB3PK+fh0mW123KC/ny9kpLwsCBLrHTsrEwacxY2rDcM OpJA== X-Gm-Message-State: AFqh2kpRit/VFh2Xvvj3wDOOGaZv68jWEMPj/0oO4QGjRL6nFhVnvvGB NrvNINXl0gT0eKo3pnt4g2mOBA== X-Received: by 2002:a5d:5222:0:b0:29b:2d42:65b7 with SMTP id i2-20020a5d5222000000b0029b2d4265b7mr18653585wra.33.1673354513414; Tue, 10 Jan 2023 04:41:53 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:a2ad:457f:18a:ffcb]) by smtp.gmail.com with ESMTPSA id q11-20020adff50b000000b0027f9f073211sm11220112wro.65.2023.01.10.04.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 04:41:52 -0800 (PST) From: Loic Poulain To: sbabic@denx.de, festevam@gmail.com Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, LW@karo-electronics.de, Loic Poulain Subject: [PATCH v2 2/2] serial: mxc: Wait for TX completion before reset Date: Tue, 10 Jan 2023 13:41:47 +0100 Message-Id: <20230110124147.1780670-2-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110124147.1780670-1-loic.poulain@linaro.org> References: <20230110124147.1780670-1-loic.poulain@linaro.org> MIME-Version: 1.0 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 The u-boot console may show some corrupted characters when printing in board_init() due to reset 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 proceding 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 --- v2: Add this commit to the series drivers/serial/serial_mxc.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c index f8c49865be..9899155c00 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); @@ -252,10 +267,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,