运维 Linux嵌入式驱动开发-设备树中的中断 - busfreq {
文章目录
中断控制器结构节点举例**顶层中断控制器**一级子中断控制器二级子中断控制器
总结
中断控制器结构
节点举例
以imx6ull.dtsi设备树文件举例
顶层中断控制器
intc 节点就是I.MX6ULL 的中断控制器节点
intc: interrupt-controller@00a01000 {
compatible = "arm,cortex-a7-gic";
#interrupt-cells =<3>;
interrupt-controller;
reg =<0x00a01000 0x1000>,
<0x00a02000 0x100>;
};
compatible:compatible属性用于平台设备驱动的匹配 拼多多帮助力入口
**#interrupt-cells:**描述了该节点的“子”中断控制器 interrupts 属性的 cells 大小,也就是一条信息有几个 cells,每个 cells 都是 32 位整形值。
对于 ARM 处理的GIC 来说,一共有 3 个 cells,这三个 cells 的含义如下:
第一个 cells:中断类型,0 表示 SPI 中断,1 表示 PPI 中断。 第二个 cells:中断号, 对于 SPI 中断来说中断号的范围为 0~987, 对于 PPI 中断来说中断号的范围为0~15。 第三个 cells:中断触发方式,可进行组合 bit[3:0]表示中断触发类型,为 1 的时候表示上升沿触发,为 2 的时候表示下降沿触发,为 4 的时候表示高电平触发,为 8 的时候表示低电平触发。 bit[15:8]为 PPI 中断的 CPU 掩码。在多核系统中这8位用于设置PPI中断发送到哪个CPU,一位代表一个CPU, 为1则将PPI中断发送到CPU,否则屏蔽。imx6ull是单核CPU,所以不用设置这些位。
interrupt-controller:声明该设备树节点是一个中断控制器,只要是中断控制器都要用该标签声明。
一级子中断控制器
imx6ull.dtsi文件中, gpc为intc的一级子中断控制器
gpc: gpc@20dc000 {
compatible = "fsl,imx6ul-gpc", "fsl,imx6q-gpc";
reg =<0x20dc000 0x4000>;
interrupt-controller;
#interrupt-cells =<3>;
interrupts =;
interrupt-parent = <&intc>;
fsl,mf-mix-wakeup-irq =<0xfc00000 0x7d00 0x0 0x1400640>;
};
interrupt-controller:声明该设备树节点是一个中断控制器,只要是中断控制器都要用该标签声明。
interrupt-parent:指定该中断控制器的“父”中断控制器。除了“顶层中断控制器”其他中断控制器都要声明“父”中断控制器。
二级子中断控制器
soc {
#address-cells =<1>;
#size-cells =<1>;
compatible = "simple-bus";
interrupt-parent = <&gpc>;
ranges;
//busfreq子节点
busfreq {
................ //表示省略
}
............... //表示省略
soc 节点即片上外设“总节点”, 外设大多包含在里面。
具体外设(例如GPIO)也可作为中断控制器,这里声明了它们的“父”中断控制器是 <&gpc>节点。
soc节点内包含的中断控制器很多,几乎用到中断的外设都是中断控制器,
gpio 节点可以作为中断控制器
比如 imx6ull.dtsi 文件中的 gpio5 节点
gpio5: gpio@020ac000 {
compatible = "fsl,imx6ul-gpio", "fsl,imx35-gpio";
reg =<0x020ac000 0x4000>;
interrupts =,
;
gpio-controller;
#gpio-cells =<2>;
interrupt-controller;
#interrupt-cells =<2>;
};
interrupts:用来描述GPIO5能产生中断类型及中断编号、触发方式。
对于 gpio5 来说一共有两条信息,中断类型都是 SPI,触发电平都是 IRQ_TYPE_LEVEL_HIGH。
《IMX6ULL 参考手册》中“Chapter 3 Interrupts and DMA Events”章节,表 3-1可以看出,GPIO5 一共用了 2 个中断号,一个是 74,一个是 75。 其中 74 对应 GPIO5_IO00~GPIO5_IO15 这低16个IO,75 对应GPIO5_IO16~GPIOI5_IO31这高16位 IO。
interrupt-controller 表明了 gpio5 节点是个中断控制器,用于控制 gpio5 所有 IO的中断。
#interrupt-cells: 声明该节点的子节点将用多少个参数来描述中断信息。
例如:
key {
#address-cells =<1>;
#size-cells =<1>;
compatible = "atkalpha-key";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_key>;
key-gpio = <&gpio1 18 GPIO_ACTIVE_LOW>; /* KEY0 */
interrupt-parent = <&gpio1>;
interrupts =<18 IRQ_TYPE_EDGE_BOTH>; /* FALLING RISING */
status = "okay";
};
interrupt-parent: 属性设置中断控制器,这里使用 gpio1 作为中断控制器。
interrupts: 设置中断信息,18 表示 GPIO1_IO018,IRQ_TYPE_EDGE_BOTH 表示双边触发。
总结
与中断有关的设备树属性信息:
#interrupt-cells:该节点的“子”中断控制器 interrupts 属性的 cells 大小。 interrupt-controller,表示当前节点为中断控制器。 interrupts,指定中断号,触发方式等。 interrupt-parent,指定父中断,也就是中断控制器。
推荐链接