# Copyright (c) 2018, Endre Karlson
# Copyright (c) 2018, Song Qiang <songqiang1304521@gmail.com>
# SPDX-License-Identifier: Apache-2.0

description: ST STM32 family ADC

compatible: "st,stm32-adc"

include: [adc-controller.yaml, pinctrl-device.yaml]

properties:
  reg:
    required: true

  clocks:
    required: true

  interrupts:
    required: true

  "#io-channel-cells":
    const: 1

  st,adc-clock-source:
    type: string
    required: true
    enum:
      - "SYNC"
      - "ASYNC"
    description: |
      Type of ADC clock source :
      - "SYNC": derived from the bus clock.
      - "ASYNC" : independent and asynchronous with the bus clock
      One of the two values may not apply to some series. Refer to the RefMan.
      If an asynchronous clock is selected, a domain clock in the clock property
      has to be defined explicitly.

  st,adc-prescaler:
    type: int
    required: true
    enum:
      - 1 # not divided
      - 2
      - 4
      - 6
      - 8
      - 10
      - 12
      - 16
      - 32
      - 64
      - 128
      - 256
    description: |
      Clock prescaler at the input of the ADC:
      Apply to synchronous or asynchronous clock depending on the STM32
      st,adc-clock-source.
      Some of the values may not apply to some series, and may depend on the
      selected clock source. Refer to the RefMan.
      On STM32F3x (except STM32F37x), this configures only the synchronous
      prescaler (see properties adcXX-prescaler in st,stm32f3-rcc bindings to
      set asynchronous prescaler).

  vref-mv:
    type: int
    default: 3300
    description: Indicates the reference voltage of the ADC in mV (on the target board).

  resolutions:
    type: array
    required: true
    description: |
      List of the resolutions supported by the ADC instance. They should be
      values created with STM32_ADC_RES macro or similar. Their order is not
      important. For example for STM32F4:
        <STM32_ADC_RES(12, 0x00) STM32_ADC_RES(10, 0x01)
         STM32_ADC_RES(8, 0x02)  STM32_ADC_RES(6, 0x03)>
      The two parameters are the resolution (for example 10 bits) and the
      corresponding register value (0x01 for a 10-bit resolution).
      By design, these macros also contains all register information (address,
      field offset and field mask) necessary to properly set the resolution.

  sampling-times:
    type: array
    required: true
    description: |
      List all the sampling times supported by the ADC instance.
      Rounded up if needed. Order is important: their index matches their binary
      value in the register.

  num-sampling-time-common-channels:
    type: int
    description: |
      Number of sampling time common channels for this ADC instance, if any.

  st,adc-sequencer:
    type: string
    required: true
    enum:
      - "NOT_FULLY_CONFIGURABLE"
      - "FULLY_CONFIGURABLE"
    description: |
      Type of ADC sequencer:
      - "NOT_FULLY_CONFIGURABLE": Not fully configurable sequencer
      - "FULLY_CONFIGURABLE": Fully configurable sequencer

  st,adc-oversampler:
    type: string
    required: true
    enum:
      - "OVERSAMPLER_NONE"
      - "OVERSAMPLER_MINIMAL"
      - "OVERSAMPLER_EXTENDED"
    description: |
      Type of ADC oversampler:
      - "OVERSAMPLER_NONE": No oversampler
      - "OVERSAMPLER_MINIMAL": Oversampler with 8 possible oversampling values (2, 4, 8, ..., 256)
      - "OVERSAMPLER_EXTENDED": Oversampler with 1024 possible oversampling values (1..1024)

io-channel-cells:
  - input
