wip sleep fix

This commit is contained in:
souldbminersmwc
2026-03-31 19:34:54 -04:00
parent 4103777f48
commit 4358df0308
12 changed files with 157 additions and 81 deletions

View File

@@ -40,7 +40,8 @@
#include "board_volt.hpp"
#include "board_misc.hpp"
#include "../soctherm.hpp"
#include "../integrations.hpp"
#include "../file_utils.hpp"
namespace board {
SysClkSocType gSocType;
@@ -52,6 +53,46 @@ namespace board {
u32 fd = 0, fd2 = 0;
constexpr u32 pscDependencies[] = {PscPmModuleId_Display}; // Our dependencies
constexpr PscPmModuleId pscModuleId = (PscPmModuleId)692; // Our ID
static PscPmModule pscModule; // Module to listen for events with
Thread SleepWakeListener;
void SleepWakeEventListener(void *ptr) {
while (true) {
Result rc = eventWait(&pscModule.event, 10'000'000);
if (R_VALUE(rc) == KERNELRESULT(TimedOut))
continue;
if (R_VALUE(rc) == KERNELRESULT(Cancelled))
break;
PscPmState eventState;
u32 flags;
if (R_FAILED(pscPmModuleGetRequest(&pscModule, &eventState, &flags)))
break;
switch (eventState) {
case PscPmState_ReadySleep:
fileUtils::LogLine("Sleep");
soctherm::StopSensors();
break;
case PscPmState_ReadyAwaken:
fileUtils::LogLine("Wake");
soctherm::StartSensors();
break;
case PscPmState_ReadyShutdown:
fileUtils::LogLine("Shutdown");
soctherm::StopSensors();
break;
default:
break;
}
pscPmModuleAcknowledge(&pscModule, eventState);
}
}
void FetchHardwareInfos() {
ReadFuses(fuseData);
SetGpuBracket(fuseData.gpuSpeedo, speedoBracket);
@@ -115,13 +156,13 @@ namespace board {
Result nvCheck = 1;
if (R_SUCCEEDED(nvInitialize())) {
nvCheck = nvOpen(&fd, "/dev/nvhost-ctrl-gpu");
Result nvCheck_sched = nvOpen(&fd2, "/dev/nvsched-ctrl");
/* This can be improved. */
NvSchedSucceed(nvCheck_sched);
// Result nvCheck_sched = nvOpen(&fd2, "/dev/nvsched-ctrl");
// /* This can be improved. */
// NvSchedSucceed(nvCheck_sched);
if (R_SUCCEEDED(nvCheck_sched)) {
SchedSetFD2(fd2);
}
// if (R_SUCCEEDED(nvCheck_sched)) {
// SchedSetFD2(fd2);
// }
}
rc = rgltrInitialize();
@@ -130,6 +171,16 @@ namespace board {
rc = pmdmntInitialize();
ASSERT_RESULT_OK(rc, "pmdmntInitialize");
rc = pscmInitialize();
ASSERT_RESULT_OK(rc, "pscmInitialize");
rc = pscmGetPmModule(&pscModule, pscModuleId, pscDependencies, sizeof(pscDependencies)/sizeof(u32), true);
ASSERT_RESULT_OK(rc, "pscmGetPmModule");
threadCreate(&SleepWakeListener, SleepWakeEventListener, NULL, NULL, 0x1000, 0x0, 3);
threadStart(&SleepWakeListener);
StartLoad(nvCheck, fd);
batteryInfoInitialize();
@@ -152,13 +203,16 @@ namespace board {
rc = svcQueryMemoryMapping(&dsiVirtAddr, &outsize, 0x54300000, 0x40000);
ASSERT_RESULT_OK(rc, "svcQueryMemoryMapping (dsi)");
display::DisplayRefreshConfig cfg = {.clkVirtAddr = clkVirtAddr, .dsiVirtAddr = dsiVirtAddr};
display::DisplayRefreshConfig cfg = {.clkVirtAddr = clkVirtAddr, .dsiVirtAddr = dsiVirtAddr, .isLite = (GetConsoleType() == HorizonOCConsoleType_Hoag), .isRetroSUPER = integrations::GetRETROSuperStatus()};
display::Initialize(&cfg);
CacheDfllData();
}
void Exit() {
soctherm::StopSensors();
if (HOSSVC_HAS_CLKRST) {
clkrstExit();
} else {
@@ -184,9 +238,12 @@ namespace board {
rgltrExit();
batteryInfoExit();
pmdmntExit();
nvExit();
display::Shutdown();
nvExit();
threadClose(&SleepWakeListener);
pscPmModuleFinalize(&pscModule);
pscPmModuleClose(&pscModule);
pscmExit();
}
SysClkSocType GetSocType() {
@@ -233,5 +290,4 @@ namespace board {
bool IsUsingRetroSuperDisplay() {
return false; /* stub for now. */
}
}

View File

@@ -31,6 +31,7 @@
#include <battery.h>
#include <pwm.h>
#include "board.hpp"
#include "../soctherm.hpp"
namespace board {
@@ -38,23 +39,50 @@ namespace board {
s32 millis = 0;
BatteryChargeInfo info;
if (sensor == SysClkThermalSensor_SOC) {
millis = tmp451TempSoc();
} else if (sensor == SysClkThermalSensor_PCB) {
millis = tmp451TempPcb();
} else if (sensor == SysClkThermalSensor_Skin) {
if (HOSSVC_HAS_TC) {
Result rc;
rc = tcGetSkinTemperatureMilliC(&millis);
ASSERT_RESULT_OK(rc, "tcGetSkinTemperatureMilliC");
soctherm::TSensorTemps temps;
soctherm::ReadSensors(temps);
switch(sensor) {
case SysClkThermalSensor_SOC: {
millis = tmp451TempSoc();
break;
}
case SysClkThermalSensor_PCB: {
millis = tmp451TempPcb();
break;
}
case SysClkThermalSensor_Skin: {
if (HOSSVC_HAS_TC) {
Result rc;
rc = tcGetSkinTemperatureMilliC(&millis);
ASSERT_RESULT_OK(rc, "tcGetSkinTemperatureMilliC");
}
break;
}
case HorizonOCThermalSensor_Battery: {
batteryInfoGetChargeInfo(&info);
millis = batteryInfoGetTemperatureMiliCelsius(&info);
break;
}
case HorizonOCThermalSensor_PMIC: {
millis = 50000;
break;
}
case HorizonOCThermalSensor_CPU: {
millis = temps.cpu;
break;
}
case HorizonOCThermalSensor_GPU: {
millis = temps.gpu;
break;
}
case HorizonOCThermalSensor_MEM: {
millis = board::GetSocType() == SysClkSocType_Mariko ? temps.pllx : temps.mem;
break;
}
default: {
ASSERT_ENUM_VALID(SysClkThermalSensor, sensor);
}
} else if (sensor == HorizonOCThermalSensor_Battery) {
batteryInfoGetChargeInfo(&info);
millis = batteryInfoGetTemperatureMiliCelsius(&info);
/* } else if (sensor == HorizonOCThermalSensor_PMIC) {
millis = 50000; */
} else {
ASSERT_ENUM_VALID(SysClkThermalSensor, sensor);
}
return std::max(0, millis);

View File

@@ -580,7 +580,7 @@ namespace clockManager {
integrations::LoadSaltyNX();
}
gContext.isUsingRetroSuper = board::IsUsingRetroSuperDisplay();
gContext.isUsingRetroSuper = integrations::GetRETROSuperStatus();
governor::startThreads();
}
@@ -616,6 +616,7 @@ namespace clockManager {
void Tick()
{
fileUtils::LogLine("CPU Temp: %d", board::GetTemperatureMilli(HorizonOCThermalSensor_CPU));
std::scoped_lock lock{gContextMutex};
std::uint32_t mode = 0;
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
@@ -633,7 +634,7 @@ namespace clockManager {
void WaitForNextTick()
{
if (!(board::GetHz(SysClkModule_MEM) < 665000000))
if (board::GetHz(SysClkModule_MEM) > 665000000)
svcSleepThread(config::GetConfigValue(SysClkConfigValue_PollingIntervalMs) * 1000000ULL);
else
svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode

View File

@@ -95,6 +95,11 @@ namespace integrations {
return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0;
}
bool GetRETROSuperStatus() {
struct stat st = {0};
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0;
}
void LoadSaltyNX() {
if (!CheckSaltyNXPort())
return;

View File

@@ -70,6 +70,7 @@ namespace integrations {
bool GetSysDockState();
bool GetSaltyNXState();
bool GetRETROSuperStatus();
void LoadSaltyNX();
u8 GetSaltyNXFPS();
u16 GetSaltyNXResolutionHeight();

View File

@@ -37,7 +37,7 @@
#include "clock_manager.hpp"
#include "ipc_service.hpp"
#include "config.hpp"
#define INNER_HEAP_SIZE 0x40000
#define INNER_HEAP_SIZE 0x45000
extern "C"

View File

@@ -418,7 +418,7 @@ namespace soctherm {
};
u32 calib[SocthermTSensor_EnumMax] = {};
u64 socthermVa;
u64 socthermVa, carVa, fuseVa;
bool isMariko;
}
@@ -509,6 +509,22 @@ namespace soctherm {
}
}
void StopSensors() {
const TSensor *sensors = isMariko ? marikoTSensors : eristaTSensors;
u32 count = isMariko ? std::size(marikoTSensors) : std::size(eristaTSensors);
for (u32 i = 0; i < count; ++i) {
SetBits(socthermVa, sensors[i].base + SENSOR_CONFIG0, SENSOR_CONFIG0_STOP);
ClearBits(socthermVa, sensors[i].base + SENSOR_CONFIG1, SENSOR_CONFIG1_TEMP_ENABLE);
WriteReg(socthermVa, sensors[i].base + SENSOR_CONFIG2, 0);
}
WriteReg(socthermVa, TSENSOR_TSENSOR_CLKEN, 0);
WriteReg(carVa, CAR_CLK_SOURCE_TSENSOR, 0);
SetBits(carVa, CAR_CLK_OUT_ENB_V, 0);
}
void StartSensors() {
if (!ReadReg(socthermVa, TSENSOR_TSENSOR_CLKEN)) {
u32 pdiv, hotspot;
@@ -597,7 +613,6 @@ namespace soctherm {
}
void Initialize() {
u64 carVa, fuseVa;
isMariko = board::GetSocType() == SysClkSocType_Mariko;
constexpr u64 SocthermPa = 0x700E2000, FusePa = 0x7000F000, CarPa = 0x60006000;

View File

@@ -122,7 +122,16 @@ namespace soctherm {
SocthermTSensor_EnumMax = 8,
};
struct TSensorTemps {
s32 cpu;
s32 gpu;
s32 mem;
s32 pllx;
};
void Initialize();
void StartSensors();
void StopSensors();
void ReadSensors(TSensorTemps &temps);
}