Skip to content

Commit

Permalink
RK3568: Add PCIe30 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredmcneill committed Apr 4, 2023
1 parent aa87bd0 commit ae1203b
Show file tree
Hide file tree
Showing 31 changed files with 702 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
I2cLib|Silicon/Rockchip/Rk356x/Library/I2cLib/I2cLib.inf
MultiPhyLib|Silicon/Rockchip/Rk356x/Library/MultiPhyLib/MultiPhyLib.inf
OtpLib|Silicon/Rockchip/Rk356x/Library/OtpLib/OtpLib.inf
Pcie30PhyLib|Silicon/Rockchip/Rk356x/Library/Pcie30PhyLib/Pcie30PhyLib.inf
SocLib|Silicon/Rockchip/Rk356x/Library/SocLib/SocLib.inf
SdramLib|Silicon/Rockchip/Rk356x/Library/SdramLib/SdramLib.inf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <Library/MultiPhyLib.h>
#include <Library/OtpLib.h>
#include <Library/SocLib.h>
#include <Library/Pcie30PhyLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
Expand Down Expand Up @@ -57,8 +58,6 @@
#define MAC_SPEED BIT2
#define RXCLK_DLY_ENA BIT1
#define TXCLK_DLY_ENA BIT0
#define GRF_IOFUNC_SEL0 (SYS_GRF + 0x0300)
#define GMAC1_IOMUX_SEL BIT8

#define TX_DELAY_GMAC0 0x3C
#define RX_DELAY_GMAC0 0x2F
Expand All @@ -76,6 +75,12 @@
#define PMIC_POWER_EN2 0xb3
#define PMIC_POWER_EN3 0xb4
#define PMIC_LDO1_ON_VSEL 0xcc
#define PMIC_LDO2_ON_VSEL 0xce
#define PMIC_LDO3_ON_VSEL 0xd0
#define PMIC_LDO4_ON_VSEL 0xd2
#define PMIC_LDO6_ON_VSEL 0xd6
#define PMIC_LDO7_ON_VSEL 0xd8
#define PMIC_LDO8_ON_VSEL 0xda
#define PMIC_LDO9_ON_VSEL 0xdc

/*
Expand All @@ -87,6 +92,15 @@
#define CORE_PVTPLL_OSC_EN BIT1
#define CORE_PVTPLL_START BIT0

/*
* SYS_GRF registers
*/
#define GRF_IOFUNC_SEL0 (SYS_GRF + 0x0300)
#define GMAC1_IOMUX_SEL BIT8
#define GRF_IOFUNC_SEL5 (SYS_GRF + 0x0314)
#define PCIE30X2_IOMUX_SEL_MASK (BIT7|BIT6)
#define PCIE30X2_IOMUX_SEL_M1 BIT6

/*
* PMU registers
*/
Expand Down Expand Up @@ -139,6 +153,12 @@ STATIC CONST GPIO_IOMUX_CONFIG mSdmmc2IomuxConfig[] = {
{ "sdmmc2_clkm0", 3, GPIO_PIN_PD3, 3, GPIO_PIN_PULL_UP, GPIO_PIN_DRIVE_2 },
};

STATIC CONST GPIO_IOMUX_CONFIG mPcie30x2IomuxConfig[] = {
{ "pcie30x2_clkreqnm1", 2, GPIO_PIN_PD4, 4, GPIO_PIN_PULL_NONE, GPIO_PIN_DRIVE_DEFAULT },
{ "pcie30x2_perstnm1", 2, GPIO_PIN_PD6, 4, GPIO_PIN_PULL_NONE, GPIO_PIN_DRIVE_DEFAULT },
{ "pcie30x2_wakenm1", 2, GPIO_PIN_PD5, 4, GPIO_PIN_PULL_NONE, GPIO_PIN_DRIVE_DEFAULT },
};

