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

title: Cirrus Logic CS35L45 Speaker Amplifier

maintainers:
  - Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
  - Richard Fitzgerald <rf@opensource.cirrus.com>

description: |
  CS35L45 is a Boosted Mono Class D Amplifier with DSP
  Speaker Protection and Adaptive Battery Management.

allOf:
  - $ref: dai-common.yaml#

properties:
  compatible:
    enum:
      - cirrus,cs35l45

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  '#sound-dai-cells':
    const: 1

  reset-gpios:
    maxItems: 1

  vdd-a-supply:
    description: voltage regulator phandle for the VDD_A supply

  vdd-batt-supply:
    description: voltage regulator phandle for the VDD_BATT supply

  spi-max-frequency:
    maximum: 5000000

  cirrus,asp-sdout-hiz-ctrl:
    description:
      Audio serial port SDOUT Hi-Z control. Sets the Hi-Z
      configuration for SDOUT pin of amplifier. Logical OR of
      CS35L45_ASP_TX_HIZ_xxx values.
    $ref: /schemas/types.yaml#/definitions/uint32
    minimum: 0
    maximum: 3
    default: 2

  cirrus,sync-lsw-txid:
    description:
      Transmitter ID to use for long software (LSW) data packets
      on the SYNC bus.
    $ref: /schemas/types.yaml#/definitions/uint32
    minimum: 0
    maximum: 7
    default: 0

  cirrus,sync-sw-txid:
    description:
      Transmitter ID to use for short software (SW) data packets
      on the SYNC bus.
    $ref: /schemas/types.yaml#/definitions/uint32
    minimum: 0
    maximum: 7
    default: 0

  cirrus,ldpm-group1-boost-select:
    type: boolean
    description:
      When in a valid group 1 level dependent power management (LDPM) state
      the integrated boost converter will enter the configured low power mode.

  cirrus,boost-low-power-mode:
    description:
      Configures the integrated boost converter reaction to a low power mode
      request.
      0 = No reaction
      1 = Force boost DCM low power mode
      2 = Force boost static bypass
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 2
    enum:
      - 0
      - 1
      - 2

  cirrus,ldpm-group1-amp-select:
    type: boolean
    description:
      When in a valid group 1 level dependent power management (LDPM) state
      the amplifier will enter the configured low power mode.

  cirrus,amplifier-low-power-mode:
    description:
      Configures the amplifier output stage reaction to a low power mode
      request.
      0 = Stop output switching (noise gate mode)
      1 = Noise floor reduction mode
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 1
    enum:
      - 0
      - 1

  cirrus,ldpm-group2-vmon-select:
    type: boolean
    description:
      When in a valid group 2 level dependent power management (LDPM) state
      the voltage monitor (VMON) circuit is put into a low power operational
      state.

  cirrus,ldpm-group2-imon-select:
    type: boolean
    description:
      When in a valid group 2 level dependent power management (LDPM) state
      the current monitor (IMON) circuit is put into a low power operational
      state.

