# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/display/allwinner,sun4i-a10-tcon.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Allwinner A10 Timings Controller (TCON) Device Tree Bindings

maintainers:
  - Chen-Yu Tsai <wens@csie.org>
  - Maxime Ripard <mripard@kernel.org>

description: |
  The TCON acts as a timing controller for RGB, LVDS and TV
  interfaces.

properties:
  "#clock-cells":
    const: 0

  compatible:
    oneOf:
      - const: allwinner,sun4i-a10-tcon
      - const: allwinner,sun5i-a13-tcon
      - const: allwinner,sun6i-a31-tcon
      - const: allwinner,sun6i-a31s-tcon
      - const: allwinner,sun7i-a20-tcon
      - const: allwinner,sun8i-a23-tcon
      - const: allwinner,sun8i-a33-tcon
      - const: allwinner,sun8i-a83t-tcon-lcd
      - const: allwinner,sun8i-a83t-tcon-tv
      - const: allwinner,sun8i-r40-tcon-tv
      - const: allwinner,sun8i-v3s-tcon
      - const: allwinner,sun9i-a80-tcon-lcd
      - const: allwinner,sun9i-a80-tcon-tv

      - items:
          - enum:
              - allwinner,sun7i-a20-tcon0
              - allwinner,sun7i-a20-tcon1
          - const: allwinner,sun7i-a20-tcon

      - items:
          - enum:
              - allwinner,sun50i-a64-tcon-lcd
          - const: allwinner,sun8i-a83t-tcon-lcd

      - items:
          - enum:
              - allwinner,sun8i-h3-tcon-tv
              - allwinner,sun50i-a64-tcon-tv
          - const: allwinner,sun8i-a83t-tcon-tv

      - items:
          - enum:
              - allwinner,sun50i-h6-tcon-tv
          - const: allwinner,sun8i-r40-tcon-tv

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  clocks:
    minItems: 1
    maxItems: 4

  clock-names:
    minItems: 1
    maxItems: 4

  clock-output-names:
    description:
      Name of the LCD pixel clock created.
    $ref: /schemas/types.yaml#/definitions/string-array
    maxItems: 1

  dmas:
    maxItems: 1

  resets:
    anyOf:
      - items:
          - description: TCON Reset Line

      - items:
          - description: TCON Reset Line
          - description: TCON LVDS Reset Line

      - items:
          - description: TCON Reset Line
          - description: TCON eDP Reset Line

      - items:
          - description: TCON Reset Line
          - description: TCON eDP Reset Line
          - description: TCON LVDS Reset Line

  reset-names:
    oneOf:
      - const: lcd

      - items:
          - const: lcd
          - const: lvds

      - items:
          - const: lcd
          - const: edp

      - items:
          - const: lcd
          - const: edp
          - const: lvds

  ports:
    type: object
    description: |
      A ports node with endpoint definitions as defined in
      Documentation/devicetree/bindings/media/video-interfaces.txt.

    properties:
      "#address-cells":
        const: 1

      "#size-cells":
        const: 0

      port@0:
        type: object
        description: |
          Input endpoints of the controller.

      port@1:
        type: object
        description: |
          Output endpoints of the controller.

        patternProperties:
          "^endpoint(@[0-9])$":
            type: object

            properties:
              allwinner,tcon-channel:
                $ref: /schemas/types.yaml#/definitions/uint32
                description: |
                  TCON can have 1 or 2 channels, usually with the
                  first channel being used for the panels interfaces
                  (RGB, LVDS, etc.), and the second being used for the
                  outputs that require another controller (TV Encoder,
                  HDMI, etc.).

                  If that property is present, specifies the TCON
                  channel the endpoint is associated to. If that
                  property is not present, the endpoint number will be
                  used as the channel number.

            unevaluatedProperties: true

    required:
      - "#address-cells"
      - "#size-cells"
      - port@0
      - port@1

    additionalProperties: false

required:
  - compatible
  - reg
  - interrupts
  - clocks
  - clock-names
  - resets
  - ports

additionalProperties: false

