Skip to content

Commit

Permalink
Initialize GMAC and expose in ACPI
Browse files Browse the repository at this point in the history
Enabled on all platforms that use it.

Tested to be working with NetBSD on:
- R58X & R58-Mini
- Orange Pi 5
- ROCK 5A
- ROC-RK3588S-PC / Station M3

VMware ESXi also detects the NICs and link status, however it's not able to get
an IP address.

The original GMAC0 definition by Rockchip was more thorough, but I have no idea
if all the methods have been tested and with what kernel, so for now we'll keep
it minimal like on Quartz64.

This will only work when connected to a Gigabit capable port, lower speed modes
are not supported due to lack of clock management in the OS.
  • Loading branch information
mariobalanica committed Aug 22, 2023
1 parent d2ed387 commit ed76800
Show file tree
Hide file tree
Showing 43 changed files with 1,021 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
/* No GMAC here */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2)

include ("Emmc.asl")
include ("Sdhc.asl")
// include ("Gmac.asl")
include ("Gmac1.asl")
// include ("Gpio.asl")
// include ("I2c.asl")
include ("Uart.asl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,40 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
switch (id) {
case 0:
/* gmac0 iomux */
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0x0F00UL << 16) | 0x0100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;
break;
case 1:
/* gmac1 iomux */
break;
default:
break;
switch (Id) {
case 1:
/* gmac1 iomux */
BUS_IOC->GPIO3B_IOMUX_SEL_H = (0x0FFFUL << 16) | 0x0111;
BUS_IOC->GPIO3A_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO3B_IOMUX_SEL_L = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3A_IOMUX_SEL_H = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3C_IOMUX_SEL_L = (0xFF00UL << 16) | 0x1100;

/* phy1 reset */
GpioPinSetDirection (0, GPIO_PIN_PD3, GPIO_PIN_OUTPUT);
break;
default:
break;
}
}

VOID
EFIAPI
GmacIoPhyReset (
UINT32 Id,
BOOLEAN Enable
)
{
switch (Id) {
case 1:
/* phy1 reset */
GpioPinWrite (0, GPIO_PIN_PD3, !Enable);
break;
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
gRK3588TokenSpaceGuid.PcdUsbDpPhy0Supported|TRUE
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }

#
# GMAC
#
gRK3588TokenSpaceGuid.PcdGmac1Supported|TRUE
gRK3588TokenSpaceGuid.PcdGmac1TxDelay|0x43

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
/* No GMAC here */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RKCP ", "RK3588S", 2)

include ("Emmc.asl")
include ("Sdhc.asl")
// include ("Gmac.asl")
include ("Gmac1.asl")
//include ("Gpio.asl")
//include ("I2c.asl")
include ("Uart.asl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,40 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
switch (id) {
case 0:
/* gmac0 iomux from Radxa Rock-5A */
#if 0
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0x0F00UL << 16) | 0x0100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;
#endif
break;
case 1:
/* gmac1 iomux */
break;
default:
break;
switch (Id) {
case 1:
/* gmac1 iomux */
BUS_IOC->GPIO3B_IOMUX_SEL_H = (0x0FFFUL << 16) | 0x0111;
BUS_IOC->GPIO3A_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO3B_IOMUX_SEL_L = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3A_IOMUX_SEL_H = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3C_IOMUX_SEL_L = (0xFF00UL << 16) | 0x1100;

/* phy1 reset */
GpioPinSetDirection (3, GPIO_PIN_PB7, GPIO_PIN_OUTPUT);
break;
default:
break;
}
}

VOID
EFIAPI
GmacIoPhyReset (
UINT32 Id,
BOOLEAN Enable
)
{
switch (Id) {
case 1:
/* phy1 reset */
GpioPinWrite (3, GPIO_PIN_PB7, !Enable);
break;
default:
break;
}
}

Expand Down
6 changes: 6 additions & 0 deletions edk2-rockchip/Platform/FriendlyElec/NanoPi-R6C/NanoPi-R6C.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
gRK3588TokenSpaceGuid.PcdUsbDpPhy0Supported|TRUE
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }

#
# GMAC
#
gRK3588TokenSpaceGuid.PcdGmac1Supported|TRUE
gRK3588TokenSpaceGuid.PcdGmac1TxDelay|0x42

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2)

