# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/thermal/allwinner,sun8i-a83t-ths.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Allwinner SUN8I Thermal Controller

maintainers:
  - Vasily Khoruzhick <anarsoul@gmail.com>
  - Yangtao Li <tiny.windzz@gmail.com>

$ref: thermal-sensor.yaml#

properties:
  compatible:
    enum:
      - allwinner,sun8i-a83t-ths
      - allwinner,sun8i-h3-ths
      - allwinner,sun8i-r40-ths
      - allwinner,sun20i-d1-ths
      - allwinner,sun50i-a64-ths
      - allwinner,sun50i-a100-ths
      - allwinner,sun50i-h5-ths
      - allwinner,sun50i-h6-ths
      - allwinner,sun50i-h616-ths

  clocks:
    minItems: 1
    items:
      - description: Bus Clock
      - description: Module Clock

  clock-names:
    minItems: 1
    items:
      - const: bus
      - const: mod

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  resets:
    maxItems: 1

  nvmem-cells:
    maxItems: 1
    description: Calibration data for thermal sensors

  nvmem-cell-names:
    const: calibration

  allwinner,sram:
    maxItems: 1
    description: phandle to device controlling temperate offset SYS_CFG register

  "#thermal-sensor-cells":
    enum:
      - 0
      - 1

allOf:
  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun20i-d1-ths
              - allwinner,sun50i-a100-ths
              - allwinner,sun50i-h6-ths
              - allwinner,sun50i-h616-ths

    then:
      properties:
        clocks:
          maxItems: 1

        clock-names:
          maxItems: 1

    else:
      properties:
        clocks:
          minItems: 2

        clock-names:
          minItems: 2

  - if:
      not:
        properties:
          compatible:
            contains:
              const: allwinner,sun50i-h616-ths

    then:
      properties:
        allwinner,sram: false

  - if:
      properties:
        compatible:
          contains:
            enum:
              - allwinner,sun8i-h3-ths
              - allwinner,sun20i-d1-ths

    then:
      properties:
        "#thermal-sensor-cells":
          const: 0

    else:
      properties:
        "#thermal-sensor-cells":
          const: 1

  - if:
      not:
        properties:
          compatible:
            contains:
              enum:
                - allwinner,sun8i-a83t-ths

    then:
      required:
        - clocks
        - clock-names
        - resets

required:
  - compatible
  - reg
  - interrupts

unevaluatedProperties: false

examples:
  - |
    thermal-sensor@1f04000 {
        compatible = "allwinner,sun8i-a83t-ths";
        reg = <0x01f04000 0x100>;
        interrupts = <0 31 0>;
        nvmem-cells = <&ths_calibration>;
        nvmem-cell-names = "calibration";
        #thermal-sensor-cells = <1>;
    };

  - |
    thermal-sensor@1c25000 {
        compatible = "allwinner,sun8i-h3-ths";
        reg = <0x01c25000 0x400>;
        clocks = <&ccu 0>, <&ccu 1>;
        clock-names = "bus", "mod";
        resets = <&ccu 2>;
        interrupts = <0 31 0>;
        nvmem-cells = <&ths_calibration>;
        nvmem-cell-names = "calibration";
        #thermal-sensor-cells = <0>;
    };

  - |
    thermal-sensor@5070400 {
        compatible = "allwinner,sun50i-h6-ths";
        reg = <0x05070400 0x100>;
        clocks = <&ccu 0>;
        clock-names = "bus";
        resets = <&ccu 2>;
        interrupts = <0 15 0>;
        nvmem-cells = <&ths_calibration>;
        nvmem-cell-names = "calibration";
        #thermal-sensor-cells = <1>;
    };

...
