fusee-cpp: implement SecureInitialize besides InitializeClock()

This commit is contained in:
Michael Scire
2021-08-21 18:00:44 -07:00
committed by SciresM
parent c9bd97192f
commit 669564b022
10 changed files with 314 additions and 115 deletions

View File

@@ -22,6 +22,51 @@ namespace ams::pinmux {
constinit uintptr_t g_pinmux_address = secmon::MemoryRegionPhysicalDeviceApbMisc.GetAddress();
constinit uintptr_t g_gpio_address = secmon::MemoryRegionPhysicalDeviceGpio.GetAddress();
void SetupFirstImpl(bool tx_cross_ext_con) {
if (tx_cross_ext_con) {
reg::Write(g_pinmux_address + PINMUX_AUX_UART2_TX, PINMUX_REG_BITS_ENUM(AUX_UART2_PM, UARTB),
PINMUX_REG_BITS_ENUM(AUX_PUPD, NONE),
PINMUX_REG_BITS_ENUM(AUX_TRISTATE, PASSTHROUGH),
PINMUX_REG_BITS_ENUM(AUX_E_INPUT, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_LOCK, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_E_OD, DISABLE));
reg::Write(g_pinmux_address + PINMUX_AUX_UART3_TX, PINMUX_REG_BITS_ENUM(AUX_UART3_PM, UARTC),
PINMUX_REG_BITS_ENUM(AUX_PUPD, NONE),
PINMUX_REG_BITS_ENUM(AUX_TRISTATE, PASSTHROUGH),
PINMUX_REG_BITS_ENUM(AUX_E_INPUT, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_LOCK, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_E_OD, DISABLE));
/* Configure GPIO for Uart-B/Uart-C. */
reg::ReadWrite(g_gpio_address + 0x108, REG_BITS_VALUE(0, 1, 1));
reg::ReadWrite(g_gpio_address + 0x00C, REG_BITS_VALUE(1, 1, 1));
reg::ReadWrite(g_gpio_address + 0x118, REG_BITS_VALUE(0, 1, 0));
reg::ReadWrite(g_gpio_address + 0x01C, REG_BITS_VALUE(1, 1, 0));
}
/* Configure PE6/PH6 */
reg::Write(g_pinmux_address + PINMUX_AUX_GPIO_PE6, PINMUX_REG_BITS_ENUM(AUX_GPIO_PE6_PM, RSVD0),
PINMUX_REG_BITS_ENUM(AUX_PUPD, NONE),
PINMUX_REG_BITS_ENUM(AUX_TRISTATE, PASSTHROUGH),
PINMUX_REG_BITS_ENUM(AUX_E_INPUT, ENABLE),
PINMUX_REG_BITS_ENUM(AUX_LOCK, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_E_OD, DISABLE));
reg::Write(g_pinmux_address + PINMUX_AUX_GPIO_PH6, PINMUX_REG_BITS_ENUM(AUX_GPIO_PH6_PM, RSVD0),
PINMUX_REG_BITS_ENUM(AUX_PUPD, NONE),
PINMUX_REG_BITS_ENUM(AUX_TRISTATE, PASSTHROUGH),
PINMUX_REG_BITS_ENUM(AUX_E_INPUT, ENABLE),
PINMUX_REG_BITS_ENUM(AUX_LOCK, DISABLE),
PINMUX_REG_BITS_ENUM(AUX_E_OD, DISABLE));
/* Configure GPIO E6/H6. */
reg::ReadWrite(g_gpio_address + 0x100, REG_BITS_VALUE(6, 1, 1));
reg::ReadWrite(g_gpio_address + 0x10C, REG_BITS_VALUE(6, 1, 1));
reg::ReadWrite(g_gpio_address + 0x110, REG_BITS_VALUE(6, 1, 0));
reg::ReadWrite(g_gpio_address + 0x11C, REG_BITS_VALUE(6, 1, 0));
}
}
void SetRegisterAddress(uintptr_t pinmux_address, uintptr_t gpio_address) {
@@ -29,6 +74,23 @@ namespace ams::pinmux {
g_gpio_address = gpio_address;
}
void SetupFirst(fuse::HardwareType hw_type) {
switch (hw_type) {
case fuse::HardwareType_Icosa:
case fuse::HardwareType_Iowa:
case fuse::HardwareType_Aula:
SetupFirstImpl(true);
break;
case fuse::HardwareType_Hoag:
case fuse::HardwareType_Calcio:
SetupFirstImpl(false);
break;
case fuse::HardwareType_Copper:
case fuse::HardwareType_Undefined:
break;
}
}
void SetupUartA() {
/* Get the registers. */
const uintptr_t PINMUX = g_pinmux_address;
@@ -180,4 +242,18 @@ namespace ams::pinmux {
PINMUX_REG_BITS_ENUM(AUX_E_OD, DISABLE));
}
void SetupVolumeButton() {
/* Configure VOL_UP/VOL_DOWN */
reg::ReadWrite(g_gpio_address + 0x50C, REG_BITS_VALUE(6, 1, 1));
reg::ReadWrite(g_gpio_address + 0x50C, REG_BITS_VALUE(7, 1, 1));
reg::ReadWrite(g_gpio_address + 0x51C, REG_BITS_VALUE(6, 1, 0));
reg::ReadWrite(g_gpio_address + 0x51C, REG_BITS_VALUE(7, 1, 0));
}
void SetupHomeButton() {
/* Configure BUTTON_HOME */
reg::ReadWrite(g_gpio_address + 0x600, REG_BITS_VALUE(1, 1, 1));
reg::ReadWrite(g_gpio_address + 0x610, REG_BITS_VALUE(1, 1, 0));
}
}

