一、,pcie开发可通过参考官方开发文档:
具体的硬件外设都有官网的参考文档,pcie的具体可参考:
https://github.com/mfkiwl/rk-open-docs/blob/master/PCIe/Rockchip_RK3399_Developer_Guide_PCIe_CN.md
二、具体设备树文件
vi arch/arm64/boot/dts/rockchip/rk3399.dtsi
pcie_phy: pcie-phy {
compatible = "rockchip,rk3399-pcie-phy";
#phy-cells = <0>;
rockchip,grf = <&grf>;
clocks = <&cru SCLK_PCIEPHY_REF>;
clock-names = "refclk";
resets = <&cru SRST_PCIEPHY>;
reset-names = "phy";
status = "disabled";
};
pcie0: pcie@f8000000 {
compatible = "rockchip,rk3399-pcie";
#address-cells = <3>;
#size-cells = <2>;
aspm-no-l0s;
clocks = <&cru ACLK_PCIE>, <&cru ACLK_PERF_PCIE>,
<&cru PCLK_PCIE>, <&cru SCLK_PCIE_PM>;
clock-names = "aclk", "aclk-perf",
"hclk", "pm";
bus-range = <0x0 0x1f>;
max-link-speed = <1>;
linux,pci-domain = <0>;
msi-map = <0x0 &its 0x0 0x1000>;
interrupts = <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH 0>,
<GIC_SPI 50 IRQ_TYPE_LEVEL_HIGH 0>,
<GIC_SPI 51 IRQ_TYPE_LEVEL_HIGH 0>;
interrupt-names = "sys", "legacy", "client";
#interrupt-cells = <1>;
interrupt-map-mask = <0 0 0 7>;
interrupt-map = <0 0 0 1 &pcie0_intc 0>,
<0 0 0 2 &pcie0_intc 1>,
<0 0 0 3 &pcie0_intc 2>,
<0 0 0 4 &pcie0_intc 3>;
power-domains = <&power RK3399_PD_PERIHP>;
phys = <&pcie_phy>;
phy-names = "pcie-phy";
ranges = <0x83000000 0x0 0xfa000000 0x0 0xfa000000 0x0 0x1e00000
0x81000000 0x0 0xfbe00000 0x0 0xfbe00000 0x0 0x100000>;
reg = <0x0 0xf8000000 0x0 0x2000000>,
<0x0 0xfd000000 0x0 0x1000000>;
reg-names = "axi-base", "apb-base";
resets = <&cru SRST_PCIE_CORE>, <&cru SRST_PCIE_MGMT>,
<&cru SRST_PCIE_MGMT_STICKY>, <&cru SRST_PCIE_PIPE>,
<&cru SRST_PCIE_PM>, <&cru SRST_P_PCIE>,
<&cru SRST_A_PCIE>;
reset-names = "core", "mgmt", "mgmt-sticky", "pipe",
"pm", "pclk", "aclk";
status = "disabled";
pcie0_intc: interrupt-controller {
interrupt-controller;
#address-cells = <0>;
#interrupt-cells = <1>;
};
};
在分析设备树之前,先简单追一下RK3399的设备树编译文件,通过编译脚本make.sh可知,在编译过程中执行./make linux prod 时候用到了这几个deb文件。
通过这几个文件的dts文件的引用关系可追踪所有相关设备树文件关系:
rk3399pro-toybrick-prod-linux-edp.dts—>rk3399pro-toybrick-prod.dtsi—>rk3399pro-toybrick.dtsi—>rk3399pro.dtsi—>rk3399.dtsi(PCIE RC设备树)
三、移植调试过程
1)、使能RK3399 PCIE,同时设置 PCIe 接口的 PERST#复位信号:
arch/arm64/boot/dts/rockchip/rk3399pro.dtsi,使能pcie,同时设置 PCIe 接口的 PERST#复位信号,ep-gpios = <&gpio0 RK_PB4 GPIO_ACTIVE_HIGH>;status = 。
2)、通过原理图确认复位引脚为GPIO0_B4(其实就是GPIO0_12,只是每8个分一组A、B……)
2) 、可选配置:用于配置 PCIe 外设的 0.9V、1.8V、3.3V 供电,如果有控制需要开启。
vpcie3v3-supply = <&vdd_pcie3v3>;
vpcie1v8-supply = <&vdd_pcie1v8>;
四、 make menuconfig 配置
确保有以下配置才可使用PCIE功能
CONFIG_PCI=y
CONFIG_PCI_DOMAINS=y
CONFIG_PCI_DOMAINS_GENERIC=y
CONFIG_PCI_SYSCALL=y
CONFIG_PCI_BUS_ADDR_T_64BIT=y
CONFIG_PCI_MSI=y
CONFIG_PCI_MSI_IRQ_DOMAIN=y
CONFIG_PHY_ROCKCHIP_PCIE=y
CONFIG_PCIE_ROCKCHIP=y
CONFIG_PCIEPORTBUS=y
CONFIG_PCIEASPM=y
CONFIG_PCIEASPM_POWERSAVE=y
CONFIG_PCIE_PME=y
CONFIG_GENERIC_MSI_IRQ=y
CONFIG_GENERIC_MSI_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_HIERARCHY=y
使能 NVMe 设备(建立在 PCIe 接口的 SSD)
CONFIG_BLK_DEV_NVME=y
使能 AHCI 设备(PCIe 转接成 SATA 的 SSD)
CONFIG_SATA_PMP=y
CONFIG_SATA_AHCI=y
CONFIG_SATA_AHCI_PLATFORM=y
CONFIG_ATA_SFF=y
CONFIG_ATA=y
五、 驱动启动过程中报错分析:
toybrick@debian10:~$ dmesg |grep pcie
[ 0.287785] of_get_named_gpiod_flags: parsed ‘gpio’ property of node ‘/vcc-pcie-regulator[0]’ - status (0)
[ 0.287824] vcc_pcie: no parameters
[ 0.287974] reg-fixed-voltage vcc-pcie-regulator: vcc_pcie supplying 0uV
[ 1.124824] phy phy-pcie-phy.3: Looking up phy-supply from device tree
[ 1.124836] phy phy-pcie-phy.3: Looking up phy-supply property in node /pcie-phy failed
[ 1.126863] rockchip-pcie f8000000.pcie: GPIO lookup for consumer ep
[ 1.126876] rockchip-pcie f8000000.pcie: using device tree for GPIO lookup
[ 1.126905] of_get_named_gpiod_flags: parsed ‘ep-gpios’ property of node ‘/pcie@f8000000[0]’ - status (0)
[ 1.127166] rockchip-pcie f8000000.pcie: Looking up vpcie3v3-supply from device tree
[ 1.127179] rockchip-pcie f8000000.pcie: Looking up vpcie3v3-supply property in node /pcie@f8000000 failed
[ 1.127195] rockchip-pcie f8000000.pcie: no vpcie3v3 regulator found
[ 1.127783] rockchip-pcie f8000000.pcie: Looking up vpcie1v8-supply from device tree
[ 1.127795] rockchip-pcie f8000000.pcie: Looking up vpcie1v8-supply property in node /pcie@f8000000 failed
[ 1.127808] rockchip-pcie f8000000.pcie: no vpcie1v8 regulator found
[ 1.128401] rockchip-pcie f8000000.pcie: Looking up vpcie0v9-supply from device tree
[ 1.128412] rockchip-pcie f8000000.pcie: Looking up vpcie0v9-supply property in node /pcie@f8000000 failed
[ 1.128425] rockchip-pcie f8000000.pcie: no vpcie0v9 regulator found
[ 1.129010] rockchip-pcie f8000000.pcie: missing “memory-region” property
[ 1.129641] PCI host bridge /pcie@f8000000 ranges:
[ 1.672204] rockchip-pcie f8000000.pcie: PCIe link training gen1 timeout!
[ 1.672842] rockchip-pcie f8000000.pcie: deferred probe failed
[ 1.673597] rockchip-pcie: probe of f8000000.pcie failed with error -110
drivers/pci/host/pcie-rockchip.c
rockchip_pcie_parse_dt解析加载设备树的函数,启动过程中报0.9V、1.8V、3.3V未配置的打印信息可忽略。
未插入外设,PCIE未检测到设备如下link ep 设备超时报-110。
插入PCIE设备link ep设备成功后:
sudo echo 1 > /sys/class/pci_bus/0000:01/device/0000:01:00.0/enable
显示PCIE网卡的配置
lspci -s 01:00.3 -x