From patchwork Sun Mar 8 16:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 11425747 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E206E139A for ; Sun, 8 Mar 2020 16:34:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C029120828 for ; Sun, 8 Mar 2020 16:34:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FqHmr56+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C029120828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:References:In-Reply-To: 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: List-Owner; bh=G3UCdn1IGfR4/xpUse5QVROmn2K7en9YdNnoUWDBkGM=; b=FqHmr56+xvDFKA w4Baswst8TL83qMzyyuk8rRApB5k/g6DGYs1Qs0AAubx7932S16Ajb9Vn7VItYYZ2uj6KyjNzALYj AnY32rUMoxtZ9HUzFffxgeaLNmjarTvMfDLI3XikVUKwM/prdRK0Ig/rYEyQxLF5PrIQDKzZj2ZVf qAwvXOP1/AFqGOP07cvFqcQiY/WAP++5y3Sm8j020RBDlXrLb6wx18DkHJMsCUeCAycaoBmHYkSVK 33xoRb7SzHdjpPJOh0SXJR6UX7yACYf/YoPuobmDzSBsG8U8JDMiziqI6+rg9PEumchQ6UTNjhH1/ S7UBTLZJeQunEBVpn6Ig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jAysp-00029P-Fh; Sun, 08 Mar 2020 16:34:31 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jAyrI-0000f4-5p for linux-arm-kernel@lists.infradead.org; Sun, 08 Mar 2020 16:32:59 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 32982B1A2; Sun, 8 Mar 2020 16:32:48 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: linux-arm-kernel@lists.infradead.org Subject: [RFC 06/11] tty: serial: Add Sunplus Plus1 UART earlycon Date: Sun, 8 Mar 2020 17:32:24 +0100 Message-Id: <20200308163230.4002-7-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200308163230.4002-1-afaerber@suse.de> References: <20200308163230.4002-1-afaerber@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200308_093256_557834_4148B1B8 X-CRM114-Status: GOOD ( 16.08 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.135.220.15 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [195.135.220.15 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: =?utf-8?b?V2VsbHMgTHUg5ZGC6Iqz6aiw?= , Greg Kroah-Hartman , Dvorkin Dmitry , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Jiri Slaby , =?utf-8?q?Andre?= =?utf-8?q?as_F=C3=A4rber?= Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Prepare an earlycon driver for Sunplus Plus1 SP7021 SoC. Based on BPI-F2S-bsp tree. Signed-off-by: Andreas Färber --- drivers/tty/serial/Kconfig | 19 +++++++++ drivers/tty/serial/Makefile | 1 + drivers/tty/serial/sunplus-uart.c | 90 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 drivers/tty/serial/sunplus-uart.c diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 880b96201530..ac6dce75c2f3 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -1562,6 +1562,25 @@ config SERIAL_MILBEAUT_USIO_CONSOLE receives all kernel messages and warnings and which allows logins in single user mode). +config SERIAL_PLUS1 + bool "Sunplus Plus1 serial port support" + depends on ARCH_SUNPLUS || COMPILE_TEST + select SERIAL_CORE + help + This driver is for Sunplus Plus1 SP7021 SoC's UART. + Say 'Y' here if you wish to use the on-board serial port. + Otherwise, say 'N'. + +config SERIAL_PLUS1_CONSOLE + bool "Console on Sunplus Plus1 serial port" + depends on SERIAL_PLUS1=y + select SERIAL_CORE_CONSOLE + select SERIAL_EARLYCON + default y + help + Say 'Y' here if you wish to use Sunplus SP7021 UART + as the system console. Only earlycon is implemented currently. + endmenu config SERIAL_MCTRL_GPIO diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile index d056ee6cca33..fed40fb19ed0 100644 --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile @@ -89,6 +89,7 @@ obj-$(CONFIG_SERIAL_OWL) += owl-uart.o obj-$(CONFIG_SERIAL_RDA) += rda-uart.o obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o +obj-$(CONFIG_SERIAL_PLUS1) += sunplus-uart.o # GPIOLIB helpers for modem control lines obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o diff --git a/drivers/tty/serial/sunplus-uart.c b/drivers/tty/serial/sunplus-uart.c new file mode 100644 index 000000000000..959dfab5e07b --- /dev/null +++ b/drivers/tty/serial/sunplus-uart.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Andreas Färber + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_DATA 0x00 +#define REG_LSR 0x04 + +#define PLUS1_UART_LSR_TX BIT(0) + +static inline void plus1_uart_write(struct uart_port *port, unsigned int off, u32 val) +{ + writel_relaxed(val, port->membase + off); +} + +static inline u32 plus1_uart_read(struct uart_port *port, unsigned int off) +{ + return readl_relaxed(port->membase + off); +} + +#ifdef CONFIG_SERIAL_PLUS1_CONSOLE + +static void plus1_console_putchar(struct uart_port *port, int ch) +{ + if (!port->membase) + return; + + while (!(plus1_uart_read(port, REG_LSR) & PLUS1_UART_LSR_TX)) + cpu_relax(); + + plus1_uart_write(port, REG_DATA, ch); +} + +static void plus1_uart_port_write(struct uart_port *port, const char *s, + u_int count) +{ + unsigned long flags; + int locked; + + local_irq_save(flags); + + if (port->sysrq) + locked = 0; + else if (oops_in_progress) + locked = spin_trylock(&port->lock); + else { + spin_lock(&port->lock); + locked = 1; + } + + uart_console_write(port, s, count, plus1_console_putchar); + + if (locked) + spin_unlock(&port->lock); + + local_irq_restore(flags); +} + +static void plus1_uart_early_console_write(struct console *co, + const char *s, + u_int count) +{ + struct earlycon_device *dev = co->data; + + plus1_uart_port_write(&dev->port, s, count); +} + +static int __init +plus1_uart_early_console_setup(struct earlycon_device *device, const char *opt) +{ + if (!device->port.membase) + return -ENODEV; + + device->con->write = plus1_uart_early_console_write; + + return 0; +} +OF_EARLYCON_DECLARE(sunplus, "sunplus,sp7021-uart", + plus1_uart_early_console_setup); + +#endif