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

title: Tesla FSD (Full Self-Driving) SoC clock controller

maintainers:
  - Alim Akhtar <alim.akhtar@samsung.com>
  - linux-fsd@tesla.com

description: |
  FSD clock controller consist of several clock management unit
  (CMU), which generates clocks for various inteernal SoC blocks.
  The root clock comes from external OSC clock (24 MHz).

  All available clocks are defined as preprocessor macros in
  'dt-bindings/clock/fsd-clk.h' header.

properties:
  compatible:
    enum:
      - tesla,fsd-clock-cmu
      - tesla,fsd-clock-imem
      - tesla,fsd-clock-peric
      - tesla,fsd-clock-fsys0
      - tesla,fsd-clock-fsys1
      - tesla,fsd-clock-mfc
      - tesla,fsd-clock-cam_csi

  clocks:
    minItems: 1
    maxItems: 6

  clock-names:
    minItems: 1
    maxItems: 6

  "#clock-cells":
    const: 1

  reg:
    maxItems: 1

allOf:
  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-cmu
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
        clock-names:
          items:
            - const: fin_pll

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-imem
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
            - description: IMEM TCU clock (from CMU_CMU)
            - description: IMEM bus clock (from CMU_CMU)
            - description: IMEM DMA clock (from CMU_CMU)
        clock-names:
          items:
            - const: fin_pll
            - const: dout_cmu_imem_tcuclk
            - const: dout_cmu_imem_aclk
            - const: dout_cmu_imem_dmaclk

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-peric
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
            - description: Shared0 PLL div4 clock (from CMU_CMU)
            - description: PERIC shared1 div36 clock (from CMU_CMU)
            - description: PERIC shared0 div3 TBU clock (from CMU_CMU)
            - description: PERIC shared0 div20 clock (from CMU_CMU)
            - description: PERIC shared1 div4 DMAclock (from CMU_CMU)
        clock-names:
          items:
            - const: fin_pll
            - const: dout_cmu_pll_shared0_div4
            - const: dout_cmu_peric_shared1div36
            - const: dout_cmu_peric_shared0div3_tbuclk
            - const: dout_cmu_peric_shared0div20
            - const: dout_cmu_peric_shared1div4_dmaclk

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-fsys0
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
            - description: Shared0 PLL div6 clock (from CMU_CMU)
            - description: FSYS0 shared1 div4 clock (from CMU_CMU)
            - description: FSYS0 shared0 div4 clock (from CMU_CMU)
        clock-names:
          items:
            - const: fin_pll
            - const: dout_cmu_pll_shared0_div6
            - const: dout_cmu_fsys0_shared1div4
            - const: dout_cmu_fsys0_shared0div4

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-fsys1
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
            - description: FSYS1 shared0 div8 clock (from CMU_CMU)
            - description: FSYS1 shared0 div4 clock (from CMU_CMU)
        clock-names:
          items:
            - const: fin_pll
            - const: dout_cmu_fsys1_shared0div8
            - const: dout_cmu_fsys1_shared0div4

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-mfc
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
        clock-names:
          items:
            - const: fin_pll

  - if:
      properties:
        compatible:
          contains:
            const: tesla,fsd-clock-cam_csi
    then:
      properties:
        clocks:
          items:
            - description: External reference clock (24 MHz)
        clock-names:
          items:
            - const: fin_pll

required:
  - compatible
  - "#clock-cells"
  - clocks
  - clock-names
  - reg

additionalProperties: false

examples:
  # Clock controller node for CMU_FSYS1
  - |
    #include <dt-bindings/clock/fsd-clk.h>

    clock_fsys1: clock-controller@16810000 {
          compatible = "tesla,fsd-clock-fsys1";
          reg = <0x16810000 0x3000>;
          #clock-cells = <1>;

          clocks = <&fin_pll>,
                   <&clock_cmu DOUT_CMU_FSYS1_SHARED0DIV8>,
                   <&clock_cmu DOUT_CMU_FSYS1_SHARED0DIV4>;
          clock-names = "fin_pll",
                        "dout_cmu_fsys1_shared0div8",
                        "dout_cmu_fsys1_shared0div4";
    };

...