diff --git a/nx/include/switch/services/pcv.h b/nx/include/switch/services/pcv.h index 7b121bf6..a50532fa 100644 --- a/nx/include/switch/services/pcv.h +++ b/nx/include/switch/services/pcv.h @@ -18,3 +18,6 @@ void pcvExit(void); Result pcvGetClockRate(PcvModule module, u32 *out_hz); Result pcvSetClockRate(PcvModule module, u32 hz); +Result pcvSetVoltageEnabled(bool state, u32 voltage); +Result pcvGetVoltageEnabled(bool *isEnabled, u32 voltage); + diff --git a/nx/source/services/pcv.c b/nx/source/services/pcv.c index 5c7e075e..b594dde6 100644 --- a/nx/source/services/pcv.c +++ b/nx/source/services/pcv.c @@ -104,3 +104,77 @@ Result pcvGetClockRate(PcvModule module, u32 *out_hz) { return rc; } + +Result pcvSetVoltageEnabled(bool state, u32 voltage) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u8 state; + u32 voltage; + } *raw; + + raw = serviceIpcPrepareHeader(&g_pcvSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 8; + raw->state = (u8)state; + raw->voltage = voltage; + + Result rc = serviceIpcDispatch(&g_pcvSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_pcvSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result pcvGetVoltageEnabled(bool *isEnabled, u32 voltage) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u32 voltage; + } *raw; + + raw = serviceIpcPrepareHeader(&g_pcvSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 9; + raw->voltage = voltage; + + Result rc = serviceIpcDispatch(&g_pcvSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + u8 isEnabled; + } *resp; + + serviceIpcParse(&g_pcvSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + if(R_SUCCEEDED(rc) && isEnabled) { + *isEnabled = (bool)resp->isEnabled; + } + } + + return rc; +}