From patchwork Wed Mar 18 14:26:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 214165 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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 D8118C5ACD6 for ; Wed, 18 Mar 2020 14:27:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B27F120772 for ; Wed, 18 Mar 2020 14:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbgCRO1A (ORCPT ); Wed, 18 Mar 2020 10:27:00 -0400 Received: from gloria.sntech.de ([185.11.138.130]:37356 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbgCRO1A (ORCPT ); Wed, 18 Mar 2020 10:27:00 -0400 Received: from [94.134.91.63] (helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jEZen-0004YX-Ay; Wed, 18 Mar 2020 15:26:53 +0100 From: Heiko Stuebner To: gregkh@linuxfoundation.org Cc: jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, heiko@sntech.de, Giulio Benetti , Heiko Stuebner Subject: [PATCH 1/7] serial: 8250: Make em485_rts_after_send() set mctrl according to rts state. Date: Wed, 18 Mar 2020 15:26:34 +0100 Message-Id: <20200318142640.982763-2-heiko@sntech.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200318142640.982763-1-heiko@sntech.de> References: <20200318142640.982763-1-heiko@sntech.de> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Giulio Benetti When rs485 enabled and RTS_AFTER_SEND set on startup, need to preserve mctrl status, because later functions will call set_mctrl passing port->mctrl=0 overriding rts status, resulting in rts pin in transmission when idle. Make mctrl reflect rts pin state. Signed-off-by: Giulio Benetti Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250_port.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 8407166610ce..67aa3a2a9afa 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -565,10 +565,13 @@ static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p) { unsigned char mcr = serial8250_in_MCR(p); - if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) + if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) { mcr |= UART_MCR_RTS; - else + p->port.mctrl |= TIOCM_RTS; + } else { mcr &= ~UART_MCR_RTS; + p->port.mctrl &= ~TIOCM_RTS; + } serial8250_out_MCR(p, mcr); } From patchwork Wed Mar 18 14:26:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 214164 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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 452B8C5ACD7 for ; Wed, 18 Mar 2020 14:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1CA7520774 for ; Wed, 18 Mar 2020 14:27:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726911AbgCRO1T (ORCPT ); Wed, 18 Mar 2020 10:27:19 -0400 Received: from gloria.sntech.de ([185.11.138.130]:37362 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbgCRO1A (ORCPT ); Wed, 18 Mar 2020 10:27:00 -0400 Received: from [94.134.91.63] (helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jEZeo-0004YX-VA; Wed, 18 Mar 2020 15:26:55 +0100 From: Heiko Stuebner To: gregkh@linuxfoundation.org Cc: jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, heiko@sntech.de, Heiko Stuebner Subject: [PATCH 4/7] serial: 8250: Start rs485 after registering port if rs485 is enabled in probe Date: Wed, 18 Mar 2020 15:26:37 +0100 Message-Id: <20200318142640.982763-5-heiko@sntech.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200318142640.982763-1-heiko@sntech.de> References: <20200318142640.982763-1-heiko@sntech.de> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Heiko Stuebner Before registering a port 8250 drivers may read devicetree information regarding rs485 emulation, but starting the em485 emulation at that point would only keep the em485 structure in the template uart port. Also at that point before the port is registered possible gpios for rts/dtr are not acquired yet as well. So simply check after acquiring the port if the rs485-enable flag is set and start the config callback in that case. Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index e682390ce0de..beab1c22b34d 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -1068,6 +1068,15 @@ int serial8250_register_8250_port(struct uart_8250_port *up) if (up->dl_write) uart->dl_write = up->dl_write; + if (uart->port.rs485_config && + (uart->port.rs485.flags & SER_RS485_ENABLED)) { + dev_dbg(uart->port.dev, "starting in rs485 mode\n"); + ret = uart->port.rs485_config(&uart->port, + &uart->port.rs485); + if (ret < 0) + goto out_unlock; + } + if (uart->port.type != PORT_8250_CIR) { if (serial8250_isa_config != NULL) serial8250_isa_config(0, &uart->port, From patchwork Wed Mar 18 14:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 214167 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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 61EFBC5ACD6 for ; Wed, 18 Mar 2020 14:27:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 317D720772 for ; Wed, 18 Mar 2020 14:27:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726973AbgCRO1F (ORCPT ); Wed, 18 Mar 2020 10:27:05 -0400 Received: from gloria.sntech.de ([185.11.138.130]:37372 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbgCRO1C (ORCPT ); Wed, 18 Mar 2020 10:27:02 -0400 Received: from [94.134.91.63] (helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jEZep-0004YX-P7; Wed, 18 Mar 2020 15:26:55 +0100 From: Heiko Stuebner To: gregkh@linuxfoundation.org Cc: jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, heiko@sntech.de, Giulio Benetti , Heiko Stuebner Subject: [PATCH 6/7] serial: 8250_dw: add em485 support Date: Wed, 18 Mar 2020 15:26:39 +0100 Message-Id: <20200318142640.982763-7-heiko@sntech.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200318142640.982763-1-heiko@sntech.de> References: <20200318142640.982763-1-heiko@sntech.de> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Giulio Benetti Need to use rs485 transceiver so let's use existing em485 485 emulation layer on top of 8250. Add rs485_config callback to port. Signed-off-by: Giulio Benetti Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250_dw.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 1c72fdc2dd37..7023b656658d 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -320,6 +320,36 @@ static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios) serial8250_do_set_ldisc(p, termios); } +static int dw8250_rs485_config(struct uart_port *p, + struct serial_rs485 *rs485) +{ + struct uart_8250_port *up = up_to_u8250p(p); + + /* Clamp the delays to [0, 100ms] */ + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); + + p->rs485 = *rs485; + + /* + * Both serial8250_em485_init and serial8250_em485_destroy + * are idempotent + */ + if (rs485->flags & SER_RS485_ENABLED) { + int ret = serial8250_em485_init(up, false); + + if (ret) { + rs485->flags &= ~SER_RS485_ENABLED; + p->rs485.flags &= ~SER_RS485_ENABLED; + } + return ret; + } + + serial8250_em485_destroy(up); + + return 0; +} + /* * dw8250_fallback_dma_filter will prevent the UART from getting just any free * channel on platforms that have DMA engines, but don't have any channels @@ -417,6 +447,7 @@ static int dw8250_probe(struct platform_device *pdev) p->serial_out = dw8250_serial_out; p->set_ldisc = dw8250_set_ldisc; p->set_termios = dw8250_set_termios; + p->rs485_config = dw8250_rs485_config; p->membase = devm_ioremap(dev, regs->start, resource_size(regs)); if (!p->membase)