• Fabrice Gasnier's avatar
    iio: adc: stm32-dfsdm: add support for buffer modes · 11646e81
    Fabrice Gasnier authored
    DFSDM conversions can be launched continuously, or using various
    triggers:
    - by software
    - hardware triggers (e.g. like in stm32-adc: TIM, LPTIM, EXTI)
    - synchronously with DFSDM filter 0. e.g. for filters 1, 2
    
    Launching conversions can be done using two methods:
    a - injected:
        - scan mode can be used to convert several channels each time a
          trigger occurs.
        - When not is scan mode, channels are converted in sequence, one upon
          each trigger.
    b - regular:
        - supports software triggers or synchronous with filter 0
        - single or continuous conversions
    
    This patch finalizes DFSDM operating modes using IIO buffer modes:
    - INDIO_BUFFER_SOFTWARE: regular continuous conversions (no trigger)
      but limited to 1 channel. Users must set sampling frequency in this case.
      For filters > 1, conversions can be started synchronously with filter 0.
    - INDIO_BUFFER_TRIGGERED: triggered conversions uses injected mode for
      launching conversions. DFSDM can use hardware triggers (e.g. STM32 timer
      or lptimer), so add INDIO_HARDWARE_TRIGGERED to supported modes.
    - INDIO_DIRECT_MODE: Only support DMA-based buffer modes. In case no DMA is
      available, only support single conversions.
    
    From userland perspective, to summarize various use cases:
    1 - single conversion on any filter:
    $ cd iio:deviceX
    $ cat in_voltageY_raw
    This uses regular a conversion (not continuous)
    
    2 - Using sampling frequency without trigger (single channel, buffer)
    $ cd iio:deviceX
    $ echo 100 > sampling_frequency
    $ echo "" > trigger/current_trigger
    $ echo 1 > scan_elements/in_voltageY_en
    $ echo 1 > buffer/enable
    This uses regular conversion in continuous mode (Frequency is achieved
    by tuning filter parameters)
    
    3 - sync mode with filter 0: other filters can be converted when using
    "st,filter0-sync" dt property. The conversions will get started at the
    same time as filter 0. So for any filters > 1:
    $ cd iio:deviceX
    $ echo 100 > sampling_frequency
    $ echo "" > trigger/current_trigger
    $ echo 1 > scan_elements/in_voltageY_en
    $ echo 1 > buffer/enable
    Then start filter 0 as in 2 above.
    
    4 - Using a hardware trigger (with one channel):
    - check trigger, configure it:
    $ cat /sys/bus/iio/devices/trigger1/name
    tim6_trgo
    $ echo 100 > /sys/bus/iio/devices/trigger1/sampling_frequency
    - go to any filter:
    $ echo 1 > scan_elements/in_voltageY_en
    $ echo tim6_trgo > trigger/current_trigger
    $ echo 1 > buffer/enable
    This uses injected conversion as it uses a hardware trigger (without scan)
    
    5 - Using a hardware trigger (with 2+ channel):
    Same as in 4/ above, but enable two or more channels in scan_elements.
    This uses injected conversion as it uses a hardware trigger (with scan mode)
    Signed-off-by: default avatarFabrice Gasnier <fabrice.gasnier@st.com>
    Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
    11646e81
stm32-dfsdm-adc.c 37.7 KB