小型模板设备树以及追加节点(Linux驱动开发篇)

1.小型模板设备树

下面写一个简单的小型设备树,目的就是了解设备树的大致结构,注意最重要的就是层次结构

  • 1.搭建一个仅含有根节点“/”的基础的框架
/ { 
    compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
} 
  • 2.1添加/cpus节点
 /  { 
        compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
        
        cpus { 
         #address-cells = <1>; 
         #size-cells = <0>; 
        
         //CPU0 节点 
         cpu0: cpu@0 { 
             compatible = "arm,cortex-a7"; 
             device_type = "cpu"; 
             reg = <0>; 
       }; 
   }; 
}  
  • 2.2 添加/soc节点
/ { 
     compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
      
     cpus { 
         #address-cells = <1>; 
         #size-cells = <0>; 
         //CPU0 节点 
         cpu0: cpu@0 { 
             compatible = "arm,cortex-a7"; 
             device_type = "cpu"; 
             reg = <0>; 
         }; 
     }; 
      
     //soc 节点 
     soc { 
         #address-cells = <1>; 
         #size-cells = <1>; 
         compatible = "simple-bus"; 
         ranges; /*,ranges属性,ranges属性为空,说明子空间和父空间地址范围相同*/
     }    
} 
  • 3.1 添加/soc/ocram节点
/ { 
     compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
      
     cpus { 
         #address-cells = <1>; 
         #size-cells = <0>; 
         //CPU0 节点 
         cpu0: cpu@0 { 
             compatible = "arm,cortex-a7"; 
             device_type = "cpu"; 
             reg = <0>; 
         }; 
     }; 
      
     //soc 节点 
     soc { 
         #address-cells = <1>; 
         #size-cells = <1>; 
         compatible = "simple-bus"; 
         ranges; 
          
         //ocram 节点 
         ocram: sram@00900000 { 
             compatible = "fsl,lpm-sram"; 
             reg = <0x00900000 0x20000>; 
         }; 
     }    
} 
  • 3.2 添加/soc/aips1(aips2、aips)节点(总线主干)