STATIC
EFI_STATUS
BoardInitSetCpuSpeed (
Expand Down Expand Up @@ -367,6 +387,23 @@ BoardInitGmac (
EthernetPhyInit (GMAC1_BASE);
}

STATIC
VOID
BoardInitPcie (
VOID
)
{
GpioSetIomuxConfig (mPcie30x2IomuxConfig, ARRAY_SIZE (mPcie30x2IomuxConfig));

/* PCIe30x2 IO mux selection - M1 */
MmioWrite32 (GRF_IOFUNC_SEL5, (PCIE30X2_IOMUX_SEL_MASK << 16) | PCIE30X2_IOMUX_SEL_M1);

/* PCIECLKIC_OE_H_GPIO3_A7 */
GpioPinSetPull (3, GPIO_PIN_PA7, GPIO_PIN_PULL_NONE);
GpioPinSetDirection (3, GPIO_PIN_PA7, GPIO_PIN_OUTPUT);
GpioPinWrite (3, GPIO_PIN_PA7, FALSE);
}

STATIC
EFI_STATUS
PmicRead (
Expand Down Expand Up @@ -438,6 +475,22 @@ BoardInitPmic (
/* Enable LDO1 and LDO9 for HDMI */
PmicWrite (PMIC_POWER_EN1, 0x11);
PmicWrite (PMIC_POWER_EN3, 0x11);


/* Initialize PMIC for HDMI */
PmicWrite (PMIC_LDO1_ON_VSEL, 0x0c); /* 0.9V - vdda0v9_image */
PmicWrite (PMIC_LDO2_ON_VSEL, 0x0c); /* 0.9V - vdda_0v9 */
PmicWrite (PMIC_LDO3_ON_VSEL, 0x0c); /* 0.9V - vdd0v9_pmu */
PmicWrite (PMIC_LDO4_ON_VSEL, 0x6c); /* 3.3V - vccio_acodec */
/* Skip LDO5 for now; 1.8V/3.3V - vccio_sd */
PmicWrite (PMIC_LDO6_ON_VSEL, 0x6c); /* 3.3V - vcc3v3_pmu */
PmicWrite (PMIC_LDO7_ON_VSEL, 0x30); /* 1.8V - vcca_1v8 */
PmicWrite (PMIC_LDO8_ON_VSEL, 0x30); /* 1.8V - vcca1v8_pmu */
PmicWrite (PMIC_LDO9_ON_VSEL, 0x30); /* 1.8V - vcca1v8_image */

PmicWrite (PMIC_POWER_EN1, 0xff); /* LDO1, LDO2, LDO3, LDO4 */
PmicWrite (PMIC_POWER_EN2, 0xee); /* LDO6, LDO7, LDO8 */
PmicWrite (PMIC_POWER_EN3, 0x55); /* LDO9, SW1*/
}

STATIC
Expand Down Expand Up @@ -508,6 +561,9 @@ BoardInitDriverEntryPoint (
GpioPinSetDirection (0, GPIO_PIN_PA6, GPIO_PIN_OUTPUT);
GpioPinWrite (0, GPIO_PIN_PA6, TRUE);

/* PCIe setup */
BoardInitPcie ();

/* GMAC setup */
BoardInitGmac ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
MultiPhyLib
OtpLib
SocLib
Pcie30PhyLib

[Protocols]

Expand Down
17 changes: 12 additions & 5 deletions edk2-rockchip/Platform/Firefly/ROC-RK3568-PC/ROC-RK3568-PC.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
I2cLib|Silicon/Rockchip/Rk356x/Library/I2cLib/I2cLib.inf
MultiPhyLib|Silicon/Rockchip/Rk356x/Library/MultiPhyLib/MultiPhyLib.inf
OtpLib|Silicon/Rockchip/Rk356x/Library/OtpLib/OtpLib.inf
Pcie30PhyLib|Silicon/Rockchip/Rk356x/Library/Pcie30PhyLib/Pcie30PhyLib.inf
SdramLib|Silicon/Rockchip/Rk356x/Library/SdramLib/SdramLib.inf
SocLib|Silicon/Rockchip/Rk356x/Library/SocLib/SocLib.inf

Expand Down Expand Up @@ -451,23 +452,29 @@
#
# PCI support
#
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x0000000300000000
gRk356xTokenSpaceGuid.PcdPcieApbBase|0xFE280000
gRk356xTokenSpaceGuid.PcdPcieDbiBase|0x00000003C0800000

gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x0000000380000000
gArmTokenSpaceGuid.PcdPciBusMin|0
# TODO: fix
gArmTokenSpaceGuid.PcdPciBusMax|1
gArmTokenSpaceGuid.PcdPciMmio32Base|0xF4000000
gArmTokenSpaceGuid.PcdPciMmio32Base|0xF0000000
gArmTokenSpaceGuid.PcdPciMmio32Size|0x02000000
gArmTokenSpaceGuid.PcdPciMmio64Base|0x0000000310000000
gArmTokenSpaceGuid.PcdPciMmio64Base|0x0000000390000000
gArmTokenSpaceGuid.PcdPciMmio64Size|0x000000002FFF0000
gArmTokenSpaceGuid.PcdPciIoBase|0x0000
gArmTokenSpaceGuid.PcdPciIoSize|0x10000
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|34

gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation|0x000000033FFF0000
gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation|0x00000003BFFF0000
gRk356xTokenSpaceGuid.PcdPcieResetGpioBank|2
gRk356xTokenSpaceGuid.PcdPcieResetGpioPin|30
gRk356xTokenSpaceGuid.PcdPciePowerGpioBank|0
gRk356xTokenSpaceGuid.PcdPciePowerGpioPin|28
gRk356xTokenSpaceGuid.PcdPcieLinkSpeed|0x3
gRk356xTokenSpaceGuid.PcdPcieNumLanes|0x2
gRk356xTokenSpaceGuid.PcdPcie30PhyLane0LinkNum|1
gRk356xTokenSpaceGuid.PcdPcie30PhyLane1LinkNum|1

#
# The ROC-RK3568-PC has a WiFi card on the third MSHC
Expand Down
1 change: 1 addition & 0 deletions edk2-rockchip/Platform/Pine64/Quartz64/Quartz64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
OtpLib|Silicon/Rockchip/Rk356x/Library/OtpLib/OtpLib.inf
SdramLib|Silicon/Rockchip/Rk356x/Library/SdramLib/SdramLib.inf
SocLib|Silicon/Rockchip/Rk356x/Library/SocLib/SocLib.inf
Pcie30PhyLib|Silicon/Rockchip/Rk356x/Library/Pcie30PhyLib/Pcie30PhyLib.inf

# Devices
NonDiscoverableDeviceRegistrationLib|MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf
Expand Down
1 change: 1 addition & 0 deletions edk2-rockchip/Platform/Pine64/SOQuartz/SOQuartz.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
I2cLib|Silicon/Rockchip/Rk356x/Library/I2cLib/I2cLib.inf
MultiPhyLib|Silicon/Rockchip/Rk356x/Library/MultiPhyLib/MultiPhyLib.inf
OtpLib|Silicon/Rockchip/Rk356x/Library/OtpLib/OtpLib.inf
Pcie30PhyLib|Silicon/Rockchip/Rk356x/Library/Pcie30PhyLib/Pcie30PhyLib.inf
SdramLib|Silicon/Rockchip/Rk356x/Library/SdramLib/SdramLib.inf
SocLib|Silicon/Rockchip/Rk356x/Library/SocLib/SocLib.inf

Expand Down
1 change: 1 addition & 0 deletions edk2-rockchip/Platform/Radxa/CM3/CM3.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
I2cLib|Silicon/Rockchip/Rk356x/Library/I2cLib/I2cLib.inf
MultiPhyLib|Silicon/Rockchip/Rk356x/Library/MultiPhyLib/MultiPhyLib.inf
OtpLib|Silicon/Rockchip/Rk356x/Library/OtpLib/OtpLib.inf
Pcie30PhyLib|Silicon/Rockchip/Rk356x/Library/Pcie30PhyLib/Pcie30PhyLib.inf
SdramLib|Silicon/Rockchip/Rk356x/Library/SdramLib/SdramLib.inf

# Devices
Expand Down
4 changes: 3 additions & 1 deletion edk2-rockchip/Platform/Rockchip/Rk356x/AcpiTables/CM3.inf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
gRk356xTokenSpaceGuid.PcdMshc2Status
gRk356xTokenSpaceGuid.PcdMshc2SdioIrq
gRk356xTokenSpaceGuid.PcdMshc2NonRemovable


gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress

[BuildOptions]
GCC:*_*_*_ASL_FLAGS = -vw3133 -vw3150
13 changes: 8 additions & 5 deletions edk2-rockchip/Platform/Rockchip/Rk356x/AcpiTables/Mcfg.aslc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <IndustryStandard/Rk356x.h>
#include "AcpiHeader.h"

#define PCIE_BASE FixedPcdGet64 (PcdPciExpressBaseAddress)
#define PCIE_SEGMENT ((PCIE_BASE - 0x300000000UL) / 0x40000000UL)

#pragma pack(push, 1)

typedef struct {
Expand All @@ -27,11 +30,11 @@ EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = {
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
),
}, {
PCIE2X1_S_BASE + 0x8000,
0, // PciSegmentGroupNumber
1, // PciBusMin
1, // PciBusMax
0 // Reserved
PCIE_BASE + 0x8000,
PCIE_SEGMENT, // PciSegmentGroupNumber
1, // PciBusMin
1, // PciBusMax
0 // Reserved
}
};

Expand Down
7 changes: 4 additions & 3 deletions edk2-rockchip/Platform/Rockchip/Rk356x/AcpiTables/Pcie2x1.asl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
* DesignWare Mobile Storage Host Controller (SD/SDIO) devices.
* PCIe2x1
*
* Copyright (c) 2022, Jared McNeill <[email protected]>
* Copyright (c) 2022-2023, Jared McNeill <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
**/
Expand All @@ -13,7 +13,8 @@ Device (PCI0) {
Name (_HID, "PNP0A08")
Name (_CID, "PNP0A03")
Name (_CCA, Zero)
Name (_SEG, Zero)
Name (_UID, 0)
Name (_SEG, 0)
Name (_BBN, One)

Name (_PRT, Package() {
Expand Down
119 changes: 119 additions & 0 deletions edk2-rockchip/Platform/Rockchip/Rk356x/AcpiTables/Pcie3x1.asl
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/** @file
* PCIe3x1
*
* Copyright (c) 2022-2023, Jared McNeill <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <IndustryStandard/Acpi60.h>

// PCIe
Device (PCI0) {
Name (_HID, "PNP0A08")
Name (_CID, "PNP0A03")
Name (_CCA, Zero)
Name (_UID, 1)
Name (_SEG, 1)
Name (_BBN, One)

Name (_PRT, Package() {
Package (4) { 0x0FFFF, 0, Zero, 189 },
Package (4) { 0x0FFFF, 1, Zero, 189 },
Package (4) { 0x0FFFF, 2, Zero, 189 },
Package (4) { 0x0FFFF, 3, Zero, 189 }
})

Method (_CRS, 0, Serialized) {
Name (RBUF, ResourceTemplate () {
WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
0, // Granularity
1, // Range Minimum
1, // Range Maximum
0, // Translation Offset
1, // Length
)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
0x00000000, // Granularity
0xF2000000, // Range Minimum
0xF3FFFFFF, // Range Maximum
0x00000000, // Translation Offset
0x02000000, // Length
)
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000000350000000, // Range Minimum
0x000000037FFEFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x000000002FFF0000, // Length
)
QWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
0, // Granularity
0x0000, // Range Minimum
0xFFFF, // Range Maximum
0x000000037FFF0000, // Translation Offset
0x10000, // Length
)
})
return (RBUF)
}

Device (RES0) {
Name (_HID, "PNP0C02")
Name (_CRS, ResourceTemplate () {
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000000340000000, // Range Minimum
0x000000034FFFFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000000010000000, // Length
)
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
0x0000000000000000, // Granularity
0x00000003C0400000, // Range Minimum
0x00000003C07FFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000000000400000, // Length
)
})
}

// OS Control Handoff
Name(SUPP, Zero) // PCI _OSC Support Field value
Name(CTRL, Zero) // PCI _OSC Control Field value

// See [1] 6.2.10, [2] 4.5
Method(_OSC,4) {
// Note, This code is very similar to the code in the PCIe firmware
// specification which can be used as a reference
// Check for proper UUID
If(LEqual(Arg0,ToUUID("33DB4D5B-1FF7-401C-9657-7441C03DD766"))) {
// Create DWord-adressable fields from the Capabilities Buffer
CreateDWordField(Arg3,0,CDW1)
CreateDWordField(Arg3,4,CDW2)
CreateDWordField(Arg3,8,CDW3)
// Save Capabilities DWord2 & 3
Store(CDW2,SUPP)
Store(CDW3,CTRL)
// Mask out Native HotPlug
And(CTRL,0x1E,CTRL)
// Always allow native PME, AER (no dependencies)
// Never allow SHPC (no SHPC controller in this system)
And(CTRL,0x1D,CTRL)

If(LNotEqual(Arg1,One)) { // Unknown revision
Or(CDW1,0x08,CDW1)
}

If(LNotEqual(CDW3,CTRL)) { // Capabilities bits were masked
Or(CDW1,0x10,CDW1)
}
// Update DWORD3 in the buffer
Store(CTRL,CDW3)
Return(Arg3)
} Else {
Or(CDW1,4,CDW1) // Unrecognized UUID
Return(Arg3)
}
} // End _OSC
} // PCI0
Loading

0 comments on commit ae1203b

Please sign in to comment.