# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/can/renesas,rcar-canfd.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Renesas R-Car CAN FD Controller

maintainers:
  - Fabrizio Castro <fabrizio.castro.jz@renesas.com>

properties:
  compatible:
    oneOf:
      - enum:
          - renesas,r9a09g047-canfd        # RZ/G3E
          - renesas,r9a09g077-canfd        # RZ/T2H

      - items:
          - enum:
              - renesas,r8a774a1-canfd     # RZ/G2M
              - renesas,r8a774b1-canfd     # RZ/G2N
              - renesas,r8a774c0-canfd     # RZ/G2E
              - renesas,r8a774e1-canfd     # RZ/G2H
              - renesas,r8a7795-canfd      # R-Car H3
              - renesas,r8a7796-canfd      # R-Car M3-W
              - renesas,r8a77961-canfd     # R-Car M3-W+
              - renesas,r8a77965-canfd     # R-Car M3-N
              - renesas,r8a77970-canfd     # R-Car V3M
              - renesas,r8a77980-canfd     # R-Car V3H
              - renesas,r8a77990-canfd     # R-Car E3
              - renesas,r8a77995-canfd     # R-Car D3
          - const: renesas,rcar-gen3-canfd # R-Car Gen3 and RZ/G2

      - items:
          - enum:
              - renesas,r8a779a0-canfd     # R-Car V3U
              - renesas,r8a779g0-canfd     # R-Car V4H
              - renesas,r8a779h0-canfd     # R-Car V4M
          - const: renesas,rcar-gen4-canfd # R-Car Gen4

      - items:
          - enum:
              - renesas,r9a07g043-canfd    # RZ/G2UL and RZ/Five
              - renesas,r9a07g044-canfd    # RZ/G2{L,LC}
              - renesas,r9a07g054-canfd    # RZ/V2L
          - const: renesas,rzg2l-canfd     # RZ/G2L family

      - items:
          - enum:
              - renesas,r9a09g056-canfd     # RZ/V2N
              - renesas,r9a09g057-canfd     # RZ/V2H(P)
          - const: renesas,r9a09g047-canfd

      - items:
          - const: renesas,r9a09g087-canfd  # RZ/N2H
          - const: renesas,r9a09g077-canfd

  reg:
    maxItems: 1

  interrupts:
    oneOf:
      - items:
          - description: Channel interrupt
          - description: Global interrupt
      - items:
          - description: CAN global error interrupt
          - description: CAN receive FIFO interrupt
          - description: CAN0 error interrupt
          - description: CAN0 transmit interrupt
          - description: CAN0 transmit/receive FIFO receive completion interrupt
          - description: CAN1 error interrupt
          - description: CAN1 transmit interrupt
          - description: CAN1 transmit/receive FIFO receive completion interrupt
          - description: CAN2 error interrupt
          - description: CAN2 transmit interrupt
          - description: CAN2 transmit/receive FIFO receive completion interrupt
          - description: CAN3 error interrupt
          - description: CAN3 transmit interrupt
          - description: CAN3 transmit/receive FIFO receive completion interrupt
          - description: CAN4 error interrupt
          - description: CAN4 transmit interrupt
          - description: CAN4 transmit/receive FIFO receive completion interrupt
          - description: CAN5 error interrupt
          - description: CAN5 transmit interrupt
          - description: CAN5 transmit/receive FIFO receive completion interrupt
        minItems: 8

  interrupt-names:
    oneOf:
      - items:
          - const: ch_int
          - const: g_int
      - items:
          - const: g_err
          - const: g_recc
          - const: ch0_err
          - const: ch0_rec
          - const: ch0_trx
          - const: ch1_err
          - const: ch1_rec
          - const: ch1_trx
          - const: ch2_err
          - const: ch2_rec
          - const: ch2_trx
          - const: ch3_err
          - const: ch3_rec
          - const: ch3_trx
          - const: ch4_err
          - const: ch4_rec
          - const: ch4_trx
          - const: ch5_err
          - const: ch5_rec
          - const: ch5_trx
        minItems: 8

  clocks:
    maxItems: 3

  clock-names:
    oneOf:
      - items:
          - const: fck
          - const: canfd
          - const: can_clk
      - items:
          - const: fck
          - const: ram_clk
          - const: can_clk

  power-domains:
    maxItems: 1

  resets: true

  reset-names:
    items:
      - const: rstp_n
      - const: rstc_n

  renesas,no-can-fd:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      The controller can operate in either CAN-FD mode (default) or FD-Only
      mode (RZ/{G2L,G3E} and R-Car Gen4) or Classical CAN mode. Specify this
      property to put the controller in Classical CAN mode.

  renesas,fd-only:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      The CANFD on RZ/{G2L,G3E} and R-Car Gen4 SoCs support 3 modes FD-Only
      mode, Classical CAN mode and CAN-FD mode (default). In FD-Only mode,
      communication in Classical CAN frame format is disabled. Specify this
      property to put the controller in FD-Only mode.

  assigned-clocks:
    description:
      Reference to the CANFD clock.  The CANFD clock is a div6 clock and can be
      used by both CAN (if present) and CAN FD controllers at the same time.
      It needs to be scaled to maximum frequency if any of these controllers
      use it.

  assigned-clock-rates:
    description: Maximum frequency of the CANFD clock.

