inac
Posts: 7
Joined: Thu Nov 16, 2017 3:58 pm

SPI0 still having spidev0.1 after loading new modified overlay

Tue Sep 25, 2018 3:24 pm

Hello all,

I'm trying to get the SPI0 running at pins 36-39. i.e. CE1 (at pin 35) is not used and free for other usage.

Therefore I modified one overlay as shown below. The problem is that there are still 2 devices

Code: Select all

[email protected]:~ $ ls /dev | grep spi
spidev0.0
spidev0.1

How can I get rid of device spidev0.1 (why is it there anyhow)?
How can I be sure that only pin 36 is used for CE and not accidentally 35 (so 35 is free 100% sure)?

Code: Select all

/dts-v1/;
/plugin/;


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

	[email protected] {
		target = <&gpio>;
		__overlay__ {
			spi0_pins: spi0_pins {
				brcm,pins = <37 38 39>;
				brcm,function = <4>;     /* alt0 was <3> alt4 */
			};

			spi0_cs_pins: spi0_cs_pins {
				brcm,pins = <36>;
				brcm,function = <1>; /* output */
			};
		};
	};

	[email protected] {
		target = <&spi0>;
		frag1: __overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;
			pinctrl-names = "default";
			pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
			cs-gpios = <&gpio 36 1>;
			status = "okay";

			spidev0_0: [email protected] {
				compatible = "spidev";
				reg = <0>;      /* CE0 */
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <125000000>;
				status = "okay";
			};
		};
	};

	[email protected] {
		target = <&aux>;
		__overlay__ {
			status = "okay";
		};
	};

	__overrides__ {
		cs0_pin  = <&spi0_cs_pins>,"brcm,pins:0",
			   <&frag1>,"cs-gpios:4";
		cs0_spidev = <&spidev0_0>,"status";
	};
};
with log

Code: Select all

013998.954: brfs: File read: /mfs/sd/overlays/spi0-1cs.dtbo
014015.350: Loaded overlay 'spi0-1cs'
014015.474: dtdebug: Found fragment 0 (offset 60)
014018.488: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
014023.398: dtdebug: merge_fragment(/soc/[email protected]/spi0_pins,/[email protected]/__overlay__/spi0_pins)
014023.425: dtdebug:   +prop(brcm,pins)
014025.453: dtdebug:   +prop(brcm,function)
014027.465: dtdebug:   +prop(phandle)
014029.489: dtdebug: merge_fragment() end
014034.496: dtdebug: merge_fragment(/soc/[email protected]/spi0_cs_pins,/[email protected]/__overlay__/spi0_cs_pins)
014034.523: dtdebug:   +prop(brcm,pins)
014036.533: dtdebug:   +prop(brcm,function)
014038.537: dtdebug:   +prop(phandle)
014040.571: dtdebug: merge_fragment() end
014040.601: dtdebug: merge_fragment() end
014040.693: dtdebug: Found fragment 1 (offset 264)
014051.157: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
014051.184: dtdebug:   +prop(#address-cells)
014053.082: dtdebug:   +prop(#size-cells)
014055.001: dtdebug:   +prop(pinctrl-names)
014056.939: dtdebug:   +prop(pinctrl-0)
014058.894: dtdebug:   +prop(cs-gpios)
014060.855: dtdebug:   +prop(status)
014066.709: dtdebug: merge_fragment(/soc/[email protected]/[email protected],/[email protected]/__overlay__/[email protected])
014066.736: dtdebug:   +prop(compatible)
014068.567: dtdebug:   +prop(reg)
014070.406: dtdebug:   +prop(#address-cells)
014072.253: dtdebug:   +prop(#size-cells)
014074.113: dtdebug:   +prop(spi-max-frequency)
014076.001: dtdebug:   +prop(status)
014078.055: dtdebug:   +prop(phandle)
014079.950: dtdebug: merge_fragment() end
014079.985: dtdebug: merge_fragment() end
014080.083: dtdebug: Found fragment 2 (offset 592)
014092.520: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
014092.547: dtdebug:   +prop(status)
014094.499: dtdebug: merge_fragment() end

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

Re: SPI0 still having spidev0.1 after loading new modified overlay

Tue Sep 25, 2018 3:47 pm

When specify new properties for a DT node using an overlay, the properties are merged with the existing values (and frustratingly it isn't possible to delete properties from an overlay). Thus your fragment 1, as well as rewriting many properties with their existing values, is overwriting the whole [email protected] node (which I consider bad form - the kernel agrees, and will object to a runtime overlay that tries to), but leaving [email protected] untouched.

Something like this ought to work:

Code: Select all

/dts-v1/;
/plugin/;


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

	[email protected] {
		target = <&spi0_pins>;
		__overlay__ {
			brcm,pins = <37 38 39>;
			brcm,function = <4>;     /* alt0 was <3> alt4 */
		};
	};

	[email protected] {
		target = <&spi0_cs_pins>;
		frag1: __overlay__ {
			brcm,pins = <36>;
			brcm,function = <1>; /* output */
		};
	};

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

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

	[email protected] {
		target = <&spi0>;
		frag4: __overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;
			cs-gpios = <&gpio 36 1>;
			status = "okay";
		};
	};

	[email protected] {
		target = <&aux>;
		__overlay__ {
			status = "okay";
		};
	};

	__overrides__ {
		cs0_pin  = <&frag1>,"brcm,pins:0",
			   <&frag4>,"cs-gpios:4";
		cs0_spidev = <&frag2>,"status";
	};
};

inac
Posts: 7
Joined: Thu Nov 16, 2017 3:58 pm

Re: SPI0 still having spidev0.1 after loading new modified overlay

Thu Sep 27, 2018 4:36 pm

Thanks that works!

I find it hard to find out in which file the original values are stored but this works.

Kind regards

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

Re: SPI0 still having spidev0.1 after loading new modified overlay

Wed Oct 03, 2018 10:05 am

You may find the "ovmerge" utility in our utils repo helpful. It can flatten a .dts file with includes, show the include hierarchy, and apply overlays. Unlike dtoverlay it works in the source code domain so labels are preserved.

Code: Select all

$ cd arch/arm/boot/dts
$ ovmerge -i bcm2710-rpi-3-b.dts
bcm2710-rpi-3-b.dts
    bcm2710.dtsi
        bcm2837.dtsi
            bcm283x.dtsi
        bcm270x.dtsi
        bcm2708-rpi.dtsi
    bcm283x-rpi-smsc9514.dtsi
$ ovmerge bcm2710-rpi-3-b.dts > base.dts
$ ovmerge base.dts overlays/spi0-cs-overlay.dts,cs0_pin=20,cs1_pin=21 > with-overlay.dts
$ diff base.dts with-overlay.dts
305,306c305,306
< 			spi0_cs_pins: spi0_cs_pins {
< 				brcm,pins = <8 7>;
---
> 			spi0_cs_pins: frag0: spi0_cs_pins {
> 				brcm,pins = <20 21>;
383c383
< 		spi: spi0: [email protected] {
---
> 		spi: spi0: frag1: [email protected] {
390c390
< 			status = "disabled";
---
> 			status = "okay";
395c395
< 			cs-gpios = <&gpio 8 1>, <&gpio 7 1>;
---
> 			cs-gpios = <&gpio 20 1>, <&gpio 21 1>;
830a831,832
> 	};
> 	__symbols__ {

Return to “Device Tree”