1 year ago

#25098

test-img

Aro Math

Implementing AD7606 driver for Raspberry Pi 4b

I am trying to implement ADC AD7606 device driver for Linux on Raspberry Pi 4B+ to make possible to read data from all channels as fast as it possible via SPI. The kernel version is v5.10.83 and the kernel was compiled and installed with support both AD7606 and AD7606_SPI as modules (make menuconfig).

The device tree overlay was created by using example on Analog Devices https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad7606 and now it is like this:

/dts-v1/;
/plugin/;

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

/ {
    compatible = "brcm,bcm2835";
    fragment@0 {
    target = <&spi0>;
    __overlay__ {
        #address-cells = <1>;
        #size-cells = <0>;
        adc0: adc@0 {
            compatible = "adi,ad7606-8";
            reg = <0>;
            spi-max-frequency = <1000000>;
            spi-cpol;
            spi-cpha;

            interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
            interrupt-parent = <&gpio>;
            adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
            reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
            adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
            adi,oversampling-ratio-gpios = <&gpio 18 GPIO_ACTIVE_HIGH>,
                                           <&gpio 23 GPIO_ACTIVE_HIGH>,
                                           <&gpio 26 GPIO_ACTIVE_HIGH>;
            standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
            adi,sw-mode;
            };
    
        };
    };
};

The overlay is activated in /boot/config.txt and reverted DT section for SPI is like this:

spi@7e204000 {
            compatible = "brcm,bcm2835-spi";
            clocks = < 0x08 0x14 >;
            status = "okay";
            #address-cells = < 0x01 >;
            interrupts = < 0x00 0x76 0x04 >;
            cs-gpios = < 0x07 0x08 0x01 0x07 0x07 0x01 >;
            #size-cells = < 0x00 >;
            dma-names = "tx\0rx";
            phandle = < 0x33 >;
            reg = < 0x7e204000 0x200 >;
            pinctrl-0 = < 0x0e 0x0f >;
            dmas = < 0x0c 0x06 0x0c 0x07 >;
            pinctrl-names = "default";

            adc@0 {
                spi-cpol;
                compatible = "adi,ad7606-8";
                adi,conversion-start-gpios = < 0x07 0x11 0x00 >;
                spi-cpha;
                adi,first-data-gpios = < 0x07 0x16 0x00 >;
                adi,oversampling-ratio-gpios = < 0x07 0x12 0x00 0x07 0x17 0x00 0x07 0x1a 0x00 >;
                interrupt-parent = < 0x07 >;
                interrupts = < 0x19 0x02 >;
                reset-gpios = < 0x07 0x1b 0x00 >;
                phandle = < 0xe9 >;
                standby-gpios = < 0x07 0x18 0x01 >;
                reg = < 0x00 >;
                adi,sw-mode;
                spi-max-frequency = < 0xf4240 >;
            };

            spidev@1 {
                compatible = "spidev";
                #address-cells = < 0x01 >;
                #size-cells = < 0x00 >;
                phandle = < 0xb0 >;
                reg = < 0x01 >;
                spi-max-frequency = < 0x7735940 >;
            };

            spidev@0 {
                compatible = "spidev";
                #address-cells = < 0x01 >;
                #size-cells = < 0x00 >;
                phandle = < 0xaf >;
                reg = < 0x00 >;
                spi-max-frequency = < 0x7735940 >;
            };
        };

During kernel boot with activated this overlay I have kernel message:

[    5.171792] spi-bcm2835 fe204000.spi: chipselect 0 already in use
[    5.171827] spi_master spi0: spi_device register error /soc/spi@7e204000/spidev@0
[    5.171861] spi_master spi0: Failed to create SPI device for /soc/spi@7e204000/spidev@0

How to resolve this problem or make troubleshooting?

linux-device-driver

kernel-module

adc

iio

0 Answers

Your Answer

Accepted video resources