patternProperties:
  "^cirrus,gpio-ctrl[1-3]$":
    description:
      GPIO pins configuration.
    type: object
    additionalProperties: false
    properties:
      gpio-dir:
        description:
          GPIO pin direction. Valid only when 'gpio-ctrl' is 1
            0 = Output
            1 = Input
        $ref: /schemas/types.yaml#/definitions/uint32
        minimum: 0
        maximum: 1
        default: 1
      gpio-lvl:
        description:
          GPIO level. Valid only when 'gpio-ctrl' is 1 and 'gpio-dir' is 0
            0 = Low
            1 = High
        $ref: /schemas/types.yaml#/definitions/uint32
        minimum: 0
        maximum: 1
        default: 0
      gpio-op-cfg:
        description:
          GPIO level. Valid only when 'gpio-ctrl' is 1 and 'gpio-dir' is 0
            0 = CMOS
            1 = Open Drain
        $ref: /schemas/types.yaml#/definitions/uint32
        minimum: 0
        maximum: 1
        default: 0
      gpio-pol:
        description:
          GPIO output polarity select. Valid only when 'gpio-ctrl' is 1
          and 'gpio-dir' is 0
            0 = Non-inverted, Active High
            1 = Inverted, Active Low
        $ref: /schemas/types.yaml#/definitions/uint32
        minimum: 0
        maximum: 1
        default: 0
      gpio-ctrl:
        description:
          Defines the function of the GPIO pin.
          GPIO1
            0 = High impedance input
            1 = Pin acts as a GPIO, direction controlled by 'gpio-dir'
            2 = Pin acts as MDSYNC, direction controlled by MDSYNC
            3-7 = Reserved
          GPIO2
            0 = High impedance input
            1 = Pin acts as a GPIO, direction controlled by 'gpio-dir'
            2 = Pin acts as open drain INT
            3 = Reserved
            4 = Pin acts as push-pull output INT. Active low.
            5 = Pin acts as push-pull output INT. Active high.
            6,7 = Reserved
          GPIO3
            0 = High impedance input
            1 = Pin acts as a GPIO, direction controlled by 'gpio-dir'
            2-7 = Reserved
        $ref: /schemas/types.yaml#/definitions/uint32
        minimum: 0
        maximum: 7
        default: 0

  "^cirrus,ldpm-group[1-2]-pcm-threshold-db$":
    description:
      Amplifier level dependent power management (LDPM) threshold. Input
      referred threshold of the PCM audio signal in which the level is low
      enough for the LDPM group to engage after entry delay. A value of dB
      -2147483648 is assumed to mean true zero data with an LSB dither.
    $ref: /schemas/types.yaml#/definitions/int32-array
    minItems: 1
    maxItems: 1
    items:
      enum: [-2147483648, -102, -96, -90, -84, -78, -72, -66]

  "^cirrus,ldpm-group[1-2]-delay-ms$":
    description:
      Amplifier level dependent power management (LDPM) state entry delay.
      Time that the incoming audio signal must be below the PCM threshold
      before the LDPM group engages.
    $ref: /schemas/types.yaml#/definitions/uint32-array
    minItems: 1
    maxItems: 1
    items:
      enum: [5, 10, 25, 50, 100, 250, 500, 1000]

required:
  - compatible
  - reg
  - "#sound-dai-cells"

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/sound/cs35l45.h>
    spi {
        #address-cells = <1>;
        #size-cells = <0>;

        cs35l45: audio-codec@2 {
            #sound-dai-cells = <1>;
            compatible = "cirrus,cs35l45";
            reg = <2>;
            spi-max-frequency = <5000000>;
            vdd-a-supply = <&dummy_vreg>;
            vdd-batt-supply = <&dummy_vreg>;
            reset-gpios = <&gpio 110 0>;
            cirrus,asp-sdout-hiz-ctrl = <(CS35L45_ASP_TX_HIZ_UNUSED |
                                          CS35L45_ASP_TX_HIZ_DISABLED)>;
            cirrus,sync-lsw-txid = <0x1>;
            cirrus,sync-sw-txid = <0x1>;
            cirrus,ldpm-group1-pcm-threshold-db = <(-66)>;
            cirrus,ldpm-group1-delay-ms = <500>;
            cirrus,ldpm-group1-boost-select;
            cirrus,boost-low-power-mode = <CS35L45_BST_LPMODE_DCM_MODE>;
            cirrus,ldpm-group1-amp-select;
            cirrus,amplifier-low-power-mode = <CS35L45_AMP_LPMODE_NFR_MODE>;
            cirrus,ldpm-group2-pcm-threshold-db = <(-102)>;
            cirrus,ldpm-group2-delay-ms = <1000>;
            cirrus,ldpm-group2-vmon-select;
            cirrus,ldpm-group2-imon-select;
            cirrus,gpio-ctrl1 {
                gpio-ctrl = <0x2>;
            };
            cirrus,gpio-ctrl2 {
                gpio-ctrl = <0x2>;
            };
            cirrus,gpio-ctrl3 {
                gpio-ctrl = <0x1>;
                gpio-dir = <0x1>;
            };
        };
    };