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

title: ChromeOS Embedded Controller

maintainers:
  - Benson Leung <bleung@chromium.org>
  - Enric Balletbo i Serra <enric.balletbo@collabora.com>
  - Guenter Roeck <groeck@chromium.org>

description:
  Google's ChromeOS EC is a microcontroller which talks to the AP and
  implements various functions such as keyboard and battery charging.
  The EC can be connected through various interfaces (I2C, SPI, and others)
  and the compatible string specifies which interface is being used.

properties:
  compatible:
    oneOf:
      - description:
          For implementations of the EC is connected through I2C.
        const: google,cros-ec-i2c
      - description:
          For implementations of the EC is connected through SPI.
        const: google,cros-ec-spi
      - description:
          For implementations of the EC is connected through RPMSG.
        const: google,cros-ec-rpmsg

  controller-data:
    description:
      SPI controller data, see bindings/spi/spi-samsung.txt
    type: object

  google,cros-ec-spi-pre-delay:
    description:
      This property specifies the delay in usecs between the
      assertion of the CS and the first clock pulse.
    allOf:
      - $ref: /schemas/types.yaml#/definitions/uint32
      - default: 0
      - minimum: 0

  google,cros-ec-spi-msg-delay:
    description:
      This property specifies the delay in usecs between messages.
    allOf:
      - $ref: /schemas/types.yaml#/definitions/uint32
      - default: 0
      - minimum: 0

  google,has-vbc-nvram:
    description:
      Some implementations of the EC include a small nvram space used to
      store verified boot context data. This boolean flag is used to specify
      whether this nvram is present or not.
    type: boolean

  mtk,rpmsg-name:
    description:
      Must be defined if the cros-ec is a rpmsg device for a Mediatek
      ARM Cortex M4 Co-processor. Contains the name pf the rpmsg
      device. Used to match the subnode to the rpmsg device announced by
      the SCP.
    $ref: "/schemas/types.yaml#/definitions/string"

  spi-max-frequency:
    description: Maximum SPI frequency of the device in Hz.

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  wakeup-source:
    description: Button can wake-up the system.

  '#address-cells':
    const: 1

  '#size-cells':
    const: 0

  typec:
    $ref: "/schemas/chrome/google,cros-ec-typec.yaml#"

  ec-pwm:
    $ref: "/schemas/pwm/google,cros-ec-pwm.yaml#"

  keyboard-controller:
    $ref: "/schemas/input/google,cros-ec-keyb.yaml#"

  proximity:
    $ref: "/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#"

  codecs:
    type: object
    additionalProperties: false

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

      '#size-cells':
        const: 1

    patternProperties:
      "^ec-codec@[a-f0-9]+$":
        type: object
        $ref: "/schemas/sound/google,cros-ec-codec.yaml#"

    required:
      - "#address-cells"
      - "#size-cells"

  cbas:
    type: object

    description:
      This device is used to signal when a detachable base is attached
      to a Chrome OS tablet. This device cannot be detected at runtime.

    properties:
      compatible:
        const: google,cros-cbas

    required:
      - compatible

    additionalProperties: false

patternProperties:
  "^i2c-tunnel[0-9]*$":
    type: object
    $ref: "/schemas/i2c/google,cros-ec-i2c-tunnel.yaml#"

  "^regulator@[0-9]+$":
    type: object
    $ref: "/schemas/regulator/google,cros-ec-regulator.yaml#"

  "^extcon[0-9]*$":
    type: object
    $ref: "/schemas/extcon/extcon-usbc-cros-ec.yaml#"

required:
  - compatible

if:
  properties:
    compatible:
      contains:
        enum:
          - google,cros-ec-i2c
          - google,cros-ec-rpmsg
then:
  properties:
    google,cros-ec-spi-pre-delay: false
    google,cros-ec-spi-msg-delay: false
    spi-max-frequency: false

additionalProperties: false

examples:
  # Example for I2C
  - |
    #include <dt-bindings/gpio/gpio.h>
    #include <dt-bindings/interrupt-controller/irq.h>

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

        cros-ec@1e {
            compatible = "google,cros-ec-i2c";
            reg = <0x1e>;
            interrupts = <6 0>;
            interrupt-parent = <&gpio0>;
        };
    };

  # Example for SPI
  - |
    #include <dt-bindings/gpio/gpio.h>
    #include <dt-bindings/interrupt-controller/irq.h>

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

        cros-ec@0 {
            compatible = "google,cros-ec-spi";
            reg = <0x0>;
            google,cros-ec-spi-msg-delay = <30>;
            google,cros-ec-spi-pre-delay = <10>;
            interrupts = <99 0>;
            interrupt-parent = <&gpio7>;
            spi-max-frequency = <5000000>;

            proximity {
                    compatible = "google,cros-ec-mkbp-proximity";
            };

            cbas {
                compatible = "google,cros-cbas";
            };
        };
    };

  # Example for RPMSG
  - |
    scp0 {
        cros-ec {
            compatible = "google,cros-ec-rpmsg";
        };
    };
...
