2022-09-13 17:19:40

by Sergiu Moga

[permalink] [raw]
Subject: [PATCH v3 00/14] Make atmel serial driver aware of GCLK

This series of patches introduces the GCLK as a potential clock source for
the baudrate generator of UART on sama5d2 SoCs. Unlike the serial mode of
the USART offered by FLEXCOM, the UART does not provide a fractional part
that can be added to the clock divisor to obtain a more accurate result,
which greatly decreases the flexibility available for producing a higher
variety of baudrates. Now, with the last patch of the series, the driver
will check for a GCLK in the DT. If provided, whenever `atmel_set_termios`
is called, unless there is a fractional part, the driver will compare the
error rate between the desired baudrate and the actual baudrate obtained
through each of the available clock sources and will choose the clock source
with the lowest error rate. While at it, convert the DT binding
for UART/USART to json-schema, update the FLEXCOM binding to reference the
new UART/USART binding (while differentiating between the SPI of USART and the
SPI of FLEXCOM) and do some small DT related fixups.

The DT bindings related patches of this patch series depend on this patch
series converting atmel-flexcom bindings to json-schema:
https://lore.kernel.org/all/[email protected]/

v1 -> v2:
- [PATCH 3] dt-bindings: mfd: atmel,sama5d2-flexcom: Add SPI child node ref
binding:
- use full schema paths

- [PATCH 5] dt-bindings: serial: atmel,at91-usart: convert to json-schema
- only do what the commit says, split the addition of other compatibles
(PATCH 6) and properties (PATCH 13) in other patches
- remove unnecessary "|"'s
- mention header in `atmel,usart-mode`'s description
- place `if:` under `allOf:`
- respect order of spi0's DT properties: compatible, then reg then the
reset of properties

- two new baudrate clock source related patches:
[PATCH 9] tty: serial: atmel: Add definition for GCLK as baudrate source clock
+
[PATCH 10] tty: serial: atmel: Define BRSRCCK bitmask of UART IP's Mode
Register:
- v1's bitfield definition of GCLK was wrong, so add two more patches:
- one for the definition of GCLK of USART IP's
- one for the definition of BRSRCCK bitmask and its bitfields
for UART IP's

- a new cleanup related patch that introduces a new struct atmel_uart_port field:
[PATCH 11] tty: serial: atmel: Only divide Clock Divisor if the IP is USART:
- this ensures a division by 8 which is unnecessary and unappliable to
UART IP's is only done for USART IP's

- four new patches regarding DT fixes and a SPI binding update that I came
upon:
[PATCH 1] spi: dt-bindings: atmel,at91rm9200-spi: Add DMA related properties
[PATCH 2] ARM: dts: at91: sama7g5: Swap rx and tx for spi11
[PATCH 4] ARM: dts: at91: sam9x60ek: Add DBGU compatibles to uart1
[PATCH 6] dt-bindings: serial: atmel,at91-usart: Highlight SAM9X60 incremental

- [PATCH 12] tty: serial: atmel: Make the driver aware of the existence of GCLK
- take into account the different placement of the baudrate clock source
into the IP's Mode Register (USART vs UART)
- don't check for atmel_port->gclk != NULL
- use clk_round_rate instead of clk_set_rate + clk_get_rate
- remove clk_disable_unprepare from the end of the probe method

v2 -> v3:
- Re-order the patches as suggested by Krzysztof Kozlowski:
1. DTS changes needed for aligning to schema.
2. all bindings
3. rest

- New DT consistency related patch:
[PATCH 3] ARM: dts: at91: Add `atmel,usart-mode` required property to serial
nodes

- [PATCH 6] dt-bindings: serial: atmel,at91-usart: convert to json-schema:
- Check value of `atmel,usart-mode` instead of the node regex
- Define all properties top level and disallow them explicitly for other type,
since additionalProperties:false conflicts with referencing other schemas
- Remove useless else if: after else:

- [PATCH 7] dt-bindings: serial: atmel,at91-usart: add SAM9260 compatibles to
SAM9X60:
- Use the commit message suggested by Krzysztof Kozlowski

- [PATCH 8] dt-bindings: mfd: atmel,sama5d2-flexcom: Add USART child node ref
binding
- Compare devices based on the compatible instead of the clock

- [PATCH 12] tty: serial: atmel: Only divide Clock Divisor if the IP is USART
- Use ATMEL_US_CD instead of 65535

