2020-02-29 16:31:22

by Martin Devera

[permalink] [raw]
Subject: [PATCH 1/2] tty/serial: Add st,swap OF option to stm32-usart

STM32 F7/H7 usarts supports RX & TX pin swapping.
Add option to turn it on.
Tested on STM32MP157.

Signed-off-by: Martin Devera <[email protected]>
---
drivers/tty/serial/stm32-usart.c | 3 ++-
drivers/tty/serial/stm32-usart.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index fdcc2142aa79..8d25869a02eb 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -780,7 +780,7 @@ static void stm32_set_termios(struct uart_port *port, struct ktermios *termios,
cr1 = USART_CR1_TE | USART_CR1_RE;
if (stm32_port->fifoen)
cr1 |= USART_CR1_FIFOEN;
- cr2 = 0;
+ cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;

/* Tx and RX FIFO configuration */
cr3 = readl_relaxed(port->membase + ofs->cr3);
@@ -1097,6 +1097,7 @@ static struct stm32_port *stm32_of_get_stm32_port(struct platform_device *pdev)

stm32_ports[id].hw_flow_control = of_property_read_bool(np,
"st,hw-flow-ctrl");
+ stm32_ports[id].swap = of_property_read_bool(np, "st,swap");
stm32_ports[id].port.line = id;
stm32_ports[id].cr1_irq = USART_CR1_RXNEIE;
stm32_ports[id].cr3_irq = 0;
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index 2a68bc48652e..2503a91b890c 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -275,6 +275,7 @@ struct stm32_port {
enum dma_cb rx_dma_cb; /* dma rx callback status */
bool tx_dma_busy; /* dma tx busy */
bool hw_flow_control;
+ bool swap; /* swap RX & TX pins */
bool fifoen;
int wakeirq;
struct pinctrl_state *console_pins;
--
2.11.0


2020-02-29 16:31:28

by Martin Devera

[permalink] [raw]
Subject: [PATCH 2/2] dt-bindings: serial: Add st,swap to stm32-usart

Add new st,swap property to allow for RX & TX pin swapping.

Signed-off-by: Martin Devera <[email protected]>
---
Documentation/devicetree/bindings/serial/st,stm32-usart.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/serial/st,stm32-usart.txt b/Documentation/devicetree/bindings/serial/st,stm32-usart.txt
index 08b499045a38..cbfa1f9f4b17 100644
--- a/Documentation/devicetree/bindings/serial/st,stm32-usart.txt
+++ b/Documentation/devicetree/bindings/serial/st,stm32-usart.txt
@@ -24,6 +24,7 @@ Optional properties:
- pinctrl-n: Phandle(s) pointing to pin configuration nodes.
For Pinctrl properties see ../pinctrl/pinctrl-bindings.txt
- st,hw-flow-ctrl: bool flag to enable hardware flow control.
+- st,swap: bool flag to swap RX and TX pins.
- rs485-rts-delay, rs485-rx-during-tx, rs485-rts-active-low,
linux,rs485-enabled-at-boot-time: see rs485.txt.
- dmas: phandle(s) to DMA controller node(s). Refer to stm32-dma.txt
--
2.11.0

2020-03-10 19:02:09

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 2/2] dt-bindings: serial: Add st,swap to stm32-usart

On Sat, 29 Feb 2020 17:05:07 +0100, Martin Devera wrote:
> Add new st,swap property to allow for RX & TX pin swapping.
>
> Signed-off-by: Martin Devera <[email protected]>
> ---
> Documentation/devicetree/bindings/serial/st,stm32-usart.txt | 1 +
> 1 file changed, 1 insertion(+)
>

Acked-by: Rob Herring <[email protected]>

2020-03-12 09:03:37

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/2] tty/serial: Add st,swap OF option to stm32-usart

On Sat, Feb 29, 2020 at 05:05:06PM +0100, Martin Devera wrote:
> STM32 F7/H7 usarts supports RX & TX pin swapping.
> Add option to turn it on.
> Tested on STM32MP157.
>
> Signed-off-by: Martin Devera <[email protected]>
> ---
> drivers/tty/serial/stm32-usart.c | 3 ++-
> drivers/tty/serial/stm32-usart.h | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)

