- sys-clk-OC: force disable charging, a temporary toggle that will be reset once power state changes (#57)

This commit is contained in:
KazushiM
2023-01-04 14:25:33 +08:00
parent 277f8d48e5
commit 012cd40a68
13 changed files with 95 additions and 14 deletions

View File

@@ -58,6 +58,7 @@ ClockManager::ClockManager()
this->oc = new SysClkOcExtra;
this->oc->systemCoreBoostCPU = false;
this->oc->batteryChargingDisabledOverride = false;
this->oc->governor = false;
this->oc->realProfile = SysClkProfile_Handheld;
@@ -209,9 +210,7 @@ void ClockManager::WaitForNextTick()
bool ClockManager::RefreshContext()
{
uint32_t chargingCurrent = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingCurrentLimit);
uint32_t chargingLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
PsmExt::ChargingHandler(chargingCurrent, chargingLimit);
PsmExt::ChargingHandler(this->GetInstance());
bool hasChanged = this->config->Refresh();
if (hasChanged) {
@@ -259,11 +258,13 @@ bool ClockManager::RefreshContext()
this->governor->Stop();
}
SysClkProfile profile = Clocks::GetCurrentProfile();
if (profile != this->oc->realProfile)
SysClkProfile realProfile = Clocks::GetCurrentProfile();
if (realProfile != this->oc->realProfile)
{
FileUtils::LogLine("[mgr] Profile change: %s", Clocks::GetProfileName(profile, true));
this->oc->realProfile = profile;
FileUtils::LogLine("[mgr] Profile change: %s", Clocks::GetProfileName(realProfile, true));
this->oc->realProfile = realProfile;
// Signal that power state has been changed, reset the override
this->SetBatteryChargingDisabledOverride(false);
hasChanged = true;
}
@@ -371,3 +372,12 @@ Config* ClockManager::GetConfig()
{
return this->config;
}
bool ClockManager::GetBatteryChargingDisabledOverride() {
return this->oc->batteryChargingDisabledOverride;
}
Result ClockManager::SetBatteryChargingDisabledOverride(bool toggle_true) {
this->oc->batteryChargingDisabledOverride = toggle_true;
return 0;
}

View File

@@ -19,6 +19,10 @@
#include "oc_extra.h"
// Forward declaration
class ReverseNXSync;
class Governor;
class ClockManager
{
public:
@@ -33,6 +37,8 @@ class ClockManager
void SetRNXRTMode(ReverseNXMode mode);
SysClkContext GetCurrentContext();
Config* GetConfig();
bool GetBatteryChargingDisabledOverride();
Result SetBatteryChargingDisabledOverride(bool toggle_true);
protected:
ClockManager();

View File

@@ -171,6 +171,15 @@ Result IpcService::ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8*
case SysClkIpcCmd_GetIsMariko:
*out_dataSize = sizeof(bool);
return ipcSrv->GetIsMariko((bool*)out_data);
case SysClkIpcCmd_GetBatteryChargingDisabledOverride:
*out_dataSize = sizeof(bool);
return ipcSrv->GetBatteryChargingDisabledOverride((bool*)out_data);
case SysClkIpcCmd_SetBatteryChargingDisabledOverride:
if (r->data.size >= sizeof(bool)) {
bool toggle_true = *((bool*)(r->data.ptr));
return ipcSrv->SetBatteryChargingDisabledOverride(toggle_true);
}
break;
}
return SYSCLK_ERROR(Generic);
@@ -321,3 +330,14 @@ Result IpcService::GetIsMariko(bool* out_is_mariko) {
*out_is_mariko = Clocks::GetIsMariko();
return 0;
}
Result IpcService::GetBatteryChargingDisabledOverride(bool* out_is_true) {
*out_is_true = ClockManager::GetInstance()->GetBatteryChargingDisabledOverride();
return 0;
}
Result IpcService::SetBatteryChargingDisabledOverride(bool toggle_true) {
return ClockManager::GetInstance()->SetBatteryChargingDisabledOverride(toggle_true);
}

View File

@@ -39,6 +39,8 @@ class IpcService
Result SetReverseNXRTMode(ReverseNXMode mode);
Result GetFrequencyTable(SysClkIpc_GetFrequencyTable_Args* args, SysClkFrequencyTable* out_table);
Result GetIsMariko(bool* out_is_mariko);
Result GetBatteryChargingDisabledOverride(bool* out_is_true);
Result SetBatteryChargingDisabledOverride(bool toggle_true);
bool running;
Thread thread;

View File

@@ -105,11 +105,12 @@ ReverseNXMode ReverseNXSync::RecheckToolMode() {
}
void PsmExt::ChargingHandler(uint32_t chargingCurrent, uint32_t chargingLimit) {
void PsmExt::ChargingHandler(ClockManager* instance) {
u32 current;
Result res = I2c_Bq24193_GetFastChargeCurrentLimit(&current);
if (R_SUCCEEDED(res)) {
current -= current % 100;
u32 chargingCurrent = instance->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingCurrentLimit);
if (current != chargingCurrent)
I2c_Bq24193_SetFastChargeCurrentLimit(chargingCurrent);
}
@@ -122,7 +123,9 @@ void PsmExt::ChargingHandler(uint32_t chargingCurrent, uint32_t chargingLimit) {
u32 chargeNow = 0;
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&chargeNow))) {
bool isCharging = PsmIsCharging(info);
if (isCharging && chargingLimit < chargeNow)
u32 chargingLimit = instance->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
bool forceDisabled = instance->GetBatteryChargingDisabledOverride();
if (isCharging && (forceDisabled || chargingLimit <= chargeNow))
serviceDispatch(session, Psm_DisableBatteryCharging);
if (!isCharging && chargingLimit > chargeNow)
serviceDispatch(session, Psm_EnableBatteryCharging);

View File

@@ -10,6 +10,10 @@
#include "file_utils.h"
#include "clocks.h"
// Forward declaration
class ClockManager;
#include "clock_manager.h"
class CpuCoreUtil {
public:
CpuCoreUtil (int coreid, uint64_t ns);
@@ -58,8 +62,8 @@ protected:
};
namespace PsmExt {
void ChargingHandler(uint32_t chargingCurrent, uint32_t chargingLimit);
};
void ChargingHandler(ClockManager* instance);
}
class Governor {
public: