From patchwork Tue Jan 10 19:23:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 640891 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp2879768pvb; Tue, 10 Jan 2023 11:23:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXvsJfPd2GQuyr+rn7JqPtt84+AJZBxNS0urHSKNeD+hVsARDKOaamZneQfP/t6gmmY9EKXh X-Received: by 2002:a05:6870:4252:b0:155:8fa7:3a72 with SMTP id v18-20020a056870425200b001558fa73a72mr13413oac.5.1673378623622; Tue, 10 Jan 2023 11:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673378623; cv=none; d=google.com; s=arc-20160816; b=AYQnIfckp+k6EjVE7AcGIwMeJrh/8UnJgHKRXlcuz1ZVbIxYpRTWROUVteHREcDZNJ 8lhsw5L6Zh5EQiFB5gL8zCJITfPlIxQdkCT//jVzMHaQOrQu3QC3oCSPNCyZl2EfFDLu Ktpj+IoSGiGnJK8L5SDf6orF4iReXjS74LiMZL1bH1UAQzztuDlEqFYj91eEwn7kVAQS 6sRTlqNaXnW7PLOcyCOE0yR25QryA2H+Z5S8KsyG6JRDl1ADBEg1lO8aoDGYaTumzcgU 8cBkg48+xdz04T26TSP1OdHXy+xFxmeWHRysWFPuofePqTCsz2+fK8f9g2UDoylYuVlV 0Xnw== 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=aLkr9jZPf/ibv6j+HMGTI+0NiPeyGoaKhog4KL2RtY02E5GEWJdzTP3v6jh6vQrTIk RnglRjef0ejkssOipkZdyRkrWGpG7ed6FiwGQfNhefCP/aDwH8Dj4bBxlbM1Q72Bdkh5 mcGVFbqw5nKTx/hrKD9Q4aawYrxvgWAJ8CSA9lAsk+ih+rUBSWePN6CQaoPpmh/Llru2 C+VIv5W/c0gyu0T12DafivC0TcUei89oNkTsZLJ3eufSiv1ZP8GRa/b7SfLuWTdHTge4 qrl8nJ6YsSUeqVPKQLpkjaxrxMibvKL3PqzTIl6sqdKJqe8HYTJkgYmR82SeCIAtRvTM 0yfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iHrvzFNP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j27-20020a056870169b00b00152c52608cbsi8758970oae.234.2023.01.10.11.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 11:23:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iHrvzFNP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 C81B385682; Tue, 10 Jan 2023 20:23:33 +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="iHrvzFNP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C7C785626; Tue, 10 Jan 2023 20:23:31 +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=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (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 5DD0C85676 for ; Tue, 10 Jan 2023 20:23:28 +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-wm1-x333.google.com with SMTP id i17-20020a05600c355100b003d99434b1cfso10922283wmq.1 for ; Tue, 10 Jan 2023 11:23:28 -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=iHrvzFNPmNpkvdFJDas45MEumh2SojV6uFkAx9auC2CnctmsaYVaWj6LMKhUYT3PzZ z2LJ+hl7tpYjyuc4QxilXv0EHqMcZxT+ABKsH6PYaHLqjio5gGJLBYeT6VGLENdzEUd3 YAABwt9qm5cumi/zYz7y3CEODyy//O2eEvUvFi5V8HQFmu4P+/h3J1UAZg3Yt70Nrn+p 34i2MWfSH7uGKF+ITq1LNI1IKAu98JBwqe9b8wJKaxR+El09fX/DCRc3TllmTuHYS1PL IIdAZ5fpoOMX3AVYgEWws3m9doRMho5VFLh9hP93eHFdfECW3E9rnb4BOt9whw99WtCP eLZA== 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=OM4Tc9S0NeqO2Mg2+Pj0m/TWSDpdQGJSqABxb5ifd2kQOx+PBOIxwVMUZi61ZR7Yl6 LDDxGcL0QzRxkbGRG4BxgiR4og/8CGb8I52gUOChGXqWhR6BAHbcjpbESPVqy06ONvBv lIaVIqHlShbReapRhoVZGX0INkSXid07ZceBb3Qb/jMja3+9E3PMcPz3NIsfe+uhI4gS ZCs5A56WVMkzm6YirG5mVJazG/FnL6DR3rrVSDoLQbFZZesP8miC8QncoKN22t8duBd7 n0T//d9tlfyucUu2RR3258fYwiMkPUbidP+dlStapaW3QGgeS0M986g5+v0bYCZfCSfh JZKw== X-Gm-Message-State: AFqh2kqLi65+Z1owJhurTm6ydLluFBG0IN0Bd/KeKKR1awqskML3Th1v 7W/Kl66PYN/Idwf/iXCVe0pQIg== X-Received: by 2002:a05:600c:229a:b0:3d9:ec70:befc with SMTP id 26-20020a05600c229a00b003d9ec70befcmr7790459wmf.13.1673378607858; Tue, 10 Jan 2023 11:23:27 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:a2ad:457f:18a:ffcb]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003a84375d0d1sm22366087wmc.44.2023.01.10.11.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 11:23:27 -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 20:23:22 +0100 Message-Id: <20230110192322.1874021-2-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110192322.1874021-1-loic.poulain@linaro.org> References: <20230110192322.1874021-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 --- 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,