本文基于RockPI 4A單板介紹Linux內(nèi)核pinctrl的相關(guān)知識點。
Linux內(nèi)核pinctrl部分主要包括 :IOMUX,驅(qū)動強度,上下拉配置等。
一、IOMUX
SOC芯片上有很多引腳,每個引腳對應(yīng)特定的功能。為了使SOC的多個功能共用一個引腳,從而提高引腳的功能,降低引腳的數(shù)量。引入了IOMUX的概念。IOMUX(Input-Output Multiplexer):IO多路復(fù)用器。
以RK3399 EMMC接口為例,RK3399 EMMC接口的emmc_pwren引腳需要設(shè)置IOMUX功能,具體如下:

圖1:RK3399 EMMC引腳
注:在Linux系統(tǒng)中,使用功能復(fù)用的引腳前,必須先配置該引腳對應(yīng)的功能。一般在dtsi中配置,也有的SOC在RCW(如NXP LX1046A)或其它文件中配置。如果引腳功能配置不正確,會導(dǎo)致功能無法使用。
二、PINCTRL
RK3399 Linux內(nèi)核pinctrl配置文件: arch/arm64/boot/dts/rockchip/rk3399.dtsi
pinctrl: pinctrl {
compatible = "rockchip,rk3399-pinctrl";
rockchip,grf = <&grf>;
rockchip,pmu = <&pmugrf>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
## 1、配置GPIO0功能,RK3399可配置GPIO0 - GPIO4,共5組引腳。
gpio0: gpio0@ff720000 {
compatible = "rockchip,gpio-bank";
reg = <0x0 0xff720000 0x0 0x100>;
clocks = <&pmucru PCLK_GPIO0_PMU>;
interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH 0>;
gpio-controller;
#gpio-cells = <0x2>;
interrupt-controller;
#interrupt-cells = <0x2>;
};
...
## 2、配置芯片引腳內(nèi)部上下拉功能
pcfg_pull_up: pcfg-pull-up {
bias-pull-up;
};
pcfg_pull_down: pcfg-pull-down {
bias-pull-down;
};
...
## 3、配置引腳驅(qū)動強度,即配置對應(yīng)的驅(qū)動強度電流值
pcfg_pull_up_20ma: pcfg-pull-up-20ma {
bias-pull-up;
drive-strength = <20>;
};
...
## 4、配置輸出電平
pcfg_output_high: pcfg-output-high {
output-high;
};
...
## 5、配置引腳指定功能,如emmc_pwren。
emmc {
# 引腳名稱:IO_EMMCpwren_PMUdebug3_PMU18gpio0a5
emmc_pwr: emmc-pwr {
rockchip,pins =
## 0 5:表示引腳索引,對應(yīng)GPIO0A5,見圖1
## RK_FUNC_1:配置功能1,即emmc_pwren,見圖2
## pcfg_pull_up:引腳上拉
<0 5 RK_FUNC_1 &pcfg_pull_up>;
};
};
...
};
RK_FUNC_*定義文件: include/dt-bindings/pinctrl/rockchip.h
## 對應(yīng)IOMUX寄存器中引腳的某個功能
#define RK_FUNC_GPIO 0
#define RK_FUNC_1 1
#define RK_FUNC_2 2
#define RK_FUNC_3 3
#define RK_FUNC_4 4
#define RK_FUNC_5 5
#define RK_FUNC_6 6
#define RK_FUNC_7 7

圖2 RK3399 EMMC_PWREN引腳配置
驅(qū)動文件: drivers/pinctrl/pinctrl-rockchip.c
## RK3399 GRF寄存器包括:
## 1、GRF, used for general non-secure system,
## 2、PMUGRF, used for always on sysyem
static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
.pin_banks = rk3399_pin_banks,
.nr_banks = ARRAY_SIZE(rk3399_pin_banks),
.label = "RK3399-GPIO",
.type = RK3399,
.grf_mux_offset = 0xe000, ## GRF MUX寄存器偏移地址,配置IOMUX
.pmu_mux_offset = 0x0, ## PMUGRF MUX寄存器偏移地址,配置IOMUX
.grf_drv_offset = 0xe100, ## GRF DRV寄存器偏移地址,配置驅(qū)動強度
.pmu_drv_offset = 0x80, ## PMUGRF DRV寄存器偏移地址,配置驅(qū)動強度
.iomux_routes = rk3399_mux_route_data,
.niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
.pull_calc_reg = rk3399_calc_pull_reg_and_bit, ## 上下拉配置實現(xiàn)函數(shù)
.drv_calc_reg = rk3399_calc_drv_reg_and_bit, ## 驅(qū)動強度實現(xiàn)函數(shù)
};
三、內(nèi)核調(diào)試
在Linux系統(tǒng)啟動后,可以查看引腳功能,如:
## 1、通過pingroups查看引腳配置功能
root@linaro-alip:/sys/kernel/debug/pinctrl/pinctrl# cat pingroups
registered pin groups:
group: emmc-pwr ## GPIO0A5配置為emmc_pwren功能
pin 5 (gpio0-5)
group: rgmii-pins
pin 113 (gpio3-17)
pin 110 (gpio3-14)
...
## 2、通過寄存器值查看
## 0xff320000是PMU GRF寄存器的基地址,PMUGRF_GPIO0A_IOMUX偏移地址是0
## PMUGRF_GPIO0A_IOMUX的值為0x5400,即bit11:10為01,表示配置為emmc_pwren
## 寄存器的值見圖2
root@linaro-alip:/# io -4 -l 16 -r 0xff320000
ff320000: 00005400 00000000 00000000 00000000
注:轉(zhuǎn)載請標(biāo)明出處。