-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PineTab2: Add support for PINE64 PineTab 2
- Loading branch information
1 parent
416d8a4
commit 5a1d666
Showing
9 changed files
with
1,107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
189 changes: 189 additions & 0 deletions
189
edk2-rockchip/Platform/Pine64/PineTab2/Drivers/BoardInitDxe/BoardInitDxe.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** @file | ||
* | ||
* Board init for the PineTab2 platform | ||
* | ||
* Copyright (c) 2021, Jared McNeill <[email protected]> | ||
* Copyright (c) 2023, Dang Huynh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
**/ | ||
|
||
#include <Base.h> | ||
#include <Library/ArmLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Library/UefiDriverEntryPoint.h> | ||
#include <Library/UefiLib.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/PcdLib.h> | ||
#include <Library/PrintLib.h> | ||
#include <Library/IoLib.h> | ||
#include <Library/TimerLib.h> | ||
#include <Library/CruLib.h> | ||
#include <Library/GpioLib.h> | ||
#include <Library/I2cLib.h> | ||
#include <Library/MultiPhyLib.h> | ||
#include <Library/OtpLib.h> | ||
#include <Library/SocLib.h> | ||
#include <Library/MemoryAllocationLib.h> | ||
#include <Library/UefiBootServicesTableLib.h> | ||
#include <Library/BaseMemoryLib.h> | ||
#include <Library/BaseCryptLib.h> | ||
|
||
#include <IndustryStandard/Rk356x.h> | ||
#include <IndustryStandard/Rk356xCru.h> | ||
#include <ConfigVars.h> | ||
|
||
/* | ||
* PMIC registers | ||
*/ | ||
#define PMIC_I2C_ADDR 0x20 | ||
|
||
#define PMIC_CHIP_NAME 0xed | ||
#define PMIC_CHIP_VER 0xee | ||
#define PMIC_POWER_EN1 0xb2 | ||
#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 | ||
|
||
/* | ||
* CPU_GRF registers | ||
*/ | ||
#define GRF_CPU_COREPVTPLL_CON0 (CPU_GRF + 0x0010) | ||
#define CORE_PVTPLL_RING_LENGTH_SEL_SHIFT 3 | ||
#define CORE_PVTPLL_RING_LENGTH_SEL_MASK (0x1FU << CORE_PVTPLL_RING_LENGTH_SEL_SHIFT) | ||
#define CORE_PVTPLL_OSC_EN BIT1 | ||
#define CORE_PVTPLL_START BIT0 | ||
|
||
/* | ||
* PMU registers | ||
*/ | ||
#define PMU_NOC_AUTO_CON0 (PMU_BASE + 0x0070) | ||
#define PMU_NOC_AUTO_CON1 (PMU_BASE + 0x0074) | ||
|
||
STATIC | ||
EFI_STATUS | ||
PmicRead ( | ||
IN UINT8 Register, | ||
OUT UINT8 *Value | ||
) | ||
{ | ||
return I2cRead (I2C0_BASE, PMIC_I2C_ADDR, | ||
&Register, sizeof (Register), | ||
Value, sizeof (*Value)); | ||
} | ||
|
||
STATIC | ||
EFI_STATUS | ||
PmicWrite ( | ||
IN UINT8 Register, | ||
IN UINT8 Value | ||
) | ||
{ | ||
return I2cWrite (I2C0_BASE, PMIC_I2C_ADDR, | ||
&Register, sizeof (Register), | ||
&Value, sizeof (Value)); | ||
} | ||
|
||
STATIC | ||
VOID | ||
BoardInitPmic ( | ||
VOID | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
UINT16 ChipName; | ||
UINT8 ChipVer; | ||
UINT8 Value; | ||
|
||
DEBUG ((DEBUG_INFO, "BOARD: PMIC init\n")); | ||
|
||
GpioPinSetPull (0, GPIO_PIN_PB1, GPIO_PIN_PULL_NONE); | ||
GpioPinSetInput (0, GPIO_PIN_PB1, GPIO_PIN_INPUT_SCHMITT); | ||
GpioPinSetFunction (0, GPIO_PIN_PB1, 1); | ||
GpioPinSetPull (0, GPIO_PIN_PB2, GPIO_PIN_PULL_NONE); | ||
GpioPinSetInput (0, GPIO_PIN_PB2, GPIO_PIN_INPUT_SCHMITT); | ||
GpioPinSetFunction (0, GPIO_PIN_PB2, 1); | ||
|
||
Status = PmicRead (PMIC_CHIP_NAME, &Value); | ||
if (EFI_ERROR (Status)) { | ||
DEBUG ((DEBUG_WARN, "Failed to read PMIC chip name! %r\n", Status)); | ||
ASSERT (FALSE); | ||
} | ||
ChipName = (UINT16)Value << 4; | ||
|
||
Status = PmicRead (PMIC_CHIP_VER, &Value); | ||
if (EFI_ERROR (Status)) { | ||
DEBUG ((DEBUG_WARN, "Failed to read PMIC chip version! %r\n", Status)); | ||
ASSERT (FALSE); | ||
} | ||
ChipName |= (Value >> 4) & 0xF; | ||
ChipVer = Value & 0xF; | ||
|
||
DEBUG ((DEBUG_INFO, "PMIC: Detected RK%03X ver 0x%X\n", ChipName, ChipVer)); | ||
ASSERT (ChipName == 0x817); | ||
|
||
/* Initialize PMIC */ | ||
PmicWrite (PMIC_LDO1_ON_VSEL, 0x30); /* 1.8V - vcca1v8_pmu */ | ||
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_dvp */ | ||
PmicWrite (PMIC_LDO9_ON_VSEL, 0x58); /* 2.8V - vcca2v8_dvp */ | ||
|
||
PmicWrite (PMIC_POWER_EN1, 0xff); /* LDO1, LDO2, LDO3, LDO4 */ | ||
PmicWrite (PMIC_POWER_EN2, 0xee); /* LDO6, LDO7, LDO8 */ | ||
PmicWrite (PMIC_POWER_EN3, 0x33); /* LDO9, BOOST */ | ||
} | ||
|
||
EFI_STATUS | ||
EFIAPI | ||
BoardInitDriverEntryPoint ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
DEBUG ((DEBUG_INFO, "BOARD: BoardInitDriverEntryPoint() called\n")); | ||
|
||
SocSetDomainVoltage (PMUIO2, VCC_1V8); /* VCCA1V8_PMU */ | ||
SocSetDomainVoltage (VCCIO1, VCC_3V3); /* VCCIO_ACODEC (PCIe) */ | ||
SocSetDomainVoltage (VCCIO2, VCC_1V8); /* VCCIO_FLASH */ | ||
SocSetDomainVoltage (VCCIO3, VCC_3V3); /* VCCIO_SD */ | ||
SocSetDomainVoltage (VCCIO4, VCC_1V8); | ||
SocSetDomainVoltage (VCCIO5, VCC_1V8); | ||
SocSetDomainVoltage (VCCIO6, VCC_1V8); | ||
SocSetDomainVoltage (VCCIO7, VCC_3V3); | ||
|
||
BoardInitPmic (); | ||
|
||
/* Enable automatic clock gating */ | ||
MmioWrite32 (PMU_NOC_AUTO_CON0, 0xFFFFFFFFU); | ||
MmioWrite32 (PMU_NOC_AUTO_CON1, 0x000F000FU); | ||
|
||
/* Set core_pvtpll ring length */ | ||
MmioWrite32 (GRF_CPU_COREPVTPLL_CON0, | ||
((CORE_PVTPLL_RING_LENGTH_SEL_MASK | CORE_PVTPLL_OSC_EN | CORE_PVTPLL_START) << 16) | | ||
(5U << CORE_PVTPLL_RING_LENGTH_SEL_SHIFT) | CORE_PVTPLL_OSC_EN | CORE_PVTPLL_START); | ||
|
||
/* Configure MULTI-PHY 0 and 1 for USB3 mode */ | ||
MultiPhySetMode (0, MULTIPHY_MODE_USB3); | ||
MultiPhySetMode (1, MULTIPHY_MODE_USB3); | ||
|
||
/* Set GPIO4 PC4 and PC5 (USB_HOST_PWREN) output high to power USB ports */ | ||
GpioPinSetDirection (4, GPIO_PIN_PC4, GPIO_PIN_OUTPUT); | ||
GpioPinWrite (4, GPIO_PIN_PC4, TRUE); | ||
GpioPinSetDirection (4, GPIO_PIN_PC5, GPIO_PIN_OUTPUT); | ||
GpioPinWrite (4, GPIO_PIN_PC5, TRUE); | ||
|
||
return EFI_SUCCESS; | ||
} |
57 changes: 57 additions & 0 deletions
57
edk2-rockchip/Platform/Pine64/PineTab2/Drivers/BoardInitDxe/BoardInitDxe.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#/** @file | ||
# | ||
# Board init PineTab2 platforms | ||
# | ||
# Copyright (c) 2021 Jared McNeill <[email protected]> | ||
# Copyright (c) 2023, Dang Huynh <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
#**/ | ||
|
||
[Defines] | ||
INF_VERSION = 0x0001001A | ||
BASE_NAME = BoardInitDxe | ||
FILE_GUID = D595E3B3-A972-4A6D-94F6-11309E3FA496 | ||
MODULE_TYPE = DXE_DRIVER | ||
VERSION_STRING = 1.0 | ||
ENTRY_POINT = BoardInitDriverEntryPoint | ||
|
||
[Sources] | ||
BoardInitDxe.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
CryptoPkg/CryptoPkg.dec | ||
ArmPlatformPkg/ArmPlatformPkg.dec | ||
ArmPkg/ArmPkg.dec | ||
EmbeddedPkg/EmbeddedPkg.dec | ||
Platform/Rockchip/Rk356x/Rk356x.dec | ||
Silicon/Rockchip/Rk356x/Rk356x.dec | ||
|
||
[LibraryClasses] | ||
ArmLib | ||
UefiBootServicesTableLib | ||
MemoryAllocationLib | ||
BaseMemoryLib | ||
BaseCryptLib | ||
BaseLib | ||
UefiLib | ||
UefiDriverEntryPoint | ||
DebugLib | ||
PrintLib | ||
TimeBaseLib | ||
TimerLib | ||
CruLib | ||
GpioLib | ||
I2cLib | ||
MultiPhyLib | ||
OtpLib | ||
SocLib | ||
|
||
[Protocols] | ||
|
||
|
||
[Depex] | ||
TRUE |
Oops, something went wrong.