Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
resources:tools-software:linux-drivers:iio-adc:ad400x [07 Nov 2018 08:56] – [Files] Mircea Caprioruresources:tools-software:linux-drivers:iio-adc:ad400x [01 Feb 2024 21:48] (current) – Recommend the AD400x user guide Marcelo Schmitt
Line 1: Line 1:
-====== AD4003/AD4007/AD4011/AD4020 Linux Driver ======+====== AD4003/AD4007/AD4011/AD4020/ADAQ4001/ADAQ4003 Linux Driver ======
  
 ===== Supported Devices ===== ===== Supported Devices =====
  
  
 +  * [[adi>AD4000]]
 +  * [[adi>AD4001]]
 +  * [[adi>AD4002]]
   * [[adi>AD4003]]   * [[adi>AD4003]]
 +  * [[adi>AD4004]]
 +  * [[adi>AD4005]]
 +  * [[adi>AD4006]]
   * [[adi>AD4007]]   * [[adi>AD4007]]
 +  * [[adi>AD4008]]
 +  * [[adi>AD4010]]
   * [[adi>AD4011]]   * [[adi>AD4011]]
   * [[adi>AD4020]]   * [[adi>AD4020]]
 +  * [[adi>AD4021]]
 +  * [[adi>AD4022]]
   * [[adi>ADAQ4003]]   * [[adi>ADAQ4003]]
  
 ===== Evaluation Boards ===== ===== Evaluation Boards =====
  
-  * [[adi>EVAL-AD400xFMCZ]]+  * [[adi>EVAL-AD400x-FMCZ]] 
 +  * [[adi>EVAL-ADAQ40xx]]
  
 ===== Description ===== ===== Description =====
  
-This is Linux industrial I/O (IIO) subsystem driver, targeting single channel serial interface ADCs. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2cspi, etc). See IIO for more information.+Analog Devices [[adi>AD4000]] and the above listed devices are high accuracy, high speed, low power SAR ADCs. 
 + 
 +This is the Linux industrial I/O ([[software:linux:docs:iio:iio|IIO]]) subsystem driver, targeting single channel SPI interface [[adi>AD4000]] and similar ADC devices. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (I2CSPI, etc). See [[software:linux:docs:iio:iio|IIO]] for more information.  
 + 
 +See the [[resources:eval:ad400x-eval-board|Evaluating AD400X and ADAQ400X devices]] user guide for instructions on how to setup and evaluate devices supported by the ad400x Linux driver.
  
 ===== Status ===== ===== Status =====
  
 ^ Source ^ Mainlined? ^ ^ Source ^ Mainlined? ^
-| [[linux.github>master/drivers/iio/adc/ad400x.c|git]] | [In progress...] |+| [[linux.github>main/drivers/iio/adc/ad400x.c|git]] | [No] |
  
 ===== Files ===== ===== Files =====
  
 ^ Function ^ File ^ ^ Function ^ File ^
-| driver  | [[linux.github>master/drivers/iio/adc/ad400x.c]] | +| driver  | [[linux.github>main?drivers/iio/adc/ad400x.c | drivers/iio/adc/ad400x.c ]] | 
-| devicetree bindings | [[linux.github>master?Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt | Documentation/devicetree/bindings/iio/adc/ad400x.txt]] |+| devicetree bindings | [[linux.github>main?Documentation/devicetree/bindings/iio/adc/adi,ad400x.yaml | Documentation/devicetree/bindings/iio/adc/adi,ad400x.yaml]] | 
 +| ZedBoard example devicetree | [[linux.github>main?arch/arm/boot/dts/zynq-zed-adv7511-ad4020.dts | arch/arm/boot/dts/zynq-zed-adv7511-ad4020.dts]] | 
 +| CoraZ7 example devicetree | [[linux.github>main?arch/arm/boot/dts/zynq-coraz7s-adaq4003.dts | arch/arm/boot/dts/zynq-coraz7s-adaq4003.dts]] | 
  
 ====== Driver setup ====== ====== Driver setup ======