This, and patch 2/2, do not apply to my tty-next branch at all. What
did you make them against?

Please rebase and resend the series.

thanks,

greg k-h

2020-03-20 18:08:56

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 2/2] dt-bindings: serial: Add st,swap to stm32-usart

On Tue, Mar 10, 2020 at 1:00 PM Rob Herring <[email protected]> wrote:
>
> On Sat, 29 Feb 2020 17:05:07 +0100, Martin Devera wrote:
> > Add new st,swap property to allow for RX & TX pin swapping.
> >
> > Signed-off-by: Martin Devera <[email protected]>
> > ---
> > Documentation/devicetree/bindings/serial/st,stm32-usart.txt | 1 +
> > 1 file changed, 1 insertion(+)
> >
>
> Acked-by: Rob Herring <[email protected]>

I take this back as there's a 2nd binding (Qcom GENI) doing swapping.
So can you use 'rx-tx-swap' instead.

Rob

2021-02-27 18:08:11

by Martin Devera

[permalink] [raw]
Subject: [PATCH v2 1/2] tty/serial: Add rx-tx-swap OF option to stm32-usart

STM32 F7/H7 usarts supports RX & TX pin swapping.
Add option to turn it on.
Tested on STM32MP157.

Signed-off-by: Martin Devera <[email protected]>
---
drivers/tty/serial/stm32-usart.c | 3 ++-
drivers/tty/serial/stm32-usart.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index b3675cf25a69..3650c8798061 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -758,7 +758,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
cr1 = USART_CR1_TE | USART_CR1_RE;
if (stm32_port->fifoen)
cr1 |= USART_CR1_FIFOEN;
- cr2 = 0;
+ cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;
cr3 = readl_relaxed(port->membase + ofs->cr3);
cr3 &= USART_CR3_TXFTIE | USART_CR3_RXFTCFG_MASK | USART_CR3_RXFTIE
| USART_CR3_TXFTCFG_MASK;
@@ -1078,6 +1078,7 @@ static struct stm32_port *stm32_usart_of_get_port(struct platform_device *pdev)
stm32_ports[id].hw_flow_control =
of_property_read_bool (np, "st,hw-flow-ctrl") /*deprecated*/ ||
of_property_read_bool (np, "uart-has-rtscts");
+ stm32_ports[id].swap = of_property_read_bool(np, "rx-tx-swap");
stm32_ports[id].port.line = id;
stm32_ports[id].cr1_irq = USART_CR1_RXNEIE;
stm32_ports[id].cr3_irq = 0;
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index cb4f327c46db..2f054e2dc0ab 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -271,6 +271,7 @@ struct stm32_port {
int last_res;
bool tx_dma_busy; /* dma tx busy */
bool hw_flow_control;
+ bool swap; /* swap RX & TX pins */
bool fifoen;
int wakeirq;
int rdr_mask; /* receive data register mask */
--
2.11.0

2021-02-27 18:11:00

by Martin Devera

[permalink] [raw]
Subject: [PATCH v2 2/2] dt-bindings: serial: Add rx-tx-swap to stm32-usart

Add new rx-tx-swap property to allow for RX & TX pin swapping.

Signed-off-by: Martin Devera <[email protected]>
---
Documentation/devicetree/bindings/serial/st,stm32-uart.yaml | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
index 8631678283f9..45f2a19997da 100644
--- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
+++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
@@ -40,6 +40,10 @@ properties:

uart-has-rtscts: true

+ rx-tx-swap:
+ type: boolean
+ maxItems: 1
+
dmas:
minItems: 1
maxItems: 2
--
2.11.0

2021-03-03 02:13:20

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] tty/serial: Add rx-tx-swap OF option to stm32-usart

