hocclk: format code

use clang format file provided for optimal formatting
This commit is contained in:
souldbminersmwc
2026-06-04 19:52:11 -04:00
parent c6a8884c14
commit 88bfa9a4ec
118 changed files with 7111 additions and 9615 deletions

View File

@@ -13,6 +13,7 @@ UseTab: Never
IndentAccessModifiers: false
AccessModifierOffset: 0
NamespaceIndentation: All
IndentPPDirectives: BeforeHash
BreakBeforeBraces: Attach
BraceWrapping:

View File

@@ -24,17 +24,16 @@
* --------------------------------------------------------------------------
*/
#pragma once
#if defined(__cplusplus)
#include "cpp_util.hpp"
extern "C"
{
extern "C" {
#endif
#include <hocclk.h>
#include <hocclk/client/ipc.h>
#if defined(__cplusplus)

View File

@@ -24,17 +24,18 @@
* --------------------------------------------------------------------------
*/
#define TESLA_INIT_IMPL
#include <tesla.hpp>
#include "ui/gui/fatal_gui.h"
#include "ui/gui/main_gui.h"
class AppOverlay : public tsl::Overlay
{
class AppOverlay : public tsl::Overlay {
public:
AppOverlay() {}
~AppOverlay() {}
AppOverlay() {
}
~AppOverlay() {
}
// virtual void initServices() override {
// rgltrInitialize();
@@ -44,52 +45,41 @@ class AppOverlay : public tsl::Overlay
hocclkIpcExit();
}
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override
{
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
uint32_t apiVersion;
smInitialize();
tsl::hlp::ScopeGuard smGuard([] { smExit(); });
if(!hocclkIpcRunning())
{
return initially<FatalGui>(
"hoc-clk is not running.\n\n"
if (!hocclkIpcRunning()) {
return initially<FatalGui>("hoc-clk is not running.\n\n"
"\n"
"Please make sure it is correctly\n\n"
"installed and enabled.",
""
);
"");
}
if(R_FAILED(hocclkIpcInitialize()) || R_FAILED(hocclkIpcGetAPIVersion(&apiVersion)))
{
return initially<FatalGui>(
"Could not connect to hoc-clk.\n\n"
if (R_FAILED(hocclkIpcInitialize()) || R_FAILED(hocclkIpcGetAPIVersion(&apiVersion))) {
return initially<FatalGui>("Could not connect to hoc-clk.\n\n"
"\n"
"Please make sure it is correctly\n\n"
"installed and enabled.",
""
);
"");
}
if(HOCCLK_IPC_API_VERSION != apiVersion)
{
return initially<FatalGui>(
"Overlay not compatible with\n\n"
if (HOCCLK_IPC_API_VERSION != apiVersion) {
return initially<FatalGui>("Overlay not compatible with\n\n"
"the running hoc-clk version.\n\n"
"\n"
"Please make sure everything is\n\n"
"installed and up to date.",
""
);
"");
}
return initially<MainGui>();
}
};
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
return tsl::loop<AppOverlay>(argc, argv);
}

View File

@@ -24,20 +24,18 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <cstdint>
#include <cstdio>
#include <string>
#include <cstdint>
#include <hocclk/board.h>
#define FREQ_DEFAULT_TEXT "Do not override"
static inline std::string formatListFreqMHz(std::uint32_t mhz)
{
if(mhz == 0)
{
static inline std::string formatListFreqMHz(std::uint32_t mhz) {
if (mhz == 0) {
return FREQ_DEFAULT_TEXT;
}
@@ -45,17 +43,17 @@ static inline std::string formatListFreqMHz(std::uint32_t mhz)
return std::string(buf, snprintf(buf, sizeof(buf), "%u MHz", mhz));
}
static inline std::string formatListFreqHz(uint32_t hz) { return formatListFreqMHz(hz / 1000000); }
static inline std::string formatListFreqHz(uint32_t hz) {
return formatListFreqMHz(hz / 1000000);
}
static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit)
{
static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit) {
if (mhz == 0)
return FREQ_DEFAULT_TEXT;
uint32_t mts = mhz * 2;
char buf[24];
switch(unit)
{
switch (unit) {
case RamDisplayUnit_MHz:
snprintf(buf, sizeof(buf), "%u MHz", mhz);
break;
@@ -70,18 +68,15 @@ static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit)
return buf;
}
static inline std::string formatListFreqHzMem(uint32_t hz, RamDisplayUnit unit)
{
static inline std::string formatListFreqHzMem(uint32_t hz, RamDisplayUnit unit) {
return formatListFreqMem(hz / 1000000, unit);
}
static inline std::string formatMemClockKhzLabel(uint32_t khz, RamDisplayUnit unit)
{
static inline std::string formatMemClockKhzLabel(uint32_t khz, RamDisplayUnit unit) {
uint32_t mhz = khz / 1000;
uint32_t mts = khz / 500;
char buf[32];
switch(unit)
{
switch (unit) {
case RamDisplayUnit_MHz:
snprintf(buf, sizeof(buf), "%u MHz", mhz);
break;

View File

@@ -28,49 +28,25 @@
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
#include "value_choice_gui.h"
class AppProfileGui : public BaseMenuGui
{
class AppProfileGui : public BaseMenuGui {
protected:
std::uint64_t applicationId;
HocClkTitleProfileList *profileList;
void openFreqChoiceGui(tsl::elm::ListItem *listItem, HocClkProfile profile, HocClkModule module);
void addModuleListItem(HocClkProfile profile, HocClkModule module);
void addModuleListItemToggle(HocClkProfile profile, HocClkModule module);
void openValueChoiceGui(
tsl::elm::ListItem* listItem,
std::uint32_t currentValue,
const ValueRange& range,
const std::string& categoryName,
ValueChoiceListener listener,
const ValueThresholds& thresholds = ValueThresholds(),
bool enableThresholds = false,
const std::map<std::uint32_t, std::string>& labels = {},
const std::vector<NamedValue>& namedValues = {},
bool showDefaultValue = true
);
std::string formatValueDisplay(
std::uint32_t value,
const std::vector<NamedValue>& namedValues,
const std::string& suffix,
std::uint32_t divisor,
int decimalPlaces
);
void addModuleListItemValue(
HocClkProfile profile,
HocClkModule module,
const std::string& categoryName,
std::uint32_t min,
std::uint32_t max,
std::uint32_t step,
const std::string& suffix,
std::uint32_t divisor,
int decimalPlaces,
ValueThresholds thresholds,
std::vector<NamedValue> namedValues = {},
bool showDefaultValue = true
);
void openValueChoiceGui(tsl::elm::ListItem *listItem, std::uint32_t currentValue, const ValueRange &range, const std::string &categoryName,
ValueChoiceListener listener, const ValueThresholds &thresholds = ValueThresholds(), bool enableThresholds = false,
const std::map<std::uint32_t, std::string> &labels = {}, const std::vector<NamedValue> &namedValues = {},
bool showDefaultValue = true);
std::string formatValueDisplay(std::uint32_t value, const std::vector<NamedValue> &namedValues, const std::string &suffix, std::uint32_t divisor,
int decimalPlaces);
void addModuleListItemValue(HocClkProfile profile, HocClkModule module, const std::string &categoryName, std::uint32_t min, std::uint32_t max,
std::uint32_t step, const std::string &suffix, std::uint32_t divisor, int decimalPlaces, ValueThresholds thresholds,
std::vector<NamedValue> namedValues = {}, bool showDefaultValue = true);
void addGovernorSection(HocClkProfile profile);
void addProfileUI(HocClkProfile profile);
public:
AppProfileGui(std::uint64_t applicationId, HocClkTitleProfileList *profileList);
~AppProfileGui();

View File

@@ -24,16 +24,18 @@
* --------------------------------------------------------------------------
*/
#include "base_gui.h"
#include "../elements/base_frame.h"
#include "base_gui.h"
void BaseFrame::draw(tsl::gfx::Renderer *renderer) {
tsl::elm::HeaderOverlayFrame::draw(renderer);
this->gui->preDraw(renderer);
}
#include <tesla.hpp>
#include <math.h>
#include <tesla.hpp>
#define LOGO_Y_REAL 65
@@ -71,14 +73,8 @@ static constexpr tsl::Color dynamicLogoRGB2 = tsl::Color( 2, 8, 11, 15);
static constexpr tsl::Color STATIC_TEAL = tsl::Color(7, 15, 15, 15);
const std::string name = " Horizon OC";
static s32 drawDynamicUltraText(
tsl::gfx::Renderer* renderer,
s32 startX,
s32 y,
u32 fontSize,
const tsl::Color& staticColor,
bool useNotificationMethod = false)
{
static s32 drawDynamicUltraText(tsl::gfx::Renderer *renderer, s32 startX, s32 y, u32 fontSize, const tsl::Color &staticColor,
bool useNotificationMethod = false) {
static constexpr double cycleDuration = 1.6;
s32 currentX = startX;
@@ -88,10 +84,10 @@ static s32 drawDynamicUltraText(
const double waveScale = 2.0 * M_PI / cycleDuration;
for (size_t i = 0; i < name.size(); i++)
{
for (size_t i = 0; i < name.size(); i++) {
char letter = name[i];
if (letter == '\0') break;
if (letter == '\0')
break;
double phase = waveScale * (timeNow + i * 0.12);
@@ -103,15 +99,9 @@ static s32 drawDynamicUltraText(
double glow = (cos(phase * 1.5) + 1.0) * 0.5;
double brightness = 0.75 + glow * 0.25;
u8 r = static_cast<u8>(
((int)dynamicLogoRGB1.r + ((int)dynamicLogoRGB2.r - (int)dynamicLogoRGB1.r) * blend) * brightness
);
u8 g = static_cast<u8>(
((int)dynamicLogoRGB1.g + ((int)dynamicLogoRGB2.g - (int)dynamicLogoRGB1.g) * blend) * brightness
);
u8 b = static_cast<u8>(
((int)dynamicLogoRGB1.b + ((int)dynamicLogoRGB2.b - (int)dynamicLogoRGB1.b) * blend) * brightness
);
u8 r = static_cast<u8>(((int)dynamicLogoRGB1.r + ((int)dynamicLogoRGB2.r - (int)dynamicLogoRGB1.r) * blend) * brightness);
u8 g = static_cast<u8>(((int)dynamicLogoRGB1.g + ((int)dynamicLogoRGB2.g - (int)dynamicLogoRGB1.g) * blend) * brightness);
u8 b = static_cast<u8>(((int)dynamicLogoRGB1.b + ((int)dynamicLogoRGB2.b - (int)dynamicLogoRGB1.b) * blend) * brightness);
r = std::clamp<u8>(r, 0, 15);
g = std::clamp<u8>(g, 0, 15);
@@ -140,14 +130,7 @@ static s32 drawDynamicUltraText(
void BaseGui::preDraw(tsl::gfx::Renderer *renderer) {
renderer->drawBitmap(LOGO_X, LOGO_Y_REAL - LOGO_LABEL_FONT_SIZE, LOGO_IMG_W, LOGO_IMG_H, hoc_rgba);
drawDynamicUltraText(
renderer,
LOGO_TEXT_X,
TEXT_Y,
LOGO_LABEL_FONT_SIZE,
STATIC_TEAL,
false
);
drawDynamicUltraText(renderer, LOGO_TEXT_X, TEXT_Y, LOGO_LABEL_FONT_SIZE, STATIC_TEAL, false);
static const std::string versionStr = "Version " + getVersionString() + " \"Gaea\"";
static constexpr tsl::Color versionColor(9, 9, 9, 15);
@@ -166,14 +149,12 @@ void BaseGui::preDraw(tsl::gfx::Renderer* renderer) {
}
}
tsl::elm::Element* BaseGui::createUI()
{
tsl::elm::Element *BaseGui::createUI() {
BaseFrame *rootFrame = new BaseFrame(this, this->headerHeight());
rootFrame->setContent(this->baseUI());
return rootFrame;
}
void BaseGui::update()
{
void BaseGui::update() {
this->refresh();
}

View File

@@ -24,32 +24,36 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <tesla.hpp>
#include "../elements/base_frame.h"
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
#include <string>
#include <tesla.hpp>
#include <vector>
#include "../style.h"
#include "../../ipc.h"
#include "../elements/base_frame.h"
#include "../style.h"
class BaseGui : public tsl::Gui
{
class BaseGui : public tsl::Gui {
public:
BaseGui() {}
~BaseGui() {}
BaseGui() {
}
~BaseGui() {
}
virtual void preDraw(tsl::gfx::Renderer *renderer);
void update() override;
tsl::elm::Element *createUI() override;
virtual tsl::elm::Element *baseUI() = 0;
virtual void refresh() {}
virtual u16 headerHeight() const { return HOC_HEADER_HEIGHT; }
virtual void refresh() {
}
virtual u16 headerHeight() const {
return HOC_HEADER_HEIGHT;
}
private:
};
extern std::string getVersionString();

View File

@@ -24,23 +24,24 @@
* --------------------------------------------------------------------------
*/
#include "../format.h"
#include "base_menu_gui.h"
#include "fatal_gui.h"
#include "../format.h"
#define TOP_Y_OFFSET 15
// Cache hardware model to avoid repeated syscalls
BaseMenuGui::BaseMenuGui() : tempColors{ tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), }
{
BaseMenuGui::BaseMenuGui()
: tempColors{
tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0),
} {
tsl::initializeThemeVars();
this->context = nullptr;
this->lastContextUpdate = 0;
this->listElement = nullptr;
// Pre-cache hardware model during initialization
IsAula();
IsMariko();
@@ -59,9 +60,9 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
BaseGui::preDraw(renderer);
// All constants pre-calculated and cached
const char* labels[] = {
"App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board", "Skin", "Now", "Avg", "BAT", "PMIC", "Fan", IsAula() || this->context->isUsingRetroSuper ? "OLED" : "LCD", "FPS", "RES"
};
const char *labels[] = { "App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board",
"Skin", "Now", "Avg", "BAT", "PMIC", "Fan", IsAula() || this->context->isUsingRetroSuper ? "OLED" : "LCD",
"FPS", "RES" };
static constexpr u32 dataPositions[6] = { 63 - 3 + 3, 200 - 1, 344 - 1 - 3, 200 - 1, 342 - 1, 321 - 1 };
@@ -74,7 +75,16 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
}
positionsInitialized = true;
}
static u32 positions[10] = {24-1, 310-labelWidths[1], 24-1, 192-labelWidths[3], 332-labelWidths[4], 24-1, 192 - labelWidths[6], 332-labelWidths[7], 192 - labelWidths[8], 332-labelWidths[9]};
static u32 positions[10] = { 24 - 1,
310 - labelWidths[1],
24 - 1,
192 - labelWidths[3],
332 - labelWidths[4],
24 - 1,
192 - labelWidths[6],
332 - labelWidths[7],
192 - labelWidths[8],
332 - labelWidths[9] };
static u32 maxProfileValueWidth = renderer->getTextDimensions("USB Charger", false, SMALL_TEXT_SIZE).first; // longest word
@@ -108,7 +118,6 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
y += 20; // Direct assignment (129 + 20)
renderer->drawString(displayStrings[5], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU real
renderer->drawString(displayStrings[6], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU real
renderer->drawString(displayStrings[7], false, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // MEM real
@@ -125,7 +134,8 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
renderer->drawString(displayStrings[8], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU voltage
renderer->drawString(displayStrings[9], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU voltage
renderer->drawStringWithColoredSections(displayStrings[10], false, {""}, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor, tsl::separatorColor);
renderer->drawStringWithColoredSections(displayStrings[10], false, { "" }, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor,
tsl::separatorColor);
renderer->drawString(displayStrings[19], false, positions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU Usage
renderer->drawString(displayStrings[17], false, positions[3], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU Usage
@@ -181,15 +191,13 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
renderer->drawString(labels[14], false, positions[4] + 9, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // FPS label
renderer->drawString(displayStrings[26], false, dataPositions[2] + 6, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // FPS
}
y += 20;
}
// Optimized refresh - now does all the string formatting once per second
void BaseMenuGui::refresh()
{
void BaseMenuGui::refresh() {
const u64 ticks = armGetSystemTick();
// Use cached comparison - 1 billion nanoseconds
if (armTicksToNs(ticks - this->lastContextUpdate) <= 1000000000UL) [[likely]] {
@@ -269,10 +277,12 @@ void BaseMenuGui::refresh()
switch (configList.values[HocClkConfigValue_RAMVoltDisplayMode]) {
case RamDisplayMode_VDD2:
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDD2] / 1000U, (context->voltages[HocClkVoltage_EMCVDD2] % 1000U) / 100U);
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDD2] / 1000U,
(context->voltages[HocClkVoltage_EMCVDD2] % 1000U) / 100U);
break;
case RamDisplayMode_VDDQ:
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDDQ] / 1000U, (context->voltages[HocClkVoltage_EMCVDDQ] % 1000U) / 100U);
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDDQ] / 1000U,
(context->voltages[HocClkVoltage_EMCVDDQ] % 1000U) / 100U);
break;
default:
strcpy(displayStrings[10], "N/A");
@@ -343,11 +353,9 @@ void BaseMenuGui::refresh()
millis = context->temps[HocClkThermalSensor_MEM];
sprintf(displayStrings[30], "%u.%u", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_MEM] = tsl::GradientColor(millis * 0.001f);
}
tsl::elm::Element* BaseMenuGui::baseUI()
{
tsl::elm::Element *BaseMenuGui::baseUI() {
auto *list = new tsl::elm::List();
this->listElement = list;
this->listUI();

View File

@@ -24,16 +24,13 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include "../../ipc.h"
#include "base_gui.h"
class BaseMenuGui : public BaseGui
{
class BaseMenuGui : public BaseGui {
protected:
public:
// u8 dockedHighestAllowedRefreshRate = 60;
HocClkContext *context;
@@ -66,9 +63,7 @@ class BaseMenuGui : public BaseGui
setsysGetProductModel(&HWmodel);
g_hardwareModelCached = true;
}
g_isMariko = (HWmodel == SetSysProductModel_Iowa ||
HWmodel == SetSysProductModel_Hoag ||
HWmodel == SetSysProductModel_Calcio ||
g_isMariko = (HWmodel == SetSysProductModel_Iowa || HWmodel == SetSysProductModel_Hoag || HWmodel == SetSysProductModel_Calcio ||
HWmodel == SetSysProductModel_Aula);
return g_isMariko;
@@ -84,7 +79,9 @@ class BaseMenuGui : public BaseGui
tsl::elm::Element *baseUI() override;
void refresh() override;
virtual void listUI() = 0;
u16 headerHeight() const override { return HOC_BOX_BOTTOM + 9; }
u16 headerHeight() const override {
return HOC_BOX_BOTTOM + 9;
}
private:
char displayStrings[48][32]; // Pre-formatted display strings

File diff suppressed because it is too large Load Diff

View File

@@ -16,8 +16,9 @@
*
*/
#pragma once
#include "misc_gui.h"
#include <vector>
#include <string>
#include <vector>
#include "misc_gui.h"
std::vector<std::string> ConfigInfoStrings(HocClkConfigValue val, bool isMariko, bool isHoag);

View File

@@ -24,45 +24,37 @@
* --------------------------------------------------------------------------
*/
#include "fatal_gui.h"
FatalGui::FatalGui(const std::string message, const std::string info)
{
FatalGui::FatalGui(const std::string message, const std::string info) {
this->message = message;
this->info = info;
}
void FatalGui::openWithResultCode(std::string tag, Result rc)
{
void FatalGui::openWithResultCode(std::string tag, Result rc) {
char rcStr[32];
std::string info = tag;
info.append(rcStr, snprintf(rcStr, sizeof(rcStr), "\n\n[0x%x] %04d-%04d", rc, R_MODULE(rc), R_DESCRIPTION(rc)));
tsl::changeTo<FatalGui>(
"Could not connect to hoc-clk sysmodule.\n\n"
tsl::changeTo<FatalGui>("Could not connect to hoc-clk sysmodule.\n\n"
"\n"
"Please make sure everything is\n\n"
"correctly installed and enabled.",
info
);
info);
}
tsl::elm::Element* FatalGui::baseUI()
{
tsl::elm::Element *FatalGui::baseUI() {
tsl::elm::CustomDrawer *drawer = new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, u16 x, u16 y, u16 w, u16 h) {
renderer->drawString("\uE150", false, 40, 210, 40, TEXT_COLOR);
renderer->drawString("Fatal error", false, 100, 210, 30, TEXT_COLOR);
std::uint32_t txtY = 255;
if(!this->message.empty())
{
if (!this->message.empty()) {
txtY += renderer->drawString(this->message.c_str(), false, 40, txtY, 23, TEXT_COLOR).second;
txtY += 55;
}
if(!this->info.empty())
{
if (!this->info.empty()) {
renderer->drawString(this->info.c_str(), false, 40, txtY, 18, DESC_COLOR);
}
});
@@ -70,10 +62,9 @@ tsl::elm::Element* FatalGui::baseUI()
return drawer;
}
bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight)
{
if((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B)
{
bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft,
HidAnalogStickState joyStickPosRight) {
if ((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B) {
while (tsl::Overlay::get()->getCurrentGui() != nullptr) {
tsl::goBack();
}

View File

@@ -24,23 +24,23 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <list>
#include "base_gui.h"
class FatalGui : public BaseGui
{
class FatalGui : public BaseGui {
protected:
std::string message;
std::string info;
public:
FatalGui(const std::string message, const std::string info);
~FatalGui() {}
~FatalGui() {
}
tsl::elm::Element *baseUI() override;
bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight);
bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft,
HidAnalogStickState joyStickPosRight);
static void openWithResultCode(std::string tag, Result rc);
};

View File

@@ -24,21 +24,13 @@
* --------------------------------------------------------------------------
*/
#include "ult_ext.h"
#include "freq_choice_gui.h"
#include "../format.h"
#include "fatal_gui.h"
#include "freq_choice_gui.h"
#include "ult_ext.h"
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
std::uint32_t* hzList,
std::uint32_t hzCount,
HocClkModule module,
FreqChoiceListener listener,
bool checkMax,
std::map<uint32_t, std::string> labels)
{
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, HocClkModule module, FreqChoiceListener listener,
bool checkMax, std::map<uint32_t, std::string> labels) {
this->selectedHz = selectedHz;
this->hzList = hzList;
this->hzCount = hzCount;
@@ -49,13 +41,11 @@ FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
this->configList = new HocClkConfigValueList{};
}
FreqChoiceGui::~FreqChoiceGui()
{
FreqChoiceGui::~FreqChoiceGui() {
delete this->configList;
}
tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety)
{
tsl::elm::ListItem *FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety) {
std::string text;
if (module == HocClkModule_MEM)
text = formatListFreqHzMem(hz, (RamDisplayUnit)this->configList->values[HocClkConfigValue_RamDisplayUnit]);
@@ -70,11 +60,9 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
if (selected)
const_cast<std::string &>(rightText) = "\uE14B";
tsl::elm::ListItem* listItem =
new tsl::elm::ListItem(text, rightText, false);
tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, rightText, false);
switch (safety)
{
switch (safety) {
case 0:
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
@@ -95,8 +83,7 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
else if (selected)
listItem->setValueColor(tsl::infoTextColor);
listItem->setClickListener([this, hz](u64 keys)
{
listItem->setClickListener([this, hz](u64 keys) {
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(hz)) {
tsl::goBack();
@@ -109,8 +96,7 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
return listItem;
}
void FreqChoiceGui::listUI()
{
void FreqChoiceGui::listUI() {
hocclkIpcGetConfigValues(this->configList);
// Header based on CPU/GPU/MEM module
@@ -118,11 +104,9 @@ void FreqChoiceGui::listUI()
this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName));
// Default option
this->listElement->addItem(
this->createFreqListItem(0, this->selectedHz == 0, 0));
this->listElement->addItem(this->createFreqListItem(0, this->selectedHz == 0, 0));
for (std::uint32_t i = 0; i < this->hzCount; i++)
{
for (std::uint32_t i = 0; i < this->hzCount; i++) {
std::uint32_t hz = this->hzList[i];
uint32_t mhz = hz / 1000000;
@@ -160,15 +144,12 @@ void FreqChoiceGui::listUI()
uint32_t danger_cpu;
uint32_t danger_gpu;
if (IsMariko())
{
if (IsMariko()) {
unsafe_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2398 : 1964;
unsafe_gpu = 1229;
danger_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2500 : 2398;
danger_gpu = 1306;
}
else
{
} else {
unsafe_cpu = this->configList->values[KipConfigValue_eristaCpuUV] ? 2092 : 1786;
if (this->configList->values[KipConfigValue_eristaGpuUV] == GPUUVLevel_NoUV) {
unsafe_gpu = 922;
@@ -202,16 +183,9 @@ void FreqChoiceGui::listUI()
} else if (moduleName == "mem") {
safety = 0;
}
this->listElement->addItem(
this->createFreqListItem(
hz,
(mhz == this->selectedHz / 1000000),
safety
)
);
this->listElement->addItem(this->createFreqListItem(hz, (mhz == this->selectedHz / 1000000), safety));
}
this->listElement->jumpToItem("", "");

View File

@@ -24,18 +24,17 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <list>
#include <functional>
#include <list>
#include <map>
#include "base_menu_gui.h"
using FreqChoiceListener = std::function<bool(std::uint32_t hz)>;
class FreqChoiceGui : public BaseMenuGui
{
class FreqChoiceGui : public BaseMenuGui {
protected:
HocClkConfigValueList *configList;
std::uint32_t selectedHz;
@@ -50,13 +49,8 @@ protected:
tsl::elm::ListItem *createFreqListItem(std::uint32_t hz, bool selected, int safety);
public:
FreqChoiceGui(std::uint32_t selectedHz,
std::uint32_t* hzList,
std::uint32_t hzCount,
HocClkModule module,
FreqChoiceListener listener,
bool checkMax = true,
std::map<uint32_t, std::string> labels = {});
FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, HocClkModule module, FreqChoiceListener listener,
bool checkMax = true, std::map<uint32_t, std::string> labels = {});
~FreqChoiceGui();

View File

@@ -25,13 +25,13 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <string>
#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
#include <string>
#include "value_choice_gui.h"
class GlobalOverrideGui : public BaseMenuGui
{
class GlobalOverrideGui : public BaseMenuGui {
protected:
std::map<HocClkModule, std::tuple<std::string, std::uint32_t, int>> customFormatModules;
tsl::elm::ListItem *listItems[HocClkModule_EnumMax];
@@ -40,34 +40,17 @@ class GlobalOverrideGui : public BaseMenuGui
void addGovernorSection();
void addModuleListItem(HocClkModule module);
void addModuleToggleItem(HocClkModule module);
void openValueChoiceGui(
tsl::elm::ListItem* listItem,
std::uint32_t currentValue,
const ValueRange& range,
const std::string& categoryName,
ValueChoiceListener listener,
const ValueThresholds& thresholds,
bool enableThresholds,
const std::map<std::uint32_t, std::string>& labels,
const std::vector<NamedValue>& namedValues,
bool showDefaultValue
);
void addModuleListItemValue(
HocClkModule module,
const std::string& categoryName,
std::uint32_t min,
std::uint32_t max,
std::uint32_t step,
const std::string& suffix,
std::uint32_t divisor,
int decimalPlaces,
ValueThresholds thresholds = {},
const std::vector<NamedValue>& namedValues = {},
bool showDefaultValue = true
);
void openValueChoiceGui(tsl::elm::ListItem *listItem, std::uint32_t currentValue, const ValueRange &range, const std::string &categoryName,
ValueChoiceListener listener, const ValueThresholds &thresholds, bool enableThresholds,
const std::map<std::uint32_t, std::string> &labels, const std::vector<NamedValue> &namedValues, bool showDefaultValue);
void addModuleListItemValue(HocClkModule module, const std::string &categoryName, std::uint32_t min, std::uint32_t max, std::uint32_t step,
const std::string &suffix, std::uint32_t divisor, int decimalPlaces, ValueThresholds thresholds = {},
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true);
public:
GlobalOverrideGui();
~GlobalOverrideGui() {}
~GlobalOverrideGui() {
}
void listUI() override;
void refresh() override;
void setModuleCustomFormat(HocClkModule module, const std::string &suffix, std::uint32_t divisor, int decimalPlaces);

View File

@@ -16,12 +16,13 @@
*
*/
#include "info_gui.h"
#include "ult_ext.h"
#include <sstream>
InfoGui::InfoGui(std::string title, std::vector<std::string> strings)
: m_title(std::move(title)), m_strings(std::move(strings)) {}
#include "info_gui.h"
#include "ult_ext.h"
InfoGui::InfoGui(std::string title, std::vector<std::string> strings) : m_title(std::move(title)), m_strings(std::move(strings)) {
}
static constexpr s32 TEXT_SIZE = 16;
static constexpr s32 LINE_H = 22;
@@ -29,15 +30,16 @@ static constexpr s32 PARA_GAP = 10;
static constexpr s32 MARGIN_L = 20;
static constexpr s32 MARGIN_R = 35;
static std::vector<std::string> wrapText(const std::string& text, s32 maxWidth)
{
static std::vector<std::string> wrapText(const std::string &text, s32 maxWidth) {
constexpr float CHAR_W = 10.0f;
// Preserve leading whitespace as an indent prefix for wrapped continuation lines.
std::string indent;
for (char c : text) {
if (c == ' ') indent += ' ';
else break;
if (c == ' ')
indent += ' ';
else
break;
}
std::vector<std::string> lines;
@@ -45,43 +47,39 @@ static std::vector<std::string> wrapText(const std::string& text, s32 maxWidth)
std::string word, line = indent; // seed with indent so first word inherits it
bool first = true;
while (ss >> word) {
std::string candidate = (first && !indent.empty()) ? indent + word
: line.empty() ? word
: line + " " + word;
std::string candidate = (first && !indent.empty()) ? indent + word : line.empty() ? word : line + " " + word;
first = false;
if (static_cast<s32>(candidate.size() * CHAR_W) <= maxWidth)
line = std::move(candidate);
else {
if (!line.empty() && line != indent) lines.push_back(line);
if (!line.empty() && line != indent)
lines.push_back(line);
line = indent + word;
}
}
if (!line.empty() && line != indent) lines.push_back(line);
if (lines.empty()) lines.emplace_back("");
if (!line.empty() && line != indent)
lines.push_back(line);
if (lines.empty())
lines.emplace_back("");
return lines;
}
void InfoGui::listUI()
{
void InfoGui::listUI() {
this->listElement->addItem(new tsl::elm::CategoryHeader(m_title));
const s32 maxWidth = tsl::cfg::FramebufferWidth - MARGIN_L - MARGIN_R;
for (const auto &para : m_strings) {
for (const auto &lineText : wrapText(para, maxWidth)) {
auto* d = new FocusableDrawer(
[lineText](tsl::gfx::Renderer* r, s32 x, s32 y, s32 w, s32 h) {
r->drawString((lineText + "\n").c_str(), false,
x + MARGIN_L, y + LINE_H - 5,
TEXT_SIZE, tsl::style::color::ColorText);
auto *d = new FocusableDrawer([lineText](tsl::gfx::Renderer *r, s32 x, s32 y, s32 w, s32 h) {
r->drawString((lineText + "\n").c_str(), false, x + MARGIN_L, y + LINE_H - 5, TEXT_SIZE, tsl::style::color::ColorText);
});
d->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, LINE_H);
this->listElement->addItem(d, LINE_H);
}
// paragraph gap
auto* gap = new tsl::elm::CustomDrawer(
[](tsl::gfx::Renderer*, s32, s32, s32, s32) {});
auto *gap = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *, s32, s32, s32, s32) {});
gap->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, PARA_GAP);
this->listElement->addItem(gap, PARA_GAP);
}

View File

@@ -16,12 +16,12 @@
*
*/
#pragma once
#include "base_menu_gui.h"
#include <string>
#include <vector>
class InfoGui : public BaseMenuGui
{
#include "base_menu_gui.h"
class InfoGui : public BaseMenuGui {
public:
InfoGui(std::string title, std::vector<std::string> strings);
~InfoGui() = default;

View File

@@ -15,136 +15,69 @@
*
*/
#include <map>
#include <cstdint>
#include <map>
#include <string>
std::map<uint32_t, std::string> cpu_freq_label_m = {
{612000000, "Sleep Mode"},
{1020000000, "Stock"},
{1224000000, "Dev OC"},
{1785000000, "Boost Mode"},
{1963000000, "Safe Max"},
{2397000000, "Unsafe Max"},
{2703000000, "Absolute Max"},
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
{ 1963000000, "Safe Max" }, { 2397000000, "Unsafe Max" }, { 2703000000, "Absolute Max" },
};
std::map<uint32_t, std::string> cpu_freq_label_m_uv = {
{612000000, "Sleep Mode"},
{1020000000, "Stock"},
{1224000000, "Dev OC"},
{1785000000, "Boost Mode"},
{2397000000, "Safe Max"},
{2499000000, "Unsafe Max"},
{2703000000, "Absolute Max"},
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
{ 2397000000, "Safe Max" }, { 2499000000, "Unsafe Max" }, { 2703000000, "Absolute Max" },
};
std::map<uint32_t, std::string> cpu_freq_label_e = {
{612000000, "Sleep Mode"},
{1020000000, "Stock"},
{1224000000, "Dev OC"},
{1785000000, "Safe Max"},
{2091000000, "Unsafe Max"},
{2397000000, "Absolute Max"},
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" },
{ 1785000000, "Safe Max" }, { 2091000000, "Unsafe Max" }, { 2397000000, "Absolute Max" },
};
std::map<uint32_t, std::string> cpu_freq_label_e_uv = {
{612000000, "Sleep Mode"},
{1020000000, "Stock"},
{1224000000, "Dev OC"},
{1785000000, "Boost Mode"},
{2091000000, "Safe Max"},
{2193000000, "Unsafe Max"},
{2397000000, "Absolute Max"},
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
{ 2091000000, "Safe Max" }, { 2193000000, "Unsafe Max" }, { 2397000000, "Absolute Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_e = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{345600000, "Handheld"},
{384000000, "Handheld"},
{422400000, "Handheld"},
{460800000, "Handheld Safe Max"},
{768000000, "Docked"},
{921600000, "Safe Max"},
{960000000, "Unsafe Max"},
{1075200000, "Absolute Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
{ 422400000, "Handheld" }, { 460800000, "Handheld Safe Max" }, { 768000000, "Docked" }, { 921600000, "Safe Max" },
{ 960000000, "Unsafe Max" }, { 1075200000, "Absolute Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_e_uv = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{345600000, "Handheld"},
{384000000, "Handheld"},
{422400000, "Handheld"},
{460800000, "Handheld Safe Max"},
{768000000, "Docked"},
{960000000, "Safe Max"},
{1075200000, "Absolute Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" },
{ 384000000, "Handheld" }, { 422400000, "Handheld" }, { 460800000, "Handheld Safe Max" },
{ 768000000, "Docked" }, { 960000000, "Safe Max" }, { 1075200000, "Absolute Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_m = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{345600000, "Handheld"},
{384000000, "Handheld"},
{422400000, "Handheld"},
{460800000, "Handheld"},
{614400000, "Handheld Safe Max"},
{768000000, "Docked"},
{998400000, "Safe Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" }, { 422400000, "Handheld" },
{ 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" }, { 998400000, "Safe Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_m_slt = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{345600000, "Handheld"},
{384000000, "Handheld"},
{422400000, "Handheld"},
{460800000, "Handheld"},
{614400000, "Handheld Safe Max"},
{768000000, "Docked"},
{1075200000, "Safe Max"},
{1305600000, "Unsafe Max"},
{1536000000, "Absolute Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
{ 422400000, "Handheld" }, { 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
{ 1075200000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_m_hiopt = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{345600000, "Handheld"},
{384000000, "Handheld"},
{422400000, "Handheld"},
{460800000, "Handheld"},
{614400000, "Handheld Safe Max"},
{768000000, "Docked"},
{1152000000, "Safe Max"},
{1305600000, "Unsafe Max"},
{1536000000, "Absolute Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
{ 422400000, "Handheld" }, { 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
{ 1152000000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
};
std::map<uint32_t, std::string> gpu_freq_label_m_highuv = {
{76800000, "Boost Mode"},
{307200000, "Handheld"},
{384000000, "Handheld"},
{460800000, "Handheld"},
{614400000, "Handheld Safe Max"},
{768000000, "Docked"},
{1228800000, "Safe Max"},
{1305600000, "Unsafe Max"},
{1536000000, "Absolute Max"},
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 384000000, "Handheld" },
{ 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
{ 1228800000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
};
std::map<uint32_t, std::string> *marikoUV[5]{
&gpu_freq_label_m,
&gpu_freq_label_m_slt,
&gpu_freq_label_m_hiopt,
&gpu_freq_label_m_hiopt,
&gpu_freq_label_m_highuv,
&gpu_freq_label_m, &gpu_freq_label_m_slt, &gpu_freq_label_m_hiopt, &gpu_freq_label_m_hiopt, &gpu_freq_label_m_highuv,
};
std::map<uint32_t, std::string> *eristaUV[3]{
&gpu_freq_label_e,
&gpu_freq_label_e_uv,

View File

@@ -24,16 +24,15 @@
* --------------------------------------------------------------------------
*/
#include "main_gui.h"
#include "fatal_gui.h"
#include "app_profile_gui.h"
#include "global_override_gui.h"
#include "misc_gui.h"
#include "about_gui.h"
#include "app_profile_gui.h"
#include "fatal_gui.h"
#include "global_override_gui.h"
#include "main_gui.h"
#include "misc_gui.h"
#include "ult_ext.h"
tsl::elm::Element *MainGui::baseUI() {
auto *list = new BoxClippedList();
this->listElement = list;
@@ -41,8 +40,7 @@ tsl::elm::Element* MainGui::baseUI() {
return list;
}
void MainGui::listUI()
{
void MainGui::listUI() {
// this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false);
// enabledToggle->setStateChangedListener([this](bool state) {
// Result rc = hocclkIpcSetEnabled(state);
@@ -58,8 +56,7 @@ void MainGui::listUI()
tsl::elm::ListItem *appProfileItem = new tsl::elm::ListItem("Edit App Profile");
appProfileItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
AppProfileGui::changeTo(this->context->applicationId);
return true;
}
@@ -68,11 +65,9 @@ void MainGui::listUI()
});
this->listElement->addItem(appProfileItem);
tsl::elm::ListItem *globalProfileItem = new tsl::elm::ListItem("Edit Global Profile");
globalProfileItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
AppProfileGui::changeTo(HOCCLK_GLOBAL_PROFILE_TID);
return true;
}
@@ -83,8 +78,7 @@ void MainGui::listUI()
tsl::elm::ListItem *globalOverrideItem = new tsl::elm::ListItem("Temporary Overrides");
globalOverrideItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
tsl::changeTo<GlobalOverrideGui>();
return true;
}
@@ -97,8 +91,7 @@ void MainGui::listUI()
tsl::elm::ListItem *miscItem = new tsl::elm::ListItem("Settings");
miscItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
tsl::changeTo<MiscGui>();
return true;
}
@@ -109,8 +102,7 @@ void MainGui::listUI()
tsl::elm::ListItem *aboutItem = new tsl::elm::ListItem("About");
aboutItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
tsl::changeTo<AboutGui>();
return true;
}
@@ -118,11 +110,9 @@ void MainGui::listUI()
return false;
});
this->listElement->addItem(aboutItem);
}
void MainGui::refresh()
{
void MainGui::refresh() {
BaseMenuGui::refresh();
// if(this->context)
//{

View File

@@ -24,18 +24,20 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include "base_menu_gui.h"
class MainGui : public BaseMenuGui
{
class MainGui : public BaseMenuGui {
public:
MainGui() {}
~MainGui() {}
MainGui() {
}
~MainGui() {
}
tsl::elm::Element *baseUI() override;
void listUI() override;
void refresh() override;
u16 headerHeight() const override { return HOC_HEADER_HEIGHT - 25; }
u16 headerHeight() const override {
return HOC_HEADER_HEIGHT - 25;
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -16,18 +16,18 @@
*
*/
#pragma once
#include "../../ipc.h"
#include "base_menu_gui.h"
#include <initializer_list>
#include <set>
#include <unordered_map>
#include <string>
#include <vector>
#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
#include "value_choice_gui.h"
#include "info_gui.h"
class MiscGui : public BaseMenuGui
{
#include "value_choice_gui.h"
#include <initializer_list>
#include <unordered_map>
class MiscGui : public BaseMenuGui {
public:
MiscGui();
~MiscGui();
@@ -47,33 +47,17 @@ protected:
void addConfigToggle(HocClkConfigValue configVal, const char *altName, bool kip = false);
void addConfigTrackbar(HocClkConfigValue configVal, const char *altName, const ValueRange &range, bool kip = true);
void addMappedConfigTrackbar(HocClkConfigValue configVal, const char* altName,
std::vector<u32> vals,
std::initializer_list<std::string> names, bool kip = true);
void addConfigButton(HocClkConfigValue configVal,
const char* altName,
const ValueRange& range,
const std::string& categoryName,
const ValueThresholds* thresholds,
const std::map<uint32_t, std::string>& labels = {},
const std::vector<NamedValue>& namedValues = {},
bool showDefaultValue = true,
bool kip = false);
void addMappedConfigTrackbar(HocClkConfigValue configVal, const char *altName, std::vector<u32> vals, std::initializer_list<std::string> names,
bool kip = true);
void addConfigButton(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, bool kip = false);
void addConfigButtonS(HocClkConfigValue configVal,
const char* altName,
const ValueRange& range,
const std::string& categoryName,
const ValueThresholds* thresholds,
const std::map<uint32_t, std::string>& labels = {},
const std::vector<NamedValue>& namedValues = {},
bool showDefaultValue = true,
const char* subText = nullptr,
void addConfigButtonS(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, const char *subText = nullptr,
bool kip = false);
void addFreqButton(HocClkConfigValue configVal,
const char* altName,
HocClkModule module,
const std::map<uint32_t, std::string>& labels = {});
void addFreqButton(HocClkConfigValue configVal, const char *altName, HocClkModule module, const std::map<uint32_t, std::string> &labels = {});
void updateConfigToggles();
tsl::elm::ToggleListItem *enabledToggle;

View File

@@ -17,11 +17,15 @@
#pragma once
#include <tesla.hpp>
#include "../elements/base_frame.h"
class TopAnchoredList : public tsl::elm::List {
public:
TopAnchoredList() { m_hasSetInitialFocusHack = true; }
TopAnchoredList() {
m_hasSetInitialFocusHack = true;
}
};
class BoxClippedList : public tsl::elm::List {
public:
@@ -34,7 +38,8 @@ public:
class CompactCategoryHeader : public tsl::elm::CategoryHeader {
public:
CompactCategoryHeader(const std::string& text) : tsl::elm::CategoryHeader(text) {}
CompactCategoryHeader(const std::string &text) : tsl::elm::CategoryHeader(text) {
}
void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
this->setBoundaries(this->getX(), this->getY(), this->getWidth(), 33);
}
@@ -47,25 +52,20 @@ private:
bool visible;
public:
ImageElement(const uint8_t* data, uint32_t w, uint32_t h)
: tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {}
ImageElement(const uint8_t *data, uint32_t w, uint32_t h) : tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {
}
void setVisible(bool v) {
visible = v;
}
virtual void draw(tsl::gfx::Renderer *renderer) override {
if (!visible) return;
if (!visible)
return;
// Draw image centered horizontally
u16 centerX = this->getX() + (this->getWidth() - imgWidth) / 2;
renderer->drawBitmap(
centerX,
this->getY() + 10,
imgWidth,
imgHeight,
imgData
);
renderer->drawBitmap(centerX, this->getY() + 10, imgWidth, imgHeight, imgData);
}
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
@@ -96,15 +96,16 @@ private:
bool visible;
public:
HideableCategoryHeader(const std::string& title)
: tsl::elm::CategoryHeader(title), visible(true) {}
HideableCategoryHeader(const std::string &title) : tsl::elm::CategoryHeader(title), visible(true) {
}
void setVisible(bool v) {
visible = v;
}
virtual void draw(tsl::gfx::Renderer *renderer) override {
if (!visible) return;
if (!visible)
return;
tsl::elm::CategoryHeader::draw(renderer);
}
@@ -119,14 +120,14 @@ public:
class FocusableDrawer : public tsl::elm::CustomDrawer {
public:
template<typename... Args>
FocusableDrawer(Args&&... args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
template <typename... Args> FocusableDrawer(Args &&...args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
m_isItem = true;
}
Element *requestFocus(Element *, tsl::FocusDirection) override {
return this;
}
void drawHighlight(tsl::gfx::Renderer*) override {}
void drawHighlight(tsl::gfx::Renderer *) override {
}
};
class HideableCustomDrawer : public tsl::elm::Element {
@@ -135,8 +136,8 @@ private:
u32 height;
public:
HideableCustomDrawer(u32 h)
: Element(), visible(true), height(h) {}
HideableCustomDrawer(u32 h) : Element(), visible(true), height(h) {
}
void setVisible(bool v) {
visible = v;

View File

@@ -16,42 +16,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ult_ext.h"
#include "value_choice_gui.h"
#include <iomanip>
#include <sstream>
#include "../format.h"
#include "fatal_gui.h"
#include <sstream>
#include <iomanip>
#include "ult_ext.h"
#include "value_choice_gui.h"
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue,
const ValueRange& range,
const std::string& categoryName,
ValueChoiceListener listener,
const ValueThresholds& thresholds,
bool enableThresholds,
std::map<std::uint32_t, std::string> labels,
std::vector<NamedValue> namedValues,
bool showDefaultValue,
bool showDNO)
: selectedValue(selectedValue),
range(range),
categoryName(categoryName),
listener(listener),
thresholds(thresholds),
enableThresholds(enableThresholds),
labels(labels),
namedValues(namedValues),
showDefaultValue(showDefaultValue),
showDNO(showDNO)
{
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
const ValueThresholds &thresholds, bool enableThresholds, std::map<std::uint32_t, std::string> labels,
std::vector<NamedValue> namedValues, bool showDefaultValue, bool showDNO)
: selectedValue(selectedValue), range(range), categoryName(categoryName), listener(listener), thresholds(thresholds),
enableThresholds(enableThresholds), labels(labels), namedValues(namedValues), showDefaultValue(showDefaultValue), showDNO(showDNO) {
}
ValueChoiceGui::~ValueChoiceGui()
{
ValueChoiceGui::~ValueChoiceGui() {
}
std::string ValueChoiceGui::formatValue(std::uint32_t value)
{
std::string ValueChoiceGui::formatValue(std::uint32_t value) {
std::ostringstream oss;
if (showDefaultValue) {
if (value == 0) {
@@ -66,8 +49,7 @@ std::string ValueChoiceGui::formatValue(std::uint32_t value)
return oss.str();
}
int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
{
int ValueChoiceGui::getSafetyLevel(std::uint32_t value) {
if (thresholds.warning == 0 && thresholds.danger == 0) {
return 0;
}
@@ -81,8 +63,7 @@ int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
return 0;
}
tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety)
{
tsl::elm::ListItem *ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety) {
std::string text = formatValue(value);
std::string rightText = "";
@@ -96,8 +77,7 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
}
tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, rightText, false);
switch (safety)
{
switch (safety) {
case 0:
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
@@ -118,8 +98,7 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
else if (selected)
listItem->setValueColor(tsl::infoTextColor);
listItem->setClickListener([this, value](u64 keys)
{
listItem->setClickListener([this, value](u64 keys) {
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(value)) {
tsl::goBack();
@@ -131,16 +110,14 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
return listItem;
}
tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& namedValue, bool selected, int safety)
{
tsl::elm::ListItem *ValueChoiceGui::createNamedValueListItem(const NamedValue &namedValue, bool selected, int safety) {
std::string text = namedValue.name;
if (selected) {
const_cast<std::string &>(namedValue.rightText) = "\uE14B";
}
tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, namedValue.rightText, false);
switch (safety)
{
switch (safety) {
case 0:
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
@@ -160,8 +137,7 @@ tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& n
else if (selected)
listItem->setValueColor(tsl::infoTextColor);
listItem->setClickListener([this, value = namedValue.value](u64 keys)
{
listItem->setClickListener([this, value = namedValue.value](u64 keys) {
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(value)) {
tsl::goBack();
@@ -173,8 +149,7 @@ tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& n
return listItem;
}
void ValueChoiceGui::listUI()
{
void ValueChoiceGui::listUI() {
if (!categoryName.empty()) {
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
}
@@ -189,8 +164,7 @@ void ValueChoiceGui::listUI()
}
if (namedValues.empty()) {
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
{
for (std::uint32_t value = range.min; value <= range.max; value += range.step) {
int safety = getSafetyLevel(value);
bool selected = (value == this->selectedValue);
this->listElement->addItem(this->createValueListItem(value, selected, safety));

View File

@@ -17,11 +17,12 @@
*
*/
#pragma once
#include <list>
#include <functional>
#include <string>
#include <list>
#include <map>
#include <string>
#include <vector>
#include "base_menu_gui.h"
using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
@@ -34,19 +35,19 @@ struct ValueRange {
std::string suffix;
std::uint32_t divisor;
int decimalPlaces;
ValueRange()
: min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {}
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step,
const std::string& suffix = "", std::uint32_t divisor = 1, int decimalPlaces = 0)
: min(min), max(max), step(step), suffix(suffix),
divisor(divisor), decimalPlaces(decimalPlaces) {}
ValueRange() : min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {
}
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step, const std::string &suffix = "", std::uint32_t divisor = 1,
int decimalPlaces = 0)
: min(min), max(max), step(step), suffix(suffix), divisor(divisor), decimalPlaces(decimalPlaces) {
}
};
struct ValueThresholds {
std::uint32_t warning;
std::uint32_t danger;
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0)
: warning(warning), danger(danger) {}
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0) : warning(warning), danger(danger) {
}
};
struct NamedValue {
@@ -54,12 +55,11 @@ struct NamedValue {
std::uint32_t value;
std::string rightText;
NamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
: name(name), value(value), rightText(rightText) {}
NamedValue(const std::string &name, std::uint32_t value, const std::string &rightText = "") : name(name), value(value), rightText(rightText) {
}
};
class ValueChoiceGui : public BaseMenuGui
{
class ValueChoiceGui : public BaseMenuGui {
protected:
std::uint32_t selectedValue;
ValueRange range;
@@ -78,35 +78,25 @@ protected:
int getSafetyLevel(std::uint32_t value);
public:
ValueChoiceGui(std::uint32_t selectedValue,
const ValueRange& range,
const std::string& categoryName,
ValueChoiceListener listener,
const ValueThresholds& thresholds = ValueThresholds(),
bool enableThresholds = false,
std::map<std::uint32_t, std::string> labels = {},
std::vector<NamedValue> namedValues = {},
bool showDefaultValue = true,
ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
const ValueThresholds &thresholds = ValueThresholds(), bool enableThresholds = false,
std::map<std::uint32_t, std::string> labels = {}, std::vector<NamedValue> namedValues = {}, bool showDefaultValue = true,
bool showDNO = false);
~ValueChoiceGui();
void addNamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
{
void addNamedValue(const std::string &name, std::uint32_t value, const std::string &rightText = "") {
namedValues.emplace_back(name, value, rightText);
}
void addNamedValues(const std::vector<NamedValue>& values)
{
void addNamedValues(const std::vector<NamedValue> &values) {
namedValues.insert(namedValues.end(), values.begin(), values.end());
}
void clearNamedValues()
{
void clearNamedValues() {
namedValues.clear();
}
void setShowDefaultValue(bool show)
{
void setShowDefaultValue(bool show) {
showDefaultValue = show;
}

View File

@@ -24,7 +24,6 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <tesla.hpp>

View File

@@ -24,31 +24,32 @@
* --------------------------------------------------------------------------
*/
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <battery.h>
#include <hocclk.h>
#include <switch.h>
#include <i2c.h>
#include <max17050.h>
#include <notification.h>
#include <pwm.h>
#include <registers.h>
#include <battery.h>
#include "../display/display_refresh_rate.hpp"
#include <notification.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../display/display_refresh_rate.hpp"
#include "../file/file_utils.hpp"
#include "../hos/apm_ext.h"
#include "../hos/integrations.hpp"
#include "../hos/rgltr.h"
#include "../tsensor/aotag.hpp"
#include "../tsensor/soctherm.hpp"
#include "board.hpp"
#include "board_fuse.hpp"
#include "board_load.hpp"
#include "board_volt.hpp"
#include "board_misc.hpp"
#include "../tsensor/soctherm.hpp"
#include "../tsensor/aotag.hpp"
#include "../hos/integrations.hpp"
#include "../file/file_utils.hpp"
#include "../hos/rgltr.h"
#include "board_volt.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
namespace board {
u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr;
@@ -189,7 +190,10 @@ namespace board {
StartMiscThread(pwmCheck, &iCon);
display::DisplayRefreshConfig cfg = {.clkVirtAddr = clkVirtAddr, .dsiVirtAddr = dsiVirtAddr, .isLite = (GetConsoleType() == HocClkConsoleType_Hoag), .isRetroSUPER = integrations::GetRETROSuperStatus()};
display::DisplayRefreshConfig cfg = { .clkVirtAddr = clkVirtAddr,
.dsiVirtAddr = dsiVirtAddr,
.isLite = (GetConsoleType() == HocClkConsoleType_Hoag),
.isRetroSUPER = integrations::GetRETROSuperStatus() };
display::Initialize(&cfg);
CacheDfllData();
@@ -270,4 +274,4 @@ namespace board {
return false; /* stub for now. */
}
}
} // namespace board

View File

@@ -26,16 +26,18 @@
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
#include "../mapping/mem_map.hpp"
#include "board_freq.hpp"
#include "board_fuse.hpp"
#include "board_load.hpp"
#include "board_name.hpp"
#include "board_freq.hpp"
#include "board_profile.hpp"
#include "board_sensor.hpp"
#include "board_volt.hpp"
#include "board_profile.hpp"
#include "../mapping/mem_map.hpp"
#define HOSSVC_HAS_CLKRST (hosversionAtLeast(8, 0, 0))
#define HOSSVC_HAS_TC (hosversionAtLeast(5, 0, 0))
@@ -58,4 +60,4 @@ namespace board {
FuseData *GetFuseData();
bool IsUsingRetroSuperDisplay();
}
} // namespace board

View File

@@ -24,24 +24,25 @@
* --------------------------------------------------------------------------
*/
#include <switch.h>
#include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include "../i2c/i2cDrv.h"
#include <t210.h>
#include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include "../display/display_refresh_rate.hpp"
#include "../file/config.hpp"
#include "../file/errors.hpp"
#include "../hos/apm_ext.h"
#include "../i2c/i2cDrv.h"
#include "../soc/gm20b.hpp"
#include "../soc/pllmb.hpp"
#include "board.hpp"
#include "board_name.hpp"
#include "../file/errors.hpp"
#include "../soc/pllmb.hpp"
#include "../file/config.hpp"
#include "../soc/gm20b.hpp"
#include "../file/config.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
namespace board {
static u32 currentInjectedHz = 0;
static u32 gMarikoGm20bCutoff = 1228800000;
@@ -80,12 +81,12 @@ namespace board {
ASSERT_RESULT_OK(pcvSetClockRate(moduleID, hz), "pcvSetClockRate");
}
void HandleCpuUv()
{
void HandleCpuUv() {
if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); // Erista tbreak is always 1581MHz
else
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
}
void SetHz(HocClkModule module, u32 hz) {
@@ -101,7 +102,8 @@ namespace board {
return;
}
bool useGm20b = (module == HocClkModule_GPU) && (GetSocType() == HocClkSocType_Mariko) && (hz % 38400000 == 0) && (hz % 76800000 != 0) && hz < gMarikoGm20bCutoff;
bool useGm20b = (module == HocClkModule_GPU) && (GetSocType() == HocClkSocType_Mariko) && (hz % 38400000 == 0) && (hz % 76800000 != 0) &&
hz < gMarikoGm20bCutoff;
u32 pcvHz = useGm20b ? ((hz + 76800000 - 1) / 76800000) * 76800000 : hz;
@@ -181,7 +183,9 @@ namespace board {
case HocClkModule_GPU:
return t210ClkGpuFreq();
case HocClkModule_MEM:
return config::GetConfigValue(HocClkConfigValue_MemoryFrequencyMeasurementMode) == MemoryFrequencyMeasurementMode_PLL ? pllmb::getRamClockRatePLLMB() : t210ClkMemFreq();
return config::GetConfigValue(HocClkConfigValue_MemoryFrequencyMeasurementMode) == MemoryFrequencyMeasurementMode_PLL
? pllmb::getRamClockRatePLLMB()
: t210ClkMemFreq();
case HocClkModule_Display:
return GetDisplayRate(hz);
default:
@@ -197,7 +201,6 @@ namespace board {
s32 tmpInMaxCount = maxCount;
s32 tmpOutCount = 0;
if (HOSSVC_HAS_CLKRST) {
ClkrstSession session = {};
@@ -263,4 +266,4 @@ namespace board {
void ResetToStockDisplay() {
display::SetRate(60);
}
}
} // namespace board

View File

@@ -25,16 +25,18 @@
*/
#pragma once
#include <switch.h>
#include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../file/errors.hpp"
#include "../hos/apm_ext.h"
#include <ipc_server.h>
#include <lockable_mutex.h>
#include "../file/errors.hpp"
namespace board {
@@ -50,8 +52,7 @@ namespace board {
void ResetToStock();
void ResetToStockDisplay();
template <typename Getter>
void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
template <typename Getter> void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
Result rc = 0;
if (hosversionAtLeast(9, 0, 0)) {
@@ -95,4 +96,4 @@ namespace board {
ResetToStockModule([](const HocClkApmConfiguration &cfg) { return cfg.mem_hz; }, HocClkModule_MEM);
}
}
} // namespace board

View File

@@ -15,11 +15,13 @@
*
*/
#include <switch.h>
#include <fuse.h>
#include "board_fuse.hpp"
#include <cstring>
#include <fuse.h>
#include <switch.h>
#include "board.hpp"
#include "board_fuse.hpp"
namespace board {
@@ -78,4 +80,4 @@ namespace board {
speedo.waferX = (speedo.waferX & BIT(8)) ? (speedo.waferX - 512) : speedo.waferX;
}
}
} // namespace board

View File

@@ -37,4 +37,4 @@ namespace board {
void ReadFuses(FuseData &speedo, u64 fuseVa);
void SetGpuBracket(u16 gpuSpeedo, u8 &gpuBracket);
}
} // namespace board

View File

@@ -24,22 +24,24 @@
* --------------------------------------------------------------------------
*/
#include <switch.h>
#include <algorithm>
#include <battery.h>
#include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <math.h>
#include <max17050.h>
#include <minIni.h>
#include <numeric>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../hos/apm_ext.h"
#include "board.hpp"
#include "board_misc.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <minIni.h>
#include <battery.h>
#include "board_misc.hpp"
#include "board.hpp"
namespace board {
@@ -65,7 +67,8 @@ namespace board {
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
uint32_t gpu_load_array[gpu_samples_average] = { 0 };
size_t i = 0;
if (R_SUCCEEDED(nvCheck_load)) do {
if (R_SUCCEEDED(nvCheck_load))
do {
u32 temp;
if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) {
gpu_load_array[i++ % gpu_samples_average] = temp;
@@ -150,7 +153,7 @@ namespace board {
namespace {
constexpr u32 NVschedCtrlEnable = 0x00000601;
constexpr u32 NVschedCtrlDisable = 0x00000602;
}
} // namespace
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method) {
if (R_FAILED(nvCheckSched) && method == GpuSchedulingOverrideMethod_NvService) {
@@ -160,7 +163,8 @@ namespace board {
u32 temp;
bool enabled = false;
switch (mode) {
case GpuSchedulingMode_DoNotOverride: break;
case GpuSchedulingMode_DoNotOverride:
break;
case GpuSchedulingMode_Disabled:
if (method == GpuSchedulingOverrideMethod_NvService) {
nvIoctl(_fd2, NVschedCtrlDisable, &temp);
@@ -198,4 +202,4 @@ namespace board {
nvCheckSched = nvSched;
}
}
} // namespace board

View File

@@ -25,8 +25,9 @@
*/
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
namespace board {
@@ -37,4 +38,4 @@ namespace board {
void SchedSetFD2(u32 fd2);
void NvSchedSucceed(Result nvSched);
}
} // namespace board

View File

@@ -24,9 +24,9 @@
* --------------------------------------------------------------------------
*/
#include <switch.h>
#include <pwm.h>
#include <cmath>
#include <pwm.h>
#include <switch.h>
namespace board {
@@ -68,4 +68,4 @@ namespace board {
threadClose(&miscThread);
}
}
} // namespace board

View File

@@ -26,9 +26,9 @@
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <pwm.h>
#include <switch.h>
namespace board {
@@ -36,4 +36,4 @@ namespace board {
void ExitMiscThread();
u8 GetFanLevel();
}
} // namespace board

View File

@@ -24,8 +24,9 @@
* --------------------------------------------------------------------------
*/
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
#include "board.hpp"
namespace board {
@@ -50,4 +51,4 @@ namespace board {
return hocclkFormatPowerSensor(sensor, pretty);
}
}
} // namespace board

View File

@@ -25,8 +25,8 @@
*/
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
namespace board {
@@ -35,4 +35,4 @@ namespace board {
const char *GetThermalSensorName(HocClkThermalSensor sensor, bool pretty);
const char *GetPowerSensorName(HocClkPowerSensor sensor, bool pretty);
}
} // namespace board

View File

@@ -24,16 +24,17 @@
* --------------------------------------------------------------------------
*/
#include <switch.h>
#include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../hos/apm_ext.h"
#include "board.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
#include "board.hpp"
namespace board {
@@ -60,4 +61,4 @@ namespace board {
return HocClkProfile_Handheld;
}
}
} // namespace board

View File

@@ -28,7 +28,5 @@
#include <hocclk.h>
namespace board {
HocClkProfile GetProfile();
}

View File

@@ -24,24 +24,26 @@
* --------------------------------------------------------------------------
*/
#include <hocclk.h>
#include <switch.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include "../i2c/i2cDrv.h"
#include <t210.h>
#include <max17050.h>
#include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <cmath>
#include <battery.h>
#include <cmath>
#include <hocclk.h>
#include <i2c.h>
#include <max17050.h>
#include <pwm.h>
#include "board.hpp"
#include "../tsensor/soctherm.hpp"
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../file/config.hpp"
#include "../hos/apm_ext.h"
#include "../i2c/i2cDrv.h"
#include "../tsensor/aotag.hpp"
#include "../tsensor/bq24193.hpp"
#include "../file/config.hpp"
#include "../tsensor/soctherm.hpp"
#include "board.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
namespace board {
@@ -127,4 +129,4 @@ namespace board {
return 0;
}
}
} // namespace board

View File

@@ -33,4 +33,4 @@ namespace board {
s32 GetTemperatureMilli(HocClkThermalSensor sensor);
s32 GetPowerMw(HocClkPowerSensor sensor);
}
} // namespace board

View File

@@ -17,18 +17,20 @@
*
*/
#include <switch.h>
#include <battery.h>
#include <cstring>
#include <hocclk.h>
#include <memmem.h>
#include <registers.h>
#include <cstring>
#include <battery.h>
#include <switch.h>
#include "../file/file_utils.hpp"
#include "../hos/rgltr.h"
#include "../i2c/i2cDrv.h"
#include "board.hpp"
#include "board_freq.hpp"
#include "board_volt.hpp"
#include "../file/file_utils.hpp"
#include "../i2c/i2cDrv.h"
#include "../hos/rgltr.h"
namespace board {
GpuVoltData voltData = {};
@@ -50,54 +52,30 @@ namespace board {
u32 tune1_high;
};
EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = { // <2118 CPU speedo
{0xFFEAD0FF, 0x25501d0},
{0xffff, 0x27007ff},
{0xefff, 0x27407ff},
{0xdfff, 0x27807ff},
{0xdfdf, 0x27a07ff},
{0xcfdf, 0x37007ff},
EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = {
// <2118 CPU speedo
{ 0xFFEAD0FF, 0x25501d0 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
{ 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
};
EristaCpuUvEntry eristaCpuUvTableHighBracket[6] = {
{0xFFEAD0FF, 0x20091d9},
{0xffff, 0x27007ff},
{0xefff, 0x27407ff},
{0xdfff, 0x27807ff},
{0xdfdf, 0x27a07ff},
{0xcfdf, 0x37007ff},
{ 0xFFEAD0FF, 0x20091d9 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
{ 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
};
MarikoCpuUvEntry marikoCpuUvLow[12] = {
{0xffa0, 0xffff, 0x21107ff, 0},
{0x0, 0xffdf, 0x21107ff, 0x27207ff},
{0xffdf, 0xffdf, 0x21107ff, 0x27307ff},
{0xffff, 0xffdf, 0x21107ff, 0x27407ff},
{0x0, 0xffdf, 0x21607ff, 0x27707ff},
{0x0, 0xffdf, 0x21607ff, 0x27807ff},
{0x0, 0xdfff, 0x21607ff, 0x27b07ff},
{0xdfff, 0xdfff, 0x21707ff, 0x27b07ff},
{0xdfff, 0xdfff, 0x21707ff, 0x27c07ff},
{0xdfff, 0xdfff, 0x21707ff, 0x27d07ff},
{0xdfff, 0xdfff, 0x21707ff, 0x27e07ff},
{0xdfff, 0xdfff, 0x21707ff, 0x27f07ff},
{ 0xffa0, 0xffff, 0x21107ff, 0 }, { 0x0, 0xffdf, 0x21107ff, 0x27207ff }, { 0xffdf, 0xffdf, 0x21107ff, 0x27307ff },
{ 0xffff, 0xffdf, 0x21107ff, 0x27407ff }, { 0x0, 0xffdf, 0x21607ff, 0x27707ff }, { 0x0, 0xffdf, 0x21607ff, 0x27807ff },
{ 0x0, 0xdfff, 0x21607ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27c07ff },
{ 0xdfff, 0xdfff, 0x21707ff, 0x27d07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27e07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27f07ff },
};
MarikoCpuUvEntry marikoCpuUvHigh[12] = {
{0x0, 0xffff, 0, 0},
{0x0, 0xffdf, 0, 0x27207ff},
{0x0, 0xffdf, 0, 0x27307ff},
{0x0, 0xffdf, 0, 0x27407ff},
{0x0, 0xffdf, 0, 0x27707ff},
{0x0, 0xffdf, 0, 0x27807ff},
{0x0, 0xdfff, 0, 0x27b07ff},
{0x0, 0xdfff, 0, 0x27c07ff},
{0x0, 0xdfff, 0, 0x27d07ff},
{0x0, 0xdfff, 0, 0x27e07ff},
{0x0, 0xdfff, 0, 0x27f07ff},
{0x0, 0xdfff, 0, 0x27f07ff},
{ 0x0, 0xffff, 0, 0 }, { 0x0, 0xffdf, 0, 0x27207ff }, { 0x0, 0xffdf, 0, 0x27307ff }, { 0x0, 0xffdf, 0, 0x27407ff },
{ 0x0, 0xffdf, 0, 0x27707ff }, { 0x0, 0xffdf, 0, 0x27807ff }, { 0x0, 0xdfff, 0, 0x27b07ff }, { 0x0, 0xdfff, 0, 0x27c07ff },
{ 0x0, 0xdfff, 0, 0x27d07ff }, { 0x0, 0xdfff, 0, 0x27e07ff }, { 0x0, 0xdfff, 0, 0x27f07ff }, { 0x0, 0xdfff, 0, 0x27f07ff },
};
}
} // namespace
void CacheDfllData() {
Result rc = QueryMemoryMapping(&cldvfs, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE);
@@ -422,33 +400,48 @@ namespace board {
u32 baseVolt = 800;
if (GetSocType() == HocClkSocType_Mariko) {
static const u32 ramTable[][22] = {
{ 2133, 2200, 2266, 2300, 2366, 2400, 2433, 2466, 2533, 2566, 2600, 2633, 2700, 2733, 2766, 2833, 2866, 2900, 2933, 3033, 3066, 3100, }, // Bracket 0
{ 2300, 2366, 2433, 2466, 2533, 2566, 2633, 2700, 2733, 2800, 2833, 2900, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3266, }, // Bracket 1
{ 2433, 2466, 2533, 2566, 2600, 2666, 2766, 2800, 2833, 2866, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3300, 3333, 3366, }, // Bracket 2
{ 2500, 2533, 2600, 2633, 2666, 2733, 2800, 2866, 2900, 2966, 3033, 3100, 3166, 3200, 3233, 3266, 3300, 3333, 3366, 3400, 3400, 3400, }, // Bracket 3
{
2133, 2200, 2266, 2300, 2366, 2400, 2433, 2466, 2533, 2566, 2600,
2633, 2700, 2733, 2766, 2833, 2866, 2900, 2933, 3033, 3066, 3100,
}, // Bracket 0
{
2300, 2366, 2433, 2466, 2533, 2566, 2633, 2700, 2733, 2800, 2833,
2900, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3266,
}, // Bracket 1
{
2433, 2466, 2533, 2566, 2600, 2666, 2766, 2800, 2833, 2866, 2933,
2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3300, 3333, 3366,
}, // Bracket 2
{
2500, 2533, 2600, 2633, 2666, 2733, 2800, 2866, 2900, 2966, 3033,
3100, 3166, 3200, 3233, 3266, 3300, 3333, 3366, 3400, 3400, 3400,
}, // Bracket 3
};
static const u32 gpuVoltArray[] = { 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, };
static const u32 gpuVoltArray[] = {
590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800,
};
if (freqMhz <= 1600) return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
if (bracket >= std::size(ramTable)) bracket = 0;
if (freqMhz <= 1600)
return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
if (bracket >= std::size(ramTable))
bracket = 0;
u32 bracketStart = ramTable[bracket][0];
u32 rampStartVolt = (bracket == 0) ? 535 : 525; // Do not touch!
u32 rampSpan = 590 - rampStartVolt;
if (freqMhz >= 1633 && freqMhz < bracketStart) {
u32 raw = rampStartVolt + ((freqMhz - 1633) * rampSpan) / (bracketStart - 1633);
u32 volt = ((raw + 2) / 5) * 5;
if (volt < rampStartVolt) volt = rampStartVolt;
if (volt > 590) volt = 590;
if (volt < rampStartVolt)
volt = rampStartVolt;
if (volt > 590)
volt = 590;
return volt;
}
baseVolt = gpuVoltArray[std::size(gpuVoltArray) - 1];
for (u32 i = 0; i < std::size(gpuVoltArray); ++i) {
if (freqMhz <= ramTable[bracket][i]) {
@@ -457,16 +450,93 @@ namespace board {
}
}
} else {
struct DvfsEntry { u32 freq; u32 volt; };
struct DvfsEntry {
u32 freq;
u32 volt;
};
static const DvfsEntry ramTable[][19] = {
{ {1733,725}, {1800,730}, {1866,735}, {1920,740}, {1958,745}, {1996,750}, {2035,755}, {2073,760}, {2112,765}, {2131,770}, {2150,775}, {2169,780}, {2188,785}, {2227,790}, {2265,795}, {2304,800}, {2342,805}, {2380,810}, {2400,815} }, // Bracket 0
{ {1733,715}, {1800,720}, {1866,725}, {1920,730}, {1958,735}, {1996,740}, {2035,745}, {2073,750}, {2112,755}, {2131,760}, {2150,765}, {2169,770}, {2188,775}, {2227,780}, {2265,785}, {2304,790}, {2342,795}, {2380,800}, {2400,805} }, // Bracket 1
{ {1733,705}, {1800,710}, {1866,715}, {1920,720}, {1958,725}, {1996,730}, {2035,735}, {2073,740}, {2112,745}, {2131,750}, {2150,755}, {2169,760}, {2188,765}, {2227,770}, {2265,775}, {2304,780}, {2342,785}, {2380,790}, {2400,795} }, // Bracket 2
{ {1733,695}, {1800,700}, {1866,705}, {1920,710}, {1958,715}, {1996,720}, {2035,725}, {2073,730}, {2112,735}, {2131,740}, {2150,745}, {2169,750}, {2188,755}, {2227,760}, {2265,765}, {2304,770}, {2342,775}, {2380,780}, {2400,785} }, // Bracket 3
{ { 1733, 725 },
{ 1800, 730 },
{ 1866, 735 },
{ 1920, 740 },
{ 1958, 745 },
{ 1996, 750 },
{ 2035, 755 },
{ 2073, 760 },
{ 2112, 765 },
{ 2131, 770 },
{ 2150, 775 },
{ 2169, 780 },
{ 2188, 785 },
{ 2227, 790 },
{ 2265, 795 },
{ 2304, 800 },
{ 2342, 805 },
{ 2380, 810 },
{ 2400, 815 } }, // Bracket 0
{ { 1733, 715 },
{ 1800, 720 },
{ 1866, 725 },
{ 1920, 730 },
{ 1958, 735 },
{ 1996, 740 },
{ 2035, 745 },
{ 2073, 750 },
{ 2112, 755 },
{ 2131, 760 },
{ 2150, 765 },
{ 2169, 770 },
{ 2188, 775 },
{ 2227, 780 },
{ 2265, 785 },
{ 2304, 790 },
{ 2342, 795 },
{ 2380, 800 },
{ 2400, 805 } }, // Bracket 1
{ { 1733, 705 },
{ 1800, 710 },
{ 1866, 715 },
{ 1920, 720 },
{ 1958, 725 },
{ 1996, 730 },
{ 2035, 735 },
{ 2073, 740 },
{ 2112, 745 },
{ 2131, 750 },
{ 2150, 755 },
{ 2169, 760 },
{ 2188, 765 },
{ 2227, 770 },
{ 2265, 775 },
{ 2304, 780 },
{ 2342, 785 },
{ 2380, 790 },
{ 2400, 795 } }, // Bracket 2
{ { 1733, 695 },
{ 1800, 700 },
{ 1866, 705 },
{ 1920, 710 },
{ 1958, 715 },
{ 1996, 720 },
{ 2035, 725 },
{ 2073, 730 },
{ 2112, 735 },
{ 2131, 740 },
{ 2150, 745 },
{ 2169, 750 },
{ 2188, 755 },
{ 2227, 760 },
{ 2265, 765 },
{ 2304, 770 },
{ 2342, 775 },
{ 2380, 780 },
{ 2400, 785 } }, // Bracket 3
};
if (freqMhz <= 1600) return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
if (bracket >= std::size(ramTable)) bracket = 0;
if (freqMhz <= 1600)
return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
if (bracket >= std::size(ramTable))
bracket = 0;
const auto &entries = ramTable[bracket];
baseVolt = entries[std::size(entries) - 1].volt;
@@ -480,4 +550,4 @@ namespace board {
return baseVolt;
}
}
} // namespace board

View File

@@ -16,8 +16,9 @@
*/
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
namespace board {
@@ -50,4 +51,4 @@ namespace board {
void PcvHijackGpuVolts(u32 vmin);
u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket);
}
} // namespace board

View File

@@ -40,9 +40,7 @@ namespace AulaDisplay {
if (mode == AulaDisplayColorMode_DoNotOverride)
return;
// send display command to change color mode.
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM,
MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM, MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
}
}
} // namespace AulaDisplay

View File

@@ -15,7 +15,7 @@
*
*/
#pragma once
#include "../board/board.hpp"
namespace AulaDisplay {

View File

@@ -184,7 +184,6 @@
#define DSI_ENABLE BIT(29)
#define HDMI_ENABLE BIT(30)
#define DC_DISP_DISP_MEM_HIGH_PRIORITY 0x403
#define DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER 0x404

View File

@@ -15,12 +15,13 @@
*
*/
#include "display_refresh_rate.hpp"
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include <string.h>
#include <switch.h>
#include "display_refresh_rate.hpp"
namespace display {
#define DSI_CLOCK_HZ 234000000llu
#define NVDISP_GET_MODE2 0x803C021B
@@ -41,7 +42,8 @@ namespace display {
static bool g_canChangeRefreshRateDocked = false;
static uint8_t g_lastVActiveSet = 0;
static const uint8_t g_dockedRefreshRates[] = {40, 45, 50, 55, 60, 70, 72, 75, 80, 90, 95, 100, 110, 120, 130, 140, 144, 150, 160, 165, 170, 180, 190, 200, 210, 220, 230, 240};
static const uint8_t g_dockedRefreshRates[] = { 40, 45, 50, 55, 60, 70, 72, 75, 80, 90, 95, 100, 110, 120,
130, 140, 144, 150, 160, 165, 170, 180, 190, 200, 210, 220, 230, 240 };
// Calculate with this tool:
// https://tomverbeure.github.io/video_timings_calculator?horiz_pixels=1920&vert_pixels=1080&refresh_rate=240&margins=false&interlaced=false&bpc=8&color_fmt=rgb444&video_opt=false&custom_hblank=80&custom_vblank=6
@@ -119,13 +121,15 @@ namespace display {
static uint8_t _getDockedRefreshRateIterator(uint32_t refreshRate) {
for (size_t i = 0; i < sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]); i++) {
if (g_dockedRefreshRates[i] == refreshRate) return i;
if (g_dockedRefreshRates[i] == refreshRate)
return i;
}
return 0xFF;
}
static void _changeOledElvssSettings(const uint32_t *offsets, const uint32_t *value, uint32_t size, uint32_t start) {
if (!g_config.dsiVirtAddr || !value || !size) return;
if (!g_config.dsiVirtAddr || !value || !size)
return;
volatile uint32_t *dsi = (uint32_t *)g_config.dsiVirtAddr;
@@ -165,7 +169,8 @@ namespace display {
}
bool Initialize(const DisplayRefreshConfig *config) {
if (!config) return false;
if (!config)
return false;
g_config = *config;
g_initialized = true;
@@ -191,17 +196,21 @@ namespace display {
uint32_t values[] = { 2, 0, 0x83 };
if (refresh_rate == 60) {
if (last_refresh_rate == 60) return;
if (last_refresh_rate == 60)
return;
} else if (refresh_rate == 45) {
if (last_refresh_rate == 45) return;
if (last_refresh_rate == 45)
return;
uint32_t vals[] = { 4, 1, 0 };
memcpy(values, vals, sizeof(vals));
} else if (refresh_rate == 50) {
if (last_refresh_rate == 50) return;
if (last_refresh_rate == 50)
return;
uint32_t vals[] = { 3, 1, 0 };
memcpy(values, vals, sizeof(vals));
} else if (refresh_rate == 55) {
if (last_refresh_rate == 55) return;
if (last_refresh_rate == 55)
return;
uint32_t vals[] = { 3, 1, 0 };
memcpy(values, vals, sizeof(vals));
} else {
@@ -228,7 +237,8 @@ namespace display {
uint8_t highestRefreshRate = 60;
uint32_t fd = fd_in;
if(!fd) nvOpen(&fd, "/dev/nvdisp-disp1");
if (!fd)
nvOpen(&fd, "/dev/nvdisp-disp1");
NvdcModeDB2 db2 = { 0 };
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
@@ -278,12 +288,14 @@ namespace display {
// highestRefreshRate = 75;
}
if (!fd_in) nvClose(fd);
if (!fd_in)
nvClose(fd);
g_dockedHighestRefreshRate = highestRefreshRate;
}
static bool _setPLLDHandheldRefreshRate(uint32_t new_refreshRate) {
if (!g_config.clkVirtAddr) return false;
if (!g_config.clkVirtAddr)
return false;
uint32_t fd = 0;
if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
@@ -307,7 +319,8 @@ namespace display {
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
nvClose(fd);
if (rc != 0x75c) return false;
if (rc != 0x75c)
return false;
PLLD_BASE base = { 0 };
PLLD_MISC misc = { 0 };
@@ -315,7 +328,8 @@ namespace display {
memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
uint32_t value = ((base.PLLD_DIVN / base.PLLD_DIVM) * 10) / 4;
if (value == 0 || value == 80) return false;
if (value == 0 || value == 80)
return false;
if (new_refreshRate > g_handheldModeRefreshRate.max) {
new_refreshRate = g_handheldModeRefreshRate.max;
@@ -337,7 +351,8 @@ namespace display {
}
}
}
if (!skip) new_refreshRate = 60;
if (!skip)
new_refreshRate = 60;
}
uint32_t pixelClock = (9375 * ((4096 * ((2 * base.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * base.PLLD_DIVM);
@@ -380,8 +395,7 @@ namespace display {
return false;
}
if (!((display_b.vActive == 480 && display_b.hActive == 720) ||
(display_b.vActive == 720 && display_b.hActive == 1280) ||
if (!((display_b.vActive == 480 && display_b.hActive == 720) || (display_b.vActive == 720 && display_b.hActive == 1280) ||
(display_b.vActive == 1080 && display_b.hActive == 1920))) {
nvClose(fd);
return false;
@@ -426,7 +440,8 @@ namespace display {
}
}
if (itr == -1) itr = _getDockedRefreshRateIterator(60);
if (itr == -1)
itr = _getDockedRefreshRateIterator(60);
// Clamp to highest allowed refresh rate
if (g_dockedRefreshRates[itr] > g_dockedHighestRefreshRate) {
@@ -472,7 +487,8 @@ namespace display {
}
static bool _setNvDispHandheldRefreshRate(uint32_t new_refreshRate) {
if (!g_config.isRetroSUPER) return false;
if (!g_config.isRetroSUPER)
return false;
if (!g_config.displaySync) {
g_wasRetroSuperTurnedOff = false;
@@ -529,7 +545,8 @@ namespace display {
}
}
}
if (!skip) new_refreshRate = 60;
if (!skip)
new_refreshRate = 60;
}
if (new_refreshRate == refreshRateNow) {
@@ -558,7 +575,8 @@ namespace display {
}
bool SetRate(uint32_t new_refreshRate) {
if (!new_refreshRate || !g_initialized) return false;
if (!new_refreshRate || !g_initialized)
return false;
uint32_t fd = 0;
@@ -569,8 +587,7 @@ namespace display {
else if ((!g_config.isRetroSUPER && g_config.isLite) || R_FAILED(nvOpen(&fd, "/dev/nvdisp-disp1"))) {
if (_setPLLDHandheldRefreshRate(new_refreshRate) == false)
return false;
}
else {
} else {
struct dpaux_read {
uint32_t cmd;
uint32_t addr;
@@ -606,7 +623,8 @@ namespace display {
}
bool GetRate(uint32_t *out_refreshRate, bool internal) {
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr) return false;
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr)
return false;
static uint32_t value = 60;
if (g_config.isRetroSUPER && !g_config.isDocked) {
@@ -634,8 +652,7 @@ namespace display {
} else {
g_wasRetroSuperTurnedOff = true;
}
}
else if ((!g_config.isPossiblySpoofedRetro) || (g_config.isPossiblySpoofedRetro && !g_config.isRetroSUPER)) {
} else if ((!g_config.isPossiblySpoofedRetro) || (g_config.isPossiblySpoofedRetro && !g_config.isRetroSUPER)) {
PLLD_BASE temp = { 0 };
PLLD_MISC misc = { 0 };
memcpy(&temp, (void *)(g_config.clkVirtAddr + 0xD0), 4);
@@ -645,7 +662,8 @@ namespace display {
if (value == 0 || value == 80) {
// Docked mode
if (g_config.isLite) return false;
if (g_config.isLite)
return false;
g_config.isDocked = true;
@@ -711,16 +729,14 @@ namespace display {
} else {
value = 60;
}
}
else if (!g_config.isRetroSUPER) {
} else if (!g_config.isRetroSUPER) {
// Handheld mode
g_config.isDocked = false;
g_canChangeRefreshRateDocked = false;
uint32_t pixelClock = (9375ULL * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
value = pixelClock / (DSI_CLOCK_HZ / 60);
}
else {
} else {
return false;
}
}
@@ -733,4 +749,4 @@ namespace display {
g_initialized = false;
memset(&g_config, 0, sizeof(g_config));
}
}
} // namespace display

View File

@@ -17,9 +17,9 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
namespace display {
typedef struct {
uint16_t hFrontPorch;
@@ -124,4 +124,4 @@ namespace display {
void CorrectOledGamma(uint32_t refresh_rate);
void SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p);
void Shutdown(void);
}
} // namespace display

View File

@@ -24,29 +24,30 @@
* --------------------------------------------------------------------------
*/
#include "config.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sstream>
#include <algorithm>
#include <atomic>
#include <cstring>
#include <ctime>
#include <map>
#include <string>
#include <atomic>
#include <initializer_list>
#include <minIni.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <map>
#include <max17050.h>
#include <minIni.h>
#include <sstream>
#include <string>
#include <t210.h>
#include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <unistd.h>
#include "../board/board.hpp"
#include "../hos/apm_ext.h"
#include "config.hpp"
#include "errors.hpp"
#include "file_utils.hpp"
#include <initializer_list>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <sys/stat.h>
#include <sys/types.h>
namespace config {
@@ -83,7 +84,8 @@ namespace config {
return 0;
}
std::uint32_t FindClockHzFromProfiles(std::uint64_t tid, HocClkModule module, std::initializer_list<HocClkProfile> profiles, u32 mhzMultiplier = 1000000) {
std::uint32_t FindClockHzFromProfiles(std::uint64_t tid, HocClkModule module, std::initializer_list<HocClkProfile> profiles,
u32 mhzMultiplier = 1000000) {
std::uint32_t mhz = 0;
if (gLoaded) {
@@ -191,7 +193,7 @@ namespace config {
gLoaded = true;
}
}
} // namespace
void Initialize() {
gPath = FILE_CONFIG_DIR "/config.ini";
@@ -234,9 +236,13 @@ namespace config {
return FindClockHzFromProfiles(tid, module, { HocClkProfile_Handheld }, returnRaw ? 1 : 1000000);
case HocClkProfile_HandheldCharging:
case HocClkProfile_HandheldChargingUSB:
return FindClockHzFromProfiles(tid, module, {HocClkProfile_HandheldChargingUSB, HocClkProfile_HandheldCharging, HocClkProfile_Handheld}, returnRaw ? 1 : 1000000);
return FindClockHzFromProfiles(tid, module,
{ HocClkProfile_HandheldChargingUSB, HocClkProfile_HandheldCharging, HocClkProfile_Handheld },
returnRaw ? 1 : 1000000);
case HocClkProfile_HandheldChargingOfficial:
return FindClockHzFromProfiles(tid, module, {HocClkProfile_HandheldChargingOfficial, HocClkProfile_HandheldCharging, HocClkProfile_Handheld}, returnRaw ? 1 : 1000000);
return FindClockHzFromProfiles(tid, module,
{ HocClkProfile_HandheldChargingOfficial, HocClkProfile_HandheldCharging, HocClkProfile_Handheld },
returnRaw ? 1 : 1000000);
case HocClkProfile_Docked:
return FindClockHzFromProfiles(tid, module, { HocClkProfile_Docked }, returnRaw ? 1 : 1000000);
default:
@@ -273,9 +279,8 @@ namespace config {
if (*mhz) {
numProfiles++;
std::string key = std::string(board::GetProfileName((HocClkProfile)profile, false)) +
"_" +
board::GetModuleName((HocClkModule)module, false);
std::string key =
std::string(board::GetProfileName((HocClkProfile)profile, false)) + "_" + board::GetModuleName((HocClkModule)module, false);
std::string value = std::to_string(*mhz);
keys.push_back(key);
@@ -484,4 +489,4 @@ namespace config {
std::scoped_lock lock{ gConfigMutex };
ini_puts(section, key, NULL, gPath.c_str());
}
}
} // namespace config

View File

@@ -59,4 +59,4 @@ namespace config {
extern uint64_t configValues[HocClkConfigValue_EnumMax];
}
} // namespace config

View File

@@ -24,11 +24,12 @@
* --------------------------------------------------------------------------
*/
#include "errors.hpp"
#include "file_utils.hpp"
#include <cstdarg>
#include <cstring>
#include "errors.hpp"
#include "file_utils.hpp"
namespace errors {
void ThrowException(const char *format, ...) {
va_list args;
@@ -38,4 +39,4 @@ namespace errors {
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
// throw std::runtime_error(msg);
}
}
} // namespace errors

View File

@@ -26,14 +26,13 @@
#pragma once
#include <switch.h>
#include <stdexcept>
#include <switch.h>
#define ERROR_THROW(format, ...) errors::ThrowException(format "\n in %s:%u", ##__VA_ARGS__, __FILE__, __LINE__)
#define ERROR_RESULT_THROW(rc, format, ...) ERROR_THROW(format "\n RC: [0x%x] %04d-%04d", ##__VA_ARGS__, rc, R_MODULE(rc), R_DESCRIPTION(rc))
#define ASSERT_RESULT_OK(rc, format, ...) \
if (R_FAILED(rc)) \
{ \
if (R_FAILED(rc)) { \
ERROR_RESULT_THROW(rc, "ASSERT_RESULT_OK: " format, ##__VA_ARGS__); \
}
#define ASSERT_ENUM_VALID(n, v) \

View File

@@ -24,12 +24,13 @@
* --------------------------------------------------------------------------
*/
#include "file_utils.hpp"
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <t210.h>
#include <tmp451.h>
#include "../hos/apm_ext.h"
#include "file_utils.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
@@ -67,7 +68,7 @@ namespace fileUtils {
Initialize();
}
}
} // namespace
bool IsInitialized() {
return g_has_initialized;
@@ -134,7 +135,8 @@ namespace fileUtils {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
fprintf(file, "%ld%03ld,%s,%016lx", now.tv_sec, now.tv_nsec / 1000000UL, hocclkFormatProfile(context->profile, false), context->applicationId);
fprintf(file, "%ld%03ld,%s,%016lx", now.tv_sec, now.tv_nsec / 1000000UL, hocclkFormatProfile(context->profile, false),
context->applicationId);
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
fprintf(file, ",%d", context->freqs[module]);
@@ -210,4 +212,4 @@ namespace fileUtils {
fsExit();
}
}
} // namespace fileUtils

View File

@@ -26,13 +26,13 @@
#pragma once
#include <switch.h>
#include <time.h>
#include <vector>
#include <string>
#include <atomic>
#include <cstdarg>
#include <hocclk.h>
#include <string>
#include <switch.h>
#include <time.h>
#include <vector>
#define FILE_CONFIG_DIR "/config/" CONFIG_DIR
#define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL)
@@ -50,4 +50,4 @@ namespace fileUtils {
void LogLine(const char *format, ...);
void WriteContextToCsv(const HocClkContext *context);
}
} // namespace fileUtils

View File

@@ -15,17 +15,17 @@
*
*/
#include "kip.hpp"
#include "../i2c/i2cDrv.h"
#include "../board/board.hpp"
#include "file_utils.hpp"
#include "../i2c/i2cDrv.h"
#include "../mgr/clock_manager.hpp"
#include "file_utils.hpp"
#include "kip.hpp"
namespace kip {
bool kipAvailable = false;
void SetKipData()
{
void SetKipData() {
// TODO: figure out if this REALLY causes issues (i doubt it)
// if(board::GetSocType() == HocClkSocType_Mariko) {
// if(R_FAILED(I2c_BuckConverter_SetMvOut(&I2c_Mariko_DRAM_VDDQ, config::GetConfigValue(KipConfigValue_marikoEmcVddqVolt) / 1000))) {
@@ -152,7 +152,8 @@ namespace kip {
configValues.values[KipCrc32] = (u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip"); // write checksum
if (config::SetConfigValues(&configValues, true)) {
fileUtils::LogLine("[kip] KIP data set. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32], configValues.values[KipConfigValue_custRev]);
fileUtils::LogLine("[kip] KIP data set. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32],
configValues.values[KipConfigValue_custRev]);
for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
}
@@ -164,8 +165,7 @@ namespace kip {
// I know this is very hacky, but the config system in the sysmodule doesn't really support writing
void GetKipData()
{
void GetKipData() {
FILE *fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "rb");
if (fp == NULL) {
@@ -192,7 +192,8 @@ namespace kip {
// return;
// }
if ((u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip") != config::GetConfigValue(KipCrc32) && !config::GetConfigValue(HocClkConfigValue_IsFirstLoad)) {
if ((u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip") != config::GetConfigValue(KipCrc32) &&
!config::GetConfigValue(HocClkConfigValue_IsFirstLoad)) {
MigrateKipData(cust_get_cust_rev(&table), cust_get_kip_version(&table));
SetKipData();
notification::writeNotification("Horizon OC\nKIP has been updated\nPlease reboot your console");
@@ -294,7 +295,8 @@ namespace kip {
if (sizeof(HocClkConfigValueList) <= sizeof(configValues)) {
if (config::SetConfigValues(&configValues, true)) {
fileUtils::LogLine("[kip] KIP loaded. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32], configValues.values[KipConfigValue_custRev]);
fileUtils::LogLine("[kip] KIP loaded. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32],
configValues.values[KipConfigValue_custRev]);
for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
}
@@ -319,7 +321,8 @@ namespace kip {
configValues.values[KipConfigValue_marikoGpuBootVolt] = 800;
configValues.values[KipConfigValue_marikoGpuUV] += 2; // Raise UV levels
configValues.values[KipConfigValue_commonGpuVoltOffset] = (u32)(-(s64)(configValues.values[KipConfigValue_commonGpuVoltOffset])); // Migrate GPU Volt Offset
configValues.values[KipConfigValue_commonGpuVoltOffset] =
(u32)(-(s64)(configValues.values[KipConfigValue_commonGpuVoltOffset])); // Migrate GPU Volt Offset
// Raise min cpu vmin
if (configValues.values[KipConfigValue_eristaCpuVmin] < 750) {
configValues.values[KipConfigValue_eristaCpuVmin] = 750;
@@ -332,5 +335,4 @@ namespace kip {
}
config::SetConfigValues(&configValues, true);
}
}
} // namespace kip

View File

@@ -16,15 +16,17 @@
*/
#pragma once
#include <switch.h>
#include <stdio.h>
#include <string.h>
#include <crc32.h>
#include <notification.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <switch.h>
#include "config.hpp"
#include "file_utils.hpp"
#include <notification.h>
#include <crc32.h>
namespace kip {
extern bool kipAvailable;
@@ -114,7 +116,8 @@ namespace kip {
while (1) {
size_t r = fread(buf, 1, sizeof(buf), f);
if (r < CUST_MAGIC_LEN) break;
if (r < CUST_MAGIC_LEN)
break;
for (size_t i = 0; i <= r - CUST_MAGIC_LEN; i++) {
if (memcmp(&buf[i], CUST_MAGIC, CUST_MAGIC_LEN) == 0) {
@@ -131,22 +134,27 @@ namespace kip {
static long cachedCustOffset = -1;
static inline long cust_get_offset(FILE *f) {
if (cachedCustOffset >= 0) return cachedCustOffset;
if (cachedCustOffset >= 0)
return cachedCustOffset;
long off;
if (!cust_find_offset(f, &off)) return -1;
if (!cust_find_offset(f, &off))
return -1;
cachedCustOffset = off;
return off;
}
static inline bool cust_read_table_f(FILE *f, CustomizeTable *out) {
long off = cust_get_offset(f);
if (off < 0) return false;
if (off < 0)
return false;
fseek(f, 0, SEEK_END);
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
if (off + (long)sizeof(CustomizeTable) > ftell(f))
return false;
fseek(f, off, SEEK_SET);
if (fread(out, 1, sizeof(CustomizeTable), f) != sizeof(CustomizeTable)) return false;
if (fread(out, 1, sizeof(CustomizeTable), f) != sizeof(CustomizeTable))
return false;
if (memcmp(out->cust, CUST_MAGIC, CUST_MAGIC_LEN) != 0) {
cachedCustOffset = -1;
@@ -157,10 +165,12 @@ namespace kip {
static inline bool cust_write_table_f(FILE *f, const CustomizeTable *in) {
long off = cust_get_offset(f);
if (off < 0) return false;
if (off < 0)
return false;
fseek(f, 0, SEEK_END);
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
if (off + (long)sizeof(CustomizeTable) > ftell(f))
return false;
fseek(f, off, SEEK_SET);
bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
@@ -170,7 +180,8 @@ namespace kip {
static inline bool cust_read_table(const char *path, CustomizeTable *out) {
FILE *f = fopen(path, "rb");
if (!f) return false;
if (!f)
return false;
bool ok = cust_read_table_f(f, out);
fclose(f);
return ok;
@@ -178,7 +189,8 @@ namespace kip {
static inline bool cust_write_table(const char *path, const CustomizeTable *in) {
FILE *f = fopen(path, "r+b");
if (!f) return false;
if (!f)
return false;
bool ok = cust_write_table_f(f, in);
fclose(f);
return ok;
@@ -196,174 +208,382 @@ namespace kip {
#define CUST_WRITE_FIELD(path, field, val) \
do { \
CustomizeTable t; \
if (!cust_read_table(path, &t)) return false; \
if (!cust_read_table(path, &t)) \
return false; \
t.field = (val); \
return cust_write_table(path, &t); \
} while (0)
// static inline bool cust_set_cust_rev(const char* p, u32 v) { CUST_WRITE_FIELD(p, custRev, v); }
// static inline bool cust_set_mtc_conf(const char* p, u32 v) { CUST_WRITE_FIELD(p, mtcConf, v); }
static inline bool cust_set_hp_mode(const char* p, u32 v) { CUST_WRITE_FIELD(p, hpMode, v); }
static inline bool cust_set_hp_mode(const char *p, u32 v) {
CUST_WRITE_FIELD(p, hpMode, v);
}
static inline bool cust_set_common_emc_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, commonEmcMemVolt, v); }
static inline bool cust_set_erista_emc_max(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaEmcMaxClock, v); }
static inline bool cust_set_step_mode(const char* p, u32 v) { CUST_WRITE_FIELD(p, stepMode, v); }
static inline bool cust_set_mariko_emc_max(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoEmcMaxClock, v); }
static inline bool cust_set_mariko_emc_vddq(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoEmcVddqVolt, v); }
static inline bool cust_set_emc_dvb_shift(const char* p, u32 v) { CUST_WRITE_FIELD(p, emcDvbShift, v); }
static inline bool cust_set_common_emc_volt(const char *p, u32 v) {
CUST_WRITE_FIELD(p, commonEmcMemVolt, v);
}
static inline bool cust_set_erista_emc_max(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaEmcMaxClock, v);
}
static inline bool cust_set_step_mode(const char *p, u32 v) {
CUST_WRITE_FIELD(p, stepMode, v);
}
static inline bool cust_set_mariko_emc_max(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoEmcMaxClock, v);
}
static inline bool cust_set_mariko_emc_vddq(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoEmcVddqVolt, v);
}
static inline bool cust_set_emc_dvb_shift(const char *p, u32 v) {
CUST_WRITE_FIELD(p, emcDvbShift, v);
}
static inline bool cust_set_tRCD(const char* p, u32 v) { CUST_WRITE_FIELD(p, t1_tRCD, v); }
static inline bool cust_set_tRP(const char* p, u32 v) { CUST_WRITE_FIELD(p, t2_tRP, v); }
static inline bool cust_set_tRAS(const char* p, u32 v) { CUST_WRITE_FIELD(p, t3_tRAS, v); }
static inline bool cust_set_tRRD(const char* p, u32 v) { CUST_WRITE_FIELD(p, t4_tRRD, v); }
static inline bool cust_set_tRFC(const char* p, u32 v) { CUST_WRITE_FIELD(p, t5_tRFC, v); }
static inline bool cust_set_tRTW(const char* p, u32 v) { CUST_WRITE_FIELD(p, t6_tRTW, v); }
static inline bool cust_set_tWTR(const char* p, u32 v) { CUST_WRITE_FIELD(p, t7_tWTR, v); }
static inline bool cust_set_tREFI(const char* p, u32 v) { CUST_WRITE_FIELD(p, t8_tREFI, v); }
static inline bool cust_set_tRP_cap(const char* p, u32 v) { CUST_WRITE_FIELD(p, t2_tRP_cap, v); }
static inline bool cust_set_timing_emc_tbreak(const char* p, u32 v) { CUST_WRITE_FIELD(p, timingEmcTbreak, v); }
static inline bool cust_set_low_tRTW(const char* p, u32 v) { CUST_WRITE_FIELD(p, low_t6_tRTW, v); }
static inline bool cust_set_low_tWTR(const char* p, u32 v) { CUST_WRITE_FIELD(p, low_t7_tWTR, v); }
static inline bool cust_set_tRTW_fine_tune(const char* p, u32 v) { CUST_WRITE_FIELD(p, t6_tRTW_fine_tune, v); }
static inline bool cust_set_tWTR_fine_tune(const char* p, u32 v) { CUST_WRITE_FIELD(p, t7_tWTR_fine_tune, v); }
static inline bool cust_set_tRCD(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t1_tRCD, v);
}
static inline bool cust_set_tRP(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t2_tRP, v);
}
static inline bool cust_set_tRAS(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t3_tRAS, v);
}
static inline bool cust_set_tRRD(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t4_tRRD, v);
}
static inline bool cust_set_tRFC(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t5_tRFC, v);
}
static inline bool cust_set_tRTW(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t6_tRTW, v);
}
static inline bool cust_set_tWTR(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t7_tWTR, v);
}
static inline bool cust_set_tREFI(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t8_tREFI, v);
}
static inline bool cust_set_tRP_cap(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t2_tRP_cap, v);
}
static inline bool cust_set_timing_emc_tbreak(const char *p, u32 v) {
CUST_WRITE_FIELD(p, timingEmcTbreak, v);
}
static inline bool cust_set_low_tRTW(const char *p, u32 v) {
CUST_WRITE_FIELD(p, low_t6_tRTW, v);
}
static inline bool cust_set_low_tWTR(const char *p, u32 v) {
CUST_WRITE_FIELD(p, low_t7_tWTR, v);
}
static inline bool cust_set_tRTW_fine_tune(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t6_tRTW_fine_tune, v);
}
static inline bool cust_set_tWTR_fine_tune(const char *p, u32 v) {
CUST_WRITE_FIELD(p, t7_tWTR_fine_tune, v);
}
static inline bool cust_set_read_latency_1333(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1333, v); }
static inline bool cust_set_read_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1600, v); }
static inline bool cust_set_read_latency_1866(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1866, v); }
static inline bool cust_set_read_latency_2133(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency2133, v); }
static inline bool cust_set_read_latency_1333(const char *p, u32 v) {
CUST_WRITE_FIELD(p, readLatency1333, v);
}
static inline bool cust_set_read_latency_1600(const char *p, u32 v) {
CUST_WRITE_FIELD(p, readLatency1600, v);
}
static inline bool cust_set_read_latency_1866(const char *p, u32 v) {
CUST_WRITE_FIELD(p, readLatency1866, v);
}
static inline bool cust_set_read_latency_2133(const char *p, u32 v) {
CUST_WRITE_FIELD(p, readLatency2133, v);
}
static inline bool cust_set_write_latency_1333(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1333, v); }
static inline bool cust_set_write_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1600, v); }
static inline bool cust_set_write_latency_1866(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1866, v); }
static inline bool cust_set_write_latency_2133(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency2133, v); }
static inline bool cust_set_write_latency_1333(const char *p, u32 v) {
CUST_WRITE_FIELD(p, writeLatency1333, v);
}
static inline bool cust_set_write_latency_1600(const char *p, u32 v) {
CUST_WRITE_FIELD(p, writeLatency1600, v);
}
static inline bool cust_set_write_latency_1866(const char *p, u32 v) {
CUST_WRITE_FIELD(p, writeLatency1866, v);
}
static inline bool cust_set_write_latency_2133(const char *p, u32 v) {
CUST_WRITE_FIELD(p, writeLatency2133, v);
}
static inline bool cust_set_erista_cpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuUV, v); }
static inline bool cust_set_eristaCpuVmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuVmin, v); }
static inline bool cust_set_erista_cpu_max_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuMaxVolt, v); }
static inline bool cust_set_eristaCpuUnlock(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuUnlock, v); }
static inline bool cust_set_erista_cpu_uv(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaCpuUV, v);
}
static inline bool cust_set_eristaCpuVmin(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaCpuVmin, v);
}
static inline bool cust_set_erista_cpu_max_volt(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaCpuMaxVolt, v);
}
static inline bool cust_set_eristaCpuUnlock(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaCpuUnlock, v);
}
static inline bool cust_set_mariko_cpu_uv_low(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuUVLow, v); }
static inline bool cust_set_mariko_cpu_uv_high(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuUVHigh, v); }
static inline bool cust_set_mariko_cpu_low_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuLowVmin, v); }
static inline bool cust_set_mariko_cpu_high_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuHighVmin, v); }
static inline bool cust_set_mariko_cpu_max_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxVolt, v); }
static inline bool cust_set_erista_cpu_boost(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuBoostClock, v); }
static inline bool cust_set_mariko_cpu_boost(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuBoostClock, v); }
static inline bool cust_set_mariko_cpu_uv_low(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuUVLow, v);
}
static inline bool cust_set_mariko_cpu_uv_high(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuUVHigh, v);
}
static inline bool cust_set_mariko_cpu_low_vmin(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuLowVmin, v);
}
static inline bool cust_set_mariko_cpu_high_vmin(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuHighVmin, v);
}
static inline bool cust_set_mariko_cpu_max_volt(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuMaxVolt, v);
}
static inline bool cust_set_erista_cpu_boost(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaCpuBoostClock, v);
}
static inline bool cust_set_mariko_cpu_boost(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuBoostClock, v);
}
static inline bool cust_set_erista_gpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaGpuUV, v); }
static inline bool cust_set_erista_gpu_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaGpuVmin, v); }
static inline bool cust_set_mariko_gpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuUV, v); }
static inline bool cust_set_mariko_gpu_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuVmin, v); }
static inline bool cust_set_mariko_gpu_boot_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuBootVolt, v); }
static inline bool cust_set_mariko_gpu_vmax(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuVmax, v); }
static inline bool cust_set_common_gpu_offset(const char* p, u32 v) { CUST_WRITE_FIELD(p, commonGpuVoltOffset, v); }
static inline bool cust_set_marikoCpuMaxClock(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxClock, v); }
static inline bool cust_set_marikoSocVmax(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoSocVmax, v); }
static inline bool cust_set_erista_gpu_uv(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaGpuUV, v);
}
static inline bool cust_set_erista_gpu_vmin(const char *p, u32 v) {
CUST_WRITE_FIELD(p, eristaGpuVmin, v);
}
static inline bool cust_set_mariko_gpu_uv(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoGpuUV, v);
}
static inline bool cust_set_mariko_gpu_vmin(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoGpuVmin, v);
}
static inline bool cust_set_mariko_gpu_boot_volt(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoGpuBootVolt, v);
}
static inline bool cust_set_mariko_gpu_vmax(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoGpuVmax, v);
}
static inline bool cust_set_common_gpu_offset(const char *p, u32 v) {
CUST_WRITE_FIELD(p, commonGpuVoltOffset, v);
}
static inline bool cust_set_marikoCpuMaxClock(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoCpuMaxClock, v);
}
static inline bool cust_set_marikoSocVmax(const char *p, u32 v) {
CUST_WRITE_FIELD(p, marikoSocVmax, v);
}
/* GPU VOLT ARRAY HELPERS */
static inline bool cust_set_erista_gpu_volt(const char *p, int idx, u32 v) {
if (idx < 0 || idx >= 27) return false;
if (idx < 0 || idx >= 27)
return false;
CustomizeTable t;
if (!cust_read_table(p, &t)) return false;
if (!cust_read_table(p, &t))
return false;
t.eristaGpuVoltArray[idx] = v;
return cust_write_table(p, &t);
}
static inline bool cust_set_mariko_gpu_volt(const char *p, int idx, u32 v) {
if (idx < 0 || idx >= 24) return false;
if (idx < 0 || idx >= 24)
return false;
CustomizeTable t;
if (!cust_read_table(p, &t)) return false;
if (!cust_read_table(p, &t))
return false;
t.marikoGpuVoltArray[idx] = v;
return cust_write_table(p, &t);
}
static inline u32 cust_get_field(const CustomizeTable *t, u32 offset) {
if (!t) return 0;
if (!t)
return 0;
return *(u32 *)((u8 *)t + offset);
}
#define CUST_GET_FIELD(table, field) ((table) ? (table)->field : 0)
static inline u32 cust_get_cust_rev(const CustomizeTable* t) { return CUST_GET_FIELD(t, custRev); }
static inline u32 cust_get_kip_version(const CustomizeTable* t) { return CUST_GET_FIELD(t, kipVersion); }
static inline u32 cust_get_cust_rev(const CustomizeTable *t) {
return CUST_GET_FIELD(t, custRev);
}
static inline u32 cust_get_kip_version(const CustomizeTable *t) {
return CUST_GET_FIELD(t, kipVersion);
}
// static inline u32 cust_get_mtc_conf(const CustomizeTable* t) { return CUST_GET_FIELD(t, mtcConf); }
static inline u32 cust_get_hp_mode(const CustomizeTable* t) { return CUST_GET_FIELD(t, hpMode); }
static inline u32 cust_get_hp_mode(const CustomizeTable *t) {
return CUST_GET_FIELD(t, hpMode);
}
static inline u32 cust_get_common_emc_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, commonEmcMemVolt); }
static inline u32 cust_get_erista_emc_max(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaEmcMaxClock); }
static inline u32 cust_get_step_mode(const CustomizeTable* t) { return CUST_GET_FIELD(t, stepMode); }
static inline u32 cust_get_mariko_emc_max(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoEmcMaxClock); }
static inline u32 cust_get_mariko_emc_vddq(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoEmcVddqVolt); }
static inline u32 cust_get_emc_dvb_shift(const CustomizeTable* t) { return CUST_GET_FIELD(t, emcDvbShift); }
static inline u32 cust_get_common_emc_volt(const CustomizeTable *t) {
return CUST_GET_FIELD(t, commonEmcMemVolt);
}
static inline u32 cust_get_erista_emc_max(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaEmcMaxClock);
}
static inline u32 cust_get_step_mode(const CustomizeTable *t) {
return CUST_GET_FIELD(t, stepMode);
}
static inline u32 cust_get_mariko_emc_max(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoEmcMaxClock);
}
static inline u32 cust_get_mariko_emc_vddq(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoEmcVddqVolt);
}
static inline u32 cust_get_emc_dvb_shift(const CustomizeTable *t) {
return CUST_GET_FIELD(t, emcDvbShift);
}
static inline u32 cust_get_tRCD(const CustomizeTable* t) { return CUST_GET_FIELD(t, t1_tRCD); }
static inline u32 cust_get_tRP(const CustomizeTable* t) { return CUST_GET_FIELD(t, t2_tRP); }
static inline u32 cust_get_tRAS(const CustomizeTable* t) { return CUST_GET_FIELD(t, t3_tRAS); }
static inline u32 cust_get_tRRD(const CustomizeTable* t) { return CUST_GET_FIELD(t, t4_tRRD); }
static inline u32 cust_get_tRFC(const CustomizeTable* t) { return CUST_GET_FIELD(t, t5_tRFC); }
static inline u32 cust_get_tRTW(const CustomizeTable* t) { return CUST_GET_FIELD(t, t6_tRTW); }
static inline u32 cust_get_tWTR(const CustomizeTable* t) { return CUST_GET_FIELD(t, t7_tWTR); }
static inline u32 cust_get_tREFI(const CustomizeTable* t) { return CUST_GET_FIELD(t, t8_tREFI); }
static inline u32 cust_get_tRP_cap(const CustomizeTable* t) { return CUST_GET_FIELD(t, t2_tRP_cap); }
static inline u32 cust_get_timing_emc_tbreak(const CustomizeTable* t) { return CUST_GET_FIELD(t, timingEmcTbreak); }
static inline u32 cust_get_low_t6_tRTW(const CustomizeTable* t) { return CUST_GET_FIELD(t, low_t6_tRTW); }
static inline u32 cust_get_low_t7_tWTR(const CustomizeTable* t) { return CUST_GET_FIELD(t, low_t7_tWTR); }
static inline u32 cust_get_tRTW_fine_tune(const CustomizeTable* t) { return CUST_GET_FIELD(t, t6_tRTW_fine_tune); }
static inline u32 cust_get_tWTR_fine_tune(const CustomizeTable* t) { return CUST_GET_FIELD(t, t7_tWTR_fine_tune); }
static inline u32 cust_get_tRCD(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t1_tRCD);
}
static inline u32 cust_get_tRP(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t2_tRP);
}
static inline u32 cust_get_tRAS(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t3_tRAS);
}
static inline u32 cust_get_tRRD(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t4_tRRD);
}
static inline u32 cust_get_tRFC(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t5_tRFC);
}
static inline u32 cust_get_tRTW(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t6_tRTW);
}
static inline u32 cust_get_tWTR(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t7_tWTR);
}
static inline u32 cust_get_tREFI(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t8_tREFI);
}
static inline u32 cust_get_tRP_cap(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t2_tRP_cap);
}
static inline u32 cust_get_timing_emc_tbreak(const CustomizeTable *t) {
return CUST_GET_FIELD(t, timingEmcTbreak);
}
static inline u32 cust_get_low_t6_tRTW(const CustomizeTable *t) {
return CUST_GET_FIELD(t, low_t6_tRTW);
}
static inline u32 cust_get_low_t7_tWTR(const CustomizeTable *t) {
return CUST_GET_FIELD(t, low_t7_tWTR);
}
static inline u32 cust_get_tRTW_fine_tune(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t6_tRTW_fine_tune);
}
static inline u32 cust_get_tWTR_fine_tune(const CustomizeTable *t) {
return CUST_GET_FIELD(t, t7_tWTR_fine_tune);
}
static inline u32 cust_get_read_latency_1333(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1333); }
static inline u32 cust_get_read_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1600); }
static inline u32 cust_get_read_latency_1866(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1866); }
static inline u32 cust_get_read_latency_2133(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency2133); }
static inline u32 cust_get_read_latency_1333(const CustomizeTable *t) {
return CUST_GET_FIELD(t, readLatency1333);
}
static inline u32 cust_get_read_latency_1600(const CustomizeTable *t) {
return CUST_GET_FIELD(t, readLatency1600);
}
static inline u32 cust_get_read_latency_1866(const CustomizeTable *t) {
return CUST_GET_FIELD(t, readLatency1866);
}
static inline u32 cust_get_read_latency_2133(const CustomizeTable *t) {
return CUST_GET_FIELD(t, readLatency2133);
}
static inline u32 cust_get_write_latency_1333(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1333); }
static inline u32 cust_get_write_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1600); }
static inline u32 cust_get_write_latency_1866(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1866); }
static inline u32 cust_get_write_latency_2133(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency2133); }
static inline u32 cust_get_write_latency_1333(const CustomizeTable *t) {
return CUST_GET_FIELD(t, writeLatency1333);
}
static inline u32 cust_get_write_latency_1600(const CustomizeTable *t) {
return CUST_GET_FIELD(t, writeLatency1600);
}
static inline u32 cust_get_write_latency_1866(const CustomizeTable *t) {
return CUST_GET_FIELD(t, writeLatency1866);
}
static inline u32 cust_get_write_latency_2133(const CustomizeTable *t) {
return CUST_GET_FIELD(t, writeLatency2133);
}
static inline u32 cust_get_erista_cpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuUV); }
static inline u32 cust_get_eristaCpuVmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuVmin); }
static inline u32 cust_get_erista_cpu_max_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuMaxVolt); }
static inline u32 cust_get_eristaCpuUnlock(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuUnlock); }
static inline u32 cust_get_erista_cpu_uv(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaCpuUV);
}
static inline u32 cust_get_eristaCpuVmin(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaCpuVmin);
}
static inline u32 cust_get_erista_cpu_max_volt(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaCpuMaxVolt);
}
static inline u32 cust_get_eristaCpuUnlock(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaCpuUnlock);
}
static inline u32 cust_get_mariko_cpu_uv_low(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuUVLow); }
static inline u32 cust_get_mariko_cpu_uv_high(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuUVHigh); }
static inline u32 cust_get_mariko_cpu_low_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuLowVmin); }
static inline u32 cust_get_mariko_cpu_high_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuHighVmin); }
static inline u32 cust_get_mariko_cpu_max_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxVolt); }
static inline u32 cust_get_erista_cpu_boost(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuBoostClock); }
static inline u32 cust_get_mariko_cpu_boost(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuBoostClock); }
static inline u32 cust_get_table_conf(const CustomizeTable* t) { return CUST_GET_FIELD(t, tableConf); }
static inline u32 cust_get_mariko_cpu_uv_low(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuUVLow);
}
static inline u32 cust_get_mariko_cpu_uv_high(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuUVHigh);
}
static inline u32 cust_get_mariko_cpu_low_vmin(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuLowVmin);
}
static inline u32 cust_get_mariko_cpu_high_vmin(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuHighVmin);
}
static inline u32 cust_get_mariko_cpu_max_volt(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuMaxVolt);
}
static inline u32 cust_get_erista_cpu_boost(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaCpuBoostClock);
}
static inline u32 cust_get_mariko_cpu_boost(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuBoostClock);
}
static inline u32 cust_get_table_conf(const CustomizeTable *t) {
return CUST_GET_FIELD(t, tableConf);
}
static inline u32 cust_get_erista_gpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaGpuUV); }
static inline u32 cust_get_erista_gpu_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaGpuVmin); }
static inline u32 cust_get_mariko_gpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuUV); }
static inline u32 cust_get_mariko_gpu_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuVmin); }
static inline u32 cust_get_mariko_gpu_boot_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuBootVolt); }
static inline u32 cust_get_mariko_gpu_vmax(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuVmax); }
static inline u32 cust_get_common_gpu_offset(const CustomizeTable* t) { return CUST_GET_FIELD(t, commonGpuVoltOffset); }
static inline u32 cust_get_marikoCpuMaxClock(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxClock); }
static inline u32 cust_get_marikoSocVmax(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoSocVmax); }
static inline u32 cust_get_erista_gpu_uv(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaGpuUV);
}
static inline u32 cust_get_erista_gpu_vmin(const CustomizeTable *t) {
return CUST_GET_FIELD(t, eristaGpuVmin);
}
static inline u32 cust_get_mariko_gpu_uv(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoGpuUV);
}
static inline u32 cust_get_mariko_gpu_vmin(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoGpuVmin);
}
static inline u32 cust_get_mariko_gpu_boot_volt(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoGpuBootVolt);
}
static inline u32 cust_get_mariko_gpu_vmax(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoGpuVmax);
}
static inline u32 cust_get_common_gpu_offset(const CustomizeTable *t) {
return CUST_GET_FIELD(t, commonGpuVoltOffset);
}
static inline u32 cust_get_marikoCpuMaxClock(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoCpuMaxClock);
}
static inline u32 cust_get_marikoSocVmax(const CustomizeTable *t) {
return CUST_GET_FIELD(t, marikoSocVmax);
}
static inline u32 cust_get_erista_gpu_volt(const CustomizeTable *t, int idx) {
if (!t || idx < 0 || idx >= 27) return 0;
if (!t || idx < 0 || idx >= 27)
return 0;
return t->eristaGpuVoltArray[idx];
}
static inline u32 cust_get_mariko_gpu_volt(const CustomizeTable *t, int idx) {
if (!t || idx < 0 || idx >= 24) return 0;
if (!t || idx < 0 || idx >= 24)
return 0;
return t->marikoGpuVoltArray[idx];
}
#define DECL_ERISTA_GPU_VOLT_HELPER(freq, idx) \
static inline bool cust_set_erista_gpu_volt_##freq( \
const char* p, u32 v) { \
static inline bool cust_set_erista_gpu_volt_##freq(const char *p, u32 v) { \
return cust_set_erista_gpu_volt(p, idx, v); \
}
#define DECL_MARIKO_GPU_VOLT_HELPER(freq, idx) \
static inline bool cust_set_mariko_gpu_volt_##freq( \
const char* p, u32 v) { \
static inline bool cust_set_mariko_gpu_volt_##freq(const char *p, u32 v) { \
return cust_set_mariko_gpu_volt(p, idx, v); \
}
@@ -423,13 +643,15 @@ namespace kip {
#define DECL_ERISTA_GPU_VOLT_GET(freq, idx) \
static inline u32 cust_get_erista_gpu_volt_##freq##_val(const char *p) { \
CustomizeTable t; \
if (!cust_read_table(p, &t)) return 0; \
if (!cust_read_table(p, &t)) \
return 0; \
return cust_get_erista_gpu_volt(&t, idx); \
}
#define DECL_MARIKO_GPU_VOLT_GET(freq, idx) \
static inline u32 cust_get_mariko_gpu_volt_##freq##_val(const char *p) { \
CustomizeTable t; \
if (!cust_read_table(p, &t)) return 0; \
if (!cust_read_table(p, &t)) \
return 0; \
return cust_get_mariko_gpu_volt(&t, idx); \
}
@@ -488,4 +710,4 @@ namespace kip {
void MigrateKipData(u32 custRev, u32 version);
void SetKipData();
void GetKipData();
}
} // namespace kip