-Since AD4003/4007/4011/4020 are high speed analog-to-digital converters with speeds up to 2 Msps additional components are required in order to achieve high performance. In this scenario the following hdl components are required:+ 
 +Since AD4003/4007/4011/4020 are high speed analog-to-digital converters with speeds up to 2 MSPS, additional components are required to achieve high performance. In this scenariothe following HDL components are required:
   * [[resources:fpga:peripherals:spi_engine|SPI Engine]]   * [[resources:fpga:peripherals:spi_engine|SPI Engine]]
   * [[resources:fpga:docs:axi_dmac|High-Speed DMA Controller Peripheral]]   * [[resources:fpga:docs:axi_dmac|High-Speed DMA Controller Peripheral]]
Line 38: Line 57:
 <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 <xterm> <xterm>
-&fpga_axi {                                                                       +properties: 
-         rx_dmarx-dmac@44a30000 {                                                +  compatible: 
-                 compatible = "adi,axi-dmac-1.00.a";                               +    enum: 
-                 reg = <0x44a30000 0x1000>;                                        +      adi,ad4000 
-                 #dma-cells = <1>;                                                 +      adi,ad4001 
-                 interrupts = <0 57 0>;                                            +      adi,ad4002 
-                 clocks = <&clkc 16>;                                              +      adi,ad4003 
-                                                                                   +      - adi,ad4004 
-                 adi,channels {                                                    +      - adi,ad4005 
-                         #size-cells = <0>;                                        +      - adi,ad4006 
-                         #address-cells = <1>;                                     +      - adi,ad4007 
-                                                                                   +      - adi,ad4008 
-                         dma-channel@0 {                                           +      - adi,ad4010 
-                                 reg = <0>;                                        +      - adi,ad4011 
-                                 adi,source-bus-width = <32>;                      +      - adi,ad4020 
-                                 adi,source-bus-type = <1>;                        +      - adi,ad4021 
-                                 adi,destination-bus-width = <64>;                 +      - adi,ad4022 
-                                 adi,destination-bus-type = <0>;                   +      - adi,adaq4003 
-                         };                                                        + 
-                 };                                                                +  reg: true 
-         };                                                                        +  spi-max-frequency: true 
-                                                                                   + 
-         axi_spi_engine_0: axi-spi-engine@44a00000                               +  dmas: 
-                 compatible = "adi,axi-spi-engine-1.00.a";                         +    description:
-                 reg = <0x44a00000 0x1000>;                                        +      DMA specifier, consisting of a phandle to DMA controller node. 
-                 interrupt-parent = <&intc>;                                       +    maxItems: 
-                 interrupts = <0 56 4>;                                            + 
-                 clocks = <&clkc 15 &clkc 15>;                                     +  dma-names: 
-                 clock-names = "s_axi_aclk", "spi_clk";                            +    const: rx 
-                 num-cs = <1>;                                                     + 
-                                                                                  +  clocks: 
-                 #address-cells = <0x1>;                                           +    maxItems: 1 
-                 #size-cells = <0x0>;                                              + 
-                                                                                   +  clock-names: 
-                 ad4020: adc@0 {                                                   +    const: ref_clk 
-                         compatible = "ad4020";                                    +    description: AD400X reference clock name. 
-                         reg = <0>;                                                + 
-                         spi-max-frequency = <71000000>;                           +  pwms: 
-                                                                                   +    description:
-                         dmas = <&rx_dma 0>;                                       +      PWM used as trigger source for the SPI enginealso represents the 
-                         dma-names = "rx";                                         +      acquisition rate for the samples. 
-                                                                                   +    maxItems: 1 
-                         vref-supply = <&vref>;                                    + 
-                         #io-channel-cells = <1>;                                  +  pwm-names: 
-                 };                                                                +    const: cnv 
-         };                                                                        + 
- };    +  vref-supply: 
 +    description: Phandle to the regulator for ADC reference voltage. 
 + 
 +  '#address-cells': 
 +    const: 
 + 
 +  '#size-cells': 
 +    const: 0 
 + 
 +patternProperties: 
 +  "^channel@([0-1])$": 
 +    $ref: adc.yaml 
 +    type: object 
 +    description: Represents the external channel connected to the ADC. 
 + 
 +    properties: 
 +      reg: 
 +        maxItems:
 + 
 +      diff-channels: true 
 + 
 +    required: 
 +      reg 
 + 
 +    additionalProperties: false 
 + 
 +required: 
 +  compatible 
 +  reg 
 +  - dmas 
 +  - dma-names 
 +  - vref-supply 
 + 
 +allOf: 
 +  - $ref: /schemas/spi/spi-peripheral-props.yaml# 
 + 
 +  - if: 
 +      properties: 
 +        compatible: 
 +          contains: 
 +            enum: 
 +              - adi,adaq4003 
 + 
 +    then: 
 +      required: 
 +        compatible 
 +        reg 
 +        - dmas 
 +        - dma-names 
 +        - clocks 
 +        - clock-names 
 +        - pwms 
 +        - pwm-names 
 +        - vref-supply 
 + 
 +unevaluatedProperties: false 
 + 
 +examples: 
 +  - | 
 +    spi { 
 +        #address-cells = <1>; 
 +        #size-cells = <0>; 
 +        /* Example for a AD400X devices */ 
 +        adc@
 +            compatible = "adi,ad4020"; 
 +            reg = <0>; 
 +            spi-max-frequency = <71000000>; 
 +            vref-supply = <&vref>; 
 + 
 +            dmas = <&rx_dma 0>; 
 +            dma-names = "rx"; 
 + 
 +            #address-cells = <1>; 
 +            #size-cells = <0>; 
 + 
 +            channel@0 { 
 +                reg = <0>; 
 +                diff-channels = <0 1>; 
 +            }; 
 +        }; 
 +    }; 
 +  - | 
 +    spi { 
 +        #address-cells = <1>; 
 +        #size-cells = <0>; 
 + 
 +        /* Example for a ADAQ400X devices */ 
 +        adc@0 { 
 +            compatible = "adi,adaq4003"; 
 +            reg = <0>; 
 +            spi-max-frequency = <80000000>; 
 +            dmas = <&rx_dma 0>; 
 +            dma-names = "rx"; 
 +            clocks = <&spi_clk>; 
 +            clock-names = "ref_clk"; 
 +            pwms = <&adc_trigger 0 0>; 
 +            pwm-names = "cnv"; 
 +            vref-supply = <&vref>; 
 + 
 +            #address-cells = <1>; 
 +            #size-cells = <0>; 
 + 
 +            channel@0 { 
 +                reg = <0>; 
 +                diff-channels = <0 1>; 
 +            }; 
 +        }; 
 +    };
 </xterm></WRAP> </xterm></WRAP>
 +
 +See the [[resources:eval:ad400x-eval-board|Evaluating AD400X and ADAQ400X devices]] user guide for examples of device trees used with devices supported by the ad400x Linux driver.
 +
 +====== Adding Linux driver support ======
 +
 +===== Enabling the driver =====
 +
 +Configure kernel with "make menuconfig" (alternatively use "make xconfig" or
 +"make qconfig")
 +
 +<WRAP round help>
 +The AD400x driver depends on **CONFIG_SPI_MASTER**
 +</WRAP>
 +
 +<code>
 +Linux Kernel Configuration
 +    Device Drivers  --->
 +        ...
 +        <*>     Industrial I/O support --->
 +            --- Industrial I/O support
 +            ...
 +            Analog to digital converters  ---> 
 +                ...
 +                <*>   Analog Devices AD400X ADC Driver
 +                ...
 +            ...
 +        ...
 +
 +</code>
 +
  
 ====== Driver testing ====== ====== Driver testing ======
