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.提供者和消费者