include ("Emmc.asl")
include ("Sdhc.asl")
// include ("Gmac.asl")
include ("Gmac1.asl")
// include ("Gpio.asl")
// include ("I2c.asl")
include ("Uart.asl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,40 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
switch (id) {
case 0:
/* gmac0 iomux */
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0x0F00UL << 16) | 0x0100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;
break;
case 1:
/* gmac1 iomux */
break;
default:
break;
switch (Id) {
case 1:
/* gmac1 iomux */
BUS_IOC->GPIO3B_IOMUX_SEL_H = (0x0FFFUL << 16) | 0x0111;
BUS_IOC->GPIO3A_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO3B_IOMUX_SEL_L = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3A_IOMUX_SEL_H = (0xF0FFUL << 16) | 0x1011;
BUS_IOC->GPIO3C_IOMUX_SEL_L = (0xFF00UL << 16) | 0x1100;

/* phy1 reset */
GpioPinSetDirection (3, GPIO_PIN_PB7, GPIO_PIN_OUTPUT);
break;
default:
break;
}
}

VOID
EFIAPI
GmacIoPhyReset (
UINT32 Id,
BOOLEAN Enable
)
{
switch (Id) {
case 1:
/* phy1 reset */
GpioPinWrite (3, GPIO_PIN_PB7, !Enable);
break;
default:
break;
}
}

Expand Down
6 changes: 6 additions & 0 deletions edk2-rockchip/Platform/FriendlyElec/NanoPi-R6S/NanoPi-R6S.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
gRK3588TokenSpaceGuid.PcdUsbDpPhy0Supported|TRUE
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }

#
# GMAC
#
gRK3588TokenSpaceGuid.PcdGmac1Supported|TRUE
gRK3588TokenSpaceGuid.PcdGmac1TxDelay|0x42

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
2 changes: 1 addition & 1 deletion edk2-rockchip/Platform/Hinlink/H88K/AcpiTables/Dsdt.asl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2)

include ("Emmc.asl")
include ("Sdhc.asl")
// include ("Gmac.asl")
include ("Gmac0.asl")
// include ("Gpio.asl")
// include ("I2c.asl")
include ("Uart.asl")
Expand Down
6 changes: 6 additions & 0 deletions edk2-rockchip/Platform/Hinlink/H88K/H88K.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }
gRK3588TokenSpaceGuid.PcdDp1LaneMux|{ 0x0 }

#
# GMAC
#
gRK3588TokenSpaceGuid.PcdGmac0Supported|TRUE
gRK3588TokenSpaceGuid.PcdGmac0TxDelay|0x44

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,42 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
switch (Id) {
case 0:
/* gmac0 iomux */
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0x0FFFUL << 16) | 0x0111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;

/* phy0 reset */
GpioPinSetDirection (4, GPIO_PIN_PB3, GPIO_PIN_OUTPUT);
break;
default:
break;
}
}

VOID
EFIAPI
GmacIoPhyReset (
UINT32 Id,
BOOLEAN Enable
)
{
/* No GMAC here */
switch (Id) {
case 0:
/* phy0 reset */
GpioPinWrite (4, GPIO_PIN_PB3, !Enable);
break;
default:
break;
}
}

VOID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
/* No GMAC here */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2)

include ("Emmc.asl")
include ("Sdhc.asl")
// include ("Gmac.asl")
include ("Gmac0.asl")
// include ("Gpio.asl")
// include ("I2c.asl")
include ("Uart.asl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,41 @@ NorFspiIomux (
VOID
EFIAPI
GmacIomux (
UINT32 id
IN UINT32 Id
)
{
switch (id) {
case 0:
/* gmac0 iomux */
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0x0F00UL << 16) | 0x0100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;
break;
case 1:
/* gmac1 iomux */
break;
default:
break;
switch (Id) {
case 0:
/* gmac0 iomux */
BUS_IOC->GPIO2A_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2B_IOMUX_SEL_L = (0xFFFFUL << 16) | 0x1111;
BUS_IOC->GPIO2B_IOMUX_SEL_H = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO2C_IOMUX_SEL_L = (0x0FFFUL << 16) | 0x0111;
BUS_IOC->GPIO4C_IOMUX_SEL_L = (0xFF00UL << 16) | 0x1100;
BUS_IOC->GPIO4C_IOMUX_SEL_H = (0x00FFUL << 16) | 0x0011;

/* phy0 reset */
GpioPinSetDirection (4, GPIO_PIN_PB3, GPIO_PIN_OUTPUT);
break;
default:
break;
}
}

VOID
EFIAPI
GmacIoPhyReset (
UINT32 Id,
BOOLEAN Enable
)
{
switch (Id) {
case 0:
/* phy0 reset */
GpioPinWrite (4, GPIO_PIN_PB3, !Enable);
break;
default:
break;
}
}

Expand Down
Loading

0 comments on commit ed76800

Please sign in to comment.