在imx6ul-14x14-evk.dts中有这个一个设备树节点:
spi4 {
compatible = "spi-gpio";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_spi4>;
pinctrl-assert-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
status = "okay";
gpio-sck = <&gpio5 11 0>;
gpio-mosi = <&gpio5 10 0>;
cs-gpios = <&gpio5 7 0>;
num-chipselects = <1>;
#address-cells = <1>;
#size-cells = <0>;
gpio_spi: gpio_spi@0 {
compatible = "fairchild,74hc595";
gpio-controller;
#gpio-cells = <2>;
reg = <0>;
registers-number = <1>;
registers-default = /bits/ 8 <0xb7>;
spi-max-frequency = <100000>;
};
};
这个设备对应的是移位寄存器(74hc595),作用是拓展gpio口,linux中驱动代码位于drivers/gpio/gpio-74x164.c。
SN74HC595N是德州仪器公司生产的集成电路芯片,是一个8位串行输入变串行输出或并行输出移位寄存器,具有高阻关断,高电平和低电平三态输出。在IO扩充上,可以最多串联15片,也就是高达120个IO扩充。
那么这种扩展出来的gpio应如何使用呢?原理图中Q0~Q7对应&gpio_spi0~7
举两个栗子说明:
1. 在用户空间控制Q7 -- LCD_nPWREN:
~# cat /sys/kernel/debug/gpio
GPIOs 248-255, spi/spi32766.0, 74hc595, can sleep:
所以,Q0~Q7对应gpio248~255
~# echo 255 > /sys/class/gpio/export
~# echo 0/1 > /sys/class/gpio/gpio255/value
2. 在device tree中添加控制节点:
backlight {
compatible = "pwm-backlight";
pwms = <&pwm1 0 5000000>;
brightness-levels = <0 4 8 16 32 64 128 255>;
default-brightness-level = <6>;
enable-gpios = <&gpio_spi 7 GPIO_ACTIVE_LOW>;
status = "okay";
};
在backlight的驱动中drivers/video/backlight/pwm_bl.c中已经有enable-gpio的获取和使用。
系统启动后可以看到:
~# cat /sys/kernel/debug/gpio
GPIOs 248-255, spi/spi32766.0, 74hc595, can sleep:
gpio-255 (enable ) out lo