Line 98: Line 254:
 <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 <xterm> <xterm>
-root@analog:/sys/bus/iio/devices# ls -l+root@analog:~# ls -l /sys/bus/iio/devices/
 total 0 total 0
-lrwxrwxrwx 1 root root 0 Jan  1  1970 iio:device0 -> ../../../devices/soc0/fpga-axi@0/44a00000.axi-spi-engine/spi_master/spi0/spi0.0/iio:device0 +lrwxrwxrwx 1 root root 0 Apr  2 21:42 iio:device0 -> ../../../devices/soc0/axi/f8007100.adc/iio:device0 
-lrwxrwxrwx 1 root root 0 Jan  1  1970 iio:device1 -> ../../../devices/soc0/amba/f8007100.adc/iio:device1 +lrwxrwxrwx 1 root root 0 Apr  2 21:43 iio:device1 -> ../../../devices/soc0/fpga-axi@0/44a00000.spi/spi_master/spi0/spi0.0/iio:device1 
-lrwxrwxrwx 1 root root 0 Jan  1  1970 iio_sysfs_trigger -> ../../../devices/iio_sysfs_trigger+lrwxrwxrwx 1 root root 0 Apr  2 21:42 iio_sysfs_trigger -> ../../../devices/iio_sysfs_trigger
  
