From patchwork Thu Aug 9 19:04:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 955765 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iQXdaYMT"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41md5q4M9Jz9s3Z for ; Fri, 10 Aug 2018 05:06:39 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3F7FFC21DA6; Thu, 9 Aug 2018 19:06:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8F38DC21DD9; Thu, 9 Aug 2018 19:05:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DB362C21D9A; Thu, 9 Aug 2018 19:05:00 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id A6025C21DA1 for ; Thu, 9 Aug 2018 19:04:56 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id h9-v6so6070183wro.3 for ; Thu, 09 Aug 2018 12:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5n6iQ5EAO+uddnuAJL7JSkceyxkH8jWzkxOqMcbgGBw=; b=iQXdaYMTA87xNqko+9h6Meib9goNglpIElc1idwTUh7AbIPjDelfRZv3JbVfKkvu63 2eamg6sCkUnVVPcceg5b3qycycFaj9ucB9pWVDBxxGpH24BVndjjKS5yg40asXFhVc3r HYVwplNs1Q69tfMT6M2I5XOvrN51zE4moruNr/ANWTDGD5d0blmv6ELc2LhwqRE9WLrT 92jm8/vdkt+8/vzh2c8/Q16qwm0FuH657f5anLggEumCGQKINz2CWhUNl5yIQHzqgxSA 7H4iMiQdxAceG8mQvBV+CS9skQRGOg6l/v9Oqha947fjLIrGU9HqFX/9wwBN+sEKNNXB qxjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5n6iQ5EAO+uddnuAJL7JSkceyxkH8jWzkxOqMcbgGBw=; b=fQtsKnqfwoCNaMLw4IktqMOiLLKl7XiZEcShUSSAdPJcWIXstoWng/2IJN34FGAHjU gENfewV+whfOSSn3UjSESOQgdWjwsarNBb6baiHONxBwz/1xpjdvc9IwFk8mh/HCuyO/ YyF4/201BjHvz+KsUOHCkapy4+raQudXDMMgrI4U6op0JTtwCb1AOfEDfvUIMLO6oLCl IZ4BK3uXHEr9+wYXolpamyaFOOmI5WxIXoolmRuZeVjlU5X1ABBmkb5JBQJsQBl4yKG5 KZvmgSJ7uO1O+upRGtEJ+ko1JfblHap6+hB6itaG+YaqkHpDwtHOVya7r0iWpbJKyg7r TK0w== X-Gm-Message-State: AOUpUlExko4BCNhvA2sITAQIdvUg17WxmHby81jupCq2dJkgZoMp/tBu bXxTtg4WqatWjVTHcD5ViJg= X-Google-Smtp-Source: AA+uWPxZE3ByiXTAK6RIa+Yk8OWJF4Xe2f/RmWFMfDZtziKLvJWYZLXCptr9dPWDuvdZwXtPLE1dxg== X-Received: by 2002:adf:f60a:: with SMTP id t10-v6mr2052642wrp.170.1533841496426; Thu, 09 Aug 2018 12:04:56 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:542c:ff11:9c97:a518]) by smtp.gmail.com with ESMTPSA id h7-v6sm8280575wrs.8.2018.08.09.12.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 12:04:55 -0700 (PDT) From: Simon Goldschmidt To: Marek Vasut Date: Thu, 9 Aug 2018 21:04:19 +0200 Message-Id: <20180809190420.28093-6-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180809190420.28093-1-simon.k.r.goldschmidt@gmail.com> References: <20180805193500.3693-1-simon.k.r.goldschmidt@gmail.com> <20180809190420.28093-1-simon.k.r.goldschmidt@gmail.com> Cc: Stefan Roese , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 5/6] serial: ns16550: fix debug uart putc called before init X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" If _debug_uart_putc() is called before _debug_uart_init(), the ns16550 debug uart driver hangs in a tight loop waiting for the tx FIFO to get empty. As this can happen via a printf sneaking in before the port calls debug_uart_init(), let's rather ignore characters before the debug uart is initialized. This is done by reading the baudrate divisor and aborting if is zero. Tested on socfpga_cyclone5_socrates. Signed-off-by: Simon Goldschmidt Acked-by: Simon Glass --- v2: - this patch is new in v2 of the series. It replaces the printf/debug change in reset_manager_gen5.c from v1 drivers/serial/ns16550.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 9c80090aa7..475075c03c 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -266,12 +266,26 @@ static inline void _debug_uart_init(void) serial_dout(&com_port->lcr, UART_LCRVAL); } +static inline int NS16550_read_baud_divisor(struct NS16550 *com_port) +{ + int ret; + + serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL); + ret = serial_din(&com_port->dll) & 0xff; + ret |= (serial_din(&com_port->dlm) & 0xff) << 8; + serial_dout(&com_port->lcr, UART_LCRVAL); + + return ret; +} + static inline void _debug_uart_putc(int ch) { struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; - while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) - ; + while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) { + if (!NS16550_read_baud_divisor(com_port)) + return; + } serial_dout(&com_port->thr, ch); }