Skip to contentSkip to conversation

Make atmel serial driver aware of GCLK

PATCH Superseded Sergiu Moga 7 participants 30 messages Aug 17, 2022 – Sep 6, 2022

Subsystems (7)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover 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 and differentiate between the SPI of USART and the SPI of FLEXCOM.

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

Sergiu Moga (5):
dt-bindings: mfd: atmel,sama5d2-flexcom: Add SPI child node ref
binding
dt-bindings: mfd: atmel,at91-usart: convert to json-schema
dt-bindings: mfd: atmel,sama5d2-flexcom: Add USART child node ref
binding
clk: at91: sama5d2: Add Generic Clocks for UART/USART
tty: serial: atmel: Make the driver aware of the existence of GCLK

 .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
 .../bindings/mfd/atmel,sama5d2-flexcom.yaml   |  18 +-
 .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
 drivers/clk/at91/sama5d2.c                    |  10 +
 drivers/tty/serial/atmel_serial.c             |  52 ++++-
 drivers/tty/serial/atmel_serial.h             |   1 +
 6 files changed, 264 insertions(+), 105 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml
 delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/5 dt-bindings: mfd: atmel,sama5d2-flexcom: Add SPI child node ref binding

Another functionality of FLEXCOM is that of SPI. In order for the proper validation of the SPI children nodes through the binding to occur, the proper binding for SPI must be referenced.

---
 .../devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml       | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml +2 -3
index 568da7cb630c..e158af47c326 100644
@@ -78,10 +78,9 @@ patternProperties:
       of USART bindings.
 
   "^spi@[0-9a-f]+$":
-    type: object
+    $ref: ../spi/atmel,at91rm9200-spi.yaml
     description:
-      Child node describing SPI. See ../spi/spi_atmel.txt for details
-      of SPI bindings.
+      Child node describing SPI.
 
   "^i2c@[0-9a-f]+$":
     $ref: ../i2c/atmel,at91sam-i2c.yaml
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/5] dt-bindings: mfd: atmel,sama5d2-flexcom: Add SPI child node ref binding

Quoted 14 lines · Sergiu Moga

Another functionality of FLEXCOM is that of SPI. In order for the proper validation of the SPI children nodes through the binding to occur, the proper binding for SPI must be referenced.

---
 .../devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml       | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml +0 -0
index 568da7cb630c..e158af47c326 100644

Documentation/devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml patternProperties: · line 81

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml +1 -1
@@ -78,10 +78,9 @@ patternProperties:
       of USART bindings.
 
   "^spi@[0-9a-f]+$":
-    type: object
+    $ref: ../spi/atmel,at91rm9200-spi.yaml

Full schemas path, so:

/schemas/spi/atmel....

Best regards,
Krzysztof

#3 lore raw

PATCH 2/5 dt-bindings: mfd: atmel,at91-usart: convert to json-schema

In reply to Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
 .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
 .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
 2 files changed, 190 insertions(+), 98 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml
 delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +190 -0
new file mode 100644
index 000000000000..cf15d73fa1e8
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/atmel,at91-usart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
+
+maintainers:
+  - Richard Genoud <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - const: atmel,at91rm9200-usart
+      - const: atmel,at91sam9260-usart
+      - const: microchip,sam9x60-usart
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart
+
+  clocks:
+    minItems: 1
+    maxItems: 2
+
+  dmas:
+    items:
+      - description: TX DMA Channel
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  atmel,usart-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Must be either 1 for SPI or 0 for USART.
+    enum: [ 0, 1 ]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+if:
+  properties:
+    $nodename:
+      pattern: "^serial@[0-9a-f]+$"
+then:
+  allOf:
+    - $ref: /schemas/serial/serial.yaml#
+    - $ref: /schemas/serial/rs485.yaml#
+
+  properties:
+    atmel,use-dma-rx:
+      type: boolean
+      description: use of PDC or DMA for receiving data
+
+    atmel,use-dma-tx:
+      type: boolean
+      description: use of PDC or DMA for transmitting data
+
+    atmel,fifo-size:
+      $ref: /schemas/types.yaml#/definitions/uint32
+      description: |
+        Maximum number of data the RX and TX FIFOs can store for FIFO
+        capable USARTS.
+      enum: [ 16, 32 ]
+
+else:
+  if:
+    properties:
+      $nodename:
+        pattern: "^spi@[0-9a-f]+$"
+  then:
+    allOf:
+      - $ref: /schemas/spi/spi-controller.yaml#
+
+    properties:
+      atmel,usart-mode:
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "#address-cells":
+        const: 1
+
+    required:
+      - atmel,usart-mode
+      - "#size-cells"
+      - "#address-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use PDC */
+    usart0: serial@fff8c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xfff8c000 0x4000>;
+        interrupts = <7>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        rts-gpios = <&pioD 15 GPIO_ACTIVE_LOW>;
+        cts-gpios = <&pioD 16 GPIO_ACTIVE_LOW>;
+        dtr-gpios = <&pioD 17 GPIO_ACTIVE_LOW>;
+        dsr-gpios = <&pioD 18 GPIO_ACTIVE_LOW>;
+        dcd-gpios = <&pioD 20 GPIO_ACTIVE_LOW>;
+        rng-gpios = <&pioD 19 GPIO_ACTIVE_LOW>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use DMA */
+    usart1: serial@f001c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xf001c000 0x100>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        atmel,fifo-size = <32>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* SPI mode */
+    spi0: spi@f001c000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "atmel,at91sam9260-usart";
+        atmel,usart-mode = <AT91_USART_MODE_SPI>;
+        reg = <0xf001c000 0x100>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        cs-gpios = <&pioB 3 GPIO_ACTIVE_HIGH>;
+    };
Documentation/devicetree/bindings/mfd/atmel-usart.txt deleted +0 -98

98 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 22 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
 .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
 .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
 2 files changed, 190 insertions(+), 98 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml
 delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
new file mode 100644
index 000000000000..cf15d73fa1e8
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/atmel,at91-usart.yaml#

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
+
+maintainers:
+  - Richard Genoud <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

This looks quite different than bindings and you commit msg is saying it is only a conversion. Mention any changes against original bindings.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +3 -0
+      - const: atmel,at91rm9200-usart
+      - const: atmel,at91sam9260-usart
+      - const: microchip,sam9x60-usart

That's an enum

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 30

Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +12 -0
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart

This is not correct - contradicts earlier one.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 35

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart

What? You wrote above that microchip,sam9x60-dbgu is compatible only with microchip,sam9x60-usart. Now you write it is also compatible with other ones?

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart

No, this has to be specific/fixed list.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 49

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  clocks:
+    minItems: 1
+    maxItems: 2

Not really - define the items. One item could be optional, though.

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  dmas:
+    items:
+      - description: TX DMA Channel

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  atmel,usart-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

No need for |

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 64

Quoted 1 line
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +1 -0
+      Must be either 1 for SPI or 0 for USART.

Mention the header.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    enum: [ 0, 1 ]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+if:

Put it under allOf.

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+  properties:
+    $nodename:
+      pattern: "^serial@[0-9a-f]+$"
+then:
+  allOf:
+    - $ref: /schemas/serial/serial.yaml#
+    - $ref: /schemas/serial/rs485.yaml#
+
+  properties:
+    atmel,use-dma-rx:

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 94

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      type: boolean
+      description: use of PDC or DMA for receiving data
+
+    atmel,use-dma-tx:
+      type: boolean
+      description: use of PDC or DMA for transmitting data
+
+    atmel,fifo-size:
+      $ref: /schemas/types.yaml#/definitions/uint32
+      description: |

No need for |

Quoted 78 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +78 -0
+        Maximum number of data the RX and TX FIFOs can store for FIFO
+        capable USARTS.
+      enum: [ 16, 32 ]
+
+else:
+  if:
+    properties:
+      $nodename:
+        pattern: "^spi@[0-9a-f]+$"
+  then:
+    allOf:
+      - $ref: /schemas/spi/spi-controller.yaml#
+
+    properties:
+      atmel,usart-mode:
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "#address-cells":
+        const: 1
+
+    required:
+      - atmel,usart-mode
+      - "#size-cells"
+      - "#address-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use PDC */
+    usart0: serial@fff8c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xfff8c000 0x4000>;
+        interrupts = <7>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        rts-gpios = <&pioD 15 GPIO_ACTIVE_LOW>;
+        cts-gpios = <&pioD 16 GPIO_ACTIVE_LOW>;
+        dtr-gpios = <&pioD 17 GPIO_ACTIVE_LOW>;
+        dsr-gpios = <&pioD 18 GPIO_ACTIVE_LOW>;
+        dcd-gpios = <&pioD 20 GPIO_ACTIVE_LOW>;
+        rng-gpios = <&pioD 19 GPIO_ACTIVE_LOW>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use DMA */
+    usart1: serial@f001c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xf001c000 0x100>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        atmel,fifo-size = <32>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 182

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* SPI mode */
+    spi0: spi@f001c000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "atmel,at91sam9260-usart";
+        atmel,usart-mode = <AT91_USART_MODE_SPI>;
+        reg = <0xf001c000 0x100>;