On 2/27/21 5:41 PM, Martin Devera wrote:
> STM32 F7/H7 usarts supports RX & TX pin swapping.
> Add option to turn it on.
> Tested on STM32MP157.
>
> Signed-off-by: Martin Devera <[email protected]>
> ---
> drivers/tty/serial/stm32-usart.c | 3 ++-
> drivers/tty/serial/stm32-usart.h | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
> index b3675cf25a69..3650c8798061 100644
> --- a/drivers/tty/serial/stm32-usart.c
> +++ b/drivers/tty/serial/stm32-usart.c
> @@ -758,7 +758,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
> cr1 = USART_CR1_TE | USART_CR1_RE;
> if (stm32_port->fifoen)
> cr1 |= USART_CR1_FIFOEN;
> - cr2 = 0;
> + cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;

Hi Martin,

Same could be done in the startup routine, that enables the port for
reception (as described in Documentation/driver-api/serial/driver.rst)

> cr3 = readl_relaxed(port->membase + ofs->cr3);
> cr3 &= USART_CR3_TXFTIE | USART_CR3_RXFTCFG_MASK | USART_CR3_RXFTIE
> | USART_CR3_TXFTCFG_MASK;
> @@ -1078,6 +1078,7 @@ static struct stm32_port *stm32_usart_of_get_port(struct platform_device *pdev)
> stm32_ports[id].hw_flow_control =
> of_property_read_bool (np, "st,hw-flow-ctrl") /*deprecated*/ ||
> of_property_read_bool (np, "uart-has-rtscts");
> + stm32_ports[id].swap = of_property_read_bool(np, "rx-tx-swap");

The swap option/bit is available starting with stm32f7 (e.g. not on
stm32f4).

This could be added to compatible data, e.g. as done for other
capabilities in stm32-usart.h. E.g you could add a "has_swap" in struct
stm32_usart_config, then use it at probe time:
if (cfg->has_swap)
stm32_ports[id].swap = ...;

Thanks for your patch,
Best regards,
Fabrice

> stm32_ports[id].port.line = id;
> stm32_ports[id].cr1_irq = USART_CR1_RXNEIE;
> stm32_ports[id].cr3_irq = 0;
> diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
> index cb4f327c46db..2f054e2dc0ab 100644
> --- a/drivers/tty/serial/stm32-usart.h
> +++ b/drivers/tty/serial/stm32-usart.h
> @@ -271,6 +271,7 @@ struct stm32_port {
> int last_res;
> bool tx_dma_busy; /* dma tx busy */
> bool hw_flow_control;
> + bool swap; /* swap RX & TX pins */
> bool fifoen;
> int wakeirq;
> int rdr_mask; /* receive data register mask */
>

2021-03-03 02:21:27

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] dt-bindings: serial: Add rx-tx-swap to stm32-usart



On 2/27/21 5:41 PM, Martin Devera wrote:
> Add new rx-tx-swap property to allow for RX & TX pin swapping.
>
> Signed-off-by: Martin Devera <[email protected]>
> ---
> Documentation/devicetree/bindings/serial/st,stm32-uart.yaml | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> index 8631678283f9..45f2a19997da 100644
> --- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> +++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> @@ -40,6 +40,10 @@ properties:
>
> uart-has-rtscts: true
>
> + rx-tx-swap:
> + type: boolean
> + maxItems: 1
> +

Hi Martin,

This could be restricted to st,stm32f7-uart and st,stm32h7-uart
compatibles. This option isn't available on stm32f4 (e.g. st,stm32-uart
compatible)

Thanks for your patch,
Best Regards,
Fabrice

> dmas:
> minItems: 1
> maxItems: 2
>

2021-03-04 05:28:22

by Martin Devera

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] tty/serial: Add rx-tx-swap OF option to stm32-usart