View File

@@ -32,10 +32,22 @@ namespace ams::pmic {
/* TODO: Find datasheet, link to it instead. */
/* NOTE: Tentatively, Max77620 "mostly" matches https://datasheets.maximintegrated.com/en/ds/MAX77863.pdf. */
/* This does not contain Max77621 documentation, though. */
constexpr inline int Max77620RegisterCnfgBbc = 0x04;
constexpr inline int Max77620RegisterOnOffStat = 0x15;
constexpr inline int Max77620RegisterSd0 = 0x16;
constexpr inline int Max77620RegisterCnfg1Ldo8 = 0x33;
constexpr inline int Max77620RegisterGpio0 = 0x36;
constexpr inline int Max77620RegisterAmeGpio = 0x40;
constexpr inline int Max77620RegisterOnOffCnfg1 = 0x41;
constexpr inline int Max77620RegisterCnfgFps0 = 0x43;
constexpr inline int Max77620RegisterCnfgFps1 = 0x44;
constexpr inline int Max77620RegisterCnfgFps2 = 0x45;
constexpr inline int Max77620RegisterFpsLdo4 = 0x4A;
constexpr inline int Max77620RegisterFpsLdo8 = 0x4E;
constexpr inline int Max77620RegisterFpsSd0 = 0x4F;
constexpr inline int Max77620RegisterFpsSd1 = 0x50;
constexpr inline int Max77620RegisterFpsSd3 = 0x52;
constexpr inline int Max77620RegisterFpsGpio3 = 0x56;
constexpr inline int Max77621RegisterVOut = 0x00;
constexpr inline int Max77621RegisterVOutDvc = 0x01;
@@ -148,6 +160,35 @@ namespace ams::pmic {
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG1, on_off_1_val);
}
void SetBackupBatteryConfig() {
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterCnfgBbc, 0x40);
}
void SetForcePowerOffTimeConfig() {
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1, 0x58);
}
void SetFlexiblePowerSequencer() {
/* Configure FPS registers. */
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterCnfgFps0, 0x38);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterCnfgFps1, 0x3A);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterCnfgFps2, 0x38);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsLdo4, 0x0F);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsLdo8, 0xC7);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsSd0, 0x4F);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsSd1, 0x29);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsSd3, 0x1B);
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterFpsGpio3, 0x22);
}
void SetVoltage(int reg, int mv) {
const u8 v = ((mv - 600) * 1000) / 12500;
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, reg, v);
}
}
void SetEnBit(Regulator regulator) {
@@ -215,15 +256,24 @@ namespace ams::pmic {
return (GetPmicOnOffStat() & (1 << 2)) != 0;
}
void SetSystemSetting() {
/* TODO */
void SetSystemSetting(fuse::SocType soc_type) {
SetBackupBatteryConfig();
SetForcePowerOffTimeConfig();
if (soc_type == fuse::SocType_Erista) {
SetFlexiblePowerSequencer();
}
}
void EnableVddCore() {
/* TODO */
void EnableVddCore(fuse::SocType soc_type) {
if (soc_type == fuse::SocType_Erista) {
SetVoltage(Max77620RegisterSd0, 1125);
} else /* if (soc_type == fuse::SocType_Mariko) */ {
SetVoltage(Max77620RegisterSd0, 1050);
}
}
void EnableLdo8() {
/* TODO */
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterCnfg1Ldo8, 0xE8);
}
}