-root@analog:/sys/bus/iio/devices#  +root@analog:~# ls -l /sys/bus/iio/devices/iio:device1/
-root@analog:/sys/bus/iio/devices# cd iio\:device0 +
-root@analog:/sys/bus/iio/devices/iio:device0# ls -l+
 total 0 total 0
-drwxrwxrwx 2 root root    0 Jan  1  1970 buffer +drwxr-xr-x 2 root root    0 Apr  2 21:43 buffer 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 dev +drwxr-xr-x 2 root root    0 Apr  2 21:43 buffer0 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 in_voltage0_raw +-r--r--r-- 1 root root 4096 Apr  2 21:43 dev 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 in_voltage0_scale +-rw-r--r-- 1 root root 4096 Apr  2 21:43 in_voltage0_offset 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 name +-rw-r--r-- root root 4096 Apr  2 21:43 in_voltage0_raw 
-lrwxrwxrwx 1 root root    0 Nov  08:43 of_node -> ../../../../../../../../firmware/devicetree/base/fpga-axi@0/axi-spi-engine@44a00000/adc@0 +-rw-r--r-- 1 root root 4096 Apr  2 21:43 in_voltage0_scale 
-drwxrwxrwx 2 root root    0 Jan  1  1970 power +-r--r--r-- 1 root root 4096 Apr  2 21:43 name 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 sampling_frequency +lrwxrwxrwx 1 root root    0 Apr  21:43 of_node -> ../../../../../../../../firmware/devicetree/base/fpga-axi@0/spi@44a00000/adc@0 
-drwxrwxrwx 2 root root    0 Jan  1  1970 scan_elements +drwxr-xr-x 2 root root    0 Apr  2 21:43 power 
-lrwxrwxrwx 1 root root    0 Nov  08:43 subsystem -> ../../../../../../../../bus/iio +-rw-r--r-- 1 root root 4096 Apr  2 21:43 sampling_frequency 
--rw-rw-rw- 1 root root 4096 Jan  1  1970 uevent +drwxr-xr-x 2 root root    0 Apr  2 21:43 scan_elements 
 +lrwxrwxrwx 1 root root    0 Apr  21:43 subsystem -> ../../../../../../../../bus/iio 
 +-rw-r--r-- 1 root root 4096 Apr  2 21:43 uevent
 </xterm></WRAP> </xterm></WRAP>
  
Line 126: Line 281:
 <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 <xterm> <xterm>
-root@analog:/sys/bus/iio/devices/iio:device0# cat name +root@analog:~# cat /sys/bus/iio/devices/iio:device1/name 
-ad4020+adaq4003
 </xterm></WRAP> </xterm></WRAP>
  
Line 133: Line 288:
  
 **Description:**\\ **Description:**\\
-Scale to be applied to in_voltagex_raw in order to obdatin the measured voltage in millivolts+Scale to be applied to in_voltagex_raw in order to obtain the measured voltage in millivolts
  
 <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> <WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 <xterm> <xterm>
