Nige7
Posts: 4
Joined: Tue May 14, 2019 1:32 pm

AD7766

Tue May 14, 2019 1:40 pm

I have compiled the ad7766.c from torvalds and it will install fine with modprobe, but with no context (iio). I understand this needs a dtoverlay. I have tried many times and can't get it to work. I would be very grateful if someone could help me.

[email protected]_7:~/ad7766 $ sudo dtoverlay ad7766
* Failed to apply overlay '1_ad7766' (kernel)

dmesg:

[ 8107.054964] OF: resolver: overlay phandle fixup failed: -22
[ 8107.054971] create_overlay: Failed to resolve tree

My overlay is:

/dts-v1/;
/plugin/;

/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

/* the spi config binding everything together */
[email protected] {
target = <&spi0>;
__overlay__ {
status = "okay";
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
adc1: [email protected] {
compatible = "adi,ad7766";
reg = <0>;
cs-gpios = <0>;
pinctrl-names = "default";
pinctrl-0 = <&adc1_pins>;
interrupt-parent = <&gpio>;
interrupts = <5 0x2>; /* falling edge */
irq-gpio = <&gpio 45 0>;
spi-max-frequency = <1000000>;
clocks = <&mclk>;
clock-names = "mclk";
vref-supply=<&vref>;
};
};
};

[email protected] {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
};

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2148
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: AD7766

Tue May 14, 2019 3:13 pm

Here's your overlay with added indentation, and a clue:

Code: Select all

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

	/* the spi config binding everything together */
	[email protected] {
		target = <&spi0>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;

			status = "okay";
			adc1: [email protected] {
				compatible = "adi,ad7766";
				reg = <0>;
				cs-gpios = <0>;
				pinctrl-names = "default";
				pinctrl-0 = <&adc1_pins>; // <=== NOT DEFINED
				interrupt-parent = <&gpio>;
				interrupts = <5 0x2>; /* falling edge */
				irq-gpio = <&gpio 45 0>;
				spi-max-frequency = <1000000>;
				clocks = <&mclk>;
				clock-names = "mclk";
				vref-supply=<&vref>;
			};
		};
	};

	[email protected] {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};
};

Nige7
Posts: 4
Joined: Tue May 14, 2019 1:32 pm

Re: AD7766

Wed May 15, 2019 10:26 am

Thank you.

Apparently, I do not need the pin settings, but I still have the same problem. Do the references &gpio, &mclk also need to be defined?

Nigel

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2148
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: AD7766

Wed May 15, 2019 2:08 pm

Any unresolved references at the point where the overlay is applied to the base DTB will prevent the overlay from being applied. "gpio" is a label declared in the base DTBs, so that should work.

The driver does seem to want a valid "mclk", and will fail without one; you'll have to find out what is needed, and then declare it (probably as a "fixed-clock") somewhere - search the other overlays for "fixed-clock" for the general idea. It also wants three regulators, but the regulator framework should invent dummy regulators for any that aren't found, so try just deleting the line "vref-supply=<&vref>;" (unless your module requires something to be switched on).

Nige7
Posts: 4
Joined: Tue May 14, 2019 1:32 pm

Re: AD7766

Thu May 16, 2019 2:06 pm

Thank you again.

I have now a working DTS. I have tried everything to start the driver. This is what I found:

echo ad7766-2-dev0 > /sys/bus/iio/devices/iio:device0/trigger/current_trigger

iio_info:

Code: Select all

Library version: 0.18 (git tag: 4e22517)
Compiled with backends: local xml ip usb serial
IIO context created with local backend.
Backend version: 0.18 (git tag: 4e22517)
Backend description string: Linux BuddiPD_7 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l
IIO context has 1 attributes:
        local,kernel: 4.14.98-v7+
IIO context has 2 devices:
        iio:device0: ad7766-2 (buffer capable)
                2 channels found:
                        voltage0:  (input, index: 0, format: be:s24/32>>0)
                        1 channel-specific attributes found:
                                attr  0: scale value: 0.000149011
                        timestamp:  (input, index: 1, format: le:S64/64>>0)
                2 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: sampling_frequency value: 2400
                1 buffer-specific attributes found:
                                attr  0: watermark value: 1
        trigger0: ad7766-2-dev0
                0 channels found:

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2148
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: AD7766

Mon May 20, 2019 8:57 am

I have no experience with the iio subsystem. What do you think this result is telling you?

Nige7
Posts: 4
Joined: Tue May 14, 2019 1:32 pm

Re: AD7766

Fri May 24, 2019 3:49 pm

Thank you for all your help. I now have it working. I found the answers in 'iio_readdev.c'.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2148
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: AD7766

Fri May 24, 2019 3:59 pm

Is your solution something that could be generally used by others? Would you be prepared to share it here? I'd be happy to add the overlay to the standard kernel set, even if it is only used as an example.

Return to “Device Tree”