Post Go back to editing

Using AD7476A IIO Single Channel Serial ADC Linux Driver with Kuiper Linux for AD7091R

Category: Hardware
Product Number: AD7091R

Hello,

i want to use the AD7091R for measuring a 4-20 mA Signal at 300 kSPS - i plugged in an EVAL-CN0336-PMDZ Evaluation Board into a PMod HAT on a Raspberry Pi 4, which is running the 2023-12-13-ADI-Kuiper-full.img Linux image.

Taking a look at the kernel config, i see that the driver, which i presume is the correct one for the ad7091r is built-in: -> Device Drivers -> Industrial I/O support  ->  Analog to digital converters -> Analog Devices AD7476 1-channel ADCs driver and other similar devices from AD and TI.

For the AD7091r or AD7476 i cant find a pre-compiled device tree overlay for that chip. I think i need to create one, maybe based on an existing one?

The tutorial here https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad7476a#example_platform_device_initialization gives some infos, but i am a bit lost.

Could you advise what to do to get the ad7091r showing up in /sys/bus/iio/devices/ ?

Thanks!

Edit Notes

Shortened and pointed out that the result should be recognising the device by the OS in /sys/bus/iio/devices.
[edited by: CBellmann at 3:36 PM (GMT -5) on 14 Feb 2024]

Thread Notes

  • Hi  ,

    I'll contact the product owner and get back to you.

    Regards,
    Jo

  • Hello  ,

    Can we get some snapshots on how are you configuring the code based on the tutorial?

    Regards,
    Jo

  • Hello NathanT,

    thank you for following up.

    I started to write the file ad7091r.dts to compile into ad7091r.dtbo.

    My Intention is add to the device in /boot/config.txt: dtoverlay=ad7091r.

    So far, my ad7091r.dts looks like this: (following lines are inside tics because "code" block of the Forum post cuts away text in <>)

    ```

    // SPDX-License-Identifier: GPL-2.0

    /dts-v1/;
    /plugin/;

    #include <dt-bindings/interrupt-controller/irq.h>
    #include <dt-bindings/gpio/gpio.h>

    / {
        compatible = "brcm,bcm2835", "brcm,bcm2711";
    };

    &gpio {
        ad7091r_pins: ad7091r_pins {
            brcm,pins = <22>; // interrupt
            brcm,function = <0>; // input
        };
    };

    &gpio {
        ad7091r_reset: ad7091r_reset {
            brcm,pins = <27>; // reset
            brcm,function = <0>; // input
        };
    };

    &spi0 {
        status = "okay";

        cs-gpios = <&gpio 8 GPIO_ACTIVE_LOW>;

        ad7091r@0 {
            compatible = "adi,ad7091r";
            reg = <0>;
            spi-max-frequency = <1000000>;
            convst-gpios = <&gpio 25 GPIO_ACTIVE_LOW>;
            reset-gpios = <&gpio_ad7091r_reset 27 GPIO_ACTIVE_LOW>; // Use the defined GPIO node
            pinctrl-names = "default";
            pinctrl-0 = <&ad7091r_pins>;
            interrupt-parent = <&gpio>;
            interrupts = <22 IRQ_TYPE_EDGE_FALLING>;
        };
    };

    &spidev0 {
        status = "disabled";
    };

    &spidev1 {
        status = "disabled";
    };

    ```

    For compilation, i did the following, whereas the dtc command failed.

    # cd /usr/src
    # sudo git clone --depth=1 --branch rpi-6.1.y https://github.com/analogdevicesinc/linux
    # cd /home/analog/createDeviceTree
    # cpp -nostdinc -I include -I arch -I/usr/src/linux/include -undef -x assembler-with-cpp  ad7091r.dts ad7091r.dts.preprocessed
    # dtc -I dts -O dtb -o ad7091r.dtb ad7091r.dts.preprocessed 

    The output of the dtc command is:

    ad7091r.dts:34.9-19: Warning (reg_format): /fragment@2/__overlay__/ad7091r@0:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
    ad7091r.dtb: Warning (pci_device_reg): Failed prerequisite 'reg_format'
    ad7091r.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format'
    ad7091r.dtb: Warning (simple_bus_reg): Failed prerequisite 'reg_format'
    ad7091r.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'
    ad7091r.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
    ad7091r.dts:32.15-42.7: Warning (avoid_default_addr_size): /fragment@2/__overlay__/ad7091r@0: Relying on default #address-cells value
    ad7091r.dts:32.15-42.7: Warning (avoid_default_addr_size): /fragment@2/__overlay__/ad7091r@0: Relying on default #size-cells value
    ad7091r.dtb: Warning (avoid_unnecessary_addr_size): Failed prerequisite 'avoid_default_addr_size'
    ad7091r.dtb: Warning (unique_unit_address): Failed prerequisite 'avoid_default_addr_size'

    From the tutorial i did not understand where the c structs are to be placed (if necessary in my case) so i jumped to creating the device tree overlay file instead.

    I am new to device tree, i hope you can help me with setting it up.

    Best regards,

    Christoph

  • Hello ,

    i see that the development for running these ADCs on linux is fairly new and the infos are quite promising. From what i understand is, the driver in c for the ad7091r is in the linux kernel. Not sure if compiling and running it would help? It is already enabled in the kernel config.

    So i went to look at the devicetree documentation to try to create a overlay file. I did make install yamldt and tried the following:

     analog@analog:~/kernel $ yamldt --in-format=yaml linux/Documentation/devicetree/bindings/iio/adc/adi,ad7091r5.yaml -o ad7091r5.dtbo

    The output though is:

    error: found incompatible YAML document.

    It looks like everything is there, but i do not know how to use it. Thanks a lot for your help, i hope you see where i am am stuck and can give me an advice on using the driver.

    Best,

    Christoph

  • Hello  ,

    Thank you for your patience. They are currently looking into this query.

    Warm regards,
    Jo

  • Dear ,

    thanks a lot! We have four EVAL-CN0336-PMDZ boards on the desk for integration, not in a hurry but waiting.

    I am looking forward to your reply,

    have a great day,

    Christoph

  • Hello  ,

    Thank you for your patience. They are currently looking into this. 

    Warm regards,
    Jo

  • I followed the git repo here: https://github.com/karu2003/rpi_ad7476 because it has a dts file provided.

    Its for the ad7476a, which is different from the ad7091r. But still i managed to get the output:

    analog@analog:~ $ cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
    2207
    analog@analog:~ $ cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
    0

    First line after reboot is a number, but every other time the value is 0.