From patchwork Tue Jan 12 20:55:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Ciocaltea X-Patchwork-Id: 12014807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE5B4C433DB for ; Tue, 12 Jan 2021 20:57:23 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E86C2311A for ; Tue, 12 Jan 2021 20:57:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E86C2311A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=XL/ee81+cTag40h6d7kHvRhtDn5JmsdYmBovmvGWpvM=; b=sC+h0OFqcBT+6KHk7BwLLfAuV+ hDxmIR/FFZfJN8yoSqmJUQEwnFH1zmX0Wum+0diXXl74D6Wqua57BawNz31lgP0nMGiRKJcqPj03D 7lO/5LJYzBrrB5vAcQqZrv36KXqKFK63OgtMsOKnKhFghYJhLYK5nr0435CM1iVSa1NUu8AgrUEUN SzMNGGeYVSP3K/nYOOtaeqc2syC2hRJTAdbDNnt02q6rZrlJ7FSL6bLx3nAVCgBcrykzAyM+n8k8K n1HKfI5PfH90iPAo3v2NrfsDM4FSukBvrntg7YuHXQeIB44Nw204MrC56OCyJXgpI02OIv+hc+iUR Ghw+6lgA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzQhe-0007L4-CR; Tue, 12 Jan 2021 20:55:46 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzQhb-0007JU-2K; Tue, 12 Jan 2021 20:55:44 +0000 Received: by mail-ej1-x632.google.com with SMTP id 6so5461184ejz.5; Tue, 12 Jan 2021 12:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mB4awCptdOD4XxS2R3y9RjPkKqrjcCd8XVKkJUf17lY=; b=EXEloGtCq2Y1xv2n/lKx4y+IKjFMhuasWC47llqnFU3lg9F+ErefoQzMzs4QWaGb1I sSJLXccTNlo514WRLeswXNX0/Pv5Tzd5cWnuQapOZgbbNlBVAV7yTxtcdSDz6AL+78tc ndvNtdhcK7lQsyosQ/m2Jl+QTAdBbZ0xkRSJBBRxEEhxHkwocTWNcPKm/tgkwOeuK2y0 jPhEWe8YX8gEn9hMRYhZ71fsnGOni0VWoVZGVd+Q/DrJYwuoh0q/d59c+Hbt2oASCWfn AABzI+gMYxMc/G8WJ5EB++xOmDY9qkWynY425QYj1nuKYOdBvfEQ4aBChJ/EJEtJZg+j aY/g== 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 :content-transfer-encoding; bh=mB4awCptdOD4XxS2R3y9RjPkKqrjcCd8XVKkJUf17lY=; b=mWBOOuMPprNFzqbg+n0bqo2gbp8VqIHgWa0ZD8Lr8+YHt4qk8/NdBVE7rxFdTIthCR YiaWZYxeGfzkcfDd028xqJGGMLt0oyChsPkllbJFf9SXkgHNb3N433UHJ6oa2VIokfN5 plByvYJqReaNfuV+GuJE348VScdDhvLNhK0/WUTMrFT9PMYgNyZkmZSRrotbvWO2Qjr4 aIFkTuv1i7jM8DsHTiRA4dzF+tmArki2YofjAGgE6Hix7Z7ptAJxM3QrU4qcfBLXx8GA SMl4piC66qd31WbhUMmwjHhyWfF7RC5slyRXMTjwG5K6wCgTPAkl9x2ecxet95ejR5Ny 1S2g== X-Gm-Message-State: AOAM5322r4LpFtlxI5NKVZ6FFWLPFXvYNq5Laukg2LJj3OZhX3MTGWPt bmH/s5z3phLVhou9iUS2NmA= X-Google-Smtp-Source: ABdhPJzwm/B8mmx3+HAGXVJ6HOwVSe5dwtB1AqDsh46+Tlxnnni5L0R7Nfumpd9EybxYCubE4esVsw== X-Received: by 2002:a17:906:7804:: with SMTP id u4mr467339ejm.97.1610484940921; Tue, 12 Jan 2021 12:55:40 -0800 (PST) Received: from localhost.localdomain ([188.24.159.61]) by smtp.gmail.com with ESMTPSA id p3sm1641423ejx.0.2021.01.12.12.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 12:55:40 -0800 (PST) From: Cristian Ciocaltea To: Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Andreas_F=C3=A4rber?= , Manivannan Sadhasivam Subject: [PATCH v3 1/1] tty: serial: owl: Add support for kernel debugger Date: Tue, 12 Jan 2021 22:55:38 +0200 Message-Id: <026543195b9aeefb339d90abc5660a6ac7463c63.1610484108.git.cristian.ciocaltea@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210112_155543_151208_B20F0829 X-CRM114-Status: GOOD ( 18.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-actions@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Implement 'poll_put_char' and 'poll_get_char' callbacks in struct 'owl_uart_ops' that enables OWL UART to be used for kernel debugging over serial line. Signed-off-by: Cristian Ciocaltea --- Changes in v3: - Used 'readl_poll_timeout_atomic()' in 'owl_uart_poll_put_char()' to get rid of 'cpu_relax()' and provide a max bound to the loop, as indicated by Greg and Jiri Changes in v2: - Reverted unnecessary changes per Andreas feedback - Optimized implementation for 'owl_uart_poll_get_char()' and 'owl_uart_poll_put_char()' callbacks drivers/tty/serial/owl-uart.c | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c index c149f8c30007..abc6042f0378 100644 --- a/drivers/tty/serial/owl-uart.c +++ b/drivers/tty/serial/owl-uart.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,9 @@ #define OWL_UART_STAT_TRFL_MASK GENMASK(16, 11) #define OWL_UART_STAT_UTBB BIT(17) +#define OWL_UART_POLL_USEC 5 +#define OWL_UART_TIMEOUT_USEC 10000 + static struct uart_driver owl_uart_driver; struct owl_uart_info { @@ -461,6 +465,36 @@ static void owl_uart_config_port(struct uart_port *port, int flags) } } +#ifdef CONFIG_CONSOLE_POLL + +static int owl_uart_poll_get_char(struct uart_port *port) +{ + if (owl_uart_read(port, OWL_UART_STAT) & OWL_UART_STAT_RFEM) + return NO_POLL_CHAR; + + return owl_uart_read(port, OWL_UART_RXDAT); +} + +static void owl_uart_poll_put_char(struct uart_port *port, unsigned char ch) +{ + u32 reg; + int ret; + + /* Wait while FIFO is full or timeout */ + ret = readl_poll_timeout_atomic(port->membase + OWL_UART_STAT, reg, + !(reg & OWL_UART_STAT_TFFU), + OWL_UART_POLL_USEC, + OWL_UART_TIMEOUT_USEC); + if (ret == -ETIMEDOUT) { + dev_err(port->dev, "Timeout waiting while UART TX FULL\n"); + return; + } + + owl_uart_write(port, ch, OWL_UART_TXDAT); +} + +#endif /* CONFIG_CONSOLE_POLL */ + static const struct uart_ops owl_uart_ops = { .set_mctrl = owl_uart_set_mctrl, .get_mctrl = owl_uart_get_mctrl, @@ -476,6 +510,10 @@ static const struct uart_ops owl_uart_ops = { .request_port = owl_uart_request_port, .release_port = owl_uart_release_port, .verify_port = owl_uart_verify_port, +#ifdef CONFIG_CONSOLE_POLL + .poll_get_char = owl_uart_poll_get_char, + .poll_put_char = owl_uart_poll_put_char, +#endif }; #ifdef CONFIG_SERIAL_OWL_CONSOLE