allOf:
  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun4i-a10-tcon
              - allwinner,sun5i-a13-tcon
              - allwinner,sun7i-a20-tcon

    then:
      properties:
        clocks:
          minItems: 3

        clock-names:
          items:
            - const: ahb
            - const: tcon-ch0
            - const: tcon-ch1

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun6i-a31-tcon
              - allwinner,sun6i-a31s-tcon

    then:
      properties:
        clocks:
          minItems: 4

        clock-names:
          items:
            - const: ahb
            - const: tcon-ch0
            - const: tcon-ch1
            - const: lvds-alt

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun8i-a23-tcon
              - allwinner,sun8i-a33-tcon

    then:
      properties:
        clocks:
          minItems: 3

        clock-names:
          items:
            - const: ahb
            - const: tcon-ch0
            - const: lvds-alt

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun8i-a83t-tcon-lcd
              - allwinner,sun8i-v3s-tcon
              - allwinner,sun9i-a80-tcon-lcd

    then:
      properties:
        clocks:
          minItems: 2

        clock-names:
          items:
            - const: ahb
            - const: tcon-ch0

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun8i-a83t-tcon-tv
              - allwinner,sun8i-r40-tcon-tv
              - allwinner,sun9i-a80-tcon-tv

    then:
      properties:
        clocks:
          minItems: 2

        clock-names:
          items:
            - const: ahb
            - const: tcon-ch1

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun5i-a13-tcon
              - allwinner,sun6i-a31-tcon
              - allwinner,sun6i-a31s-tcon
              - allwinner,sun7i-a20-tcon
              - allwinner,sun8i-a23-tcon
              - allwinner,sun8i-a33-tcon
              - allwinner,sun8i-v3s-tcon
              - allwinner,sun9i-a80-tcon-lcd
              - allwinner,sun4i-a10-tcon
              - allwinner,sun8i-a83t-tcon-lcd

    then:
      required:
        - "#clock-cells"
        - clock-output-names

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun6i-a31-tcon
              - allwinner,sun6i-a31s-tcon
              - allwinner,sun8i-a23-tcon
              - allwinner,sun8i-a33-tcon
              - allwinner,sun8i-a83t-tcon-lcd

    then:
      properties:
        resets:
          minItems: 2

        reset-names:
          items:
            - const: lcd
            - const: lvds

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun9i-a80-tcon-lcd

    then:
      properties:
        resets:
          minItems: 3

        reset-names:
          items:
            - const: lcd
            - const: edp
            - const: lvds

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun9i-a80-tcon-tv

    then:
      properties:
        resets:
          minItems: 2

        reset-names:
          items:
            - const: lcd
            - const: edp

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun4i-a10-tcon
              - allwinner,sun5i-a13-tcon
              - allwinner,sun6i-a31-tcon
              - allwinner,sun6i-a31s-tcon
              - allwinner,sun7i-a20-tcon
              - allwinner,sun8i-a23-tcon
              - allwinner,sun8i-a33-tcon

    then:
      required:
        - dmas

