# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/sound/microchip,sama7g5-pdmc.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Microchip Pulse Density Microphone Controller

maintainers:
  - Codrin Ciubotariu <codrin.ciubotariu@microchip.com>

description:
  The Microchip Pulse Density Microphone Controller (PDMC) interfaces up to 4
  digital microphones having Pulse Density Modulated (PDM) outputs.

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

properties:
  compatible:
    const: microchip,sama7g5-pdmc

  reg:
    maxItems: 1

  "#sound-dai-cells":
    const: 0

  interrupts:
    maxItems: 1

  clocks:
    items:
      - description: Peripheral Bus Clock
      - description: Generic Clock

  clock-names:
    items:
      - const: pclk
      - const: gclk

  dmas:
    description: RX DMA Channel
    maxItems: 1

  dma-names:
    const: rx

  microchip,mic-pos:
    description: |
      Position of PDM microphones on the DS line and the sampling edge (rising
      or falling) of the CLK line. A microphone is represented as a pair of DS
      line and the sampling edge. The first microphone is mapped to channel 0,
      the second to channel 1, etc.
    $ref: /schemas/types.yaml#/definitions/uint32-matrix
    items:
      items:
        - description: value for DS line
          enum: [0, 1]
        - description: value for sampling edge
          enum: [0, 1]
    minItems: 1
    maxItems: 4
    uniqueItems: true

  microchip,startup-delay-us:
    description: |
      Specifies the delay in microseconds that needs to be applied after
      enabling the PDMC microphones to avoid unwanted noise due to microphones
      not being ready.

required:
  - compatible
  - reg
  - "#sound-dai-cells"
  - interrupts
  - clocks
  - clock-names
  - dmas
  - dma-names
  - microchip,mic-pos

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/clock/at91.h>
    #include <dt-bindings/dma/at91.h>
    #include <dt-bindings/interrupt-controller/arm-gic.h>
    #include <dt-bindings/sound/microchip,pdmc.h>

    pdmc: sound@e1608000 {
        compatible = "microchip,sama7g5-pdmc";
        reg = <0xe1608000 0x4000>;
        #sound-dai-cells = <0>;
        interrupts = <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
        dmas = <&dma0 AT91_XDMAC_DT_PERID(37)>;
        dma-names = "rx";
        clocks = <&pmc PMC_TYPE_PERIPHERAL 68>, <&pmc PMC_TYPE_GCK 68>;
        clock-names = "pclk", "gclk";
        microchip,mic-pos = <MCHP_PDMC_DS0 MCHP_PDMC_CLK_POSITIVE>,
                            <MCHP_PDMC_DS0 MCHP_PDMC_CLK_NEGATIVE>,
                            <MCHP_PDMC_DS1 MCHP_PDMC_CLK_POSITIVE>,
                            <MCHP_PDMC_DS1 MCHP_PDMC_CLK_NEGATIVE>;
    };