# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
# Copyright (C) 2021 Renesas Electronics Corp.
%YAML 1.2
---
$id: http://devicetree.org/schemas/media/i2c/maxim,max96712.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Quad GMSL2 to CSI-2 Deserializer with GMSL1 Compatibility

maintainers:
  - Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

description: |
  The MAX96712 deserializer converts GMSL2 or GMSL1 serial inputs into MIPI
  CSI-2 D-PHY or C-PHY formatted outputs. The device allows each link to
  simultaneously transmit bidirectional control-channel data while forward
  video transmissions are in progress. The MAX96712 can accommodate as many as
  four remotely located sensors using industry-standard coax or STP
  interconnects.

  Each GMSL2 serial link operates at a fixed rate of 3Gbps or 6Gbps in the
  forward direction and 187.5Mbps in the reverse direction. In GMSL1 mode, the
  MAX96712 can be paired with first-generation 3.12Gbps or 1.5Gbps GMSL1
  serializers or operate up to 3.12Gbps with GMSL2 serializers in GMSL1 mode.

  MAX96724F and MAX96724R only support a fixed rate of 3Gbps in the forward
  direction.

properties:
  compatible:
    items:
      - enum:
          - maxim,max96712
          - maxim,max96724
          - maxim,max96724f
          - maxim,max96724r

  reg:
    description: I2C device address
    maxItems: 1

  enable-gpios: true

  maxim,control-channel-port:
    description:
      Selects which deserializer control-channel port is connected to the
      upstream I2C segment when the device resets. 0 selects port 0, 1 selects
      port 1. Defaults to 0 when omitted.
    $ref: /schemas/types.yaml#/definitions/uint32
    enum: [0, 1]
    default: 0

  i2c-alias-pool:
    maxItems: 4

  i2c-atr:
    type: object
    additionalProperties: false

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

      '#size-cells':
        const: 0

    patternProperties:
      '^i2c@[0-3]$':
        $ref: /schemas/i2c/i2c-controller.yaml#
        unevaluatedProperties: false
        properties:
          reg:
            items:
              minimum: 0
              maximum: 3

  ports:
    $ref: /schemas/graph.yaml#/properties/ports

    patternProperties:
      '^port@[0-3]$':
        $ref: /schemas/graph.yaml#/properties/port
        description: GMSL Input ports 0-3

      '^port@[4-7]$':
        $ref: /schemas/graph.yaml#/$defs/port-base
        unevaluatedProperties: false
        description: CSI-2 Output port 0-3

        properties:
          endpoint:
            $ref: /schemas/media/video-interfaces.yaml#
            unevaluatedProperties: false

            properties:
              data-lanes: true
              bus-type:
                enum:
                  - 1 # MEDIA_BUS_TYPE_CSI2_CPHY
                  - 4 # MEDIA_BUS_TYPE_CSI2_DPHY

            required:
              - data-lanes
              - bus-type

    anyOf:
      - required: [port@4]
      - required: [port@5]
      - required: [port@6]
      - required: [port@7]

patternProperties:
  '^port[0-3]-poc-supply$':
    description: Regulator providing Power over Coax for GMSL ports

required:
  - compatible
  - reg
  - ports

additionalProperties: false

allOf:
  - $ref: /schemas/i2c/i2c-atr.yaml#

dependentRequired:
  i2c-atr: [i2c-alias-pool]
  i2c-alias-pool: [i2c-atr]

examples:
  - |
    #include <dt-bindings/gpio/gpio.h>
    #include <dt-bindings/media/video-interfaces.h>

    i2c@e6508000 {
            #address-cells = <1>;
            #size-cells = <0>;

            reg = <0 0xe6508000>;

            gmsl0: gmsl-deserializer@49 {
                    compatible = "maxim,max96712";
                    reg = <0x49>;
                    enable-gpios = <&pca9654_a 0 GPIO_ACTIVE_HIGH>;

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

                            port@4 {
                                    reg = <4>;
                                    max96712_out0: endpoint {
                                            bus-type = <MEDIA_BUS_TYPE_CSI2_DPHY>;
                                            clock-lanes = <0>;
                                            data-lanes = <1 2 3 4>;
                                            remote-endpoint = <&csi40_in>;
                                    };
                            };
                    };
            };
    };