设备树之 provider 和 consumer

1. 控制器说明



2.资源提供者

bash 复制代码
/* arch/arm64/boot/dts/vendor/soc.dtsi ------ 厂商随内核提供,通常不改 */
gpio1: gpio@10060000 {
    compatible = "vendor,gpio";
    reg = <0x0 0x10060000 0x0 0x1000>;
    gpio-controller;
    #gpio-cells = <2>;
    interrupt-controller;
    #interrupt-cells = <2>;
};
这里面有两个# 引用为什么只写第一组参数 第二个参数为什么不用,

3.设备树节点例子

cpp 复制代码
/* 板 B 的 sensor 节点,两套都用上了 */
sensor@48 {
    compatible = "ti,ads1115";
    reg = <0x48>;

    enable-gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;   

    interrupt-parent = <&gpio1>;
    interrupts = <6 IRQ_TYPE_EDGE_FALLING>;       
};

4.中断分离式(interrupt-parent + interrupts), 扩展式(interrupts-extended)。

官方文档位置

你可以在以下官方资源中找到详细定义:

  • ‌**Devicetree Specification (ePAPR / IEEE 1275 衍生标准)**‌:

    • 章节:‌**"Interrupts and Interrupt Mapping"**‌
    • 内容:明确区分了 interrupt-parent(指定控制器)和 interrupts(指定参数)的职责,并引入了 interrupts-extended 作为支持多控制器引用的替代方案。
  • ‌Linux Kernel Documentation‌:

    • 路径:Documentation/devicetree/bindings/interrupt-controller/interrupts.txt (旧版) 或 Documentation/devicetree/usage-model.rst 及相关绑定文档。
    • 内容:解释了 Linux 内核如何遵循设备树规范来解析中断,强调了 interrupt-parent 的继承机制和 interrupts 属性的纯数据特性。
cpp 复制代码
/* 假设 gpio1 是中断控制器,#interrupt-cells = <2> */
my_device {
    compatible = "vendor,device";
    
    /* 
     * 格式:<&中断控制器 中断号 触发类型>
     * &gpio1: 引用名为 gpio1 的中断控制器节点
     * 17: 中断号(具体含义由 gpio1 的 #interrupt-cells 定义)
     * IRQ_TYPE_EDGE_FALLING: 触发类型(下降沿触发)
     */
    interrupts-extended = <&gpio1 17 IRQ_TYPE_EDGE_FALLING>;
};

|------------------|----------------|--------------------|--------------------------------------|-------------------------------|
| 属性/字段 | 所在节点 | 作用 | 是否需要额外参数? | 示例 |
| #gpio-cells | 控制器 (gpio1) | ‌定义格式‌:引用我时需传几个参数 | 否,它是规则声明 | <2> |
| #interrupt-cells | 控制器 (gpio1) | ‌定义格式‌:引用我时需传几个参数 | 否,它是规则声明 | <2> |
| gpios | 使用者 (如 LED) | ‌引用 GPIO‌:打包控制器+参数 | 是,格式为 <&ctrl arg1 arg2> | <&gpio1 5 0> |
| interrupt-parent | 使用者 (如 Button) | ‌指定中断控制器‌:仅建立连接 | ‌否‌,只接受一个 Phandle | <&gpio1> |
| interrupts | 使用者 (如 Button) | ‌描述中断细节‌:仅包含参数 | 是,参数个数由 #interrupt-cells 决定 | <17 0> |
| reg | 自身 (gpio1) | ‌自身地址映射‌:纯数据 | 否,全是数值,格式由父节点 #address/size-cells 决定 | <0x0 0x10060000 0x0 0x1000> |

5.节点#属性 声明

|------------------|-----------|---------------|------------------|-----------------------------|
| 属性名 | 所属角色 | 作用 | 典型值含义 | 使用者属性示例 |
| #interrupt-cells | 中断控制器 | 定义中断参数个数 | <2>: 中断号+触发类型 | interrupts = <17 0>; |
| #gpio-cells | GPIO 控制器 | 定义 GPIO 参数个数 | <2>: 引脚号+标志位 | gpios = <&gpio 5 0>; |
| #address-cells | 父节点/总线 | 定义地址部分长度 | <2>: 64位地址 | reg = <0x0 0x1000 ...>; |
| #size-cells | 父节点/总线 | 定义长度部分长度 | <2>: 64位长度 | reg = <... 0x0 0x1000>; |
| #clock-cells | 时钟控制器 | 定义时钟参数个数 | <1>: 时钟ID | clocks = <&clk 5>; |
| #phy-cells | PHY 控制器 | 定义 PHY 参数个数 | <1>: PHY地址 | phys = <&phy 1>; |
| #iommu-cells | IOMMU 控制器 | 定义 IOMMU 参数个数 | <1>: Stream ID | iommus = <&iommu 0x123>; |

6.提供者和消费者

相关推荐
Hilaku13 小时前
你们公司有 35 岁以上的前端吗?
前端·javascript·程序员
徐小夕13 小时前
开源Vector-Graph-RAG:向量+图谱双引擎,打破纯向量RAG的效果天花板
前端·vue.js·github
阿屿13 小时前
从零手搓 AI 伴侣(二):好感度通胀危机,与它的「货币政策」
java·人工智能
SameX13 小时前
HarmonyOS ArkTS 把组件截图保存成 PNG 再调系统分享面板的做法
前端
灿飞13 小时前
Kotlin与Java虚拟机十一:类与属性:构造顺序、backing field 与显式 backing field
java·后端·kotlin
aiks_yuan13 小时前
40亿个QQ号 1G内存怎么去重:Java BitSet 装不下,long 数组位图 512MB 实测 46 秒(JDK 17)
java
Swot13 小时前
SvelteKit SSG 发布后,为什么老访客非要强刷才能看到新内容?
前端
鸿蒙开发13 小时前
小程序存档写到一半怎么办?双槽保存与损坏恢复实战
前端·javascript·react.js
文丑颜不良啊14 小时前
LeetCode2521~2540题目解析
java·leetcode
杨凯凡14 小时前
Spring Framework 7 HTTP Interface 实战:声明式 RestClient、超时与测试
java·spring·http