View File

@@ -24,60 +24,50 @@
* --------------------------------------------------------------------------
*/
#include <stdatomic.h>
#include "apm_ext.h"
#include <stdatomic.h>
static Service g_apmSrv;
static Service g_apmSysSrv;
static atomic_size_t g_refCnt;
Result apmExtInitialize(void)
{
Result apmExtInitialize(void) {
g_refCnt++;
if (serviceIsActive(&g_apmSrv))
{
if (serviceIsActive(&g_apmSrv)) {
return 0;
}
Result rc = 0;
rc = smGetService(&g_apmSrv, "apm");
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = smGetService(&g_apmSysSrv, "apm:sys");
}
if (R_FAILED(rc))
{
if (R_FAILED(rc)) {
apmExtExit();
}
return rc;
}
void apmExtExit(void)
{
if (--g_refCnt == 0)
{
void apmExtExit(void) {
if (--g_refCnt == 0) {
serviceClose(&g_apmSrv);
serviceClose(&g_apmSysSrv);
}
}
Result apmExtGetPerformanceMode(u32* out_mode)
{
Result apmExtGetPerformanceMode(u32 *out_mode) {
return serviceDispatchOut(&g_apmSrv, 1, *out_mode);
}
Result apmExtSysRequestPerformanceMode(u32 mode)
{
Result apmExtSysRequestPerformanceMode(u32 mode) {
return serviceDispatchIn(&g_apmSysSrv, 0, mode);
}
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf)
{
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf) {
return serviceDispatchOut(&g_apmSysSrv, 7, *out_conf);
}

View File

@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>

View File

@@ -24,7 +24,6 @@
* --------------------------------------------------------------------------
*/
#include <hocclk/apm.h>
HocClkApmConfiguration hocclk_g_apm_configurations[] = {
@@ -46,4 +45,3 @@ HocClkApmConfiguration hocclk_g_apm_configurations[] = {
{ 0x9222000C, 1020000000, 76800000, 1331200000 },
{ 0, 0, 0, 0 },
};

View File

@@ -15,10 +15,11 @@
*
*/
#include "integrations.hpp"
#include <sys/stat.h>
#include <SaltyNX.h>
#include "integrations.hpp"
#include "process_management.hpp"
#include <sys/stat.h>
namespace integrations {
@@ -38,7 +39,8 @@ namespace integrations {
svcCloseHandle(saltysd);
break;
}
if (i == 66) return false;
if (i == 66)
return false;
svcSleepThread(1'000'000);
}
@@ -74,7 +76,7 @@ namespace integrations {
gSharedMemoryUsed = true;
}
}
} // namespace
bool GetSysDockState() {
struct stat st = { 0 };
@@ -143,8 +145,10 @@ namespace integrations {
resolutionLookup = 1;
return 0;
} else if (resolutionLookup == 1) {
if (gNxFps->renderCalls[0].calls != 0xFFFF) resolutionLookup = 2;
else return 0;
if (gNxFps->renderCalls[0].calls != 0xFFFF)
resolutionLookup = 2;
else
return 0;
}
return gNxFps->renderCalls[0].height == 0 ? gNxFps->viewportCalls[0].height : gNxFps->renderCalls[0].height;
@@ -152,4 +156,4 @@ namespace integrations {
return 0;
}
}
} // namespace integrations

View File

@@ -17,8 +17,8 @@
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
namespace integrations {
@@ -66,4 +66,4 @@ namespace integrations {
u8 GetSaltyNXFPS();
u16 GetSaltyNXResolutionHeight();
}
} // namespace integrations

View File

@@ -15,7 +15,6 @@
*
*/
#include "notification.h"
namespace notification {
@@ -40,4 +39,4 @@ namespace notification {
fclose(file);
}
}
}
} // namespace notification

View File

@@ -17,9 +17,9 @@
#pragma once
#include <string>
#include <ctime>
#include <cstdio>
#include <ctime>
#include <string>
namespace notification {
void writeNotification(const std::string &message);
}

View File

@@ -44,7 +44,6 @@
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv)
*/
// GPIOs T210: 3: 3.3V, 5: CPU PMIC, 6: GPU PMIC, 7: DSI/VI 1.2V powered by ldo0.
/*

View File

@@ -24,19 +24,20 @@
* --------------------------------------------------------------------------
*/
#include "process_management.hpp"
#include "../file/file_utils.hpp"
#include "../file/errors.hpp"
#include <cstring>
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "process_management.hpp"
namespace processManagement {
namespace {
constexpr u64 Qlaunch = 0x0100000000001000ULL;
constexpr u32 IsQlaunch = 0x20f;
Service pdmqryClone;
}
} // namespace
void Initialize() {
Result rc = 0;
@@ -54,7 +55,6 @@ namespace processManagement {
serviceClone(pdmqrySrv, &pdmqryClone);
serviceClose(pdmqrySrv);
memcpy(pdmqrySrv, &pdmqryClone, sizeof(Service));
}
void WaitForQLaunch() {
@@ -77,12 +77,15 @@ namespace processManagement {
u64 PIDnow;
Result rc = pmdmntGetApplicationProcessId(&PIDnow);
if(R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
rc = pmdmntGetProgramId(&TIDnow, PIDnow);
if(R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
rc = pdmqryGetAvailablePlayEventRange(&total_entries, &start_entry_index, &end_entry_index);
if (R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
if (total_entries == last_total_entries) {
*outOfFocus = isOutOfFocus;
return 0;
@@ -92,10 +95,13 @@ namespace processManagement {
PdmPlayEvent events[16];
s32 out = 0;
s32 start_entry = end_entry_index - 15;
if (start_entry < 0) start_entry = 0;
if (start_entry < 0)
start_entry = 0;
rc = pdmqryQueryPlayEvent(start_entry, events, sizeof(events) / sizeof(events[0]), &out);
if (R_FAILED(rc)) return rc;
if (out == 0) return 1;
if (R_FAILED(rc))
return rc;
if (out == 0)
return 1;
int itr = -1;
for (int i = out - 1; i >= 0; i--) {
@@ -112,8 +118,6 @@ namespace processManagement {
TID.parts.part[0] = events[i].event_data.applet.program_id[1];
TID.parts.part[1] = events[i].event_data.applet.program_id[0];
if (TID.full != (TIDnow & ~0xFFF))
continue;
else {
@@ -121,9 +125,11 @@ namespace processManagement {
break;
}
}
if (itr == -1) return 1;
if (itr == -1)
return 1;
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus || events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus ||
events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
*outOfFocus = isOut;
isOutOfFocus = isOut;
return 0;
@@ -158,4 +164,4 @@ namespace processManagement {
pdmqryExit();
}
}
} // namespace processManagement

View File

@@ -24,7 +24,6 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <switch.h>
@@ -36,4 +35,4 @@ namespace processManagement {
Result isApplicationOutOfFocus(bool *outOfFocus);
void Exit();
}
} // namespace processManagement

View File

@@ -19,25 +19,36 @@
const char *PsmPowerRoleToStr(PsmPowerRole role) {
switch (role) {
case PsmPowerRole_Sink: return "Sink";
case PsmPowerRole_Source: return "Source";
default: return "Unknown";
case PsmPowerRole_Sink:
return "Sink";
case PsmPowerRole_Source:
return "Source";
default:
return "Unknown";
}
}
const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
switch (type) {
case PsmInfoChargerType_None: return "None";
case PsmInfoChargerType_PD: return "USB-C PD";
case PsmInfoChargerType_None:
return "None";
case PsmInfoChargerType_PD:
return "USB-C PD";
case PsmInfoChargerType_TypeC_1500mA:
case PsmInfoChargerType_TypeC_3000mA: return "USB-C";
case PsmInfoChargerType_DCP: return "USB DCP";
case PsmInfoChargerType_CDP: return "USB CDP";
case PsmInfoChargerType_SDP: return "USB SDP";
case PsmInfoChargerType_TypeC_3000mA:
return "USB-C";
case PsmInfoChargerType_DCP:
return "USB DCP";
case PsmInfoChargerType_CDP:
return "USB CDP";
case PsmInfoChargerType_SDP:
return "USB SDP";
case PsmInfoChargerType_Apple_500mA:
case PsmInfoChargerType_Apple_1000mA:
case PsmInfoChargerType_Apple_2000mA: return "Apple";
default: return "Unknown";
case PsmInfoChargerType_Apple_2000mA:
return "Apple";
default:
return "Unknown";
}
}
@@ -59,9 +70,13 @@ PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info) {
switch (PsmGetBatteryState(info)) {
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
case PsmBatteryState_ChargingPaused:return "| |";
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶
default: return "?";
case PsmBatteryState_Discharging:
return "\u25c0"; // ◀
case PsmBatteryState_ChargingPaused:
return "| |";
case PsmBatteryState_FastCharging:
return "\u25b6"; // ▶
default:
return "?";
}
}

View File

@@ -25,10 +25,7 @@ typedef enum {
PsmPDC_AcceptedRDO = 3 // Received and accepted Request Data Object
} PsmChargeInfoPDC; // BM92T series
typedef enum {
PsmPowerRole_Sink = 1,
PsmPowerRole_Source = 2
} PsmPowerRole;
typedef enum { PsmPowerRole_Sink = 1, PsmPowerRole_Source = 2 } PsmPowerRole;
const char *PsmPowerRoleToStr(PsmPowerRole role);
@@ -84,11 +81,7 @@ typedef enum {
bool PsmIsChargerConnected(const PsmChargeInfo *info);
bool PsmIsCharging(const PsmChargeInfo *info);
typedef enum {
PsmBatteryState_Discharging,
PsmBatteryState_ChargingPaused,
PsmBatteryState_FastCharging
} PsmBatteryState;
typedef enum { PsmBatteryState_Discharging, PsmBatteryState_ChargingPaused, PsmBatteryState_FastCharging } PsmBatteryState;
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info);
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info);

View File

@@ -17,6 +17,7 @@
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include <switch.h>
#include "../util/service_guard.h"
#include "pwm.h"
@@ -37,10 +38,7 @@ Service* pwmGetServiceSession(void) {
}
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code) {
return serviceDispatchIn(&g_pwmSrv, 2, device_code,
.out_num_objects = 1,
.out_objects = &out->s,
);
return serviceDispatchIn(&g_pwmSrv, 2, device_code, .out_num_objects = 1, .out_objects = &out->s, );
}
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out) {

View File

@@ -17,8 +17,10 @@
#pragma once
#include <switch.h>
#include "pcv_types.h"
typedef struct {
Service s;
} RgltrSession;

View File

@@ -16,9 +16,11 @@
*/
#include <switch.h>
#include "rgltr.h"
#include "rgltr_services.h" // for extern Service g_rgltrSrv, etc.
// Global service handle
Service g_rgltrSrv;
@@ -35,13 +37,7 @@ void rgltrExit(void) {
Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id) {
const u32 in = (u32)module_id;
return serviceDispatchIn(
&g_rgltrSrv,
0,
in,
.out_num_objects = 1,
.out_objects = &session_out->s
);
return serviceDispatchIn(&g_rgltrSrv, 0, in, .out_num_objects = 1, .out_objects = &session_out->s);
}
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt) {

View File

@@ -18,8 +18,10 @@
#pragma once
#include <switch.h> // for Service, Result, hosversionBefore(), smGetService(), serviceClose(), etc.
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
extern Service g_rgltrSrv;
Result rgltrInitialize(void);

View File

@@ -24,22 +24,15 @@
* --------------------------------------------------------------------------
*/
#include "i2c.h"
#define I2C_CMD_SND 0
#define I2C_CMD_RCV 1
Result i2csessionExtRegReceive(I2cSession* s, u8 in, void* out, u8 out_size)
{
u8 cmdlist[5] = {
I2C_CMD_SND | (I2cTransactionOption_Start << 6),
sizeof(in),
in,
Result i2csessionExtRegReceive(I2cSession *s, u8 in, void *out, u8 out_size) {
u8 cmdlist[5] = { I2C_CMD_SND | (I2cTransactionOption_Start << 6), sizeof(in), in,
I2C_CMD_RCV | (I2cTransactionOption_All << 6),
out_size
};
I2C_CMD_RCV | (I2cTransactionOption_All << 6), out_size };
return i2csessionExecuteCommandList(s, out, out_size, cmdlist, sizeof(cmdlist));
}

View File

@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>

View File

@@ -37,8 +37,12 @@ Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) {
}
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
struct { u8 reg; } __attribute__((packed)) cmd;
struct { u8 val; } __attribute__((packed)) rec;
struct {
u8 reg;
} __attribute__((packed)) cmd;
struct {
u8 val;
} __attribute__((packed)) rec;
I2cSession _session;
Result res = i2cOpenSession(&_session, dev);
@@ -63,8 +67,12 @@ Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
}
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) {
struct { u8 reg; } __attribute__((packed)) cmd;
struct { u16 val; } __attribute__((packed)) rec;
struct {
u8 reg;
} __attribute__((packed)) cmd;
struct {
u16 val;
} __attribute__((packed)) rec;
I2cSession _session;
Result res = i2cOpenSession(&_session, dev);
@@ -223,13 +231,20 @@ Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) {
// Converts mA to the raw value for bits [2:0] of REG00
static u8 I2c_Bq24193_Convert_InputmA_Raw(u32 ma) {
if (ma <= 100) return 0b000;
if (ma <= 150) return 0b001;
if (ma <= 500) return 0b010;
if (ma <= 900) return 0b011;
if (ma <= 1200) return 0b100;
if (ma <= 1500) return 0b101;
if (ma <= 2000) return 0b110;
if (ma <= 100)
return 0b000;
if (ma <= 150)
return 0b001;
if (ma <= 500)
return 0b010;
if (ma <= 900)
return 0b011;
if (ma <= 1200)
return 0b100;
if (ma <= 1500)
return 0b101;
if (ma <= 2000)
return 0b110;
return 0b111; // 3000mA max
}
@@ -239,9 +254,7 @@ Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
return 0;
u8 raw;
Result res = I2cRead_OutU8(I2cDevice_Bq24193,
BQ24193_INPUT_SOURCE_CONTROL_REG,
&raw);
Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_INPUT_SOURCE_CONTROL_REG, &raw);
if (R_FAILED(res))
return res;
@@ -259,15 +272,33 @@ Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma) {
return res;
switch (raw & 0x07) {
case 0b000: *ma = 100; break;
case 0b001: *ma = 150; break;
case 0b010: *ma = 500; break;
case 0b011: *ma = 900; break;
case 0b100: *ma = 1200; break;
case 0b101: *ma = 1500; break;
case 0b110: *ma = 2000; break;
case 0b111: *ma = 3000; break;
default: *ma = 0; break;
case 0b000:
*ma = 100;
break;
case 0b001:
*ma = 150;
break;
case 0b010:
*ma = 500;
break;
case 0b011:
*ma = 900;
break;
case 0b100:
*ma = 1200;
break;
case 0b101:
*ma = 1500;
break;
case 0b110:
*ma = 2000;
break;
case 0b111:
*ma = 3000;
break;
default:
*ma = 0;
break;
}
return 0;
}

