# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/leds/nxp,pca963x.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: NXP PCA963x LED controllers

maintainers:
  - Laurent Pinchart <laurent.pinchart@ideasonboard.com>

description: |
  The NXP PCA963x are I2C-controlled LED drivers optimized for
  Red/Green/Blue/Amber (RGBA) color mixing applications. Each LED is
  individually controllable and has its own PWM controller.

  Datasheets are available at

  - https://www.nxp.com/docs/en/data-sheet/PCA9632.pdf
  - https://www.nxp.com/docs/en/data-sheet/PCA9633.pdf
  - https://www.nxp.com/docs/en/data-sheet/PCA9634.pdf
  - https://www.nxp.com/docs/en/data-sheet/PCA9635.pdf

properties:
  compatible:
    enum:
      - nxp,pca9632
      - nxp,pca9633
      - nxp,pca9634
      - nxp,pca9635

  reg:
    maxItems: 1

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

  nxp,hw-blink:
    type: boolean
    description:
      Use hardware blinking instead of software blinking

  nxp,inverted-out:
    type: boolean
    description:
      Invert the polarity of the generated PWM.

  nxp,period-scale:
    $ref: /schemas/types.yaml#/definitions/uint32
    description:
      In some configurations, the chip blinks faster than expected. This
      parameter provides a scaling ratio (fixed point, decimal divided by 1000)
      to compensate, e.g. 1300=1.3x and 750=0.75x.

  nxp,totem-pole:
    type: boolean
    description:
      Use totem pole (push-pull) instead of open-drain (pca9632 defaults to
      open-drain, newer chips to totem pole).

patternProperties:
  "^led@[0-9a-f]$":
    type: object
    $ref: common.yaml#
    unevaluatedProperties: false

    properties:
      reg:
        maximum: 15

    required:
      - reg

  "^multi-led@[0-9a-f]$":
    type: object
    $ref: leds-class-multicolor.yaml#
    unevaluatedProperties: false

    properties:
      reg:
        maximum: 15

      "#address-cells":
        const: 1

      "#size-cells":
        const: 0

    patternProperties:
      "^led@[0-9a-f]$":
        type: object
        $ref: common.yaml#
        unevaluatedProperties: false

        properties:
          reg:
            maximum: 15

        required:
          - reg
          - color

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

allOf:
  - if:
      properties:
        compatible:
          contains:
            enum:
              - nxp,pca9632
              - nxp,pca9633
    then:
      patternProperties:
        "^.*led@[0-9a-f]$":
          properties:
            reg:
              maximum: 3
        "^multi-led@[0-9a-f]$":
          patternProperties:
            "^led@[0-9a-f]$":
              properties:
                reg:
                  maximum: 3
  - if:
      properties:
        compatible:
          contains:
            enum:
              - nxp,pca9634
    then:
      patternProperties:
        "^.*led@[0-9a-f]$":
          properties:
            reg:
              maximum: 7
        "^multi-led@[0-9a-f]$":
          patternProperties:
            "^led@[0-9a-f]$":
              properties:
                reg:
                  maximum: 7

additionalProperties: false

examples:
  - |
    #include <dt-bindings/leds/common.h>

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

        led-controller@62 {
            compatible = "nxp,pca9632";
            reg = <0x62>;
            #address-cells = <1>;
            #size-cells = <0>;

            led@0 {
                reg = <0>;
                color = <LED_COLOR_ID_RED>;
                function = LED_FUNCTION_STATUS;
            };

            led@1 {
                reg = <1>;
                color = <LED_COLOR_ID_GREEN>;
                function = LED_FUNCTION_STATUS;
            };

            led@2 {
                reg = <2>;
                color = <LED_COLOR_ID_BLUE>;
                function = LED_FUNCTION_STATUS;
            };

            led@3 {
                reg = <3>;
                color = <LED_COLOR_ID_WHITE>;
                function = LED_FUNCTION_STATUS;
            };
        };
    };

  - |
    #include <dt-bindings/leds/common.h>

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

        led-controller@62 {
            compatible = "nxp,pca9633";
            reg = <0x62>;
            #address-cells = <1>;
            #size-cells = <0>;

            /* Three channels controlling one RGB LED */
            multi-led@0 {
                reg = <0>;
                color = <LED_COLOR_ID_RGB>;
                function = LED_FUNCTION_STATUS;
                #address-cells = <1>;
                #size-cells = <0>;

                led@0 {
                    reg = <0>;
                    color = <LED_COLOR_ID_RED>;
                };

                led@1 {
                    reg = <1>;
                    color = <LED_COLOR_ID_GREEN>;
                };

                led@2 {
                    reg = <2>;
                    color = <LED_COLOR_ID_BLUE>;
                };
            };

            /* Remaining channel used as a plain white LED */
            led@3 {
                reg = <3>;
                color = <LED_COLOR_ID_WHITE>;
                function = LED_FUNCTION_STATUS;
            };
        };
    };

...