本文主要对在Linux下使用zynq-7000或者FMQL45T900控制MIO/EMIO
首先内核配置项
如下,这个不用太多关注,一般都是默认打开的
CONFIG_GPIO_SYSFS=y
CONFIG_SYSVIPC=y
CONFIG_GPIO_ZYNQ=y
两者的控制都是流程都是一样的,在细节上又区别
首先都在/sys/class/gpio/查看对应节点
FMQL45T900
Zynq-7000平台
这里两者的明显的区别在于FMQL45T900节点个数比较多有四个,这里简单分析一下原因
两者的GPIO的驱动设计不一样
Zynq驱动设计从设备树zynq-7000.dtsi可以看出确实只有一个节点
gpio0: gpio@e000a000 {
compatible = "xlnx,zynq-gpio-1.0";
#gpio-cells = <2>;
clocks = <&clkc 42>;
gpio-controller;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&intc>;
interrupts = <0 20 4>;
reg = <0xe000a000 0x1000>;
};
FMQL45T900中设备文件fmsh-psoc.dtsi可以看出有四个节点
gpio0: gpio@e0003000 {
compatible = "snps,dw-apb-gpio";
reg = <0xe0003000 0x100>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&clkc NCLK_APB_GPIO>;
status = "disabled";
porta: gpio-controller@0 {
compatible = "snps,dw-apb-gpio-port";
bank-name = "porta";
gpio-controller;
#gpio-cells = <2>;
snps,nr-gpios = <32>;
reg = <0>;
interrupt-controller;
#interrupt-cells = <2>;
interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
};
};
gpio1: gpio@e0003100 {
compatible = "snps,dw-apb-gpio";
reg = <0xe0003100 0x100>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&clkc NCLK_APB_GPIO>;
status = "disabled";
portb: gpio-controller@0 {
compatible = "snps,dw-apb-gpio-port";
bank-name = "portb";
gpio-controller;
#gpio-cells = <2>;
snps,nr-gpios = <22>;
reg = <0>;
interrupt-controller;
#interrupt-cells = <2>;
interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
};
};
gpio2: gpio@e0003200 {
compatible = "snps,dw-apb-gpio";
reg = <0xe0003200 0x100>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&clkc NCLK_APB_GPIO>;
status = "disabled";
portc: gpio-controller@0 {
compatible = "snps,dw-apb-gpio-port";
bank-name = "portc";
gpio-controller;
#gpio-cells = <2>;
snps,nr-gpios = <32>;
reg = <0>;
interrupt-controller;
#interrupt-cells = <2>;
interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
};
};
gpio3: gpio@e0003400 {
compatible = "snps,dw-apb-gpio";
reg = <0xe0003400 0x100>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&clkc NCLK_APB_GPIO>;
status = "disabled";
portd: gpio-controller@0 {
compatible = "snps,dw-apb-gpio-port";
bank-name = "portd";
gpio-controller;
#gpio-cells = <2>;
snps,nr-gpios = <32>;
reg = <0>;
interrupt-controller;
#interrupt-cells = <2>;
interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
};
};
怎么计算我们需要操作的原理图上的IO管脚
Zynq-7000假如要操作MIO10
从上图可以看到设备中第一个IO编号为906,这个编号属于MIO的编号。即第一个GPIO为gpio906。你需要操作某个GPIO直接找出对应的GPIO编号,比如:我要使用MIO10对应第11个GPIO对应的编号为:gpio916。注意第一个为906对应MIO0。
FMQL45T900的计算稍微复杂一点,提供了四个根节点,分别对应每个bank
其他MIO/EMIO可以根据下表格计算出来,这里列举几个实际使用的IO
Linux节点 | 对应bank | 对应IO | 最大偏移量 |
gpiochip394 | BANK3起始节点 | EMIO32 | 32 |
gpiochip426 | BANK2起始节点 | EMIO0 | 32 |
gpiochip458 | BANK1起始节点 | MIO32 | 54-32 |
gpiochip480 | BANK0起始节点 | MIO0 | 32 |
这里列举几个实际使用的管脚对应的节点
MIO32 -> gpiochip458
MIO43 -> gpiochip469
EMIO0 -> gpiochip426
EMIO5 -> gpiochip431
EMIO6 -> gpiochip432
EMIO7 -> gpiochip433
EMIO8 -> gpiochip434
EMIO9 -> gpiochip435
EMIO10 -> gpiochip436