Linux设备树

1、根节点
dts中最开头 / {} 根节点
标准结构 xxx@yyy{…} xxx节点名字 yyy节点的地址(非必须)

2、节点的地址
reg 个数由父节点的#address-cells #size-cells决定

3、兼容性
是设备节点 compatible(兼容性)作为驱动和设备(设备节点)的匹配依据(不止一个) fsl,imx8mq

4、实例dts
Documentation/devicetree/bindings

5、节点关系
引用 包含

6、驱动与节点的匹配
内核知道dtb文件的地址 由Uboot来告诉内核
只要驱动中的of_match_table 中的compatible 值和设备节点中的compatible 相匹配,那么probe函数就会被触发

7、属性的设置与获取
int of_device_is_compatible(const struct device_node *device, const char *name)来判断当前节点是否包含指定的compatible(兼容性)

8、gpio的设置与获取
xxx-gpios = <&gpio1 15 1> gpio1_15 1代表低电平有效 0代表高电平有效(非必须) #gpio-cells = <1>;

驱动通过gpio = of_get_named_gpio(node, "xxx-gpios", index);	参数1 节点 参数2 名字 参数3编号(0)

直接通过以下接口来获取gpio号 gpio = of_get_gpio(node, index);

9、中断的设置与获取
确定中断所在的组 interrupt-parent = <&gpio6>; interrupts = <8 2>; /表示中断,GPIO6中的第8个IO,2为触发类型,下降沿触发/

驱动中使用 中断号 =irq_of_parse_and_map(node, index)函数返回值来得到中断号

10、自定义属性的设置与获取
自定义设备节点中的属性
reg_3p3v: 3p3v {
compatible = “regulator-fixed”;
regulator-name = “3P3V”;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-always-on;
};
驱动 of_property_read_u32(node, “regulator-min-microvolt”, &microvolt); //参数1 节点 参数2 属性名字 参数3输出型参数(把读出来的值放进去)

检查节点中某个属性是否存在	bool of_property_read_bool(const struct device_node *np, const char *propname)	//存在则返回true,不存在则返回false

节点中的字符串 读取		of_property_read_string(node, "regulator-name", &string)

节点中的数组 读取	

/带有数组的某个节点/
L2: cache-controller@1e00a000 {
compatible = “arm,pl310-cache”;
arm,data-latency = <1 1 1>;
arm,tag-latency = <1 1 1>;
};

/驱动中使用API来读取数组, &data为输出型参数/
of_property_read_u32_array(node, “arm,pl310-cache”, &data, ARRAY_SIZE(data));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

weixin_40723768

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

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

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

打赏作者

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

抵扣说明:

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

余额充值