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

title: Airoha EN7581 Frame Engine Ethernet controller

maintainers:
  - Lorenzo Bianconi <lorenzo@kernel.org>

description:
  The frame engine ethernet controller can be found on Airoha SoCs.
  These SoCs have multi-GMAC ports.

properties:
  compatible:
    enum:
      - airoha,en7581-eth
      - airoha,an7583-eth

  reg:
    items:
      - description: Frame engine base address
      - description: QDMA0 base address
      - description: QDMA1 base address

  reg-names:
    items:
      - const: fe
      - const: qdma0
      - const: qdma1

  interrupts:
    items:
      - description: QDMA lan irq0
      - description: QDMA lan irq1
      - description: QDMA lan irq2
      - description: QDMA lan irq3
      - description: QDMA wan irq0
      - description: QDMA wan irq1
      - description: QDMA wan irq2
      - description: QDMA wan irq3
      - description: FE error irq
      - description: PDMA irq

  resets:
    minItems: 7
    maxItems: 8

  reset-names:
    items:
      - const: fe
      - const: pdma
      - const: qdma
      - const: xsi-mac
      - const: hsi0-mac
      - const: hsi1-mac
      - enum: [ hsi-mac, xfp-mac ]
      - const: xfp-mac
    minItems: 7

  memory-region:
    items:
      - description: QDMA0 buffer memory
      - description: QDMA1 buffer memory

  memory-region-names:
    items:
      - const: qdma0-buf
      - const: qdma1-buf

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

  airoha,npu:
    $ref: /schemas/types.yaml#/definitions/phandle
    description:
      Phandle to the node used to configure the NPU module.
      The Airoha Network Processor Unit (NPU) provides a configuration
      interface to implement hardware flow offloading programming Packet
      Processor Engine (PPE) flow table.

allOf:
  - $ref: ethernet-controller.yaml#
  - if:
      properties:
        compatible:
          contains:
            enum:
              - airoha,en7581-eth
    then:
      properties:
        resets:
          minItems: 8

        reset-names:
          minItems: 8

  - if:
      properties:
        compatible:
          contains:
            enum:
              - airoha,an7583-eth
    then:
      properties:
        resets:
          maxItems: 7

        reset-names:
          maxItems: 7

patternProperties:
  "^ethernet@[1-4]$":
    type: object
    unevaluatedProperties: false
    $ref: ethernet-controller.yaml#
    description:
      Ethernet GMAC port associated to the MAC controller
    properties:
      compatible:
        const: airoha,eth-mac

      reg:
        minimum: 1
        maximum: 4
        description: GMAC port identifier

    allOf:
      - if:
          properties:
            reg:
              contains:
                items:
                  - enum:
                      - 3
                      - 4
        then:
          properties:
            '#address-cells':
              const: 1

            '#size-cells':
              const: 0

          patternProperties:
            "^ethernet@[0-5]$":
              type: object
              unevaluatedProperties: false
              $ref: ethernet-controller.yaml#
              description: External ethernet port ID available on the GDM port

              properties:
                compatible:
                  const: airoha,eth-port

                reg:
                  maximum: 5
                  description: External ethernet port identifier

              required:
                - reg
                - compatible

    required:
      - reg
      - compatible

required:
  - compatible
  - reg
  - interrupts
  - resets
  - reset-names

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>
    #include <dt-bindings/interrupt-controller/irq.h>
    #include <dt-bindings/clock/en7523-clk.h>

    soc {
      #address-cells = <2>;
      #size-cells = <2>;

      eth: ethernet@1fb50000 {
        compatible = "airoha,en7581-eth";
        reg = <0 0x1fb50000 0 0x2600>,
              <0 0x1fb54000 0 0x2000>,
              <0 0x1fb56000 0 0x2000>;
        reg-names = "fe", "qdma0", "qdma1";

        resets = <&scuclk 44>,
                 <&scuclk 30>,
                 <&scuclk 31>,
                 <&scuclk 6>,
                 <&scuclk 15>,
                 <&scuclk 16>,
                 <&scuclk 17>,
                 <&scuclk 26>;
        reset-names = "fe", "pdma", "qdma", "xsi-mac",
                      "hsi0-mac", "hsi1-mac", "hsi-mac",
                      "xfp-mac";

        interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 56 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 57 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 58 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 60 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH>,
                     <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;

        memory-region = <&qdma0_buf>, <&qdma1_buf>;
        memory-region-names = "qdma0-buf", "qdma1-buf";

        airoha,npu = <&npu>;

        #address-cells = <1>;
        #size-cells = <0>;

        ethernet@1 {
          compatible = "airoha,eth-mac";
          reg = <1>;
        };

        ethernet@4 {
          compatible = "airoha,eth-mac";
          reg = <4>;

          #address-cells = <1>;
          #size-cells = <0>;

          ethernet@0 {
            compatible = "airoha,eth-port";
            reg = <0>;
          };

          ethernet@1 {
            compatible = "airoha,eth-port";
            reg = <1>;
          };
        };
      };
    };