compatible, then reg then the reset of properties

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 190

Quoted 8 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +8 -0
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        cs-gpios = <&pioB 3 GPIO_ACTIVE_HIGH>;
+    };

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 29 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 26 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +9 -0
new file mode 100644
index 000000000000..cf15d73fa1e8
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/atmel,at91-usart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
+
Quoted 8 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 15

Quoted 6 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +6 -0
+maintainers:
+  - Richard Genoud <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

This looks quite different than bindings and you commit msg is saying it is only a conversion. Mention any changes against original bindings.

Noted. Will make the commit message more descriptive to also include the new compatibles.  Perhaps the addition of the GCLK should come under a different patch as well.

Quoted 17 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +3 -0
+      - const: atmel,at91rm9200-usart
+      - const: atmel,at91sam9260-usart
+      - const: microchip,sam9x60-usart

That's an enum

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 30

Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +12 -0
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart
Quoted 2 lines

This is not correct - contradicts earlier one.

Yes, this was for a DT node we have internally, my bad. You are right, it does not really make sense and it should not be the other way around:
having the DT validate the binding. I will remove this combination in the next version.

Quoted 8 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 35

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart

What? You wrote above that microchip,sam9x60-dbgu is compatible only with microchip,sam9x60-usart. Now you write it is also compatible with other ones?

Yes, this one is intended because the 9x60 IP has new functionalities on top of 9260, and some nodes do keep all four as fallback.

Quoted 11 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart

No, this has to be specific/fixed list.

I wanted to highlight the fact that it must contain either:
clock-names = "usart";
or
clock-names = "usart", "gclk";

What would be the recommended way of doing this then?

Quoted 157 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 49

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  clocks:
+    minItems: 1
+    maxItems: 2

Not really - define the items. One item could be optional, though.

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  dmas:
+    items:
+      - description: TX DMA Channel

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  atmel,usart-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

No need for |

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 64

Quoted 1 line
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +1 -0
+      Must be either 1 for SPI or 0 for USART.

Mention the header.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    enum: [ 0, 1 ]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+if:

Put it under allOf.

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+  properties:
+    $nodename:
+      pattern: "^serial@[0-9a-f]+$"
+then:
+  allOf:
+    - $ref: /schemas/serial/serial.yaml#
+    - $ref: /schemas/serial/rs485.yaml#
+
+  properties:
+    atmel,use-dma-rx:

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 94

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      type: boolean
+      description: use of PDC or DMA for receiving data
+
+    atmel,use-dma-tx:
+      type: boolean
+      description: use of PDC or DMA for transmitting data
+
+    atmel,fifo-size:
+      $ref: /schemas/types.yaml#/definitions/uint32
+      description: |

No need for |

Quoted 78 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +78 -0
+        Maximum number of data the RX and TX FIFOs can store for FIFO
+        capable USARTS.
+      enum: [ 16, 32 ]
+
+else:
+  if:
+    properties:
+      $nodename:
+        pattern: "^spi@[0-9a-f]+$"
+  then:
+    allOf:
+      - $ref: /schemas/spi/spi-controller.yaml#
+
+    properties:
+      atmel,usart-mode:
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "#address-cells":
+        const: 1
+
+    required:
+      - atmel,usart-mode
+      - "#size-cells"
+      - "#address-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use PDC */
+    usart0: serial@fff8c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xfff8c000 0x4000>;
+        interrupts = <7>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        rts-gpios = <&pioD 15 GPIO_ACTIVE_LOW>;
+        cts-gpios = <&pioD 16 GPIO_ACTIVE_LOW>;
+        dtr-gpios = <&pioD 17 GPIO_ACTIVE_LOW>;
+        dsr-gpios = <&pioD 18 GPIO_ACTIVE_LOW>;
+        dcd-gpios = <&pioD 20 GPIO_ACTIVE_LOW>;
+        rng-gpios = <&pioD 19 GPIO_ACTIVE_LOW>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use DMA */
+    usart1: serial@f001c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xf001c000 0x100>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        atmel,fifo-size = <32>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 182

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* SPI mode */
+    spi0: spi@f001c000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "atmel,at91sam9260-usart";
+        atmel,usart-mode = <AT91_USART_MODE_SPI>;
+        reg = <0xf001c000 0x100>;

compatible, then reg then the reset of properties

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 190

Quoted 8 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +8 -0
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        cs-gpios = <&pioB 3 GPIO_ACTIVE_HIGH>;
+    };
Quoted 2 lines

Best regards,
Krzysztof

Regards,
    Sergiu

#6 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 12 lines · On 19/08/2022 11:37, [email protected] wrote:
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +12 -0
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart
Quoted 7 lines
Quoted 2 lines

This is not correct - contradicts earlier one.

Yes, this was for a DT node we have internally, my bad. You are right, it does not really make sense and it should not be the other way around:
having the DT validate the binding. I will remove this combination in the next version.

You need to fix any out of tree DTS or upstream it.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
Quoted 7 lines
Quoted 3 lines

What? You wrote above that microchip,sam9x60-dbgu is compatible only with microchip,sam9x60-usart. Now you write it is also compatible with other ones?

Yes, this one is intended because the 9x60 IP has new functionalities on top of 9260, and some nodes do keep all four as fallback.

Then all nodes should keep fallbacks.

Quoted 15 lines
Quoted 13 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 45

Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart

No, this has to be specific/fixed list.

Quoted 6 lines

I wanted to highlight the fact that it must contain either:
clock-names = "usart";
or
clock-names = "usart", "gclk";

What would be the recommended way of doing this then?

We have an example for this.

https://elixir.bootlin.com/linux/v5.19/source/Documentation/devicetree/bindings/example-schema.yaml#L91

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

In reply to Krzysztof Kozlowski
Quoted 101 lines · Krzysztof Kozlowski
Quoted 22 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
new file mode 100644
index 000000000000..cf15d73fa1e8
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/atmel,at91-usart.yaml#

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
+
+maintainers:
+  - Richard Genoud <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

This looks quite different than bindings and you commit msg is saying it is only a conversion. Mention any changes against original bindings.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +3 -0
+      - const: atmel,at91rm9200-usart
+      - const: atmel,at91sam9260-usart
+      - const: microchip,sam9x60-usart

That's an enum

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 30

Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +12 -0
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart

This is not correct - contradicts earlier one.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 35

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart

What? You wrote above that microchip,sam9x60-dbgu is compatible only with microchip,sam9x60-usart. Now you write it is also compatible with other ones?

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart

No, this has to be specific/fixed list.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 49

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  clocks:
+    minItems: 1
+    maxItems: 2

Not really - define the items. One item could be optional, though.

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  dmas:
+    items:
+      - description: TX DMA Channel

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  atmel,usart-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

No need for |

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 64

Quoted 1 line
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +1 -0
+      Must be either 1 for SPI or 0 for USART.

Mention the header.

Quoted 11 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    enum: [ 0, 1 ]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+if:

Put it under allOf.

I missed this in the first read, but what do you mean by under allOf? The only allOf's in this file are under the then:'s.

Quoted 120 lines
Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+  properties:
+    $nodename:
+      pattern: "^serial@[0-9a-f]+$"
+then:
+  allOf:
+    - $ref: /schemas/serial/serial.yaml#
+    - $ref: /schemas/serial/rs485.yaml#
+
+  properties:
+    atmel,use-dma-rx:

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 94

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      type: boolean
+      description: use of PDC or DMA for receiving data
+
+    atmel,use-dma-tx:
+      type: boolean
+      description: use of PDC or DMA for transmitting data
+
+    atmel,fifo-size:
+      $ref: /schemas/types.yaml#/definitions/uint32
+      description: |

No need for |