On 3/1/21 11:28 AM, Fabrice Gasnier wrote:
> On 2/27/21 5:41 PM, Martin Devera wrote:
>> STM32 F7/H7 usarts supports RX & TX pin swapping.
>> Add option to turn it on.
>> Tested on STM32MP157.
>>
>> Signed-off-by: Martin Devera <[email protected]>
>> ---
>> drivers/tty/serial/stm32-usart.c | 3 ++-
>> drivers/tty/serial/stm32-usart.h | 1 +
>> 2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
>> index b3675cf25a69..3650c8798061 100644
>> --- a/drivers/tty/serial/stm32-usart.c
>> +++ b/drivers/tty/serial/stm32-usart.c
>> @@ -758,7 +758,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
>> cr1 = USART_CR1_TE | USART_CR1_RE;
>> if (stm32_port->fifoen)
>> cr1 |= USART_CR1_FIFOEN;
>> - cr2 = 0;
>> + cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;
> Hi Martin,
>
> Same could be done in the startup routine, that enables the port for
> reception (as described in Documentation/driver-api/serial/driver.rst)
Hello Fabrice,

I already incorporated all your comments but I'm struggling with the one
above.
The code must be in stm32_usart_set_termios too, because CR2 is modified.
What is the reason to have it in startup() ?
Is it because USART can be started without calling set_termios at all ? Like
to reuse bootloader's last settings ?

Thanks, Martin

2021-03-04 06:11:44

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] tty/serial: Add rx-tx-swap OF option to stm32-usart

