From patchwork Thu Feb 7 17:11:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Masson X-Patchwork-Id: 10801581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 660A614E1 for ; Thu, 7 Feb 2019 17:30:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B0552E23E for ; Thu, 7 Feb 2019 17:30:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B76D2E33A; Thu, 7 Feb 2019 17:30:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6DAA62E23E for ; Thu, 7 Feb 2019 17:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1o34QlQKasSdrENqgVPHlhOrqQr69e0vUxI2ndcSy8k=; b=K6ZUbaLXTWEJJ2 /04/8/P46N6gxFM10RhF3TZBtogxvbQ0RaHPlK0BJ3sJBfsTbfyQyBSvV57eRup+RcgZdq4k0uRFK E3XY95mRn+4OxELeEd24W2rdygvLW158ddlyqNQzMjedse4HaR4FUpPweH6c8H5YLpOZYvads3kxX iHk6/apF8WLuH+JeegqbT9zUUQ8Ueeu/NNjzWW/PRFy+EoXBzLFLFPsvhrrN98r/Th2TQrDMy8c96 R0z9Yj3qma+fvSkDfJ3N8PLnunHOJ2Q4Q84wk+qwELKshl9pjeviZBLs1RhbURtvitsKuhvl5BIgu jn9DYZRRei4UoQpPJMcQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1grnVE-0003x4-Mk; Thu, 07 Feb 2019 17:30:20 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1grnVA-0003w7-QX for linux-arm-kernel@lists.infradead.org; Thu, 07 Feb 2019 17:30:19 +0000 Received: by mail-ed1-x542.google.com with SMTP id f9so522429eds.10 for ; Thu, 07 Feb 2019 09:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version; bh=goV4oeui+QjZXGASbWEnmi9tnJ5aRRm3TV6+qGVkZCw=; b=E/G1eVpclGbPqa6wEwR+w2v8D7LjGwl1tAIfNRowttC7eNOQpkPu667FDpDXYrNELx 5QCX2dVTrTZAu3VHSS9v+/14Q4WKrnAktZHQnCYhQ9zBaPPPCYy9otw/JYxe/dwQq2n1 pbNLeVX7sgvao51xy6MK8X5Jz3EWf1YxW0Nju7yEqa7N0LhU7Ji2ExddPoPXbJtKiaIS C3q7393v1NxEk8BRT/i5rsTfe5VLQs5ZGYMBdVXZNCf3FMGV0d2HfSXa5yoMzVsLCtsN fjs2CJXo59KZTAgbsHExzLwyNorAH2U6mcTEhqaxjIWdMbJ4Q+1IISoBjmkkhzDbX3zZ yPEw== 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:mime-version; bh=goV4oeui+QjZXGASbWEnmi9tnJ5aRRm3TV6+qGVkZCw=; b=SQEwtlWSrJZE9mn5a5qcuPEsjzKj6rqbwMmN7rWC/WyUt3SOZvKdcdqMyaHzd3Nsyn og7INIuigcp/MnWMfJe+6PqW0eBci/F53EMWRxgXRPkDBzcJPOCthejocRFcyO4C/VjB cvUcJK28JQSvpJf3Fb1sn3E0NDBc6Tcsjo67a/PtuDrSekUq6CC8eqH/DYPXPW5SjVpG terRDTO1f+aOB18xEy4/goWR7iFEUpH3kytsvRs1QW/LIULPggFtAlCTxz1/DdWGfORp LTG3OptoUBgRSoIZh1JuqMdQZfYYTFFKIq1hn0FtEv5NdkY6Lm7WnS94+36X1xoYTGUl CBpA== X-Gm-Message-State: AHQUAub8mB/nXUaGLIU3PI5FNN/xjo3mMLP2xbq5wCC1LReuBS18bf4Y /JuCQx9soetnrVan1XiJ+8ucMQ== X-Google-Smtp-Source: AHgI3Ia1KW0iSGh1qbZtY6aDlkL1lwFh8uSLrKbWxO0couClL/4F1IkZWaqSpRyPGLODpi3nwn7HSg== X-Received: by 2002:a17:906:12cf:: with SMTP id l15mr7724322ejb.31.1549560614919; Thu, 07 Feb 2019 09:30:14 -0800 (PST) Received: from localhost ([2620:10d:c092:180::1:a0f9]) by smtp.gmail.com with ESMTPSA id w27sm4275214eje.76.2019.02.07.09.30.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Feb 2019 09:30:13 -0800 (PST) From: Julien Masson To: Kevin Hilman , Greg Kroah-Hartman Subject: [PATCH v2] tty: serial: meson_uart: Add support for kernel debugger Date: Thu, 7 Feb 2019 18:11:29 +0100 Message-ID: <86k1ibv74r.fsf@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_093016_873982_92B35608 X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Masson , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Jiri Slaby , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The kgdb invokes the poll_put_char and poll_get_char when communicating with the host. This patch implement the serial polling hooks for the meson_uart to be used for KGDB debugging over serial line. Signed-off-by: Julien Masson --- Changes since v1 [0]: * Use readl_poll_timeout_atomic instead of looping with read + cpu_relax -> read every 5 usecs during 1 msec * add some comments [0]: https://lore.kernel.org/lkml/1549015162-17418-1-git-send-email-jmasson@baylibre.com drivers/tty/serial/meson_uart.c | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index 8a84259..bcff572 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,8 @@ #define AML_UART_PORT_NUM 6 #define AML_UART_DEV_NAME "ttyAML" +#define AML_UART_POLL_USEC 5 +#define AML_UART_TIMEOUT_USEC 1000 static struct uart_driver meson_uart_driver; @@ -426,6 +429,64 @@ static void meson_uart_config_port(struct uart_port *port, int flags) } } +#ifdef CONFIG_CONSOLE_POLL +/* + * Console polling routines for writing and reading from the uart while + * in an interrupt or debug context (i.e. kgdb). + */ + +static int meson_uart_poll_get_char(struct uart_port *port) +{ + u32 c; + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + + if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) + c = NO_POLL_CHAR; + else + c = readl(port->membase + AML_UART_RFIFO); + + spin_unlock_irqrestore(&port->lock, flags); + + return c; +} + +static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) +{ + unsigned long flags; + u32 reg; + int ret; + + spin_lock_irqsave(&port->lock, flags); + + /* Wait until FIFO is empty or timeout */ + ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, + reg & AML_UART_TX_EMPTY, + AML_UART_POLL_USEC, + AML_UART_TIMEOUT_USEC); + if (ret == -ETIMEDOUT) { + dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); + goto out; + } + + /* Write the character */ + writel(c, port->membase + AML_UART_WFIFO); + + /* Wait until FIFO is empty or timeout */ + ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, + reg & AML_UART_TX_EMPTY, + AML_UART_POLL_USEC, + AML_UART_TIMEOUT_USEC); + if (ret == -ETIMEDOUT) + dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); + +out: + spin_unlock_irqrestore(&port->lock, flags); +} + +#endif /* CONFIG_CONSOLE_POLL */ + static const struct uart_ops meson_uart_ops = { .set_mctrl = meson_uart_set_mctrl, .get_mctrl = meson_uart_get_mctrl, @@ -441,6 +502,10 @@ static const struct uart_ops meson_uart_ops = { .request_port = meson_uart_request_port, .release_port = meson_uart_release_port, .verify_port = meson_uart_verify_port, +#ifdef CONFIG_CONSOLE_POLL + .poll_get_char = meson_uart_poll_get_char, + .poll_put_char = meson_uart_poll_put_char, +#endif }; #ifdef CONFIG_SERIAL_MESON_CONSOLE