View File

@@ -40,11 +40,21 @@ typedef struct I2c_BuckConverter_Domain {
u8 por_val;
} I2c_BuckConverter_Domain;
const I2c_BuckConverter_Domain I2c_SOC = { I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000, };
const I2c_BuckConverter_Domain I2c_VDD2 = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000, };
const I2c_BuckConverter_Domain I2c_Display = { I2cDevice_Max77620Pmic, I2c_Max77620_LDO0VOLT_REG, 0x3F, 25000, 800000, 1325000, };
const I2c_BuckConverter_Domain I2c_Erista_CPU = { I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
const I2c_BuckConverter_Domain I2c_Erista_GPU = { I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
const I2c_BuckConverter_Domain I2c_SOC = {
I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000,
};
const I2c_BuckConverter_Domain I2c_VDD2 = {
I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000,
};
const I2c_BuckConverter_Domain I2c_Display = {
I2cDevice_Max77620Pmic, I2c_Max77620_LDO0VOLT_REG, 0x3F, 25000, 800000, 1325000,
};
const I2c_BuckConverter_Domain I2c_Erista_CPU = {
I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000,
};
const I2c_BuckConverter_Domain I2c_Erista_GPU = {
I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000,
};
const I2c_BuckConverter_Domain I2c_Mariko_CPU = { I2cDevice_Max77812_2, I2c_Max77812_CPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
const I2c_BuckConverter_Domain I2c_Mariko_GPU = { I2cDevice_Max77812_2, I2c_Max77812_GPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDDQ = { I2cDevice_Max77812_2, I2c_Max77812_MEMVOLT_REG, 0xFF, 5000, 250000, 700000, 0x78 };

View File

@@ -22,8 +22,8 @@
*
*/
#include "max17050.h"
#include "i2c.h"
#include "max17050.h"
#define MAX17050_WAIT_NS 1000000000UL
@@ -40,15 +40,13 @@ static u64 g_update_ticks = 0;
static s32 g_power_now = 0;
static s32 g_power_avg = 0;
static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
{
static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg) {
s64 ma, mv;
u16 values[3] = { 0 };
Result rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_VCELL, values, sizeof(values));
if (R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
ma = (s16)values[1];
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN);
@@ -57,13 +55,11 @@ static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
*out_mw_now = ma * mv / 1000000;
}
if (R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_AvgVCELL, values, sizeof(u16));
}
if (R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
ma = (s16)values[2];
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN);
@@ -75,50 +71,42 @@ static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
return rc;
}
static void _max17050_update()
{
static void _max17050_update() {
u64 ticks = armGetSystemTick();
if(armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS)
{
if (armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS) {
return;
}
g_update_ticks = ticks;
if(!serviceIsActive(&g_i2c_session.s))
{
if (!serviceIsActive(&g_i2c_session.s)) {
return;
}
_max17050_get_power(&g_power_now, &g_power_avg);
}
Result max17050Initialize(void)
{
Result max17050Initialize(void) {
Result rc = i2cInitialize();
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = i2cOpenSession(&g_i2c_session, I2cDevice_Max17050);
}
return rc;
}
void max17050Exit(void)
{
void max17050Exit(void) {
i2csessionClose(&g_i2c_session);
i2cExit();
}
s32 max17050PowerNow(void)
{
s32 max17050PowerNow(void) {
_max17050_update();
return g_power_now;
}
s32 max17050PowerAvg(void)
{
s32 max17050PowerAvg(void) {
_max17050_update();
return g_power_avg;
}

View File

@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>

View File

@@ -17,8 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tmp451.h"
#include "i2c.h"
#include "tmp451.h"
#define TMP451_WAIT_NS 1000000000UL
@@ -33,37 +33,31 @@ static u64 g_update_ticks = 0;
static s32 g_temp_pcb = 0;
static s32 g_temp_soc = 0;
static Result _tmp451_get_temp(u8 reg, u8 dec_reg, s32* out)
{
static Result _tmp451_get_temp(u8 reg, u8 dec_reg, s32 *out) {
u8 val = 0;
Result rc = i2csessionExtRegReceive(&g_i2c_session, reg, &val, sizeof(val));
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
*out = (s32)val * 1000;
rc = i2csessionExtRegReceive(&g_i2c_session, dec_reg, &val, sizeof(val));
}
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
*out += ((s32)(val >> 4) * 625) / 10;
}
return rc;
}
static void _tmp451_update()
{
static void _tmp451_update() {
u64 ticks = armGetSystemTick();
if(armTicksToNs(ticks - g_update_ticks) <= TMP451_WAIT_NS)
{
if (armTicksToNs(ticks - g_update_ticks) <= TMP451_WAIT_NS) {
return;
}
g_update_ticks = ticks;
if(!serviceIsActive(&g_i2c_session.s))
{
if (!serviceIsActive(&g_i2c_session.s)) {
return;
}
@@ -71,32 +65,27 @@ static void _tmp451_update()
_tmp451_get_temp(TMP451_SOC_TEMP_REG, TMP451_SOC_TMP_DEC_REG, &g_temp_soc);
}
Result tmp451Initialize(void)
{
Result tmp451Initialize(void) {
Result rc = i2cInitialize();
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = i2cOpenSession(&g_i2c_session, I2cDevice_Tmp451);
}
return rc;
}
void tmp451Exit(void)
{
void tmp451Exit(void) {
i2csessionClose(&g_i2c_session);
i2cExit();
}
s32 tmp451TempPcb(void)
{
s32 tmp451TempPcb(void) {
_tmp451_update();
return g_temp_pcb;
}
s32 tmp451TempSoc(void)
{
s32 tmp451TempSoc(void) {
_tmp451_update();
return g_temp_soc;
}

View File

@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>

View File

@@ -24,14 +24,12 @@
* --------------------------------------------------------------------------
*/
#include "ipc_server.h"
#include <string.h>
Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions)
{
if(max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1))
{
#include "ipc_server.h"
Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions) {
if (max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1)) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
@@ -40,27 +38,22 @@ Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions)
server->count = 0;
Result rc = smRegisterService(&server->handles[0], server->srvName, false, max_sessions);
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
server->count = 1;
}
return rc;
}
Result ipcServerExit(IpcServer* server)
{
for(u32 i = 0; i < server->count; i++)
{
Result ipcServerExit(IpcServer *server) {
for (u32 i = 0; i < server->count; i++) {
svcCloseHandle(server->handles[i]);
}
server->count = 0;
return smUnregisterService(server->srvName);
}
static Result _ipcServerAddSession(IpcServer* server, Handle session)
{
if(server->count >= server->max)
{
static Result _ipcServerAddSession(IpcServer *server, Handle session) {
if (server->count >= server->max) {
return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
}
@@ -69,25 +62,21 @@ static Result _ipcServerAddSession(IpcServer* server, Handle session)
return 0;
}
static Result _ipcServerDeleteSession(IpcServer* server, u32 index)
{
if(!index || index >= server->count)
{
static Result _ipcServerDeleteSession(IpcServer *server, u32 index) {
if (!index || index >= server->count) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
svcCloseHandle(server->handles[index]);
for(u32 j = index; j < (server->count - 1); j++)
{
for (u32 j = index; j < (server->count - 1); j++) {
server->handles[j] = server->handles[j + 1];
}
server->count--;
return 0;
}
static Result _ipcServerParseRequest(IpcServerRequest* r)
{
static Result _ipcServerParseRequest(IpcServerRequest *r) {
u8 *base = armGetTls();
r->hipc = hipcParseRequest(base);
@@ -95,19 +84,16 @@ static Result _ipcServerParseRequest(IpcServerRequest* r)
r->data.size = 0;
r->data.ptr = NULL;
if(r->hipc.meta.type == CmifCommandType_Request)
{
if (r->hipc.meta.type == CmifCommandType_Request) {
IpcServerRawHeader *header = cmifGetAlignedDataStart(r->hipc.data.data_words, base);
size_t dataSize = r->hipc.meta.num_data_words * 4;
if(!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC)
{
if (!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
r->data.cmdId = header->cmdId;
if(dataSize > sizeof(IpcServerRawHeader))
{
if (dataSize > sizeof(IpcServerRawHeader)) {
r->data.size = dataSize - sizeof(IpcServerRawHeader);
r->data.ptr = ((u8 *)header) + sizeof(IpcServerRawHeader);
}
@@ -116,37 +102,30 @@ static Result _ipcServerParseRequest(IpcServerRequest* r)
return 0;
}
static void _ipcServerPrepareResponse(Result rc, void* data, size_t dataSize)
{
static void _ipcServerPrepareResponse(Result rc, void *data, size_t dataSize) {
u8 *base = armGetTls();
HipcRequest hipc = hipcMakeRequestInline(base,
.type = CmifCommandType_Request,
.num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4,
);
HipcRequest hipc =
hipcMakeRequestInline(base, .type = CmifCommandType_Request, .num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4, );
IpcServerRawHeader *rawHeader = cmifGetAlignedDataStart(hipc.data_words, base);
rawHeader->magic = CMIF_OUT_HEADER_MAGIC;
rawHeader->result = rc;
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
memcpy(((u8 *)rawHeader) + sizeof(IpcServerRawHeader), data, dataSize);
}
}
static Result _ipcServerProcessNewSession(IpcServer* server)
{
static Result _ipcServerProcessNewSession(IpcServer *server) {
Handle session;
Result rc = svcAcceptSession(&session, server->handles[0]);
if(R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session)))
{
if (R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session))) {
svcCloseHandle(session);
}
return rc;
}
static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandler handler, void* userdata, u32 handleIndex)
{
static Result _ipcServerProcessSession(IpcServer *server, IpcServerRequestHandler handler, void *userdata, u32 handleIndex) {
s32 unusedIndex;
IpcServerRequest r;
size_t dataSize = 0;
@@ -154,21 +133,14 @@ static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandle
bool close = false;
Result rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 1, 0, UINT64_MAX);
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = _ipcServerParseRequest(&r);
}
if(R_SUCCEEDED(rc))
{
switch(r.hipc.meta.type)
{
if (R_SUCCEEDED(rc)) {
switch (r.hipc.meta.type) {
case CmifCommandType_Request:
_ipcServerPrepareResponse(
handler(userdata, &r, data, &dataSize),
data,
dataSize
);
_ipcServerPrepareResponse(handler(userdata, &r, data, &dataSize), data, dataSize);
break;
case CmifCommandType_Close:
_ipcServerPrepareResponse(0, NULL, 0);
@@ -180,42 +152,33 @@ static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandle
}
rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 0, server->handles[handleIndex], 0);
if(rc == KERNELRESULT(TimedOut))
{
if (rc == KERNELRESULT(TimedOut)) {
rc = 0;
}
}
if(R_FAILED(rc) || close)
{
if (R_FAILED(rc) || close) {
_ipcServerDeleteSession(server, handleIndex);
}
return rc;
}
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata)
{
Result ipcServerProcess(IpcServer *server, IpcServerRequestHandler handler, void *userdata) {
s32 handleIndex = -1;
Result rc = svcWaitSynchronization(&handleIndex, server->handles, server->count, UINT64_MAX);
if(R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count))
{
if (R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count)) {
rc = MAKERESULT(Module_Libnx, LibnxError_NotFound);
}
if(R_SUCCEEDED(rc))
{
if(handleIndex)
{
if (R_SUCCEEDED(rc)) {
if (handleIndex) {
rc = _ipcServerProcessSession(server, handler, userdata, handleIndex);
}
else
{
} else {
rc = _ipcServerProcessNewSession(server);
}
}
return rc;
}

View File

@@ -24,45 +24,38 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>
#define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader))
typedef struct
{
typedef struct {
u64 magic;
union
{
union {
u64 cmdId;
u64 result;
};
} IpcServerRawHeader;
typedef struct
{
typedef struct {
SmServiceName srvName;
Handle handles[MAX_WAIT_OBJECTS];
u32 max;
u32 count;
} IpcServer;
typedef struct
{
typedef struct {
u64 cmdId;
void *ptr;
size_t size;
} IpcServerRequestData;
typedef struct
{
typedef struct {
HipcParsedRequest hipc;
IpcServerRequestData data;
} IpcServerRequest;

View File

@@ -24,21 +24,22 @@
* --------------------------------------------------------------------------
*/
#include "ipc_service.hpp"
#include <cstring>
#include <switch.h>
#include "../hos/apm_ext.h"
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h>
#include "../file/config.hpp"
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "../file/kip.hpp"
#include "../hos/apm_ext.h"
#include "../mgr/clock_manager.hpp"
#include "ipc_service.hpp"
#include <ipc_server.h>
#include <lockable_mutex.h>
#include "../file/file_utils.hpp"
#include "../file/errors.hpp"
#include "../mgr/clock_manager.hpp"
#include "../file/config.hpp"
#include "../file/kip.hpp"
namespace ipcService {
namespace {
@@ -149,10 +150,8 @@ namespace ipcService {
case HocClkIpcCmd_GetVersionString:
if (r->hipc.meta.num_recv_buffers >= 1) {
return GetVersionString(
(char*)hipcGetBufferAddress(r->hipc.data.recv_buffers),
hipcGetBufferSize(r->hipc.data.recv_buffers)
);
return GetVersionString((char *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
hipcGetBufferSize(r->hipc.data.recv_buffers));
}
break;
@@ -179,7 +178,8 @@ namespace ipcService {
if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) {
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
if (bufSize >= sizeof(HocClkTitleProfileList)) {
return GetProfiles((std::uint64_t*)r->data.ptr, (HocClkTitleProfileList*)hipcGetBufferAddress(r->hipc.data.recv_buffers));
return GetProfiles((std::uint64_t *)r->data.ptr,
(HocClkTitleProfileList *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
}
}
break;
@@ -223,12 +223,9 @@ namespace ipcService {
case HocClkIpcCmd_GetFreqList:
if (r->data.size >= sizeof(HocClkIpc_GetFreqList_Args) && r->hipc.meta.num_recv_buffers >= 1) {
*out_dataSize = sizeof(std::uint32_t);
return GetFreqList(
(HocClkIpc_GetFreqList_Args*)r->data.ptr,
return GetFreqList((HocClkIpc_GetFreqList_Args *)r->data.ptr,
(std::uint32_t *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
hipcGetBufferSize(r->hipc.data.recv_buffers),
(std::uint32_t*)out_data
);
hipcGetBufferSize(r->hipc.data.recv_buffers), (std::uint32_t *)out_data);
}
break;
@@ -259,7 +256,7 @@ namespace ipcService {
}
}
}
} // namespace
void Initialize() {
std::int32_t priority;
@@ -297,4 +294,4 @@ namespace ipcService {
}
}
}
} // namespace ipcService

View File

@@ -35,4 +35,4 @@ namespace ipcService {
void Exit();
void SetRunning(bool running);
}
} // namespace ipcService

View File

@@ -27,21 +27,20 @@
#include <cstdlib>
#include <cstring>
#include <malloc.h>
#include <switch.h>
#include "board/board.hpp"
#include "file/config.hpp"
#include "file/errors.hpp"
#include "file/file_utils.hpp"
#include "board/board.hpp"
#include "hos/process_management.hpp"
#include "mgr/clock_manager.hpp"
#include "ipc/ipc_service.hpp"
#include "file/config.hpp"
#include "mgr/clock_manager.hpp"
#define INNER_HEAP_SIZE 0x40000
extern "C"
{
extern "C" {
void virtmemSetup(void);
extern std::uint32_t __start__;
@@ -72,8 +71,7 @@ extern "C"
return;
}
void __libnx_initheap(void)
{
void __libnx_initheap(void) {
void *addr = nx_inner_heap;
size_t size = nx_inner_heap_size;
@@ -87,16 +85,13 @@ extern "C"
virtmemSetup();
}
void __appInit(void)
{
if (R_FAILED(smInitialize()))
{
void __appInit(void) {
if (R_FAILED(smInitialize())) {
fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
}
Result rc = setsysInitialize();
if (R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
SetSysFirmwareVersion fw;
rc = setsysGetFirmwareVersion(&fw);
if (R_SUCCEEDED(rc))
@@ -111,11 +106,9 @@ extern "C"
rc = i2cInitialize();
if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
}
void __appExit(void)
{
void __appExit(void) {
// CloseFanControllerThread();
// fanExit();
i2cExit();
@@ -126,11 +119,9 @@ extern "C"
}
}
int main(int argc, char** argv)
{
int main(int argc, char **argv) {
Result rc = fileUtils::Initialize();
if (R_FAILED(rc))
{
if (R_FAILED(rc)) {
fatalThrow(rc);
return 1;
}
@@ -145,7 +136,6 @@ int main(int argc, char** argv)
clockManager::Initialize();
ipcService::Initialize();
clockManager::SetRunning(true);
config::SetEnabled(true);
ipcService::SetRunning(true);
@@ -154,8 +144,7 @@ int main(int argc, char** argv)
// InitFanController(table);
// StartFanControllerThread();
while (clockManager::Running())
{
while (clockManager::Running()) {
clockManager::Tick();
clockManager::WaitForNextTick();
}

View File

@@ -16,8 +16,10 @@
*/
#include <switch.h>
#include "../file/file_utils.hpp"
Result QueryMemoryMapping(u64 *virtaddr, u64 physaddr, u64 size) {
if (hosversionAtLeast(10, 0, 0)) {
u64 out_size;

View File

@@ -24,32 +24,31 @@
* --------------------------------------------------------------------------
*/
#include "clock_manager.hpp"
#include <cstring>
#include "../file/file_utils.hpp"
#include "../board/board.hpp"
#include "../hos/process_management.hpp"
#include "../file/errors.hpp"
#include "../ipc/ipc_service.hpp"
#include "../file/kip.hpp"
#include <i2c.h>
#include "../i2c/i2cDrv.h"
#include "../display/display_refresh_rate.hpp"
#include <cstdio>
#include <crc32.h>
#include "../file/config.hpp"
#include "../hos/integrations.hpp"
#include "../util/lockable_mutex.h"
#include "../file/kip.hpp"
#include "governor.hpp"
#include <cstdio>
#include <cstring>
#include <i2c.h>
#include "../board/board.hpp"
#include "../display/aula.hpp"
#include "../display/display_refresh_rate.hpp"
#include "../file/config.hpp"
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "../file/kip.hpp"
#include "../hos/integrations.hpp"
#include "../hos/process_management.hpp"
#include "../i2c/i2cDrv.h"
#include "../ipc/ipc_service.hpp"
#include "../soc/gm20b.hpp"
#include "../util/lockable_mutex.h"
#include "clock_manager.hpp"
#include "governor.hpp"
#define HOSPPC_HAS_BOOST (hosversionAtLeast(7, 0, 0))
namespace clockManager {
bool gRunning = false;
LockableMutex gContextMutex;
HocClkContext gContext = {};
@@ -59,8 +58,7 @@ namespace clockManager {
std::uint64_t gLastPowerLogNs = 0;
std::uint64_t gLastCsvWriteNs = 0;
bool IsAssignableHz(HocClkModule module, std::uint32_t hz)
{
bool IsAssignableHz(HocClkModule module, std::uint32_t hz) {
switch (module) {
case HocClkModule_CPU:
return hz >= 500000000;
@@ -71,8 +69,7 @@ namespace clockManager {
}
}
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile)
{
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile) {
if (config::GetConfigValue(HocClkConfigValue_UncappedClocks)) {
return ~0; // Integer limit, uncapped clocks ON
} else {
@@ -144,8 +141,7 @@ namespace clockManager {
return 0;
}
std::uint32_t GetNearestHz(HocClkModule module, std::uint32_t inHz, std::uint32_t maxHz)
{
std::uint32_t GetNearestHz(HocClkModule module, std::uint32_t inHz, std::uint32_t maxHz) {
std::uint32_t *freqs = &gFreqTable[module].list[0];
size_t count = gFreqTable[module].count - 1;
@@ -163,21 +159,20 @@ namespace clockManager {
return freqs[i];
}
void ResetToStockClocks()
{
void ResetToStockClocks() {
board::ResetToStockCpu();
if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
else
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
}
board::ResetToStockGpu();
}
bool ConfigIntervalTimeout(HocClkConfigValue intervalMsConfigValue, std::uint64_t ns, std::uint64_t *lastLogNs)
{
bool ConfigIntervalTimeout(HocClkConfigValue intervalMsConfigValue, std::uint64_t ns, std::uint64_t *lastLogNs) {
std::uint64_t logInterval = config::GetConfigValue(intervalMsConfigValue) * 1000000ULL;
bool shouldLog = logInterval && ((ns - *lastLogNs) > logInterval);
@@ -188,8 +183,7 @@ namespace clockManager {
return shouldLog;
}
void RefreshFreqTableRow(HocClkModule module)
{
void RefreshFreqTableRow(HocClkModule module) {
std::scoped_lock lock{ gContextMutex };
std::uint32_t freqs[HOCCLK_FREQ_LIST_MAX];
@@ -201,15 +195,16 @@ namespace clockManager {
std::uint32_t *hz = &gFreqTable[module].list[0];
gFreqTable[module].count = 0;
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko
&& config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) {
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko &&
config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) {
constexpr u32 kStep = 38400000;
constexpr u32 kPcvStep = 76800000;
u32 kMax = ~0;
for (u32 i = 0; i < count; i++) {
for (u32 j = 0; j < count; j++) {
if (freqs[j] + kStep == freqs[i]) {
if (freqs[j] < kMax) kMax = freqs[j];
if (freqs[j] < kMax)
kMax = freqs[j];
break;
}
}
@@ -217,7 +212,8 @@ namespace clockManager {
if (kMax == ~0u) {
kMax = 0;
for (u32 i = 0; i < count; i++) {
if (freqs[i] > kMax) kMax = freqs[i];
if (freqs[i] > kMax)
kMax = freqs[i];
}
}
@@ -264,32 +260,19 @@ namespace clockManager {
u32 hz;
HocClkConfigValue kval;
} eristaGpuVoltMap[] = {
{ 76800000, KipConfigValue_g_volt_e_76800 },
{ 115200000, KipConfigValue_g_volt_e_115200 },
{ 153600000, KipConfigValue_g_volt_e_153600 },
{ 192000000, KipConfigValue_g_volt_e_192000 },
{ 230400000, KipConfigValue_g_volt_e_230400 },
{ 268800000, KipConfigValue_g_volt_e_268800 },
{ 307200000, KipConfigValue_g_volt_e_307200 },
{ 345600000, KipConfigValue_g_volt_e_345600 },
{ 384000000, KipConfigValue_g_volt_e_384000 },
{ 422400000, KipConfigValue_g_volt_e_422400 },
{ 460800000, KipConfigValue_g_volt_e_460800 },
{ 499200000, KipConfigValue_g_volt_e_499200 },
{ 537600000, KipConfigValue_g_volt_e_537600 },
{ 576000000, KipConfigValue_g_volt_e_576000 },
{ 614400000, KipConfigValue_g_volt_e_614400 },
{ 652800000, KipConfigValue_g_volt_e_652800 },
{ 691200000, KipConfigValue_g_volt_e_691200 },
{ 729600000, KipConfigValue_g_volt_e_729600 },
{ 768000000, KipConfigValue_g_volt_e_768000 },
{ 806400000, KipConfigValue_g_volt_e_806400 },
{ 844800000, KipConfigValue_g_volt_e_844800 },
{ 883200000, KipConfigValue_g_volt_e_883200 },
{ 921600000, KipConfigValue_g_volt_e_921600 },
{ 960000000, KipConfigValue_g_volt_e_960000 },
{ 998400000, KipConfigValue_g_volt_e_998400 },
{1036800000, KipConfigValue_g_volt_e_1036800 },
{ 76800000, KipConfigValue_g_volt_e_76800 }, { 115200000, KipConfigValue_g_volt_e_115200 },
{ 153600000, KipConfigValue_g_volt_e_153600 }, { 192000000, KipConfigValue_g_volt_e_192000 },
{ 230400000, KipConfigValue_g_volt_e_230400 }, { 268800000, KipConfigValue_g_volt_e_268800 },
{ 307200000, KipConfigValue_g_volt_e_307200 }, { 345600000, KipConfigValue_g_volt_e_345600 },
{ 384000000, KipConfigValue_g_volt_e_384000 }, { 422400000, KipConfigValue_g_volt_e_422400 },
{ 460800000, KipConfigValue_g_volt_e_460800 }, { 499200000, KipConfigValue_g_volt_e_499200 },
{ 537600000, KipConfigValue_g_volt_e_537600 }, { 576000000, KipConfigValue_g_volt_e_576000 },
{ 614400000, KipConfigValue_g_volt_e_614400 }, { 652800000, KipConfigValue_g_volt_e_652800 },
{ 691200000, KipConfigValue_g_volt_e_691200 }, { 729600000, KipConfigValue_g_volt_e_729600 },
{ 768000000, KipConfigValue_g_volt_e_768000 }, { 806400000, KipConfigValue_g_volt_e_806400 },
{ 844800000, KipConfigValue_g_volt_e_844800 }, { 883200000, KipConfigValue_g_volt_e_883200 },
{ 921600000, KipConfigValue_g_volt_e_921600 }, { 960000000, KipConfigValue_g_volt_e_960000 },
{ 998400000, KipConfigValue_g_volt_e_998400 }, { 1036800000, KipConfigValue_g_volt_e_1036800 },
{ 1075200000, KipConfigValue_g_volt_e_1075200 },
};
bool skip = false;
@@ -301,7 +284,8 @@ namespace clockManager {
break;
}
}
if (skip) continue;
if (skip)
continue;
}
*hz = freqs[i];
@@ -314,14 +298,15 @@ namespace clockManager {
fileUtils::LogLine("[mgr] count = %u", gFreqTable[module].count);
}
bool HandleSafetyFeatures(bool isBoost)
{
if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) && config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
bool HandleSafetyFeatures(bool isBoost) {
if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) &&
config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
ResetToStockClocks();
return true;
}
if (config::GetConfigValue(HocClkConfigValue_AutoRAMCPUOverclock) && !isBoost && !governor::isCpuGovernorEnabled && (board::GetSocType() == HocClkSocType_Mariko)) {
if (config::GetConfigValue(HocClkConfigValue_AutoRAMCPUOverclock) && !isBoost && !governor::isCpuGovernorEnabled &&
(board::GetSocType() == HocClkSocType_Mariko)) {
u32 ramHz = gContext.freqs[HocClkModule_MEM];
u32 threshold = (u32)config::GetConfigValue(HocClkConfigValue_AutoRamCpuRamOCThreshold) * 1000;
if (ramHz >= threshold) {
@@ -339,8 +324,7 @@ namespace clockManager {
}
return false;
}
void HandleMiscFeatures()
{
void HandleMiscFeatures() {
// these dont need to run that often, so dont bother
static u32 tick = 0;
@@ -394,9 +378,7 @@ namespace clockManager {
}
}
void DVFSReset()
{
void DVFSReset() {
if (config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) {
board::PcvHijackGpuVolts(0); // Reset to vMin
@@ -416,8 +398,7 @@ namespace clockManager {
}
}
void HandleFreqReset(HocClkModule module, bool isBoost, bool didHijackPcv)
{
void HandleFreqReset(HocClkModule module, bool isBoost, bool didHijackPcv) {
switch (module) {
case HocClkModule_CPU:
if (!(isBoost || (config::GetConfigValue(HocClkConfigValue_OverwriteBoostMode) && isBoost)))
@@ -426,7 +407,9 @@ namespace clockManager {
if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
else
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow),
config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
}
break;
case HocClkModule_GPU:
@@ -449,8 +432,7 @@ namespace clockManager {
}
}
void SetClocks(bool isBoost)
{
void SetClocks(bool isBoost) {
std::uint32_t targetHz = 0;
std::uint32_t maxHz = 0;
std::uint32_t nearestHz = 0;
@@ -521,12 +503,9 @@ namespace clockManager {
nearestHz = GetNearestHz((HocClkModule)module, targetHz, maxHz);
if (nearestHz != gContext.freqs[module]) {
fileUtils::LogLine(
"[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)",
board::GetModuleName((HocClkModule)module, true),
nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10,
targetHz / 1000000, targetHz / 100000 - targetHz / 1000000 * 10
);
fileUtils::LogLine("[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", board::GetModuleName((HocClkModule)module, true),
nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10, targetHz / 1000000,
targetHz / 100000 - targetHz / 1000000 * 10);
// The logic MUST be done in this order otherwise you WILL get crashes
if (module == HocClkModule_MEM && targetHz > oldHz && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) {
@@ -553,8 +532,7 @@ namespace clockManager {
}
}
bool RefreshContext()
{
bool RefreshContext() {
bool hasChanged = false;
std::uint32_t mode = 0;
@@ -589,7 +567,8 @@ namespace clockManager {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
hz = board::GetHz((HocClkModule)module);
if (hz != 0 && hz != gContext.freqs[module]) {
fileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
fileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000,
hz / 100000 - hz / 1000000 * 10);
gContext.freqs[module] = hz;
if (module < HocClkModuleStable_EnumMax) {
@@ -601,7 +580,8 @@ namespace clockManager {
hz = config::GetOverrideHz((HocClkModule)module);
if (hz != gContext.overrideFreqs[module]) {
if (hz) {
fileUtils::LogLine("[mgr] %s override change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
fileUtils::LogLine("[mgr] %s override change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000,
hz / 100000 - hz / 1000000 * 10);
}
gContext.overrideFreqs[module] = hz;
@@ -620,7 +600,8 @@ namespace clockManager {
for (unsigned int sensor = 0; sensor < HocClkThermalSensor_EnumMax; sensor++) {
millis = board::GetTemperatureMilli((HocClkThermalSensor)sensor);
if (shouldLogTemp) {
fileUtils::LogLine("[mgr] %s temp: %u.%u °C", board::GetThermalSensorName((HocClkThermalSensor)sensor, true), millis / 1000, (millis - millis / 1000 * 1000) / 100);
fileUtils::LogLine("[mgr] %s temp: %u.%u °C", board::GetThermalSensorName((HocClkThermalSensor)sensor, true), millis / 1000,
(millis - millis / 1000 * 1000) / 100);
}
gContext.temps[sensor] = millis;
@@ -650,7 +631,8 @@ namespace clockManager {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
realHz = board::GetRealHz((HocClkModule)module);
if (shouldLogFreq) {
fileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), realHz / 1000000, realHz / 100000 - realHz / 1000000 * 10);
fileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), realHz / 1000000,
realHz / 100000 - realHz / 1000000 * 10);
}
gContext.realFreqs[module] = realHz;
@@ -704,8 +686,7 @@ namespace clockManager {
return hasChanged;
}
void Initialize()
{
void Initialize() {
gContext = {};
gContext.applicationId = 0;
gContext.profile = HocClkProfile_Handheld;
@@ -744,7 +725,8 @@ namespace clockManager {
gContext.isDram8GB = board::IsDram8GB();
gContext.consoleType = board::GetConsoleType();
board::SetGpuSchedulingMode((GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling), (GpuSchedulingOverrideMethod)config::GetConfigValue(HocClkConfigValue_GPUSchedulingMethod));
board::SetGpuSchedulingMode((GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling),
(GpuSchedulingOverrideMethod)config::GetConfigValue(HocClkConfigValue_GPUSchedulingMethod));
gContext.gpuSchedulingMode = (GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling);
gContext.isSysDockInstalled = integrations::GetSysDockState();
@@ -757,37 +739,31 @@ namespace clockManager {
governor::startThreads();
}
void Exit()
{
void Exit() {
governor::exitThreads();
}
HocClkContext GetCurrentContext()
{
HocClkContext GetCurrentContext() {
std::scoped_lock lock{ gContextMutex };
return gContext;
}
void SetRunning(bool running)
{
void SetRunning(bool running) {
gRunning = running;
}
bool Running()
{
bool Running() {
return gRunning;
}
void GetFreqList(HocClkModule module, std::uint32_t *list, std::uint32_t maxCount, std::uint32_t *outCount)
{
void GetFreqList(HocClkModule module, std::uint32_t *list, std::uint32_t maxCount, std::uint32_t *outCount) {
ASSERT_ENUM_VALID(HocClkModule, module);
*outCount = std::min(maxCount, gFreqTable[module].count);
memcpy(list, &gFreqTable[module].list[0], *outCount * sizeof(gFreqTable[0].list[0]));
}
void Tick()
{
void Tick() {
std::scoped_lock lock{ gContextMutex };
std::uint32_t mode = 0;
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
@@ -799,13 +775,13 @@ namespace clockManager {
HandleMiscFeatures();
// GPU clock should always be the same unless PCV has overwriten our change, so reset it
if ((RefreshContext() || config::Refresh() || (board::GetRealHz(HocClkModule_GPU) != gContext.freqs[HocClkModule_GPU])) && !shouldSkipClockSet) {
if ((RefreshContext() || config::Refresh() || (board::GetRealHz(HocClkModule_GPU) != gContext.freqs[HocClkModule_GPU])) &&
!shouldSkipClockSet) {
SetClocks(isBoost);
}
}
void WaitForNextTick()
{
void WaitForNextTick() {
if (board::GetHz(HocClkModule_MEM) > 665000000)
svcSleepThread(config::GetConfigValue(HocClkConfigValue_PollingIntervalMs) * 1000000ULL);
else

View File

@@ -28,6 +28,7 @@
#include <hocclk.h>
#include <switch.h>
#include "../util/lockable_mutex.h"
namespace clockManager {
@@ -37,7 +38,6 @@ namespace clockManager {
std::uint32_t list[HOCCLK_FREQ_LIST_MAX];
};
extern bool hasChanged;
// instance variables
@@ -50,7 +50,6 @@ namespace clockManager {
extern std::uint64_t gLastPowerLogNs;
extern std::uint64_t gLastCsvWriteNs;
void Initialize();
void Exit();
@@ -66,4 +65,4 @@ namespace clockManager {
void Tick();
void WaitForNextTick();
}
} // namespace clockManager

View File

@@ -15,9 +15,10 @@
*
*/
#include "governor.hpp"
#include "../hos/process_management.hpp"
#include "governor.hpp"
#include <hocclk/clock_manager.h>
namespace governor {
#define POLL_NS 5'000'000 // 5 ms governor poll rate
@@ -44,8 +45,10 @@ namespace governor {
}
auto resolve = [](u8 app, u8 temp) -> u8 {
if (temp == ComponentGovernor_Disabled) return ComponentGovernor_Disabled;
if (temp != ComponentGovernor_DoNotOverride) return temp;
if (temp == ComponentGovernor_Disabled)
return ComponentGovernor_Disabled;
if (temp != ComponentGovernor_DoNotOverride)
return temp;
return app;
};
@@ -68,8 +71,10 @@ namespace governor {
if (newVrrGovernorState == false && lastVrrGovernorState == true)
board::ResetToStockDisplay();
if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState || newVrrGovernorState != lastVrrGovernorState) {
fileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled", newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled");
if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState ||
newVrrGovernorState != lastVrrGovernorState) {
fileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled",
newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled");
lastCpuGovernorState = newCpuGovernorState;
lastGpuGovernorState = newGpuGovernorState;
lastVrrGovernorState = newVrrGovernorState;
@@ -91,13 +96,9 @@ namespace governor {
u32 ResolveTargetHz(HocClkModule module) {
u32 hz = clockManager::gContext.overrideFreqs[module];
if (!hz)
hz = config::GetAutoClockHz(
clockManager::gContext.applicationId, module,
clockManager::gContext.profile, false);
hz = config::GetAutoClockHz(clockManager::gContext.applicationId, module, clockManager::gContext.profile, false);
if (!hz)
hz = config::GetAutoClockHz(
HOCCLK_GLOBAL_PROFILE_TID, module,
clockManager::gContext.profile, false);
hz = config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, module, clockManager::gContext.profile, false);
return hz;
}
@@ -248,9 +249,11 @@ namespace governor {
u32 targetHz = clockManager::gContext.overrideFreqs[HocClkModule_Display];
if (!targetHz) {
targetHz = config::GetAutoClockHz(clockManager::gContext.applicationId, HocClkModule_Display, clockManager::gContext.profile, false);
targetHz = config::GetAutoClockHz(clockManager::gContext.applicationId, HocClkModule_Display,
clockManager::gContext.profile, false);
if (!targetHz)
targetHz = config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, HocClkModule_Display, clockManager::gContext.profile, false);
targetHz =
config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, HocClkModule_Display, clockManager::gContext.profile, false);
}
u8 maxDisplay = targetHz ? (u8)targetHz : 60;
@@ -292,19 +295,11 @@ namespace governor {
}
void startThreads() {
threadCreate(
&governorTHREAD,
GovernorThread,
nullptr,
NULL,
0x2000,
0x3F,
-2
);
threadCreate(&governorTHREAD, GovernorThread, nullptr, NULL, 0x2000, 0x3F, -2);
threadStart(&governorTHREAD);
}
void exitThreads() {
threadClose(&governorTHREAD);
}
}
} // namespace governor

View File

@@ -15,17 +15,18 @@
*
*/
#include <switch.h>
#include <hocclk.h>
#include "../board/board.hpp"
#include "clock_manager.hpp"
#include <cstring>
#include "../file/file_utils.hpp"
#include <hocclk.h>
#include <switch.h>
#include "../board/board.hpp"
#include "../file/errors.hpp"
#include "../file/config.hpp"
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "../hos/integrations.hpp"
#include "../util/lockable_mutex.h"
#include "clock_manager.hpp"
namespace governor {
extern bool isCpuGovernorInBoostMode;
@@ -38,4 +39,4 @@ namespace governor {
void startThreads();
void exitThreads();
void HandleGovernor(uint32_t targetHz);
}
} // namespace governor

View File

@@ -15,8 +15,9 @@
*
*/
#include <switch.h>
#include <cstring>
#include <switch.h>
#include "battery.h"
// Internal PSM service handle
@@ -24,16 +25,7 @@ static Service g_psmService = {0};
static bool g_batteryInfoInitialized = false;
static const char *s_chargerTypeStrings[] = {
"None",
"Power Delivery",
"USB-C @ 1.5A",
"USB-C @ 3.0A",
"USB-DCP",
"USB-CDP",
"USB-SDP",
"Apple @ 0.5A",
"Apple @ 1.0A",
"Apple @ 2.0A",
"None", "Power Delivery", "USB-C @ 1.5A", "USB-C @ 3.0A", "USB-DCP", "USB-CDP", "USB-SDP", "Apple @ 0.5A", "Apple @ 1.0A", "Apple @ 2.0A",
};
static const char *s_powerRoleStrings[] = {
@@ -42,12 +34,7 @@ static const char* s_powerRoleStrings[] = {
"Source",
};
static const char* s_pdStateStrings[] = {
"Unknown",
"New PDO Received",
"No PD Source",
"RDO Accepted"
};
static const char *s_pdStateStrings[] = { "Unknown", "New PDO Received", "No PD Source", "RDO Accepted" };
// Internal PSM command implementations
static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) {

View File

@@ -16,9 +16,9 @@
*/
#pragma once
#include <switch.h>
#include <inttypes.h>
#include <string.h>
#include <switch.h>
typedef enum {
BatteryFlag_NoHub = BIT(0), // Hub is disconnected
BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail

View File

@@ -297,18 +297,8 @@
#define FUSE_ARRAY_WORDS_NUM 192
#define FUSE_ARRAY_WORDS_NUM_B01 256
enum
{
FUSE_NX_HW_TYPE_ICOSA,
FUSE_NX_HW_TYPE_IOWA,
FUSE_NX_HW_TYPE_HOAG,
FUSE_NX_HW_TYPE_AULA
};
enum { FUSE_NX_HW_TYPE_ICOSA, FUSE_NX_HW_TYPE_IOWA, FUSE_NX_HW_TYPE_HOAG, FUSE_NX_HW_TYPE_AULA };
enum
{
FUSE_NX_HW_STATE_PROD,
FUSE_NX_HW_STATE_DEV
};
enum { FUSE_NX_HW_STATE_PROD, FUSE_NX_HW_STATE_DEV };
#endif

View File

@@ -17,9 +17,9 @@
*
*/
#include "gm20b.hpp"
#include "../mapping/mem_map.hpp"
#include "gm20b.hpp"
namespace gm20b {
u64 gpu_base = 0;
@@ -78,12 +78,8 @@ namespace gm20b {
}
static void _clk_setup_slide() {
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2,
GPCPLL_CFG2_STEPA_MASK,
0x04u << GPCPLL_CFG2_STEPA_SHIFT);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG3,
GPCPLL_CFG3_STEPB_MASK,
0x05u << GPCPLL_CFG3_STEPB_SHIFT);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_STEPA_MASK, 0x04u << GPCPLL_CFG2_STEPA_SHIFT);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG3, GPCPLL_CFG3_STEPB_MASK, 0x05u << GPCPLL_CFG3_STEPB_SHIFT);
}
static bool _gpu_pllg_slide(u32 new_divn) {
@@ -95,9 +91,7 @@ namespace gm20b {
_clk_setup_slide();
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL,
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_SDM_DIN_NEW_MASK, 0);
@@ -106,9 +100,7 @@ namespace gm20b {
GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_COEFF) = coeff;
usleep(1);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
NDIV_SLOWDOWN_EN_DYNRAMP,
NDIV_SLOWDOWN_EN_DYNRAMP);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_EN_DYNRAMP, NDIV_SLOWDOWN_EN_DYNRAMP);
int ramp_timeout = RAMP_TIMEOUT_US;
bool success = false;
@@ -125,9 +117,7 @@ namespace gm20b {
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_SDM_DIN_MASK, 0);
}
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP,
0);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP, 0);
(void)GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN);
return success;
@@ -149,9 +139,11 @@ namespace gm20b {
u32 new_divn = (u64)khz * divm * divp * 2 / osc_khz;
// L4T clamps the registers here for some reason, do that
if (new_divn < 8) new_divn = 8;
if (new_divn > 255) new_divn = 255;
if (new_divn < 8)
new_divn = 8;
if (new_divn > 255)
new_divn = 255;
return _gpu_pllg_slide(new_divn);
}
}
} // namespace gm20b

View File

@@ -113,4 +113,4 @@ namespace pllmb {
u32 pllm = ptoGetMHz(CLK_PLLM, 2, PLLM_MISC2, BIT(8));
return pllmb == 0 ? pllm : pllmb; // pllmb is zeroed out at times, fallback to pllm
}
}
} // namespace pllmb

View File

@@ -19,10 +19,12 @@
#pragma once
#include <cstdint>
#include <switch.h>
#include <hocclk.h>
#include "../board/board.hpp"
#include <registers.h>
#include <switch.h>
#include "../board/board.hpp"
namespace pllmb {
u64 getRamClockRatePLLMB();

View File

@@ -80,8 +80,7 @@
#define ACTMON_DEV_BASE (ACTMON_BASE + 0x80)
#define ACTMON(x) (*(volatile u32 *)(ACTMON_BASE + (x)))
typedef enum _actmon_dev_t
{
typedef enum _actmon_dev_t {
ACTMON_DEV_CPU,
ACTMON_DEV_BPMP,
ACTMON_DEV_AHB,
@@ -93,8 +92,7 @@ typedef enum _actmon_dev_t
ACTMON_DEV_NUM,
} actmon_dev_t;
typedef struct _actmon_dev_reg_t
{
typedef struct _actmon_dev_reg_t {
vu32 ctrl;
vu32 upper_wnark;
vu32 lower_wmark;
@@ -122,8 +120,7 @@ static u32 g_emc_bw_all = 0;
static u32 g_emc_bw_cpu = 0;
static u32 g_emc_bw_gpu = 0;
static u32 _clock_get_dev_freq(u32 id, u32 multiplier)
{
static u32 _clock_get_dev_freq(u32 id, u32 multiplier) {
const u32 pto_win = 16;
const u32 pto_osc = 32768;
@@ -158,8 +155,7 @@ static u32 _clock_get_dev_freq(u32 id, u32 multiplier)
return freq_khz;
}
static void _actmon_dev_enable(actmon_dev_t dev, u32 freq, u32 weight)
{
static void _actmon_dev_enable(actmon_dev_t dev, u32 freq, u32 weight) {
actmon_dev_reg_t *regs = (actmon_dev_reg_t *)(ACTMON_DEV_BASE + (dev * ACTMON_DEV_SIZE));
regs->init_avg = (u32)freq * ACTMON_PERIOD_MS / 2;
@@ -168,72 +164,58 @@ static void _actmon_dev_enable(actmon_dev_t dev, u32 freq, u32 weight)
regs->ctrl = ACTMON_DEV_CTRL_ENB | ACTMON_DEV_CTRL_ENB_PERIODIC | ACTMON_DEV_CTRL_K_VAL(3); // 8 samples average.
}
static u32 _actmon_dev_get_count_avg(actmon_dev_t dev)
{
static u32 _actmon_dev_get_count_avg(actmon_dev_t dev) {
actmon_dev_reg_t *regs = (actmon_dev_reg_t *)(ACTMON_DEV_BASE + (dev * ACTMON_DEV_SIZE));
return regs->avg_count;
}
static inline Result _svcQueryMemoryMappingFallback(u64* virtaddr, u64 physaddr, u64 size)
{
if(hosversionAtLeast(10,0,0))
{
static inline Result _svcQueryMemoryMappingFallback(u64 *virtaddr, u64 physaddr, u64 size) {
if (hosversionAtLeast(10, 0, 0)) {
u64 out_size;
return svcQueryMemoryMapping(virtaddr, &out_size, physaddr, size);
}
else
{
} else {
return svcLegacyQueryIoMapping(virtaddr, physaddr, size);
}
}
static void _clock_update_freqs(void)
{
static void _clock_update_freqs(void) {
u64 ticks = armGetSystemTick();
if(armTicksToNs(ticks - g_update_ticks) <= WAIT_NS)
{
if (armTicksToNs(ticks - g_update_ticks) <= WAIT_NS) {
return;
}
g_update_ticks = ticks;
if (!g_clk_base)
{
if (!g_clk_base) {
_svcQueryMemoryMappingFallback(&g_clk_base, 0x60006000ul, 0x1000);
}
if(!g_clk_base)
{
if (!g_clk_base) {
return;
}
g_mem_freq = _clock_get_dev_freq(CLK_PTO_EMC, 1);
g_cpu_freq = _clock_get_dev_freq(CLK_PTO_CCLK_G_DIV2, 2);
if (!g_gpu_base)
{
if (!g_gpu_base) {
_svcQueryMemoryMappingFallback(&g_gpu_base, 0x57000000ul, 0x1000000);
}
if (!g_gpu_base)
{
if (!g_gpu_base) {
return;
}
bool gpu_enabled = (CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_X) & BIT(24)) && !(CLOCK(CLK_RST_CONTROLLER_RST_DEVICES_X) & BIT(24));
if(!gpu_enabled)
{
if (!gpu_enabled) {
return;
}
if (!g_act_base)
{
if (!g_act_base) {
_svcQueryMemoryMappingFallback(&g_act_base, 0x6000C000ul, 0x1000);
}
if(!g_act_base)
{
if (!g_act_base) {
return;
}
@@ -247,8 +229,7 @@ static void _clock_update_freqs(void)
u32 emc_freq = g_mem_freq / 1000;
// Check if actmon is disabled
if (!(ACTMON(ACTMON_GLB_STATUS) & ACTMON_MCALL_MON_ACT))
{
if (!(ACTMON(ACTMON_GLB_STATUS) & ACTMON_MCALL_MON_ACT)) {
ACTMON(ACTMON_GLB_PERIOD_CTRL) = ACTMON_GLB_PERIOD_SAMPLE(ACTMON_PERIOD_MS);
_actmon_dev_enable(ACTMON_DEV_MC_ALL, emc_freq, 256 * 4);
}
@@ -270,57 +251,47 @@ static void _clock_update_freqs(void)
g_emc_bw_gpu = g_emc_bw_all - g_emc_bw_cpu;
}
u32 t210ClkCpuFreq(void)
{
u32 t210ClkCpuFreq(void) {
_clock_update_freqs();
return g_cpu_freq;
}
u32 t210ClkMemFreq(void)
{
u32 t210ClkMemFreq(void) {
_clock_update_freqs();
return g_mem_freq;
}
u32 t210ClkGpuFreq(void)
{
u32 t210ClkGpuFreq(void) {
_clock_update_freqs();
return g_gpu_freq;
}
u32 t210EmcLoadAll()
{
u32 t210EmcLoadAll() {
_clock_update_freqs();
return g_emc_lall;
}
u32 t210EmcLoadCpu()
{
u32 t210EmcLoadCpu() {
_clock_update_freqs();
return g_emc_lcpu;
}
u32 t210EmcBwAll()
{
u32 t210EmcBwAll() {
_clock_update_freqs();
return g_emc_bw_all;
}
u32 t210EmcBwCpu()
{
u32 t210EmcBwCpu() {
_clock_update_freqs();
return g_emc_bw_cpu;
}
u32 t210EmcBwGpu()
{
u32 t210EmcBwGpu() {
_clock_update_freqs();
return g_emc_bw_gpu;
}
u32 t210EmcBwPeak()
{
u32 t210EmcBwPeak() {
_clock_update_freqs();
return ((u64)g_mem_freq * 16) / 1000000;
}

View File

@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>

Some files were not shown because too many files have changed in this diff Show More