lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180601141158.93817-2-giulio.benetti@micronovasrl.com>
Date:   Fri,  1 Jun 2018 16:11:58 +0200
From:   Giulio Benetti <giulio.benetti@...ronovasrl.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     Jiri Slaby <jslaby@...e.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Kees Cook <keescook@...omium.org>,
        Matthias Brugger <mbrugger@...e.com>,
        Allen Pais <allen.lkml@...il.com>, Sean Young <sean@...s.org>,
        Ed Blake <ed.blake@...drel.com>,
        Stefan Potyra <Stefan.Potyra@...ktrobit.com>,
        Philipp Zabel <p.zabel@...gutronix.de>,
        Joshua Scott <joshua.scott@...iedtelesis.co.nz>,
        Vignesh R <vigneshr@...com>,
        Rolf Evers-Fischer <rolf.evers.fischer@...iv.com>,
        Aaron Sierra <asierra@...-inc.com>,
        Rafael Gago <rafael.gago@...il.com>,
        Joel Stanley <joel@....id.au>,
        Sean Wang <sean.wang@...iatek.com>,
        linux-serial@...r.kernel.org, linux-kernel@...r.kernel.org,
        Giulio Benetti <giulio.benetti@...ronovasrl.com>
Subject: [PATCH 2/2] serial: 8250: Add SERIAL_MCTRL_GPIO support to 8250.

Sometimes mctrl signals can be connected to pins different from HW ones.

User serial_mctrl_gpio helpers to align HW signals(RTS, CTS, etc.) with
gpios-rts, gpios-cts etc.

Signed-off-by: Giulio Benetti <giulio.benetti@...ronovasrl.com>
---
 drivers/tty/serial/8250/8250_core.c |  6 ++++++
 drivers/tty/serial/8250/8250_port.c | 18 +++++++++++++++---
 include/linux/serial_8250.h         |  2 ++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 9342fc2ee7df..c2bc906ffdf4 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -41,6 +41,8 @@
 
 #include "8250.h"
 
+#include "../serial_mctrl_gpio.h"
+
 /*
  * Configuration:
  *   share_irqs - whether we pass IRQF_SHARED to request_irq().  This option
@@ -1036,6 +1038,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
 		if (up->dl_write)
 			uart->dl_write = up->dl_write;
 
+		uart->gpios = mctrl_gpio_init(&up->port, 0);
+		if (IS_ERR(uart->gpios))
+			return PTR_ERR(uart->gpios);
+
 		if (uart->port.type != PORT_8250_CIR) {
 			if (serial8250_isa_config != NULL)
 				serial8250_isa_config(0, &uart->port,
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 95833cbc4338..3004aa3ef4e5 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -40,6 +40,8 @@
 
 #include "8250.h"
 
+#include "../serial_mctrl_gpio.h"
+
 /*
  * These are definitions for the Exar XR17V35X and XR17(C|D)15X
  */
@@ -567,6 +569,8 @@ static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p)
 	else
 		mcr &= ~UART_MCR_RTS;
 	serial8250_out_MCR(p, mcr);
+
+	mctrl_gpio_set(p->gpios, p->port.mctrl);
 }
 
 static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t);
@@ -1591,12 +1595,17 @@ static inline void start_tx_rs485(struct uart_port *port)
 	mcr = serial8250_in_MCR(up);
 	if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) !=
 	    !!(mcr & UART_MCR_RTS)) {
-		if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND)
+		if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) {
 			mcr |= UART_MCR_RTS;
-		else
+			up->port.mctrl |= TIOCM_RTS;
+		} else {
 			mcr &= ~UART_MCR_RTS;
+			up->port.mctrl &= ~TIOCM_RTS;
+		}
 		serial8250_out_MCR(up, mcr);
 
+		mctrl_gpio_set(up->gpios, up->port.mctrl);
+
 		if (up->port.rs485.delay_rts_before_send > 0) {
 			em485->active_timer = &em485->start_tx_timer;
 			start_hrtimer_ms(&em485->start_tx_timer,
@@ -1957,7 +1966,8 @@ unsigned int serial8250_do_get_mctrl(struct uart_port *port)
 		ret |= TIOCM_DSR;
 	if (status & UART_MSR_CTS)
 		ret |= TIOCM_CTS;
-	return ret;
+
+	return mctrl_gpio_get(up->gpios, &ret);
 }
 EXPORT_SYMBOL_GPL(serial8250_do_get_mctrl);
 
@@ -1987,6 +1997,8 @@ void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl)
 	mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
 
 	serial8250_out_MCR(up, mcr);
+
+	mctrl_gpio_set(up->gpios, mctrl);
 }
 EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl);
 
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index a27ef5f56431..7872f11d4b04 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -134,6 +134,8 @@ struct uart_8250_port {
 	void			(*dl_write)(struct uart_8250_port *, int);
 
 	struct uart_8250_em485 *em485;
+
+	struct mctrl_gpios *gpios;
 };
 
 static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
-- 
2.17.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