examples:
  - |
    #include <dt-bindings/dma/sun4i-a10.h>

    /*
     * This comes from the clock/sun4i-a10-ccu.h and
     * reset/sun4i-a10-ccu.h headers, but we can't include them since
     * it would trigger a bunch of warnings for redefinitions of
     * symbols with the other example.
     */

    #define CLK_AHB_LCD0	56
    #define CLK_TCON0_CH0	149
    #define CLK_TCON0_CH1	155
    #define RST_TCON0		11

    lcd-controller@1c0c000 {
        compatible = "allwinner,sun4i-a10-tcon";
        reg = <0x01c0c000 0x1000>;
        interrupts = <44>;
        resets = <&ccu RST_TCON0>;
        reset-names = "lcd";
        clocks = <&ccu CLK_AHB_LCD0>,
                 <&ccu CLK_TCON0_CH0>,
                 <&ccu CLK_TCON0_CH1>;
        clock-names = "ahb",
                      "tcon-ch0",
                      "tcon-ch1";
        clock-output-names = "tcon0-pixel-clock";
        #clock-cells = <0>;
        dmas = <&dma SUN4I_DMA_DEDICATED 14>;

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

            port@0 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0>;

                endpoint@0 {
                    reg = <0>;
                    remote-endpoint = <&be0_out_tcon0>;
                };

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&be1_out_tcon0>;
                };
            };

            port@1 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <1>;

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&hdmi_in_tcon0>;
                    allwinner,tcon-channel = <1>;
                };
            };
        };
    };

    #undef CLK_AHB_LCD0
    #undef CLK_TCON0_CH0
    #undef CLK_TCON0_CH1
    #undef RST_TCON0

  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>

    /*
     * This comes from the clock/sun6i-a31-ccu.h and
     * reset/sun6i-a31-ccu.h headers, but we can't include them since
     * it would trigger a bunch of warnings for redefinitions of
     * symbols with the other example.
     */

    #define CLK_PLL_MIPI	15
    #define CLK_AHB1_LCD0	47
    #define CLK_LCD0_CH0	127
    #define CLK_LCD0_CH1	129
    #define RST_AHB1_LCD0	27
    #define RST_AHB1_LVDS	41

    lcd-controller@1c0c000 {
        compatible = "allwinner,sun6i-a31-tcon";
        reg = <0x01c0c000 0x1000>;
        interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
        dmas = <&dma 11>;
        resets = <&ccu RST_AHB1_LCD0>, <&ccu RST_AHB1_LVDS>;
        reset-names = "lcd", "lvds";
        clocks = <&ccu CLK_AHB1_LCD0>,
                 <&ccu CLK_LCD0_CH0>,
                 <&ccu CLK_LCD0_CH1>,
                 <&ccu CLK_PLL_MIPI>;
        clock-names = "ahb",
                      "tcon-ch0",
                      "tcon-ch1",
                      "lvds-alt";
        clock-output-names = "tcon0-pixel-clock";
        #clock-cells = <0>;

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

            port@0 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0>;

                endpoint@0 {
                    reg = <0>;
                    remote-endpoint = <&drc0_out_tcon0>;
                };

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&drc1_out_tcon0>;
                };
            };

            port@1 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <1>;

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&hdmi_in_tcon0>;
                    allwinner,tcon-channel = <1>;
                };
            };
        };
    };

    #undef CLK_PLL_MIPI
    #undef CLK_AHB1_LCD0
    #undef CLK_LCD0_CH0
    #undef CLK_LCD0_CH1
    #undef RST_AHB1_LCD0
    #undef RST_AHB1_LVDS

  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>

    /*
     * This comes from the clock/sun9i-a80-ccu.h and
     * reset/sun9i-a80-ccu.h headers, but we can't include them since
     * it would trigger a bunch of warnings for redefinitions of
     * symbols with the other example.
     */

    #define CLK_BUS_LCD0	102
    #define CLK_LCD0		58
    #define RST_BUS_LCD0	22
    #define RST_BUS_EDP		24
    #define RST_BUS_LVDS	25

    lcd-controller@3c00000 {
        compatible = "allwinner,sun9i-a80-tcon-lcd";
        reg = <0x03c00000 0x10000>;
        interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&ccu CLK_BUS_LCD0>, <&ccu CLK_LCD0>;
        clock-names = "ahb", "tcon-ch0";
        resets = <&ccu RST_BUS_LCD0>, <&ccu RST_BUS_EDP>, <&ccu RST_BUS_LVDS>;
        reset-names = "lcd", "edp", "lvds";
        clock-output-names = "tcon0-pixel-clock";
        #clock-cells = <0>;

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

            port@0 {
                reg = <0>;

                endpoint {
                    remote-endpoint = <&drc0_out_tcon0>;
                };
            };

            port@1 {
                reg = <1>;
            };
        };
    };

    #undef CLK_BUS_TCON0
    #undef CLK_TCON0
    #undef RST_BUS_TCON0
    #undef RST_BUS_EDP
    #undef RST_BUS_LVDS

  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>

    /*
     * This comes from the clock/sun8i-a83t-ccu.h and
     * reset/sun8i-a83t-ccu.h headers, but we can't include them since
     * it would trigger a bunch of warnings for redefinitions of
     * symbols with the other example.
     */

    #define CLK_BUS_TCON0	36
    #define CLK_TCON0		85
    #define RST_BUS_TCON0	22
    #define RST_BUS_LVDS	31

    lcd-controller@1c0c000 {
        compatible = "allwinner,sun8i-a83t-tcon-lcd";
        reg = <0x01c0c000 0x1000>;
        interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&ccu CLK_BUS_TCON0>, <&ccu CLK_TCON0>;
        clock-names = "ahb", "tcon-ch0";
        clock-output-names = "tcon-pixel-clock";
        #clock-cells = <0>;
        resets = <&ccu RST_BUS_TCON0>, <&ccu RST_BUS_LVDS>;
        reset-names = "lcd", "lvds";

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

            port@0 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0>;

                endpoint@0 {
                    reg = <0>;
                    remote-endpoint = <&mixer0_out_tcon0>;
                };

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&mixer1_out_tcon0>;
                };
            };

            port@1 {
                reg = <1>;
            };
        };
    };

    #undef CLK_BUS_TCON0
    #undef CLK_TCON0
    #undef RST_BUS_TCON0
    #undef RST_BUS_LVDS

  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>

    /*
     * This comes from the clock/sun8i-r40-ccu.h and
     * reset/sun8i-r40-ccu.h headers, but we can't include them since
     * it would trigger a bunch of warnings for redefinitions of
     * symbols with the other example.
     */

    #define CLK_BUS_TCON_TV0	73
    #define RST_BUS_TCON_TV0	49

    tcon_tv0: lcd-controller@1c73000 {
        compatible = "allwinner,sun8i-r40-tcon-tv";
        reg = <0x01c73000 0x1000>;
        interrupts = <GIC_SPI 51 IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&ccu CLK_BUS_TCON_TV0>, <&tcon_top 0>;
        clock-names = "ahb", "tcon-ch1";
        resets = <&ccu RST_BUS_TCON_TV0>;
        reset-names = "lcd";

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

            port@0 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0>;

                endpoint@0 {
                    reg = <0>;
                    remote-endpoint = <&tcon_top_mixer0_out_tcon_tv0>;
                };

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&tcon_top_mixer1_out_tcon_tv0>;
                };
            };

            tcon_tv0_out: port@1 {
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <1>;

                endpoint@1 {
                    reg = <1>;
                    remote-endpoint = <&tcon_top_hdmi_in_tcon_tv0>;
                };
            };
        };
    };

    #undef CLK_BUS_TCON_TV0
    #undef RST_BUS_TCON_TV0

...
