This article talks about how to modify device tree nodes.
For related subjects, please refer to the SOC Table of Contents.
On lines 122 to 142 in zynq-7000.dtsi, two i2c devices (eeprom and rtc) are defined.
i2c0: i2c@e0004000 { compatible = "cdns,i2c-r1p10"; status = "disabled"; clocks = <&clkc 38>; interrupt-parent = <&intc>; interrupts = <0 25 4>; reg = <0xe0004000 0x1000>; #address-cells = <1>; #size-cells = <0>; }; i2c1: i2c@e0005000 { compatible = "cdns,i2c-r1p10"; status = "disabled"; clocks = <&clkc 39>; interrupt-parent = <&intc>; interrupts = <0 48 4>; reg = <0xe0005000 0x1000>; #address-cells = <1>; #size-cells = <0>; };
If we wanted to add the two i2c devices to the i2c0 bus, we can simply create two child nodes under the i2c0 node, one for each device. The new i2c0 node would look like the following:
i2c0: i2c@e0004000 { compatible = "cdns,i2c-r1p10"; status = "disabled"; clocks = <&clkc 38>; interrupt-parent = <&intc>; interrupts = <0 25 4>; reg = <0xe0004000 0x1000>; #address-cells = <1>; #size-cells = <0>; 24c64@50{ compatible = “atmel,24c64”; reg = <0x50>; pagesize = <32>; }; rtc@51{ compatible = “nxp,pcf8563”; reg = <0x51>; }; };
Note that the first child node adds the eeprom device to the i2c0 bus while the second child node adds the rtc device. Because zynq-7000.dtsi is a device tree header file, these two devices will now also be added to all other development boards. In order for this to now affect other boards, we will need to add code to the device tree file.
The current device tree file used is system-top.dts, thus we will need to add content to system-top.dts. The formatting is as follows:
&i2c0{ /* content to be added or edited */ };
The &i2c0 in the first line shows that it will reference the node corresponding to i2c0, which is i2c0: i2c@e0004000 in zynq-7000.dtsi.
We will now proceed to open system-top.dts and add what is needed. The code shown starts from the file’s 8th line.
/dts-v1/; #include “zynq-7000.dtsi” #include “pl.dtsi” #include “pcw.dtsi” /{ model = “FII ZYNQ Development Board”; chosen{ bootargs = “console-ttyPS0,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait”; stdout-path = “serial0:115200n8”; }; aliases{ ethernet0 = &gem0; i2c0 = &i2c_2; i2c1 = &i2c0; i2c2 = &i2c1; serial0 = &uart0; serial1 = &uart1; spi0 = &qspi; }; memory{ device_type = “memory”; reg = <0x0 0x20000000>; }; }; &i2c0{ clock-frequency = <100000>; status = “okay”; 24c64@50{ compatible = “atmel,24c64”; reg = <0x50>; pagesize = <32>; }; rtc@51{ compatible = “nxp,pcf8563”; reg = <0x51>; }; }; &gem0{ local-mac-address = [00 0a 35 00 le 53]; };
Lines 34 to 48 add and edit data to node i2c0, such as the added property “clock-frequency = <100000>” on line 35, which sets the clock of i2c0 as 100KHz.
Line 36 involves changing the status property from the original disabled to okay.
Lines 38 to 47 involve adding two child nodes (24c64@50 and rtc@51) to the child node i2c0.
Lines 12 to 32 adds some extra nodes to the root node defined in zynq-7000.dtsi.
As stated before, this example focuses on system-top.dts, so it wouldn’t affect other boards that use the ZYNQ-7000 processor. This example mainly showcased adding and changing file details, mainly being accessing nodes via &label and then editing it. For example, we can see many node references as well as editing node content in pcw.dtsi.