“ADC Linux driver”的版本间的差异

来自百问网嵌入式Linux wiki
第1行: 第1行:
 
== Article purpose ==
 
== Article purpose ==
This article introduces the Linux<sup>&reg;</sup> driver for the ADC<ref name="ADC internal peripheral">[[ADC internal peripheral]]</ref> internal peripheral:
+
本文介绍了用于ADC <ref name="ADC internal peripheral">[[ADC internal peripheral]]</ref>内部外围设备的Linux<sup>&reg;</sup>驱动程序:
* Which ADC features are supported by the driver
+
* 驱动程序支持哪些ADC功能
* How to configure, use and debug the driver
+
* 如何配置,使用和调试驱动程序
* What is the driver structure, and where the source code can be found.
+
* 驱动程序的结构是什么,以及在哪里可以找到源代码。
  
 
== Short description ==
 
== Short description ==

2020年11月9日 (一) 11:13的版本

Article purpose

本文介绍了用于ADC [1]内部外围设备的Linux®驱动程序:

  • 驱动程序支持哪些ADC功能
  • 如何配置,使用和调试驱动程序
  • 驱动程序的结构是什么,以及在哪里可以找到源代码。

Short description

The ADC Linux® driver (kernel space) is based on the IIO framework. It supports two modes:

  1. IIO direct mode: single capture on a channel (using interrupts)
  2. IIO triggered buffer mode: capture on one or more channels (preferably using DMA).
    It uses the hardware triggers available in IIO. See TIM Linux driver and LPTIM Linux driver.

Configuration

Kernel configuration

Activate the ADC[1] Linux® driver in the kernel configuration using the Linux Menuconfig tool: Menuconfig or how to configure kernel (enable both CONFIG_STM32_ADC_CORE and CONFIG_STM32_ADC).

Device Drivers  --->
   <*> Industrial I/O support  --->
      Analog to digital converters  --->
         <*> STMicroelectronics STM32 adc core
         <*>   STMicroelectronics STM32 adc

Device tree

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

How to use

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 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).

How to trace and debug

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

Refer to How to debug with debugfs for how to access the ADC registers.

The ADC has system wide dependencies towards other key resources:

  • runtime power management can be disabled, for example it may be forced on via power/control sysfs entry:
Board $> cd /sys/devices/platform/soc/48003000.adc/48003000.adc:adc@0
Board $> cat power/autosuspend_delay_ms
2000
Board $> cat power/control
auto                                     # kernel is allowed to automatically suspend the ADC device after autosuspend_delay_ms
Board $> echo on > power/control         # force the kernel to resume the ADC device (e.g. keep clocks and regulators enabled)
Info.png It might be useful to disable runtime power management, in order to dump registers by any means or to check clock and regulator usage (see example below).
  • clock[2] usage can be verified by reading clk_summary:
Board $> cat /sys/kernel/debug/clk/clk_summary | grep adc
         adc12_k                     1        1        0    24000000          0 0
                  adc12              1        1        0   196607910          0 0
  • regulator[3] tree and usage can be verified (e.g. use count, open count or regulator reference voltage) as follows:
Board $> cat /sys/kernel/debug/regulator/regulator_summary
 regulator                      use open bypass voltage current     min     max
-------------------------------------------------------------------------------
    v3v3                          4    5      0  3300mV     0mA  3300mV  3300mV
       vdda                       1    2      0  2900mV     0mA  2900mV  2900mV 
          40017000.dac                                              0mV     0mV
          48003000.adc                                              0mV     0mV
  • pinctrl[4] usage can be verified by reading pinmux-pins:
Board $> cd /sys/kernel/debug/pinctrl/soc\:pin-controller@50002000/
Board $> cat pinmux-pins | grep adc
pin 92 (PF12): device 48003000.adc function analog group PF12   # check pin is assigned to ADC and is configured as "analog"
  • interrupts can be verified by reading "interrupts":
Board $> cat /proc/interrupts
           CPU0       CPU1
 56:          2          0     dummy   0 Edge      48003000.adc:adc@0

Source code location

The ADC source code is composed of:

References

<securetransclude src="ProtectedTemplate:PublicationRequestId" params="9337 | 2018-10-23 | AnneJ"></securetransclude> <securetransclude src="ProtectedTemplate:ArticleBasedOnModel" params="Linux driver article model"></securetransclude>