1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-26 13:52:21 +00:00

fatal: update to use clkrst api on 8.0.0+

This commit is contained in:
Michael Scire 2019-04-24 16:36:35 -07:00
parent d44b91826d
commit 14683405be
3 changed files with 48 additions and 11 deletions

View file

@ -102,9 +102,16 @@ void __appInit(void) {
std::abort();
}
rc = pcvInitialize();
if (R_FAILED(rc)) {
std::abort();
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) {
rc = clkrstInitialize();
if (R_FAILED(rc)) {
std::abort();
}
} else {
rc = pcvInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}
rc = lblInitialize();
@ -155,7 +162,11 @@ void __appExit(void) {
spsmExit();
psmExit();
lblExit();
pcvExit();
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) {
clkrstExit();
} else {
pcvExit();
}
bpcExit();
i2cExit();
pminfoExit();

View file

@ -17,6 +17,31 @@
#include <switch.h>
#include "fatal_task_clock.hpp"
Result AdjustClockTask::AdjustClockForModule(PcvModule module, u32 hz) {
Result rc;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) {
/* On 8.0.0+, convert to module id + use clkrst API. */
PcvModuleId module_id;
if (R_FAILED((rc = pcvGetModuleId(&module_id, module)))) {
return rc;
}
ClkrstSession session;
Result rc = clkrstOpenSession(&session, module_id, 3);
if (R_FAILED(rc)) {
return rc;
}
ON_SCOPE_EXIT { clkrstCloseSession(&session); };
rc = clkrstSetClockRate(&session, hz);
} else {
/* On 1.0.0-7.0.1, use pcv API. */
rc = pcvSetClockRate(module, hz);
}
return rc;
}
Result AdjustClockTask::AdjustClock() {
/* Fatal sets the CPU to 1020MHz, the GPU to 307 MHz, and the EMC to 1331MHz. */
@ -24,19 +49,19 @@ Result AdjustClockTask::AdjustClock() {
constexpr u32 GPU_CLOCK_307MHZ = 0x124F8000L;
constexpr u32 EMC_CLOCK_1331MHZ = 0x4F588000L;
Result rc = ResultSuccess;
if (R_FAILED((rc = pcvSetClockRate(PcvModule_Cpu, CPU_CLOCK_1020MHZ)))) {
if (R_FAILED((rc = AdjustClockForModule(PcvModule_CpuBus, CPU_CLOCK_1020MHZ)))) {
return rc;
}
if (R_FAILED((rc = pcvSetClockRate(PcvModule_Gpu, GPU_CLOCK_307MHZ)))) {
if (R_FAILED((rc = AdjustClockForModule(PcvModule_GPU, GPU_CLOCK_307MHZ)))) {
return rc;
}
if (R_FAILED((rc = pcvSetClockRate(PcvModule_Emc, EMC_CLOCK_1331MHZ)))) {
if (R_FAILED((rc = AdjustClockForModule(PcvModule_EMC, EMC_CLOCK_1331MHZ)))) {
return rc;
}
return rc;
}

View file

@ -21,6 +21,7 @@
class AdjustClockTask : public IFatalTask {
private:
Result AdjustClockForModule(PcvModule module, u32 hz);
Result AdjustClock();
public:
AdjustClockTask(FatalThrowContext *ctx, u64 title_id) : IFatalTask(ctx, title_id) { }