- [PATCH 14] tty: serial: atmel: Make the driver aware of the existence of GCLK
- add `gclk_fail` goto
- replace `goto err` with `goto err_clk_disable_unprepare;`


Sergiu Moga (14):
ARM: dts: at91: sama7g5: Swap rx and tx for spi11
ARM: dts: at91: sam9x60ek: Add DBGU compatibles to uart1
ARM: dts: at91: Add `atmel,usart-mode` required property to serial
nodes
spi: dt-bindings: atmel,at91rm9200-spi: Add DMA related properties
dt-bindings: mfd: atmel,sama5d2-flexcom: Add SPI child node ref
binding
dt-bindings: serial: atmel,at91-usart: convert to json-schema
dt-bindings: serial: atmel,at91-usart: Add SAM9260 compatibles to
SAM9X60
dt-bindings: mfd: atmel,sama5d2-flexcom: Add USART child node ref
binding
dt-bindings: serial: atmel,at91-usart: Add gclk as a possible USART
clock
tty: serial: atmel: Define GCLK as USART baudrate source clock
tty: serial: atmel: Define BRSRCCK bitmask of UART IP's Mode Register
tty: serial: atmel: Only divide Clock Divisor if the IP is USART
clk: at91: sama5d2: Add Generic Clocks for UART/USART
tty: serial: atmel: Make the driver aware of the existence of GCLK

.../bindings/mfd/atmel,sama5d2-flexcom.yaml | 19 +-
.../devicetree/bindings/mfd/atmel-usart.txt | 98 ---------
.../bindings/serial/atmel,at91-usart.yaml | 190 ++++++++++++++++++
.../bindings/spi/atmel,at91rm9200-spi.yaml | 10 +
arch/arm/boot/dts/at91-sam9x60ek.dts | 3 +-
arch/arm/boot/dts/at91rm9200.dtsi | 6 +
arch/arm/boot/dts/at91sam9260.dtsi | 8 +
arch/arm/boot/dts/at91sam9261.dtsi | 5 +
arch/arm/boot/dts/at91sam9263.dtsi | 5 +
arch/arm/boot/dts/at91sam9g45.dtsi | 6 +
arch/arm/boot/dts/at91sam9n12.dtsi | 6 +
arch/arm/boot/dts/at91sam9rl.dtsi | 6 +
arch/arm/boot/dts/at91sam9x5.dtsi | 7 +
arch/arm/boot/dts/at91sam9x5_usart3.dtsi | 2 +
arch/arm/boot/dts/sam9x60.dtsi | 2 +
arch/arm/boot/dts/sama5d2.dtsi | 11 +
arch/arm/boot/dts/sama5d3.dtsi | 7 +
arch/arm/boot/dts/sama5d3_uart.dtsi | 3 +
arch/arm/boot/dts/sama5d4.dtsi | 9 +
arch/arm/boot/dts/sama7g5.dtsi | 11 +-
drivers/clk/at91/sama5d2.c | 10 +
drivers/tty/serial/atmel_serial.c | 76 ++++++-
drivers/tty/serial/atmel_serial.h | 4 +
23 files changed, 394 insertions(+), 110 deletions(-)
delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt
create mode 100644 Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml

--
2.34.1


2022-09-13 17:23:47

by Sergiu Moga

[permalink] [raw]
Subject: [PATCH v3 01/14] ARM: dts: at91: sama7g5: Swap rx and tx for spi11

Swap the rx and tx of the DMA related DT properties of the spi11 node
in order to maintain consistency across Microchip/Atmel SoC files.

Signed-off-by: Sergiu Moga <[email protected]>
---


v1 -> v2:
- Nothing, this patch was not here before


v2 -> v3:
- Nothing, this was previously [PATCH 2]



arch/arm/boot/dts/sama7g5.dtsi | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/sama7g5.dtsi b/arch/arm/boot/dts/sama7g5.dtsi
index bb6d71e6dfeb..249f9c640b6c 100644
--- a/arch/arm/boot/dts/sama7g5.dtsi
+++ b/arch/arm/boot/dts/sama7g5.dtsi
@@ -866,9 +866,9 @@ spi11: spi@400 {
#address-cells = <1>;
#size-cells = <0>;
atmel,fifo-size = <32>;
- dmas = <&dma0 AT91_XDMAC_DT_PERID(27)>,
- <&dma0 AT91_XDMAC_DT_PERID(28)>;
- dma-names = "rx", "tx";
+ dmas = <&dma0 AT91_XDMAC_DT_PERID(28)>,
+ <&dma0 AT91_XDMAC_DT_PERID(27)>;
+ dma-names = "tx", "rx";
status = "disabled";
};
};
--
2.34.1

