参考文档:
内核 Documentation\devicetree\bindings\interrupt-controller\interrupts.txt
在设备树中,中断控制器节点中必须有一个属性: interrupt-controller,表明它是“中断控制器”。
还必须有一个属性: #interrupt-cells,表明引用这个中断控制器的话需要多少个 cell。
#interrupt-cells 的值一般有如下取值:
① #interrupt-cells=<1>
别的节点要使用这个中断控制器时,只需要一个 cell 来表明使用“哪一个中断”。
② #interrupt-cells=<2>
别的节点要使用这个中断控制器时,需要一个 cell 来表明使用“哪一个中断”;
还需要另一个 cell 来描述中断,一般是表明触发类型:
第 2 个 cell 的 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,低电平触发
举个例子:
vic: intc@10140000 {
compatible = "arm,versatile-vic";
interrupt-controller;
#interrupt-cells = <1>;
reg = <0x10140000 0x1000>;
};
如果中断控制器有级联关系,下级的中断控制器还需要表明它的“ interrupt-parent”是谁(使用了哪个一中断控制器),用了interrupt-parent”中的哪一个“ interrupts”,请看下一小节。
2、设备树里使用中断
一个外设,它的中断信号接到哪个“中断控制器”的哪个“中断引脚”,这个中断的触发方式是怎样的?
这 3 个问题,在设备树里使用中断时,都要有所体现。
① interrupt-parent=<&XXXX>
你要用哪一个中断控制器里的中断?
② interrupts
你要用哪一个中断?
Interrupts 里要用几个 cell,由 interrupt-parent 对应的中断控制器决定。在中断控制器里有“ #interrupt-cells”属性,它指明了要用几个 cell 来描述中断。
比如:
i2c@7000c000 {
gpioext: gpio-adnp@41 {
compatible = "ad,gpio-adnp"; //保证驱动程序与之匹配
interrupt-parent = <&gpio>; //说明它所使用的中断属于该中断控制器
interrupts = <160 1>; //表明使用了该中断控制器中的160 号中断,触发类型是上升沿触发
gpio-controller; //表明它是一个中断控制器
#gpio-cells = <1>; //如果有要使用它的中断,需要用一个 cell来描述所使用的中断
interrupt-controller;
#interrupt-cells = <2>;
};
......
};
③ 新写法: interrupts-extended
一个“ interrupts-extended”属性就可以既指定“ interrupt-parent”,也指定“ interrupts”,比如:
interrupts-extended = <&intc1 5 1>, <&intc2 1 0>; //表明了所属中断控制器的同时,亦表明描述了所使用的中断。