2017年1月31日 星期二

GPIO in device tree

Documentation/devicetree/bindings/gpio/gpio.txt

GPIOs property

Note that gpio-specifier length is controller dependent. In the below example, &gpio1 uses 2 cells to specify a gpio, while &gpio2 only uses one.
gpio1: gpio1 {
   gpio-controller
   #gpio-cells = <2>;
 };  
 gpio2: gpio2 {
   gpio-controller
   #gpio-cells = <1>;
 };  
 [...]
  chipsel-gpios = <&gpio1 12 0>,
      <&gpio1 13 0>,
      <0>, /* holes are permitted, means no GPIO 2 */
      <&gpio2 2>;

Most controllers are however specifying a generic flag bitfield in the last cell, so for these, use the macros defined in include/dt-bindings/gpio/gpio.h whenever possible
node {                                                                                          
           enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>
}                                                                                            
qe_pio_e: gpio-controller.
GPIO_ACTIVE_HIGH: 0 (defined in include/dt-bindings/gpio/gpio.h).
gpio-specifier: "18 0".

gpio-controller


Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt

pinctrl-#

pinctrl-names定义了一个state列表。
pinctrl-0是一个sleep state時的句柄(phandle)列表,每个句柄指向一个pin configurationpinctrl-1是一个active state。
serial device只定义了一个state就是default,对应pinctrl-0属性定义。
pinctrl-0是一个句柄(phandle)列表,每个句柄指向一个pin configuration。
phandle 0x2以及0x3分別是在別處定義的pin configuration。

Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

property:

  • interrupt-parent: is used to specify the controller to which interrupts are routed and contains a single phandle
  • interrupts:
    #interrupt-cells:1
    defines the index of the interrupt within the controller
    #interrupt-cells:2
    the first cell defines the index of the interrupt within the controller
    the second cell is used to specify any of the following flags:
    bits[3:0] trigger type and level flags
    1 = low-to-high edge triggered
    2 = high-to-low edge triggered
    4 = active high level-sensitive
    8 = active low level-sensitive

Reference

2017年1月29日 星期日

Device Tree Fundamental


ARM的核心代码仍然保存在arch/arm目录下
ARM SOC的周边外设模块的驱动保存在drivers目录下
ARM SoC core architecture code保存在arch/arm目录下
ARM SOC的特定代码在arch/arm/mach-xxx目录下
ARM SOC board specific的代码被移除,由Device Tree机制来负责传递硬件拓扑和硬件资源信息

由bootloader傳遞識別platform的訊息,決定帶起哪一個dtb。

Device Tree的結構

Device Tree對於那些可以動態偵測到的device是不需要描述的(ex, USB device, PCIE device),不過對於SOC上的usb host controller,它是無法動態偵測的,需要在device tree中描述。同样的道理,在computer system中,PCI bridge如果不能被探测,那就需要描述之。

Device tree的基本单元是node,这些node被组织成树状结构,除了root node,每个node都只有一个parent。一个device tree文件中只能有一个root node。
每个node用节点名字(node name)标识,节点名字的格式是node-name@unit-address,如果该node没有reg属性(后面会描述这个property),那么该节点名字中必须不能包括@和unit-address。

Device Tree source file語法

在dts文件中,一个node被定義成:

Property - Value:
  • 属性值是text string或者string list,用双引号表示。例如device_type = "memory"
  • 属性值是32bit unsigned integers,用尖括号表示。例如#size-cells = <1>
  • 属性值是binary data,用方括号表示。例如binary-property = [0x01 0x23 0x45 0x67]

Property Key word:
  • device_type: 定义了该node的设备类型,例如cpu、serial等
  • reg: 属性定义了访问该device node的地址信息,该属性的值被解析成任意长度的(address,size)数组,具体用多长的数据来表示address和size是在其parent node中定义(#address-cells和#size-cells)
  • #address-cells: 用來表示reg address的cell數
  • #size-cells:用來表示reg size長度的cell數
  • Status: 一般在dtsi文件中配置节点时status=disable,然后在dts中&xxx status="okay" (status會被較後面include進來的dts覆蓋),没有status = ‘okay’没有关系,只要不显式的设置“status=disable”,都会编译进入

Reference