2022-09-13 17:24:18

by Sergiu Moga

[permalink] [raw]
Subject: [PATCH v3 11/14] tty: serial: atmel: Define BRSRCCK bitmask of UART IP's Mode Register

Add definitions for the Baud Rate Source Clock bitmask of the
Mode Register of UART IP's and its bitfields.

Signed-off-by: Sergiu Moga <[email protected]>
---


v1 -> v2:
- Nothing, this patch was not here before



v2 -> v3:
- Previously this was [PATCH 11]


drivers/tty/serial/atmel_serial.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/atmel_serial.h b/drivers/tty/serial/atmel_serial.h
index 70d0611e56fd..ed64035ba6c3 100644
--- a/drivers/tty/serial/atmel_serial.h
+++ b/drivers/tty/serial/atmel_serial.h
@@ -68,6 +68,9 @@
#define ATMEL_US_NBSTOP_1 (0 << 12)
#define ATMEL_US_NBSTOP_1_5 (1 << 12)
#define ATMEL_US_NBSTOP_2 (2 << 12)
+#define ATMEL_UA_BRSRCCK GENMASK(13, 12) /* Clock Selection for UART */
+#define ATMEL_UA_BRSRCCK_PERIPH_CLK (0 << 12)
+#define ATMEL_UA_BRSRCCK_GCLK (1 << 12)
#define ATMEL_US_CHMODE GENMASK(15, 14) /* Channel Mode */
#define ATMEL_US_CHMODE_NORMAL (0 << 14)
#define ATMEL_US_CHMODE_ECHO (1 << 14)
--
2.34.1

2022-09-13 17:25:22

by Sergiu Moga

[permalink] [raw]
Subject: [PATCH v3 07/14] dt-bindings: serial: atmel,at91-usart: Add SAM9260 compatibles to SAM9X60

Require SAM9260 fallback compatible for SAM9X60, because SAM9X60 is
fully compatible with SAM9260 and Linux driver requires the latter.

Signed-off-by: Sergiu Moga <[email protected]>
---


v1 -> v2:
- Nothing, this patch was not here before


v2 -> v3:
- Use the commit message suggested by Krzysztof Kozlowski




Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml b/Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml
index bb1b5ed431f7..4da642763bef 100644
--- a/Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml
+++ b/Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml
@@ -26,6 +26,8 @@ properties:
- items:
- const: microchip,sam9x60-dbgu
- const: microchip,sam9x60-usart
+ - const: atmel,at91sam9260-dbgu
+ - const: atmel,at91sam9260-usart

reg:
maxItems: 1
--
2.34.1

2022-09-16 09:14:52

by Claudiu Beznea

[permalink] [raw]
Subject: Re: [PATCH v3 01/14] ARM: dts: at91: sama7g5: Swap rx and tx for spi11

On 13.09.2022 17:21, Sergiu Moga wrote:
> Swap the rx and tx of the DMA related DT properties of the spi11 node
> in order to maintain consistency across Microchip/Atmel SoC files.
>
> Signed-off-by: Sergiu Moga <[email protected]>

Applied to at91-dt, thanks!

> ---
>
>
> v1 -> v2:
> - Nothing, this patch was not here before
>
>
> v2 -> v3:
> - Nothing, this was previously [PATCH 2]
>
>
>
> arch/arm/boot/dts/sama7g5.dtsi | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/boot/dts/sama7g5.dtsi b/arch/arm/boot/dts/sama7g5.dtsi
> index bb6d71e6dfeb..249f9c640b6c 100644
> --- a/arch/arm/boot/dts/sama7g5.dtsi
> +++ b/arch/arm/boot/dts/sama7g5.dtsi
> @@ -866,9 +866,9 @@ spi11: spi@400 {
> #address-cells = <1>;
> #size-cells = <0>;
> atmel,fifo-size = <32>;
> - dmas = <&dma0 AT91_XDMAC_DT_PERID(27)>,
> - <&dma0 AT91_XDMAC_DT_PERID(28)>;
> - dma-names = "rx", "tx";
> + dmas = <&dma0 AT91_XDMAC_DT_PERID(28)>,
> + <&dma0 AT91_XDMAC_DT_PERID(27)>;
> + dma-names = "tx", "rx";
> status = "disabled";
> };
> };