From 23cb37d6be142a2704f3b14c586cdedfd7cac87e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 5 Jan 2021 00:30:28 -0800 Subject: [PATCH] pmic: use correct shutdown impl for erista power-off --- .../libexosphere/source/pmic/pmic_api.cpp | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/libraries/libexosphere/source/pmic/pmic_api.cpp b/libraries/libexosphere/source/pmic/pmic_api.cpp index f42d4264e..76ee8c683 100644 --- a/libraries/libexosphere/source/pmic/pmic_api.cpp +++ b/libraries/libexosphere/source/pmic/pmic_api.cpp @@ -125,6 +125,29 @@ namespace ams::pmic { return i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffStat); } + void ShutdownSystemImpl(bool reboot) { + /* Get value, set or clear software reset mask. */ + u8 on_off_2_val = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG2); + if (reboot) { + on_off_2_val |= MAX77620_ONOFFCNFG2_SFT_RST_WK; + } else { + on_off_2_val &= ~(MAX77620_ONOFFCNFG2_SFT_RST_WK); + } + i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG2, on_off_2_val); + + /* Get value, set software reset mask. */ + u8 on_off_1_val = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG1); + on_off_1_val |= MAX77620_ONOFFCNFG1_SFT_RST; + + /* NOTE: Here, userland finalizes the battery on non-Calcio. */ + if (fuse::GetHardwareType() != fuse::HardwareType_Calcio) { + /* ... */ + } + + /* Actually write the value to trigger shutdown/reset. */ + i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG1, on_off_1_val); + } + } void SetEnBit(Regulator regulator) { @@ -171,32 +194,8 @@ namespace ams::pmic { i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1, cnfg); } - void PowerOff() { - /* Write power-off to onoff cfg. */ - i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1, MAX77620_ONOFFCNFG1_PWR_OFF); - } - void ShutdownSystem(bool reboot) { - /* Get value, set or clear software reset mask. */ - u8 on_off_2_val = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG2); - if (reboot) { - on_off_2_val |= MAX77620_ONOFFCNFG2_SFT_RST_WK; - } else { - on_off_2_val &= ~(MAX77620_ONOFFCNFG2_SFT_RST_WK); - } - i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG2, on_off_2_val); - - /* Get value, set software reset mask. */ - u8 on_off_1_val = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG1); - on_off_1_val |= MAX77620_ONOFFCNFG1_SFT_RST; - - /* NOTE: Here, userland finalizes the battery on non-Calcio. */ - if (fuse::GetHardwareType() != fuse::HardwareType_Calcio) { - /* ... */ - } - - /* Actually write the value to trigger shutdown/reset. */ - i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, MAX77620_REG_ONOFFCNFG1, on_off_1_val); + ShutdownSystemImpl(reboot); /* Allow up to 5 seconds for shutdown/reboot to take place. */ util::WaitMicroSeconds(5'000'000ul); @@ -204,6 +203,10 @@ namespace ams::pmic { AMS_ABORT("Shutdown failed"); } + void PowerOff() { + ShutdownSystemImpl(false); + } + bool IsAcOk() { return (GetPmicOnOffStat() & (1 << 1)) != 0; }