From patchwork Tue Aug 1 12:52:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 9874525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E712260365 for ; Tue, 1 Aug 2017 12:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA3F727F91 for ; Tue, 1 Aug 2017 12:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D91692844B; Tue, 1 Aug 2017 12:53:43 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 5FFB8283DA for ; Tue, 1 Aug 2017 12:53:42 +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:Subject:To:From :Date: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=fRdIvarJvVfaus3YuX+HOb7kw4jJtTO6FxC1rX/GCqA=; b=bPI+8s6FkAhEk3 p8wEP77vXs5C/CAJIxq56bjr9skd4LfC32+IBw6I6o8nbuOE1wQMbwecrGJyRVvnQ8U562B9sOX5s D0xKvTyX5S06oqYIWo/x5MiI342GWr53iwW6MpJ4Yz4/FOgpTWs2UcT5Eg4SZ7Jopisd9pW/LhRmI Ra1kYkZ01H8JaCGkmQEiL2pF3c3XTtgpbEnsPOwEjhZxJTER5Xm+SkBfkyr2zU4uV9U2V5vPoFnnc slaGvhwqEC5wL5qv12+vBVfrr4aHeLBq1Y1o9UXZ8tYCXsBIe6bVdmvGK/E9r2XQ9LS3FK3a1IY8R vkbrPXo/h6hEyOwlvgqw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dcWfn-0004u3-Lo; Tue, 01 Aug 2017 12:53:19 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dcWfe-0004qM-G0 for linux-arm-kernel@lists.infradead.org; Tue, 01 Aug 2017 12:53:17 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23994249AbdHAMwpv-nmy (ORCPT ); Tue, 1 Aug 2017 14:52:45 +0200 Date: Tue, 1 Aug 2017 14:52:44 +0200 From: Ladislav Michl To: linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org Subject: [PATCH] serial: amba-pl011: Add basic rs485 support Message-ID: <20170801125244.cmeycp5ujp2lmmwr@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170801_055310_852350_6FBCD253 X-CRM114-Status: GOOD ( 10.50 ) 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: Russell King 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 Currently RS485 mode can be selected only via DT bindings. Signed-off-by: Ladislav Michl --- Notes: this change was sitting in my tree for a year and now with "serial: Add common rs485 device tree parsing function" et al. patches being submitted is time to move forward a bit. Although rpi with this patched driver is working for months I do not like mdelay in interrupt while waiting for last bit to leave tx wire. If anyone has better idea, I'll happily implement it. Thank you. drivers/tty/serial/amba-pl011.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 8a857bb34fbb..44016840f5df 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1319,9 +1319,22 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) static void pl011_stop_tx(struct uart_port *port) { + unsigned int cr; struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); + /* Handle RS-485 */ + if (port->rs485.flags & SER_RS485_ENABLED) { + while (readl(port->membase + UART01x_FR) & UART01x_FR_BUSY) + mdelay(1); + cr = readw(uap->port.membase + UART011_CR); + if (port->rs485.flags & SER_RS485_RTS_ON_SEND) + cr &= ~UART011_CR_RTS; + else + cr |= UART011_CR_RTS; + writew(cr, uap->port.membase + UART011_CR); + } + uap->im &= ~UART011_TXIM; pl011_write(uap->im, uap, REG_IMSC); pl011_dma_tx_stop(uap); @@ -1340,9 +1353,20 @@ static void pl011_start_tx_pio(struct uart_amba_port *uap) static void pl011_start_tx(struct uart_port *port) { + unsigned int cr; struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); + /* Handle RS-485 */ + if (port->rs485.flags & SER_RS485_ENABLED) { + cr = readw(uap->port.membase + UART011_CR); + if (port->rs485.flags & SER_RS485_RTS_ON_SEND) + cr |= UART011_CR_RTS; + else + cr &= ~UART011_CR_RTS; + writew(cr, uap->port.membase + UART011_CR); + } + if (!pl011_dma_tx_start(uap)) pl011_start_tx_pio(uap); } @@ -2588,6 +2612,7 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap, return PTR_ERR(base); index = pl011_probe_dt_alias(index, dev); + of_get_rs485_mode(dev->of_node, &uap->port.rs485); uap->old_cr = 0; uap->port.dev = dev;