MDF Linux driver

Revision as of 12:06, 16 May 2024 by Registered User (→‎Source code location)
Applicable for STM32MP25x lines

1. Article purpose[edit source]

This article introduces the Linux® driver for the MDF internal peripheral. It addresses the following questions:

  • Which MDF features does the driver support?
  • How to configure, use, and debug the driver?
  • What are the drivers structures and where is the source code located?

2. Short Description[edit source]

The MDF Linux® driver (kernel space) is based on the IIO and ALSA frameworks.

It offers an extended API[1] for audio usage, allowing PDM microphone captures through an SPI interface.

3. Configuration[edit source]

3.1. Kernel configuration[edit source]

Activate the MDF Linux® driver in the kernel configuration by using the menuconfig tool.

3.1.1. IIO driver[edit source]

Configuration flag: CONFIG_STM32_MDF_ADC

     -> Device Drivers
       -> Industrial I/O support (IIO [=y])
         -> Analog to digital converters
           -> STMicroelectronics STM32 MDF adc (STM32_MDF_ADC [=m])

3.1.2. Audio driver[edit source]

Configuration flag: CONFIG_SND_SOC_STM32_MDF

Info white.png Information
This configuration is dependent on CONFIG_STM32_MDF_ADC
     -> Device Drivers
       -> Sound card support (SOUND [=y])
         -> Advanced Linux Sound Architecture (SND [=y])
           -> ALSA for SoC audio support (SND_SOC [=y])
             -> STMicroelectronics STM32 SOC audio support
               -> SoC Audio support for STM32 MDF (SND_SOC_STM32_MDF [=m])

3.2. Device tree[edit source]

Refer to the MDF device tree configuration article when configuring the MDF Linux kernel driver.

4. How to use[edit source]

4.1. IIO driver[edit source]

In "IIO direct mode", the conversion result can be read directly from sysfs. (Refer to How to do a simple ADC conversion using the sysfs interface.)

In "IIO triggered buffer mode", the configuration must be performed by using sysfs first. Then, character device (/dev/iio:deviceX) is used to read data. (Refer to Convert one or more channels using triggered buffer mode.)

For information on the standard IIO consumer interface, refer to How to use IIO kernel API, which gives an example of the IIO consumer kernel API.

4.2. Audio driver[edit source]

The MDF Linux driver can be accessed from userland through an ALSA device. Refer to ALSA overview for information on how to list and use ALSA devices.

5. How to trace and debug[edit source]

5.1. How to monitor[edit source]

The MDF driver uses resources such as clocks and GPIOs.

5.1.1. How to monitor with debugfs[edit source]

The MDF registers are accessed using REGMAP by MDF Linux® driver.

It comes with debugfs entries to dump registers:

$ cat /sys/kernel/debug/regmap/404d0000.mdf/registers
$ cat /sys/kernel/debug/regmap/404d*.sitf/registers
$ cat /sys/kernel/debug/regmap/404d*.filter/registers

5.1.2. Other ways to monitor[edit source]

  • The MDF interrupts and/or the MDF DMA interrupts can be verified by reading "interrupts" procfs entry:
$ cat /proc/interrupts
           CPU0       CPU1
...
88:          0          0 GIC-0 216 Level     404d0084.filter
89:          0          0 GIC-0 217 Level     404d0104.filter
90:          0          0 GIC-0 218 Level     404d0184.filter
91:          0          0 GIC-0 219 Level     404d0204.filter
...

5.2. How to trace[edit source]

5.2.1. IIO driver[edit source]

Refer to How to trace with dynamic debug for how to enable the debug logs in the driver and in the framework.

 dmesg -n8
 echo 'file stm32-mdf* +p' > /sys/kernel/debug/dynamic_debug/control

To enable dynamic debug at boot time, append the following arguments on the kernel command line:

loglevel=8 dyndbg="file drivers/iio/adc/stm32-mdf* +p"

5.2.2. Audio driver[edit source]

Refer to ALSA_overview#How_to_trace for details on trace tools.

5.3. How to debug[edit source]

5.3.1. Audio driver[edit source]

Refer to ALSA_overview#How_to_debug for details on debugging tools.

6. Source code location[edit source]

It is composed of:

  • stm32-mdf-core.c : the core part of the MDF Linux driver, which handles the common resources, such as registers and clock.
  • stm32-mdf-serial.c : the serial interface part of the MDF Linux driver, which handles the sitf resources configuration, such as input/output clocks and serial mode.
  • stm32-mdf-adc.c : the ADC part of the MDF Linux driver, which handles ADC operations.
  • stm32_amdf.c : the ASoC DAI part of the MDF Linux driver, which handles audio operations.

7. References[edit source]