Self-help group to understand device tree overlays


#35

I’m not sure why we need the clocks property in your overlay though. It should already be set in the base device tree, did something not work?

Removing that property should not trigger the bug anymore (and we will fix that bug in a next release)


#36

Same here but it didn’t work when I’ve removed the line. I saw messages about missing clock definition in dmesg output.
Jkw
PS: thanks for the fix


#37

If you still have those messages somewhere, I’m interested. You definitely shouldn’t need that in your overlay


#38

Not that you couldn’t do that yourself … but sure :stuck_out_tongue:

I’ve taken this file as base and removed the mmc-clk line, placed it in the early and got
https://raw.githubusercontent.com/KoljaWindeler/CHIP_TZATZIFFY/ace4fc336ee011937f0bb2e9d009f845215b961f/overlay/dip-2a-2.dts

root@dark_frame:~# dmesg | grep mmc
[    2.205000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe
[    2.735000] sunxi-mmc 1c0f000.mmc: No vqmmc regulator found
[    2.745000] sunxi-mmc 1c0f000.mmc: allocated mmc-pwrseq
[    2.785000] sunxi-mmc 1c0f000.mmc: base:0xe01fa000 irq:20
[    2.790000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe
[    3.000000] sunxi-mmc 1c0f000.mmc: smc 0 err, cmd 8, RTO !!
[    3.020000] mmc0: new high speed SDIO card at address 0001
[    8.975000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe
[   15.430000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe
[   16.180000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe
[   16.475000] sunxi-mmc 1c11000.mmc: could not find pctldev for node /soc@01c00000/interrupt-controller@01c20400, deferring probe

then replaced the file with the single files


in early and

in non-early

rebooted and got my sd card …

root@dark_frame:~# dmesg | grep mmc
[    2.715000] sunxi-mmc 1c0f000.mmc: No vqmmc regulator found
[    2.725000] sunxi-mmc 1c0f000.mmc: allocated mmc-pwrseq
[    2.765000] sunxi-mmc 1c0f000.mmc: base:0xe01fa000 irq:20
[    2.790000] sunxi-mmc 1c0f000.mmc: smc 0 err, cmd 8, RTO !!
[    2.810000] mmc0: new high speed SDIO card at address 0001
[   10.630000] sunxi-mmc 1c11000.mmc: Got CD GPIO
[   10.675000] sunxi-mmc 1c11000.mmc: base:0xe0cce000 irq:113
[   10.915000] mmc1: host does not support reading read-only switch, assuming write-enable
[   10.970000] mmc1: new high speed SDHC card at address 59b4
[   11.005000] mmcblk0: mmc1:59b4 NCard 7.51 GiB 
[   11.075000]  mmcblk0: p1

JKW


#39

Hi @mripard and everyone else,
I’ve another question regarding the device-trees … as powerful as the concept is, it’s still not easy for me :slight_smile:
My target is to run a few external key as keyboard input. Pressing down a button shall write e.g. “x” to a textfile.

I’ve seen that gpio-keys is already part of chips kernel :heart_eyes: and the overlay should be super easy, ok … lets try…

Try1:

gpio-keys {
compatible = “gpio-keys”;
power {
label = “Power Button”;
gpios = <&gpio6 1 0>;
linux,key-code = <116>; /* KEY_POWER */
};
};

hmm <gpio6 1 0> should be PG1 … but I don’t think that it will work … nope … can’t resolve &gpio6 … I’ve copied this syntax from a raspberry forum and I think they have all banks (1…2…3…) available as &gpioX …

ok … I’ve used something like that before for the humus … create a pin handle and link it …

    fragment@0 {
            target = <&pio>;
            __overlay__ {
                    ppp: ppp0@0 {
                            allwinner,pins = "PG1";
                            allwinner,function = "gpio_in";
                            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
                            allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
                    };
            };
    };
    /*       Enable gpio-keys            */
    fragment@1 {
            gpio-keys {
                    compatible = "gpio-keys";
                    autorepeat;
                    up {
                            label = "GPIO Key UP";
                            linux,code = <103>;
                            gpios = <&ppp>;
                    };
            };
    };

its not complaining, but it’s also not doing anything … I guess that’s not the right approach.

next idea:

/ {
compatible = “nextthing,chip”, “allwinner,sun5i-r8”;
/* Enable our SDIO pins */
fragment@0 {
gpio-keys {
compatible = “gpio-keys”;
autorepeat;
up {
label = “GPIO Key UP”;
linux,code = <103>;
gpios = <&pio 6 1 GPIO_ACTIVE_LOW>;
};
};
};
};

compile … load … dmesg:

[  224.920000] of_overlay_create: of_build_overlay_info() failed for tree@/
[  224.930000] create_overlay: Failed to create overlay (err=-19)

:frowning:

So in short: Can someone tell me how I can address the pins ? maybe even the pins on the extender?
Thanks!
JKW


#40

On other kind of board, I’ve succeeded loading this overlay :

/dts-v1/;
/plugin/;

/ {
   compatible = "allwinner,sun8i-h3";

   fragment@0 {
      target = <&pio>;
      __overlay__ {
         keypad_pins: keypad_pins {
            allwinner,pins = "PA10";
            allwinner,function = "gpio_in";
            allwinner,pull = <1>;
         };
      };
   };

   fragment@1 {
      target-path = "/";
      __overlay__ {
         mykeypad: mykeypad {
            compatible = "gpio-keys";
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-names = "default";
            pinctrl-0 = <&keypad_pins>;
            status = "okay";
            button@10 {
               label = "GPIO KEY_ENTER";
               linux,code = <13>;
               gpios = <&pio 0 10 1>; // PA10, active_low
            };
         };
      };
   };

   __overrides__ {
      mykeypad =     <&mykeypad>,"status";
   };
};

#41

Dang it !

you’ve helped me a lot! I’ve added your name to the source file :slight_smile:

works just perfect, connect a bunch of buttons and you have a keyboard with left,right,up,down,x,y,enter,esc
:thumbsup:
JKW


CSP - ChipStationPortable
#42

and once more @martinayotte or @mripard or really anyone else:

my gpio expander arrived and works just fine using sysfs I can export the pin, set the gpio, all good.
This is my dts: http://pastebin.com/1Qk5PrAt that doen’t work. It complains:

[  546.120000] //mykeypad/button@00: could not get #gpio-cells for /soc@01c00000/interrupt-controller@01c20400
[  546.130000] gpio-keys mykeypad: Failed to get gpio flags, error: -22
[  546.135000] gpio-keys: probe of mykeypad failed with error -22

As soon as I switch &csp with &xio (so switching the source from the pca9555 to the chip internal gpio expander) everything works just fine.

Any idea why it keeps failing?
JKW

Edit: Its actually getting worse: I’ve changed the driver that I’ve used to the same driver that is used in the CHIP device tree. “nxp,pcf8574a” just to check if it would work. The driver actually says that the IC was found which is no big surprise as they use similar commands but I still get the GPIO-cells error!

[  129.640000] pcf857x 1-0020: probed
[  129.645000] //mykeypad/button@00: could not get #gpio-cells for /soc@01c00000/interrupt-controller@01c20400
[  129.655000] gpio-keys mykeypad: Failed to get gpio flags, error: -22
[  129.660000] gpio-keys: probe of mykeypad failed with error -22

#43

and once more @martinayotte or @mripard or really anyone else:

my gpio expander arrived and works just fine using sysfs I can export the pin, set the gpio, all good.
This is my dts: http://pastebin.com/1Qk5PrAt that doen’t work. It complains:

[  546.120000] //mykeypad/button@00: could not get #gpio-cells for /soc@01c00000/interrupt-controller@01c20400
[  546.130000] gpio-keys mykeypad: Failed to get gpio flags, error: -22
[  546.135000] gpio-keys: probe of mykeypad failed with error -22

As soon as I switch &csp with &xio (so switching the source from the pca9555 to the chip internal gpio expander) everything works just fine.

Any idea why it keeps failing?

Can you give the real, entire device tree source? This one won’t even compile (missing end bracket).


#44

yes sir
https://github.com/KoljaWindeler/CHIP_STATION_PORTABLE/blob/master/overlay/dip-2a-3_post_part.dts
thanks JKW


#45

got it … the

overrides {
mykeypad = <&mykeypad>,“status”;
};

… well. … that part does something … i don’t know what, but as soon as I remove it, everything works 100% fine :slight_smile:
thanks for taking a look. I start to enjoy this device tree stuff :imp:


#46

yes sir
https://github.com/KoljaWindeler/CHIP_STATION_PORTABLE/blob/master/overlay/dip-2a-3_post_part.dts

I’m guessing from your latest commit that it works now? :slight_smile:

Just out of curiosity, what was the issue?


#47

thats right, see the post above. the override statement was the problem but I still don’t understand why it worked fine with the onboard extender and did not with the external one … I guess there has to be some remaining mystery


#48

Ok I figure out how to create the dtbo for the DHT22.

My problem is that the implementation of the dtbo by itself.

RIght now I’m using the /etc/rc.local to load the device tree.

https://bbs.nextthing.co/t/reading-dht11-dht22-am2302-sensors/2383/78?u=danjperron

Is there other way to load the overlay on boot ?
Is there something similar like the config.txt on the Raspberry Pi?


#49

The idea is to add a ds2431 EEPROM to the 1wire pin and have the w1_ds2431 Module load the overlay.
Read: http://docs.getchip.com/dip.html#dip-maker-39-s-guide
Jkw


#50

This work well if you add an shield board. But what about if you want to add already build-in features like a DHT22 sensor , the extra UART2 ,… etc.


#51

I was able to connect a mcp2515 on the chip.

Presently I got the stuff on sun5i-r8-chip.dtb but I want to create a dtbo. This way I could only load/unload the file
but I can’t figure out was is wrong with my dts overlay

this is the working diff from sun5i-r8-chip.dts
> — sun5i-r8-chip-original.dts 2016-11-21 16:35:38.753150858 -0500
> +++ sun5i-r8-chip.dts 2016-11-22 13:44:46.285417206 -0500
> @@ -54,12 +54,14 @@
> model = “NextThing C.H.I.P.”;
> compatible = “nextthing,chip”, “allwinner,sun5i-r8”;
>
> +
> aliases {
> i2c0 = &i2c0;
> i2c1 = &i2c1;
> i2c2 = &i2c2;
> serial0 = &uart1;
> serial1 = &uart3;
> + spi2 = &spi2;
> };
>
> chosen {
> @@ -101,6 +103,16 @@
> vin0-supply = <&reg_ldo3>;
> vin1-supply = <&reg_ldo4>;
> };
> +
> + clocks {
> + can_clk: can_clk@0 {
> + compatible = “fixed-clock”;
> + #clock-cells = <0>;
> + clock-frequency = <8000000>;
> + clock-output-names = “can_clk”;
> + };
> + };
> +
> };
>
> &be0 {
> @@ -264,6 +276,10 @@
> allwinner,drive = <SUN4I_PINCTRL_10_MA>;
> allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
> };
> +
> +
> +
> +
> };
>
> &reg_dcdc2 {
> @@ -356,3 +372,28 @@
> usb0_vbus-supply = <&reg_usb0_vbus>;
> usb1_vbus-supply = <&reg_vcc5v0>;
> };
> +
> +
> +/* Add support for SPI */
> +
> +&spi2 {
> + pinctrl-names = “default”;
> + pinctrl-0 = <&spi2_pins_a>,
> + <&spi2_cs0_pins_a>;
> + status = “okay”;
> +
> + can0: can0@0 {
> + compatible = “microchip,mcp2515”;
> + reg = <0>;
> + spi-max-frequency = <10000000>;
> + gpio-controller;
> + #gpio-cells = <2>;
> +
> + interrupt-parent = <&pio>;
> + interrupts = <6 1 IRQ_TYPE_EDGE_FALLING>;
> + interrupt-controller;
> + #interrupt-cells = <2>;
> + clocks = <&can_clk>;
> + };
> +};
> +

and this is my not working dtbo version (in dts mode).
> /dts-v1/;
> /plugin/;

> / {
> 	compatible = "nextthing,chip", "allwinner,sun5i-r8";

> 	/* activate the gpio for interrupt */

> 	fragment@0 {
> 		target = <&pio>;
> 		
> 		__overlay__ {
> 			can0_interrupt_pin: can0_interrupt_pin@0 {
> 				allwinner,pins = "PG1";
> 				allwinner,function = "gpio_in";
> 				allwinner,drive = <0x0>;
> 				allwinner,pull = <0x0>;
> 			};

> 			can0_spi2_pins: can0_spi2@0 {
> 				allwinner,pins = "PE1", "PE2", "PE3";
> 				allwinner,function = "spi2";
> 				allwinner,drive = <0x0>;
> 				allwinner,pull = <0x0>;
> 			};

> 			can0_spi2_cs0_pins: can0_spi2_cs0@0 {
> 				allwinner,pins = "PE0";
> 				allwinner,function = "spi2";
> 				allwinner,drive = <0x0>;
> 				allwinner,pull = <0x0>;
> 			};
> 		};
> 	};

>  /* the clock/oscillator of the can-controller */
>     fragment@1 {
>         target-path   = "/clocks";
>         __overlay__ {
>             /* external oscillator of mcp2515 on SPI2.0 */
>             can0_osc: can0_osc@0 {
>                 compatible = "fixed-clock";
>                 #clock-cells = <0>;
>                 clock-frequency  = <8000000>;
>                 clock-output-names = "can0_osc";
>             };
>         };
>     };


> 	/*
> 	 * Enable our SPI device, with an spidev device connected
> 	 * to it
> 	 */
> 	fragment@2 {
> 		target = <&spi2>;

> 		__overlay__ {
> 			pinctrl-names = "default";
> 			pinctrl-0 = <&can0_spi2_pins>,
> 				    <&can0_spi2_cs0_pins>;
> 			status = "okay";
> 			#address-cells = <1>;
> 			#size-cells = <0>;


> 			spidev@0{
> 				#address-cells = <1>;
> 				#size-cells = <0>;
> 				compatible = "microchip,mcp2515";
> 				pinctrl-names = "default";
> 				pinctrl-0 = <&can0_interrupt_pin>;
> 				reg = <0>;
> 				interrupt-parent = <&pio>;
> 				interrupts = <6 1 0x2>;
>                                 clocks = <&can0_osc>;
> 				spi-max-frequency = <12000000>;
> 			};

> 		};
> 	};

> };

Any help will be appreciated.

B.T.W. To get the can-bus can0 you need to create a config file in /etc/network/interfaces.d/ and reboot.
> type /etc/network/interfaces.d/can0.cfg
> auto can0
> iface can0 inet manual
> re-up /sbin/ip link set $IFACE type can bitrate 125000 triple-sampling on
> up /sbin/ifconfig $IFACE up
> down /sbin/ifconfig $IFACE down

After the reboot you need to activate the can0 network
> root@chip2:/home/chip# ip link set can0 type can bitrate 125000 triple-sampling on
> root@chip2:/home/chip# ifconfig can0 up
> root@chip2:/home/chip# ifconfig
> can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
> UP RUNNING NOARP MTU:16 Metric:1
> RX packets:0 errors:0 dropped:0 overruns:0 frame:0
> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:10
> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


CAN bus (MCP2515 via SPI), anyone?
#52

And this is the error I got

First when I load manually the dtbo there is no error

root@chip2:/home/chip# mkdir /sys/kernel/config/device-tree/overlays/can0
root@chip2:/home/chip# cat /home/chip/can.dtbo > /sys/kernel/config/device-tree/overlays/can0/dtbo

But when I check dmesg I got

[ 128.460000] sun4i-spi 1c17000.spi: chipselect 0 already in use
[ 128.465000] spi_master spi32766: spi_device register error /soc@01c00000/spi@01c17000/spidev@0
[ 128.475000] of_spi_notify: failed to create for ‘/soc@01c00000/spi@01c17000/spidev@0’
[ 128.480000] __of_changeset_entry_notify: notifier error @/soc@01c00000/spi@01c17000/spidev@0

And the can0 doesn’t exist

root@chip2:/home/chip# ls /sys/class/net
lo  sit0  usb0	wlan0  wlan1

#53

I think you might need the SPI (fragment 2) stuff in the dtbo ahead of the CAN stuff (fragment 1). Not sure on that, but that is what I would do.


#54

This seems to be important !
I got the same error on another board where GPIO was used by STATUS_LED.
I have to remove it from main DTS.