/ { 
     compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
      
     cpus { 
         #address-cells = <1>; 
         #size-cells = <0>; 
         //CPU0 节点 
         cpu0: cpu@0 { 
             compatible = "arm,cortex-a7"; 
             device_type = "cpu"; 
             reg = <0>; 
         }; 
     }; 
      
     //soc 节点 
     soc { 
         #address-cells = <1>; 
         #size-cells = <1>; 
         compatible = "simple-bus"; 
         ranges; 
          
         //ocram 节点 
         ocram: sram@00900000 { 
             compatible = "fsl,lpm-sram"; 
             reg = <0x00900000 0x20000>; 
         }; 
          
         //aips1 节点 
         aips1: aips-bus@02000000 { 
             compatible = "fsl,aips-bus", "simple-bus"; 
             #address-cells = <1>; 
             #size-cells = <1>; 
             reg = <0x02000000 0x100000>; 
             ranges;  
         } 
         
         //aips2 节点 
         aips2: aips-bus@02100000 { 
             compatible = "fsl,aips-bus", "simple-bus"; 
             #address-cells = <1>; 
             #size-cells = <1>; 
             reg = <0x02100000 0x100000>; 
             ranges; 
         } 
      
         //aips3 节点    
         aips3: aips-bus@02200000 { 
             compatible = "fsl,aips-bus", "simple-bus"; 
             #address-cells = <1>; 
             #size-cells = <1>; 
             reg = <0x02200000 0x100000>; 
             ranges; 
         } 
     } 
} 
  • 4.1 分别添加/soc/aips1/ecspi1节点(外设控制器节点)
    /soc/aips2/usbotg1节点(外设控制器节点)
    /soc/aips3/rngb节点(外设控制器节点)
 / { 
      compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
       
      cpus { 
          #address-cells = <1>; 
          #size-cells = <0>; 
 
          //CPU0 节点 
          cpu0: cpu@0 { 
              compatible = "arm,cortex-a7"; 
              device_type = "cpu"; 
              reg = <0>; 
          }; 
      }; 
       
      //soc 节点 
      soc { 
          #address-cells = <1>; 
          #size-cells = <1>; 
          compatible = "simple-bus"; 
          ranges; 
           
          //ocram 节点 
          ocram: sram@00900000 { 
              compatible = "fsl,lpm-sram"; 
              reg = <0x00900000 0x20000>; 
          }; 
           
          //aips1 节点 
          aips1: aips-bus@02000000 { 
              compatible = "fsl,aips-bus", "simple-bus"; 
              #address-cells = <1>; 
              #size-cells = <1>; 
              reg = <0x02000000 0x100000>; 
              ranges;  
               
              //ecspi1 节点 
              ecspi1: ecspi@02008000 { 
                  #address-cells = <1>; 
                  #size-cells = <0>; 
                  compatible = "fsl,imx6ul-ecspi", "fsl,imx51-ecspi
                  reg = <0x02008000 0x4000>; 
                  status = "disabled"; 
              }; 
          } 
       
          //aips2 节点 
          aips2: aips-bus@02100000 { 
              compatible = "fsl,aips-bus", "simple-bus"; 
              #address-cells = <1>; 
              #size-cells = <1>; 
              reg = <0x02100000 0x100000>; 
              ranges; 
               
              //usbotg1 节点 
              usbotg1: usb@02184000 { 
                  compatible = "fsl,imx6ul-usb", "fsl,imx27-usb"; 
                  reg = <0x02184000 0x4000>; 
                  status = "disabled"; 
             }; 
         } 
      
         //aips3 节点    
         aips3: aips-bus@02200000 { 
             compatible = "fsl,aips-bus", "simple-bus"; 
             #address-cells = <1>; 
             #size-cells = <1>; 
             reg = <0x02200000 0x100000>; 
             ranges; 
              
             //rngb节点 
             rngb: rngb@02284000 { 
                 compatible = "fsl,imx6sl-rng", "fsl,imx-rng", "imx-rng"; 
                 reg = <0x02284000 0x4000>; 
             }; 
         } 
     } 
} 
  • 4.2 当然你可以继续追加比如,添加/soc/aips2/i2c(adc等)
 / { 
      compatible = "fsl,imx6ull-alientek-evk", "fsl,imx6ull"; 
       
      cpus { 
          #address-cells = <1>; 
          #size-cells = <0>; 
 
          //CPU0 节点 
          cpu0: cpu@0 { 
              compatible = "arm,cortex-a7"; 
              device_type = "cpu"; 
              reg = <0>; 
          }; 
      }; 
       
      //soc 节点 
      soc { 
          #address-cells = <1>; 
          #size-cells = <1>; 
          compatible = "simple-bus"; 
          ranges; 
           
          //ocram 节点 
          ocram: sram@00900000 { 
              compatible = "fsl,lpm-sram"; 
              reg = <0x00900000 0x20000>; 
          }; 
           
          //aips1 节点 
          aips1: aips-bus@02000000 { 
              compatible = "fsl,aips-bus", "simple-bus"; 
              #address-cells = <1>; 
              #size-cells = <1>; 
              reg = <0x02000000 0x100000>; 
              ranges;  
               
              //ecspi1 节点 
              ecspi1: ecspi@02008000 { 
                  #address-cells = <1>; 
                  #size-cells = <0>; 
                  compatible = "fsl,imx6ul-ecspi", "fsl,imx51-ecspi
                  reg = <0x02008000 0x4000>; 
                  status = "disabled"; 
              }; 
          } 
       
          //aips2 节点 
          aips2: aips-bus@02100000 { 
              compatible = "fsl,aips-bus", "simple-bus"; 
              #address-cells = <1>; 
              #size-cells = <1>; 
              reg = <0x02100000 0x100000>; 
              ranges; 
               
              //usbotg1 节点 
              usbotg1: usb@02184000 { 
                  compatible = "fsl,imx6ul-usb", "fsl,imx27-usb"; 
                  reg = <0x02184000 0x4000>; 
                  status = "disabled"; 
             }; 
             
             //adc1节点
    		  adc1: adc@02198000 {
					compatible = "fsl,imx6ul-adc", "fsl,vf610-adc";
					reg = <0x02198000 0x4000>;
					interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
					clocks = <&clks IMX6UL_CLK_ADC1>;
					num-channels = <2>;
					clock-names = "adc";
					status = "disabled";
             };
			
			 //i2c1节点
			  i2c1: i2c@021a0000 {
					#address-cells = <1>;
					#size-cells = <0>;
					compatible = "fsl,imx6ul-i2c", "fsl,imx21-i2c";
					reg = <0x021a0000 0x4000>;
					interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
					clocks = <&clks IMX6UL_CLK_I2C1>;
					status = "disabled";
			};         
         } 
      
         //aips3 节点    
         aips3: aips-bus@02200000 { 
             compatible = "fsl,aips-bus", "simple-bus"; 
             #address-cells = <1>; 
             #size-cells = <1>; 
             reg = <0x02200000 0x100000>; 
             ranges; 
              
             //rngb节点 
             rngb: rngb@02284000 { 
                 compatible = "fsl,imx6sl-rng", "fsl,imx-rng", "imx-rng"; 
                 reg = <0x02284000 0x4000>; 
             }; 
         } 
     } 
} 

2.追加节点(常用)

**这里切记dtsi文件是通用的,所以我们在特定改板子的信息的时候需要用&label在dts里面追加节点信息,好处是,精华和冗余分开放 **

  • 现在有个六轴芯片fxls8471,fxls8471 要接到 I.MX6U-ALPHA 开发板的 I2C1 接口上,那么相当于需要在 i2c1 这个节点上添加一个 fxls8471 子节点。

  • 下面的这样就不对,在dtsi里面追加

i2c1: i2c@021a0000 { 
    #address-cells = <1>; 
    #size-cells = <0>; 
    compatible = "fsl,imx6ul-i2c", "fsl,imx21-i2c"; 
    reg = <0x021a0000 0x4000>; 
    interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; 
    clocks = <&clks IMX6UL_CLK_I2C1>; 
    status = "disabled"; 
    
    //fxls8471 子节点 
   fxls8471@1e { 
       compatible = "fsl,fxls8471"; 
       reg = <0x1e>; 
   }; 
 }; 

  • 应该在dts里面追加
&i2c1 { 
    clock-frequency = <100000>; 
    pinctrl-names = "default"; 
    pinctrl-0 = <&pinctrl_i2c1>; 
    status = "okay"; 

    fxls8471@1e { 
        compatible = "fsl,fxls8471"; 
        reg = <0x1e>; 
        position = <0>; 
        interrupt-parent = <&gpio5>; 
        interrupts = <0 8>; 
    }; 

就吹到这里了,希望可以让你更好的理解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

栋哥爱做饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值