-root@analog:/sys/bus/iio/devices/iio:device0# cat in_voltage0_scale  +root@analog:~# cat /sys/bus/iio/devices/iio:device1/in_voltage0_scale 
-0.002384185+0.019073486
 </xterm></WRAP> </xterm></WRAP>
 +
 +=== Configure sampling rate ===
 +
 +**__Description:__** /sys/bus/iio/devices/iio:deviceX/sampling_frequency \\
 +Configures the input sampling rate.
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:~# cat /sys/bus/iio/devices/iio:device1/sampling_frequency
 +2000000
 +</xterm></WRAP>
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:~# **echo 1000000 > /sys/bus/iio/devices/iio:device1/sampling_frequency**
 +root@analog:~# cat /sys/bus/iio/devices/iio:device1/sampling_frequency
 +1000000
 +</xterm></WRAP>
 +
 +
 +===== Buffer management =====
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:~# ls -l /sys/bus/iio/devices/iio:device1/buffer/
 +total 0
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 data_available
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 direction
 +-rw-r--r-- 1 root root 4096 Apr  3 08:11 enable
 +-rw-r--r-- 1 root root 4096 Apr  3 08:11 length
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 length_align_bytes
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 watermark
 +</xterm></WRAP>
 +
 +{{page>software:linux:docs:iio:iio_snippets#Buffer management&noheader&firstseconly&noeditbtn}}
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:~# ls -l /sys/bus/iio/devices/iio:device1/scan_elements/
 +total 0
 +-rw-r--r-- 1 root root 4096 Apr  3 08:11 in_voltage0_en
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 in_voltage0_index
 +-r--r--r-- 1 root root 4096 Apr  3 08:11 in_voltage0_type
 +</xterm></WRAP>
 +
 +{{page>software:linux:docs:iio:iio_snippets#Typical ADC scan elements&noheader&firstseconly&noeditbtn}}
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:/sys/bus/iio/devices/iio:device1/scan_elements# grep "" *
 +in_voltage0_en:0
 +in_voltage0_index:0
 +in_voltage0_type:le:s18/32>>0
 +</xterm></WRAP>
 +
 +===== Buffer Example =====
 +
 +When the buffer is enabled, the ad400x driver prepares a read transfer and configures the [[resources:fpga:peripherals:spi_engine:offload|SPI Engine Offload]] module to repeat that transfer each time the offload module is triggered. Then, the ad400x driver sets a PWM device to trigger the offload module at the rate specified by the ''sampling_frequency'' attribute. With that, ADC readings are gathered continuously while the buffer remains enabled.
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target - Example command sequence</wrap>
 +<xterm>
 +root@analog:~# echo 1 > /sys/bus/iio/devices/iio:device1/scan_elements/in_voltage0_en
 +root@analog:~# cat /sys/bus/iio/devices/iio:device1/scan_elements/in_voltage0_en
 +1
 +root@analog:~# echo 1 > /sys/bus/iio/devices/iio:device1/buffer/enable
 +root@analog:~# cat /sys/bus/iio/devices/iio:device1/buffer/data_available
 +32768
 +</xterm></WRAP>
 +
 +==== Data interpretation ====
 +
 +Each buffer entry contains one sample. The amount of bits and their meaning will vary according to ADC precision and output code pattern (whether output code is twos complement or not). Buffer raw data may be retrieved by reading the character device associated with the ADC device.
 +
 +<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap>
 +<xterm>
 +root@analog:~# hexdump -n 512 -e ' 32 "%d " "\n"' /dev/iio:device1
 +4864 4889 4730 4716 4695 4678 4667 4659 4662 4676 4706 4738 4770 4789 4786 4785 4775 4763 4752 4737 4723 4703 4686 4673 4666 4672 4688 4715 4762 4799 4820 4821
 +4816 4807 4788 4773 4757 4737 4718 4694 4676 4664 4668 4692 4727 4777 4814 4837 4836 4829 4822 4808 4796 4771 4748 4728 4707 4685 4664 4654 4651 4659 4675 4709
 +4757 4801 4823 4826 4812 4800 4789 4770 4749 4724 4700 4677 4653 4644 4633 4639 4659 4695 4738 4777 4798 4799 4794 4785 4772 4755 4735 4712 4692 4668 4652 4646
 +4641 4648 4674 4709 4753 4793 4817 4818 4808 4797 4780 4764 4748 4724 4699 4674 4656 4639 4627 4633 4644 4677 4716 4765 4794 4804 4801 4791 4778 4763 4744 4721
 +</xterm></WRAP>
 +
 +Remove the ''-n'' parameter to keep reading the buffer continuously. To stop capture, disable the buffer by writing 0 to ''/sys/bus/iio/devices/iio:device1/buffer/enable''.
  
 ====== More Information ====== ====== More Information ======
  
 {{page>software:linux:docs:iio:iio_snippets#iio pointers&noheader&firstseconly&noeditbtn}} {{page>software:linux:docs:iio:iio_snippets#iio pointers&noheader&firstseconly&noeditbtn}}
resources/tools-software/linux-drivers/iio-adc/ad400x.1541577389.txt.gz · Last modified: 07 Nov 2018 08:56 by Mircea Caprioru