# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/serial/st,stm32-uart.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

maintainers:
  - Erwan Le Ray <erwan.leray@st.com>

title: STMicroelectronics STM32 USART bindings

properties:
  compatible:
    enum:
      - st,stm32-uart
      - st,stm32f7-uart
      - st,stm32h7-uart

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  clocks:
    maxItems: 1

  resets:
    maxItems: 1

  label:
    description: label associated with this uart

  st,hw-flow-ctrl:
    description: enable hardware flow control (deprecated)
    $ref: /schemas/types.yaml#/definitions/flag

  uart-has-rtscts: true

  rx-tx-swap: true

  dmas:
    minItems: 1
    maxItems: 2

  dma-names:
    items:
      enum: [ rx, tx ]
    minItems: 1
    maxItems: 2

# cts-gpios and rts-gpios properties can be used instead of 'uart-has-rtscts'
# or 'st,hw-flow-ctrl' (deprecated) for making use of any gpio pins for flow
# control instead of dedicated pins.
#
# It should be noted that both cts-gpios/rts-gpios and 'uart-has-rtscts' or
# 'st,hw-flow-ctrl' (deprecated) properties cannot co-exist in a design.
  cts-gpios: true
  rts-gpios: true

  wakeup-source: true

  rs485-rts-delay: true
  rs485-rts-active-low: true
  linux,rs485-enabled-at-boot-time: true
  rs485-rx-during-tx: true

  rx-threshold:
    description:
      If value is set to 1, RX FIFO threshold is disabled.
    enum: [1, 2, 4, 8, 12, 14, 16]
    default: 8

  tx-threshold:
    description:
      If value is set to 1, TX FIFO threshold is disabled.
    enum: [1, 2, 4, 8, 12, 14, 16]
    default: 8

allOf:
  - $ref: rs485.yaml#
  - $ref: serial.yaml#
  - if:
      required:
        - st,hw-flow-ctrl
    then:
      properties:
        cts-gpios: false
        rts-gpios: false
  - if:
      properties:
        compatible:
          const: st,stm32-uart
    then:
      properties:
        rx-tx-swap: false
  - if:
      properties:
        compatible:
          contains:
            enum:
              - st,stm32-uart
              - st,stm32f7-uart
    then:
      properties:
        rx-threshold: false
        tx-threshold: false

required:
  - compatible
  - reg
  - interrupts
  - clocks

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/clock/stm32mp1-clks.h>
    usart1: serial@40011000 {
      compatible = "st,stm32h7-uart";
      reg = <0x40011000 0x400>;
      interrupts = <37>;
      clocks = <&rcc 0 164>;
      dmas = <&dma2 2 4 0x414 0x0>,
             <&dma2 7 4 0x414 0x0>;
      dma-names = "rx", "tx";
      rx-threshold = <4>;
      tx-threshold = <4>;
      rs485-rts-active-low;
    };

...