Quoted 78 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +78 -0
+        Maximum number of data the RX and TX FIFOs can store for FIFO
+        capable USARTS.
+      enum: [ 16, 32 ]
+
+else:
+  if:
+    properties:
+      $nodename:
+        pattern: "^spi@[0-9a-f]+$"
+  then:
+    allOf:
+      - $ref: /schemas/spi/spi-controller.yaml#
+
+    properties:
+      atmel,usart-mode:
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "#address-cells":
+        const: 1
+
+    required:
+      - atmel,usart-mode
+      - "#size-cells"
+      - "#address-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use PDC */
+    usart0: serial@fff8c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xfff8c000 0x4000>;
+        interrupts = <7>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        rts-gpios = <&pioD 15 GPIO_ACTIVE_LOW>;
+        cts-gpios = <&pioD 16 GPIO_ACTIVE_LOW>;
+        dtr-gpios = <&pioD 17 GPIO_ACTIVE_LOW>;
+        dsr-gpios = <&pioD 18 GPIO_ACTIVE_LOW>;
+        dcd-gpios = <&pioD 20 GPIO_ACTIVE_LOW>;
+        rng-gpios = <&pioD 19 GPIO_ACTIVE_LOW>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* use DMA */
+    usart1: serial@f001c000 {
+        compatible = "atmel,at91sam9260-usart";
+        reg = <0xf001c000 0x100>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        atmel,use-dma-rx;
+        atmel,use-dma-tx;
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        atmel,fifo-size = <32>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 182

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    #include <dt-bindings/mfd/at91-usart.h>
+    #include <dt-bindings/dma/at91.h>
+
+    /* SPI mode */
+    spi0: spi@f001c000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "atmel,at91sam9260-usart";
+        atmel,usart-mode = <AT91_USART_MODE_SPI>;
+        reg = <0xf001c000 0x100>;

compatible, then reg then the reset of properties

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 190

Quoted 8 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +8 -0
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>;
+        clocks = <&usart0_clk>;
+        clock-names = "usart";
+        dmas = <&dma0 2 AT91_DMA_CFG_PER_ID(3)>,
+               <&dma0 2 (AT91_DMA_CFG_PER_ID(4) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
+        dma-names = "tx", "rx";
+        cs-gpios = <&pioB 3 GPIO_ACTIVE_HIGH>;
+    };
Quoted 2 lines

Best regards,
Krzysztof

Regards,
    Sergiu

#8 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 115 lines · On 19/08/2022 12:25, [email protected] wrote:
Quoted 101 lines · Krzysztof Kozlowski
Quoted 22 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
new file mode 100644
index 000000000000..cf15d73fa1e8
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/atmel,at91-usart.yaml#

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
+
+maintainers:
+  - Richard Genoud <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

This looks quite different than bindings and you commit msg is saying it is only a conversion. Mention any changes against original bindings.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +3 -0
+      - const: atmel,at91rm9200-usart
+      - const: atmel,at91sam9260-usart
+      - const: microchip,sam9x60-usart

That's an enum

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 30

Quoted 12 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +12 -0
+      - items:
+          - const: atmel,at91rm9200-dbgu
+          - const: atmel,at91rm9200-usart
+      - items:
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+      - items:
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-usart

This is not correct - contradicts earlier one.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 35

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +5 -0
+      - items:
+          - const: microchip,sam9x60-dbgu
+          - const: microchip,sam9x60-usart
+          - const: atmel,at91sam9260-dbgu
+          - const: atmel,at91sam9260-usart

What? You wrote above that microchip,sam9x60-dbgu is compatible only with microchip,sam9x60-usart. Now you write it is also compatible with other ones?

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    contains:
+      const: usart

No, this has to be specific/fixed list.

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 49

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  clocks:
+    minItems: 1
+    maxItems: 2

Not really - define the items. One item could be optional, though.

Quoted 4 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +4 -0
+
+  dmas:
+    items:
+      - description: TX DMA Channel

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+      - description: RX DMA Channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  atmel,usart-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

No need for |

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 64

Quoted 1 line
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +1 -0
+      Must be either 1 for SPI or 0 for USART.

Mention the header.

Quoted 11 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +10 -0
+    enum: [ 0, 1 ]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+if:

Put it under allOf.

Quoted 3 lines

I missed this in the first read, but what do you mean by under allOf? The only allOf's in this file are under the then:'s.

It means that "if:" is preferred to be under allOf, just like example schema is showing:
https://elixir.bootlin.com/linux/v5.19/source/Documentation/devicetree/bindings/example-schema.yaml

Not some other allOf, which could be many in your bindings. The one allOf in top-level, just like example schema.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

In reply to Sergiu Moga

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
 .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
 .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
 2 files changed, 190 insertions(+), 98 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml
 delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Regards,
    Sergiu

#11 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 23 lines · On 19/08/2022 11:38, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Sorry, but that's poor argument. Driver subsystems match Linux convention, not necessarily hardware type/naming. Bindings directories match hardware. MFD bindings are only for MFD wrapper drivers and this is a serial interface. Not a MFD. You even do not add MFD devices in the driver but add *always one* device depending on serial feature you want. This is not even MFD device but regular platform device with children.

You put it in SoC, though, because all other SoCs store it there...

Best regards,
Krzysztof

#12 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 30 lines · Krzysztof Kozlowski
Quoted 23 lines · On 19/08/2022 11:38, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Quoted 8 lines

Sorry, but that's poor argument. Driver subsystems match Linux convention, not necessarily hardware type/naming. Bindings directories match hardware. MFD bindings are only for MFD wrapper drivers and this is a serial interface. Not a MFD. You even do not add MFD devices in the driver but add *always one* device depending on serial feature you want. This is not even MFD device but regular platform device with children.

You put it in SoC, though, because all other SoCs store it there...

The last one should be:

You could put it in SoC, though, because all other SoCs store it there...

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 38 lines · Krzysztof Kozlowski
Quoted 37 lines · Krzysztof Kozlowski
Quoted 23 lines · On 19/08/2022 11:38, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
   .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
   .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
   2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Sorry, but that's poor argument. Driver subsystems match Linux convention, not necessarily hardware type/naming. Bindings directories match hardware. MFD bindings are only for MFD wrapper drivers and this is a serial interface. Not a MFD. You even do not add MFD devices in the driver but add *always one* device depending on serial feature you want. This is not even MFD device but regular platform device with children.

Quoted 5 lines
Quoted 1 line

You put it in SoC, though, because all other SoCs store it there...

The last one should be:

You could put it in SoC, though, because all other SoCs store it there...

Hi,

If it this is only a conversion to yaml, why do you want it moved to another dir ?
Perhaps if you consider SoC or serial as a better place, it should be done through a different patch.

Also, disputing whether this is really a MFD or not, is not in the scope of this patch.

Eugen

Quoted 9 lines

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#14 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 29 lines · On 01/09/2022 13:31, [email protected] wrote:
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 8 lines

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 5 lines
Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Sorry, but that's poor argument. Driver subsystems match Linux convention, not necessarily hardware type/naming. Bindings directories match hardware. MFD bindings are only for MFD wrapper drivers and this is a serial interface. Not a MFD. You even do not add MFD devices in the driver but add *always one* device depending on serial feature you want. This is not even MFD device but regular platform device with children.

Quoted 5 lines
Quoted 1 line

You put it in SoC, though, because all other SoCs store it there...

The last one should be:

You could put it in SoC, though, because all other SoCs store it there...

Hi,

Quoted 8 lines

If it this is only a conversion to yaml, why do you want it moved to another dir ?
Perhaps if you consider SoC or serial as a better place, it should be done through a different patch.

Also, disputing whether this is really a MFD or not, is not in the scope of this patch.

Because you are converting - thus renaming - the bindings, so this is the place to put them in proper place. The conversion to DT Schema comes pretty often with small fixups, so proper location is one of them. That's quite common case.

Best regards,
Krzysztof

maintainer
#15 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

In reply to [email protected]
Quoted 23 lines · On Fri, 19 Aug 2022, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
  .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
  .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
  2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Looks like a UART driver to me.

Which MFD driver does this pertain to?

Signature · 1 line
Lee Jones [李琼斯]
#16 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 32 lines · Lee Jones
Quoted 23 lines · On Fri, 19 Aug 2022, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
   .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
   .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
   2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Quoted 6 lines

Looks like a UART driver to me.

Which MFD driver does this pertain to?

--
Lee Jones [李琼斯]

Hi,

It's this one: drivers/mfd/at91-usart.c[1]

[1]
https://elixir.bootlin.com/linux/v6.0-rc4/source/drivers/mfd/at91-usart.c

Regards,
Sergiu

#17 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 40 lines · On 05/09/2022 17:22, [email protected] wrote:
Quoted 32 lines · Lee Jones
Quoted 23 lines · On Fri, 19 Aug 2022, [email protected] wrote:
Quoted 22 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
   .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
   .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
   2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Quoted 6 lines

Looks like a UART driver to me.

Which MFD driver does this pertain to?

--
Lee Jones [李琼斯]

Quoted 7 lines

Hi,

It's this one: drivers/mfd/at91-usart.c[1]

[1]
https://elixir.bootlin.com/linux/v6.0-rc4/source/drivers/mfd/at91-usart.c

Which is not a "real MFD driver" because it probes exactly one child (depending on the chosen serial protocol). Aren't MFD supposed to have more then one child?

Best regards,
Krzysztof

maintainer
#18 lore raw

Re: [PATCH 2/5] dt-bindings: mfd: atmel,at91-usart: convert to json-schema

Quoted 44 lines · Krzysztof Kozlowski
Quoted 43 lines · On 05/09/2022 17:22, [email protected] wrote:
Quoted 29 lines · Lee Jones
Quoted 26 lines · On Fri, 19 Aug 2022, [email protected] wrote:
Quoted 24 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml

Quoted 16 lines · Sergiu Moga

Convert at91 USART DT Binding for Atmel/Microchip SoCs to json-schema format.

---
   .../bindings/mfd/atmel,at91-usart.yaml        | 190 ++++++++++++++++++
   .../devicetree/bindings/mfd/atmel-usart.txt   |  98 ---------
   2 files changed, 190 insertions(+), 98 deletions(-)

create mode 100644 Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml delete mode 100644 Documentation/devicetree/bindings/mfd/atmel-usart.txt

Documentation/devicetree/bindings/mfd/atmel,at91-usart.yaml new file +0 -0
new file mode 100644
index 000000000000..cf15d73fa1e8

One more thing - I think this should be in serial directory, not mfd, even though it includes SPI. MFD is just a Linux naming/wrapper device.

Best regards,
Krzysztof

Quoted 7 lines
Quoted 2 lines

I would rather keep it in this directory, since its corresponding driver is also in the mfd directory.

Looks like a UART driver to me.

Which MFD driver does this pertain to?

Hi,

It's this one: drivers/mfd/at91-usart.c[1]

Quoted 6 lines
Quoted 2 lines

[1]
https://elixir.bootlin.com/linux/v6.0-rc4/source/drivers/mfd/at91-usart.c

Which is not a "real MFD driver" because it probes exactly one child (depending on the chosen serial protocol). Aren't MFD supposed to have more then one child?

It's a single piece of silicon which supports multiple functions.

There is no stipulation detailing simultaneous usage.

Still, happy to receive suggestions on implementing this differently.

Signature · 6 lines
Lee Jones [李琼斯]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#19 lore raw

PATCH 3/5 dt-bindings: mfd: atmel,sama5d2-flexcom: Add USART child node ref binding

In reply to Sergiu Moga

FLEXCOM, among other functionalities, has the ability to offer the USART serial communication protocol. To have the FLEXCOM binding properly validate its USART children nodes, we must reference the correct binding. To differentiate between the SPI of FLEXCOM and the SPI of USART in SPI mode, use the clock-names property, since the latter's respective property is supposed to contain the "usart" string.

---
 .../bindings/mfd/atmel,sama5d2-flexcom.yaml       | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/mfd/atmel,sama5d2-flexcom.yaml +11 -4
index e158af47c326..617331a5e66e 100644
@@ -72,13 +72,20 @@ properties:
 
 patternProperties:
   "^serial@[0-9a-f]+$":
-    type: object
+    $ref: atmel,at91-usart.yaml
     description:
-      Child node describing USART. See atmel-usart.txt for details
-      of USART bindings.
+      Child node describing USART.
 
   "^spi@[0-9a-f]+$":
-    $ref: ../spi/atmel,at91rm9200-spi.yaml
+    if:
+      properties:
+        clock-names:
+          contains:
+            const: usart
+    then:
+      $ref: atmel,at91-usart.yaml
+    else:
+      $ref: ../spi/atmel,at91rm9200-spi.yaml
     description:
       Child node describing SPI.
 
Signature · 1 line
2.25.1
#20 lore raw

PATCH 4/5 clk: at91: sama5d2: Add Generic Clocks for UART/USART

In reply to Sergiu Moga

Add the generic clocks for UART/USART in the sama5d2 driver to allow them to be registered in the Common Clock Framework.

---
 drivers/clk/at91/sama5d2.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/clk/at91/sama5d2.c +10 -0
index cfd0f5e23b99..84156dc52bff 100644
@@ -120,6 +120,16 @@ static const struct {
 	struct clk_range r;
 	int chg_pid;
 } sama5d2_gck[] = {
+	{ .n = "flx0_gclk",   .id = 19, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx1_gclk",   .id = 20, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx2_gclk",   .id = 21, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx3_gclk",   .id = 22, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx4_gclk",   .id = 23, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart0_gclk",  .id = 24, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart1_gclk",  .id = 25, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart2_gclk",  .id = 26, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart3_gclk",  .id = 27, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart4_gclk",  .id = 28, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
 	{ .n = "sdmmc0_gclk", .id = 31, .chg_pid = INT_MIN, },
 	{ .n = "sdmmc1_gclk", .id = 32, .chg_pid = INT_MIN, },
 	{ .n = "tcb0_gclk",   .id = 35, .chg_pid = INT_MIN, .r = { .min = 0, .max = 83000000 }, },
Signature · 1 line
2.25.1
Reviewed-by on v1 4/5
#21 lore raw

Re: [PATCH 4/5] clk: at91: sama5d2: Add Generic Clocks for UART/USART

Quoted 4 lines · Sergiu Moga

Add the generic clocks for UART/USART in the sama5d2 driver to allow them to be registered in the Common Clock Framework.

Quoted 25 lines
---
 drivers/clk/at91/sama5d2.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/clk/at91/sama5d2.c +10 -0
index cfd0f5e23b99..84156dc52bff 100644
@@ -120,6 +120,16 @@ static const struct {
 	struct clk_range r;
 	int chg_pid;
 } sama5d2_gck[] = {
+	{ .n = "flx0_gclk",   .id = 19, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx1_gclk",   .id = 20, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx2_gclk",   .id = 21, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx3_gclk",   .id = 22, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "flx4_gclk",   .id = 23, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart0_gclk",  .id = 24, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart1_gclk",  .id = 25, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart2_gclk",  .id = 26, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart3_gclk",  .id = 27, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
+	{ .n = "uart4_gclk",  .id = 28, .chg_pid = INT_MIN, .r = { .min = 0, .max = 27666666 }, },
 	{ .n = "sdmmc0_gclk", .id = 31, .chg_pid = INT_MIN, },
 	{ .n = "sdmmc1_gclk", .id = 32, .chg_pid = INT_MIN, },
 	{ .n = "tcb0_gclk",   .id = 35, .chg_pid = INT_MIN, .r = { .min = 0, .max = 83000000 }, },
maintainer
#22 lore raw

Re: [PATCH 4/5] clk: at91: sama5d2: Add Generic Clocks for UART/USART

In reply to Sergiu Moga

Quoting Sergiu Moga (2022-08-17 00:55:17)

Quoted 5 lines

Add the generic clocks for UART/USART in the sama5d2 driver to allow them to be registered in the Common Clock Framework.

---

Should I pick this up to clk-next or did you want to take it via another tree?

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#23 lore raw

Re: [PATCH 4/5] clk: at91: sama5d2: Add Generic Clocks for UART/USART

Quoted 11 lines · Stephen Boyd

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoting Sergiu Moga (2022-08-17 00:55:17)

Quoted 5 lines

Add the generic clocks for UART/USART in the sama5d2 driver to allow them to be registered in the Common Clock Framework.

---

Should I pick this up to clk-next or did you want to take it via another tree?

For me it's OK if it goes though clk-next.

Thank you,
Claudiu Beznea

#24 lore raw

PATCH 5/5 tty: serial: atmel: Make the driver aware of the existence of GCLK

In reply to Sergiu Moga

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
 drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++-
 drivers/tty/serial/atmel_serial.h |  1 +
 2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +51 -1
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/console.h>
 #include <linux/sysrq.h>
 #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
 #endif
 
 #define ATMEL_ISR_PASS_LIMIT	256
+#define ERROR_RATE(desired_value, actual_value) \
+	((int)(100 - ((desired_value) * 100) / (actual_value)))
 
 struct atmel_dma_buffer {
 	unsigned char	*buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
 struct atmel_uart_port {
 	struct uart_port	uart;		/* uart */
 	struct clk		*clk;		/* uart clock */
+	struct clk		*gclk;		/* uart generic clock */
 	int			may_wakeup;	/* cached value of device_may_wakeup for times we need to disable it */
 	u32			backup_imr;	/* IMR saved during suspend */
 	int			break_active;	/* break being received */
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
 		 * This is called on uart_close() or a suspend event.
 		 */
 		clk_disable_unprepare(atmel_port->clk);
+		if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);
 		break;
 	default:
 		dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 {
 	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 	unsigned long flags;
-	unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+	unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+	unsigned int baud, actual_baud, gclk_rate;
 
 	/* save the current mode register */
 	mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 		cd /= 8;
 		mode |= ATMEL_US_USCLKS_MCK_DIV8;
 	}
+
+	/*
+	 * If there is no Fractional Part, there is a high chance that
+	 * we may be able to generate a baudrate closer to the desired one
+	 * if we use the GCLK as the clock source driving the baudrate
+	 * generator.
+	 */
+	if (!fp && atmel_port->gclk) {
+		if (__clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);
+		clk_set_rate(atmel_port->gclk, 16 * baud);
+		gclk_rate = clk_get_rate(atmel_port->gclk);
+		actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+		if (abs(ERROR_RATE(baud, actual_baud)) >
+		    abs(ERROR_RATE(baud, gclk_rate / 16))) {
+			mode |= ATMEL_US_GCLK;
+
+			/*
+			 * Set the Clock Divisor for GCLK to 1.
+			 * Since we were able to generate the smallest
+			 * multiple of the desired baudrate times 16,
+			 * then we surely can generate a bigger multiple
+			 * with the exact error rate for an equally increased
+			 * CD. Thus no need to take into account
+			 * a higher value for CD.
+			 */
+			cd = 1;
+			clk_prepare_enable(atmel_port->gclk);
+		}
+	}
+
 	quot = cd | fp << ATMEL_US_FP_OFFSET;
 
 	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
+	atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (atmel_port->gclk) {
+		ret = clk_prepare_enable(atmel_port->gclk);
+		if (ret) {
+			atmel_port->gclk = NULL;
+			return ret;
+		}
+		clk_disable_unprepare(atmel_port->gclk);
+	}
+
 	ret = atmel_init_port(atmel_port, pdev);
 	if (ret)
 		goto err_clk_disable_unprepare;
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	 * is used
 	 */
 	clk_disable_unprepare(atmel_port->clk);
+	if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+		clk_disable_unprepare(atmel_port->gclk);
 
 	return 0;
 
drivers/tty/serial/atmel_serial.h +1 -0
index 0d8a0f9cc5c3..fb718972f81a 100644
@@ -63,6 +63,7 @@
 #define		ATMEL_US_PAR_MARK		(3 <<  9)
 #define		ATMEL_US_PAR_NONE		(4 <<  9)
 #define		ATMEL_US_PAR_MULTI_DROP		(6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)
 #define	ATMEL_US_NBSTOP		GENMASK(13, 12)	/* Number of Stop Bits */
 #define		ATMEL_US_NBSTOP_1		(0 << 12)
 #define		ATMEL_US_NBSTOP_1_5		(1 << 12)
Signature · 1 line
2.25.1
#25 lore raw

Re: [PATCH 5/5] tty: serial: atmel: Make the driver aware of the existence of GCLK

Le 17/08/2022 à 09:55, Sergiu Moga a écrit :

Quoted 133 lines

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
  drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++-
  drivers/tty/serial/atmel_serial.h |  1 +
  2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +51 -1
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
  #include <linux/init.h>
  #include <linux/serial.h>
  #include <linux/clk.h>
+#include <linux/clk-provider.h>
  #include <linux/console.h>
  #include <linux/sysrq.h>
  #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
  #endif
 
  #define ATMEL_ISR_PASS_LIMIT	256
+#define ERROR_RATE(desired_value, actual_value) \
+	((int)(100 - ((desired_value) * 100) / (actual_value)))
 
  struct atmel_dma_buffer {
  	unsigned char	*buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
  struct atmel_uart_port {
  	struct uart_port	uart;		/* uart */
  	struct clk		*clk;		/* uart clock */
+	struct clk		*gclk;		/* uart generic clock */
  	int			may_wakeup;	/* cached value of device_may_wakeup for times we need to disable it */
  	u32			backup_imr;	/* IMR saved during suspend */
  	int			break_active;	/* break being received */
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
  		 * This is called on uart_close() or a suspend event.
  		 */
  		clk_disable_unprepare(atmel_port->clk);
+		if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);
  		break;
  	default:
  		dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  {
  	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
  	unsigned long flags;
-	unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+	unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+	unsigned int baud, actual_baud, gclk_rate;
 
  	/* save the current mode register */
  	mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  		cd /= 8;
  		mode |= ATMEL_US_USCLKS_MCK_DIV8;
  	}
+
+	/*
+	 * If there is no Fractional Part, there is a high chance that
+	 * we may be able to generate a baudrate closer to the desired one
+	 * if we use the GCLK as the clock source driving the baudrate
+	 * generator.
+	 */
+	if (!fp && atmel_port->gclk) {
+		if (__clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);
+		clk_set_rate(atmel_port->gclk, 16 * baud);
+		gclk_rate = clk_get_rate(atmel_port->gclk);
+		actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+		if (abs(ERROR_RATE(baud, actual_baud)) >
+		    abs(ERROR_RATE(baud, gclk_rate / 16))) {
+			mode |= ATMEL_US_GCLK;
+
+			/*
+			 * Set the Clock Divisor for GCLK to 1.
+			 * Since we were able to generate the smallest
+			 * multiple of the desired baudrate times 16,
+			 * then we surely can generate a bigger multiple
+			 * with the exact error rate for an equally increased
+			 * CD. Thus no need to take into account
+			 * a higher value for CD.
+			 */
+			cd = 1;
+			clk_prepare_enable(atmel_port->gclk);
+		}
+	}
+
  	quot = cd | fp << ATMEL_US_FP_OFFSET;
 
  	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	if (ret)
  		goto err;
 
+	atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (atmel_port->gclk) {
+		ret = clk_prepare_enable(atmel_port->gclk);
+		if (ret) {
+			atmel_port->gclk = NULL;
+			return ret;
+		}
+		clk_disable_unprepare(atmel_port->gclk);
+	}
+
  	ret = atmel_init_port(atmel_port, pdev);
  	if (ret)
  		goto err_clk_disable_unprepare;
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	 * is used
  	 */
  	clk_disable_unprepare(atmel_port->clk);
+	if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+		clk_disable_unprepare(atmel_port->gclk);
 
  	return 0;
 
drivers/tty/serial/atmel_serial.h +0 -0
index 0d8a0f9cc5c3..fb718972f81a 100644

drivers/tty/serial/atmel_serial.h line 69

Quoted 7 lines
drivers/tty/serial/atmel_serial.h +1 -0
@@ -63,6 +63,7 @@
  #define		ATMEL_US_PAR_MARK		(3 <<  9)
  #define		ATMEL_US_PAR_NONE		(4 <<  9)
  #define		ATMEL_US_PAR_MULTI_DROP		(6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)
  #define	ATMEL_US_NBSTOP		GENMASK(13, 12)	/* Number of Stop Bits */
  #define		ATMEL_US_NBSTOP_1		(0 << 12)
  #define		ATMEL_US_NBSTOP_1_5		(1 << 12)

Correct me if I'm wrong, but GCLK is selected by the bit 12 only in UART_MR, not in USART_MR.
In USART_MR, it seems to be controlled by bits 4-5 (and bit 12 is for stop bits, as we can see above, and in the datasheet). cf https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA5D2-Series-Datasheet-DS60001476H.pdf
page 1637

Regards,
Richard.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#26 lore raw

Re: [PATCH 5/5] tty: serial: atmel: Make the driver aware of the existence of GCLK

Quoted 161 lines · Richard Genoud
Quoted 148 lines · Sergiu Moga

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
  drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++- drivers/tty/serial/atmel_serial.h |  1 +

  2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +3 -0
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
   #include <linux/init.h>
   #include <linux/serial.h>
   #include <linux/clk.h>
+#include <linux/clk-provider.h>
   #include <linux/console.h>
   #include <linux/sysrq.h>
   #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
   #endif
 
   #define ATMEL_ISR_PASS_LIMIT        256
+#define ERROR_RATE(desired_value, actual_value) \
+     ((int)(100 - ((desired_value) * 100) / (actual_value)))
 
   struct atmel_dma_buffer {
       unsigned char   *buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
   struct atmel_uart_port {

      struct uart_port        uart;           /* uart */ struct clk              *clk;           /* uart clock */ +     struct clk              *gclk;          /* uart generic clock */ int                     may_wakeup;     /* cached value of device_may_wakeup for times we need to disable it */
      u32                     backup_imr;     /* IMR saved during suspend */
      int                     break_active;   /* break being received */

drivers/tty/serial/atmel_serial.c +2 -0
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port 
 *port, unsigned int state,
                * This is called on uart_close() or a suspend event.
                */
               clk_disable_unprepare(atmel_port->clk);
+             if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+                     clk_disable_unprepare(atmel_port->gclk);
               break;

      default:
              dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);

drivers/tty/serial/atmel_serial.c +2 -1
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port 
 *port, struct ktermios *termios,
   {
       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
       unsigned long flags;
-     unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+     unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+     unsigned int baud, actual_baud, gclk_rate;
 
       /* save the current mode register */

      mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);

drivers/tty/serial/atmel_serial.c +23 -0
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port 
 *port, struct ktermios *termios,
               cd /= 8;
               mode |= ATMEL_US_USCLKS_MCK_DIV8;
       }
+
+     /*
+      * If there is no Fractional Part, there is a high chance that
+      * we may be able to generate a baudrate closer to the desired one
+      * if we use the GCLK as the clock source driving the baudrate
+      * generator.
+      */
+     if (!fp && atmel_port->gclk) {
+             if (__clk_is_enabled(atmel_port->gclk))
+                     clk_disable_unprepare(atmel_port->gclk);
+             clk_set_rate(atmel_port->gclk, 16 * baud);
+             gclk_rate = clk_get_rate(atmel_port->gclk);
+             actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+             if (abs(ERROR_RATE(baud, actual_baud)) >
+                 abs(ERROR_RATE(baud, gclk_rate / 16))) {
+                     mode |= ATMEL_US_GCLK;
+
+                     /*
+                      * Set the Clock Divisor for GCLK to 1.
+                      * Since we were able to generate the smallest
+                      * multiple of the desired baudrate times 16,
+                      * then we surely can generate a bigger multiple
+                      * with the exact error rate for an equally 

increased
+                      * CD. Thus no need to take into account +                      * a higher value for CD.
+                      */
+                     cd = 1;
+                     clk_prepare_enable(atmel_port->gclk); +             }
+     }
+
      quot = cd | fp << ATMEL_US_FP_OFFSET;

      if (!(port->iso7816.flags & SER_ISO7816_ENABLED))

drivers/tty/serial/atmel_serial.c +10 -0
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct 
 platform_device *pdev)
       if (ret)
               goto err;
 
+     atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+     if (atmel_port->gclk) {
+             ret = clk_prepare_enable(atmel_port->gclk);
+             if (ret) {
+                     atmel_port->gclk = NULL;
+                     return ret;
+             }
+             clk_disable_unprepare(atmel_port->gclk);
+     }
+
       ret = atmel_init_port(atmel_port, pdev);
       if (ret)

              goto err_clk_disable_unprepare;

drivers/tty/serial/atmel_serial.c +2 -0
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct 
 platform_device *pdev)
        * is used
        */
       clk_disable_unprepare(atmel_port->clk);
+     if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+             clk_disable_unprepare(atmel_port->gclk);
 
       return 0;
drivers/tty/serial/atmel_serial.h +1 -0
index 0d8a0f9cc5c3..fb718972f81a 100644
@@ -63,6 +63,7 @@
   #define             ATMEL_US_PAR_MARK               (3 <<  9)
   #define             ATMEL_US_PAR_NONE               (4 <<  9)
   #define             ATMEL_US_PAR_MULTI_DROP         (6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)
   #define     ATMEL_US_NBSTOP         GENMASK(13, 12) /* Number of 
Quoted 3 lines

Stop Bits */
  #define             ATMEL_US_NBSTOP_1               (0 << 12) #define             ATMEL_US_NBSTOP_1_5             (1 << 12)

Correct me if I'm wrong, but GCLK is selected by the bit 12 only in UART_MR, not in USART_MR.
In USART_MR, it seems to be controlled by bits 4-5 (and bit 12 is for stop bits, as we can see above, and in the datasheet).
cf
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA5D2-Series-Datasheet-DS60001476H.pdf

Quoted 4 lines

page 1637

Regards,
Richard.

Yes, you are correct, this should have been called ATMEL_UA_GCLK instead. I think I will add both ATMEL_UA_GCLK and ATMEL_US_GCLK bits and an additional field in struct atmel_uart_port to hold ATMEL_UA_GCLK for UART or ATMEL_US_GCLK for USART. I guess this field should be set in atmel_get_ip_name(), the same place where the decision between ATMEL_UA_RTOR and ATMEL_US_RTOR is taken.

Thanks,
Sergiu

#27 lore raw

Re: [PATCH 5/5] tty: serial: atmel: Make the driver aware of the existence of GCLK

In reply to Sergiu Moga
Quoted 46 lines · Sergiu Moga

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
 drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++-
 drivers/tty/serial/atmel_serial.h |  1 +
 2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +4 -0
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/console.h>
 #include <linux/sysrq.h>
 #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
 #endif
 
 #define ATMEL_ISR_PASS_LIMIT	256
+#define ERROR_RATE(desired_value, actual_value) \
+	((int)(100 - ((desired_value) * 100) / (actual_value)))
 
 struct atmel_dma_buffer {
 	unsigned char	*buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
 struct atmel_uart_port {
 	struct uart_port	uart;		/* uart */
 	struct clk		*clk;		/* uart clock */
+	struct clk		*gclk;		/* uart generic clock */
 	int			may_wakeup;	/* cached value of device_may_wakeup for times we need to disable it */
 	u32			backup_imr;	/* IMR saved during suspend */
 	int			break_active;	/* break being received */

drivers/tty/serial/atmel_serial.c static void atmel_serial_pm(struct uart_port *port, unsigned int state, · line 2122

Quoted 4 lines
drivers/tty/serial/atmel_serial.c +1 -0
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
 		 * This is called on uart_close() or a suspend event.
 		 */
 		clk_disable_unprepare(atmel_port->clk);
+		if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))

No need to check for atmel_port->gclk != NULL. clk APIs are already doing this.

Quoted 18 lines
drivers/tty/serial/atmel_serial.c +3 -1
+			clk_disable_unprepare(atmel_port->gclk);
 		break;
 	default:
 		dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 {
 	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 	unsigned long flags;
-	unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+	unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+	unsigned int baud, actual_baud, gclk_rate;
 
 	/* save the current mode register */
 	mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 		cd /= 8;
 		mode |= ATMEL_US_USCLKS_MCK_DIV8;
 	}

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2307

Quoted 10 lines
drivers/tty/serial/atmel_serial.c +10 -0
+
+	/*
+	 * If there is no Fractional Part, there is a high chance that
+	 * we may be able to generate a baudrate closer to the desired one
+	 * if we use the GCLK as the clock source driving the baudrate
+	 * generator.
+	 */
+	if (!fp && atmel_port->gclk) {
+		if (__clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);

You disabled it here, set new rate but re-enable it conditionally above, is this intended? the below condition may fail.

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2309

Quoted 2 lines
drivers/tty/serial/atmel_serial.c +2 -0
+		clk_set_rate(atmel_port->gclk, 16 * baud);
+		gclk_rate = clk_get_rate(atmel_port->gclk);

You should be able to use clk_round_rate() here:

		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);

With this you can re-write all this block something like:

		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);
		actual_baud = gclk_rate / (16 * cd);
		if (abs(ERROR_RATE(baud, actual_baud)) >
		    abd(ERROR_RATE(baud, gclk_rate / 16))) {
			mode |= ATMEL_US_GCLK;
			cd = 1;
			if (__clk_is_enabled(atmel_port->gclk))
				clk_disable_unprepare(atmel_port->gclk)
			clk_set_rate(atmel_port->gclk, gclk_rate);
			clk_prepare_enable(atmel_port->gclk);
		}
Quoted 24 lines
drivers/tty/serial/atmel_serial.c +19 -0
+		actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+		if (abs(ERROR_RATE(baud, actual_baud)) >
+		    abs(ERROR_RATE(baud, gclk_rate / 16))) {
+			mode |= ATMEL_US_GCLK;
+
+			/*
+			 * Set the Clock Divisor for GCLK to 1.
+			 * Since we were able to generate the smallest
+			 * multiple of the desired baudrate times 16,
+			 * then we surely can generate a bigger multiple
+			 * with the exact error rate for an equally increased
+			 * CD. Thus no need to take into account
+			 * a higher value for CD.
+			 */
+			cd = 1;
+			clk_prepare_enable(atmel_port->gclk);
+		}
+	}
+
 	quot = cd | fp << ATMEL_US_FP_OFFSET;
 
 	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	if (ret)

drivers/tty/serial/atmel_serial.c static int atmel_serial_probe(struct platform_device *pdev) · line 2931

Quoted 10 lines
drivers/tty/serial/atmel_serial.c +8 -0
 		goto err;
 
+	atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (atmel_port->gclk) {
+		ret = clk_prepare_enable(atmel_port->gclk);
+		if (ret) {
+			atmel_port->gclk = NULL;
+			return ret;
+		}
+		clk_disable_unprepare(atmel_port->gclk);

Is there a reason you enable then disable the clock here?

drivers/tty/serial/atmel_serial.c static int atmel_serial_probe(struct platform_device *pdev) · line 2981

Quoted 11 lines
drivers/tty/serial/atmel_serial.c +4 -0
+	}
+
 	ret = atmel_init_port(atmel_port, pdev);
 	if (ret)
 		goto err_clk_disable_unprepare;
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	 * is used
 	 */
 	clk_disable_unprepare(atmel_port->clk);
+	if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+		clk_disable_unprepare(atmel_port->gclk);

Is this due to the enable in atmel_set_termios()? Is that called on probe path? Also, there is no need to check for atmel_port->gclk as clk APIs are already doing this.

drivers/tty/serial/atmel_serial.h line 66

Quoted 12 lines
drivers/tty/serial/atmel_serial.c +0 -0
 	return 0;
 
drivers/tty/serial/atmel_serial.h +1 -0
index 0d8a0f9cc5c3..fb718972f81a 100644
@@ -63,6 +63,7 @@
 #define		ATMEL_US_PAR_MARK		(3 <<  9)
 #define		ATMEL_US_PAR_NONE		(4 <<  9)
 #define		ATMEL_US_PAR_MULTI_DROP		(6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)

It seems there are spaces here.

Quoted 3 lines
drivers/tty/serial/atmel_serial.h +0 -0
 #define	ATMEL_US_NBSTOP		GENMASK(13, 12)	/* Number of Stop Bits */
 #define		ATMEL_US_NBSTOP_1		(0 << 12)
 #define		ATMEL_US_NBSTOP_1_5		(1 << 12)
#28 lore raw

Re: [PATCH 5/5] tty: serial: atmel: Make the driver aware of the existence of GCLK

Quoted 77 lines · Claudiu Beznea
Quoted 46 lines · Sergiu Moga

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
  drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++-
  drivers/tty/serial/atmel_serial.h |  1 +
  2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +4 -0
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
  #include <linux/init.h>
  #include <linux/serial.h>
  #include <linux/clk.h>
+#include <linux/clk-provider.h>
  #include <linux/console.h>
  #include <linux/sysrq.h>
  #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
  #endif
 
  #define ATMEL_ISR_PASS_LIMIT	256
+#define ERROR_RATE(desired_value, actual_value) \
+	((int)(100 - ((desired_value) * 100) / (actual_value)))
 
  struct atmel_dma_buffer {
  	unsigned char	*buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
  struct atmel_uart_port {
  	struct uart_port	uart;		/* uart */
  	struct clk		*clk;		/* uart clock */
+	struct clk		*gclk;		/* uart generic clock */
  	int			may_wakeup;	/* cached value of device_may_wakeup for times we need to disable it */
  	u32			backup_imr;	/* IMR saved during suspend */
  	int			break_active;	/* break being received */

drivers/tty/serial/atmel_serial.c static void atmel_serial_pm(struct uart_port *port, unsigned int state, · line 2122

Quoted 4 lines
drivers/tty/serial/atmel_serial.c +1 -0
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
  		 * This is called on uart_close() or a suspend event.
  		 */
  		clk_disable_unprepare(atmel_port->clk);
+		if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))

No need to check for atmel_port->gclk != NULL. clk APIs are already doing this.

Quoted 23 lines
drivers/tty/serial/atmel_serial.c +8 -1
+			clk_disable_unprepare(atmel_port->gclk);
  		break;
  	default:
  		dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  {
  	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
  	unsigned long flags;
-	unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+	unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+	unsigned int baud, actual_baud, gclk_rate;
 
  	/* save the current mode register */
  	mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  		cd /= 8;
  		mode |= ATMEL_US_USCLKS_MCK_DIV8;
  	}
+
+	/*
+	 * If there is no Fractional Part, there is a high chance that
+	 * we may be able to generate a baudrate closer to the desired one
+	 * if we use the GCLK as the clock source driving the baudrate
Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2307

Quoted 5 lines
drivers/tty/serial/atmel_serial.c +5 -0
+	 * generator.
+	 */
+	if (!fp && atmel_port->gclk) {
+		if (__clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);

You disabled it here, set new rate but re-enable it conditionally above, is this intended? the below condition may fail.

Yes, it is intended. Gclk should remain disabled if the below condition fails.

Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2309

Quoted 2 lines
drivers/tty/serial/atmel_serial.c +2 -0
+		clk_set_rate(atmel_port->gclk, 16 * baud);
+		gclk_rate = clk_get_rate(atmel_port->gclk);

You should be able to use clk_round_rate() here:

		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);

With this you can re-write all this block something like:

Quoted 14 lines
		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);
		actual_baud = gclk_rate / (16 * cd);
		if (abs(ERROR_RATE(baud, actual_baud)) >
		    abd(ERROR_RATE(baud, gclk_rate / 16))) {
			mode |= ATMEL_US_GCLK;
			cd = 1;
			if (__clk_is_enabled(atmel_port->gclk))
				clk_disable_unprepare(atmel_port->gclk)
			clk_set_rate(atmel_port->gclk, gclk_rate);
			clk_prepare_enable(atmel_port->gclk);
		}

Hmm, yes, you are right, it is much better with this clk_round_rate() since there would be no need to disable gclk before setting the new rate, I did not know of this function at that point. However, in this case, the if(abs...) will also need an else to disable the gclk in case the condition failed and it was somehow enabled before.

Quoted 26 lines
Quoted 26 lines
drivers/tty/serial/atmel_serial.c +19 -0
+		actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+		if (abs(ERROR_RATE(baud, actual_baud)) >
+		    abs(ERROR_RATE(baud, gclk_rate / 16))) {
+			mode |= ATMEL_US_GCLK;
+
+			/*
+			 * Set the Clock Divisor for GCLK to 1.
+			 * Since we were able to generate the smallest
+			 * multiple of the desired baudrate times 16,
+			 * then we surely can generate a bigger multiple
+			 * with the exact error rate for an equally increased
+			 * CD. Thus no need to take into account
+			 * a higher value for CD.
+			 */
+			cd = 1;
+			clk_prepare_enable(atmel_port->gclk);
+		}
+	}
+
  	quot = cd | fp << ATMEL_US_FP_OFFSET;
 
  	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	if (ret)
  		goto err;
 
Quoted 11 lines

drivers/tty/serial/atmel_serial.c static int atmel_serial_probe(struct platform_device *pdev) · line 2931

Quoted 8 lines
drivers/tty/serial/atmel_serial.c +8 -0
+	atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (atmel_port->gclk) {
+		ret = clk_prepare_enable(atmel_port->gclk);
+		if (ret) {
+			atmel_port->gclk = NULL;
+			return ret;
+		}
+		clk_disable_unprepare(atmel_port->gclk);

Is there a reason you enable then disable the clock here?

I think it's better to make sure in the probe method that enabling the gclk issues no errors, so that the error does not appear in set_termios(). Since the user must place the optional gclk in DT if they want a finer rate when missing the Fractional Part, I think they should know before even trying to open the port that it is first correctly setup in the clock tree as well by making the probe method fail from the very beginning in case it is not.

So, I first enable it and make sure there are no errors and then disable it because I do not see the point of having an enabled clock that might not be used.

Quoted 7 lines
Quoted 7 lines
drivers/tty/serial/atmel_serial.c +2 -0
+	}
+
  	ret = atmel_init_port(atmel_port, pdev);
  	if (ret)
  		goto err_clk_disable_unprepare;
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	 * is used
Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_serial_pm(struct uart_port *port, unsigned int state, · line 2123

Quoted 4 lines
drivers/tty/serial/atmel_serial.c +2 -0
  	 */
  	clk_disable_unprepare(atmel_port->clk);
+	if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+		clk_disable_unprepare(atmel_port->gclk);

Is this due to the enable in atmel_set_termios()? Is that called on probe path? Also, there is no need to check for atmel_port->gclk as clk APIs are already doing this.

No, I guess this is not really needed, since it is disabled once it is claimed from DT if enabling it succeeds. I initially placed this code sequence wherever the peripheral clock is disabled as well.

Quoted 19 lines

drivers/tty/serial/atmel_serial.h line 66

Quoted 12 lines
drivers/tty/serial/atmel_serial.c +0 -0
  	return 0;
 
drivers/tty/serial/atmel_serial.h +1 -0
index 0d8a0f9cc5c3..fb718972f81a 100644
@@ -63,6 +63,7 @@
  #define		ATMEL_US_PAR_MARK		(3 <<  9)
  #define		ATMEL_US_PAR_NONE		(4 <<  9)
  #define		ATMEL_US_PAR_MULTI_DROP		(6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)

It seems there are spaces here.

Quoted 3 lines
drivers/tty/serial/atmel_serial.h +0 -0
  #define	ATMEL_US_NBSTOP		GENMASK(13, 12)	/* Number of Stop Bits */
  #define		ATMEL_US_NBSTOP_1		(0 << 12)
  #define		ATMEL_US_NBSTOP_1_5		(1 << 12)

Thanks,
Sergiu

#29 lore raw

Re: [PATCH 5/5] tty: serial: atmel: Make the driver aware of the existence of GCLK

Quoted 116 lines · On 31.08.2022 14:32, Sergiu Moga - M68701 wrote:
Quoted 77 lines · Claudiu Beznea
Quoted 46 lines · Sergiu Moga

Previously, the atmel serial driver did not take into account the possibility of using the more customizable generic clock as its baudrate generator. Unless there is a Fractional Part available to increase accuracy, there is a high chance that we may be able to generate a baudrate closer to the desired one by using the GCLK as the clock source. Now, depending on the error rate between
the desired baudrate and the actual baudrate, the serial driver will fallback on the generic clock. The generic clock must be provided in the DT node of the serial that may need a more flexible clock source.

---
  drivers/tty/serial/atmel_serial.c | 52 ++++++++++++++++++++++++++++++-
  drivers/tty/serial/atmel_serial.h |  1 +
  2 files changed, 52 insertions(+), 1 deletion(-)
drivers/tty/serial/atmel_serial.c +4 -0
index 30ba9eef7b39..0a0b46ee0955 100644
@@ -15,6 +15,7 @@
  #include <linux/init.h>
  #include <linux/serial.h>
  #include <linux/clk.h>
+#include <linux/clk-provider.h>
  #include <linux/console.h>
  #include <linux/sysrq.h>
  #include <linux/tty_flip.h>
@@ -77,6 +78,8 @@ static void atmel_stop_rx(struct uart_port *port);
  #endif
 
  #define ATMEL_ISR_PASS_LIMIT	256
+#define ERROR_RATE(desired_value, actual_value) \
+	((int)(100 - ((desired_value) * 100) / (actual_value)))
 
  struct atmel_dma_buffer {
  	unsigned char	*buf;
@@ -110,6 +113,7 @@ struct atmel_uart_char {
  struct atmel_uart_port {
  	struct uart_port	uart;		/* uart */
  	struct clk		*clk;		/* uart clock */
+	struct clk		*gclk;		/* uart generic clock */
  	int			may_wakeup;	/* cached value of device_may_wakeup for times we need to disable it */
  	u32			backup_imr;	/* IMR saved during suspend */
  	int			break_active;	/* break being received */

drivers/tty/serial/atmel_serial.c static void atmel_serial_pm(struct uart_port *port, unsigned int state, · line 2122

Quoted 4 lines
drivers/tty/serial/atmel_serial.c +1 -0
@@ -2115,6 +2119,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
  		 * This is called on uart_close() or a suspend event.
  		 */
  		clk_disable_unprepare(atmel_port->clk);
+		if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))

No need to check for atmel_port->gclk != NULL. clk APIs are already doing this.

Quoted 23 lines
drivers/tty/serial/atmel_serial.c +8 -1
+			clk_disable_unprepare(atmel_port->gclk);
  		break;
  	default:
  		dev_err(port->dev, "atmel_serial: unknown pm %d\n", state);
@@ -2129,7 +2135,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  {
  	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
  	unsigned long flags;
-	unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
+	unsigned int old_mode, mode, imr, quot, div, cd, fp = 0;
+	unsigned int baud, actual_baud, gclk_rate;
 
  	/* save the current mode register */
  	mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2288,6 +2295,37 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
  		cd /= 8;
  		mode |= ATMEL_US_USCLKS_MCK_DIV8;
  	}
+
+	/*
+	 * If there is no Fractional Part, there is a high chance that
+	 * we may be able to generate a baudrate closer to the desired one
+	 * if we use the GCLK as the clock source driving the baudrate
Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2307

Quoted 5 lines
drivers/tty/serial/atmel_serial.c +5 -0
+	 * generator.
+	 */
+	if (!fp && atmel_port->gclk) {
+		if (__clk_is_enabled(atmel_port->gclk))
+			clk_disable_unprepare(atmel_port->gclk);

You disabled it here, set new rate but re-enable it conditionally above, is this intended? the below condition may fail.

Yes, it is intended. Gclk should remain disabled if the below condition fails.

Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · line 2309

Quoted 2 lines
drivers/tty/serial/atmel_serial.c +2 -0
+		clk_set_rate(atmel_port->gclk, 16 * baud);
+		gclk_rate = clk_get_rate(atmel_port->gclk);

You should be able to use clk_round_rate() here:

		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);

With this you can re-write all this block something like:

Quoted 14 lines
		gclk_rate = clk_round_rate(atmel_port->gclk,
					   16 * baudrate);
		actual_baud = gclk_rate / (16 * cd);
		if (abs(ERROR_RATE(baud, actual_baud)) >
		    abd(ERROR_RATE(baud, gclk_rate / 16))) {
			mode |= ATMEL_US_GCLK;
			cd = 1;
			if (__clk_is_enabled(atmel_port->gclk))
				clk_disable_unprepare(atmel_port->gclk)
			clk_set_rate(atmel_port->gclk, gclk_rate);
			clk_prepare_enable(atmel_port->gclk);
		}
Quoted 5 lines

Hmm, yes, you are right, it is much better with this clk_round_rate() since there would be no need to disable gclk before setting the new rate, I did not know of this function at that point. However, in this case, the if(abs...) will also need an else to disable the gclk in case the condition failed and it was somehow enabled before.

Then you can keep the disable at the beginning of the block (as it previously was) and use clk_round_rate() instead of:

		clk_set_rate();
		clk_get_rate();

And use clk_set_rate() only if the following is true:

+ if (abs(ERROR_RATE(baud, actual_baud)) >
+ abs(ERROR_RATE(baud, gclk_rate / 16))) {

Having this, in case gclk cannot be used it is just disable w/o also having the rate changed.

Quoted 41 lines
Quoted 28 lines
Quoted 28 lines
drivers/tty/serial/atmel_serial.c +19 -0
+		actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd);
+		if (abs(ERROR_RATE(baud, actual_baud)) >
+		    abs(ERROR_RATE(baud, gclk_rate / 16))) {
+			mode |= ATMEL_US_GCLK;
+
+			/*
+			 * Set the Clock Divisor for GCLK to 1.
+			 * Since we were able to generate the smallest
+			 * multiple of the desired baudrate times 16,
+			 * then we surely can generate a bigger multiple
+			 * with the exact error rate for an equally increased
+			 * CD. Thus no need to take into account
+			 * a higher value for CD.
+			 */
+			cd = 1;
+			clk_prepare_enable(atmel_port->gclk);
+		}
+	}
+
  	quot = cd | fp << ATMEL_US_FP_OFFSET;
 
  	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
@@ -2883,6 +2921,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	if (ret)
  		goto err;
 
Quoted 11 lines

drivers/tty/serial/atmel_serial.c static int atmel_serial_probe(struct platform_device *pdev) · line 2931

Quoted 8 lines
drivers/tty/serial/atmel_serial.c +8 -0
+	atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (atmel_port->gclk) {
+		ret = clk_prepare_enable(atmel_port->gclk);
+		if (ret) {
+			atmel_port->gclk = NULL;
+			return ret;
+		}
+		clk_disable_unprepare(atmel_port->gclk);

Is there a reason you enable then disable the clock here?

Quoted 7 lines

I think it's better to make sure in the probe method that enabling the gclk issues no errors, so that the error does not appear in set_termios(). Since the user must place the optional gclk in DT if they want a finer rate when missing the Fractional Part, I think they should know before even trying to open the port that it is first correctly setup in the clock tree as well by making the probe method fail from the very beginning in case it is not.

There is no guarantee that the disable/enable in set_termios() will not fail. If you want to avoid failures you can just take into account the returning code of clk_prepare_enable() in set_termios() and decide to use generic clock for baud rate depending on this.

Quoted 50 lines

So, I first enable it and make sure there are no errors and then disable it because I do not see the point of having an enabled clock that might not be used.

Quoted 7 lines
Quoted 7 lines
drivers/tty/serial/atmel_serial.c +2 -0
+	}
+
  	ret = atmel_init_port(atmel_port, pdev);
  	if (ret)
  		goto err_clk_disable_unprepare;
@@ -2929,6 +2977,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
  	 * is used
Quoted 9 lines

drivers/tty/serial/atmel_serial.c static void atmel_serial_pm(struct uart_port *port, unsigned int state, · line 2123

Quoted 4 lines
drivers/tty/serial/atmel_serial.c +2 -0
  	 */
  	clk_disable_unprepare(atmel_port->clk);
+	if (atmel_port->gclk && __clk_is_enabled(atmel_port->gclk))
+		clk_disable_unprepare(atmel_port->gclk);

Is this due to the enable in atmel_set_termios()? Is that called on probe path? Also, there is no need to check for atmel_port->gclk as clk APIs are already doing this.

No, I guess this is not really needed, since it is disabled once it is claimed from DT if enabling it succeeds. I initially placed this code sequence wherever the peripheral clock is disabled as well.

Quoted 19 lines

drivers/tty/serial/atmel_serial.h line 66

Quoted 12 lines
drivers/tty/serial/atmel_serial.c +0 -0
  	return 0;
 
drivers/tty/serial/atmel_serial.h +1 -0
index 0d8a0f9cc5c3..fb718972f81a 100644
@@ -63,6 +63,7 @@
  #define		ATMEL_US_PAR_MARK		(3 <<  9)
  #define		ATMEL_US_PAR_NONE		(4 <<  9)
  #define		ATMEL_US_PAR_MULTI_DROP		(6 <<  9)
+#define ATMEL_US_GCLK                          BIT(12)

It seems there are spaces here.

Quoted 3 lines
drivers/tty/serial/atmel_serial.h +0 -0
  #define	ATMEL_US_NBSTOP		GENMASK(13, 12)	/* Number of Stop Bits */
  #define		ATMEL_US_NBSTOP_1		(0 << 12)
  #define		ATMEL_US_NBSTOP_1_5		(1 << 12)

Thanks,
Sergiu