On 3/1/21 11:40 PM, Martin DEVERA wrote:
> On 3/1/21 11:28 AM, Fabrice Gasnier wrote:
>> On 2/27/21 5:41 PM, Martin Devera wrote:
>>> STM32 F7/H7 usarts supports RX & TX pin swapping.
>>> Add option to turn it on.
>>> Tested on STM32MP157.
>>>
>>> Signed-off-by: Martin Devera <[email protected]>
>>> ---
>>>   drivers/tty/serial/stm32-usart.c | 3 ++-
>>>   drivers/tty/serial/stm32-usart.h | 1 +
>>>   2 files changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/tty/serial/stm32-usart.c
>>> b/drivers/tty/serial/stm32-usart.c
>>> index b3675cf25a69..3650c8798061 100644
>>> --- a/drivers/tty/serial/stm32-usart.c
>>> +++ b/drivers/tty/serial/stm32-usart.c
>>> @@ -758,7 +758,7 @@ static void stm32_usart_set_termios(struct
>>> uart_port *port,
>>>       cr1 = USART_CR1_TE | USART_CR1_RE;
>>>       if (stm32_port->fifoen)
>>>           cr1 |= USART_CR1_FIFOEN;
>>> -    cr2 = 0;
>>> +    cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;
>> Hi Martin,
>>
>> Same could be done in the startup routine, that enables the port for
>> reception (as described in Documentation/driver-api/serial/driver.rst)
> Hello Fabrice,
>
> I already incorporated all your comments but I'm struggling with the one
> above.
> The code must be in stm32_usart_set_termios too, because CR2 is modified.

Hi Martin,

Yes, sure,

> What is the reason to have it in startup() ?

RX is enabled at both places. So the swap setting should be there too.

> Is it because USART can be started without calling set_termios at all ?

Yes, that's what the driver API expects: "startup(port)" ... "Enable the
port for reception."

Best Regards,
Fabrice

> Like
> to reuse bootloader's last settings ?
>
> Thanks, Martin
>

2021-03-04 07:02:59

by Martin Devera

[permalink] [raw]
Subject: [PATCH v3 1/2] dt-bindings: serial: Add rx-tx-swap to stm32-usart

Add new rx-tx-swap property to allow for RX & TX pin swapping.

Signed-off-by: Martin Devera <[email protected]>
---
.../devicetree/bindings/serial/st,stm32-uart.yaml | 32 +++++++++++++++-------
1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
index 8631678283f9..6eab2debebb5 100644
--- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
+++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
@@ -9,9 +9,6 @@ maintainers:

title: STMicroelectronics STM32 USART bindings

-allOf:
- - $ref: rs485.yaml
-
properties:
compatible:
enum:
@@ -40,6 +37,10 @@ properties:

uart-has-rtscts: true

+ rx-tx-swap:
+ type: boolean
+ maxItems: 1
+
dmas:
minItems: 1
maxItems: 2
@@ -66,13 +67,24 @@ properties:
linux,rs485-enabled-at-boot-time: true
rs485-rx-during-tx: true

-if:
- required:
- - st,hw-flow-ctrl
-then:
- properties:
- cts-gpios: false
- rts-gpios: false
+allOf:
+ - $ref: rs485.yaml
+ - if:
+ required:
+ - st,hw-flow-ctrl
+ then:
+ properties:
+ cts-gpios: false
+ rts-gpios: false
+ - if:
+ required:
+ - rx-tx-swap
+ then:
+ properties:
+ compatible:
+ enum:
+ - st,stm32f7-uart
+ - st,stm32h7-uart

required:
- compatible
--
2.11.0

2021-03-04 20:30:56

by Martin Devera

[permalink] [raw]
Subject: [PATCH v3 2/2] tty/serial: Add rx-tx-swap OF option to stm32-usart

STM32 F7/H7 usarts supports RX & TX pin swapping.
Add option to turn it on.
Tested on STM32MP157.

Signed-off-by: Martin Devera <[email protected]>
---
drivers/tty/serial/stm32-usart.c | 11 ++++++++++-
drivers/tty/serial/stm32-usart.h | 5 +++++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index b3675cf25a69..d390f7da1441 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -644,6 +644,12 @@ static int stm32_usart_startup(struct uart_port *port)
if (ret)
return ret;

+ if (stm32_port->swap) {
+ val = readl_relaxed(port->membase + ofs->cr2);
+ val |= USART_CR2_SWAP;
+ writel_relaxed(val, port->membase + ofs->cr2);
+ }
+
/* RX FIFO Flush */
if (ofs->rqr != UNDEF_REG)
stm32_usart_set_bits(port, ofs->rqr, USART_RQR_RXFRQ);
@@ -758,7 +764,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
cr1 = USART_CR1_TE | USART_CR1_RE;
if (stm32_port->fifoen)
cr1 |= USART_CR1_FIFOEN;
- cr2 = 0;
+ cr2 = stm32_port->swap ? USART_CR2_SWAP : 0;
cr3 = readl_relaxed(port->membase + ofs->cr3);
cr3 &= USART_CR3_TXFTIE | USART_CR3_RXFTCFG_MASK | USART_CR3_RXFTIE
| USART_CR3_TXFTCFG_MASK;
@@ -1006,6 +1012,9 @@ static int stm32_usart_init_port(struct stm32_port *stm32port,
return stm32port->wakeirq ? : -ENODEV;
}

+ stm32port->swap = stm32port->info->cfg.has_swap &&
+ of_property_read_bool(pdev->dev.of_node, "rx-tx-swap");
+
stm32port->fifoen = stm32port->info->cfg.has_fifo;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index cb4f327c46db..bd18dd1c1bcd 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -25,6 +25,7 @@ struct stm32_usart_offsets {
struct stm32_usart_config {
u8 uart_enable_bit; /* USART_CR1_UE */
bool has_7bits_data;
+ bool has_swap;
bool has_wakeup;
bool has_fifo;
int fifosize;
@@ -55,6 +56,7 @@ struct stm32_usart_info stm32f4_info = {
.cfg = {
.uart_enable_bit = 13,
.has_7bits_data = false,
+ .has_swap = false,
.fifosize = 1,
}
};
@@ -76,6 +78,7 @@ struct stm32_usart_info stm32f7_info = {
.cfg = {
.uart_enable_bit = 0,
.has_7bits_data = true,
+ .has_swap = true,
.fifosize = 1,
}
};
@@ -97,6 +100,7 @@ struct stm32_usart_info stm32h7_info = {
.cfg = {
.uart_enable_bit = 0,
.has_7bits_data = true,
+ .has_swap = true,
.has_wakeup = true,
.has_fifo = true,
.fifosize = 16,
@@ -271,6 +275,7 @@ struct stm32_port {
int last_res;
bool tx_dma_busy; /* dma tx busy */
bool hw_flow_control;
+ bool swap; /* swap RX & TX pins */
bool fifoen;
int wakeirq;
int rdr_mask; /* receive data register mask */
--
2.11.0