From: Sergiu Moga <sergiu.moga@microchip.com> To: <richard.genoud@gmail.com>, <gregkh@linuxfoundation.org>, <jirislaby@kernel.org>, <nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>, <claudiu.beznea@microchip.com>, <rmk+kernel@arm.linux.org.uk>, <claudio@evidence.eu.com>, <rick@efn.org>, <ryan@bluewatersys.com> Cc: <linux-serial@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <ilpo.jarvinen@linux.intel.com>, Sergiu Moga <sergiu.moga@microchip.com> Subject: [PATCH v2] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Date: Wed, 24 Aug 2022 17:29:03 +0300 [thread overview] Message-ID: <20220824142902.502596-1-sergiu.moga@microchip.com> (raw) Whenever the atmel_rs485_config() driver method would be called, the USART mode is reset to normal mode before even checking if RS485 flag is set, thus resulting in losing the previous USART mode in the case where the checking fails. Some tools, such as `linux-serial-test`, lead to the driver calling this method when doing the setup of the serial port: after setting the port mode (Hardware Flow Control, Normal Mode, RS485 Mode, etc.), `linux-serial-test` tries to enable/disable RS485 depending on the commandline arguments that were passed. Example of how this issue could reveal itself: When doing a serial communication with Hardware Flow Control through `linux-serial-test`, the tool would lead to the driver roughly doing the following: - set the corresponding bit to 1 (ATMEL_US_USMODE_HWHS bit in the ATMEL_US_MR register) through the atmel_set_termios() to enable Hardware Flow Control - disable RS485 through the atmel_config_rs485() method Thus, when the latter is called, the mode will be reset and the previously set bit is unset, leaving USART in normal mode instead of the expected Hardware Flow Control mode. This fix ensures that this reset is only done if the checking for RS485 succeeds and that the previous mode is preserved otherwise. Fixes: e8faff7330a35 ("ARM: 6092/1: atmel_serial: support for RS485 communications") Signed-off-by: Sergiu Moga <sergiu.moga@microchip.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> --- v1 -> v2: - split commit message to slightly shorter bits such that it would be easier to read - add Reviewed-by tag drivers/tty/serial/atmel_serial.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 0a0b46ee0955..c29b1fb48694 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -298,9 +298,6 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, mode = atmel_uart_readl(port, ATMEL_US_MR); - /* Resetting serial mode to RS232 (0x0) */ - mode &= ~ATMEL_US_USMODE; - if (rs485conf->flags & SER_RS485_ENABLED) { dev_dbg(port->dev, "Setting UART to RS485\n"); if (rs485conf->flags & SER_RS485_RX_DURING_TX) @@ -310,6 +307,7 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, atmel_uart_writel(port, ATMEL_US_TTGR, rs485conf->delay_rts_after_send); + mode &= ~ATMEL_US_USMODE; mode |= ATMEL_US_USMODE_RS485; } else { dev_dbg(port->dev, "Setting UART to RS232\n"); -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Sergiu Moga <sergiu.moga@microchip.com> To: <richard.genoud@gmail.com>, <gregkh@linuxfoundation.org>, <jirislaby@kernel.org>, <nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>, <claudiu.beznea@microchip.com>, <rmk+kernel@arm.linux.org.uk>, <claudio@evidence.eu.com>, <rick@efn.org>, <ryan@bluewatersys.com> Cc: <linux-serial@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <ilpo.jarvinen@linux.intel.com>, Sergiu Moga <sergiu.moga@microchip.com> Subject: [PATCH v2] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Date: Wed, 24 Aug 2022 17:29:03 +0300 [thread overview] Message-ID: <20220824142902.502596-1-sergiu.moga@microchip.com> (raw) Whenever the atmel_rs485_config() driver method would be called, the USART mode is reset to normal mode before even checking if RS485 flag is set, thus resulting in losing the previous USART mode in the case where the checking fails. Some tools, such as `linux-serial-test`, lead to the driver calling this method when doing the setup of the serial port: after setting the port mode (Hardware Flow Control, Normal Mode, RS485 Mode, etc.), `linux-serial-test` tries to enable/disable RS485 depending on the commandline arguments that were passed. Example of how this issue could reveal itself: When doing a serial communication with Hardware Flow Control through `linux-serial-test`, the tool would lead to the driver roughly doing the following: - set the corresponding bit to 1 (ATMEL_US_USMODE_HWHS bit in the ATMEL_US_MR register) through the atmel_set_termios() to enable Hardware Flow Control - disable RS485 through the atmel_config_rs485() method Thus, when the latter is called, the mode will be reset and the previously set bit is unset, leaving USART in normal mode instead of the expected Hardware Flow Control mode. This fix ensures that this reset is only done if the checking for RS485 succeeds and that the previous mode is preserved otherwise. Fixes: e8faff7330a35 ("ARM: 6092/1: atmel_serial: support for RS485 communications") Signed-off-by: Sergiu Moga <sergiu.moga@microchip.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> --- v1 -> v2: - split commit message to slightly shorter bits such that it would be easier to read - add Reviewed-by tag drivers/tty/serial/atmel_serial.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 0a0b46ee0955..c29b1fb48694 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -298,9 +298,6 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, mode = atmel_uart_readl(port, ATMEL_US_MR); - /* Resetting serial mode to RS232 (0x0) */ - mode &= ~ATMEL_US_USMODE; - if (rs485conf->flags & SER_RS485_ENABLED) { dev_dbg(port->dev, "Setting UART to RS485\n"); if (rs485conf->flags & SER_RS485_RX_DURING_TX) @@ -310,6 +307,7 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, atmel_uart_writel(port, ATMEL_US_TTGR, rs485conf->delay_rts_after_send); + mode &= ~ATMEL_US_USMODE; mode |= ATMEL_US_USMODE_RS485; } else { dev_dbg(port->dev, "Setting UART to RS232\n"); -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2022-08-24 14:29 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-24 14:29 Sergiu Moga [this message] 2022-08-24 14:29 ` [PATCH v2] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Sergiu Moga
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220824142902.502596-1-sergiu.moga@microchip.com \ --to=sergiu.moga@microchip.com \ --cc=alexandre.belloni@bootlin.com \ --cc=claudio@evidence.eu.com \ --cc=claudiu.beznea@microchip.com \ --cc=gregkh@linuxfoundation.org \ --cc=ilpo.jarvinen@linux.intel.com \ --cc=jirislaby@kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-serial@vger.kernel.org \ --cc=nicolas.ferre@microchip.com \ --cc=richard.genoud@gmail.com \ --cc=rick@efn.org \ --cc=rmk+kernel@arm.linux.org.uk \ --cc=ryan@bluewatersys.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.