Device Tree

Device tree is for describe the peripheral HW. It not noly can describe the detectable devices, but also can be used for non-detectable devices

non-detectable device: Like memory information, flash information, UARTs, GPIOs …etc.

Device Tree Source (.dts)

root

  • /: This is root for device tree.
/ {
    
    name = "device-tree-example";
    model = "device model name";
    compatiable = "deive-tree";
    #address-cells = <2>;
    #size-cells = <2>;
    # linux,phandle = <0>;
}

node

[aliae_name:] node-name[@unit-address] {
    [properties definitions]
    [child nodes]
};

[]: means option

  • [aliae_name:] node-name[@unit-address] :
    • unit-address: indicate the address mapping to device.
    • if the node doesn't have "reg" property, the unit-address can't be exist.
  • properties definitions:
    • describe the node property

    • the property can be no assigned value. e.g properties = [value]

      • value :
        • can be a value or multiple value.
        ​​​​​​​​​​​​address = <1>;
        ​​​​​​​​​​​​address2 = [0x00001 0x20000];
        
        • can be string lists
        ​​​​​​​​​​​​device_type = "memory";
        ​​​​​​​​​​​​name = "PowerPC,970";
        
        Property value
    • properties attirbute:
      Standard Properties
      Here are list some special properites.

      1. address-cells and #size-cells :

      The #address-cells and #size-cells properties may be used in any device node that has children in the devicetree hierarchy and describes how child device nodes should be addressed.

      The #address-cells property defines the number of <u32> cells used to encode the address field in a child node’s reg property.

      The #size-cells property defines the number of <u32> cells used to encode the size field in a child node’s reg property

      ​​​​​​​​    e.g: 
      ​​​​​​​​    #address-cells = <2>;
      ​​​​​​​​    #size-celss = <2>;
      ​​​​​​​​    memory@0 {
      ​​​​​​​​        device_type = "memory";
      ​​​​​​​​        reg = <0x000000000 0x00000000 0x00000000 0x80000000>;
      ​​​​​​​​    };
      

      reg will use <address1, size1, address2, size2, …>

      1. phandle:

      A phandle value is a way to reference another node in the devicetree

      1. In an array, the "&" reference will expand to a phandle.
      ​​​​​​​​mydevice: mydev {
      ​​​​​​​​    compatiable = "mydevice_list";
      ​​​​​​​​    pincontrol = <&my_pin_ctrl>;
      ​​​​​​​​}
      ​​​​​​​​
      ​​​​​​​​maybe in another dtsi
      ​​​​​​​​
      ​​​​​​​​my_pin_ctrl: my_pin_ctrl {
      ​​​​​​​​    ....
      ​​​​​​​​};
      
      1. Outside an arry, the "&" reference will expand to the path of the node you're referring to.
      ​​​​​​​​label:node {
      ​​​​​​​​    #address-cell = <1>;
      ​​​​​​​​    #size-cells = <0>;
      ​​​​​​​​}
      
      ​​​​​​​​&label {
      ​​​​​​​​    ...;
      ​​​​​​​​};
      

      This means

      ​​​​​​​​label:node {
      ​​​​​​​​    #address-cell = <1>;
      ​​​​​​​​    #size-cells = <0>;
      ​​​​​​​​    ....;
      ​​​​​​​​}
      

Device tree code trace and How to load into kernel

[TBD]

how to build

$ dtc -@ -I dts -O dtb -o <output>.dtbo <src>.dts

ref

Introduction to Linux kernel
driver programming

Device TreeοΌˆδΊŒοΌ‰οΌšεŸΊζœ¬ζ¦‚εΏ΅
Device TreeοΌˆδΈ‰οΌ‰οΌšδ»£η εˆ†ζž
Device TreeοΌˆε››οΌ‰οΌšζ–‡δ»Άη»“ζž„θ§£ζž
example in linux kernel

  • dtsi example
    dtsi example
  • dts example
    dts example
  • Device Tree PIN defineitions
    Device Tree defineitions
  • Device match to device driver
    Device match to device driver