patternProperties:
  "^channel[0-7]$":
    type: object
    description:
      The controller supports multiple channels and each is represented as a
      child node.  Each channel can be enabled/disabled individually.

    properties:
      phys:
        maxItems: 1

    additionalProperties: false

required:
  - compatible
  - reg
  - interrupts
  - interrupt-names
  - clocks
  - clock-names
  - power-domains
  - assigned-clocks
  - assigned-clock-rates
  - channel0
  - channel1

allOf:
  - $ref: can-controller.yaml#

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,rzg2l-canfd
    then:
      properties:
        interrupts:
          maxItems: 8

        interrupt-names:
          maxItems: 8

        resets:
          minItems: 2
          maxItems: 2

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,rcar-gen3-canfd
              - renesas,rcar-gen4-canfd
    then:
      properties:
        interrupts:
          minItems: 2
          maxItems: 2

        interrupt-names:
          minItems: 2
          maxItems: 2

        resets:
          maxItems: 1

  - if:
      properties:
        compatible:
          contains:
            const: renesas,r9a09g047-canfd
    then:
      properties:
        interrupts:
          minItems: 20

        interrupt-names:
          minItems: 20

        resets:
          minItems: 2
          maxItems: 2

  - if:
      properties:
        compatible:
          contains:
            const: renesas,r9a09g077-canfd
    then:
      properties:
        interrupts:
          maxItems: 8

        interrupt-names:
          maxItems: 8

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,r9a09g077-canfd
              - renesas,rcar-gen3-canfd
              - renesas,rzg2l-canfd
    then:
      patternProperties:
        "^channel[2-7]$": false

  - if:
      properties:
        compatible:
          contains:
            const: renesas,r8a779h0-canfd
    then:
      patternProperties:
        "^channel[4-7]$": false

  - if:
      properties:
        compatible:
          contains:
            const: renesas,r9a09g047-canfd
    then:
      patternProperties:
        "^channel[6-7]$": false

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,rcar-gen3-canfd
    then:
      properties:
        renesas,fd-only: false

  - if:
      required:
        - renesas,no-can-fd
    then:
      properties:
        renesas,fd-only: false

  - if:
      required:
        - renesas,fd-only
    then:
      properties:
        renesas,no-can-fd: false

  - if:
      properties:
        compatible:
          contains:
            const: renesas,r9a09g077-canfd
    then:
      properties:
        resets: false
        reset-names: false

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,r9a09g047-canfd
              - renesas,rzg2l-canfd
    then:
      required:
        - resets
        - reset-names

  - if:
      properties:
        compatible:
          contains:
            enum:
              - renesas,rcar-gen3-canfd
              - renesas,rcar-gen4-canfd
    then:
      required:
        - resets
      properties:
        reset-names: false

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/clock/r8a7795-cpg-mssr.h>
    #include <dt-bindings/interrupt-controller/arm-gic.h>
    #include <dt-bindings/power/r8a7795-sysc.h>

    canfd: can@e66c0000 {
            compatible = "renesas,r8a7795-canfd",
                         "renesas,rcar-gen3-canfd";
            reg = <0xe66c0000 0x8000>;
            interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>,
                         <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
            interrupt-names = "ch_int", "g_int";
            clocks = <&cpg CPG_MOD 914>,
                     <&cpg CPG_CORE R8A7795_CLK_CANFD>,
                     <&can_clk>;
            clock-names = "fck", "canfd", "can_clk";
            assigned-clocks = <&cpg CPG_CORE R8A7795_CLK_CANFD>;
            assigned-clock-rates = <40000000>;
            power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
            resets = <&cpg 914>;

            channel0 {
            };

            channel1 {
            };
    };
