Bugfix RTS line config in RS485 mode is overwritten in pl011_set_mctrl() function.
PATCH 1/1 Bugfix RTS line config in RS485 mode is overwritten in pl011_set_mctrl() function.
Based on the "0001-serial-amba-pl011-add-RS485-support.patch" this change is necesarry otherwise the RTS-line will be pulled up in SER_RS485_RTS_BEFORE_SEND mode before sending data. This hinders the driver to receive data, f.ex. when the device is an RS485 slave device.
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tty/serial/amba-pl011.c +6 -2
@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + } cr =pl011_read (uap,REG_CR );
Signature · 1 line
2.20.1
Quoted 3 lines · jmades
Based on the "0001-serial-amba-pl011-add-RS485-support.patch" this change is necesarry otherwise the RTS-line will be pulled up in
SER_RS485_RTS_BEFORE_SENDmode before sending data. This hinders the driver to receive data, f.ex. when the device is an RS485 slave device.Signed-off-by jmades <[email protected]>
Patch is correct, but commit message could be improved:
* Subject should be in imperative mood (by convention), it should be prepended by "serial: pl011: " (in line with previous commits touching this driver, use "git log --oneline amba-pl011.c") and the trailing dot is unnecessary, e.g.:
"serial: pl011: Fix incorrect rs485 RTS polarity on set_mctrl"
* Commit message should be wrapped at 72 characters (so that it appears centered when displayed with "git log" on an 80 chars terminal). The reference to "0001-serial-amba-pl011-add-RS485-support.patch" should be replaced with a reference to the offending commit, e.g.:
"Commit 8d479237727c ("serial: amba-pl011: add RS485 support") sought to keep RTS deasserted on set_mctrl if rs485 is enabled. However it did so only if deasserted RTS polarity is high. Fix it in case it's low."
Feel free to copy this to a v2 of your patch and amend as you see fit.
* Add tags for the offending commit:
* Be sure to cc the author of the offending commit.
Thanks,
Lukas
Quoted 22 lines
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + } cr =pl011_read (uap,REG_CR );
Hi,
Quoted 58 lines · Lukas Wunner
Quoted 3 lines · jmades
Based on the "0001-serial-amba-pl011-add-RS485-support.patch" this change is necesarry otherwise the RTS-line will be pulled up in
SER_RS485_RTS_BEFORE_SENDmode before sending data. This hinders the driver to receive data, f.ex. when the device is an RS485 slave device.Signed-off-by jmades <[email protected]>Patch is correct, but commit message could be improved:
* Subject should be in imperative mood (by convention), it should be prepended by "serial: pl011: " (in line with previous commits touching this driver, use "git log --oneline
amba-pl011.c") and the trailing dot is unnecessary, e.g.:"serial: pl011: Fix incorrect rs485 RTS polarity on
set_mctrl"* Commit message should be wrapped at 72 characters (so that it appears centered when displayed with "git log" on an 80 chars terminal). The reference to "0001-serial-amba-pl011-add-RS485-support.patch" should be replaced with a reference to the offending commit, e.g.:
"Commit
8d479237727c("serial: amba-pl011: add RS485 support") sought to keep RTS deasserted onset_mctrlif rs485 is enabled. However it did so only if deasserted RTS polarity is high. Fix it in case it's low."Feel free to copy this to a v2 of your patch and amend as you see fit.
* Add tags for the offending commit:
Fixes 8d479237727c ("serial: amba-pl011: add RS485 support")Cc [email protected] # v5.15+* Be sure to cc the author of the offending commit.
Thanks,
Lukas
Quoted 21 lines
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );
Does this logic really have to be implemented in the driver? It looks as if the serial core already takes RS485 into account before calling set_mctrls(). At least I get the impression when looking at uart_tiocmset() and uart_port_dtr_rts(). Also other drivers like imx simply seem to ignore RTS in case of RS485.
Regards,
Lino
Quoted 17 lines · Lino Sanfilippo
Quoted 16 lines · Lukas Wunner
Quoted 15 lines · jmades
drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }
Quoted 3 lines
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );Does this logic really have to be implemented in the driver?
No, it doesn't have to be and indeed I'm working towards consolidating it in the serial core with this collection of patches:
https://git.kernel.org/gregkh/tty/c/d3b3404df318
https://lore.kernel.org/all/f49f945375f5ccb979893c49f1129f51651ac738.1641129062.git.lukas@wunner.de
https://lore.kernel.org/all/e22089ab49e6e78822c50c8c4db46bf3ee885623.1641129328.git.lukas@wunner.de
https://lore.kernel.org/all/bceeaba030b028ed810272d55d5fc6f3656ddddb.1641129752.git.lukas@wunner.de
https://github.com/l1k/linux/commit/532ef2ad757f
The last of these removes the rs485 logic from pl011_set_mctrl(). I'll post it once the others (and Jochen Mades' patch) have landed.
Even though the logic is eventually removed from pl011_set_mctrl(), Jochen's patch makes sense as a backportable fix for v5.15.
Quoted 4 lines
It looks as if the serial core already takes RS485 into account before calling
set_mctrls(). At least I get the impression when looking atuart_tiocmset()anduart_port_dtr_rts(). Also other drivers like imx simply seem to ignore RTS in case of RS485.
The logic in uart_port_dtr_rts() is broken. That's fixed by d3b3404df318, which is queued up in tty-next for v5.17.
The pl011 driver papered over it with its own rs485-specific logic in pl011_set_mctrl(). But as Jochen Mades correctly pointed out, that only worked correctly if RTS is driven high on idle.
The logic in uart_tiocmset() is correct, but not sufficient because uart_throttle(), uart_unthrottle and uart_set_termios() need to become rs485-aware as well. That's also addressed by the above-linked GitHub commit.
Thanks,
Lukas
Quoted 51 lines · Lukas Wunner
Quoted 17 lines · Lino Sanfilippo
Quoted 16 lines · Lukas Wunner
Quoted 15 lines · jmades
drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }Quoted 3 lines
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );Does this logic really have to be implemented in the driver?
No, it doesn't have to be and indeed I'm working towards consolidating it in the serial core with this collection of patches:
https://git.kernel.org/gregkh/tty/c/d3b3404df318
https://lore.kernel.org/all/f49f945375f5ccb979893c49f1129f51651ac738.1641129062.git.lukas@wunner.de
https://lore.kernel.org/all/e22089ab49e6e78822c50c8c4db46bf3ee885623.1641129328.git.lukas@wunner.de
https://lore.kernel.org/all/bceeaba030b028ed810272d55d5fc6f3656ddddb.1641129752.git.lukas@wunner.de
https://github.com/l1k/linux/commit/532ef2ad757fThe last of these removes the rs485 logic from
pl011_set_mctrl(). I'll post it once the others (and Jochen Mades' patch) have landed.Even though the logic is eventually removed from
pl011_set_mctrl(), Jochen's patch makes sense as a backportable fix for v5.15.Quoted 4 lines
It looks as if the serial core already takes RS485 into account before calling
set_mctrls(). At least I get the impression when looking atuart_tiocmset()anduart_port_dtr_rts(). Also other drivers like imx simply seem to ignore RTS in case of RS485.The logic in
uart_port_dtr_rts()is broken. That's fixed byd3b3404df318, which is queued up in tty-next for v5.17.The pl011 driver papered over it with its own rs485-specific logic in
pl011_set_mctrl(). But as Jochen Mades correctly pointed out, that only worked correctly if RTS is driven high on idle.
Quoted 5 lines
The logic in
uart_tiocmset()is correct, but not sufficient becauseuart_throttle(),uart_unthrottleanduart_set_termios()need to become rs485-aware as well. That's also addressed by the above-linked GitHub commit.
Thanks for this information. I have one or two patches prepared a while ago that aim into a similar direction (move RS485 related code out of the drivers into the serial core). I will send them in the next days.
Best regards,
Lino
Hi Lukas, Lino,
please let me know when I could test again with an "official" linux kernel, instead of using my local patch.
Bests
Jochen
Quoted 62 lines · On 02/01/2022 19:28 Lukas Wunner <[email protected]> wrote:
Quoted 17 lines · Lino Sanfilippo
Quoted 16 lines · Lukas Wunner
Quoted 15 lines · jmades
drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }Quoted 3 lines
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );Does this logic really have to be implemented in the driver?
No, it doesn't have to be and indeed I'm working towards consolidating it in the serial core with this collection of patches:
https://git.kernel.org/gregkh/tty/c/d3b3404df318
https://lore.kernel.org/all/f49f945375f5ccb979893c49f1129f51651ac738.1641129062.git.lukas@wunner.de
https://lore.kernel.org/all/e22089ab49e6e78822c50c8c4db46bf3ee885623.1641129328.git.lukas@wunner.de
https://lore.kernel.org/all/bceeaba030b028ed810272d55d5fc6f3656ddddb.1641129752.git.lukas@wunner.de
https://github.com/l1k/linux/commit/532ef2ad757fThe last of these removes the rs485 logic from
pl011_set_mctrl(). I'll post it once the others (and Jochen Mades' patch) have landed.Even though the logic is eventually removed from
pl011_set_mctrl(), Jochen's patch makes sense as a backportable fix for v5.15.Quoted 4 lines
It looks as if the serial core already takes RS485 into account before calling
set_mctrls(). At least I get the impression when looking atuart_tiocmset()anduart_port_dtr_rts(). Also other drivers like imx simply seem to ignore RTS in case of RS485.The logic in
uart_port_dtr_rts()is broken. That's fixed byd3b3404df318, which is queued up in tty-next for v5.17.The pl011 driver papered over it with its own rs485-specific logic in
pl011_set_mctrl(). But as Jochen Mades correctly pointed out, that only worked correctly if RTS is driven high on idle.The logic in
uart_tiocmset()is correct, but not sufficient becauseuart_throttle(),uart_unthrottleanduart_set_termios()need to become rs485-aware as well. That's also addressed by the above-linked GitHub commit.Thanks,
Lukas
Hi Jochen,
Quoted 6 lines · Jochen Mades
Hi Lukas, Lino,
please let me know when I could test again with an "official" linux kernel, instead of using my local patch.
Bests
Jochen
While the fix itself looks good so far there are still some style issue as Lukas pointed out. These issues have to be fixed before the patch can be accepted for mainline integration. Please have a look at Documentation/process/submitting-patches.rst for the correct patch format. After these issues are fixed please send the patch as a v2, so we can review the new version.
Best regards,
Lino
Hi Lukas,
Quoted 14 lines
Patch is correct, but commit message could be improved:
* Subject should be in imperative mood (by convention), it should be prepended by "serial: pl011: " (in line with previous commits touching this driver, use "git log --oneline
amba-pl011.c") and the trailing dot is unnecessary, e.g.:"serial: pl011: Fix incorrect rs485 RTS polarity on
set_mctrl"* Commit message should be wrapped at 72 characters (so that it appears centered when displayed with "git log" on an 80 chars terminal). The reference to "0001-serial-amba-pl011-add-RS485-support.patch" should be replaced with a reference to the offending commit, e.g.:
Quoted 7 lines
"Commit
8d479237727c("serial: amba-pl011: add RS485 support") sought to keep RTS deasserted onset_mctrlif rs485 is enabled. However it did so only if deasserted RTS polarity is high. Fix it in case it's low."Feel free to copy this to a v2 of your patch and amend as you see fit.
Find attached the patch with the new subject and corretced commit message.
Quoted 6 lines
* Add tags for the offending commit:
Fixes 8d479237727c ("serial: amba-pl011: add RS485 support")Cc [email protected] # v5.15+* Be sure to cc the author of the offending commit.
Sorry I don't know how to do that correctly. Can you please give support/hints?
Quoted 25 lines
Thanks,
Lukas
Quoted 21 lines
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );
From 90690b3e8afbdfbbb5ceb0f6cef40ed282b1c004 Mon Sep 17 00:00:00 2001
From: jmades <[email protected]>
Date: Mon, 27 Dec 2021 08:37:26 +0000
Subject: [PATCH] serial: pl011: Fix incorrect rs485 RTS polarity on set_mctrl
Commit 8d479237727c ("serial: amba-pl011: add RS485 support") sought to keep RTS deasserted on set_mctrl if rs485 is enabled. However it did so only if deasserted RTS polarity is high. Fix it in case it's low.
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tty/serial/amba-pl011.c +6 -2
@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + } cr =pl011_read (uap,REG_CR );
Signature · 1 line
2.20.1
Greg KH
maintainerQuoted 61 lines · Jochen Mades
Hi Lukas,
Quoted 14 lines
Patch is correct, but commit message could be improved:
* Subject should be in imperative mood (by convention), it should be prepended by "serial: pl011: " (in line with previous commits touching this driver, use "git log --oneline
amba-pl011.c") and the trailing dot is unnecessary, e.g.:"serial: pl011: Fix incorrect rs485 RTS polarity on
set_mctrl"* Commit message should be wrapped at 72 characters (so that it appears centered when displayed with "git log" on an 80 chars terminal). The reference to "0001-serial-amba-pl011-add-RS485-support.patch" should be replaced with a reference to the offending commit, e.g.:
Quoted 7 lines
"Commit
8d479237727c("serial: amba-pl011: add RS485 support") sought to keep RTS deasserted onset_mctrlif rs485 is enabled. However it did so only if deasserted RTS polarity is high. Fix it in case it's low."Feel free to copy this to a v2 of your patch and amend as you see fit.
Find attached the patch with the new subject and corretced commit message.
Quoted 6 lines
* Add tags for the offending commit:
Fixes 8d479237727c ("serial: amba-pl011: add RS485 support")Cc [email protected] # v5.15+* Be sure to cc the author of the offending commit.
Sorry I don't know how to do that correctly. Can you please give support/hints?
Quoted 25 lines
Thanks,
Lukas
Quoted 21 lines
--- drivers/tty/serial/amba-pl011.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/tty/serial/amba-pl011.c +6
-2@@ -1646,8 +1646,12 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) container_of(port, struct uart_amba_port, port);unsigned int cr; -if (port->rs485.flags &SER_RS485_ENABLED ) - mctrl &= ~TIOCM_RTS ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ) + mctrl &= ~TIOCM_RTS ; +else + mctrl |=TIOCM_RTS ; + }
Quoted 1 line
Quoted 1 line
drivers/tty/serial/amba-pl011.c static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) · line 1656
Quoted 1 line
drivers/tty/serial/amba-pl011.c +0
-0cr =pl011_read (uap,REG_CR );
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- Your patch was attached, please place it inline so that it can be applied directly from the email message itself.
- It looks like you did not use your "real" name for the patch on either the Signed-off-by: line, or the From: line (both of which have to match). Please read the kernel file, Documentation/SubmittingPatches for how to do this correctly.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
Quoted 1 line · Jochen Mades
Find attached the patch with the new subject and corretced commit message.
Greg doesn't accept patches as attachments and during the merge window (which ends today). I've just resubmitted your patch as part of a 2-patch series, together with a patch of mine which goes on top of yours:
(I sent your patch twice because I botched the Date header the first time around, sorry about that.)
Note that you still get patch authorship (and thus credit for the patch) even though I submitted it, due to the From: line at the top of the message body.
Quoted 8 lines
Quoted 6 lines
* Add tags for the offending commit:
Fixes 8d479237727c ("serial: amba-pl011: add RS485 support")Cc [email protected] # v5.15+* Be sure to cc the author of the offending commit.
Sorry I don't know how to do that correctly. Can you please give support/hints?
It just means that you need to add the two above-quoted tags to the commit message. The maintainers of stable kernels use them to determine which patches need to be backported to which kernel releases. I've fixed up the commit message of your patch with the missing tags, no problem.
And "cc the author of the offending commit" just means that when posting the patch, it is customary to send a copy of the e-mail to the author of the commit you're fixing, which is Lino in this case, as he authored 8d479237727c.
Thanks,
Lukas