前面编写的基于设备树的 LED 驱动,本质上还是配置 LED 使用的 GPIO 寄存器,驱动开发方式和裸机基本没区别。Linux 内核提供了 pinctrl 和 gpio 子系统用于 GPIO 驱动,借助 pinctrl 和 gpio 子系统来简化 GPIO 驱动开发。
这些节点里都是把某些引脚复用成某些功能。
nxp:
pinctrl_tsc: tscgrp {
fsl,pins =<
MX6UL_PAD_GPI01_I001_GPIO1_I001 oxb0
MX6UL_PAD_GP101_I002_GPI01_I002 0xb0
MX6UL PADGPI01I003GPI01I003 Oxb0
MX6UL_PAD GPI01I004 GP1O1_I004 0xb0
>;
};
pinctrl_uart1: uart1grp {
fsl,pins =<
MX6UL_PAD _UART1_TX_DATA UART1DCE_TX 0x1b0b1
MX6UL_PAD_UART1_RX_DATA_ _UART1DCE RX 0x1b0b1
>;
};
pinctrl_uart2: uart2grp {
fsl,pins =<
MX6UL PAD_ _UART2_TX_DATA__UART2_DCE_TX Ox1b0b1
MX6UL_PAD _UART2 RX_DATA UART2_DCE RX 0x1b0b1
MX6UL_PAD__UART3_RX_DATA__ _UART2_DCE_RTS Ox1b0b1
MX6UL_PAD__UART3_TX_DATA__UART2_DCE_CTs ox1b0b1
>;
};
三星:
gt911_irq: gt911-irq {
nexell,pins ="gpiob-29","gptoe-30";
nexell,pin-function = <1>;
nexell,pin-pull = <2>;
nexell,pin-strength = <2>;
};
pinctrl_gpio_keys: pinctrl_gpio_keys {
nexell,pins = "allve-8", "gpioa-28", "gpiob-9", "gpiob-30", "gpiob-31";
nexell,pin-function = <0>;
nexell,pin-pull = <1>;
nexell,pin-strength = <0>;
};
buzzer:buzzer {
nexell,pins = "gpioc-14";
nexell,pin-function = <0>;
nexell,pin-pull = <1>;
nexell,pin-strength = <0>;
};
led:led {
nexell,pins = "aploc-1";
nexell,pin-function = <0>;
nexell,pin-pull = <1>;
nexell,pin-strength = <0>;
};
Rax485:max485 {
nexell,pins = "gpioc-6";
nexell,pin-function = <0>;
nexell,pin-pull = <1>;
nexell,pin-strength = <0>;
};
瑞星微:
lcd-panel {
lcd_panel_reset: lcd-panel-reset {
rockchip,pins = <4 29 RK_FUNC_GPIO &pcfg_pull_up>;
};
lcd_en: lcd-en {
rockchip,pins = <1 1 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
可以通过Linux源码目录/Documentation/devicetree/bindings下的 txt 文档查看。
例1:
pinctrl-names = "default";
pinctrl-0= <&pinctrl_hog_1>;
含义:
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog_1>;
例2:
pinctrl-names ="default", "wake up";
pinctrl-0 = <&pinctrl_hog_1>;
pinctrl-1 = <&pinctrl_hog_2>;
含义:
pinctrl-names ="default", "wake up";
pinctrl-0 =<&pinctrl_hog_1>;
pinctrl-1 = <&pinctrl_hog_2>;
例3:
pinctrl-names = "default"
pinctrl-0 =<&pinctrl_hog_1,
&pinctrl_hog_2>;
含义
pinctrl-names = "default";
pinctrl-0=<&pinctrl_hog_1, &pinctrl_hog_2>;