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 IndentAccessModifiers: false
AccessModifierOffset: 0 AccessModifierOffset: 0
NamespaceIndentation: All NamespaceIndentation: All
IndentPPDirectives: BeforeHash
BreakBeforeBraces: Attach BreakBeforeBraces: Attach
BraceWrapping: BraceWrapping:

View File

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

View File

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

View File

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

View File

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

View File

@@ -24,16 +24,18 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "base_gui.h"
#include "../elements/base_frame.h" #include "../elements/base_frame.h"
#include "base_gui.h"
void BaseFrame::draw(tsl::gfx::Renderer* renderer) {
void BaseFrame::draw(tsl::gfx::Renderer *renderer) {
tsl::elm::HeaderOverlayFrame::draw(renderer); tsl::elm::HeaderOverlayFrame::draw(renderer);
this->gui->preDraw(renderer); this->gui->preDraw(renderer);
} }
#include <tesla.hpp>
#include <math.h> #include <math.h>
#include <tesla.hpp>
#define LOGO_Y_REAL 65 #define LOGO_Y_REAL 65
@@ -53,8 +55,8 @@ void BaseFrame::draw(tsl::gfx::Renderer* renderer) {
#define VERSION_FONT_SIZE 15 #define VERSION_FONT_SIZE 15
extern "C" { extern "C" {
extern const u8 hoc_rgba[]; extern const u8 hoc_rgba[];
extern const u32 hoc_rgba_size; extern const u32 hoc_rgba_size;
} }
std::string getVersionString() { std::string getVersionString() {
@@ -66,19 +68,13 @@ std::string getVersionString() {
return std::string(buf); return std::string(buf);
} }
static constexpr tsl::Color dynamicLogoRGB1 = tsl::Color( 7, 15, 15, 15); static constexpr tsl::Color dynamicLogoRGB1 = tsl::Color(7, 15, 15, 15);
static constexpr tsl::Color dynamicLogoRGB2 = tsl::Color( 2, 8, 11, 15); static constexpr tsl::Color dynamicLogoRGB2 = tsl::Color(2, 8, 11, 15);
static constexpr tsl::Color STATIC_TEAL = tsl::Color( 7, 15, 15, 15); static constexpr tsl::Color STATIC_TEAL = tsl::Color(7, 15, 15, 15);
const std::string name = " Horizon OC"; const std::string name = " Horizon OC";
static s32 drawDynamicUltraText( static s32 drawDynamicUltraText(tsl::gfx::Renderer *renderer, s32 startX, s32 y, u32 fontSize, const tsl::Color &staticColor,
tsl::gfx::Renderer* renderer, bool useNotificationMethod = false) {
s32 startX,
s32 y,
u32 fontSize,
const tsl::Color& staticColor,
bool useNotificationMethod = false)
{
static constexpr double cycleDuration = 1.6; static constexpr double cycleDuration = 1.6;
s32 currentX = startX; s32 currentX = startX;
@@ -88,10 +84,10 @@ static s32 drawDynamicUltraText(
const double waveScale = 2.0 * M_PI / cycleDuration; 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]; char letter = name[i];
if (letter == '\0') break; if (letter == '\0')
break;
double phase = waveScale * (timeNow + i * 0.12); 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 glow = (cos(phase * 1.5) + 1.0) * 0.5;
double brightness = 0.75 + glow * 0.25; double brightness = 0.75 + glow * 0.25;
u8 r = static_cast<u8>( u8 r = static_cast<u8>(((int)dynamicLogoRGB1.r + ((int)dynamicLogoRGB2.r - (int)dynamicLogoRGB1.r) * blend) * brightness);
((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 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); r = std::clamp<u8>(r, 0, 15);
g = std::clamp<u8>(g, 0, 15); g = std::clamp<u8>(g, 0, 15);
@@ -137,17 +127,10 @@ static s32 drawDynamicUltraText(
return currentX; return currentX;
} }
void BaseGui::preDraw(tsl::gfx::Renderer* renderer) { 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); renderer->drawBitmap(LOGO_X, LOGO_Y_REAL - LOGO_LABEL_FONT_SIZE, LOGO_IMG_W, LOGO_IMG_H, hoc_rgba);
drawDynamicUltraText( drawDynamicUltraText(renderer, LOGO_TEXT_X, TEXT_Y, LOGO_LABEL_FONT_SIZE, STATIC_TEAL, false);
renderer,
LOGO_TEXT_X,
TEXT_Y,
LOGO_LABEL_FONT_SIZE,
STATIC_TEAL,
false
);
static const std::string versionStr = "Version " + getVersionString() + " \"Gaea\""; static const std::string versionStr = "Version " + getVersionString() + " \"Gaea\"";
static constexpr tsl::Color versionColor(9, 9, 9, 15); 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());
BaseFrame* rootFrame = new BaseFrame(this, this->headerHeight());
rootFrame->setContent(this->baseUI()); rootFrame->setContent(this->baseUI());
return rootFrame; return rootFrame;
} }
void BaseGui::update() void BaseGui::update() {
{
this->refresh(); this->refresh();
} }

View File

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

View File

@@ -24,23 +24,24 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "../format.h"
#include "base_menu_gui.h" #include "base_menu_gui.h"
#include "fatal_gui.h" #include "fatal_gui.h"
#include "../format.h"
#define TOP_Y_OFFSET 15 #define TOP_Y_OFFSET 15
// Cache hardware model to avoid repeated syscalls // 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(); tsl::initializeThemeVars();
this->context = nullptr; this->context = nullptr;
this->lastContextUpdate = 0; this->lastContextUpdate = 0;
this->listElement = nullptr; this->listElement = nullptr;
// Pre-cache hardware model during initialization // Pre-cache hardware model during initialization
IsAula(); IsAula();
IsMariko(); IsMariko();
@@ -51,19 +52,19 @@ BaseMenuGui::BaseMenuGui() : tempColors{ tsl::Color(0), tsl::Color(0), tsl::Colo
} }
BaseMenuGui::~BaseMenuGui() { BaseMenuGui::~BaseMenuGui() {
delete this->context; // delete handles nullptr automatically delete this->context; // delete handles nullptr automatically
} }
// Fast preDraw - just renders pre-computed strings // Fast preDraw - just renders pre-computed strings
void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) { void BaseMenuGui::preDraw(tsl::gfx::Renderer *renderer) {
BaseGui::preDraw(renderer); BaseGui::preDraw(renderer);
// All constants pre-calculated and cached // All constants pre-calculated and cached
const char* labels[] = { const char *labels[] = { "App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board",
"App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board", "Skin", "Now", "Avg", "BAT", "PMIC", "Fan", IsAula() || this->context->isUsingRetroSuper ? "OLED" : "LCD", "FPS", "RES" "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}; static constexpr u32 dataPositions[6] = { 63 - 3 + 3, 200 - 1, 344 - 1 - 3, 200 - 1, 342 - 1, 321 - 1 };
static u32 labelWidths[10]; static u32 labelWidths[10];
static bool positionsInitialized = false; static bool positionsInitialized = false;
@@ -74,14 +75,23 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
} }
positionsInitialized = true; 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 static u32 maxProfileValueWidth = renderer->getTextDimensions("USB Charger", false, SMALL_TEXT_SIZE).first; // longest word
u32 y = 91 + TOP_Y_OFFSET; u32 y = 91 + TOP_Y_OFFSET;
// === TOP SECTION === // === TOP SECTION ===
renderer->drawRoundedRect(14, 70-1 + TOP_Y_OFFSET, 420, 30+2, 12.0f, renderer->aWithOpacity(tsl::tableBGColor)); renderer->drawRoundedRect(14, 70 - 1 + TOP_Y_OFFSET, 420, 30 + 2, 12.0f, renderer->aWithOpacity(tsl::tableBGColor));
// App ID - use pre-formatted string // App ID - use pre-formatted string
renderer->drawString(labels[0], false, positions[0], y, SMALL_TEXT_SIZE, tsl::sectionTextColor); renderer->drawString(labels[0], false, positions[0], y, SMALL_TEXT_SIZE, tsl::sectionTextColor);
@@ -91,7 +101,7 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
renderer->drawString(labels[1], false, 423 - maxProfileValueWidth - labelWidths[1] - 9, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); renderer->drawString(labels[1], false, 423 - maxProfileValueWidth - labelWidths[1] - 9, y, SMALL_TEXT_SIZE, tsl::sectionTextColor);
renderer->drawString(displayStrings[1], false, 423 - maxProfileValueWidth, y, SMALL_TEXT_SIZE, tsl::infoTextColor); renderer->drawString(displayStrings[1], false, 423 - maxProfileValueWidth, y, SMALL_TEXT_SIZE, tsl::infoTextColor);
y += 38; // Direct assignment instead of += 38 y += 38; // Direct assignment instead of += 38
// === MAIN DATA SECTION === // === MAIN DATA SECTION ===
renderer->drawRoundedRect(14, 106 + TOP_Y_OFFSET, 420, 156, 10.0f, renderer->aWithOpacity(tsl::tableBGColor)); renderer->drawRoundedRect(14, 106 + TOP_Y_OFFSET, 420, 156, 10.0f, renderer->aWithOpacity(tsl::tableBGColor));
@@ -106,8 +116,7 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
renderer->drawString(displayStrings[3], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU renderer->drawString(displayStrings[3], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU
renderer->drawString(displayStrings[4], false, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // MEM renderer->drawString(displayStrings[4], false, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // MEM
y += 20; // Direct assignment (129 + 20) y += 20; // Direct assignment (129 + 20)
renderer->drawString(displayStrings[5], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU real 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[6], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU real
@@ -119,19 +128,20 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
// === REAL FREQUENCIES === // === REAL FREQUENCIES ===
y += 20; // Direct assignment (149 + 20) y += 20; // Direct assignment (149 + 20)
// === VOLTAGES === // === VOLTAGES ===
renderer->drawString(displayStrings[8], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU voltage 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->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[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 renderer->drawString(displayStrings[17], false, positions[3], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU Usage
renderer->drawString(displayStrings[18], false, positions[4], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // RAM Usage renderer->drawString(displayStrings[18], false, positions[4], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // RAM Usage
y += 22; // Direct assignment (169 + 22) y += 22; // Direct assignment (169 + 22)
// === TEMPERATURE SECTION === // === TEMPERATURE SECTION ===
// Labels // Labels
@@ -141,59 +151,57 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
// Temperatures with color - use pre-computed colors // Temperatures with color - use pre-computed colors
renderer->drawString(displayStrings[11], false, dataPositions[0] - 1, y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_SOC]); // SOC renderer->drawString(displayStrings[11], false, dataPositions[0] - 1, y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_SOC]); // SOC
renderer->drawString(displayStrings[12], false, dataPositions[1], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_PCB]); // PCB renderer->drawString(displayStrings[12], false, dataPositions[1], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_PCB]); // PCB
renderer->drawString(displayStrings[13], false, dataPositions[2], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_Skin]); // Skin renderer->drawString(displayStrings[13], false, dataPositions[2], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_Skin]); // Skin
y += 20; // Direct assignment (191 + 20) y += 20; // Direct assignment (191 + 20)
renderer->drawString(displayStrings[14], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // SOC voltage renderer->drawString(displayStrings[14], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // SOC voltage
// Power labels and values // Power labels and values
renderer->drawString(labels[8], false, positions[8]-1, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); renderer->drawString(labels[8], false, positions[8] - 1, y, SMALL_TEXT_SIZE, tsl::sectionTextColor);
renderer->drawString(labels[9], false, positions[9], y, SMALL_TEXT_SIZE, tsl::sectionTextColor); renderer->drawString(labels[9], false, positions[9], y, SMALL_TEXT_SIZE, tsl::sectionTextColor);
renderer->drawString(displayStrings[15], false, dataPositions[3], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Power now renderer->drawString(displayStrings[15], false, dataPositions[3], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Power now
renderer->drawString(displayStrings[16], false, dataPositions[4], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Power avg renderer->drawString(displayStrings[16], false, dataPositions[4], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Power avg
y+=20; y += 20;
renderer->drawString(labels[10], false, positions[2], y, SMALL_TEXT_SIZE, tsl::sectionTextColor); renderer->drawString(labels[10], false, positions[2], y, SMALL_TEXT_SIZE, tsl::sectionTextColor);
renderer->drawString(displayStrings[20], false, dataPositions[0], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_Battery]); // Battery renderer->drawString(displayStrings[20], false, dataPositions[0], y, SMALL_TEXT_SIZE, tempColors[HocClkThermalSensor_Battery]); // Battery
renderer->drawString(labels[12], false, positions[3], y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // fan label renderer->drawString(labels[12], false, positions[3], y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // fan label
renderer->drawString(displayStrings[24], false, dataPositions[1] + 5, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // fan speed renderer->drawString(displayStrings[24], false, dataPositions[1] + 5, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // fan speed
renderer->drawString(labels[13], false, positions[4] + 4, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // disp label renderer->drawString(labels[13], false, positions[4] + 4, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // disp label
renderer->drawString(displayStrings[25], false, dataPositions[2] + 6, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // disp freq renderer->drawString(displayStrings[25], false, dataPositions[2] + 6, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // disp freq
y+=20; y += 20;
renderer->drawString(displayStrings[21], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Bat voltage renderer->drawString(displayStrings[21], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Bat voltage
renderer->drawString(displayStrings[23], false, positions[2] - 2, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Bat Age renderer->drawString(displayStrings[23], false, positions[2] - 2, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // Bat Age
if(this->context->isSaltyNXInstalled) { if (this->context->isSaltyNXInstalled) {
renderer->drawString(labels[15], false, positions[3] + 7, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // RES label renderer->drawString(labels[15], false, positions[3] + 7, y, SMALL_TEXT_SIZE, tsl::sectionTextColor); // RES label
renderer->drawString(displayStrings[27], false, dataPositions[1] + 5, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // RES renderer->drawString(displayStrings[27], false, dataPositions[1] + 5, y, SMALL_TEXT_SIZE, tsl::infoTextColor); // RES
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
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; y += 20;
} }
// Optimized refresh - now does all the string formatting once per second // Optimized refresh - now does all the string formatting once per second
void BaseMenuGui::refresh() void BaseMenuGui::refresh() {
{
const u64 ticks = armGetSystemTick(); const u64 ticks = armGetSystemTick();
// Use cached comparison - 1 billion nanoseconds // Use cached comparison - 1 billion nanoseconds
if (armTicksToNs(ticks - this->lastContextUpdate) <= 1000000000UL) [[likely]] { if (armTicksToNs(ticks - this->lastContextUpdate) <= 1000000000UL) [[likely]] {
return; // Early exit for most calls return; // Early exit for most calls
} }
this->lastContextUpdate = ticks; this->lastContextUpdate = ticks;
@@ -224,22 +232,22 @@ void BaseMenuGui::refresh()
strcpy(displayStrings[1], hocclkFormatProfile(context->profile, true)); strcpy(displayStrings[1], hocclkFormatProfile(context->profile, true));
// Current frequencies // Current frequencies
u32 hz = context->freqs[HocClkModule_CPU]; // CPU u32 hz = context->freqs[HocClkModule_CPU]; // CPU
sprintf(displayStrings[2], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U); sprintf(displayStrings[2], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U);
hz = context->freqs[HocClkModule_GPU]; // GPU hz = context->freqs[HocClkModule_GPU]; // GPU
sprintf(displayStrings[3], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U); sprintf(displayStrings[3], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U);
hz = context->freqs[HocClkModule_MEM]; // MEM hz = context->freqs[HocClkModule_MEM]; // MEM
std::uint32_t unit = configList.values[HocClkConfigValue_RamDisplayUnit]; std::uint32_t unit = configList.values[HocClkConfigValue_RamDisplayUnit];
std::uint32_t mhz = hz / 1000000U; std::uint32_t mhz = hz / 1000000U;
std::uint32_t mts = mhz * 2; std::uint32_t mts = mhz * 2;
std::uint32_t tenth = (hz / 100000U) % 10U; std::uint32_t tenth = (hz / 100000U) % 10U;
if(unit == RamDisplayUnit_MTs) if (unit == RamDisplayUnit_MTs)
sprintf(displayStrings[4], "%u MT/s", mts); sprintf(displayStrings[4], "%u MT/s", mts);
else if(unit == RamDisplayUnit_MHz) else if (unit == RamDisplayUnit_MHz)
sprintf(displayStrings[4], "%u.%u MHz", mhz, tenth); sprintf(displayStrings[4], "%u.%u MHz", mhz, tenth);
else if(unit == RamDisplayUnit_MHzMTs) { else if (unit == RamDisplayUnit_MHzMTs) {
hz = context->realFreqs[HocClkModule_MEM]; hz = context->realFreqs[HocClkModule_MEM];
mhz = hz / 1000000U; mhz = hz / 1000000U;
tenth = (hz / 100000U) % 10U; tenth = (hz / 100000U) % 10U;
@@ -247,18 +255,18 @@ void BaseMenuGui::refresh()
} }
// Real frequencies // Real frequencies
hz = context->realFreqs[HocClkModule_CPU]; // CPU hz = context->realFreqs[HocClkModule_CPU]; // CPU
sprintf(displayStrings[5], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U); sprintf(displayStrings[5], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U);
hz = context->realFreqs[HocClkModule_GPU]; // GPU hz = context->realFreqs[HocClkModule_GPU]; // GPU
sprintf(displayStrings[6], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U); sprintf(displayStrings[6], "%u.%u MHz", hz / 1000000U, (hz / 100000U) % 10U);
hz = context->realFreqs[HocClkModule_MEM]; // MEM hz = context->realFreqs[HocClkModule_MEM]; // MEM
unit = configList.values[HocClkConfigValue_RamDisplayUnit]; unit = configList.values[HocClkConfigValue_RamDisplayUnit];
mhz = hz / 1000000U; mhz = hz / 1000000U;
mts = mhz * 2; mts = mhz * 2;
tenth = (hz / 100000U) % 10U; tenth = (hz / 100000U) % 10U;
if(unit == RamDisplayUnit_MTs || unit == RamDisplayUnit_MHzMTs) if (unit == RamDisplayUnit_MTs || unit == RamDisplayUnit_MHzMTs)
sprintf(displayStrings[7], "%u MT/s", mts); sprintf(displayStrings[7], "%u MT/s", mts);
else else
sprintf(displayStrings[7], "%u.%u MHz", mhz, tenth); sprintf(displayStrings[7], "%u.%u MHz", mhz, tenth);
@@ -267,12 +275,14 @@ void BaseMenuGui::refresh()
sprintf(displayStrings[8], "%.1f mV", context->voltages[HocClkVoltage_CPU] / 1000.0); sprintf(displayStrings[8], "%.1f mV", context->voltages[HocClkVoltage_CPU] / 1000.0);
sprintf(displayStrings[9], "%.1f mV", context->voltages[HocClkVoltage_GPU] / 1000.0); sprintf(displayStrings[9], "%.1f mV", context->voltages[HocClkVoltage_GPU] / 1000.0);
switch(configList.values[HocClkConfigValue_RAMVoltDisplayMode]) { switch (configList.values[HocClkConfigValue_RAMVoltDisplayMode]) {
case RamDisplayMode_VDD2: 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; break;
case RamDisplayMode_VDDQ: 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; break;
default: default:
strcpy(displayStrings[10], "N/A"); strcpy(displayStrings[10], "N/A");
@@ -280,15 +290,15 @@ void BaseMenuGui::refresh()
} }
// Temperatures and pre-compute colors // Temperatures and pre-compute colors
u32 millis = context->temps[HocClkThermalSensor_SOC]; // SOC u32 millis = context->temps[HocClkThermalSensor_SOC]; // SOC
sprintf(displayStrings[11], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U); sprintf(displayStrings[11], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_SOC] = tsl::GradientColor(millis * 0.001f); tempColors[HocClkThermalSensor_SOC] = tsl::GradientColor(millis * 0.001f);
millis = context->temps[HocClkThermalSensor_PCB]; // PCB millis = context->temps[HocClkThermalSensor_PCB]; // PCB
sprintf(displayStrings[12], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U); sprintf(displayStrings[12], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_PCB] = tsl::GradientColor(millis * 0.001f); tempColors[HocClkThermalSensor_PCB] = tsl::GradientColor(millis * 0.001f);
millis = context->temps[HocClkThermalSensor_Skin]; // Skin millis = context->temps[HocClkThermalSensor_Skin]; // Skin
sprintf(displayStrings[13], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U); sprintf(displayStrings[13], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_Skin] = tsl::GradientColor(millis * 0.001f); tempColors[HocClkThermalSensor_Skin] = tsl::GradientColor(millis * 0.001f);
@@ -296,26 +306,26 @@ void BaseMenuGui::refresh()
sprintf(displayStrings[14], "%u mV", context->voltages[HocClkVoltage_SOC] / 1000U); sprintf(displayStrings[14], "%u mV", context->voltages[HocClkVoltage_SOC] / 1000U);
// Power // Power
sprintf(displayStrings[15], "%d mW", context->power[0]); // Now sprintf(displayStrings[15], "%d mW", context->power[0]); // Now
sprintf(displayStrings[16], "%d mW", context->power[1]); // Avg sprintf(displayStrings[16], "%d mW", context->power[1]); // Avg
sprintf(displayStrings[17], "%u%%", context->partLoad[HocClkPartLoad_GPU] / 10); sprintf(displayStrings[17], "%u%%", context->partLoad[HocClkPartLoad_GPU] / 10);
sprintf(displayStrings[18], "%u%%", context->partLoad[HocClkPartLoad_EMC] / 10); sprintf(displayStrings[18], "%u%%", context->partLoad[HocClkPartLoad_EMC] / 10);
sprintf(displayStrings[19], "%u%%", context->partLoad[HocClkPartLoad_CPUMax] / 10); sprintf(displayStrings[19], "%u%%", context->partLoad[HocClkPartLoad_CPUMax] / 10);
millis = context->temps[HocClkThermalSensor_Battery]; // Battery millis = context->temps[HocClkThermalSensor_Battery]; // Battery
sprintf(displayStrings[20], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U); sprintf(displayStrings[20], "%u.%u °C", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_Battery] = tsl::GradientColor(millis * 0.001f); tempColors[HocClkThermalSensor_Battery] = tsl::GradientColor(millis * 0.001f);
sprintf(displayStrings[21], "%d mV", context->voltages[HocClkVoltage_Battery]); // BAT AVG sprintf(displayStrings[21], "%d mV", context->voltages[HocClkVoltage_Battery]); // BAT AVG
sprintf(displayStrings[23], "%u%%", context->partLoad[HocClkPartLoad_BAT] / 1000); sprintf(displayStrings[23], "%u%%", context->partLoad[HocClkPartLoad_BAT] / 1000);
sprintf(displayStrings[24], "%u%%", context->partLoad[HocClkPartLoad_FAN]); sprintf(displayStrings[24], "%u%%", context->partLoad[HocClkPartLoad_FAN]);
sprintf(displayStrings[25], "%u Hz", context->realFreqs[HocClkModule_Display]); sprintf(displayStrings[25], "%u Hz", context->realFreqs[HocClkModule_Display]);
if(this->context->isSaltyNXInstalled) { if (this->context->isSaltyNXInstalled) {
if(context->fps == 254) { if (context->fps == 254) {
strcpy(displayStrings[26], "N/A"); strcpy(displayStrings[26], "N/A");
} else { } else {
memset(displayStrings[26], 0, sizeof(displayStrings[26])); memset(displayStrings[26], 0, sizeof(displayStrings[26]));
@@ -323,8 +333,8 @@ void BaseMenuGui::refresh()
} }
} }
if(this->context->isSaltyNXInstalled) { if (this->context->isSaltyNXInstalled) {
if(context->resolutionHeight == 0) { if (context->resolutionHeight == 0) {
strcpy(displayStrings[27], "N/A"); strcpy(displayStrings[27], "N/A");
} else { } else {
memset(displayStrings[27], 0, sizeof(displayStrings[27])); memset(displayStrings[27], 0, sizeof(displayStrings[27]));
@@ -343,12 +353,10 @@ void BaseMenuGui::refresh()
millis = context->temps[HocClkThermalSensor_MEM]; millis = context->temps[HocClkThermalSensor_MEM];
sprintf(displayStrings[30], "%u.%u", millis / 1000U, (millis % 1000U) / 100U); sprintf(displayStrings[30], "%u.%u", millis / 1000U, (millis % 1000U) / 100U);
tempColors[HocClkThermalSensor_MEM] = tsl::GradientColor(millis * 0.001f); tempColors[HocClkThermalSensor_MEM] = tsl::GradientColor(millis * 0.001f);
} }
tsl::elm::Element* BaseMenuGui::baseUI() tsl::elm::Element *BaseMenuGui::baseUI() {
{ auto *list = new tsl::elm::List();
auto* list = new tsl::elm::List();
this->listElement = list; this->listElement = list;
this->listUI(); this->listUI();

View File

@@ -24,69 +24,66 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#include "../../ipc.h" #include "../../ipc.h"
#include "base_gui.h" #include "base_gui.h"
class BaseMenuGui : public BaseGui class BaseMenuGui : public BaseGui {
{
protected: protected:
public: public:
// u8 dockedHighestAllowedRefreshRate = 60; // u8 dockedHighestAllowedRefreshRate = 60;
HocClkContext* context; HocClkContext *context;
std::uint64_t lastContextUpdate; std::uint64_t lastContextUpdate;
HocClkConfigValueList configList; HocClkConfigValueList configList;
bool g_hardwareModelCached = false; bool g_hardwareModelCached = false;
bool g_isMariko = false; bool g_isMariko = false;
bool g_isAula = false; bool g_isAula = false;
bool g_isHoag = false; bool g_isHoag = false;
SetSysProductModel HWmodel = SetSysProductModel_Invalid; SetSysProductModel HWmodel = SetSysProductModel_Invalid;
bool IsAula() { bool IsAula() {
if (!g_hardwareModelCached) { if (!g_hardwareModelCached) {
setsysGetProductModel(&HWmodel); setsysGetProductModel(&HWmodel);
g_hardwareModelCached = true; g_hardwareModelCached = true;
}
g_isAula = (HWmodel == SetSysProductModel_Aula);
return g_isAula;
} }
bool IsHoag() { g_isAula = (HWmodel == SetSysProductModel_Aula);
if (!g_hardwareModelCached) { return g_isAula;
setsysGetProductModel(&HWmodel); }
g_hardwareModelCached = true; bool IsHoag() {
} if (!g_hardwareModelCached) {
g_isHoag = (HWmodel == SetSysProductModel_Hoag); setsysGetProductModel(&HWmodel);
return g_isHoag; g_hardwareModelCached = true;
} }
bool IsMariko() { g_isHoag = (HWmodel == SetSysProductModel_Hoag);
if (!g_hardwareModelCached) { return g_isHoag;
setsysGetProductModel(&HWmodel); }
g_hardwareModelCached = true; bool IsMariko() {
} if (!g_hardwareModelCached) {
g_isMariko = (HWmodel == SetSysProductModel_Iowa || setsysGetProductModel(&HWmodel);
HWmodel == SetSysProductModel_Hoag || g_hardwareModelCached = true;
HWmodel == SetSysProductModel_Calcio || }
HWmodel == SetSysProductModel_Aula); g_isMariko = (HWmodel == SetSysProductModel_Iowa || HWmodel == SetSysProductModel_Hoag || HWmodel == SetSysProductModel_Calcio ||
HWmodel == SetSysProductModel_Aula);
return g_isMariko; return g_isMariko;
} }
bool IsErista() { bool IsErista() {
return !IsMariko(); return !IsMariko();
} }
BaseMenuGui(); BaseMenuGui();
~BaseMenuGui(); ~BaseMenuGui();
void preDraw(tsl::gfx::Renderer* renderer) override; void preDraw(tsl::gfx::Renderer *renderer) override;
tsl::elm::List* listElement; tsl::elm::List *listElement;
tsl::elm::Element* baseUI() override; tsl::elm::Element *baseUI() override;
void refresh() override; void refresh() override;
virtual void listUI() = 0; virtual void listUI() = 0;
u16 headerHeight() const override { return HOC_BOX_BOTTOM + 9; } u16 headerHeight() const override {
return HOC_BOX_BOTTOM + 9;
}
private: private:
char displayStrings[48][32]; // Pre-formatted display strings char displayStrings[48][32]; // Pre-formatted display strings
tsl::Color tempColors[HocClkThermalSensor_EnumMax]; // Pre-computed temperature colors tsl::Color tempColors[HocClkThermalSensor_EnumMax]; // Pre-computed temperature colors
}; };

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -24,23 +24,23 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#include <list> #include <list>
#include "base_gui.h" #include "base_gui.h"
class FatalGui : public BaseGui class FatalGui : public BaseGui {
{
protected: protected:
std::string message; std::string message;
std::string info; std::string info;
public: public:
FatalGui(const std::string message, const std::string info); 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); tsl::elm::Element *baseUI() override;
static void openWithResultCode(std::string tag, Result rc); 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 "../format.h"
#include "fatal_gui.h" #include "fatal_gui.h"
#include "freq_choice_gui.h"
#include "ult_ext.h"
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz, FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, HocClkModule module, FreqChoiceListener listener,
std::uint32_t* hzList, bool checkMax, std::map<uint32_t, std::string> labels) {
std::uint32_t hzCount,
HocClkModule module,
FreqChoiceListener listener,
bool checkMax,
std::map<uint32_t, std::string> labels)
{
this->selectedHz = selectedHz; this->selectedHz = selectedHz;
this->hzList = hzList; this->hzList = hzList;
this->hzCount = hzCount; this->hzCount = hzCount;
@@ -46,18 +38,16 @@ FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
this->listener = listener; this->listener = listener;
this->checkMax = checkMax; this->checkMax = checkMax;
this->labels = labels; this->labels = labels;
this->configList = new HocClkConfigValueList {}; this->configList = new HocClkConfigValueList{};
} }
FreqChoiceGui::~FreqChoiceGui() FreqChoiceGui::~FreqChoiceGui() {
{
delete this->configList; 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; std::string text;
if(module == HocClkModule_MEM) if (module == HocClkModule_MEM)
text = formatListFreqHzMem(hz, (RamDisplayUnit)this->configList->values[HocClkConfigValue_RamDisplayUnit]); text = formatListFreqHzMem(hz, (RamDisplayUnit)this->configList->values[HocClkConfigValue_RamDisplayUnit]);
else else
text = formatListFreqHz(hz); text = formatListFreqHz(hz);
@@ -68,35 +58,32 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
rightText = it->second; rightText = it->second;
if (selected) if (selected)
const_cast<std::string&>(rightText) = "\uE14B"; const_cast<std::string &>(rightText) = "\uE14B";
tsl::elm::ListItem* listItem = tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, rightText, false);
new tsl::elm::ListItem(text, rightText, false);
switch (safety) switch (safety) {
{ case 0:
case 0: listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setTextColor(tsl::Color(255, 255, 255, 255)); listItem->setValueColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255)); break;
break; case 1:
case 1: listItem->setTextColor(tsl::Color(255, 165, 0, 255));
listItem->setTextColor(tsl::Color(255, 165, 0, 255)); listItem->setValueColor(tsl::Color(255, 165, 0, 255));
listItem->setValueColor(tsl::Color(255, 165, 0, 255)); break;
break; case 2:
case 2: listItem->setTextColor(tsl::Color(255, 0, 0, 255));
listItem->setTextColor(tsl::Color(255, 0, 0, 255)); listItem->setValueColor(tsl::Color(255, 0, 0, 255));
listItem->setValueColor(tsl::Color(255, 0, 0, 255)); break;
break;
} }
// Make annotation grey // Make annotation grey
if (!rightText.empty() && !selected) if (!rightText.empty() && !selected)
listItem->setValueColor(tsl::Color(180, 180, 180, 255)); listItem->setValueColor(tsl::Color(180, 180, 180, 255));
else if(selected) else if (selected)
listItem->setValueColor(tsl::infoTextColor); 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 ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(hz)) { if (this->listener(hz)) {
tsl::goBack(); tsl::goBack();
@@ -109,8 +96,7 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
return listItem; return listItem;
} }
void FreqChoiceGui::listUI() void FreqChoiceGui::listUI() {
{
hocclkIpcGetConfigValues(this->configList); hocclkIpcGetConfigValues(this->configList);
// Header based on CPU/GPU/MEM module // Header based on CPU/GPU/MEM module
@@ -118,11 +104,9 @@ void FreqChoiceGui::listUI()
this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName)); this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName));
// Default option // Default option
this->listElement->addItem( this->listElement->addItem(this->createFreqListItem(0, this->selectedHz == 0, 0));
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]; std::uint32_t hz = this->hzList[i];
uint32_t mhz = hz / 1000000; uint32_t mhz = hz / 1000000;
@@ -160,17 +144,14 @@ void FreqChoiceGui::listUI()
uint32_t danger_cpu; uint32_t danger_cpu;
uint32_t danger_gpu; uint32_t danger_gpu;
if (IsMariko()) if (IsMariko()) {
{
unsafe_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2398 : 1964; unsafe_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2398 : 1964;
unsafe_gpu = 1229; unsafe_gpu = 1229;
danger_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2500 : 2398; danger_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2500 : 2398;
danger_gpu = 1306; danger_gpu = 1306;
} } else {
else
{
unsafe_cpu = this->configList->values[KipConfigValue_eristaCpuUV] ? 2092 : 1786; unsafe_cpu = this->configList->values[KipConfigValue_eristaCpuUV] ? 2092 : 1786;
if(this->configList->values[KipConfigValue_eristaGpuUV] == GPUUVLevel_NoUV) { if (this->configList->values[KipConfigValue_eristaGpuUV] == GPUUVLevel_NoUV) {
unsafe_gpu = 922; unsafe_gpu = 922;
} else { } else {
unsafe_gpu = 961; unsafe_gpu = 961;
@@ -202,16 +183,9 @@ void FreqChoiceGui::listUI()
} else if (moduleName == "mem") { } else if (moduleName == "mem") {
safety = 0; safety = 0;
} }
this->listElement->addItem( this->listElement->addItem(this->createFreqListItem(hz, (mhz == this->selectedHz / 1000000), safety));
this->createFreqListItem(
hz,
(mhz == this->selectedHz / 1000000),
safety
)
);
} }
this->listElement->jumpToItem("", ""); this->listElement->jumpToItem("", "");

View File

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

View File

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

View File

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

View File

@@ -16,18 +16,18 @@
* *
*/ */
#pragma once #pragma once
#include "base_menu_gui.h"
#include <string> #include <string>
#include <vector> #include <vector>
class InfoGui : public BaseMenuGui #include "base_menu_gui.h"
{
public: class InfoGui : public BaseMenuGui {
public:
InfoGui(std::string title, std::vector<std::string> strings); InfoGui(std::string title, std::vector<std::string> strings);
~InfoGui() = default; ~InfoGui() = default;
void listUI() override; void listUI() override;
private: private:
std::string m_title; std::string m_title;
std::vector<std::string> m_strings; std::vector<std::string> m_strings;
}; };

View File

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

View File

@@ -24,25 +24,23 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#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 "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" #include "ult_ext.h"
tsl::elm::Element* MainGui::baseUI() {
auto* list = new BoxClippedList(); tsl::elm::Element *MainGui::baseUI() {
auto *list = new BoxClippedList();
this->listElement = list; this->listElement = list;
this->listUI(); this->listUI();
return list; return list;
} }
void MainGui::listUI() void MainGui::listUI() {
{
// this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false); // this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false);
// enabledToggle->setStateChangedListener([this](bool state) { // enabledToggle->setStateChangedListener([this](bool state) {
// Result rc = hocclkIpcSetEnabled(state); // Result rc = hocclkIpcSetEnabled(state);
@@ -56,10 +54,9 @@ void MainGui::listUI()
// }); // });
// this->listElement->addItem(this->enabledToggle); // this->listElement->addItem(this->enabledToggle);
tsl::elm::ListItem* appProfileItem = new tsl::elm::ListItem("Edit App Profile"); tsl::elm::ListItem *appProfileItem = new tsl::elm::ListItem("Edit App Profile");
appProfileItem->setClickListener([this](u64 keys) { 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); AppProfileGui::changeTo(this->context->applicationId);
return true; return true;
} }
@@ -68,11 +65,9 @@ void MainGui::listUI()
}); });
this->listElement->addItem(appProfileItem); this->listElement->addItem(appProfileItem);
tsl::elm::ListItem *globalProfileItem = new tsl::elm::ListItem("Edit Global Profile");
tsl::elm::ListItem* globalProfileItem = new tsl::elm::ListItem("Edit Global Profile");
globalProfileItem->setClickListener([this](u64 keys) { 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); AppProfileGui::changeTo(HOCCLK_GLOBAL_PROFILE_TID);
return true; return true;
} }
@@ -81,10 +76,9 @@ void MainGui::listUI()
}); });
this->listElement->addItem(globalProfileItem); this->listElement->addItem(globalProfileItem);
tsl::elm::ListItem* globalOverrideItem = new tsl::elm::ListItem("Temporary Overrides"); tsl::elm::ListItem *globalOverrideItem = new tsl::elm::ListItem("Temporary Overrides");
globalOverrideItem->setClickListener([this](u64 keys) { globalOverrideItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
{
tsl::changeTo<GlobalOverrideGui>(); tsl::changeTo<GlobalOverrideGui>();
return true; return true;
} }
@@ -93,12 +87,11 @@ void MainGui::listUI()
}); });
this->listElement->addItem(globalOverrideItem); this->listElement->addItem(globalOverrideItem);
//this->listElement->addItem(new tsl::elm::CategoryHeader("Misc")); // this->listElement->addItem(new tsl::elm::CategoryHeader("Misc"));
tsl::elm::ListItem* miscItem = new tsl::elm::ListItem("Settings"); tsl::elm::ListItem *miscItem = new tsl::elm::ListItem("Settings");
miscItem->setClickListener([this](u64 keys) { miscItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
{
tsl::changeTo<MiscGui>(); tsl::changeTo<MiscGui>();
return true; return true;
} }
@@ -107,10 +100,9 @@ void MainGui::listUI()
}); });
this->listElement->addItem(miscItem); this->listElement->addItem(miscItem);
tsl::elm::ListItem* aboutItem = new tsl::elm::ListItem("About"); tsl::elm::ListItem *aboutItem = new tsl::elm::ListItem("About");
aboutItem->setClickListener([this](u64 keys) { aboutItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
{
tsl::changeTo<AboutGui>(); tsl::changeTo<AboutGui>();
return true; return true;
} }
@@ -118,14 +110,12 @@ void MainGui::listUI()
return false; return false;
}); });
this->listElement->addItem(aboutItem); this->listElement->addItem(aboutItem);
} }
void MainGui::refresh() void MainGui::refresh() {
{
BaseMenuGui::refresh(); BaseMenuGui::refresh();
//if(this->context) // if(this->context)
//{ //{
// this->enabledToggle->setState(this->context->enabled); // this->enabledToggle->setState(this->context->enabled);
//} // }
} }

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -16,67 +16,51 @@
* *
*/ */
#pragma once #pragma once
#include "../../ipc.h"
#include "base_menu_gui.h"
#include <initializer_list>
#include <set> #include <set>
#include <unordered_map>
#include <string> #include <string>
#include <vector> #include <vector>
#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h" #include "freq_choice_gui.h"
#include "value_choice_gui.h"
#include "info_gui.h" #include "info_gui.h"
class MiscGui : public BaseMenuGui #include "value_choice_gui.h"
{ #include <initializer_list>
public: #include <unordered_map>
class MiscGui : public BaseMenuGui {
public:
MiscGui(); MiscGui();
~MiscGui(); ~MiscGui();
void listUI() override; void listUI() override;
void refresh() override; void refresh() override;
protected: protected:
HocClkConfigValueList* configList; HocClkConfigValueList *configList;
std::map<HocClkConfigValue, tsl::elm::ListItem*> configButtons; std::map<HocClkConfigValue, tsl::elm::ListItem *> configButtons;
std::map<HocClkConfigValue, ValueRange> configRanges; std::map<HocClkConfigValue, ValueRange> configRanges;
std::map<HocClkConfigValue, std::vector<NamedValue>> configNamedValues; std::map<HocClkConfigValue, std::vector<NamedValue>> configNamedValues;
std::map<HocClkConfigValue, tsl::elm::ToggleListItem*> configToggles; std::map<HocClkConfigValue, tsl::elm::ToggleListItem *> configToggles;
std::map<HocClkConfigValue, std::tuple<tsl::elm::TrackBar*, tsl::elm::ListItem*, std::vector<uint64_t>>> configTrackbars; std::map<HocClkConfigValue, std::tuple<tsl::elm::TrackBar *, tsl::elm::ListItem *, std::vector<uint64_t>>> configTrackbars;
std::set<HocClkConfigValue> configButtonSKeys; std::set<HocClkConfigValue> configButtonSKeys;
std::map<HocClkConfigValue, std::string> configButtonSSubtext; std::map<HocClkConfigValue, std::string> configButtonSSubtext;
std::set<HocClkConfigValue> emcClockConfigs; std::set<HocClkConfigValue> emcClockConfigs;
void addConfigToggle(HocClkConfigValue configVal, const char* altName, bool kip = false); void addConfigToggle(HocClkConfigValue configVal, const char *altName, bool kip = false);
void addConfigTrackbar(HocClkConfigValue configVal, const char* altName, const ValueRange& range, bool kip = true); void addConfigTrackbar(HocClkConfigValue configVal, const char *altName, const ValueRange &range, bool kip = true);
void addMappedConfigTrackbar(HocClkConfigValue configVal, const char* altName, void addMappedConfigTrackbar(HocClkConfigValue configVal, const char *altName, std::vector<u32> vals, std::initializer_list<std::string> names,
std::vector<u32> vals, bool kip = true);
std::initializer_list<std::string> names, bool kip = true); void addConfigButton(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
void addConfigButton(HocClkConfigValue configVal, const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
const char* altName, const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, bool kip = false);
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, void addConfigButtonS(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
const char* altName, const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
const ValueRange& range, const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, const char *subText = nullptr,
const std::string& categoryName, bool kip = false);
const ValueThresholds* thresholds, void addFreqButton(HocClkConfigValue configVal, const char *altName, HocClkModule module, const std::map<uint32_t, std::string> &labels = {});
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 updateConfigToggles(); void updateConfigToggles();
tsl::elm::ToggleListItem* enabledToggle; tsl::elm::ToggleListItem *enabledToggle;
u8 frameCounter = 60; u8 frameCounter = 60;
bool shouldSaveKip = false; bool shouldSaveKip = false;
}; };

View File

@@ -17,15 +17,19 @@
#pragma once #pragma once
#include <tesla.hpp> #include <tesla.hpp>
#include "../elements/base_frame.h" #include "../elements/base_frame.h"
class TopAnchoredList : public tsl::elm::List { class TopAnchoredList : public tsl::elm::List {
public: public:
TopAnchoredList() { m_hasSetInitialFocusHack = true; } TopAnchoredList() {
m_hasSetInitialFocusHack = true;
}
}; };
class BoxClippedList : public tsl::elm::List { class BoxClippedList : public tsl::elm::List {
public: public:
void draw(tsl::gfx::Renderer* renderer) override { void draw(tsl::gfx::Renderer *renderer) override {
renderer->enableScissoring(0, HOC_BOX_BOTTOM, tsl::cfg::FramebufferWidth, tsl::cfg::FramebufferHeight - HOC_BOX_BOTTOM); renderer->enableScissoring(0, HOC_BOX_BOTTOM, tsl::cfg::FramebufferWidth, tsl::cfg::FramebufferHeight - HOC_BOX_BOTTOM);
tsl::elm::List::draw(renderer); tsl::elm::List::draw(renderer);
renderer->disableScissoring(); renderer->disableScissoring();
@@ -33,39 +37,35 @@ public:
}; };
class CompactCategoryHeader : public tsl::elm::CategoryHeader { class CompactCategoryHeader : public tsl::elm::CategoryHeader {
public: 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 { void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
this->setBoundaries(this->getX(), this->getY(), this->getWidth(), 33); this->setBoundaries(this->getX(), this->getY(), this->getWidth(), 33);
} }
}; };
class ImageElement : public tsl::elm::ListItem { class ImageElement : public tsl::elm::ListItem {
private: private:
const uint8_t* imgData; const uint8_t *imgData;
uint32_t imgWidth, imgHeight; uint32_t imgWidth, imgHeight;
bool visible; bool visible;
public: public:
ImageElement(const uint8_t* data, uint32_t w, uint32_t h) ImageElement(const uint8_t *data, uint32_t w, uint32_t h) : tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {
: tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {} }
void setVisible(bool v) { void setVisible(bool v) {
visible = v; visible = v;
} }
virtual void draw(tsl::gfx::Renderer *renderer) override { virtual void draw(tsl::gfx::Renderer *renderer) override {
if (!visible) return; if (!visible)
return;
// Draw image centered horizontally // Draw image centered horizontally
u16 centerX = this->getX() + (this->getWidth() - imgWidth) / 2; u16 centerX = this->getX() + (this->getWidth() - imgWidth) / 2;
renderer->drawBitmap( renderer->drawBitmap(centerX, this->getY() + 10, imgWidth, imgHeight, imgData);
centerX,
this->getY() + 10,
imgWidth,
imgHeight,
imgData
);
} }
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override { virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
@@ -83,28 +83,29 @@ public:
} }
virtual bool onClick(u64 keys) override { virtual bool onClick(u64 keys) override {
return false; // Non-clickable return false; // Non-clickable
} }
virtual Element* requestFocus(Element *oldFocus, tsl::FocusDirection direction) override { virtual Element *requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
return nullptr; // Make it non-focusable return nullptr; // Make it non-focusable
} }
}; };
class HideableCategoryHeader : public tsl::elm::CategoryHeader { class HideableCategoryHeader : public tsl::elm::CategoryHeader {
private: private:
bool visible; bool visible;
public: public:
HideableCategoryHeader(const std::string& title) HideableCategoryHeader(const std::string &title) : tsl::elm::CategoryHeader(title), visible(true) {
: tsl::elm::CategoryHeader(title), visible(true) {} }
void setVisible(bool v) { void setVisible(bool v) {
visible = v; visible = v;
} }
virtual void draw(tsl::gfx::Renderer *renderer) override { virtual void draw(tsl::gfx::Renderer *renderer) override {
if (!visible) return; if (!visible)
return;
tsl::elm::CategoryHeader::draw(renderer); tsl::elm::CategoryHeader::draw(renderer);
} }
@@ -118,25 +119,25 @@ public:
}; };
class FocusableDrawer : public tsl::elm::CustomDrawer { class FocusableDrawer : public tsl::elm::CustomDrawer {
public: public:
template<typename... Args> template <typename... Args> FocusableDrawer(Args &&...args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
FocusableDrawer(Args&&... args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
m_isItem = true; m_isItem = true;
} }
Element* requestFocus(Element*, tsl::FocusDirection) override { Element *requestFocus(Element *, tsl::FocusDirection) override {
return this; return this;
} }
void drawHighlight(tsl::gfx::Renderer*) override {} void drawHighlight(tsl::gfx::Renderer *) override {
}
}; };
class HideableCustomDrawer : public tsl::elm::Element { class HideableCustomDrawer : public tsl::elm::Element {
private: private:
bool visible; bool visible;
u32 height; u32 height;
public: public:
HideableCustomDrawer(u32 h) HideableCustomDrawer(u32 h) : Element(), visible(true), height(h) {
: Element(), visible(true), height(h) {} }
void setVisible(bool v) { void setVisible(bool v) {
visible = v; visible = v;
@@ -154,7 +155,7 @@ public:
} }
} }
virtual Element* requestFocus(Element *oldFocus, tsl::FocusDirection direction) override { virtual Element *requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
return nullptr; return nullptr;
} }
}; };

View File

@@ -16,44 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ult_ext.h" #include <iomanip>
#include "value_choice_gui.h" #include <sstream>
#include "../format.h" #include "../format.h"
#include "fatal_gui.h" #include "fatal_gui.h"
#include <sstream> #include "ult_ext.h"
#include <iomanip> #include "value_choice_gui.h"
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue, ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
const ValueRange& range, const ValueThresholds &thresholds, bool enableThresholds, std::map<std::uint32_t, std::string> labels,
const std::string& categoryName, std::vector<NamedValue> namedValues, bool showDefaultValue, bool showDNO)
ValueChoiceListener listener, : selectedValue(selectedValue), range(range), categoryName(categoryName), listener(listener), thresholds(thresholds),
const ValueThresholds& thresholds, enableThresholds(enableThresholds), labels(labels), namedValues(namedValues), showDefaultValue(showDefaultValue), showDNO(showDNO) {
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; std::ostringstream oss;
if(showDefaultValue) { if (showDefaultValue) {
if (value == 0) { if (value == 0) {
return this->showDNO ? FREQ_DEFAULT_TEXT : VALUE_DEFAULT_TEXT; return this->showDNO ? FREQ_DEFAULT_TEXT : VALUE_DEFAULT_TEXT;
} }
@@ -66,9 +49,8 @@ std::string ValueChoiceGui::formatValue(std::uint32_t value)
return oss.str(); return oss.str();
} }
int ValueChoiceGui::getSafetyLevel(std::uint32_t value) int ValueChoiceGui::getSafetyLevel(std::uint32_t value) {
{ if (thresholds.warning == 0 && thresholds.danger == 0) {
if(thresholds.warning == 0 && thresholds.danger == 0) {
return 0; return 0;
} }
@@ -81,8 +63,7 @@ int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
return 0; 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 text = formatValue(value);
std::string rightText = ""; std::string rightText = "";
@@ -92,34 +73,32 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
} }
if (selected) { if (selected) {
const_cast<std::string&>(rightText) = "\uE14B"; 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:
case 0: listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setTextColor(tsl::Color(255, 255, 255, 255)); listItem->setValueColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255)); break;
break; case 1:
case 1: listItem->setTextColor(tsl::Color(255, 165, 0, 255));
listItem->setTextColor(tsl::Color(255, 165, 0, 255)); listItem->setValueColor(tsl::Color(255, 165, 0, 255));
listItem->setValueColor(tsl::Color(255, 165, 0, 255)); break;
break; case 2:
case 2: listItem->setTextColor(tsl::Color(255, 0, 0, 255));
listItem->setTextColor(tsl::Color(255, 0, 0, 255)); listItem->setValueColor(tsl::Color(255, 0, 0, 255));
listItem->setValueColor(tsl::Color(255, 0, 0, 255)); break;
break;
} }
// Make annotation grey // Make annotation grey
if (!rightText.empty() && !selected) if (!rightText.empty() && !selected)
listItem->setValueColor(tsl::Color(180, 180, 180, 255)); listItem->setValueColor(tsl::Color(180, 180, 180, 255));
else if(selected) else if (selected)
listItem->setValueColor(tsl::infoTextColor); 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 ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(value)) { if (this->listener(value)) {
tsl::goBack(); tsl::goBack();
@@ -131,37 +110,34 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
return listItem; 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; std::string text = namedValue.name;
if (selected) { if (selected) {
const_cast<std::string&>(namedValue.rightText) = "\uE14B"; const_cast<std::string &>(namedValue.rightText) = "\uE14B";
} }
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, namedValue.rightText, false); tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, namedValue.rightText, false);
switch (safety) switch (safety) {
{ case 0:
case 0: listItem->setTextColor(tsl::Color(255, 255, 255, 255));
listItem->setTextColor(tsl::Color(255, 255, 255, 255)); listItem->setValueColor(tsl::Color(255, 255, 255, 255));
listItem->setValueColor(tsl::Color(255, 255, 255, 255)); break;
break; case 1:
case 1: listItem->setTextColor(tsl::Color(255, 165, 0, 255));
listItem->setTextColor(tsl::Color(255, 165, 0, 255)); listItem->setValueColor(tsl::Color(255, 165, 0, 255));
listItem->setValueColor(tsl::Color(255, 165, 0, 255)); break;
break; case 2:
case 2: listItem->setTextColor(tsl::Color(255, 0, 0, 255));
listItem->setTextColor(tsl::Color(255, 0, 0, 255)); listItem->setValueColor(tsl::Color(255, 0, 0, 255));
listItem->setValueColor(tsl::Color(255, 0, 0, 255)); break;
break;
} }
if (!namedValue.rightText.empty() && !selected) if (!namedValue.rightText.empty() && !selected)
listItem->setValueColor(tsl::Color(180, 180, 180, 255)); listItem->setValueColor(tsl::Color(180, 180, 180, 255));
else if(selected) else if (selected)
listItem->setValueColor(tsl::infoTextColor); 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 ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
if (this->listener(value)) { if (this->listener(value)) {
tsl::goBack(); tsl::goBack();
@@ -173,8 +149,7 @@ tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& n
return listItem; return listItem;
} }
void ValueChoiceGui::listUI() void ValueChoiceGui::listUI() {
{
if (!categoryName.empty()) { if (!categoryName.empty()) {
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName)); this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
} }
@@ -182,15 +157,14 @@ void ValueChoiceGui::listUI()
if (showDefaultValue) { if (showDefaultValue) {
this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0)); this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0));
} }
for (const auto& namedValue : namedValues) { for (const auto &namedValue : namedValues) {
int safety = enableThresholds ? getSafetyLevel(namedValue.value) : 0; int safety = enableThresholds ? getSafetyLevel(namedValue.value) : 0;
bool selected = (namedValue.value == this->selectedValue); bool selected = (namedValue.value == this->selectedValue);
this->listElement->addItem(this->createNamedValueListItem(namedValue, selected, safety)); this->listElement->addItem(this->createNamedValueListItem(namedValue, selected, safety));
} }
if (namedValues.empty()) { 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); int safety = getSafetyLevel(value);
bool selected = (value == this->selectedValue); bool selected = (value == this->selectedValue);
this->listElement->addItem(this->createValueListItem(value, selected, safety)); this->listElement->addItem(this->createValueListItem(value, selected, safety));

View File

@@ -17,11 +17,12 @@
* *
*/ */
#pragma once #pragma once
#include <list>
#include <functional> #include <functional>
#include <string> #include <list>
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
#include "base_menu_gui.h" #include "base_menu_gui.h"
using ValueChoiceListener = std::function<bool(std::uint32_t value)>; using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
@@ -34,19 +35,19 @@ struct ValueRange {
std::string suffix; std::string suffix;
std::uint32_t divisor; std::uint32_t divisor;
int decimalPlaces; int decimalPlaces;
ValueRange() ValueRange() : min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {
: min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {} }
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step, ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step, const std::string &suffix = "", std::uint32_t divisor = 1,
const std::string& suffix = "", std::uint32_t divisor = 1, int decimalPlaces = 0) int decimalPlaces = 0)
: min(min), max(max), step(step), suffix(suffix), : min(min), max(max), step(step), suffix(suffix), divisor(divisor), decimalPlaces(decimalPlaces) {
divisor(divisor), decimalPlaces(decimalPlaces) {} }
}; };
struct ValueThresholds { struct ValueThresholds {
std::uint32_t warning; std::uint32_t warning;
std::uint32_t danger; std::uint32_t danger;
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0) ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0) : warning(warning), danger(danger) {
: warning(warning), danger(danger) {} }
}; };
struct NamedValue { struct NamedValue {
@@ -54,13 +55,12 @@ struct NamedValue {
std::uint32_t value; std::uint32_t value;
std::string rightText; std::string rightText;
NamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "") NamedValue(const std::string &name, std::uint32_t value, const std::string &rightText = "") : name(name), value(value), rightText(rightText) {
: name(name), value(value), rightText(rightText) {} }
}; };
class ValueChoiceGui : public BaseMenuGui class ValueChoiceGui : public BaseMenuGui {
{ protected:
protected:
std::uint32_t selectedValue; std::uint32_t selectedValue;
ValueRange range; ValueRange range;
std::string categoryName; std::string categoryName;
@@ -72,41 +72,31 @@ protected:
std::vector<NamedValue> namedValues; std::vector<NamedValue> namedValues;
bool showDefaultValue = true; bool showDefaultValue = true;
bool showDNO = false; bool showDNO = false;
tsl::elm::ListItem* createValueListItem(std::uint32_t value, bool selected, int safety); tsl::elm::ListItem *createValueListItem(std::uint32_t value, bool selected, int safety);
tsl::elm::ListItem* createNamedValueListItem(const NamedValue& namedValue, bool selected, int safety); tsl::elm::ListItem *createNamedValueListItem(const NamedValue &namedValue, bool selected, int safety);
std::string formatValue(std::uint32_t value); std::string formatValue(std::uint32_t value);
int getSafetyLevel(std::uint32_t value); int getSafetyLevel(std::uint32_t value);
public: public:
ValueChoiceGui(std::uint32_t selectedValue, ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
const ValueRange& range, const ValueThresholds &thresholds = ValueThresholds(), bool enableThresholds = false,
const std::string& categoryName, std::map<std::uint32_t, std::string> labels = {}, std::vector<NamedValue> namedValues = {}, bool showDefaultValue = true,
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); bool showDNO = false);
~ValueChoiceGui(); ~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); 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()); namedValues.insert(namedValues.end(), values.begin(), values.end());
} }
void clearNamedValues() void clearNamedValues() {
{
namedValues.clear(); namedValues.clear();
} }
void setShowDefaultValue(bool show) void setShowDefaultValue(bool show) {
{
showDefaultValue = show; showDefaultValue = show;
} }

View File

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

View File

@@ -24,31 +24,32 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "../hos/apm_ext.h" #include <battery.h>
#include <i2c.h>
#include <t210.h>
#include <max17050.h>
#include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include <hocclk.h> #include <hocclk.h>
#include <switch.h> #include <i2c.h>
#include <max17050.h>
#include <notification.h>
#include <pwm.h> #include <pwm.h>
#include <registers.h> #include <registers.h>
#include <battery.h> #include <switch.h>
#include "../display/display_refresh_rate.hpp" #include <t210.h>
#include <notification.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.hpp"
#include "board_fuse.hpp" #include "board_fuse.hpp"
#include "board_load.hpp" #include "board_load.hpp"
#include "board_volt.hpp"
#include "board_misc.hpp" #include "board_misc.hpp"
#include "../tsensor/soctherm.hpp" #include "board_volt.hpp"
#include "../tsensor/aotag.hpp" #include <ipc_server.h>
#include "../hos/integrations.hpp" #include <lockable_mutex.h>
#include "../file/file_utils.hpp"
#include "../hos/rgltr.h"
namespace board { namespace board {
u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr; u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr;
@@ -62,25 +63,25 @@ namespace board {
u32 fd = 0, fd2 = 0; u32 fd = 0, fd2 = 0;
#define PMC_BASE 0x7000E400 #define PMC_BASE 0x7000E400
#define APB_MISC_GP_HIDREV 0x804 #define APB_MISC_GP_HIDREV 0x804
#define GP_HIDREV_MAJOR_T210 0x1 #define GP_HIDREV_MAJOR_T210 0x1
#define GP_HIDREV_MAJOR_T210B01 0x2 #define GP_HIDREV_MAJOR_T210B01 0x2
#define APB_BASE 0x70000000 #define APB_BASE 0x70000000
#define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x)) #define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x))
#define FUSE_OFFSET 0x800 #define FUSE_OFFSET 0x800
void FetchHardwareInfos() { void FetchHardwareInfos() {
ReadFuses(fuseData, fuseVirtAddr); ReadFuses(fuseData, fuseVirtAddr);
SetGpuBracket(fuseData.gpuSpeedo, speedoBracket); SetGpuBracket(fuseData.gpuSpeedo, speedoBracket);
u32 hidrev = *(u32*)(apbVirtAddr + APB_MISC_GP_HIDREV); u32 hidrev = *(u32 *)(apbVirtAddr + APB_MISC_GP_HIDREV);
if (((hidrev >> 4) & 0xF) >= GP_HIDREV_MAJOR_T210B01) { if (((hidrev >> 4) & 0xF) >= GP_HIDREV_MAJOR_T210B01) {
gSocType = HocClkSocType_Mariko; gSocType = HocClkSocType_Mariko;
} else { } else {
gSocType = HocClkSocType_Erista; gSocType = HocClkSocType_Erista;
} }
u32 odm4 = *(u32*)(fuseVirtAddr + FUSE_OFFSET + FUSE_RESERVED_ODMX(4)); u32 odm4 = *(u32 *)(fuseVirtAddr + FUSE_OFFSET + FUSE_RESERVED_ODMX(4));
if (gSocType == HocClkSocType_Mariko) { if (gSocType == HocClkSocType_Mariko) {
switch ((odm4 & 0xF0000) >> 16) { switch ((odm4 & 0xF0000) >> 16) {
@@ -123,7 +124,7 @@ namespace board {
rc = psmInitialize(); rc = psmInitialize();
ASSERT_RESULT_OK(rc, "psmInitialize"); ASSERT_RESULT_OK(rc, "psmInitialize");
if(HOSSVC_HAS_TC) { if (HOSSVC_HAS_TC) {
rc = tcInitialize(); rc = tcInitialize();
ASSERT_RESULT_OK(rc, "tcInitialize"); ASSERT_RESULT_OK(rc, "tcInitialize");
} }
@@ -170,7 +171,7 @@ namespace board {
batteryInfoInitialize(); batteryInfoInitialize();
tsensor::InitializeSoctherm(); // SOCTHERM must be init before AOTAG tsensor::InitializeSoctherm(); // SOCTHERM must be init before AOTAG
// PMC exosphere check // PMC exosphere check
SecmonArgs args = {}; SecmonArgs args = {};
@@ -178,18 +179,21 @@ namespace board {
args.X[1] = PMC_BASE; args.X[1] = PMC_BASE;
svcCallSecureMonitor(&args); svcCallSecureMonitor(&args);
if (args.X[1] != PMC_BASE) { // if param 1 is identical read failed if (args.X[1] != PMC_BASE) { // if param 1 is identical read failed
tsensor::InitializeAotag(GetSocType() == HocClkSocType_Mariko); tsensor::InitializeAotag(GetSocType() == HocClkSocType_Mariko);
} }
Result pwmCheck = 1; Result pwmCheck = 1;
if (hosversionAtLeast(6,0,0) && R_SUCCEEDED(pwmInitialize())) { if (hosversionAtLeast(6, 0, 0) && R_SUCCEEDED(pwmInitialize())) {
pwmCheck = pwmOpenSession2(&iCon, 0x3D000001); pwmCheck = pwmOpenSession2(&iCon, 0x3D000001);
} }
StartMiscThread(pwmCheck, &iCon); 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); display::Initialize(&cfg);
CacheDfllData(); CacheDfllData();
@@ -243,7 +247,7 @@ namespace board {
args.X[1] = MC_REGISTER_BASE + MC_EMEM_CFG_0; args.X[1] = MC_REGISTER_BASE + MC_EMEM_CFG_0;
svcCallSecureMonitor(&args); svcCallSecureMonitor(&args);
if (args.X[1] == (MC_REGISTER_BASE + MC_EMEM_CFG_0)) { // if param 1 is identical read failed if (args.X[1] == (MC_REGISTER_BASE + MC_EMEM_CFG_0)) { // if param 1 is identical read failed
notification::writeNotification("Horizon OC\nSecmon read failed!\n This may be a hardware issue!"); notification::writeNotification("Horizon OC\nSecmon read failed!\n This may be a hardware issue!");
return false; return false;
} }
@@ -270,4 +274,4 @@ namespace board {
return false; /* stub for now. */ return false; /* stub for now. */
} }
} } // namespace board

View File

@@ -26,18 +26,20 @@
#pragma once #pragma once
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include <switch.h>
#include "../mapping/mem_map.hpp"
#include "board_freq.hpp"
#include "board_fuse.hpp" #include "board_fuse.hpp"
#include "board_load.hpp" #include "board_load.hpp"
#include "board_name.hpp" #include "board_name.hpp"
#include "board_freq.hpp" #include "board_profile.hpp"
#include "board_sensor.hpp" #include "board_sensor.hpp"
#include "board_volt.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_CLKRST (hosversionAtLeast(8,0,0)) #define HOSSVC_HAS_TC (hosversionAtLeast(5, 0, 0))
#define HOSSVC_HAS_TC (hosversionAtLeast(5,0,0))
namespace board { namespace board {
extern u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr; extern u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr;
@@ -58,4 +60,4 @@ namespace board {
FuseData *GetFuseData(); FuseData *GetFuseData();
bool IsUsingRetroSuperDisplay(); bool IsUsingRetroSuperDisplay();
} } // namespace board

View File

@@ -24,24 +24,25 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include "../i2c/i2cDrv.h"
#include <t210.h>
#include <max17050.h> #include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include <ipc_server.h>
#include <lockable_mutex.h>
#include "../display/display_refresh_rate.hpp" #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.hpp"
#include "board_name.hpp" #include "board_name.hpp"
#include "../file/errors.hpp" #include <ipc_server.h>
#include "../soc/pllmb.hpp" #include <lockable_mutex.h>
#include "../file/config.hpp"
#include "../soc/gm20b.hpp"
#include "../file/config.hpp"
namespace board { namespace board {
static u32 currentInjectedHz = 0; static u32 currentInjectedHz = 0;
static u32 gMarikoGm20bCutoff = 1228800000; static u32 gMarikoGm20bCutoff = 1228800000;
@@ -80,12 +81,12 @@ namespace board {
ASSERT_RESULT_OK(pcvSetClockRate(moduleID, hz), "pcvSetClockRate"); ASSERT_RESULT_OK(pcvSetClockRate(moduleID, hz), "pcvSetClockRate");
} }
void HandleCpuUv() void HandleCpuUv() {
{
if (board::GetSocType() == HocClkSocType_Erista) if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); // Erista tbreak is always 1581MHz board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); // Erista tbreak is always 1581MHz
else 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) { void SetHz(HocClkModule module, u32 hz) {
@@ -101,7 +102,8 @@ namespace board {
return; 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; u32 pcvHz = useGm20b ? ((hz + 76800000 - 1) / 76800000) * 76800000 : hz;
@@ -129,7 +131,7 @@ namespace board {
PcvSetHz(GetPcvModule(module), pcvHz); PcvSetHz(GetPcvModule(module), pcvHz);
} }
} }
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv) && module == HocClkModule_CPU) { if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv) && module == HocClkModule_CPU) {
HandleCpuUv(); HandleCpuUv();
} }
if (useGm20b) { if (useGm20b) {
@@ -181,7 +183,9 @@ namespace board {
case HocClkModule_GPU: case HocClkModule_GPU:
return t210ClkGpuFreq(); return t210ClkGpuFreq();
case HocClkModule_MEM: 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: case HocClkModule_Display:
return GetDisplayRate(hz); return GetDisplayRate(hz);
default: default:
@@ -197,7 +201,6 @@ namespace board {
s32 tmpInMaxCount = maxCount; s32 tmpInMaxCount = maxCount;
s32 tmpOutCount = 0; s32 tmpOutCount = 0;
if (HOSSVC_HAS_CLKRST) { if (HOSSVC_HAS_CLKRST) {
ClkrstSession session = {}; ClkrstSession session = {};
@@ -230,20 +233,20 @@ namespace board {
void ResetToStock() { void ResetToStock() {
Result rc; Result rc;
if (hosversionAtLeast(9,0,0)) { if (hosversionAtLeast(9, 0, 0)) {
std::uint32_t confId = 0; std::uint32_t confId = 0;
rc = apmExtGetCurrentPerformanceConfiguration(&confId); rc = apmExtGetCurrentPerformanceConfiguration(&confId);
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
HocClkApmConfiguration* apmConfiguration = nullptr; HocClkApmConfiguration *apmConfiguration = nullptr;
for (size_t i = 0; hocclk_g_apm_configurations[i].id; ++i) { for (size_t i = 0; hocclk_g_apm_configurations[i].id; ++i) {
if(hocclk_g_apm_configurations[i].id == confId) { if (hocclk_g_apm_configurations[i].id == confId) {
apmConfiguration = &hocclk_g_apm_configurations[i]; apmConfiguration = &hocclk_g_apm_configurations[i];
break; break;
} }
} }
if(!apmConfiguration) { if (!apmConfiguration) {
ERROR_THROW("Unknown apm configuration: %x", confId); ERROR_THROW("Unknown apm configuration: %x", confId);
} }
@@ -263,4 +266,4 @@ namespace board {
void ResetToStockDisplay() { void ResetToStockDisplay() {
display::SetRate(60); display::SetRate(60);
} }
} } // namespace board

View File

@@ -25,16 +25,18 @@
*/ */
#pragma once #pragma once
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h>
#include <max17050.h> #include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include "../file/errors.hpp"
#include "../hos/apm_ext.h"
#include <ipc_server.h> #include <ipc_server.h>
#include <lockable_mutex.h> #include <lockable_mutex.h>
#include "../file/errors.hpp"
namespace board { namespace board {
@@ -50,8 +52,7 @@ namespace board {
void ResetToStock(); void ResetToStock();
void ResetToStockDisplay(); void ResetToStockDisplay();
template <typename Getter> template <typename Getter> void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
Result rc = 0; Result rc = 0;
if (hosversionAtLeast(9, 0, 0)) { if (hosversionAtLeast(9, 0, 0)) {
@@ -59,7 +60,7 @@ namespace board {
rc = apmExtGetCurrentPerformanceConfiguration(&confId); rc = apmExtGetCurrentPerformanceConfiguration(&confId);
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
HocClkApmConfiguration* apmConfiguration = nullptr; HocClkApmConfiguration *apmConfiguration = nullptr;
for (size_t i = 0; hocclk_g_apm_configurations[i].id; ++i) { for (size_t i = 0; hocclk_g_apm_configurations[i].id; ++i) {
if (hocclk_g_apm_configurations[i].id == confId) { if (hocclk_g_apm_configurations[i].id == confId) {
@@ -84,15 +85,15 @@ namespace board {
} }
inline void ResetToStockCpu() { inline void ResetToStockCpu() {
ResetToStockModule([](const HocClkApmConfiguration& cfg) {return cfg.cpu_hz; }, HocClkModule_CPU); ResetToStockModule([](const HocClkApmConfiguration &cfg) { return cfg.cpu_hz; }, HocClkModule_CPU);
} }
inline void ResetToStockGpu() { inline void ResetToStockGpu() {
ResetToStockModule([](const HocClkApmConfiguration& cfg){ return cfg.gpu_hz; }, HocClkModule_GPU); ResetToStockModule([](const HocClkApmConfiguration &cfg) { return cfg.gpu_hz; }, HocClkModule_GPU);
} }
inline void ResetToStockMem() { inline void ResetToStockMem() {
ResetToStockModule([](const HocClkApmConfiguration& cfg){ return cfg.mem_hz; }, HocClkModule_MEM); ResetToStockModule([](const HocClkApmConfiguration &cfg) { return cfg.mem_hz; }, HocClkModule_MEM);
} }
} } // namespace board

View File

@@ -15,16 +15,18 @@
* *
*/ */
#include <switch.h>
#include <fuse.h>
#include "board_fuse.hpp"
#include <cstring> #include <cstring>
#include <fuse.h>
#include <switch.h>
#include "board.hpp" #include "board.hpp"
#include "board_fuse.hpp"
namespace board { namespace board {
void SetGpuBracket(u16 speedo, u8 &gpuBracket) { void SetGpuBracket(u16 speedo, u8 &gpuBracket) {
if(GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
if (speedo <= 1624) { if (speedo <= 1624) {
gpuBracket = 0; gpuBracket = 0;
return; return;
@@ -43,7 +45,7 @@ namespace board {
/* >= 1754 */ /* >= 1754 */
gpuBracket = 3; gpuBracket = 3;
} else { } else {
switch(speedo) { switch (speedo) {
case 1850 ... 1925: case 1850 ... 1925:
gpuBracket = 0; gpuBracket = 0;
break; break;
@@ -70,12 +72,12 @@ namespace board {
speedo.cpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_0_CALIB); speedo.cpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_0_CALIB);
speedo.gpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_2_CALIB); speedo.gpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_2_CALIB);
speedo.socSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_SPEEDO_0_CALIB); speedo.socSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_SPEEDO_0_CALIB);
speedo.cpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_IDDQ_CALIB) * 4; speedo.cpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_IDDQ_CALIB) * 4;
speedo.gpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_GPU_IDDQ_CALIB) * 5; speedo.gpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_GPU_IDDQ_CALIB) * 5;
speedo.socIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_IDDQ_CALIB) * 4; speedo.socIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_IDDQ_CALIB) * 4;
speedo.waferX = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_X_COORDINATE); speedo.waferX = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_X_COORDINATE);
speedo.waferY = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_Y_COORDINATE); speedo.waferY = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_Y_COORDINATE);
speedo.waferX = (speedo.waferX & BIT(8)) ? (speedo.waferX - 512) : speedo.waferX; 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 ReadFuses(FuseData &speedo, u64 fuseVa);
void SetGpuBracket(u16 gpuSpeedo, u8 &gpuBracket); 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 <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h> #include <math.h>
#include <max17050.h> #include <max17050.h>
#include <minIni.h>
#include <numeric>
#include <switch.h>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include "../hos/apm_ext.h"
#include "board.hpp"
#include "board_misc.hpp"
#include <ipc_server.h> #include <ipc_server.h>
#include <lockable_mutex.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 { namespace board {
@@ -61,23 +63,24 @@ namespace board {
constexpr double Systemtickfrequency = 19200000.0 * (static_cast<double>(CpuTimeOutNs) / 1'000'000'000.0); constexpr double Systemtickfrequency = 19200000.0 * (static_cast<double>(CpuTimeOutNs) / 1'000'000'000.0);
void GpuLoadThread(void *ptr) { void GpuLoadThread(void *ptr) {
#define gpu_samples_average 8 #define gpu_samples_average 8
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715 #define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
uint32_t gpu_load_array[gpu_samples_average] = {0}; uint32_t gpu_load_array[gpu_samples_average] = { 0 };
size_t i = 0; size_t i = 0;
if (R_SUCCEEDED(nvCheck_load)) do { if (R_SUCCEEDED(nvCheck_load))
u32 temp; do {
if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) { u32 temp;
gpu_load_array[i++ % gpu_samples_average] = temp; if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) {
gpuLoad = std::accumulate(&gpu_load_array[0], &gpu_load_array[gpu_samples_average], 0) / gpu_samples_average; gpu_load_array[i++ % gpu_samples_average] = temp;
} gpuLoad = std::accumulate(&gpu_load_array[0], &gpu_load_array[gpu_samples_average], 0) / gpu_samples_average;
svcSleepThread(16'666'000); // wait a bit (this is the perfect amount of time to keep the reading accurate) }
} while(true); svcSleepThread(16'666'000); // wait a bit (this is the perfect amount of time to keep the reading accurate)
} while (true);
} }
void CheckCore(void *idletickPtr) { void CheckCore(void *idletickPtr) {
u64* idletick = static_cast<u64 *>(idletickPtr); u64 *idletick = static_cast<u64 *>(idletickPtr);
while(true) { while (true) {
u64 idletickA; u64 idletickA;
u64 idletickB; u64 idletickB;
svcGetInfo(&idletickB, InfoType_IdleTickCount, INVALID_HANDLE, -1); svcGetInfo(&idletickB, InfoType_IdleTickCount, INVALID_HANDLE, -1);
@@ -107,11 +110,11 @@ namespace board {
float cpuUsage0 = std::clamp(((Systemtickfrequency - idletick0) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0); float cpuUsage0 = std::clamp(((Systemtickfrequency - idletick0) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
float cpuUsage1 = std::clamp(((Systemtickfrequency - idletick1) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0); float cpuUsage1 = std::clamp(((Systemtickfrequency - idletick1) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
float cpuUsage2 = std::clamp(((Systemtickfrequency - idletick2) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0); float cpuUsage2 = std::clamp(((Systemtickfrequency - idletick2) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
return std::round(std::max({cpuUsage0, cpuUsage1, cpuUsage2})); return std::round(std::max({ cpuUsage0, cpuUsage1, cpuUsage2 }));
} }
u32 GetPartLoad(HocClkPartLoad loadSource) { u32 GetPartLoad(HocClkPartLoad loadSource) {
switch(loadSource) { switch (loadSource) {
case HocClkPartLoad_EMC: case HocClkPartLoad_EMC:
return t210EmcLoadAll(); return t210EmcLoadAll();
case HocClkPartLoad_EMCCpu: case HocClkPartLoad_EMCCpu:
@@ -148,9 +151,9 @@ namespace board {
} }
namespace { namespace {
constexpr u32 NVschedCtrlEnable = 0x00000601; constexpr u32 NVschedCtrlEnable = 0x00000601;
constexpr u32 NVschedCtrlDisable = 0x00000602; constexpr u32 NVschedCtrlDisable = 0x00000602;
} } // namespace
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method) { void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method) {
if (R_FAILED(nvCheckSched) && method == GpuSchedulingOverrideMethod_NvService) { if (R_FAILED(nvCheckSched) && method == GpuSchedulingOverrideMethod_NvService) {
@@ -160,7 +163,8 @@ namespace board {
u32 temp; u32 temp;
bool enabled = false; bool enabled = false;
switch (mode) { switch (mode) {
case GpuSchedulingMode_DoNotOverride: break; case GpuSchedulingMode_DoNotOverride:
break;
case GpuSchedulingMode_Disabled: case GpuSchedulingMode_Disabled:
if (method == GpuSchedulingOverrideMethod_NvService) { if (method == GpuSchedulingOverrideMethod_NvService) {
nvIoctl(_fd2, NVschedCtrlDisable, &temp); nvIoctl(_fd2, NVschedCtrlDisable, &temp);
@@ -198,4 +202,4 @@ namespace board {
nvCheckSched = nvSched; nvCheckSched = nvSched;
} }
} } // namespace board

View File

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

View File

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

View File

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

View File

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

View File

@@ -25,8 +25,8 @@
*/ */
#pragma once #pragma once
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include <switch.h>
namespace board { namespace board {
@@ -35,4 +35,4 @@ namespace board {
const char *GetThermalSensorName(HocClkThermalSensor sensor, bool pretty); const char *GetThermalSensorName(HocClkThermalSensor sensor, bool pretty);
const char *GetPowerSensorName(HocClkPowerSensor 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 <hocclk.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h>
#include <max17050.h> #include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include "../hos/apm_ext.h"
#include "board.hpp"
#include <ipc_server.h> #include <ipc_server.h>
#include <lockable_mutex.h> #include <lockable_mutex.h>
#include "board.hpp"
namespace board { namespace board {
@@ -60,4 +61,4 @@ namespace board {
return HocClkProfile_Handheld; return HocClkProfile_Handheld;
} }
} } // namespace board

View File

@@ -28,7 +28,5 @@
#include <hocclk.h> #include <hocclk.h>
namespace board { namespace board {
HocClkProfile GetProfile(); 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 <battery.h>
#include <cmath>
#include <hocclk.h>
#include <i2c.h>
#include <max17050.h>
#include <pwm.h> #include <pwm.h>
#include "board.hpp" #include <switch.h>
#include "../tsensor/soctherm.hpp" #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/aotag.hpp"
#include "../tsensor/bq24193.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 { namespace board {
@@ -52,7 +54,7 @@ namespace board {
tsensor::TSensorTemps temps = {}; tsensor::TSensorTemps temps = {};
tsensor::ReadTSensors(temps); tsensor::ReadTSensors(temps);
switch(sensor) { switch (sensor) {
case HocClkThermalSensor_SOC: { case HocClkThermalSensor_SOC: {
millis = tmp451TempSoc(); millis = tmp451TempSoc();
break; break;
@@ -127,4 +129,4 @@ namespace board {
return 0; return 0;
} }
} } // namespace board

View File

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

View File

@@ -17,22 +17,24 @@
* *
*/ */
#include <switch.h> #include <battery.h>
#include <cstring>
#include <hocclk.h> #include <hocclk.h>
#include <memmem.h> #include <memmem.h>
#include <registers.h> #include <registers.h>
#include <cstring> #include <switch.h>
#include <battery.h>
#include "../file/file_utils.hpp"
#include "../hos/rgltr.h"
#include "../i2c/i2cDrv.h"
#include "board.hpp" #include "board.hpp"
#include "board_freq.hpp" #include "board_freq.hpp"
#include "board_volt.hpp" #include "board_volt.hpp"
#include "../file/file_utils.hpp"
#include "../i2c/i2cDrv.h"
#include "../hos/rgltr.h"
namespace board { namespace board {
GpuVoltData voltData = {}; GpuVoltData voltData = {};
u32 cpuVoltTable[32] = {}; // 32LUT u32 cpuVoltTable[32] = {}; // 32LUT
u64 cldvfs; u64 cldvfs;
CpuDfllData cachedTune; CpuDfllData cachedTune;
@@ -50,54 +52,30 @@ namespace board {
u32 tune1_high; u32 tune1_high;
}; };
EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = { // <2118 CPU speedo EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = {
{0xFFEAD0FF, 0x25501d0}, // <2118 CPU speedo
{0xffff, 0x27007ff}, { 0xFFEAD0FF, 0x25501d0 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
{0xefff, 0x27407ff}, { 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
{0xdfff, 0x27807ff},
{0xdfdf, 0x27a07ff},
{0xcfdf, 0x37007ff},
}; };
EristaCpuUvEntry eristaCpuUvTableHighBracket[6] = { EristaCpuUvEntry eristaCpuUvTableHighBracket[6] = {
{0xFFEAD0FF, 0x20091d9}, { 0xFFEAD0FF, 0x20091d9 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
{0xffff, 0x27007ff}, { 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
{0xefff, 0x27407ff},
{0xdfff, 0x27807ff},
{0xdfdf, 0x27a07ff},
{0xcfdf, 0x37007ff},
}; };
MarikoCpuUvEntry marikoCpuUvLow[12] = { MarikoCpuUvEntry marikoCpuUvLow[12] = {
{0xffa0, 0xffff, 0x21107ff, 0}, { 0xffa0, 0xffff, 0x21107ff, 0 }, { 0x0, 0xffdf, 0x21107ff, 0x27207ff }, { 0xffdf, 0xffdf, 0x21107ff, 0x27307ff },
{0x0, 0xffdf, 0x21107ff, 0x27207ff}, { 0xffff, 0xffdf, 0x21107ff, 0x27407ff }, { 0x0, 0xffdf, 0x21607ff, 0x27707ff }, { 0x0, 0xffdf, 0x21607ff, 0x27807ff },
{0xffdf, 0xffdf, 0x21107ff, 0x27307ff}, { 0x0, 0xdfff, 0x21607ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27c07ff },
{0xffff, 0xffdf, 0x21107ff, 0x27407ff}, { 0xdfff, 0xdfff, 0x21707ff, 0x27d07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27e07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27f07ff },
{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] = { MarikoCpuUvEntry marikoCpuUvHigh[12] = {
{0x0, 0xffff, 0, 0}, { 0x0, 0xffff, 0, 0 }, { 0x0, 0xffdf, 0, 0x27207ff }, { 0x0, 0xffdf, 0, 0x27307ff }, { 0x0, 0xffdf, 0, 0x27407ff },
{0x0, 0xffdf, 0, 0x27207ff}, { 0x0, 0xffdf, 0, 0x27707ff }, { 0x0, 0xffdf, 0, 0x27807ff }, { 0x0, 0xdfff, 0, 0x27b07ff }, { 0x0, 0xdfff, 0, 0x27c07ff },
{0x0, 0xffdf, 0, 0x27307ff}, { 0x0, 0xdfff, 0, 0x27d07ff }, { 0x0, 0xdfff, 0, 0x27e07ff }, { 0x0, 0xdfff, 0, 0x27f07ff }, { 0x0, 0xdfff, 0, 0x27f07ff },
{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() { void CacheDfllData() {
Result rc = QueryMemoryMapping(&cldvfs, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE); Result rc = QueryMemoryMapping(&cldvfs, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE);
@@ -111,33 +89,33 @@ namespace board {
/* TODO: clean up this code. */ /* TODO: clean up this code. */
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint) { void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint) {
u32* tune0_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0); u32 *tune0_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
u32* tune1_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0); u32 *tune1_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
if (GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
if (GetHz(HocClkModule_CPU) < tbreakPoint && (levelLow || levelHigh)) { if (GetHz(HocClkModule_CPU) < tbreakPoint && (levelLow || levelHigh)) {
if (levelLow) { if (levelLow) {
*tune0_ptr = marikoCpuUvLow[levelLow-1].tune0_low; *tune0_ptr = marikoCpuUvLow[levelLow - 1].tune0_low;
*tune1_ptr = marikoCpuUvLow[levelLow-1].tune1_low; *tune1_ptr = marikoCpuUvLow[levelLow - 1].tune1_low;
} }
return; return;
} else { } else {
if (levelLow) { if (levelLow) {
*tune0_ptr = marikoCpuUvLow[levelLow-1].tune0_low; *tune0_ptr = marikoCpuUvLow[levelLow - 1].tune0_low;
*tune1_ptr = marikoCpuUvLow[levelLow-1].tune1_low; *tune1_ptr = marikoCpuUvLow[levelLow - 1].tune1_low;
} }
if (levelHigh) { if (levelHigh) {
*tune0_ptr = marikoCpuUvHigh[levelHigh-1].tune0_high; *tune0_ptr = marikoCpuUvHigh[levelHigh - 1].tune0_high;
*tune1_ptr = marikoCpuUvHigh[levelHigh-1].tune1_high; *tune1_ptr = marikoCpuUvHigh[levelHigh - 1].tune1_high;
} }
return; return;
} }
if (GetHz(HocClkModule_CPU) < tbreakPoint || (!levelLow)) { // account for tbreak if (GetHz(HocClkModule_CPU) < tbreakPoint || (!levelLow)) { // account for tbreak
*tune0_ptr = 0xCFFF; *tune0_ptr = 0xCFFF;
*tune1_ptr = 0xFF072201; *tune1_ptr = 0xFF072201;
return; return;
} else if (GetHz(HocClkModule_CPU) >= tbreakPoint || (!levelHigh)) { } else if (GetHz(HocClkModule_CPU) >= tbreakPoint || (!levelHigh)) {
*tune0_ptr = cachedTune.tune0High; // per console? *tune0_ptr = cachedTune.tune0High; // per console?
*tune1_ptr = 0xFFF7FF3F; *tune1_ptr = 0xFFF7FF3F;
return; return;
} }
@@ -210,9 +188,9 @@ namespace board {
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
} PowerDomainId; } PowerDomainId;
*/ */
/* /*
Note: I think Nintendo's I2C driver (or my driver, but it looks correct to me) Note: I think Nintendo's I2C driver (or my driver, but it looks correct to me)
*/ */
u32 GetVoltage(HocClkVoltage voltage) { u32 GetVoltage(HocClkVoltage voltage) {
u32 out = 0; u32 out = 0;
BatteryChargeInfo info; BatteryChargeInfo info;
@@ -225,7 +203,7 @@ namespace board {
out = I2c_BuckConverter_GetUvOut(&I2c_VDD2); out = I2c_BuckConverter_GetUvOut(&I2c_VDD2);
break; break;
case HocClkVoltage_CPU: case HocClkVoltage_CPU:
if(GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_CPU); out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_CPU);
} else { } else {
rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Cpu); rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Cpu);
@@ -234,7 +212,7 @@ namespace board {
} }
break; break;
case HocClkVoltage_GPU: case HocClkVoltage_GPU:
if(GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_GPU); out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_GPU);
} else { } else {
rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Gpu); rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Gpu);
@@ -243,7 +221,7 @@ namespace board {
} }
break; break;
case HocClkVoltage_EMCVDDQ: case HocClkVoltage_EMCVDDQ:
if(GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_DRAM_VDDQ); out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_DRAM_VDDQ);
} else { } else {
out = I2c_BuckConverter_GetUvOut(&I2c_VDD2); out = I2c_BuckConverter_GetUvOut(&I2c_VDD2);
@@ -266,8 +244,8 @@ namespace board {
Handle GetPcvHandle() { Handle GetPcvHandle() {
constexpr u64 PcvID = 0x10000000000001a; constexpr u64 PcvID = 0x10000000000001a;
u64 processIDList[80]{}; u64 processIDList[80]{};
s32 processCount = 0; s32 processCount = 0;
Handle handle = INVALID_HANDLE; Handle handle = INVALID_HANDLE;
DebugEventInfo debugEvent{}; DebugEventInfo debugEvent{};
@@ -306,9 +284,9 @@ namespace board {
void CacheGpuVoltTable() { void CacheGpuVoltTable() {
// Likely CPU regulator? // Likely CPU regulator?
UnkRegulator reg = { UnkRegulator reg = {
.voltageMin = 600000, .voltageMin = 600000,
.voltageStep = 12500, .voltageStep = 12500,
.voltageMax = 1400000, .voltageMax = 1400000,
}; };
Handle handle = GetPcvHandle(); Handle handle = GetPcvHandle();
@@ -365,17 +343,17 @@ namespace board {
} }
constexpr u32 CpuVoltageTableOffset = 0xB8; constexpr u32 CpuVoltageTableOffset = 0xB8;
std::memcpy(cpuVoltTable, &buffer[index + CpuVoltageTableOffset], sizeof(cpuVoltTable)); // TODO: verify the CPU table std::memcpy(cpuVoltTable, &buffer[index + CpuVoltageTableOffset], sizeof(cpuVoltTable)); // TODO: verify the CPU table
svcCloseHandle(handle); svcCloseHandle(handle);
handle = INVALID_HANDLE; handle = INVALID_HANDLE;
// Print info AFTER we exit the handle to avoid hangs // Print info AFTER we exit the handle to avoid hangs
for(int i = 0; i < (int)std::size(cpuVoltTable); ++i) { for (int i = 0; i < (int)std::size(cpuVoltTable); ++i) {
fileUtils::LogLine("[dvfs] cpu volt %d: %u mV", i, cpuVoltTable[i]); fileUtils::LogLine("[dvfs] cpu volt %d: %u mV", i, cpuVoltTable[i]);
} }
for(int i = 0; i < (int)std::size(voltData.voltTable); ++i) { for (int i = 0; i < (int)std::size(voltData.voltTable); ++i) {
fileUtils::LogLine("[dvfs] gpu volt %d: %u mV", i, voltData.voltTable[0][i]); fileUtils::LogLine("[dvfs] gpu volt %d: %u mV", i, voltData.voltTable[0][i]);
} }
return; return;
@@ -420,35 +398,50 @@ namespace board {
u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket) { u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket) {
u32 baseVolt = 800; u32 baseVolt = 800;
if(GetSocType() == HocClkSocType_Mariko) { if (GetSocType() == HocClkSocType_Mariko) {
static const u32 ramTable[][22] = { 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 2133, 2200, 2266, 2300, 2366, 2400, 2433, 2466, 2533, 2566, 2600,
{ 2433, 2466, 2533, 2566, 2600, 2666, 2766, 2800, 2833, 2866, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3300, 3333, 3366, }, // Bracket 2 2633, 2700, 2733, 2766, 2833, 2866, 2900, 2933, 3033, 3066, 3100,
{ 2500, 2533, 2600, 2633, 2666, 2733, 2800, 2866, 2900, 2966, 3033, 3100, 3166, 3200, 3233, 3266, 3300, 3333, 3366, 3400, 3400, 3400, }, // Bracket 3 }, // 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 (freqMhz <= 1600)
if (bracket >= std::size(ramTable)) bracket = 0; 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 bracketStart = ramTable[bracket][0];
u32 rampStartVolt = (bracket == 0) ? 535 : 525; // Do not touch!
u32 rampStartVolt = (bracket == 0) ? 535 : 525; // Do not touch!
u32 rampSpan = 590 - rampStartVolt; u32 rampSpan = 590 - rampStartVolt;
if (freqMhz >= 1633 && freqMhz < bracketStart) { if (freqMhz >= 1633 && freqMhz < bracketStart) {
u32 raw = rampStartVolt + ((freqMhz - 1633) * rampSpan) / (bracketStart - 1633); u32 raw = rampStartVolt + ((freqMhz - 1633) * rampSpan) / (bracketStart - 1633);
u32 volt = ((raw + 2) / 5) * 5; u32 volt = ((raw + 2) / 5) * 5;
if (volt < rampStartVolt) volt = rampStartVolt; if (volt < rampStartVolt)
if (volt > 590) volt = 590; volt = rampStartVolt;
if (volt > 590)
volt = 590;
return volt; return volt;
} }
baseVolt = gpuVoltArray[std::size(gpuVoltArray) - 1]; baseVolt = gpuVoltArray[std::size(gpuVoltArray) - 1];
for (u32 i = 0; i < std::size(gpuVoltArray); ++i) { for (u32 i = 0; i < std::size(gpuVoltArray); ++i) {
if (freqMhz <= ramTable[bracket][i]) { if (freqMhz <= ramTable[bracket][i]) {
@@ -457,20 +450,97 @@ namespace board {
} }
} }
} else { } else {
struct DvfsEntry { u32 freq; u32 volt; }; struct DvfsEntry {
u32 freq;
u32 volt;
};
static const DvfsEntry ramTable[][19] = { 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, 725 },
{ {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 { 1800, 730 },
{ {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 { 1866, 735 },
{ {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 { 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 (freqMhz <= 1600)
if (bracket >= std::size(ramTable)) bracket = 0; return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
if (bracket >= std::size(ramTable))
bracket = 0;
const auto& entries = ramTable[bracket]; const auto &entries = ramTable[bracket];
baseVolt = entries[std::size(entries) - 1].volt; baseVolt = entries[std::size(entries) - 1].volt;
for (const auto& entry : entries) { for (const auto &entry : entries) {
if (freqMhz <= entry.freq) { if (freqMhz <= entry.freq) {
baseVolt = entry.volt; baseVolt = entry.volt;
break; break;
@@ -480,4 +550,4 @@ namespace board {
return baseVolt; return baseVolt;
} }
} } // namespace board

View File

@@ -16,8 +16,9 @@
*/ */
#pragma once #pragma once
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include <switch.h>
namespace board { namespace board {
@@ -37,9 +38,9 @@ namespace board {
u32 tune0High; u32 tune0High;
u32 tune1Low; u32 tune1Low;
u32 tune1High; u32 tune1High;
// u32 tune_high_min_millivolts; // u32 tune_high_min_millivolts;
// u32 tune_high_margin_millivolts; // u32 tune_high_margin_millivolts;
// u64 dvco_calibration_max; // u64 dvco_calibration_max;
}; };
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint); void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint);
@@ -50,4 +51,4 @@ namespace board {
void PcvHijackGpuVolts(u32 vmin); void PcvHijackGpuVolts(u32 vmin);
u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket); u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket);
} } // namespace board

View File

@@ -23,26 +23,24 @@
// I *think* HOS changes this in some ways, so look into it more // I *think* HOS changes this in some ways, so look into it more
namespace AulaDisplay { namespace AulaDisplay {
#define MMIO_REG32(base, off) *(vu32 *)((base) + (off)) #define MMIO_REG32(base, off) *(vu32 *)((base) + (off))
#define DSI(off) MMIO_REG32(board::dsiVirtAddr, (off) << 2u) #define DSI(off) MMIO_REG32(board::dsiVirtAddr, (off) << 2u)
#define DSI_WR_DATA 0xA #define DSI_WR_DATA 0xA
#define DSI_TRIGGER 0x13 #define DSI_TRIGGER 0x13
void _display_dsi_send_cmd(u8 cmd, u32 param, u32 wait) { void _display_dsi_send_cmd(u8 cmd, u32 param, u32 wait) {
DSI(DSI_WR_DATA) = (param << 8) | cmd; DSI(DSI_WR_DATA) = (param << 8) | cmd;
DSI(DSI_TRIGGER) = DSI_TRIGGER_HOST; DSI(DSI_TRIGGER) = DSI_TRIGGER_HOST;
if (wait) if (wait)
svcSleepThread(wait * 1000); // usleep-equivalant svcSleepThread(wait * 1000); // usleep-equivalant
} }
void SetDisplayColorMode(AulaColorMode mode) { void SetDisplayColorMode(AulaColorMode mode) {
if(mode == AulaDisplayColorMode_DoNotOverride) if (mode == AulaDisplayColorMode_DoNotOverride)
return; return;
// send display command to change color mode. // send display command to change color mode.
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM, _display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM, MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
} }
} } // namespace AulaDisplay

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -15,23 +15,24 @@
* *
*/ */
#include "display_refresh_rate.hpp"
#include <string.h>
#include <math.h> #include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h>
#include <switch.h> #include <switch.h>
#include "display_refresh_rate.hpp"
namespace display { namespace display {
#define DSI_CLOCK_HZ 234000000llu #define DSI_CLOCK_HZ 234000000llu
#define NVDISP_GET_MODE2 0x803C021B #define NVDISP_GET_MODE2 0x803C021B
#define NVDISP_SET_MODE2 0x403C021C #define NVDISP_SET_MODE2 0x403C021C
#define NVDISP_VALIDATE_MODE2 0xC03C021D #define NVDISP_VALIDATE_MODE2 0xC03C021D
#define NVDISP_GET_MODE_DB2 0xEF20021E #define NVDISP_GET_MODE_DB2 0xEF20021E
#define NVDISP_GET_PANEL_DATA 0xC01C0226 #define NVDISP_GET_PANEL_DATA 0xC01C0226
#define MAX_REFRESH_RATE 72 #define MAX_REFRESH_RATE 72
static DisplayRefreshConfig g_config = {0}; static DisplayRefreshConfig g_config = { 0 };
static bool g_initialized = false; static bool g_initialized = false;
static uint8_t g_dockedHighestRefreshRate = 60; static uint8_t g_dockedHighestRefreshRate = 60;
@@ -41,7 +42,8 @@ namespace display {
static bool g_canChangeRefreshRateDocked = false; static bool g_canChangeRefreshRateDocked = false;
static uint8_t g_lastVActiveSet = 0; 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: // 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 // 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
@@ -59,83 +61,85 @@ namespace display {
} DockedTimings; } DockedTimings;
*/ */
static const DockedTimings g_dockedTimings1080p[] = { static const DockedTimings g_dockedTimings1080p[] = {
{8, 32, 40, 7, 8, 6, 0, 88080}, // 40Hz { 8, 32, 40, 7, 8, 6, 0, 88080 }, // 40Hz
{8, 32, 40, 9, 8, 6, 0, 99270}, // 45Hz { 8, 32, 40, 9, 8, 6, 0, 99270 }, // 45Hz
{528, 44, 148, 4, 5, 36, 31, 148500}, // 50Hz { 528, 44, 148, 4, 5, 36, 31, 148500 }, // 50Hz
{8, 32, 40, 15, 8, 6, 0, 121990}, // 55Hz { 8, 32, 40, 15, 8, 6, 0, 121990 }, // 55Hz
{88, 44, 148, 4, 5, 36, 16, 148500}, // 60Hz { 88, 44, 148, 4, 5, 36, 16, 148500 }, // 60Hz
{8, 32, 40, 22, 8, 6, 0, 156240}, // 70Hz { 8, 32, 40, 22, 8, 6, 0, 156240 }, // 70Hz
{8, 32, 40, 23, 8, 6, 0, 160848}, // 72Hz { 8, 32, 40, 23, 8, 6, 0, 160848 }, // 72Hz
{8, 32, 40, 25, 8, 6, 0, 167850}, // 75Hz { 8, 32, 40, 25, 8, 6, 0, 167850 }, // 75Hz
{8, 32, 40, 28, 8, 6, 0, 179520}, // 80Hz { 8, 32, 40, 28, 8, 6, 0, 179520 }, // 80Hz
{8, 32, 40, 33, 8, 6, 0, 202860}, // 90Hz { 8, 32, 40, 33, 8, 6, 0, 202860 }, // 90Hz
{8, 32, 40, 36, 8, 6, 0, 214700}, // 95Hz { 8, 32, 40, 36, 8, 6, 0, 214700 }, // 95Hz
{528, 44, 148, 4, 5, 36, 64, 297000}, // 100Hz { 528, 44, 148, 4, 5, 36, 64, 297000 }, // 100Hz
{8, 32, 40, 44, 8, 6, 0, 250360}, // 110Hz { 8, 32, 40, 44, 8, 6, 0, 250360 }, // 110Hz
{88, 44, 148, 4, 5, 36, 63, 297000}, // 120Hz { 88, 44, 148, 4, 5, 36, 63, 297000 }, // 120Hz
{8, 32, 40, 55, 8, 6, 0, 298750}, //130Hz CVT-RBv2 { 8, 32, 40, 55, 8, 6, 0, 298750 }, // 130Hz CVT-RBv2
{8, 32, 40, 61, 8, 6, 0, 323400}, //140Hz CVT-RBv2 { 8, 32, 40, 61, 8, 6, 0, 323400 }, // 140Hz CVT-RBv2
{8, 32, 40, 63, 8, 6, 0, 333216}, //144Hz CVT-RBv2 { 8, 32, 40, 63, 8, 6, 0, 333216 }, // 144Hz CVT-RBv2
{8, 32, 40, 67, 8, 6, 0, 348300}, //150Hz CVT-RBv2 { 8, 32, 40, 67, 8, 6, 0, 348300 }, // 150Hz CVT-RBv2
{8, 32, 40, 72, 8, 6, 0, 373120}, //160Hz CVT-RBv2 { 8, 32, 40, 72, 8, 6, 0, 373120 }, // 160Hz CVT-RBv2
{8, 32, 40, 75, 8, 6, 0, 385770}, //165Hz CVT-RBv2 { 8, 32, 40, 75, 8, 6, 0, 385770 }, // 165Hz CVT-RBv2
{8, 32, 40, 78, 8, 6, 0, 398480}, //170Hz CVT-RBv2 { 8, 32, 40, 78, 8, 6, 0, 398480 }, // 170Hz CVT-RBv2
{8, 32, 40, 84, 8, 6, 0, 424080}, //180Hz CVT-RBv2 { 8, 32, 40, 84, 8, 6, 0, 424080 }, // 180Hz CVT-RBv2
{8, 32, 40, 90, 8, 6, 0, 449920}, //190Hz CVT-RBv2 { 8, 32, 40, 90, 8, 6, 0, 449920 }, // 190Hz CVT-RBv2
{8, 32, 40, 96, 8, 6, 0, 476000}, //200Hz CVT-RBv2 { 8, 32, 40, 96, 8, 6, 0, 476000 }, // 200Hz CVT-RBv2
{8, 32, 40, 102, 8, 6, 0, 502320}, //210Hz CVT-RBv2 { 8, 32, 40, 102, 8, 6, 0, 502320 }, // 210Hz CVT-RBv2
{8, 32, 40, 108, 8, 6, 0, 528880}, //220Hz CVT-RBv2 { 8, 32, 40, 108, 8, 6, 0, 528880 }, // 220Hz CVT-RBv2
{8, 32, 40, 114, 8, 6, 0, 555680}, //230Hz CVT-RBv2 { 8, 32, 40, 114, 8, 6, 0, 555680 }, // 230Hz CVT-RBv2
{8, 32, 40, 121, 8, 6, 0, 583200}, //240Hz CVT-RBv2 { 8, 32, 40, 121, 8, 6, 0, 583200 }, // 240Hz CVT-RBv2
// technically you can go to 476hz, but in practice, why would you? // technically you can go to 476hz, but in practice, why would you?
}; };
// These timings *should* work but are untested // These timings *should* work but are untested
static const HandheldTimings g_handheldTimingsRETRO[] = { static const HandheldTimings g_handheldTimingsRETRO[] = {
{72, 136, 72, 1, 660, 9, 78000}, // 40Hz { 72, 136, 72, 1, 660, 9, 78000 }, // 40Hz
{72, 136, 72, 1, 612, 9, 77982}, // 41Hz { 72, 136, 72, 1, 612, 9, 77982 }, // 41Hz
{72, 136, 72, 1, 567, 9, 77994}, // 42Hz { 72, 136, 72, 1, 567, 9, 77994 }, // 42Hz
{72, 136, 72, 1, 524, 9, 78002}, // 43Hz { 72, 136, 72, 1, 524, 9, 78002 }, // 43Hz
{72, 136, 72, 1, 483, 9, 78012}, // 44Hz { 72, 136, 72, 1, 483, 9, 78012 }, // 44Hz
{72, 136, 72, 1, 443, 9, 77985}, // 45Hz { 72, 136, 72, 1, 443, 9, 77985 }, // 45Hz
{72, 136, 72, 1, 406, 9, 78016}, // 46Hz { 72, 136, 72, 1, 406, 9, 78016 }, // 46Hz
{72, 136, 72, 1, 370, 9, 78020}, // 47Hz { 72, 136, 72, 1, 370, 9, 78020 }, // 47Hz
{72, 136, 72, 1, 335, 9, 78000}, // 48Hz { 72, 136, 72, 1, 335, 9, 78000 }, // 48Hz
{72, 136, 72, 1, 302, 9, 78008}, // 49Hz { 72, 136, 72, 1, 302, 9, 78008 }, // 49Hz
{72, 136, 72, 1, 270, 9, 78000}, // 50Hz { 72, 136, 72, 1, 270, 9, 78000 }, // 50Hz
{72, 136, 72, 1, 239, 9, 77979}, // 51Hz { 72, 136, 72, 1, 239, 9, 77979 }, // 51Hz
{72, 136, 72, 1, 210, 9, 78000}, // 52Hz { 72, 136, 72, 1, 210, 9, 78000 }, // 52Hz
{72, 136, 72, 1, 182, 9, 78016}, // 53Hz { 72, 136, 72, 1, 182, 9, 78016 }, // 53Hz
{72, 136, 72, 1, 154, 9, 77976}, // 54Hz { 72, 136, 72, 1, 154, 9, 77976 }, // 54Hz
{72, 136, 72, 1, 128, 9, 77990}, // 55Hz { 72, 136, 72, 1, 128, 9, 77990 }, // 55Hz
{72, 136, 72, 1, 103, 9, 78008}, // 56Hz { 72, 136, 72, 1, 103, 9, 78008 }, // 56Hz
{72, 136, 72, 1, 78, 9, 77976}, // 57Hz { 72, 136, 72, 1, 78, 9, 77976 }, // 57Hz
{72, 136, 72, 1, 55, 9, 78010}, // 58Hz { 72, 136, 72, 1, 55, 9, 78010 }, // 58Hz
{72, 136, 72, 1, 32, 9, 77998}, // 59Hz { 72, 136, 72, 1, 32, 9, 77998 }, // 59Hz
{72, 136, 72, 1, 10, 9, 78000}, // 60Hz { 72, 136, 72, 1, 10, 9, 78000 }, // 60Hz
}; };
static const MinMaxRefreshRate g_handheldModeRefreshRate = {40, 80}; static const MinMaxRefreshRate g_handheldModeRefreshRate = { 40, 80 };
static uint8_t _getDockedRefreshRateIterator(uint32_t refreshRate) { static uint8_t _getDockedRefreshRateIterator(uint32_t refreshRate) {
for (size_t i = 0; i < sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]); i++) { 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; return 0xFF;
} }
static void _changeOledElvssSettings(const uint32_t* offsets, const uint32_t* value, uint32_t size, uint32_t start) { 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; volatile uint32_t *dsi = (uint32_t *)g_config.dsiVirtAddr;
#define DSI_VIDEO_MODE_CONTROL 0x4E #define DSI_VIDEO_MODE_CONTROL 0x4E
#define DSI_WR_DATA 0xA #define DSI_WR_DATA 0xA
#define DSI_TRIGGER 0x13 #define DSI_TRIGGER 0x13
#define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15 #define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15
#define MIPI_DSI_DCS_LONG_WRITE 0x39 #define MIPI_DSI_DCS_LONG_WRITE 0x39
#define MIPI_DCS_PRIV_SM_SET_REG_OFFSET 0xB0 #define MIPI_DCS_PRIV_SM_SET_REG_OFFSET 0xB0
#define MIPI_DCS_PRIV_SM_SET_ELVSS 0xB1 #define MIPI_DCS_PRIV_SM_SET_ELVSS 0xB1
dsi[DSI_VIDEO_MODE_CONTROL] = true; dsi[DSI_VIDEO_MODE_CONTROL] = true;
svcSleepThread(20000000); svcSleepThread(20000000);
@@ -164,8 +168,9 @@ namespace display {
g_config.isDocked = isDocked; g_config.isDocked = isDocked;
} }
bool Initialize(const DisplayRefreshConfig* config) { bool Initialize(const DisplayRefreshConfig *config) {
if (!config) return false; if (!config)
return false;
g_config = *config; g_config = *config;
g_initialized = true; g_initialized = true;
@@ -187,22 +192,26 @@ namespace display {
} }
counter = 0; counter = 0;
uint32_t offsets[] = {0x1A, 0x24, 0x25}; uint32_t offsets[] = { 0x1A, 0x24, 0x25 };
uint32_t values[] = {2, 0, 0x83}; uint32_t values[] = { 2, 0, 0x83 };
if (refresh_rate == 60) { if (refresh_rate == 60) {
if (last_refresh_rate == 60) return; if (last_refresh_rate == 60)
return;
} else if (refresh_rate == 45) { } else if (refresh_rate == 45) {
if (last_refresh_rate == 45) return; if (last_refresh_rate == 45)
uint32_t vals[] = {4, 1, 0}; return;
uint32_t vals[] = { 4, 1, 0 };
memcpy(values, vals, sizeof(vals)); memcpy(values, vals, sizeof(vals));
} else if (refresh_rate == 50) { } else if (refresh_rate == 50) {
if (last_refresh_rate == 50) return; if (last_refresh_rate == 50)
uint32_t vals[] = {3, 1, 0}; return;
uint32_t vals[] = { 3, 1, 0 };
memcpy(values, vals, sizeof(vals)); memcpy(values, vals, sizeof(vals));
} else if (refresh_rate == 55) { } else if (refresh_rate == 55) {
if (last_refresh_rate == 55) return; if (last_refresh_rate == 55)
uint32_t vals[] = {3, 1, 0}; return;
uint32_t vals[] = { 3, 1, 0 };
memcpy(values, vals, sizeof(vals)); memcpy(values, vals, sizeof(vals));
} else { } else {
return; return;
@@ -228,8 +237,9 @@ namespace display {
uint8_t highestRefreshRate = 60; uint8_t highestRefreshRate = 60;
uint32_t fd = fd_in; uint32_t fd = fd_in;
if(!fd) nvOpen(&fd, "/dev/nvdisp-disp1"); if (!fd)
NvdcModeDB2 db2 = {0}; nvOpen(&fd, "/dev/nvdisp-disp1");
NvdcModeDB2 db2 = { 0 };
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2); int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
if (rc == 0) { if (rc == 0) {
@@ -252,7 +262,7 @@ namespace display {
if (highestRefreshRate > g_dockedRefreshRates[numRates - 1]) if (highestRefreshRate > g_dockedRefreshRates[numRates - 1])
highestRefreshRate = g_dockedRefreshRates[numRates - 1]; highestRefreshRate = g_dockedRefreshRates[numRates - 1];
NvdcMode2 display_b = {0}; NvdcMode2 display_b = { 0 };
rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b); rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
struct dpaux_read_0x100 { struct dpaux_read_0x100 {
@@ -261,15 +271,15 @@ namespace display {
uint32_t size; uint32_t size;
struct { struct {
unsigned char link_rate; unsigned char link_rate;
unsigned int lane_count: 5; unsigned int lane_count : 5;
unsigned int unk1: 2; unsigned int unk1 : 2;
unsigned int isFramingEnhanced: 1; unsigned int isFramingEnhanced : 1;
unsigned char downspread; unsigned char downspread;
unsigned char training_pattern; unsigned char training_pattern;
unsigned char lane_pattern[4]; unsigned char lane_pattern[4];
unsigned char unk2[8]; unsigned char unk2[8];
} set; } set;
} dpaux = {6, 0x100, 0x10}; } dpaux = { 6, 0x100, 0x10 };
rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux); rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
if (rc == 0) { if (rc == 0) {
@@ -278,12 +288,14 @@ namespace display {
// highestRefreshRate = 75; // highestRefreshRate = 75;
} }
if (!fd_in) nvClose(fd); if (!fd_in)
nvClose(fd);
g_dockedHighestRefreshRate = highestRefreshRate; g_dockedHighestRefreshRate = highestRefreshRate;
} }
static bool _setPLLDHandheldRefreshRate(uint32_t new_refreshRate) { static bool _setPLLDHandheldRefreshRate(uint32_t new_refreshRate) {
if (!g_config.clkVirtAddr) return false; if (!g_config.clkVirtAddr)
return false;
uint32_t fd = 0; uint32_t fd = 0;
if (nvOpen(&fd, "/dev/nvdisp-disp0")) { if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
@@ -298,24 +310,26 @@ namespace display {
unsigned int rev_minor : 4; unsigned int rev_minor : 4;
unsigned int rev_major : 4; unsigned int rev_major : 4;
unsigned char link_rate; unsigned char link_rate;
unsigned int lane_count: 5; unsigned int lane_count : 5;
unsigned int unk1: 2; unsigned int unk1 : 2;
unsigned int isFramingEnhanced: 1; unsigned int isFramingEnhanced : 1;
unsigned char unk2[13]; unsigned char unk2[13];
} DPCD; } DPCD;
} dpaux = {6, 0, 0x10}; } dpaux = { 6, 0, 0x10 };
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux); int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
nvClose(fd); nvClose(fd);
if (rc != 0x75c) return false; if (rc != 0x75c)
return false;
PLLD_BASE base = {0}; PLLD_BASE base = { 0 };
PLLD_MISC misc = {0}; PLLD_MISC misc = { 0 };
memcpy(&base, (void*)(g_config.clkVirtAddr + 0xD0), 4); memcpy(&base, (void *)(g_config.clkVirtAddr + 0xD0), 4);
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4); memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
uint32_t value = ((base.PLLD_DIVN / base.PLLD_DIVM) * 10) / 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) { if (new_refreshRate > g_handheldModeRefreshRate.max) {
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); uint32_t pixelClock = (9375 * ((4096 * ((2 * base.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * base.PLLD_DIVM);
@@ -354,8 +369,8 @@ namespace display {
uint64_t expected_pixel_clock = (DSI_CLOCK_HZ * new_refreshRate) / 60; uint64_t expected_pixel_clock = (DSI_CLOCK_HZ * new_refreshRate) / 60;
misc.PLLD_SDM_DIN = ((8 * base.PLLD_DIVM * expected_pixel_clock) / 9375) - (4096 * ((2 * base.PLLD_DIVN) + 1)); misc.PLLD_SDM_DIN = ((8 * base.PLLD_DIVM * expected_pixel_clock) / 9375) - (4096 * ((2 * base.PLLD_DIVN) + 1));
memcpy((void*)(g_config.clkVirtAddr + 0xD0), &base, 4); memcpy((void *)(g_config.clkVirtAddr + 0xD0), &base, 4);
memcpy((void*)(g_config.clkVirtAddr + 0xDC), &misc, 4); memcpy((void *)(g_config.clkVirtAddr + 0xDC), &misc, 4);
return true; return true;
} }
@@ -368,7 +383,7 @@ namespace display {
return false; return false;
} }
NvdcMode2 display_b = {0}; NvdcMode2 display_b = { 0 };
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b); int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
if (rc != 0) { if (rc != 0) {
nvClose(fd); nvClose(fd);
@@ -380,9 +395,8 @@ namespace display {
return false; return false;
} }
if (!((display_b.vActive == 480 && display_b.hActive == 720) || if (!((display_b.vActive == 480 && display_b.hActive == 720) || (display_b.vActive == 720 && display_b.hActive == 1280) ||
(display_b.vActive == 720 && display_b.hActive == 1280) || (display_b.vActive == 1080 && display_b.hActive == 1920))) {
(display_b.vActive == 1080 && display_b.hActive == 1920))) {
nvClose(fd); nvClose(fd);
return false; 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 // Clamp to highest allowed refresh rate
if (g_dockedRefreshRates[itr] > g_dockedHighestRefreshRate) { if (g_dockedRefreshRates[itr] > g_dockedHighestRefreshRate) {
@@ -472,7 +487,8 @@ namespace display {
} }
static bool _setNvDispHandheldRefreshRate(uint32_t new_refreshRate) { static bool _setNvDispHandheldRefreshRate(uint32_t new_refreshRate) {
if (!g_config.isRetroSUPER) return false; if (!g_config.isRetroSUPER)
return false;
if (!g_config.displaySync) { if (!g_config.displaySync) {
g_wasRetroSuperTurnedOff = false; g_wasRetroSuperTurnedOff = false;
@@ -488,7 +504,7 @@ namespace display {
return false; return false;
} }
NvdcMode2 display_b = {0}; NvdcMode2 display_b = { 0 };
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b); int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
if (rc != 0) { if (rc != 0) {
nvClose(fd); nvClose(fd);
@@ -529,7 +545,8 @@ namespace display {
} }
} }
} }
if (!skip) new_refreshRate = 60; if (!skip)
new_refreshRate = 60;
} }
if (new_refreshRate == refreshRateNow) { if (new_refreshRate == refreshRateNow) {
@@ -558,7 +575,8 @@ namespace display {
} }
bool SetRate(uint32_t new_refreshRate) { bool SetRate(uint32_t new_refreshRate) {
if (!new_refreshRate || !g_initialized) return false; if (!new_refreshRate || !g_initialized)
return false;
uint32_t fd = 0; 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"))) { else if ((!g_config.isRetroSUPER && g_config.isLite) || R_FAILED(nvOpen(&fd, "/dev/nvdisp-disp1"))) {
if (_setPLLDHandheldRefreshRate(new_refreshRate) == false) if (_setPLLDHandheldRefreshRate(new_refreshRate) == false)
return false; return false;
} } else {
else {
struct dpaux_read { struct dpaux_read {
uint32_t cmd; uint32_t cmd;
uint32_t addr; uint32_t addr;
@@ -579,24 +596,24 @@ namespace display {
unsigned int rev_minor : 4; unsigned int rev_minor : 4;
unsigned int rev_major : 4; unsigned int rev_major : 4;
unsigned char link_rate; unsigned char link_rate;
unsigned int lane_count: 5; unsigned int lane_count : 5;
unsigned int unk1: 2; unsigned int unk1 : 2;
unsigned int isFramingEnhanced: 1; unsigned int isFramingEnhanced : 1;
unsigned char unk2[13]; unsigned char unk2[13];
} DPCD; } DPCD;
} dpaux = {6, 0, 0x10}; } dpaux = { 6, 0, 0x10 };
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux); int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
nvClose(fd); nvClose(fd);
if (rc != 0) { if (rc != 0) {
if (!g_config.isRetroSUPER) { if (!g_config.isRetroSUPER) {
return _setPLLDHandheldRefreshRate(new_refreshRate); return _setPLLDHandheldRefreshRate(new_refreshRate);
} else { } else {
return _setNvDispHandheldRefreshRate(new_refreshRate); return _setNvDispHandheldRefreshRate(new_refreshRate);
} }
} else { } else {
if(g_config.isDocked) if (g_config.isDocked)
return _setNvDispDockedRefreshRate(new_refreshRate); return _setNvDispDockedRefreshRate(new_refreshRate);
else else
return true; return true;
@@ -605,22 +622,23 @@ namespace display {
return false; return false;
} }
bool GetRate(uint32_t* out_refreshRate, bool internal) { 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; static uint32_t value = 60;
if (g_config.isRetroSUPER && !g_config.isDocked) { if (g_config.isRetroSUPER && !g_config.isDocked) {
uint32_t fd = 0; uint32_t fd = 0;
PLLD_BASE temp = {0}; PLLD_BASE temp = { 0 };
PLLD_MISC misc = {0}; PLLD_MISC misc = { 0 };
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4); memcpy(&temp, (void *)(g_config.clkVirtAddr + 0xD0), 4);
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4); memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4; value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
if (value != 0 && value != 80) { if (value != 0 && value != 80) {
if (!nvOpen(&fd, "/dev/nvdisp-disp0")) { if (!nvOpen(&fd, "/dev/nvdisp-disp0")) {
NvdcMode2 display_b = {0}; NvdcMode2 display_b = { 0 };
if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) { if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) {
uint64_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch; uint64_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
uint64_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch; uint64_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
@@ -634,18 +652,18 @@ namespace display {
} else { } else {
g_wasRetroSuperTurnedOff = true; 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_BASE temp = {0}; PLLD_MISC misc = { 0 };
PLLD_MISC misc = {0}; memcpy(&temp, (void *)(g_config.clkVirtAddr + 0xD0), 4);
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4); memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4; value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
if (value == 0 || value == 80) { if (value == 0 || value == 80) {
// Docked mode // Docked mode
if (g_config.isLite) return false; if (g_config.isLite)
return false;
g_config.isDocked = true; g_config.isDocked = true;
@@ -658,15 +676,15 @@ namespace display {
uint32_t size; uint32_t size;
struct { struct {
unsigned char link_rate; unsigned char link_rate;
unsigned int lane_count: 5; unsigned int lane_count : 5;
unsigned int unk1: 2; unsigned int unk1 : 2;
unsigned int isFramingEnhanced: 1; unsigned int isFramingEnhanced : 1;
unsigned char downspread; unsigned char downspread;
unsigned char training_pattern; unsigned char training_pattern;
unsigned char lane_pattern[4]; unsigned char lane_pattern[4];
unsigned char unk2[8]; unsigned char unk2[8];
} set; } set;
} dpaux = {6, 0x100, 0x10}; } dpaux = { 6, 0x100, 0x10 };
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux); int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
nvClose(fd); nvClose(fd);
@@ -682,13 +700,13 @@ namespace display {
return false; return false;
} }
} }
if(internal) { if (internal) {
*out_refreshRate = value; *out_refreshRate = value;
return true; return true;
} }
uint32_t fd = 0; uint32_t fd = 0;
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) { if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
NvdcMode2 display_b = {0}; NvdcMode2 display_b = { 0 };
if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) { if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) {
if (!display_b.pclkKHz) { if (!display_b.pclkKHz) {
nvClose(fd); nvClose(fd);
@@ -711,16 +729,14 @@ namespace display {
} else { } else {
value = 60; value = 60;
} }
} } else if (!g_config.isRetroSUPER) {
else if (!g_config.isRetroSUPER) {
// Handheld mode // Handheld mode
g_config.isDocked = false; g_config.isDocked = false;
g_canChangeRefreshRateDocked = false; g_canChangeRefreshRateDocked = false;
uint32_t pixelClock = (9375ULL * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM); uint32_t pixelClock = (9375ULL * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
value = pixelClock / (DSI_CLOCK_HZ / 60); value = pixelClock / (DSI_CLOCK_HZ / 60);
} } else {
else {
return false; return false;
} }
} }
@@ -733,4 +749,4 @@ namespace display {
g_initialized = false; g_initialized = false;
memset(&g_config, 0, sizeof(g_config)); memset(&g_config, 0, sizeof(g_config));
} }
} } // namespace display

View File

@@ -17,9 +17,9 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
namespace display { namespace display {
typedef struct { typedef struct {
uint16_t hFrontPorch; uint16_t hFrontPorch;
@@ -71,35 +71,35 @@ namespace display {
} NvdcModeDB2; } NvdcModeDB2;
typedef struct { typedef struct {
unsigned int PLLD_DIVM: 8; unsigned int PLLD_DIVM : 8;
unsigned int reserved_1: 3; unsigned int reserved_1 : 3;
unsigned int PLLD_DIVN: 8; unsigned int PLLD_DIVN : 8;
unsigned int reserved_2: 1; unsigned int reserved_2 : 1;
unsigned int PLLD_DIVP: 3; unsigned int PLLD_DIVP : 3;
unsigned int CSI_CLK_SRC: 1; unsigned int CSI_CLK_SRC : 1;
unsigned int reserved_3: 1; unsigned int reserved_3 : 1;
unsigned int PLL_D: 1; unsigned int PLL_D : 1;
unsigned int reserved_4: 1; unsigned int reserved_4 : 1;
unsigned int PLLD_LOCK: 1; unsigned int PLLD_LOCK : 1;
unsigned int reserved_5: 1; unsigned int reserved_5 : 1;
unsigned int PLLD_REF_DIS: 1; unsigned int PLLD_REF_DIS : 1;
unsigned int PLLD_ENABLE: 1; unsigned int PLLD_ENABLE : 1;
unsigned int PLLD_BYPASS: 1; unsigned int PLLD_BYPASS : 1;
} PLLD_BASE; } PLLD_BASE;
typedef struct { typedef struct {
signed int PLLD_SDM_DIN: 16; signed int PLLD_SDM_DIN : 16;
unsigned int PLLD_EN_SDM: 1; unsigned int PLLD_EN_SDM : 1;
unsigned int PLLD_LOCK_OVERRIDE: 1; unsigned int PLLD_LOCK_OVERRIDE : 1;
unsigned int PLLD_EN_LCKDET: 1; unsigned int PLLD_EN_LCKDET : 1;
unsigned int PLLD_FREQLOCK: 1; unsigned int PLLD_FREQLOCK : 1;
unsigned int PLLD_IDDQ: 1; unsigned int PLLD_IDDQ : 1;
unsigned int PLLD_ENABLE_CLK: 1; unsigned int PLLD_ENABLE_CLK : 1;
unsigned int PLLD_KVCO: 1; unsigned int PLLD_KVCO : 1;
unsigned int PLLD_KCP: 2; unsigned int PLLD_KCP : 2;
unsigned int PLLD_PTS: 2; unsigned int PLLD_PTS : 2;
unsigned int PLLD_LDPULSE_ADJ: 3; unsigned int PLLD_LDPULSE_ADJ : 3;
unsigned int reserved: 2; unsigned int reserved : 2;
} PLLD_MISC; } PLLD_MISC;
typedef struct { typedef struct {
@@ -116,12 +116,12 @@ namespace display {
bool displaySyncDocked; bool displaySyncDocked;
bool displaySyncDockedOutOfFocus60; bool displaySyncDockedOutOfFocus60;
} DisplayRefreshConfig; } DisplayRefreshConfig;
bool Initialize(const DisplayRefreshConfig* config); bool Initialize(const DisplayRefreshConfig *config);
void SetDockedState(bool isDocked); void SetDockedState(bool isDocked);
bool SetRate(uint32_t new_refreshRate); bool SetRate(uint32_t new_refreshRate);
bool GetRate(uint32_t* out_refreshRate, bool internal); bool GetRate(uint32_t *out_refreshRate, bool internal);
uint8_t GetDockedHighestAllowed(void); uint8_t GetDockedHighestAllowed(void);
void CorrectOledGamma(uint32_t refresh_rate); void CorrectOledGamma(uint32_t refresh_rate);
void SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p); void SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p);
void Shutdown(void); 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 <algorithm>
#include <atomic>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <map>
#include <string>
#include <atomic>
#include <initializer_list>
#include <minIni.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h> #include <map>
#include <max17050.h> #include <max17050.h>
#include <minIni.h>
#include <sstream>
#include <string>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include <ipc_server.h> #include <unistd.h>
#include <lockable_mutex.h>
#include "../board/board.hpp" #include "../board/board.hpp"
#include "../hos/apm_ext.h"
#include "config.hpp"
#include "errors.hpp" #include "errors.hpp"
#include "file_utils.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 { namespace config {
@@ -57,7 +58,7 @@ namespace config {
bool gLoaded = false; bool gLoaded = false;
std::string gPath; std::string gPath;
time_t gMtime = 0; time_t gMtime = 0;
std::atomic_bool gEnabled{false}; std::atomic_bool gEnabled{ false };
std::uint32_t gOverrideFreqs[HocClkModule_EnumMax]; std::uint32_t gOverrideFreqs[HocClkModule_EnumMax];
std::map<std::tuple<std::uint64_t, HocClkProfile, HocClkModule>, std::uint32_t> gProfileMHzMap; std::map<std::tuple<std::uint64_t, HocClkProfile, HocClkModule>, std::uint32_t> gProfileMHzMap;
std::map<std::uint64_t, std::uint8_t> gProfileCountMap; std::map<std::uint64_t, std::uint8_t> gProfileCountMap;
@@ -83,11 +84,12 @@ namespace config {
return 0; 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; std::uint32_t mhz = 0;
if (gLoaded) { if (gLoaded) {
for (auto profile: profiles) { for (auto profile : profiles) {
mhz = FindClockMHz(tid, module, profile); mhz = FindClockMHz(tid, module, profile);
if (mhz) { if (mhz) {
break; break;
@@ -98,7 +100,7 @@ namespace config {
return std::max((std::uint32_t)0, mhz * mhzMultiplier); return std::max((std::uint32_t)0, mhz * mhzMultiplier);
} }
int BrowseIniFunc(const char* section, const char* key, const char* value, void* userdata) { int BrowseIniFunc(const char *section, const char *key, const char *value, void *userdata) {
(void)userdata; (void)userdata;
std::uint64_t input; std::uint64_t input;
if (!strcmp(section, CONFIG_VAL_SECTION)) { if (!strcmp(section, CONFIG_VAL_SECTION)) {
@@ -129,14 +131,14 @@ namespace config {
HocClkModule parsedModule = HocClkModule_EnumMax; HocClkModule parsedModule = HocClkModule_EnumMax;
for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) { for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) {
const char* profileCode = board::GetProfileName((HocClkProfile)profile, false); const char *profileCode = board::GetProfileName((HocClkProfile)profile, false);
size_t profileCodeLen = strlen(profileCode); size_t profileCodeLen = strlen(profileCode);
if (!strncmp(key, profileCode, profileCodeLen) && key[profileCodeLen] == '_') { if (!strncmp(key, profileCode, profileCodeLen) && key[profileCodeLen] == '_') {
const char* subkey = key + profileCodeLen + 1; const char *subkey = key + profileCodeLen + 1;
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
const char* moduleCode = board::GetModuleName((HocClkModule)module, false); const char *moduleCode = board::GetModuleName((HocClkModule)module, false);
size_t moduleCodeLen = strlen(moduleCode); size_t moduleCodeLen = strlen(moduleCode);
if (!strncmp(subkey, moduleCode, moduleCodeLen) && subkey[moduleCodeLen] == '\0') { if (!strncmp(subkey, moduleCode, moduleCodeLen) && subkey[moduleCodeLen] == '\0') {
parsedProfile = (HocClkProfile)profile; parsedProfile = (HocClkProfile)profile;
@@ -191,7 +193,7 @@ namespace config {
gLoaded = true; gLoaded = true;
} }
} } // namespace
void Initialize() { void Initialize() {
gPath = FILE_CONFIG_DIR "/config.ini"; gPath = FILE_CONFIG_DIR "/config.ini";
@@ -209,12 +211,12 @@ namespace config {
} }
void Exit() { void Exit() {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
Close(); Close();
} }
bool Refresh() { bool Refresh() {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
if (!gLoaded || gMtime != CheckModificationTime()) { if (!gLoaded || gMtime != CheckModificationTime()) {
Load(); Load();
return true; return true;
@@ -223,30 +225,34 @@ namespace config {
} }
bool HasProfilesLoaded() { bool HasProfilesLoaded() {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
return gLoaded; return gLoaded;
} }
std::uint32_t GetAutoClockHz(std::uint64_t tid, HocClkModule module, HocClkProfile profile, bool returnRaw) { std::uint32_t GetAutoClockHz(std::uint64_t tid, HocClkModule module, HocClkProfile profile, bool returnRaw) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
switch (profile) { switch (profile) {
case HocClkProfile_Handheld: case HocClkProfile_Handheld:
return FindClockHzFromProfiles(tid, module, {HocClkProfile_Handheld}, returnRaw ? 1 : 1000000); return FindClockHzFromProfiles(tid, module, { HocClkProfile_Handheld }, returnRaw ? 1 : 1000000);
case HocClkProfile_HandheldCharging: case HocClkProfile_HandheldCharging:
case HocClkProfile_HandheldChargingUSB: 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: 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: case HocClkProfile_Docked:
return FindClockHzFromProfiles(tid, module, {HocClkProfile_Docked}, returnRaw ? 1 : 1000000); return FindClockHzFromProfiles(tid, module, { HocClkProfile_Docked }, returnRaw ? 1 : 1000000);
default: default:
ERROR_THROW("Unhandled HocClkProfile: %u", profile); ERROR_THROW("Unhandled HocClkProfile: %u", profile);
} }
return 0; return 0;
} }
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList* out_profiles) { void GetProfiles(std::uint64_t tid, HocClkTitleProfileList *out_profiles) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) { for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
out_profiles->mhzMap[profile][module] = FindClockMHz(tid, (HocClkModule)module, (HocClkProfile)profile); out_profiles->mhzMap[profile][module] = FindClockMHz(tid, (HocClkModule)module, (HocClkProfile)profile);
@@ -254,11 +260,11 @@ namespace config {
} }
} }
bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList* profiles, bool immediate) { bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList *profiles, bool immediate) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
uint8_t numProfiles = 0; uint8_t numProfiles = 0;
char section[17] = {0}; char section[17] = { 0 };
snprintf(section, sizeof(section), "%016lX", tid); snprintf(section, sizeof(section), "%016lX", tid);
std::vector<std::string> keys; std::vector<std::string> keys;
@@ -266,16 +272,15 @@ namespace config {
keys.reserve(+HocClkProfile_EnumMax * +HocClkModule_EnumMax); keys.reserve(+HocClkProfile_EnumMax * +HocClkModule_EnumMax);
values.reserve(+HocClkProfile_EnumMax * +HocClkModule_EnumMax); values.reserve(+HocClkProfile_EnumMax * +HocClkModule_EnumMax);
std::uint32_t* mhz = &profiles->mhz[0]; std::uint32_t *mhz = &profiles->mhz[0];
for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) { for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
if (*mhz) { if (*mhz) {
numProfiles++; numProfiles++;
std::string key = std::string(board::GetProfileName((HocClkProfile)profile, false)) + std::string key =
"_" + std::string(board::GetProfileName((HocClkProfile)profile, false)) + "_" + board::GetModuleName((HocClkModule)module, false);
board::GetModuleName((HocClkModule)module, false);
std::string value = std::to_string(*mhz); std::string value = std::to_string(*mhz);
keys.push_back(key); keys.push_back(key);
@@ -285,8 +290,8 @@ namespace config {
} }
} }
std::vector<const char*> keyPointers; std::vector<const char *> keyPointers;
std::vector<const char*> valuePointers; std::vector<const char *> valuePointers;
keyPointers.reserve(keys.size() + 1); keyPointers.reserve(keys.size() + 1);
valuePointers.reserve(values.size() + 1); valuePointers.reserve(values.size() + 1);
@@ -337,45 +342,45 @@ namespace config {
void SetOverrideHz(HocClkModule module, std::uint32_t hz) { void SetOverrideHz(HocClkModule module, std::uint32_t hz) {
ASSERT_ENUM_VALID(HocClkModule, module); ASSERT_ENUM_VALID(HocClkModule, module);
std::scoped_lock lock{gOverrideMutex}; std::scoped_lock lock{ gOverrideMutex };
gOverrideFreqs[module] = hz; gOverrideFreqs[module] = hz;
} }
std::uint32_t GetOverrideHz(HocClkModule module) { std::uint32_t GetOverrideHz(HocClkModule module) {
ASSERT_ENUM_VALID(HocClkModule, module); ASSERT_ENUM_VALID(HocClkModule, module);
std::scoped_lock lock{gOverrideMutex}; std::scoped_lock lock{ gOverrideMutex };
return gOverrideFreqs[module]; return gOverrideFreqs[module];
} }
std::uint64_t GetConfigValue(HocClkConfigValue kval) { std::uint64_t GetConfigValue(HocClkConfigValue kval) {
ASSERT_ENUM_VALID(HocClkConfigValue, kval); ASSERT_ENUM_VALID(HocClkConfigValue, kval);
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
return configValues[kval]; return configValues[kval];
} }
const char* GetConfigValueName(HocClkConfigValue kval, bool pretty) { const char *GetConfigValueName(HocClkConfigValue kval, bool pretty) {
ASSERT_ENUM_VALID(HocClkConfigValue, kval); ASSERT_ENUM_VALID(HocClkConfigValue, kval);
return hocclkFormatConfigValue(kval, pretty); return hocclkFormatConfigValue(kval, pretty);
} }
void GetConfigValues(HocClkConfigValueList* out_configValues) { void GetConfigValues(HocClkConfigValueList *out_configValues) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) { for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) {
out_configValues->values[kval] = configValues[kval]; out_configValues->values[kval] = configValues[kval];
} }
} }
bool SetConfigValues(HocClkConfigValueList* configValues, bool immediate) { bool SetConfigValues(HocClkConfigValueList *configValues, bool immediate) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
std::vector<const char*> iniKeys; std::vector<const char *> iniKeys;
std::vector<std::string> iniValues; std::vector<std::string> iniValues;
iniKeys.reserve(HocClkConfigValue_EnumMax + 1); iniKeys.reserve(HocClkConfigValue_EnumMax + 1);
iniValues.reserve(HocClkConfigValue_EnumMax); iniValues.reserve(HocClkConfigValue_EnumMax);
for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) { for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) {
if (!hocclkValidConfigValue((HocClkConfigValue)kval, configValues->values[kval]) || if (!hocclkValidConfigValue((HocClkConfigValue)kval, configValues->values[kval]) ||
configValues->values[kval] == hocclkDefaultConfigValue((HocClkConfigValue)kval)) { configValues->values[kval] == hocclkDefaultConfigValue((HocClkConfigValue)kval)) {
continue; continue;
} }
iniValues.push_back(std::to_string(configValues->values[kval])); iniValues.push_back(std::to_string(configValues->values[kval]));
@@ -384,9 +389,9 @@ namespace config {
iniKeys.push_back(NULL); iniKeys.push_back(NULL);
std::vector<const char*> valuePointers; std::vector<const char *> valuePointers;
valuePointers.reserve(iniValues.size() + 1); valuePointers.reserve(iniValues.size() + 1);
for (const auto& val : iniValues) { for (const auto &val : iniValues) {
valuePointers.push_back(val.c_str()); valuePointers.push_back(val.c_str());
} }
valuePointers.push_back(NULL); valuePointers.push_back(NULL);
@@ -414,11 +419,11 @@ namespace config {
return false; return false;
} }
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
std::uint64_t defaultValue = hocclkDefaultConfigValue(kval); std::uint64_t defaultValue = hocclkDefaultConfigValue(kval);
std::vector<const char*> iniKeys; std::vector<const char *> iniKeys;
std::vector<std::string> iniValues; std::vector<std::string> iniValues;
iniKeys.reserve(2); iniKeys.reserve(2);
iniValues.reserve(1); iniValues.reserve(1);
@@ -427,9 +432,9 @@ namespace config {
iniValues.push_back(""); iniValues.push_back("");
iniKeys.push_back(NULL); iniKeys.push_back(NULL);
std::vector<const char*> valuePointers; std::vector<const char *> valuePointers;
valuePointers.reserve(iniValues.size() + 1); valuePointers.reserve(iniValues.size() + 1);
for (const auto& val : iniValues) { for (const auto &val : iniValues) {
valuePointers.push_back(val.c_str()); valuePointers.push_back(val.c_str());
} }
valuePointers.push_back(NULL); valuePointers.push_back(NULL);
@@ -453,9 +458,9 @@ namespace config {
return false; return false;
} }
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
std::vector<const char*> iniKeys; std::vector<const char *> iniKeys;
std::vector<std::string> iniValues; std::vector<std::string> iniValues;
iniKeys.reserve(2); iniKeys.reserve(2);
iniValues.reserve(1); iniValues.reserve(1);
@@ -464,7 +469,7 @@ namespace config {
iniValues.push_back(std::to_string(value)); iniValues.push_back(std::to_string(value));
iniKeys.push_back(NULL); iniKeys.push_back(NULL);
std::vector<const char*> valuePointers; std::vector<const char *> valuePointers;
valuePointers.reserve(2); valuePointers.reserve(2);
valuePointers.push_back(iniValues[0].c_str()); valuePointers.push_back(iniValues[0].c_str());
valuePointers.push_back(NULL); valuePointers.push_back(NULL);
@@ -480,8 +485,8 @@ namespace config {
return true; return true;
} }
void DeleteKey(const char* section, const char* key) { void DeleteKey(const char *section, const char *key) {
std::scoped_lock lock{gConfigMutex}; std::scoped_lock lock{ gConfigMutex };
ini_puts(section, key, NULL, gPath.c_str()); ini_puts(section, key, NULL, gPath.c_str());
} }
} } // namespace config

View File

@@ -40,8 +40,8 @@ namespace config {
bool HasProfilesLoaded(); bool HasProfilesLoaded();
std::uint8_t GetProfileCount(std::uint64_t tid); std::uint8_t GetProfileCount(std::uint64_t tid);
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList* out_profiles); void GetProfiles(std::uint64_t tid, HocClkTitleProfileList *out_profiles);
bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList* profiles, bool immediate); bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList *profiles, bool immediate);
std::uint32_t GetAutoClockHz(std::uint64_t tid, HocClkModule module, HocClkProfile profile, bool returnRaw); std::uint32_t GetAutoClockHz(std::uint64_t tid, HocClkModule module, HocClkProfile profile, bool returnRaw);
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
@@ -50,13 +50,13 @@ namespace config {
std::uint32_t GetOverrideHz(HocClkModule module); std::uint32_t GetOverrideHz(HocClkModule module);
std::uint64_t GetConfigValue(HocClkConfigValue val); std::uint64_t GetConfigValue(HocClkConfigValue val);
const char* GetConfigValueName(HocClkConfigValue val, bool pretty); const char *GetConfigValueName(HocClkConfigValue val, bool pretty);
void GetConfigValues(HocClkConfigValueList* out_configValues); void GetConfigValues(HocClkConfigValueList *out_configValues);
bool SetConfigValues(HocClkConfigValueList* configValues, bool immediate); bool SetConfigValues(HocClkConfigValueList *configValues, bool immediate);
bool ResetConfigValue(HocClkConfigValue kval); bool ResetConfigValue(HocClkConfigValue kval);
bool SetConfigValue(HocClkConfigValue kval, std::uint64_t value, bool immediate = true); bool SetConfigValue(HocClkConfigValue kval, std::uint64_t value, bool immediate = true);
void DeleteKey(const char* section, const char* key); void DeleteKey(const char *section, const char *key);
extern uint64_t configValues[HocClkConfigValue_EnumMax]; extern uint64_t configValues[HocClkConfigValue_EnumMax];
} } // namespace config

View File

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

View File

@@ -26,14 +26,13 @@
#pragma once #pragma once
#include <switch.h>
#include <stdexcept> #include <stdexcept>
#include <switch.h>
#define ERROR_THROW(format, ...) errors::ThrowException(format "\n in %s:%u", ##__VA_ARGS__, __FILE__, __LINE__) #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 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, ...) \ #define ASSERT_RESULT_OK(rc, format, ...) \
if (R_FAILED(rc)) \ if (R_FAILED(rc)) { \
{ \
ERROR_RESULT_THROW(rc, "ASSERT_RESULT_OK: " format, ##__VA_ARGS__); \ ERROR_RESULT_THROW(rc, "ASSERT_RESULT_OK: " format, ##__VA_ARGS__); \
} }
#define ASSERT_ENUM_VALID(n, v) \ #define ASSERT_ENUM_VALID(n, v) \
@@ -43,6 +42,6 @@
namespace errors { namespace errors {
void ThrowException(const char* format, ...); void ThrowException(const char *format, ...);
} }

View File

@@ -24,12 +24,13 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "file_utils.hpp"
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h>
#include <max17050.h> #include <max17050.h>
#include <t210.h>
#include <tmp451.h> #include <tmp451.h>
#include "../hos/apm_ext.h"
#include "file_utils.hpp"
#include <ipc_server.h> #include <ipc_server.h>
#include <lockable_mutex.h> #include <lockable_mutex.h>
@@ -52,7 +53,7 @@ namespace fileUtils {
return; return;
} }
FILE* file = fopen(FILE_LOG_FLAG_PATH, "r"); FILE *file = fopen(FILE_LOG_FLAG_PATH, "r");
if (file) { if (file) {
g_log_enabled = true; g_log_enabled = true;
fclose(file); fclose(file);
@@ -63,11 +64,11 @@ namespace fileUtils {
g_last_flag_check = now; g_last_flag_check = now;
} }
void InitializeThreadFunc(void* args) { void InitializeThreadFunc(void *args) {
Initialize(); Initialize();
} }
} } // namespace
bool IsInitialized() { bool IsInitialized() {
return g_has_initialized; return g_has_initialized;
@@ -77,8 +78,8 @@ namespace fileUtils {
return g_log_enabled; return g_log_enabled;
} }
void LogLine(const char* format, ...) { void LogLine(const char *format, ...) {
std::scoped_lock lock{g_log_mutex}; std::scoped_lock lock{ g_log_mutex };
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -86,7 +87,7 @@ namespace fileUtils {
RefreshFlags(false); RefreshFlags(false);
if (g_log_enabled) { if (g_log_enabled) {
FILE* file = fopen(FILE_LOG_FILE_PATH, "a"); FILE *file = fopen(FILE_LOG_FILE_PATH, "a");
if (file) { if (file) {
timespec now = {}; timespec now = {};
@@ -102,10 +103,10 @@ namespace fileUtils {
va_end(args); va_end(args);
} }
void WriteContextToCsv(const HocClkContext* context) { void WriteContextToCsv(const HocClkContext *context) {
std::scoped_lock lock{g_csv_mutex}; std::scoped_lock lock{ g_csv_mutex };
FILE* file = fopen(FILE_CONTEXT_CSV_PATH, "a"); FILE *file = fopen(FILE_CONTEXT_CSV_PATH, "a");
if (file) { if (file) {
// Print header // Print header
@@ -134,7 +135,8 @@ namespace fileUtils {
struct timespec now; struct timespec now;
clock_gettime(CLOCK_REALTIME, &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++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
fprintf(file, ",%d", context->freqs[module]); fprintf(file, ",%d", context->freqs[module]);
@@ -164,7 +166,7 @@ namespace fileUtils {
} }
void InitializeAsync() { void InitializeAsync() {
Thread initThread = {0}; Thread initThread = { 0 };
threadCreate(&initThread, InitializeThreadFunc, NULL, NULL, 0x4000, 0x15, 0); threadCreate(&initThread, InitializeThreadFunc, NULL, NULL, 0x4000, 0x15, 0);
threadStart(&initThread); threadStart(&initThread);
} }
@@ -210,4 +212,4 @@ namespace fileUtils {
fsExit(); fsExit();
} }
} } // namespace fileUtils

View File

@@ -26,13 +26,13 @@
#pragma once #pragma once
#include <switch.h>
#include <time.h>
#include <vector>
#include <string>
#include <atomic> #include <atomic>
#include <cstdarg> #include <cstdarg>
#include <hocclk.h> #include <hocclk.h>
#include <string>
#include <switch.h>
#include <time.h>
#include <vector>
#define FILE_CONFIG_DIR "/config/" CONFIG_DIR #define FILE_CONFIG_DIR "/config/" CONFIG_DIR
#define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL) #define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL)
@@ -47,7 +47,7 @@ namespace fileUtils {
bool IsInitialized(); bool IsInitialized();
bool IsLogEnabled(); bool IsLogEnabled();
void InitializeAsync(); void InitializeAsync();
void LogLine(const char* format, ...); void LogLine(const char *format, ...);
void WriteContextToCsv(const HocClkContext* context); 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 "../board/board.hpp"
#include "file_utils.hpp" #include "../i2c/i2cDrv.h"
#include "../mgr/clock_manager.hpp" #include "../mgr/clock_manager.hpp"
#include "file_utils.hpp"
#include "kip.hpp"
namespace kip { namespace kip {
bool kipAvailable = false; bool kipAvailable = false;
void SetKipData() void SetKipData() {
{
// TODO: figure out if this REALLY causes issues (i doubt it) // TODO: figure out if this REALLY causes issues (i doubt it)
// if(board::GetSocType() == HocClkSocType_Mariko) { // if(board::GetSocType() == HocClkSocType_Mariko) {
// if(R_FAILED(I2c_BuckConverter_SetMvOut(&I2c_Mariko_DRAM_VDDQ, config::GetConfigValue(KipConfigValue_marikoEmcVddqVolt) / 1000))) { // if(R_FAILED(I2c_BuckConverter_SetMvOut(&I2c_Mariko_DRAM_VDDQ, config::GetConfigValue(KipConfigValue_marikoEmcVddqVolt) / 1000))) {
@@ -34,7 +34,7 @@ namespace kip {
// } // }
// } // }
CustomizeTable table; CustomizeTable table;
FILE* fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "r+b"); FILE *fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "r+b");
if (fp == NULL) { if (fp == NULL) {
notification::writeNotification("Horizon OC\nKip opening failed"); notification::writeNotification("Horizon OC\nKip opening failed");
@@ -50,7 +50,7 @@ namespace kip {
return; return;
} }
u32 custRev = cust_get_cust_rev(&table); u32 custRev = cust_get_cust_rev(&table);
u32 kipVersion = cust_get_kip_version(&table); u32 kipVersion = cust_get_kip_version(&table);
if (custRev < CUST_REV || kipVersion < KIP_VERSION) { if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
fclose(fp); fclose(fp);
@@ -149,10 +149,11 @@ namespace kip {
HocClkConfigValueList configValues; HocClkConfigValueList configValues;
config::GetConfigValues(&configValues); config::GetConfigValues(&configValues);
configValues.values[KipCrc32] = (u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip"); // write checksum configValues.values[KipCrc32] = (u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip"); // write checksum
if (config::SetConfigValues(&configValues, true)) { 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++) { for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]); fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
} }
@@ -164,9 +165,8 @@ namespace kip {
// I know this is very hacky, but the config system in the sysmodule doesn't really support writing // 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");
FILE* fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "rb");
if (fp == NULL) { if (fp == NULL) {
notification::writeNotification("Horizon OC\nKip opening failed"); notification::writeNotification("Horizon OC\nKip opening failed");
@@ -192,22 +192,23 @@ namespace kip {
// return; // 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)); MigrateKipData(cust_get_cust_rev(&table), cust_get_kip_version(&table));
SetKipData(); SetKipData();
notification::writeNotification("Horizon OC\nKIP has been updated\nPlease reboot your console"); notification::writeNotification("Horizon OC\nKIP has been updated\nPlease reboot your console");
return; return;
} }
if (config::GetConfigValue(HocClkConfigValue_IsFirstLoad) == true) { if (config::GetConfigValue(HocClkConfigValue_IsFirstLoad) == true) {
configValues.values[HocClkConfigValue_IsFirstLoad] = (u64)false; configValues.values[HocClkConfigValue_IsFirstLoad] = (u64) false;
notification::writeNotification("Horizon OC has been installed"); notification::writeNotification("Horizon OC has been installed");
} }
configValues.values[KipCrc32] = (u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip"); // write checksum configValues.values[KipCrc32] = (u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip"); // write checksum
// configValues.values[KipConfigValue_mtcConf] = cust_get_mtc_conf(&table); // configValues.values[KipConfigValue_mtcConf] = cust_get_mtc_conf(&table);
clockManager::gContext.custRev = cust_get_cust_rev(&table); clockManager::gContext.custRev = cust_get_cust_rev(&table);
u32 custRev = cust_get_cust_rev(&table); u32 custRev = cust_get_cust_rev(&table);
u32 kipVersion = cust_get_kip_version(&table); u32 kipVersion = cust_get_kip_version(&table);
if (custRev < CUST_REV || kipVersion < KIP_VERSION) { if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
notification::writeNotification("Horizon OC\nOutdated kip detected!\nPlease update Horizon OC"); notification::writeNotification("Horizon OC\nOutdated kip detected!\nPlease update Horizon OC");
@@ -223,7 +224,7 @@ namespace kip {
clockManager::gContext.kipVersion = kipVersion; clockManager::gContext.kipVersion = kipVersion;
configValues.values[KipConfigValue_custRev] = cust_get_cust_rev(&table); configValues.values[KipConfigValue_custRev] = cust_get_cust_rev(&table);
configValues.values[KipConfigValue_KipVersion] = cust_get_kip_version(&table); // Run this after the check so we can do migration process configValues.values[KipConfigValue_KipVersion] = cust_get_kip_version(&table); // Run this after the check so we can do migration process
configValues.values[KipConfigValue_hpMode] = cust_get_hp_mode(&table); configValues.values[KipConfigValue_hpMode] = cust_get_hp_mode(&table);
configValues.values[KipConfigValue_commonEmcMemVolt] = cust_get_common_emc_volt(&table); configValues.values[KipConfigValue_commonEmcMemVolt] = cust_get_common_emc_volt(&table);
@@ -294,7 +295,8 @@ namespace kip {
if (sizeof(HocClkConfigValueList) <= sizeof(configValues)) { if (sizeof(HocClkConfigValueList) <= sizeof(configValues)) {
if (config::SetConfigValues(&configValues, true)) { 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++) { for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]); fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
} }
@@ -312,16 +314,17 @@ namespace kip {
HocClkConfigValueList configValues; HocClkConfigValueList configValues;
config::GetConfigValues(&configValues); config::GetConfigValues(&configValues);
u32 previousVersion = configValues.values[KipConfigValue_KipVersion]; u32 previousVersion = configValues.values[KipConfigValue_KipVersion];
if(previousVersion < 240 && version >= 240) { if (previousVersion < 240 && version >= 240) {
// <2.4.0 -> 2.4.0 migration // <2.4.0 -> 2.4.0 migration
// add marikoGpuBootVolt with default value of 800mV // add marikoGpuBootVolt with default value of 800mV
configValues.values[KipConfigValue_marikoGpuBootVolt] = 800; configValues.values[KipConfigValue_marikoGpuBootVolt] = 800;
configValues.values[KipConfigValue_marikoGpuUV] += 2; // Raise UV levels 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 // Raise min cpu vmin
if(configValues.values[KipConfigValue_eristaCpuVmin] < 750) { if (configValues.values[KipConfigValue_eristaCpuVmin] < 750) {
configValues.values[KipConfigValue_eristaCpuVmin] = 750; configValues.values[KipConfigValue_eristaCpuVmin] = 750;
} }
@@ -332,5 +335,4 @@ namespace kip {
} }
config::SetConfigValues(&configValues, true); config::SetConfigValues(&configValues, true);
} }
} } // namespace kip

View File

@@ -16,21 +16,23 @@
*/ */
#pragma once #pragma once
#include <switch.h> #include <crc32.h>
#include <stdio.h> #include <notification.h>
#include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <switch.h>
#include "config.hpp" #include "config.hpp"
#include "file_utils.hpp" #include "file_utils.hpp"
#include <notification.h>
#include <crc32.h>
namespace kip { namespace kip {
extern bool kipAvailable; extern bool kipAvailable;
typedef struct { typedef struct {
u8 cust[4]; u8 cust[4];
u32 custRev; u32 custRev;
u32 kipVersion; u32 kipVersion;
u32 hpMode; u32 hpMode;
@@ -97,24 +99,25 @@ namespace kip {
u32 reserved[60]; u32 reserved[60];
} CustomizeTable; } CustomizeTable;
#define CUST_MAGIC "CUST" #define CUST_MAGIC "CUST"
#define CUST_MAGIC_LEN 4 #define CUST_MAGIC_LEN 4
typedef struct { typedef struct {
FILE* file; FILE *file;
long offset; long offset;
CustomizeTable cached_table; CustomizeTable cached_table;
bool has_cache; bool has_cache;
} CustHandle; } CustHandle;
static inline bool cust_find_offset(FILE* f, long* out_offset) { static inline bool cust_find_offset(FILE *f, long *out_offset) {
u8 buf[512]; u8 buf[512];
long pos = 0; long pos = 0;
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
while (1) { while (1) {
size_t r = fread(buf, 1, sizeof(buf), f); 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++) { for (size_t i = 0; i <= r - CUST_MAGIC_LEN; i++) {
if (memcmp(&buf[i], CUST_MAGIC, CUST_MAGIC_LEN) == 0) { if (memcmp(&buf[i], CUST_MAGIC, CUST_MAGIC_LEN) == 0) {
@@ -130,23 +133,28 @@ namespace kip {
static long cachedCustOffset = -1; static long cachedCustOffset = -1;
static inline long cust_get_offset(FILE* f) { static inline long cust_get_offset(FILE *f) {
if (cachedCustOffset >= 0) return cachedCustOffset; if (cachedCustOffset >= 0)
return cachedCustOffset;
long off; long off;
if (!cust_find_offset(f, &off)) return -1; if (!cust_find_offset(f, &off))
return -1;
cachedCustOffset = off; cachedCustOffset = off;
return off; return off;
} }
static inline bool cust_read_table_f(FILE* f, CustomizeTable* out) { static inline bool cust_read_table_f(FILE *f, CustomizeTable *out) {
long off = cust_get_offset(f); long off = cust_get_offset(f);
if (off < 0) return false; if (off < 0)
return false;
fseek(f, 0, SEEK_END); 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); 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) { if (memcmp(out->cust, CUST_MAGIC, CUST_MAGIC_LEN) != 0) {
cachedCustOffset = -1; cachedCustOffset = -1;
@@ -155,12 +163,14 @@ namespace kip {
return true; return true;
} }
static inline bool cust_write_table_f(FILE* f, const CustomizeTable* in) { static inline bool cust_write_table_f(FILE *f, const CustomizeTable *in) {
long off = cust_get_offset(f); long off = cust_get_offset(f);
if (off < 0) return false; if (off < 0)
return false;
fseek(f, 0, SEEK_END); 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); fseek(f, off, SEEK_SET);
bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable); bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
@@ -168,246 +178,456 @@ namespace kip {
return ok; return ok;
} }
static inline bool cust_read_table(const char* path, CustomizeTable* out) { static inline bool cust_read_table(const char *path, CustomizeTable *out) {
FILE* f = fopen(path, "rb"); FILE *f = fopen(path, "rb");
if (!f) return false; if (!f)
return false;
bool ok = cust_read_table_f(f, out); bool ok = cust_read_table_f(f, out);
fclose(f); fclose(f);
return ok; return ok;
} }
static inline bool cust_write_table(const char* path, const CustomizeTable* in) { static inline bool cust_write_table(const char *path, const CustomizeTable *in) {
FILE* f = fopen(path, "r+b"); FILE *f = fopen(path, "r+b");
if (!f) return false; if (!f)
return false;
bool ok = cust_write_table_f(f, in); bool ok = cust_write_table_f(f, in);
fclose(f); fclose(f);
return ok; return ok;
} }
static inline bool cust_read_and_cache(const char* path, CustomizeTable* out) { static inline bool cust_read_and_cache(const char *path, CustomizeTable *out) {
return cust_read_table(path, out); return cust_read_table(path, out);
} }
#define CUST_WRITE_FIELD_BATCH(table, field, val) \ #define CUST_WRITE_FIELD_BATCH(table, field, val) \
do { \ do { \
(table)->field = (val); \ (table)->field = (val); \
} while (0) } while (0)
#define CUST_WRITE_FIELD(path, field, val) \ #define CUST_WRITE_FIELD(path, field, val) \
do { \ do { \
CustomizeTable t; \ CustomizeTable t; \
if (!cust_read_table(path, &t)) return false; \ if (!cust_read_table(path, &t)) \
t.field = (val); \ return false; \
return cust_write_table(path, &t); \ t.field = (val); \
} while (0) 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_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_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_common_emc_volt(const char *p, u32 v) {
static inline bool cust_set_erista_emc_max(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaEmcMaxClock, v); } CUST_WRITE_FIELD(p, commonEmcMemVolt, 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_erista_emc_max(const char *p, u32 v) {
static inline bool cust_set_mariko_emc_vddq(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoEmcVddqVolt, v); } CUST_WRITE_FIELD(p, eristaEmcMaxClock, 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_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_tRCD(const char *p, u32 v) {
static inline bool cust_set_tRP(const char* p, u32 v) { CUST_WRITE_FIELD(p, t2_tRP, v); } CUST_WRITE_FIELD(p, t1_tRCD, 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_tRP(const char *p, u32 v) {
static inline bool cust_set_tRFC(const char* p, u32 v) { CUST_WRITE_FIELD(p, t5_tRFC, v); } CUST_WRITE_FIELD(p, t2_tRP, 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_tRAS(const char *p, u32 v) {
static inline bool cust_set_tREFI(const char* p, u32 v) { CUST_WRITE_FIELD(p, t8_tREFI, v); } CUST_WRITE_FIELD(p, t3_tRAS, 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_tRRD(const char *p, u32 v) {
static inline bool cust_set_low_tRTW(const char* p, u32 v) { CUST_WRITE_FIELD(p, low_t6_tRTW, v); } CUST_WRITE_FIELD(p, t4_tRRD, 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_tRFC(const char *p, u32 v) {
static inline bool cust_set_tWTR_fine_tune(const char* p, u32 v) { CUST_WRITE_FIELD(p, t7_tWTR_fine_tune, 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_1333(const char *p, u32 v) {
static inline bool cust_set_read_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1600, v); } CUST_WRITE_FIELD(p, readLatency1333, 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_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_1333(const char *p, u32 v) {
static inline bool cust_set_write_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1600, v); } CUST_WRITE_FIELD(p, writeLatency1333, 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_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_erista_cpu_uv(const char *p, u32 v) {
static inline bool cust_set_eristaCpuVmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuVmin, v); } CUST_WRITE_FIELD(p, eristaCpuUV, 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_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_low(const char *p, u32 v) {
static inline bool cust_set_mariko_cpu_uv_high(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuUVHigh, v); } CUST_WRITE_FIELD(p, marikoCpuUVLow, 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_uv_high(const char *p, u32 v) {
static inline bool cust_set_mariko_cpu_max_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxVolt, v); } CUST_WRITE_FIELD(p, marikoCpuUVHigh, 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_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_uv(const char *p, u32 v) {
static inline bool cust_set_erista_gpu_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaGpuVmin, v); } CUST_WRITE_FIELD(p, eristaGpuUV, 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_erista_gpu_vmin(const char *p, u32 v) {
static inline bool cust_set_mariko_gpu_boot_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuBootVolt, v); } CUST_WRITE_FIELD(p, eristaGpuVmin, 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_mariko_gpu_uv(const char *p, u32 v) {
static inline bool cust_set_marikoCpuMaxClock(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxClock, v); } CUST_WRITE_FIELD(p, marikoGpuUV, v);
static inline bool cust_set_marikoSocVmax(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoSocVmax, 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 */ /* GPU VOLT ARRAY HELPERS */
static inline bool cust_set_erista_gpu_volt(const char* p, int idx, u32 v) { 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; CustomizeTable t;
if (!cust_read_table(p, &t)) return false; if (!cust_read_table(p, &t))
return false;
t.eristaGpuVoltArray[idx] = v; t.eristaGpuVoltArray[idx] = v;
return cust_write_table(p, &t); return cust_write_table(p, &t);
} }
static inline bool cust_set_mariko_gpu_volt(const char* p, int idx, u32 v) { 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; CustomizeTable t;
if (!cust_read_table(p, &t)) return false; if (!cust_read_table(p, &t))
return false;
t.marikoGpuVoltArray[idx] = v; t.marikoGpuVoltArray[idx] = v;
return cust_write_table(p, &t); return cust_write_table(p, &t);
} }
static inline u32 cust_get_field(const CustomizeTable* t, u32 offset) { static inline u32 cust_get_field(const CustomizeTable *t, u32 offset) {
if (!t) return 0; if (!t)
return *(u32*)((u8*)t + offset); return 0;
return *(u32 *)((u8 *)t + offset);
} }
#define CUST_GET_FIELD(table, field) ((table) ? (table)->field : 0) #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_cust_rev(const CustomizeTable *t) {
static inline u32 cust_get_kip_version(const CustomizeTable* t) { return CUST_GET_FIELD(t, kipVersion); } 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_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_common_emc_volt(const CustomizeTable *t) {
static inline u32 cust_get_erista_emc_max(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaEmcMaxClock); } return CUST_GET_FIELD(t, commonEmcMemVolt);
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_erista_emc_max(const CustomizeTable *t) {
static inline u32 cust_get_mariko_emc_vddq(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoEmcVddqVolt); } return CUST_GET_FIELD(t, eristaEmcMaxClock);
static inline u32 cust_get_emc_dvb_shift(const CustomizeTable* t) { return CUST_GET_FIELD(t, emcDvbShift); } }
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_tRCD(const CustomizeTable *t) {
static inline u32 cust_get_tRP(const CustomizeTable* t) { return CUST_GET_FIELD(t, t2_tRP); } return CUST_GET_FIELD(t, t1_tRCD);
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_tRP(const CustomizeTable *t) {
static inline u32 cust_get_tRFC(const CustomizeTable* t) { return CUST_GET_FIELD(t, t5_tRFC); } return CUST_GET_FIELD(t, t2_tRP);
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_tRAS(const CustomizeTable *t) {
static inline u32 cust_get_tREFI(const CustomizeTable* t) { return CUST_GET_FIELD(t, t8_tREFI); } return CUST_GET_FIELD(t, t3_tRAS);
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_tRRD(const CustomizeTable *t) {
static inline u32 cust_get_low_t6_tRTW(const CustomizeTable* t) { return CUST_GET_FIELD(t, low_t6_tRTW); } return CUST_GET_FIELD(t, t4_tRRD);
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_tRFC(const CustomizeTable *t) {
static inline u32 cust_get_tWTR_fine_tune(const CustomizeTable* t) { return CUST_GET_FIELD(t, t7_tWTR_fine_tune); } 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_1333(const CustomizeTable *t) {
static inline u32 cust_get_read_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1600); } return CUST_GET_FIELD(t, readLatency1333);
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_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_1333(const CustomizeTable *t) {
static inline u32 cust_get_write_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1600); } return CUST_GET_FIELD(t, writeLatency1333);
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_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_erista_cpu_uv(const CustomizeTable *t) {
static inline u32 cust_get_eristaCpuVmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuVmin); } return CUST_GET_FIELD(t, eristaCpuUV);
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_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_low(const CustomizeTable *t) {
static inline u32 cust_get_mariko_cpu_uv_high(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuUVHigh); } return CUST_GET_FIELD(t, marikoCpuUVLow);
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_uv_high(const CustomizeTable *t) {
static inline u32 cust_get_mariko_cpu_max_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxVolt); } return CUST_GET_FIELD(t, marikoCpuUVHigh);
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_mariko_cpu_low_vmin(const CustomizeTable *t) {
static inline u32 cust_get_table_conf(const CustomizeTable* t) { return CUST_GET_FIELD(t, tableConf); } 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_uv(const CustomizeTable *t) {
static inline u32 cust_get_erista_gpu_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaGpuVmin); } return CUST_GET_FIELD(t, eristaGpuUV);
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_erista_gpu_vmin(const CustomizeTable *t) {
static inline u32 cust_get_mariko_gpu_boot_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuBootVolt); } return CUST_GET_FIELD(t, eristaGpuVmin);
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_mariko_gpu_uv(const CustomizeTable *t) {
static inline u32 cust_get_marikoCpuMaxClock(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxClock); } return CUST_GET_FIELD(t, marikoGpuUV);
static inline u32 cust_get_marikoSocVmax(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoSocVmax); } }
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) { 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]; return t->eristaGpuVoltArray[idx];
} }
static inline u32 cust_get_mariko_gpu_volt(const CustomizeTable* t, int 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]; return t->marikoGpuVoltArray[idx];
} }
#define DECL_ERISTA_GPU_VOLT_HELPER(freq, idx) \ #define DECL_ERISTA_GPU_VOLT_HELPER(freq, idx) \
static inline bool cust_set_erista_gpu_volt_##freq( \ static inline bool cust_set_erista_gpu_volt_##freq(const char *p, u32 v) { \
const char* p, u32 v) { \ return cust_set_erista_gpu_volt(p, idx, v); \
return cust_set_erista_gpu_volt(p, idx, v); \
} }
#define DECL_MARIKO_GPU_VOLT_HELPER(freq, idx) \ #define DECL_MARIKO_GPU_VOLT_HELPER(freq, idx) \
static inline bool cust_set_mariko_gpu_volt_##freq( \ static inline bool cust_set_mariko_gpu_volt_##freq(const char *p, u32 v) { \
const char* p, u32 v) { \ return cust_set_mariko_gpu_volt(p, idx, v); \
return cust_set_mariko_gpu_volt(p, idx, v); \
} }
DECL_ERISTA_GPU_VOLT_HELPER(76800, 0) DECL_ERISTA_GPU_VOLT_HELPER(76800, 0)
DECL_ERISTA_GPU_VOLT_HELPER(115200, 1) DECL_ERISTA_GPU_VOLT_HELPER(115200, 1)
DECL_ERISTA_GPU_VOLT_HELPER(153600, 2) DECL_ERISTA_GPU_VOLT_HELPER(153600, 2)
DECL_ERISTA_GPU_VOLT_HELPER(192000, 3) DECL_ERISTA_GPU_VOLT_HELPER(192000, 3)
DECL_ERISTA_GPU_VOLT_HELPER(230400, 4) DECL_ERISTA_GPU_VOLT_HELPER(230400, 4)
DECL_ERISTA_GPU_VOLT_HELPER(268800, 5) DECL_ERISTA_GPU_VOLT_HELPER(268800, 5)
DECL_ERISTA_GPU_VOLT_HELPER(307200, 6) DECL_ERISTA_GPU_VOLT_HELPER(307200, 6)
DECL_ERISTA_GPU_VOLT_HELPER(345600, 7) DECL_ERISTA_GPU_VOLT_HELPER(345600, 7)
DECL_ERISTA_GPU_VOLT_HELPER(384000, 8) DECL_ERISTA_GPU_VOLT_HELPER(384000, 8)
DECL_ERISTA_GPU_VOLT_HELPER(422400, 9) DECL_ERISTA_GPU_VOLT_HELPER(422400, 9)
DECL_ERISTA_GPU_VOLT_HELPER(460800, 10) DECL_ERISTA_GPU_VOLT_HELPER(460800, 10)
DECL_ERISTA_GPU_VOLT_HELPER(499200, 11) DECL_ERISTA_GPU_VOLT_HELPER(499200, 11)
DECL_ERISTA_GPU_VOLT_HELPER(537600, 12) DECL_ERISTA_GPU_VOLT_HELPER(537600, 12)
DECL_ERISTA_GPU_VOLT_HELPER(576000, 13) DECL_ERISTA_GPU_VOLT_HELPER(576000, 13)
DECL_ERISTA_GPU_VOLT_HELPER(614400, 14) DECL_ERISTA_GPU_VOLT_HELPER(614400, 14)
DECL_ERISTA_GPU_VOLT_HELPER(652800, 15) DECL_ERISTA_GPU_VOLT_HELPER(652800, 15)
DECL_ERISTA_GPU_VOLT_HELPER(691200, 16) DECL_ERISTA_GPU_VOLT_HELPER(691200, 16)
DECL_ERISTA_GPU_VOLT_HELPER(729600, 17) DECL_ERISTA_GPU_VOLT_HELPER(729600, 17)
DECL_ERISTA_GPU_VOLT_HELPER(768000, 18) DECL_ERISTA_GPU_VOLT_HELPER(768000, 18)
DECL_ERISTA_GPU_VOLT_HELPER(806400, 19) DECL_ERISTA_GPU_VOLT_HELPER(806400, 19)
DECL_ERISTA_GPU_VOLT_HELPER(844800, 20) DECL_ERISTA_GPU_VOLT_HELPER(844800, 20)
DECL_ERISTA_GPU_VOLT_HELPER(883200, 21) DECL_ERISTA_GPU_VOLT_HELPER(883200, 21)
DECL_ERISTA_GPU_VOLT_HELPER(921600, 22) DECL_ERISTA_GPU_VOLT_HELPER(921600, 22)
DECL_ERISTA_GPU_VOLT_HELPER(960000, 23) DECL_ERISTA_GPU_VOLT_HELPER(960000, 23)
DECL_ERISTA_GPU_VOLT_HELPER(998400, 24) DECL_ERISTA_GPU_VOLT_HELPER(998400, 24)
DECL_ERISTA_GPU_VOLT_HELPER(1036800, 25) DECL_ERISTA_GPU_VOLT_HELPER(1036800, 25)
DECL_ERISTA_GPU_VOLT_HELPER(1075200, 26) DECL_ERISTA_GPU_VOLT_HELPER(1075200, 26)
DECL_MARIKO_GPU_VOLT_HELPER(76800, 0) DECL_MARIKO_GPU_VOLT_HELPER(76800, 0)
DECL_MARIKO_GPU_VOLT_HELPER(153600, 1) DECL_MARIKO_GPU_VOLT_HELPER(153600, 1)
DECL_MARIKO_GPU_VOLT_HELPER(230400, 2) DECL_MARIKO_GPU_VOLT_HELPER(230400, 2)
DECL_MARIKO_GPU_VOLT_HELPER(307200, 3) DECL_MARIKO_GPU_VOLT_HELPER(307200, 3)
DECL_MARIKO_GPU_VOLT_HELPER(384000, 4) DECL_MARIKO_GPU_VOLT_HELPER(384000, 4)
DECL_MARIKO_GPU_VOLT_HELPER(460800, 5) DECL_MARIKO_GPU_VOLT_HELPER(460800, 5)
DECL_MARIKO_GPU_VOLT_HELPER(537600, 6) DECL_MARIKO_GPU_VOLT_HELPER(537600, 6)
DECL_MARIKO_GPU_VOLT_HELPER(614400, 7) DECL_MARIKO_GPU_VOLT_HELPER(614400, 7)
DECL_MARIKO_GPU_VOLT_HELPER(691200, 8) DECL_MARIKO_GPU_VOLT_HELPER(691200, 8)
DECL_MARIKO_GPU_VOLT_HELPER(768000, 9) DECL_MARIKO_GPU_VOLT_HELPER(768000, 9)
DECL_MARIKO_GPU_VOLT_HELPER(844800, 10) DECL_MARIKO_GPU_VOLT_HELPER(844800, 10)
DECL_MARIKO_GPU_VOLT_HELPER(921600, 11) DECL_MARIKO_GPU_VOLT_HELPER(921600, 11)
DECL_MARIKO_GPU_VOLT_HELPER(998400, 12) DECL_MARIKO_GPU_VOLT_HELPER(998400, 12)
DECL_MARIKO_GPU_VOLT_HELPER(1075200, 13) DECL_MARIKO_GPU_VOLT_HELPER(1075200, 13)
DECL_MARIKO_GPU_VOLT_HELPER(1152000, 14) DECL_MARIKO_GPU_VOLT_HELPER(1152000, 14)
DECL_MARIKO_GPU_VOLT_HELPER(1228800, 15) DECL_MARIKO_GPU_VOLT_HELPER(1228800, 15)
@@ -420,60 +640,62 @@ namespace kip {
DECL_MARIKO_GPU_VOLT_HELPER(1497600, 22) DECL_MARIKO_GPU_VOLT_HELPER(1497600, 22)
DECL_MARIKO_GPU_VOLT_HELPER(1536000, 23) DECL_MARIKO_GPU_VOLT_HELPER(1536000, 23)
#define DECL_ERISTA_GPU_VOLT_GET(freq, idx) \ #define DECL_ERISTA_GPU_VOLT_GET(freq, idx) \
static inline u32 cust_get_erista_gpu_volt_##freq##_val(const char* p) { \ static inline u32 cust_get_erista_gpu_volt_##freq##_val(const char *p) { \
CustomizeTable t; \ CustomizeTable t; \
if (!cust_read_table(p, &t)) return 0; \ if (!cust_read_table(p, &t)) \
return cust_get_erista_gpu_volt(&t, idx); \ return 0; \
return cust_get_erista_gpu_volt(&t, idx); \
} }
#define DECL_MARIKO_GPU_VOLT_GET(freq, idx) \ #define DECL_MARIKO_GPU_VOLT_GET(freq, idx) \
static inline u32 cust_get_mariko_gpu_volt_##freq##_val(const char* p) { \ static inline u32 cust_get_mariko_gpu_volt_##freq##_val(const char *p) { \
CustomizeTable t; \ CustomizeTable t; \
if (!cust_read_table(p, &t)) return 0; \ if (!cust_read_table(p, &t)) \
return cust_get_mariko_gpu_volt(&t, idx); \ return 0; \
return cust_get_mariko_gpu_volt(&t, idx); \
} }
DECL_ERISTA_GPU_VOLT_GET(76800, 0) DECL_ERISTA_GPU_VOLT_GET(76800, 0)
DECL_ERISTA_GPU_VOLT_GET(115200, 1) DECL_ERISTA_GPU_VOLT_GET(115200, 1)
DECL_ERISTA_GPU_VOLT_GET(153600, 2) DECL_ERISTA_GPU_VOLT_GET(153600, 2)
DECL_ERISTA_GPU_VOLT_GET(192000, 3) DECL_ERISTA_GPU_VOLT_GET(192000, 3)
DECL_ERISTA_GPU_VOLT_GET(230400, 4) DECL_ERISTA_GPU_VOLT_GET(230400, 4)
DECL_ERISTA_GPU_VOLT_GET(268800, 5) DECL_ERISTA_GPU_VOLT_GET(268800, 5)
DECL_ERISTA_GPU_VOLT_GET(307200, 6) DECL_ERISTA_GPU_VOLT_GET(307200, 6)
DECL_ERISTA_GPU_VOLT_GET(345600, 7) DECL_ERISTA_GPU_VOLT_GET(345600, 7)
DECL_ERISTA_GPU_VOLT_GET(384000, 8) DECL_ERISTA_GPU_VOLT_GET(384000, 8)
DECL_ERISTA_GPU_VOLT_GET(422400, 9) DECL_ERISTA_GPU_VOLT_GET(422400, 9)
DECL_ERISTA_GPU_VOLT_GET(460800, 10) DECL_ERISTA_GPU_VOLT_GET(460800, 10)
DECL_ERISTA_GPU_VOLT_GET(499200, 11) DECL_ERISTA_GPU_VOLT_GET(499200, 11)
DECL_ERISTA_GPU_VOLT_GET(537600, 12) DECL_ERISTA_GPU_VOLT_GET(537600, 12)
DECL_ERISTA_GPU_VOLT_GET(576000, 13) DECL_ERISTA_GPU_VOLT_GET(576000, 13)
DECL_ERISTA_GPU_VOLT_GET(614400, 14) DECL_ERISTA_GPU_VOLT_GET(614400, 14)
DECL_ERISTA_GPU_VOLT_GET(652800, 15) DECL_ERISTA_GPU_VOLT_GET(652800, 15)
DECL_ERISTA_GPU_VOLT_GET(691200, 16) DECL_ERISTA_GPU_VOLT_GET(691200, 16)
DECL_ERISTA_GPU_VOLT_GET(729600, 17) DECL_ERISTA_GPU_VOLT_GET(729600, 17)
DECL_ERISTA_GPU_VOLT_GET(768000, 18) DECL_ERISTA_GPU_VOLT_GET(768000, 18)
DECL_ERISTA_GPU_VOLT_GET(806400, 19) DECL_ERISTA_GPU_VOLT_GET(806400, 19)
DECL_ERISTA_GPU_VOLT_GET(844800, 20) DECL_ERISTA_GPU_VOLT_GET(844800, 20)
DECL_ERISTA_GPU_VOLT_GET(883200, 21) DECL_ERISTA_GPU_VOLT_GET(883200, 21)
DECL_ERISTA_GPU_VOLT_GET(921600, 22) DECL_ERISTA_GPU_VOLT_GET(921600, 22)
DECL_ERISTA_GPU_VOLT_GET(960000, 23) DECL_ERISTA_GPU_VOLT_GET(960000, 23)
DECL_ERISTA_GPU_VOLT_GET(998400, 24) DECL_ERISTA_GPU_VOLT_GET(998400, 24)
DECL_ERISTA_GPU_VOLT_GET(1036800, 25) DECL_ERISTA_GPU_VOLT_GET(1036800, 25)
DECL_ERISTA_GPU_VOLT_GET(1075200, 26) DECL_ERISTA_GPU_VOLT_GET(1075200, 26)
DECL_MARIKO_GPU_VOLT_GET(76800, 0) DECL_MARIKO_GPU_VOLT_GET(76800, 0)
DECL_MARIKO_GPU_VOLT_GET(153600, 1) DECL_MARIKO_GPU_VOLT_GET(153600, 1)
DECL_MARIKO_GPU_VOLT_GET(230400, 2) DECL_MARIKO_GPU_VOLT_GET(230400, 2)
DECL_MARIKO_GPU_VOLT_GET(307200, 3) DECL_MARIKO_GPU_VOLT_GET(307200, 3)
DECL_MARIKO_GPU_VOLT_GET(384000, 4) DECL_MARIKO_GPU_VOLT_GET(384000, 4)
DECL_MARIKO_GPU_VOLT_GET(460800, 5) DECL_MARIKO_GPU_VOLT_GET(460800, 5)
DECL_MARIKO_GPU_VOLT_GET(537600, 6) DECL_MARIKO_GPU_VOLT_GET(537600, 6)
DECL_MARIKO_GPU_VOLT_GET(614400, 7) DECL_MARIKO_GPU_VOLT_GET(614400, 7)
DECL_MARIKO_GPU_VOLT_GET(691200, 8) DECL_MARIKO_GPU_VOLT_GET(691200, 8)
DECL_MARIKO_GPU_VOLT_GET(768000, 9) DECL_MARIKO_GPU_VOLT_GET(768000, 9)
DECL_MARIKO_GPU_VOLT_GET(844800, 10) DECL_MARIKO_GPU_VOLT_GET(844800, 10)
DECL_MARIKO_GPU_VOLT_GET(921600, 11) DECL_MARIKO_GPU_VOLT_GET(921600, 11)
DECL_MARIKO_GPU_VOLT_GET(998400, 12) DECL_MARIKO_GPU_VOLT_GET(998400, 12)
DECL_MARIKO_GPU_VOLT_GET(1075200, 13) DECL_MARIKO_GPU_VOLT_GET(1075200, 13)
DECL_MARIKO_GPU_VOLT_GET(1152000, 14) DECL_MARIKO_GPU_VOLT_GET(1152000, 14)
DECL_MARIKO_GPU_VOLT_GET(1228800, 15) DECL_MARIKO_GPU_VOLT_GET(1228800, 15)
@@ -488,4 +710,4 @@ namespace kip {
void MigrateKipData(u32 custRev, u32 version); void MigrateKipData(u32 custRev, u32 version);
void SetKipData(); void SetKipData();
void GetKipData(); void GetKipData();
} } // namespace kip

View File

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

View File

@@ -24,12 +24,10 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
#include <switch.h> #include <switch.h>
@@ -37,19 +35,19 @@ extern "C"
Result apmExtInitialize(void); Result apmExtInitialize(void);
void apmExtExit(void); void apmExtExit(void);
Result apmExtGetPerformanceMode(u32* out_mode); Result apmExtGetPerformanceMode(u32 *out_mode);
Result apmExtSysRequestPerformanceMode(u32 mode); Result apmExtSysRequestPerformanceMode(u32 mode);
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf); Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
Result apmExtSysRequestPerformanceMode(u32 mode); Result apmExtSysRequestPerformanceMode(u32 mode);
Result apmExtSysSetCpuBoostMode(u32 mode); Result apmExtSysSetCpuBoostMode(u32 mode);
Result apmExtGetPerformanceMode(u32 *out_mode); Result apmExtGetPerformanceMode(u32 *out_mode);
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf); Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz
return (conf_id == 0x92220009 || conf_id == 0x9222000A); return (conf_id == 0x92220009 || conf_id == 0x9222000A);
}; };
inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz
return (conf_id >= 0x92220009 && conf_id <= 0x9222000C); return (conf_id >= 0x92220009 && conf_id <= 0x9222000C);
}; };

View File

@@ -24,26 +24,24 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include <hocclk/apm.h> #include <hocclk/apm.h>
HocClkApmConfiguration hocclk_g_apm_configurations[] = { HocClkApmConfiguration hocclk_g_apm_configurations[] = {
{0x00010000, 1020000000, 384000000, 1600000000}, { 0x00010000, 1020000000, 384000000, 1600000000 },
{0x00010001, 1020000000, 768000000, 1600000000}, { 0x00010001, 1020000000, 768000000, 1600000000 },
{0x00010002, 1224000000, 691200000, 1600000000}, { 0x00010002, 1224000000, 691200000, 1600000000 },
{0x00020000, 1020000000, 230400000, 1600000000}, { 0x00020000, 1020000000, 230400000, 1600000000 },
{0x00020001, 1020000000, 307200000, 1600000000}, { 0x00020001, 1020000000, 307200000, 1600000000 },
{0x00020002, 1224000000, 230400000, 1600000000}, { 0x00020002, 1224000000, 230400000, 1600000000 },
{0x00020003, 1020000000, 307200000, 1331200000}, { 0x00020003, 1020000000, 307200000, 1331200000 },
{0x00020004, 1020000000, 384000000, 1331200000}, { 0x00020004, 1020000000, 384000000, 1331200000 },
{0x00020005, 1020000000, 307200000, 1065600000}, { 0x00020005, 1020000000, 307200000, 1065600000 },
{0x00020006, 1020000000, 384000000, 1065600000}, { 0x00020006, 1020000000, 384000000, 1065600000 },
{0x92220007, 1020000000, 460800000, 1600000000}, { 0x92220007, 1020000000, 460800000, 1600000000 },
{0x92220008, 1020000000, 460800000, 1331200000}, { 0x92220008, 1020000000, 460800000, 1331200000 },
{0x92220009, 1785000000, 76800000, 1600000000}, { 0x92220009, 1785000000, 76800000, 1600000000 },
{0x9222000A, 1785000000, 76800000, 1331200000}, { 0x9222000A, 1785000000, 76800000, 1331200000 },
{0x9222000B, 1020000000, 76800000, 1600000000}, { 0x9222000B, 1020000000, 76800000, 1600000000 },
{0x9222000C, 1020000000, 76800000, 1331200000}, { 0x9222000C, 1020000000, 76800000, 1331200000 },
{0, 0, 0, 0}, { 0, 0, 0, 0 },
}; };

View File

@@ -15,16 +15,17 @@
* *
*/ */
#include "integrations.hpp"
#include <sys/stat.h>
#include <SaltyNX.h> #include <SaltyNX.h>
#include "integrations.hpp"
#include "process_management.hpp" #include "process_management.hpp"
#include <sys/stat.h>
namespace integrations { namespace integrations {
namespace { namespace {
NxFpsSharedBlock* gNxFps = nullptr; NxFpsSharedBlock *gNxFps = nullptr;
SharedMemory gSharedMemory = {}; SharedMemory gSharedMemory = {};
bool gSharedMemoryUsed = false; bool gSharedMemoryUsed = false;
Handle gRemoteSharedMemory = 1; Handle gRemoteSharedMemory = 1;
@@ -38,7 +39,8 @@ namespace integrations {
svcCloseHandle(saltysd); svcCloseHandle(saltysd);
break; break;
} }
if (i == 66) return false; if (i == 66)
return false;
svcSleepThread(1'000'000); svcSleepThread(1'000'000);
} }
@@ -56,7 +58,7 @@ namespace integrations {
void SearchSharedMemoryBlock(uintptr_t base) { void SearchSharedMemoryBlock(uintptr_t base) {
ptrdiff_t search_offset = 0; ptrdiff_t search_offset = 0;
while (search_offset < 0x1000) { while (search_offset < 0x1000) {
gNxFps = (NxFpsSharedBlock*)(base + search_offset); gNxFps = (NxFpsSharedBlock *)(base + search_offset);
if (gNxFps->MAGIC == 0x465053) if (gNxFps->MAGIC == 0x465053)
return; return;
search_offset += 4; search_offset += 4;
@@ -74,21 +76,21 @@ namespace integrations {
gSharedMemoryUsed = true; gSharedMemoryUsed = true;
} }
} } // namespace
bool GetSysDockState() { bool GetSysDockState() {
struct stat st = {0}; struct stat st = { 0 };
return stat("sdmc:/atmosphere/contents/42000000000000A0/flags/boot2.flag", &st) == 0; return stat("sdmc:/atmosphere/contents/42000000000000A0/flags/boot2.flag", &st) == 0;
} }
bool GetSaltyNXState() { bool GetSaltyNXState() {
struct stat st = {0}; struct stat st = { 0 };
return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0; return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0;
} }
bool GetRETROSuperStatus() { bool GetRETROSuperStatus() {
struct stat st = {0}; struct stat st = { 0 };
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this
} }
void LoadSaltyNX() { void LoadSaltyNX() {
@@ -143,8 +145,10 @@ namespace integrations {
resolutionLookup = 1; resolutionLookup = 1;
return 0; return 0;
} else if (resolutionLookup == 1) { } else if (resolutionLookup == 1) {
if (gNxFps->renderCalls[0].calls != 0xFFFF) resolutionLookup = 2; if (gNxFps->renderCalls[0].calls != 0xFFFF)
else return 0; resolutionLookup = 2;
else
return 0;
} }
return gNxFps->renderCalls[0].height == 0 ? gNxFps->viewportCalls[0].height : gNxFps->renderCalls[0].height; return gNxFps->renderCalls[0].height == 0 ? gNxFps->viewportCalls[0].height : gNxFps->renderCalls[0].height;
@@ -152,4 +156,4 @@ namespace integrations {
return 0; return 0;
} }
} } // namespace integrations

View File

@@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h>
#include <hocclk.h> #include <hocclk.h>
#include <switch.h>
namespace integrations { namespace integrations {
@@ -39,9 +39,9 @@ namespace integrations {
uint8_t SetActiveBuffers; uint8_t SetActiveBuffers;
union { union {
struct { struct {
bool handheld: 1; bool handheld : 1;
bool docked: 1; bool docked : 1;
unsigned int reserved: 6; unsigned int reserved : 6;
} NX_PACKED ds; } NX_PACKED ds;
uint8_t general; uint8_t general;
} displaySync; } displaySync;
@@ -66,4 +66,4 @@ namespace integrations {
u8 GetSaltyNXFPS(); u8 GetSaltyNXFPS();
u16 GetSaltyNXResolutionHeight(); u16 GetSaltyNXResolutionHeight();
} } // namespace integrations

View File

@@ -15,14 +15,13 @@
* *
*/ */
#include "notification.h" #include "notification.h"
namespace notification { namespace notification {
void writeNotification(const std::string& message) { void writeNotification(const std::string &message) {
static const char* flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag"; static const char *flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
FILE* flagFile = fopen(flagPath, "r"); FILE *flagFile = fopen(flagPath, "r");
if (!flagFile) { if (!flagFile) {
return; return;
} }
@@ -31,7 +30,7 @@ namespace notification {
std::string filename = "hoc-" + std::to_string(std::time(nullptr)) + ".notify"; std::string filename = "hoc-" + std::to_string(std::time(nullptr)) + ".notify";
std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename; std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename;
FILE* file = fopen(fullPath.c_str(), "w"); FILE *file = fopen(fullPath.c_str(), "w");
if (file) { if (file) {
fprintf(file, "{\n"); fprintf(file, "{\n");
fprintf(file, " \"text\": \"%s\",\n", message.c_str()); fprintf(file, " \"text\": \"%s\",\n", message.c_str());
@@ -40,4 +39,4 @@ namespace notification {
fclose(file); fclose(file);
} }
} }
} } // namespace notification

View File

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

View File

@@ -26,24 +26,23 @@
*/ */
/* /*
* Switch Power domains (max77620): * Switch Power domains (max77620):
* Name | Usage | uV step | uV min | uV default | uV max | Init * Name | Usage | uV step | uV min | uV default | uV max | Init
*-------+---------------+---------+--------+------------+---------+------------------ *-------+---------------+---------+--------+------------+---------+------------------
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1) * sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1)
* sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1) * sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1)
* sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv) * sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv)
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 | * sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1) * ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv) * ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 | * ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv) * ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv) * ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv) * ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv) * ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv) * ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv) * 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. // GPIOs T210: 3: 3.3V, 5: CPU PMIC, 6: GPU PMIC, 7: DSI/VI 1.2V powered by ldo0.
@@ -66,15 +65,15 @@
*/ */
/* /*
* MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode * MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode
* MAX77620_REG_GPIOx: 0x9 sets output and enable * MAX77620_REG_GPIOx: 0x9 sets output and enable
*/ */
typedef enum { typedef enum {
PcvPowerDomain_Max77620_Sd0 = 0, PcvPowerDomain_Max77620_Sd0 = 0,
PcvPowerDomain_Max77620_Sd1 = 1, PcvPowerDomain_Max77620_Sd1 = 1,
PcvPowerDomain_Max77620_Sd2 = 2, PcvPowerDomain_Max77620_Sd2 = 2,
PcvPowerDomain_Max77620_Sd3 = 3, PcvPowerDomain_Max77620_Sd3 = 3,
PcvPowerDomain_Max77620_Ldo0 = 4, PcvPowerDomain_Max77620_Ldo0 = 4,
PcvPowerDomain_Max77620_Ldo1 = 5, PcvPowerDomain_Max77620_Ldo1 = 5,
PcvPowerDomain_Max77620_Ldo2 = 6, PcvPowerDomain_Max77620_Ldo2 = 6,
@@ -84,18 +83,18 @@ typedef enum {
PcvPowerDomain_Max77620_Ldo6 = 10, PcvPowerDomain_Max77620_Ldo6 = 10,
PcvPowerDomain_Max77620_Ldo7 = 11, PcvPowerDomain_Max77620_Ldo7 = 11,
PcvPowerDomain_Max77620_Ldo8 = 12, PcvPowerDomain_Max77620_Ldo8 = 12,
PcvPowerDomain_Max77621_Cpu = 13, PcvPowerDomain_Max77621_Cpu = 13,
PcvPowerDomain_Max77621_Gpu = 14, PcvPowerDomain_Max77621_Gpu = 14,
PcvPowerDomain_Max77812_Cpu = 15, PcvPowerDomain_Max77812_Cpu = 15,
PcvPowerDomain_Max77812_Gpu = 16, PcvPowerDomain_Max77812_Gpu = 16,
PcvPowerDomain_Max77812_Dram = 17, PcvPowerDomain_Max77812_Dram = 17,
} PowerDomain; } PowerDomain;
typedef enum { typedef enum {
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080, PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2 PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082, PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083, PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0, PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0,
PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1, PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1,
PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2, PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2,
@@ -105,9 +104,9 @@ typedef enum {
PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6, PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6,
PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7, PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7,
PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8, PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8,
PcvPowerDomainId_Max77621_Cpu = 0x3A000003, PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
PcvPowerDomainId_Max77621_Gpu = 0x3A000004, PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Cpu = 0x3A000003, PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
PcvPowerDomainId_Max77812_Gpu = 0x3A000004, PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
} PowerDomainId; } PowerDomainId;

View File

@@ -24,19 +24,20 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "process_management.hpp"
#include "../file/file_utils.hpp"
#include "../file/errors.hpp"
#include <cstring> #include <cstring>
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "process_management.hpp"
namespace processManagement { namespace processManagement {
namespace { namespace {
constexpr u64 Qlaunch = 0x0100000000001000ULL; constexpr u64 Qlaunch = 0x0100000000001000ULL;
constexpr u32 IsQlaunch = 0x20f; constexpr u32 IsQlaunch = 0x20f;
Service pdmqryClone; Service pdmqryClone;
} } // namespace
void Initialize() { void Initialize() {
Result rc = 0; Result rc = 0;
@@ -50,11 +51,10 @@ namespace processManagement {
rc = pdmqryInitialize(); rc = pdmqryInitialize();
ASSERT_RESULT_OK(rc, "pdmqryInitialize"); ASSERT_RESULT_OK(rc, "pdmqryInitialize");
Service* pdmqrySrv = pdmqryGetServiceSession(); Service *pdmqrySrv = pdmqryGetServiceSession();
serviceClone(pdmqrySrv, &pdmqryClone); serviceClone(pdmqrySrv, &pdmqryClone);
serviceClose(pdmqrySrv); serviceClose(pdmqrySrv);
memcpy(pdmqrySrv, &pdmqryClone, sizeof(Service)); memcpy(pdmqrySrv, &pdmqryClone, sizeof(Service));
} }
void WaitForQLaunch() { void WaitForQLaunch() {
@@ -62,12 +62,12 @@ namespace processManagement {
u64 pid = 0; u64 pid = 0;
do { do {
rc = pmdmntGetProcessId(&pid, Qlaunch); rc = pmdmntGetProcessId(&pid, Qlaunch);
svcSleepThread(50 * 1000000ULL); // 50ms svcSleepThread(50 * 1000000ULL); // 50ms
} while (R_FAILED(rc)); } while (R_FAILED(rc));
} }
// Ty to Masa for this function! // Ty to Masa for this function!
Result isApplicationOutOfFocus(bool* outOfFocus) { Result isApplicationOutOfFocus(bool *outOfFocus) {
static s32 last_total_entries = 0; static s32 last_total_entries = 0;
static bool isOutOfFocus = false; static bool isOutOfFocus = false;
s32 total_entries = 0; s32 total_entries = 0;
@@ -77,12 +77,15 @@ namespace processManagement {
u64 PIDnow; u64 PIDnow;
Result rc = pmdmntGetApplicationProcessId(&PIDnow); Result rc = pmdmntGetApplicationProcessId(&PIDnow);
if(R_FAILED(rc)) return rc; if (R_FAILED(rc))
return rc;
rc = pmdmntGetProgramId(&TIDnow, PIDnow); 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); 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) { if (total_entries == last_total_entries) {
*outOfFocus = isOutOfFocus; *outOfFocus = isOutOfFocus;
return 0; return 0;
@@ -92,13 +95,16 @@ namespace processManagement {
PdmPlayEvent events[16]; PdmPlayEvent events[16];
s32 out = 0; s32 out = 0;
s32 start_entry = end_entry_index - 15; 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); rc = pdmqryQueryPlayEvent(start_entry, events, sizeof(events) / sizeof(events[0]), &out);
if (R_FAILED(rc)) return rc; if (R_FAILED(rc))
if (out == 0) return 1; return rc;
if (out == 0)
return 1;
int itr = -1; int itr = -1;
for (int i = out-1; i >= 0; i--) { for (int i = out - 1; i >= 0; i--) {
if (events[i].play_event_type != PdmPlayEventType_Applet) if (events[i].play_event_type != PdmPlayEventType_Applet)
continue; continue;
if (events[i].event_data.applet.applet_id != AppletId_application) if (events[i].event_data.applet.applet_id != AppletId_application)
@@ -112,8 +118,6 @@ namespace processManagement {
TID.parts.part[0] = events[i].event_data.applet.program_id[1]; TID.parts.part[0] = events[i].event_data.applet.program_id[1];
TID.parts.part[1] = events[i].event_data.applet.program_id[0]; TID.parts.part[1] = events[i].event_data.applet.program_id[0];
if (TID.full != (TIDnow & ~0xFFF)) if (TID.full != (TIDnow & ~0xFFF))
continue; continue;
else { else {
@@ -121,9 +125,11 @@ namespace processManagement {
break; 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; *outOfFocus = isOut;
isOutOfFocus = isOut; isOutOfFocus = isOut;
return 0; return 0;
@@ -158,4 +164,4 @@ namespace processManagement {
pdmqryExit(); pdmqryExit();
} }
} } // namespace processManagement

View File

@@ -24,7 +24,6 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#include <switch.h> #include <switch.h>
@@ -33,7 +32,7 @@ namespace processManagement {
void Initialize(); void Initialize();
void WaitForQLaunch(); void WaitForQLaunch();
u64 GetCurrentApplicationId(); u64 GetCurrentApplicationId();
Result isApplicationOutOfFocus(bool* outOfFocus); Result isApplicationOutOfFocus(bool *outOfFocus);
void Exit(); void Exit();
} } // namespace processManagement

View File

@@ -17,39 +17,50 @@
#include "psm_ext.h" #include "psm_ext.h"
const char* PsmPowerRoleToStr(PsmPowerRole role) { const char *PsmPowerRoleToStr(PsmPowerRole role) {
switch (role) { switch (role) {
case PsmPowerRole_Sink: return "Sink"; case PsmPowerRole_Sink:
case PsmPowerRole_Source: return "Source"; return "Sink";
default: return "Unknown"; case PsmPowerRole_Source:
return "Source";
default:
return "Unknown";
} }
} }
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type) { const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
switch (type) { switch (type) {
case PsmInfoChargerType_None: return "None"; case PsmInfoChargerType_None:
case PsmInfoChargerType_PD: return "USB-C PD"; return "None";
case PsmInfoChargerType_PD:
return "USB-C PD";
case PsmInfoChargerType_TypeC_1500mA: case PsmInfoChargerType_TypeC_1500mA:
case PsmInfoChargerType_TypeC_3000mA: return "USB-C"; case PsmInfoChargerType_TypeC_3000mA:
case PsmInfoChargerType_DCP: return "USB DCP"; return "USB-C";
case PsmInfoChargerType_CDP: return "USB CDP"; case PsmInfoChargerType_DCP:
case PsmInfoChargerType_SDP: return "USB SDP"; return "USB DCP";
case PsmInfoChargerType_CDP:
return "USB CDP";
case PsmInfoChargerType_SDP:
return "USB SDP";
case PsmInfoChargerType_Apple_500mA: case PsmInfoChargerType_Apple_500mA:
case PsmInfoChargerType_Apple_1000mA: case PsmInfoChargerType_Apple_1000mA:
case PsmInfoChargerType_Apple_2000mA: return "Apple"; case PsmInfoChargerType_Apple_2000mA:
default: return "Unknown"; return "Apple";
default:
return "Unknown";
} }
} }
bool PsmIsChargerConnected(const PsmChargeInfo* info) { bool PsmIsChargerConnected(const PsmChargeInfo *info) {
return info->ChargerType != PsmInfoChargerType_None; return info->ChargerType != PsmInfoChargerType_None;
} }
bool PsmIsCharging(const PsmChargeInfo* info) { bool PsmIsCharging(const PsmChargeInfo *info) {
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1); return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
} }
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) { PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info) {
if (!PsmIsChargerConnected(info)) if (!PsmIsChargerConnected(info))
return PsmBatteryState_Discharging; return PsmBatteryState_Discharging;
if (!PsmIsCharging(info)) if (!PsmIsCharging(info))
@@ -57,11 +68,15 @@ PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
return PsmBatteryState_FastCharging; return PsmBatteryState_FastCharging;
} }
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) { const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info) {
switch (PsmGetBatteryState(info)) { switch (PsmGetBatteryState(info)) {
case PsmBatteryState_Discharging: return "\u25c0"; // ◀ case PsmBatteryState_Discharging:
case PsmBatteryState_ChargingPaused:return "| |"; return "\u25c0"; // ◀
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶ case PsmBatteryState_ChargingPaused:
default: return "?"; return "| |";
case PsmBatteryState_FastCharging:
return "\u25b6"; // ▶
default:
return "?";
} }
} }

View File

@@ -20,75 +20,68 @@
#include <switch.h> #include <switch.h>
typedef enum { typedef enum {
PsmPDC_NewPDO = 1, //Received new Power Data Object PsmPDC_NewPDO = 1, // Received new Power Data Object
PsmPDC_NoPD = 2, //No Power Delivery source is detected PsmPDC_NoPD = 2, // No Power Delivery source is detected
PsmPDC_AcceptedRDO = 3 //Received and accepted Request Data Object PsmPDC_AcceptedRDO = 3 // Received and accepted Request Data Object
} PsmChargeInfoPDC; //BM92T series } PsmChargeInfoPDC; // BM92T series
typedef enum { PsmPowerRole_Sink = 1, PsmPowerRole_Source = 2 } PsmPowerRole;
const char *PsmPowerRoleToStr(PsmPowerRole role);
typedef enum { typedef enum {
PsmPowerRole_Sink = 1, PsmInfoChargerType_None = 0,
PsmPowerRole_Source = 2 PsmInfoChargerType_PD = 1,
} PsmPowerRole;
const char* PsmPowerRoleToStr(PsmPowerRole role);
typedef enum {
PsmInfoChargerType_None = 0,
PsmInfoChargerType_PD = 1,
PsmInfoChargerType_TypeC_1500mA = 2, PsmInfoChargerType_TypeC_1500mA = 2,
PsmInfoChargerType_TypeC_3000mA = 3, PsmInfoChargerType_TypeC_3000mA = 3,
PsmInfoChargerType_DCP = 4, PsmInfoChargerType_DCP = 4,
PsmInfoChargerType_CDP = 5, PsmInfoChargerType_CDP = 5,
PsmInfoChargerType_SDP = 6, PsmInfoChargerType_SDP = 6,
PsmInfoChargerType_Apple_500mA = 7, PsmInfoChargerType_Apple_500mA = 7,
PsmInfoChargerType_Apple_1000mA = 8, PsmInfoChargerType_Apple_1000mA = 8,
PsmInfoChargerType_Apple_2000mA = 9 PsmInfoChargerType_Apple_2000mA = 9
} PsmInfoChargerType; } PsmInfoChargerType;
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type); const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type);
typedef enum { typedef enum {
PsmFlags_NoHub = BIT(0), //If hub is disconnected PsmFlags_NoHub = BIT(0), // If hub is disconnected
PsmFlags_Rail = BIT(8), //At least one Joy-con is charging from rail PsmFlags_Rail = BIT(8), // At least one Joy-con is charging from rail
PsmFlags_SPDSRC = BIT(12), //OTG PsmFlags_SPDSRC = BIT(12), // OTG
PsmFlags_ACC = BIT(16) //Accessory PsmFlags_ACC = BIT(16) // Accessory
} PsmChargeInfoFlags; } PsmChargeInfoFlags;
typedef struct { typedef struct {
int32_t InputCurrentLimit; //Input (Sink) current limit in mA int32_t InputCurrentLimit; // Input (Sink) current limit in mA
int32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA int32_t VBUSCurrentLimit; // Output (Source/VBUS/OTG) current limit in mA
int32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C) int32_t ChargeCurrentLimit; // Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
int32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C) int32_t ChargeVoltageLimit; // Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
int32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases int32_t unk_x10; // Possibly an emum, getting the same value as PowerRole in all tested cases
int32_t unk_x14; //Possibly flags int32_t unk_x14; // Possibly flags
PsmChargeInfoPDC PDCState; //Power Delivery Controller State PsmChargeInfoPDC PDCState; // Power Delivery Controller State
int32_t BatteryTemperature; //Battery temperature in milli C int32_t BatteryTemperature; // Battery temperature in milli C
int32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm) int32_t RawBatteryCharge; // Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
int32_t VoltageAvg; //Voltage avg in mV (more in Notes) int32_t VoltageAvg; // Voltage avg in mV (more in Notes)
int32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm) int32_t BatteryAge; // Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
PsmPowerRole PowerRole; PsmPowerRole PowerRole;
PsmInfoChargerType ChargerType; PsmInfoChargerType ChargerType;
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV int32_t ChargerVoltageLimit; // Charger and external device voltage limit in mV
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA int32_t ChargerCurrentLimit; // Charger and external device current limit in mA
PsmChargeInfoFlags Flags; //Unknown flags PsmChargeInfoFlags Flags; // Unknown flags
} PsmChargeInfo; } PsmChargeInfo;
typedef enum { typedef enum {
Psm_EnableBatteryCharging = 2, Psm_EnableBatteryCharging = 2,
Psm_DisableBatteryCharging = 3, Psm_DisableBatteryCharging = 3,
Psm_EnableFastBatteryCharging = 10, Psm_EnableFastBatteryCharging = 10,
Psm_DisableFastBatteryCharging = 11, Psm_DisableFastBatteryCharging = 11,
Psm_GetBatteryChargeInfoFields = 17, Psm_GetBatteryChargeInfoFields = 17,
} IPsmServerCmd; } IPsmServerCmd;
bool PsmIsChargerConnected(const PsmChargeInfo* info); bool PsmIsChargerConnected(const PsmChargeInfo *info);
bool PsmIsCharging(const PsmChargeInfo* info); bool PsmIsCharging(const PsmChargeInfo *info);
typedef enum { typedef enum { PsmBatteryState_Discharging, PsmBatteryState_ChargingPaused, PsmBatteryState_FastCharging } PsmBatteryState;
PsmBatteryState_Discharging,
PsmBatteryState_ChargingPaused,
PsmBatteryState_FastCharging
} PsmBatteryState;
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info); PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info);
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info); const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info);

View File

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

View File

@@ -29,11 +29,11 @@ typedef struct {
Result pwmInitialize(void); Result pwmInitialize(void);
void pwmExit(void); void pwmExit(void);
Service* pwmGetServiceSession(void); Service *pwmGetServiceSession(void);
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code); Result pwmOpenSession2(PwmChannelSession *out, u32 device_code);
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out); Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out);
void pwmChannelSessionClose(PwmChannelSession *c); void pwmChannelSessionClose(PwmChannelSession *c);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif

View File

@@ -17,8 +17,10 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include "pcv_types.h" #include "pcv_types.h"
typedef struct { typedef struct {
Service s; Service s;
} RgltrSession; } RgltrSession;
@@ -27,12 +29,12 @@ Result rgltrInitialize(void);
void rgltrExit(void); void rgltrExit(void);
Service* rgltrGetServiceSession(void); Service *rgltrGetServiceSession(void);
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id); Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id);
void rgltrCloseSession(RgltrSession* session); void rgltrCloseSession(RgltrSession *session);
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt); Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt);
Result rgltrGetPowerModuleNumLimit(u32 *out); Result rgltrGetPowerModuleNumLimit(u32 *out);
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out); Result rgltrGetVoltageEnabled(RgltrSession *session, u32 *out);
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt); Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt);
Result rgltrCancelVoltageRequest(RgltrSession* session); Result rgltrCancelVoltageRequest(RgltrSession *session);

View File

@@ -16,9 +16,11 @@
*/ */
#include <switch.h> #include <switch.h>
#include "rgltr.h" #include "rgltr.h"
#include "rgltr_services.h" // for extern Service g_rgltrSrv, etc. #include "rgltr_services.h" // for extern Service g_rgltrSrv, etc.
// Global service handle // Global service handle
Service g_rgltrSrv; Service g_rgltrSrv;
@@ -33,18 +35,12 @@ void rgltrExit(void) {
serviceClose(&g_rgltrSrv); serviceClose(&g_rgltrSrv);
} }
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id) { Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id) {
const u32 in = (u32)module_id; const u32 in = (u32)module_id;
return serviceDispatchIn( return serviceDispatchIn(&g_rgltrSrv, 0, in, .out_num_objects = 1, .out_objects = &session_out->s);
&g_rgltrSrv,
0,
in,
.out_num_objects = 1,
.out_objects = &session_out->s
);
} }
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) { Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt) {
u32 temp = 0; u32 temp = 0;
Result rc = serviceDispatchOut(&session->s, 4, temp); Result rc = serviceDispatchOut(&session->s, 4, temp);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
@@ -53,14 +49,14 @@ Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
return rc; return rc;
} }
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt) { Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt) {
return serviceDispatchIn(&session->s, 5, microvolt); return serviceDispatchIn(&session->s, 5, microvolt);
} }
Result rgltrCancelVoltageRequest(RgltrSession* session) { Result rgltrCancelVoltageRequest(RgltrSession *session) {
return serviceDispatch(&session->s, 6); return serviceDispatch(&session->s, 6);
} }
void rgltrCloseSession(RgltrSession* session) { void rgltrCloseSession(RgltrSession *session) {
serviceClose(&session->s); serviceClose(&session->s);
} }

View File

@@ -18,15 +18,17 @@
#pragma once #pragma once
#include <switch.h> // for Service, Result, hosversionBefore(), smGetService(), serviceClose(), etc. #include <switch.h> // for Service, Result, hosversionBefore(), smGetService(), serviceClose(), etc.
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
extern Service g_rgltrSrv; extern Service g_rgltrSrv;
Result rgltrInitialize(void); Result rgltrInitialize(void);
void rgltrExit(void); void rgltrExit(void);
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id); Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id);
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt); Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt);
void rgltrCloseSession(RgltrSession* session); void rgltrCloseSession(RgltrSession *session);

View File

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

View File

@@ -24,17 +24,15 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
#include <switch.h> #include <switch.h>
Result i2csessionExtRegReceive(I2cSession* s, u8 in, void* out, u8 out_size); Result i2csessionExtRegReceive(I2cSession *s, u8 in, void *out, u8 out_size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -37,8 +37,12 @@ Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) {
} }
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) { Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
struct { u8 reg; } __attribute__((packed)) cmd; struct {
struct { u8 val; } __attribute__((packed)) rec; u8 reg;
} __attribute__((packed)) cmd;
struct {
u8 val;
} __attribute__((packed)) rec;
I2cSession _session; I2cSession _session;
Result res = i2cOpenSession(&_session, dev); 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) { Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) {
struct { u8 reg; } __attribute__((packed)) cmd; struct {
struct { u16 val; } __attribute__((packed)) rec; u8 reg;
} __attribute__((packed)) cmd;
struct {
u16 val;
} __attribute__((packed)) rec;
I2cSession _session; I2cSession _session;
Result res = i2cOpenSession(&_session, dev); Result res = i2cOpenSession(&_session, dev);
@@ -94,20 +102,20 @@ float I2c_Max17050_GetBatteryCurrent() {
if (res) if (res)
return 0.f; return 0.f;
const float SenseResistor = 5.; // in uOhm const float SenseResistor = 5.; // in uOhm
const float CGain = 1.99993; const float CGain = 1.99993;
return (s16)val * (1.5625 / (SenseResistor * CGain)); return (s16)val * (1.5625 / (SenseResistor * CGain));
} }
u32 I2c_BuckConverter_MultiplierToMvOut(const I2c_BuckConverter_Domain* domain, u8 multiplier) { u32 I2c_BuckConverter_MultiplierToMvOut(const I2c_BuckConverter_Domain *domain, u8 multiplier) {
return (domain->uv_min + domain->uv_step * multiplier) / 1000; return (domain->uv_min + domain->uv_step * multiplier) / 1000;
} }
u32 I2c_BuckConverter_MultiplierToUvOut(const I2c_BuckConverter_Domain* domain, u8 multiplier) { u32 I2c_BuckConverter_MultiplierToUvOut(const I2c_BuckConverter_Domain *domain, u8 multiplier) {
return domain->uv_min + domain->uv_step * multiplier; return domain->uv_min + domain->uv_step * multiplier;
} }
u8 I2c_BuckConverter_MvOutToMultiplier(const I2c_BuckConverter_Domain* domain, u32 mvolt) { u8 I2c_BuckConverter_MvOutToMultiplier(const I2c_BuckConverter_Domain *domain, u32 mvolt) {
u32 uvolt = mvolt * 1000; u32 uvolt = mvolt * 1000;
if (uvolt < domain->uv_min) if (uvolt < domain->uv_min)
uvolt = domain->uv_min; uvolt = domain->uv_min;
@@ -117,7 +125,7 @@ u8 I2c_BuckConverter_MvOutToMultiplier(const I2c_BuckConverter_Domain* domain, u
return (uvolt - domain->uv_min) / domain->uv_step; return (uvolt - domain->uv_min) / domain->uv_step;
} }
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain) { u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain *domain) {
u8 val; u8 val;
// Retry 5 times if received POR value // Retry 5 times if received POR value
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
@@ -133,7 +141,7 @@ u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain) {
return I2c_BuckConverter_MultiplierToMvOut(domain, val & domain->volt_mask); return I2c_BuckConverter_MultiplierToMvOut(domain, val & domain->volt_mask);
} }
u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain* domain) { u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain *domain) {
u8 val; u8 val;
// Retry 5 times if received POR value // Retry 5 times if received POR value
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
@@ -149,7 +157,7 @@ u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain* domain) {
return I2c_BuckConverter_MultiplierToUvOut(domain, val & domain->volt_mask); return I2c_BuckConverter_MultiplierToUvOut(domain, val & domain->volt_mask);
} }
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt) { Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain *domain, u32 mvolt) {
u8 val; u8 val;
Result res = I2cRead_OutU8(domain->device, domain->reg, &val); Result res = I2cRead_OutU8(domain->device, domain->reg, &val);
if (R_FAILED(res)) if (R_FAILED(res))
@@ -179,7 +187,7 @@ u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
// Adjustment is required // Adjustment is required
u8 raw = 0; u8 raw = 0;
if (ma > MA_RANGE_MAX) // capping if (ma > MA_RANGE_MAX) // capping
ma = MA_RANGE_MAX; ma = MA_RANGE_MAX;
bool pct20 = ma <= (MA_RANGE_MIN - 64); bool pct20 = ma <= (MA_RANGE_MIN - 64);
@@ -188,8 +196,8 @@ u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
raw |= 0x1; raw |= 0x1;
} }
ma -= ma % 100; // round to 100 ma -= ma % 100; // round to 100
ma -= (MA_RANGE_MIN - 64); // ceiling ma -= (MA_RANGE_MIN - 64); // ceiling
raw |= (ma >> 6) << 2; raw |= (ma >> 6) << 2;
return raw; return raw;
@@ -223,14 +231,21 @@ Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) {
// Converts mA to the raw value for bits [2:0] of REG00 // Converts mA to the raw value for bits [2:0] of REG00
static u8 I2c_Bq24193_Convert_InputmA_Raw(u32 ma) { static u8 I2c_Bq24193_Convert_InputmA_Raw(u32 ma) {
if (ma <= 100) return 0b000; if (ma <= 100)
if (ma <= 150) return 0b001; return 0b000;
if (ma <= 500) return 0b010; if (ma <= 150)
if (ma <= 900) return 0b011; return 0b001;
if (ma <= 1200) return 0b100; if (ma <= 500)
if (ma <= 1500) return 0b101; return 0b010;
if (ma <= 2000) return 0b110; if (ma <= 900)
return 0b111; // 3000mA max return 0b011;
if (ma <= 1200)
return 0b100;
if (ma <= 1500)
return 0b101;
if (ma <= 2000)
return 0b110;
return 0b111; // 3000mA max
} }
Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) { Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
@@ -239,35 +254,51 @@ Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
return 0; return 0;
u8 raw; u8 raw;
Result res = I2cRead_OutU8(I2cDevice_Bq24193, Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_INPUT_SOURCE_CONTROL_REG, &raw);
BQ24193_INPUT_SOURCE_CONTROL_REG,
&raw);
if (R_FAILED(res)) if (R_FAILED(res))
return res; return res;
raw &= ~0x07; raw &= ~0x07;
raw |= I2c_Bq24193_Convert_InputmA_Raw(ma); raw |= I2c_Bq24193_Convert_InputmA_Raw(ma);
return I2cSet_U8(I2cDevice_Bq24193,BQ24193_INPUT_SOURCE_CONTROL_REG,raw); return I2cSet_U8(I2cDevice_Bq24193, BQ24193_INPUT_SOURCE_CONTROL_REG, raw);
} }
// not used // not used
Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma) { Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma) {
u8 raw; 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)) if (R_FAILED(res))
return res; return res;
switch (raw & 0x07) { switch (raw & 0x07) {
case 0b000: *ma = 100; break; case 0b000:
case 0b001: *ma = 150; break; *ma = 100;
case 0b010: *ma = 500; break; break;
case 0b011: *ma = 900; break; case 0b001:
case 0b100: *ma = 1200; break; *ma = 150;
case 0b101: *ma = 1500; break; break;
case 0b110: *ma = 2000; break; case 0b010:
case 0b111: *ma = 3000; break; *ma = 500;
default: *ma = 0; break; 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; return 0;
} }

View File

@@ -22,12 +22,12 @@ const u8 MAX17050_CURRENT_REG = 0x0A;
// Buck Converter // Buck Converter
typedef enum I2c_BuckConverter_Reg { typedef enum I2c_BuckConverter_Reg {
I2c_Max77620_SD0VOLT_REG = 0x16, I2c_Max77620_SD0VOLT_REG = 0x16,
I2c_Max77620_SD1VOLT_REG = 0x17, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2 I2c_Max77620_SD1VOLT_REG = 0x17, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2
I2c_Max77620_LDO0VOLT_REG = 0x23, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2 I2c_Max77620_LDO0VOLT_REG = 0x23, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2
I2c_Max77621_VOLT_REG = 0x00, I2c_Max77621_VOLT_REG = 0x00,
I2c_Max77812_CPUVOLT_REG = 0x26, I2c_Max77812_CPUVOLT_REG = 0x26,
I2c_Max77812_GPUVOLT_REG = 0x23, I2c_Max77812_GPUVOLT_REG = 0x23,
I2c_Max77812_MEMVOLT_REG = 0x25, // Master 3 (GPU 1 + 2, DRAM 3, CPU 4), used for Mariko VDDQ I2c_Max77812_MEMVOLT_REG = 0x25, // Master 3 (GPU 1 + 2, DRAM 3, CPU 4), used for Mariko VDDQ
} I2c_BuckConverter_Reg; } I2c_BuckConverter_Reg;
typedef struct I2c_BuckConverter_Domain { typedef struct I2c_BuckConverter_Domain {
@@ -40,22 +40,32 @@ typedef struct I2c_BuckConverter_Domain {
u8 por_val; u8 por_val;
} I2c_BuckConverter_Domain; } I2c_BuckConverter_Domain;
const I2c_BuckConverter_Domain I2c_SOC = { I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000, }; const I2c_BuckConverter_Domain I2c_SOC = {
const I2c_BuckConverter_Domain I2c_VDD2 = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000, }; I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000,
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_VDD2 = {
const I2c_BuckConverter_Domain I2c_Erista_GPU = { I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, }; I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000,
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_Display = {
const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDDQ = { I2cDevice_Max77812_2, I2c_Max77812_MEMVOLT_REG, 0xFF, 5000, 250000, 700000, 0x78 }; 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 };
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain); u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain *domain);
u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain* domain); u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain *domain);
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt); Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain *domain, u32 mvolt);
// Bq24193 Battery management // Bq24193 Battery management
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw); u32 I2c_Bq24193_Convert_Raw_mA(u8 raw);
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma); u8 I2c_Bq24193_Convert_mA_Raw(u32 ma);
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma); Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma);
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma); Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma);

View File

@@ -22,15 +22,15 @@
* *
*/ */
#include "max17050.h"
#include "i2c.h" #include "i2c.h"
#include "max17050.h"
#define MAX17050_WAIT_NS 1000000000UL #define MAX17050_WAIT_NS 1000000000UL
#define MAX17050_VCELL 0x09 #define MAX17050_VCELL 0x09
#define MAX17050_Current 0x0A #define MAX17050_Current 0x0A
#define MAX17050_AvgCurrent 0x0B #define MAX17050_AvgCurrent 0x0B
#define MAX17050_AvgVCELL 0x19 #define MAX17050_AvgVCELL 0x19
#define MAX17050_BOARD_CGAIN 2 #define MAX17050_BOARD_CGAIN 2
#define MAX17050_BOARD_SNS_RESISTOR_UOHM 5000 #define MAX17050_BOARD_SNS_RESISTOR_UOHM 5000
@@ -40,15 +40,13 @@ static u64 g_update_ticks = 0;
static s32 g_power_now = 0; static s32 g_power_now = 0;
static s32 g_power_avg = 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; s64 ma, mv;
u16 values[3] = {0}; u16 values[3] = { 0 };
Result rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_VCELL, values, sizeof(values)); Result rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_VCELL, values, sizeof(values));
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc)) {
{
ma = (s16)values[1]; ma = (s16)values[1];
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN); 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; *out_mw_now = ma * mv / 1000000;
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc)) {
{
rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_AvgVCELL, values, sizeof(u16)); rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_AvgVCELL, values, sizeof(u16));
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc)) {
{
ma = (s16)values[2]; ma = (s16)values[2];
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN); 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; return rc;
} }
static void _max17050_update() static void _max17050_update() {
{
u64 ticks = armGetSystemTick(); u64 ticks = armGetSystemTick();
if(armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS) if (armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS) {
{
return; return;
} }
g_update_ticks = ticks; g_update_ticks = ticks;
if(!serviceIsActive(&g_i2c_session.s)) if (!serviceIsActive(&g_i2c_session.s)) {
{
return; return;
} }
_max17050_get_power(&g_power_now, &g_power_avg); _max17050_get_power(&g_power_now, &g_power_avg);
} }
Result max17050Initialize(void) Result max17050Initialize(void) {
{
Result rc = i2cInitialize(); Result rc = i2cInitialize();
if(R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc)) {
{
rc = i2cOpenSession(&g_i2c_session, I2cDevice_Max17050); rc = i2cOpenSession(&g_i2c_session, I2cDevice_Max17050);
} }
return rc; return rc;
} }
void max17050Exit(void) void max17050Exit(void) {
{
i2csessionClose(&g_i2c_session); i2csessionClose(&g_i2c_session);
i2cExit(); i2cExit();
} }
s32 max17050PowerNow(void) s32 max17050PowerNow(void) {
{
_max17050_update(); _max17050_update();
return g_power_now; return g_power_now;
} }
s32 max17050PowerAvg(void) s32 max17050PowerAvg(void) {
{
_max17050_update(); _max17050_update();
return g_power_avg; return g_power_avg;
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -24,55 +24,48 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
#include <switch.h> #include <switch.h>
#define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader)) #define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader))
typedef struct typedef struct {
{
u64 magic; u64 magic;
union union {
{
u64 cmdId; u64 cmdId;
u64 result; u64 result;
}; };
} IpcServerRawHeader; } IpcServerRawHeader;
typedef struct typedef struct {
{
SmServiceName srvName; SmServiceName srvName;
Handle handles[MAX_WAIT_OBJECTS]; Handle handles[MAX_WAIT_OBJECTS];
u32 max; u32 max;
u32 count; u32 count;
} IpcServer; } IpcServer;
typedef struct typedef struct {
{
u64 cmdId; u64 cmdId;
void* ptr; void *ptr;
size_t size; size_t size;
} IpcServerRequestData; } IpcServerRequestData;
typedef struct typedef struct {
{
HipcParsedRequest hipc; HipcParsedRequest hipc;
IpcServerRequestData data; IpcServerRequestData data;
} IpcServerRequest; } IpcServerRequest;
typedef Result (*IpcServerRequestHandler)(void* userdata, const IpcServerRequest* r, u8* out_data, size_t* out_dataSize); typedef Result (*IpcServerRequestHandler)(void *userdata, const IpcServerRequest *r, u8 *out_data, size_t *out_dataSize);
Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions); Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions);
Result ipcServerExit(IpcServer* server); Result ipcServerExit(IpcServer *server);
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata); Result ipcServerProcess(IpcServer *server, IpcServerRequestHandler handler, void *userdata);
Result ipcServerParseCommand(const IpcServerRequest* r, size_t* out_datasize, void** out_data, u64* out_cmd); Result ipcServerParseCommand(const IpcServerRequest *r, size_t *out_datasize, void **out_data, u64 *out_cmd);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -24,21 +24,22 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#include "ipc_service.hpp"
#include <cstring> #include <cstring>
#include <switch.h>
#include "../hos/apm_ext.h"
#include <i2c.h> #include <i2c.h>
#include <t210.h>
#include <max17050.h> #include <max17050.h>
#include <switch.h>
#include <t210.h>
#include <tmp451.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 <ipc_server.h>
#include <lockable_mutex.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 ipcService {
namespace { namespace {
@@ -48,19 +49,19 @@ namespace ipcService {
LockableMutex gThreadMutex; LockableMutex gThreadMutex;
IpcServer gServer; IpcServer gServer;
Result GetApiVersion(u32* out_version) { Result GetApiVersion(u32 *out_version) {
*out_version = HOCCLK_IPC_API_VERSION; *out_version = HOCCLK_IPC_API_VERSION;
return 0; return 0;
} }
Result GetVersionString(char* out_buf, size_t bufSize) { Result GetVersionString(char *out_buf, size_t bufSize) {
if (bufSize) { if (bufSize) {
strncpy(out_buf, TARGET_VERSION, bufSize-1); strncpy(out_buf, TARGET_VERSION, bufSize - 1);
} }
return 0; return 0;
} }
Result GetCurrentContext(HocClkContext* out_ctx) { Result GetCurrentContext(HocClkContext *out_ctx) {
*out_ctx = clockManager::GetCurrentContext(); *out_ctx = clockManager::GetCurrentContext();
return 0; return 0;
} }
@@ -70,7 +71,7 @@ namespace ipcService {
return 0; return 0;
} }
Result GetProfileCount(std::uint64_t* tid, std::uint8_t* out_count) { Result GetProfileCount(std::uint64_t *tid, std::uint8_t *out_count) {
if (!config::HasProfilesLoaded()) { if (!config::HasProfilesLoaded()) {
return HOCCLK_ERROR(ConfigNotLoaded); return HOCCLK_ERROR(ConfigNotLoaded);
} }
@@ -78,7 +79,7 @@ namespace ipcService {
return 0; return 0;
} }
Result GetProfiles(std::uint64_t* tid, HocClkTitleProfileList* out_profiles) { Result GetProfiles(std::uint64_t *tid, HocClkTitleProfileList *out_profiles) {
if (!config::HasProfilesLoaded()) { if (!config::HasProfilesLoaded()) {
return HOCCLK_ERROR(ConfigNotLoaded); return HOCCLK_ERROR(ConfigNotLoaded);
} }
@@ -86,7 +87,7 @@ namespace ipcService {
return 0; return 0;
} }
Result SetProfiles(HocClkIpc_SetProfiles_Args* args) { Result SetProfiles(HocClkIpc_SetProfiles_Args *args) {
if (!config::HasProfilesLoaded()) { if (!config::HasProfilesLoaded()) {
return HOCCLK_ERROR(ConfigNotLoaded); return HOCCLK_ERROR(ConfigNotLoaded);
} }
@@ -97,12 +98,12 @@ namespace ipcService {
return 0; return 0;
} }
Result SetEnabled(std::uint8_t* enabled) { Result SetEnabled(std::uint8_t *enabled) {
config::SetEnabled(*enabled); config::SetEnabled(*enabled);
return 0; return 0;
} }
Result SetOverride(HocClkIpc_SetOverride_Args* args) { Result SetOverride(HocClkIpc_SetOverride_Args *args) {
if (!HOCCLK_ENUM_VALID(HocClkModule, args->module)) { if (!HOCCLK_ENUM_VALID(HocClkModule, args->module)) {
return HOCCLK_ERROR(Generic); return HOCCLK_ERROR(Generic);
} }
@@ -110,7 +111,7 @@ namespace ipcService {
return 0; return 0;
} }
Result GetConfigValuesHandler(HocClkConfigValueList* out_configValues) { Result GetConfigValuesHandler(HocClkConfigValueList *out_configValues) {
if (!config::HasProfilesLoaded()) { if (!config::HasProfilesLoaded()) {
return HOCCLK_ERROR(ConfigNotLoaded); return HOCCLK_ERROR(ConfigNotLoaded);
} }
@@ -118,7 +119,7 @@ namespace ipcService {
return 0; return 0;
} }
Result SetConfigValuesHandler(HocClkConfigValueList* configValues) { Result SetConfigValuesHandler(HocClkConfigValueList *configValues) {
if (!config::HasProfilesLoaded()) { if (!config::HasProfilesLoaded()) {
return HOCCLK_ERROR(ConfigNotLoaded); return HOCCLK_ERROR(ConfigNotLoaded);
} }
@@ -129,30 +130,28 @@ namespace ipcService {
return 0; return 0;
} }
Result GetFreqList(HocClkIpc_GetFreqList_Args* args, std::uint32_t* out_list, std::size_t size, std::uint32_t* out_count) { Result GetFreqList(HocClkIpc_GetFreqList_Args *args, std::uint32_t *out_list, std::size_t size, std::uint32_t *out_count) {
if (!HOCCLK_ENUM_VALID(HocClkModule, args->module)) { if (!HOCCLK_ENUM_VALID(HocClkModule, args->module)) {
return HOCCLK_ERROR(Generic); return HOCCLK_ERROR(Generic);
} }
if (args->maxCount != size/sizeof(*out_list)) { if (args->maxCount != size / sizeof(*out_list)) {
return HOCCLK_ERROR(Generic); return HOCCLK_ERROR(Generic);
} }
clockManager::GetFreqList(args->module, out_list, args->maxCount, out_count); clockManager::GetFreqList(args->module, out_list, args->maxCount, out_count);
return 0; return 0;
} }
Result ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8* out_data, size_t* out_dataSize) { Result ServiceHandlerFunc(void *arg, const IpcServerRequest *r, u8 *out_data, size_t *out_dataSize) {
(void)arg; (void)arg;
switch (r->data.cmdId) { switch (r->data.cmdId) {
case HocClkIpcCmd_GetApiVersion: case HocClkIpcCmd_GetApiVersion:
*out_dataSize = sizeof(u32); *out_dataSize = sizeof(u32);
return GetApiVersion((u32*)out_data); return GetApiVersion((u32 *)out_data);
case HocClkIpcCmd_GetVersionString: case HocClkIpcCmd_GetVersionString:
if (r->hipc.meta.num_recv_buffers >= 1) { if (r->hipc.meta.num_recv_buffers >= 1) {
return GetVersionString( return GetVersionString((char *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
(char*)hipcGetBufferAddress(r->hipc.data.recv_buffers), hipcGetBufferSize(r->hipc.data.recv_buffers));
hipcGetBufferSize(r->hipc.data.recv_buffers)
);
} }
break; break;
@@ -160,7 +159,7 @@ namespace ipcService {
if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) { if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) {
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers); size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
if (bufSize >= sizeof(HocClkContext)) { if (bufSize >= sizeof(HocClkContext)) {
return GetCurrentContext((HocClkContext*)hipcGetBufferAddress(r->hipc.data.recv_buffers)); return GetCurrentContext((HocClkContext *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
} }
} }
break; break;
@@ -171,7 +170,7 @@ namespace ipcService {
case HocClkIpcCmd_GetProfileCount: case HocClkIpcCmd_GetProfileCount:
if (r->data.size >= sizeof(std::uint64_t)) { if (r->data.size >= sizeof(std::uint64_t)) {
*out_dataSize = sizeof(std::uint8_t); *out_dataSize = sizeof(std::uint8_t);
return GetProfileCount((std::uint64_t*)r->data.ptr, (std::uint8_t*)out_data); return GetProfileCount((std::uint64_t *)r->data.ptr, (std::uint8_t *)out_data);
} }
break; break;
@@ -179,26 +178,27 @@ namespace ipcService {
if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) { if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) {
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers); size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
if (bufSize >= sizeof(HocClkTitleProfileList)) { 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; break;
case HocClkIpcCmd_SetProfiles: case HocClkIpcCmd_SetProfiles:
if (r->data.size >= sizeof(HocClkIpc_SetProfiles_Args)) { if (r->data.size >= sizeof(HocClkIpc_SetProfiles_Args)) {
return SetProfiles((HocClkIpc_SetProfiles_Args*)r->data.ptr); return SetProfiles((HocClkIpc_SetProfiles_Args *)r->data.ptr);
} }
break; break;
case HocClkIpcCmd_SetEnabled: case HocClkIpcCmd_SetEnabled:
if (r->data.size >= sizeof(std::uint8_t)) { if (r->data.size >= sizeof(std::uint8_t)) {
return SetEnabled((std::uint8_t*)r->data.ptr); return SetEnabled((std::uint8_t *)r->data.ptr);
} }
break; break;
case HocClkIpcCmd_SetOverride: case HocClkIpcCmd_SetOverride:
if (r->data.size >= sizeof(HocClkIpc_SetOverride_Args)) { if (r->data.size >= sizeof(HocClkIpc_SetOverride_Args)) {
return SetOverride((HocClkIpc_SetOverride_Args*)r->data.ptr); return SetOverride((HocClkIpc_SetOverride_Args *)r->data.ptr);
} }
break; break;
@@ -206,7 +206,7 @@ namespace ipcService {
if (r->hipc.meta.num_recv_buffers >= 1) { if (r->hipc.meta.num_recv_buffers >= 1) {
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers); size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
if (bufSize >= sizeof(HocClkConfigValueList)) { if (bufSize >= sizeof(HocClkConfigValueList)) {
return GetConfigValuesHandler((HocClkConfigValueList*)hipcGetBufferAddress(r->hipc.data.recv_buffers)); return GetConfigValuesHandler((HocClkConfigValueList *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
} }
} }
break; break;
@@ -215,7 +215,7 @@ namespace ipcService {
if (r->hipc.meta.num_send_buffers >= 1) { if (r->hipc.meta.num_send_buffers >= 1) {
size_t bufSize = hipcGetBufferSize(r->hipc.data.send_buffers); size_t bufSize = hipcGetBufferSize(r->hipc.data.send_buffers);
if (bufSize >= sizeof(HocClkConfigValueList)) { if (bufSize >= sizeof(HocClkConfigValueList)) {
return SetConfigValuesHandler((HocClkConfigValueList*)hipcGetBufferAddress(r->hipc.data.send_buffers)); return SetConfigValuesHandler((HocClkConfigValueList *)hipcGetBufferAddress(r->hipc.data.send_buffers));
} }
} }
break; break;
@@ -223,12 +223,9 @@ namespace ipcService {
case HocClkIpcCmd_GetFreqList: case HocClkIpcCmd_GetFreqList:
if (r->data.size >= sizeof(HocClkIpc_GetFreqList_Args) && r->hipc.meta.num_recv_buffers >= 1) { if (r->data.size >= sizeof(HocClkIpc_GetFreqList_Args) && r->hipc.meta.num_recv_buffers >= 1) {
*out_dataSize = sizeof(std::uint32_t); *out_dataSize = sizeof(std::uint32_t);
return GetFreqList( return GetFreqList((HocClkIpc_GetFreqList_Args *)r->data.ptr,
(HocClkIpc_GetFreqList_Args*)r->data.ptr, (std::uint32_t *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
(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; break;
@@ -243,7 +240,7 @@ namespace ipcService {
return HOCCLK_ERROR(Generic); return HOCCLK_ERROR(Generic);
} }
void ProcessThreadFunc(void* arg) { void ProcessThreadFunc(void *arg) {
(void)arg; (void)arg;
Result rc; Result rc;
while (true) { while (true) {
@@ -259,7 +256,7 @@ namespace ipcService {
} }
} }
} } // namespace
void Initialize() { void Initialize() {
std::int32_t priority; std::int32_t priority;
@@ -281,7 +278,7 @@ namespace ipcService {
} }
void SetRunning(bool running) { void SetRunning(bool running) {
std::scoped_lock lock{gThreadMutex}; std::scoped_lock lock{ gThreadMutex };
if (gRunning == running) { if (gRunning == running) {
return; return;
} }
@@ -297,4 +294,4 @@ namespace ipcService {
} }
} }
} } // namespace ipcService

View File

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

View File

@@ -27,115 +27,106 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <malloc.h> #include <malloc.h>
#include <switch.h> #include <switch.h>
#include "board/board.hpp"
#include "file/config.hpp"
#include "file/errors.hpp" #include "file/errors.hpp"
#include "file/file_utils.hpp" #include "file/file_utils.hpp"
#include "board/board.hpp"
#include "hos/process_management.hpp" #include "hos/process_management.hpp"
#include "mgr/clock_manager.hpp"
#include "ipc/ipc_service.hpp" #include "ipc/ipc_service.hpp"
#include "file/config.hpp" #include "mgr/clock_manager.hpp"
#define INNER_HEAP_SIZE 0x40000 #define INNER_HEAP_SIZE 0x40000
extern "C" extern "C" {
{ void virtmemSetup(void);
void virtmemSetup(void);
extern std::uint32_t __start__; extern std::uint32_t __start__;
std::uint32_t __nx_applet_type = AppletType_None; std::uint32_t __nx_applet_type = AppletType_None;
TimeServiceType __nx_time_service_type = TimeServiceType_System; TimeServiceType __nx_time_service_type = TimeServiceType_System;
std::uint32_t __nx_fs_num_sessions = 1; std::uint32_t __nx_fs_num_sessions = 1;
u32 __nx_nv_transfermem_size = 0x8000; u32 __nx_nv_transfermem_size = 0x8000;
size_t nx_inner_heap_size = INNER_HEAP_SIZE; size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE]; char nx_inner_heap[INNER_HEAP_SIZE];
NvServiceType __nx_nv_service_type = NvServiceType_Factory; NvServiceType __nx_nv_service_type = NvServiceType_Factory;
// Ty to MasaGratoR for this! // Ty to MasaGratoR for this!
// This is done to save some space as they have no practical use in our case // This is done to save some space as they have no practical use in our case
void* __real___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)); void *__real___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *));
void* __real__Unwind_Resume(); void *__real__Unwind_Resume();
void* __real___gxx_personality_v0(); void *__real___gxx_personality_v0();
void __wrap___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)) { void __wrap___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)) {
abort(); abort();
}
void __wrap__Unwind_Resume() {
return;
}
void __wrap___gxx_personality_v0() {
return;
}
void __libnx_initheap(void)
{
void* addr = nx_inner_heap;
size_t size = nx_inner_heap_size;
/* Newlib Heap Management */
extern char* fake_heap_start;
extern char* fake_heap_end;
fake_heap_start = (char*)addr;
fake_heap_end = (char*)addr + size;
virtmemSetup();
}
void __appInit(void)
{
if (R_FAILED(smInitialize()))
{
fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
}
Result rc = setsysInitialize();
if (R_SUCCEEDED(rc))
{
SetSysFirmwareVersion fw;
rc = setsysGetFirmwareVersion(&fw);
if (R_SUCCEEDED(rc))
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
setsysExit();
}
// rc = fanInitialize();
// if (R_FAILED(rc))
// diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
rc = i2cInitialize();
if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
}
void __appExit(void)
{
// CloseFanControllerThread();
// fanExit();
i2cExit();
setsysExit();
fsdevUnmountAll();
fsExit();
smExit();
}
} }
int main(int argc, char** argv) void __wrap__Unwind_Resume() {
{ return;
Result rc = fileUtils::Initialize(); }
void __wrap___gxx_personality_v0() {
return;
}
void __libnx_initheap(void) {
void *addr = nx_inner_heap;
size_t size = nx_inner_heap_size;
/* Newlib Heap Management */
extern char *fake_heap_start;
extern char *fake_heap_end;
fake_heap_start = (char *)addr;
fake_heap_end = (char *)addr + size;
virtmemSetup();
}
void __appInit(void) {
if (R_FAILED(smInitialize())) {
fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
}
Result rc = setsysInitialize();
if (R_SUCCEEDED(rc)) {
SetSysFirmwareVersion fw;
rc = setsysGetFirmwareVersion(&fw);
if (R_SUCCEEDED(rc))
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
setsysExit();
}
// rc = fanInitialize();
// if (R_FAILED(rc))
// diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
rc = i2cInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
{ diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
}
void __appExit(void) {
// CloseFanControllerThread();
// fanExit();
i2cExit();
setsysExit();
fsdevUnmountAll();
fsExit();
smExit();
}
}
int main(int argc, char **argv) {
Result rc = fileUtils::Initialize();
if (R_FAILED(rc)) {
fatalThrow(rc); fatalThrow(rc);
return 1; return 1;
} }
config::Initialize(); config::Initialize();
config::Refresh(); // Get config from file config::Refresh(); // Get config from file
board::Initialize(); board::Initialize();
processManagement::Initialize(); processManagement::Initialize();
@@ -145,7 +136,6 @@ int main(int argc, char** argv)
clockManager::Initialize(); clockManager::Initialize();
ipcService::Initialize(); ipcService::Initialize();
clockManager::SetRunning(true); clockManager::SetRunning(true);
config::SetEnabled(true); config::SetEnabled(true);
ipcService::SetRunning(true); ipcService::SetRunning(true);
@@ -154,8 +144,7 @@ int main(int argc, char** argv)
// InitFanController(table); // InitFanController(table);
// StartFanControllerThread(); // StartFanControllerThread();
while (clockManager::Running()) while (clockManager::Running()) {
{
clockManager::Tick(); clockManager::Tick();
clockManager::WaitForNextTick(); clockManager::WaitForNextTick();
} }

View File

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

View File

@@ -18,5 +18,5 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
Result QueryMemoryMapping(u64* virtaddr, u64 physaddr, u64 size); Result QueryMemoryMapping(u64 *virtaddr, u64 physaddr, u64 size);
Result MapAddress(u64 &va, const u64 &physAddr, const char *name); Result MapAddress(u64 &va, const u64 &physAddr, const char *name);

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 <crc32.h>
#include "../file/config.hpp" #include <cstdio>
#include "../hos/integrations.hpp" #include <cstring>
#include "../util/lockable_mutex.h" #include <i2c.h>
#include "../file/kip.hpp"
#include "governor.hpp"
#include "../display/aula.hpp"
#include "../soc/gm20b.hpp"
#define HOSPPC_HAS_BOOST (hosversionAtLeast(7,0,0)) #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 { namespace clockManager {
bool gRunning = false; bool gRunning = false;
LockableMutex gContextMutex; LockableMutex gContextMutex;
HocClkContext gContext = {}; HocClkContext gContext = {};
@@ -59,22 +58,20 @@ namespace clockManager {
std::uint64_t gLastPowerLogNs = 0; std::uint64_t gLastPowerLogNs = 0;
std::uint64_t gLastCsvWriteNs = 0; std::uint64_t gLastCsvWriteNs = 0;
bool IsAssignableHz(HocClkModule module, std::uint32_t hz) bool IsAssignableHz(HocClkModule module, std::uint32_t hz) {
{
switch (module) { switch (module) {
case HocClkModule_CPU: case HocClkModule_CPU:
return hz >= 500000000; return hz >= 500000000;
case HocClkModule_MEM: case HocClkModule_MEM:
return hz >= 665600000; return hz >= 665600000;
default: default:
return true; return true;
} }
} }
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile) std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile) {
{
if (config::GetConfigValue(HocClkConfigValue_UncappedClocks)) { if (config::GetConfigValue(HocClkConfigValue_UncappedClocks)) {
return ~0; // Integer limit, uncapped clocks ON return ~0; // Integer limit, uncapped clocks ON
} else { } else {
if (module == HocClkModule_GPU) { if (module == HocClkModule_GPU) {
if (profile < HocClkProfile_HandheldCharging) { if (profile < HocClkProfile_HandheldCharging) {
@@ -82,7 +79,7 @@ namespace clockManager {
case HocClkSocType_Erista: case HocClkSocType_Erista:
return 460800000; return 460800000;
case HocClkSocType_Mariko: case HocClkSocType_Mariko:
if(board::GetConsoleType() == HocClkConsoleType_Hoag) { if (board::GetConsoleType() == HocClkConsoleType_Hoag) {
switch (config::GetConfigValue(KipConfigValue_marikoGpuUV)) { switch (config::GetConfigValue(KipConfigValue_marikoGpuUV)) {
case 0 ... 2: case 0 ... 2:
return 614400000; return 614400000;
@@ -144,8 +141,7 @@ namespace clockManager {
return 0; 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]; std::uint32_t *freqs = &gFreqTable[module].list[0];
size_t count = gFreqTable[module].count - 1; size_t count = gFreqTable[module].count - 1;
@@ -163,21 +159,20 @@ namespace clockManager {
return freqs[i]; return freqs[i];
} }
void ResetToStockClocks() void ResetToStockClocks() {
{
board::ResetToStockCpu(); board::ResetToStockCpu();
if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) { if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
if (board::GetSocType() == HocClkSocType_Erista) if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
else 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(); 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; std::uint64_t logInterval = config::GetConfigValue(intervalMsConfigValue) * 1000000ULL;
bool shouldLog = logInterval && ((ns - *lastLogNs) > logInterval); bool shouldLog = logInterval && ((ns - *lastLogNs) > logInterval);
@@ -188,9 +183,8 @@ namespace clockManager {
return shouldLog; return shouldLog;
} }
void RefreshFreqTableRow(HocClkModule module) void RefreshFreqTableRow(HocClkModule module) {
{ std::scoped_lock lock{ gContextMutex };
std::scoped_lock lock{gContextMutex};
std::uint32_t freqs[HOCCLK_FREQ_LIST_MAX]; std::uint32_t freqs[HOCCLK_FREQ_LIST_MAX];
std::uint32_t count; std::uint32_t count;
@@ -201,15 +195,16 @@ namespace clockManager {
std::uint32_t *hz = &gFreqTable[module].list[0]; std::uint32_t *hz = &gFreqTable[module].list[0];
gFreqTable[module].count = 0; gFreqTable[module].count = 0;
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko &&
&& config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) { config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) {
constexpr u32 kStep = 38400000; constexpr u32 kStep = 38400000;
constexpr u32 kPcvStep = 76800000; constexpr u32 kPcvStep = 76800000;
u32 kMax = ~0; u32 kMax = ~0;
for (u32 i = 0; i < count; i++) { for (u32 i = 0; i < count; i++) {
for (u32 j = 0; j < count; j++) { for (u32 j = 0; j < count; j++) {
if (freqs[j] + kStep == freqs[i]) { if (freqs[j] + kStep == freqs[i]) {
if (freqs[j] < kMax) kMax = freqs[j]; if (freqs[j] < kMax)
kMax = freqs[j];
break; break;
} }
} }
@@ -217,7 +212,8 @@ namespace clockManager {
if (kMax == ~0u) { if (kMax == ~0u) {
kMax = 0; kMax = 0;
for (u32 i = 0; i < count; i++) { for (u32 i = 0; i < count; i++) {
if (freqs[i] > kMax) kMax = freqs[i]; if (freqs[i] > kMax)
kMax = freqs[i];
} }
} }
@@ -264,36 +260,23 @@ namespace clockManager {
u32 hz; u32 hz;
HocClkConfigValue kval; HocClkConfigValue kval;
} eristaGpuVoltMap[] = { } eristaGpuVoltMap[] = {
{ 76800000, KipConfigValue_g_volt_e_76800 }, { 76800000, KipConfigValue_g_volt_e_76800 }, { 115200000, KipConfigValue_g_volt_e_115200 },
{ 115200000, KipConfigValue_g_volt_e_115200 }, { 153600000, KipConfigValue_g_volt_e_153600 }, { 192000000, KipConfigValue_g_volt_e_192000 },
{ 153600000, KipConfigValue_g_volt_e_153600 }, { 230400000, KipConfigValue_g_volt_e_230400 }, { 268800000, KipConfigValue_g_volt_e_268800 },
{ 192000000, KipConfigValue_g_volt_e_192000 }, { 307200000, KipConfigValue_g_volt_e_307200 }, { 345600000, KipConfigValue_g_volt_e_345600 },
{ 230400000, KipConfigValue_g_volt_e_230400 }, { 384000000, KipConfigValue_g_volt_e_384000 }, { 422400000, KipConfigValue_g_volt_e_422400 },
{ 268800000, KipConfigValue_g_volt_e_268800 }, { 460800000, KipConfigValue_g_volt_e_460800 }, { 499200000, KipConfigValue_g_volt_e_499200 },
{ 307200000, KipConfigValue_g_volt_e_307200 }, { 537600000, KipConfigValue_g_volt_e_537600 }, { 576000000, KipConfigValue_g_volt_e_576000 },
{ 345600000, KipConfigValue_g_volt_e_345600 }, { 614400000, KipConfigValue_g_volt_e_614400 }, { 652800000, KipConfigValue_g_volt_e_652800 },
{ 384000000, KipConfigValue_g_volt_e_384000 }, { 691200000, KipConfigValue_g_volt_e_691200 }, { 729600000, KipConfigValue_g_volt_e_729600 },
{ 422400000, KipConfigValue_g_volt_e_422400 }, { 768000000, KipConfigValue_g_volt_e_768000 }, { 806400000, KipConfigValue_g_volt_e_806400 },
{ 460800000, KipConfigValue_g_volt_e_460800 }, { 844800000, KipConfigValue_g_volt_e_844800 }, { 883200000, KipConfigValue_g_volt_e_883200 },
{ 499200000, KipConfigValue_g_volt_e_499200 }, { 921600000, KipConfigValue_g_volt_e_921600 }, { 960000000, KipConfigValue_g_volt_e_960000 },
{ 537600000, KipConfigValue_g_volt_e_537600 }, { 998400000, KipConfigValue_g_volt_e_998400 }, { 1036800000, KipConfigValue_g_volt_e_1036800 },
{ 576000000, KipConfigValue_g_volt_e_576000 }, { 1075200000, KipConfigValue_g_volt_e_1075200 },
{ 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; bool skip = false;
for (auto& entry : eristaGpuVoltMap) { for (auto &entry : eristaGpuVoltMap) {
if (entry.hz == freqs[i]) { if (entry.hz == freqs[i]) {
if (config::GetConfigValue(entry.kval) == 2000) { if (config::GetConfigValue(entry.kval) == 2000) {
skip = true; skip = true;
@@ -301,7 +284,8 @@ namespace clockManager {
break; break;
} }
} }
if (skip) continue; if (skip)
continue;
} }
*hz = freqs[i]; *hz = freqs[i];
@@ -314,14 +298,15 @@ namespace clockManager {
fileUtils::LogLine("[mgr] count = %u", gFreqTable[module].count); fileUtils::LogLine("[mgr] count = %u", gFreqTable[module].count);
} }
bool HandleSafetyFeatures(bool isBoost) bool HandleSafetyFeatures(bool isBoost) {
{ if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) &&
if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) && config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) { config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
ResetToStockClocks(); ResetToStockClocks();
return true; 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 ramHz = gContext.freqs[HocClkModule_MEM];
u32 threshold = (u32)config::GetConfigValue(HocClkConfigValue_AutoRamCpuRamOCThreshold) * 1000; u32 threshold = (u32)config::GetConfigValue(HocClkConfigValue_AutoRamCpuRamOCThreshold) * 1000;
if (ramHz >= threshold) { if (ramHz >= threshold) {
@@ -339,31 +324,30 @@ namespace clockManager {
} }
return false; return false;
} }
void HandleMiscFeatures() void HandleMiscFeatures() {
{
// these dont need to run that often, so dont bother // these dont need to run that often, so dont bother
static u32 tick = 0; static u32 tick = 0;
if(++tick > 10) { if (++tick > 10) {
tick = 0; tick = 0;
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) { if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)); I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
} }
if (config::GetConfigValue(HocClkConfigValue_InputCurrentLimit)) { if (config::GetConfigValue(HocClkConfigValue_InputCurrentLimit)) {
I2c_Bq24193_SetInputCurrentLimit(config::GetConfigValue(HocClkConfigValue_InputCurrentLimit)); I2c_Bq24193_SetInputCurrentLimit(config::GetConfigValue(HocClkConfigValue_InputCurrentLimit));
} }
I2c_BuckConverter_SetMvOut(&I2c_Display, config::GetConfigValue(HocClkConfigValue_DisplayVoltage)); I2c_BuckConverter_SetMvOut(&I2c_Display, config::GetConfigValue(HocClkConfigValue_DisplayVoltage));
if(board::GetConsoleType() == HocClkConsoleType_Aula) if (board::GetConsoleType() == HocClkConsoleType_Aula)
AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset)); AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset));
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) { if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
board::HandleCpuUv(); board::HandleCpuUv();
}
} }
} }
}
void ApplyGpuDvfs(u32 targetHz) { void ApplyGpuDvfs(u32 targetHz) {
s32 dvfsOffset = config::GetConfigValue(HocClkConfigValue_DVFSOffset); s32 dvfsOffset = config::GetConfigValue(HocClkConfigValue_DVFSOffset);
@@ -394,11 +378,9 @@ namespace clockManager {
} }
} }
void DVFSReset() {
void DVFSReset()
{
if (config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) { if (config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) {
board::PcvHijackGpuVolts(0); // Reset to vMin board::PcvHijackGpuVolts(0); // Reset to vMin
u32 targetHz = gContext.overrideFreqs[HocClkModule_GPU]; u32 targetHz = gContext.overrideFreqs[HocClkModule_GPU];
if (!targetHz) { if (!targetHz) {
@@ -416,8 +398,7 @@ namespace clockManager {
} }
} }
void HandleFreqReset(HocClkModule module, bool isBoost, bool didHijackPcv) void HandleFreqReset(HocClkModule module, bool isBoost, bool didHijackPcv) {
{
switch (module) { switch (module) {
case HocClkModule_CPU: case HocClkModule_CPU:
if (!(isBoost || (config::GetConfigValue(HocClkConfigValue_OverwriteBoostMode) && isBoost))) if (!(isBoost || (config::GetConfigValue(HocClkConfigValue_OverwriteBoostMode) && isBoost)))
@@ -426,7 +407,9 @@ namespace clockManager {
if (board::GetSocType() == HocClkSocType_Erista) if (board::GetSocType() == HocClkSocType_Erista)
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
else 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; break;
case HocClkModule_GPU: case HocClkModule_GPU:
@@ -434,7 +417,7 @@ namespace clockManager {
break; break;
case HocClkModule_MEM: case HocClkModule_MEM:
board::ResetToStockMem(); board::ResetToStockMem();
if(!didHijackPcv) { if (!didHijackPcv) {
DVFSReset(); DVFSReset();
didHijackPcv = true; didHijackPcv = true;
} }
@@ -449,8 +432,7 @@ namespace clockManager {
} }
} }
void SetClocks(bool isBoost) void SetClocks(bool isBoost) {
{
std::uint32_t targetHz = 0; std::uint32_t targetHz = 0;
std::uint32_t maxHz = 0; std::uint32_t maxHz = 0;
std::uint32_t nearestHz = 0; std::uint32_t nearestHz = 0;
@@ -461,16 +443,16 @@ namespace clockManager {
if (skipCpuDueToBoost) { if (skipCpuDueToBoost) {
board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU)); board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU));
prepareBoostExit = true; prepareBoostExit = true;
return; // Return if we aren't overwriting boost mode return; // Return if we aren't overwriting boost mode
} }
if (prepareBoostExit) { if (prepareBoostExit) {
board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU)); board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU));
prepareBoostExit = false; prepareBoostExit = false;
} }
bool returnRaw = false; // Return a value scaled to MHz instead of raw value bool returnRaw = false; // Return a value scaled to MHz instead of raw value
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
u32 oldHz = board::GetHz((HocClkModule)module); // Get Old hz (used primarily for DVFS Logic) u32 oldHz = board::GetHz((HocClkModule)module); // Get Old hz (used primarily for DVFS Logic)
if (module > HocClkModule_MEM) if (module > HocClkModule_MEM)
returnRaw = true; returnRaw = true;
@@ -521,12 +503,9 @@ namespace clockManager {
nearestHz = GetNearestHz((HocClkModule)module, targetHz, maxHz); nearestHz = GetNearestHz((HocClkModule)module, targetHz, maxHz);
if (nearestHz != gContext.freqs[module]) { if (nearestHz != gContext.freqs[module]) {
fileUtils::LogLine( fileUtils::LogLine("[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", board::GetModuleName((HocClkModule)module, true),
"[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10, targetHz / 1000000,
board::GetModuleName((HocClkModule)module, true), targetHz / 100000 - targetHz / 1000000 * 10);
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 // 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) { if (module == HocClkModule_MEM && targetHz > oldHz && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) {
@@ -544,7 +523,7 @@ namespace clockManager {
ApplyGpuDvfs(targetHz); ApplyGpuDvfs(targetHz);
} }
if(module == HocClkModule_MEM && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) if (module == HocClkModule_MEM && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack)
didHijackPcv = false; didHijackPcv = false;
} }
} else { } else {
@@ -553,8 +532,7 @@ namespace clockManager {
} }
} }
bool RefreshContext() bool RefreshContext() {
{
bool hasChanged = false; bool hasChanged = false;
std::uint32_t mode = 0; std::uint32_t mode = 0;
@@ -589,7 +567,8 @@ namespace clockManager {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
hz = board::GetHz((HocClkModule)module); hz = board::GetHz((HocClkModule)module);
if (hz != 0 && hz != gContext.freqs[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; gContext.freqs[module] = hz;
if (module < HocClkModuleStable_EnumMax) { if (module < HocClkModuleStable_EnumMax) {
@@ -601,7 +580,8 @@ namespace clockManager {
hz = config::GetOverrideHz((HocClkModule)module); hz = config::GetOverrideHz((HocClkModule)module);
if (hz != gContext.overrideFreqs[module]) { if (hz != gContext.overrideFreqs[module]) {
if (hz) { 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; gContext.overrideFreqs[module] = hz;
@@ -620,7 +600,8 @@ namespace clockManager {
for (unsigned int sensor = 0; sensor < HocClkThermalSensor_EnumMax; sensor++) { for (unsigned int sensor = 0; sensor < HocClkThermalSensor_EnumMax; sensor++) {
millis = board::GetTemperatureMilli((HocClkThermalSensor)sensor); millis = board::GetTemperatureMilli((HocClkThermalSensor)sensor);
if (shouldLogTemp) { 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; gContext.temps[sensor] = millis;
@@ -650,7 +631,8 @@ namespace clockManager {
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) { for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
realHz = board::GetRealHz((HocClkModule)module); realHz = board::GetRealHz((HocClkModule)module);
if (shouldLogFreq) { 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; gContext.realFreqs[module] = realHz;
@@ -694,18 +676,17 @@ namespace clockManager {
if (gContext.isSaltyNXInstalled) if (gContext.isSaltyNXInstalled)
gContext.fps = integrations::GetSaltyNXFPS(); gContext.fps = integrations::GetSaltyNXFPS();
else else
gContext.fps = 254; // N/A gContext.fps = 254; // N/A
if (gContext.isSaltyNXInstalled) if (gContext.isSaltyNXInstalled)
gContext.resolutionHeight = integrations::GetSaltyNXResolutionHeight(); gContext.resolutionHeight = integrations::GetSaltyNXResolutionHeight();
else else
gContext.resolutionHeight = 0; // N/A gContext.resolutionHeight = 0; // N/A
return hasChanged; return hasChanged;
} }
void Initialize() void Initialize() {
{
gContext = {}; gContext = {};
gContext.applicationId = 0; gContext.applicationId = 0;
gContext.profile = HocClkProfile_Handheld; gContext.profile = HocClkProfile_Handheld;
@@ -744,7 +725,8 @@ namespace clockManager {
gContext.isDram8GB = board::IsDram8GB(); gContext.isDram8GB = board::IsDram8GB();
gContext.consoleType = board::GetConsoleType(); 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.gpuSchedulingMode = (GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling);
gContext.isSysDockInstalled = integrations::GetSysDockState(); gContext.isSysDockInstalled = integrations::GetSysDockState();
@@ -757,38 +739,32 @@ namespace clockManager {
governor::startThreads(); governor::startThreads();
} }
void Exit() void Exit() {
{
governor::exitThreads(); governor::exitThreads();
} }
HocClkContext GetCurrentContext() HocClkContext GetCurrentContext() {
{ std::scoped_lock lock{ gContextMutex };
std::scoped_lock lock{gContextMutex};
return gContext; return gContext;
} }
void SetRunning(bool running) void SetRunning(bool running) {
{
gRunning = running; gRunning = running;
} }
bool Running() bool Running() {
{
return gRunning; 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); ASSERT_ENUM_VALID(HocClkModule, module);
*outCount = std::min(maxCount, gFreqTable[module].count); *outCount = std::min(maxCount, gFreqTable[module].count);
memcpy(list, &gFreqTable[module].list[0], *outCount * sizeof(gFreqTable[0].list[0])); memcpy(list, &gFreqTable[module].list[0], *outCount * sizeof(gFreqTable[0].list[0]));
} }
void Tick() void Tick() {
{ std::scoped_lock lock{ gContextMutex };
std::scoped_lock lock{gContextMutex};
std::uint32_t mode = 0; std::uint32_t mode = 0;
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode); Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration"); ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
@@ -799,16 +775,16 @@ namespace clockManager {
HandleMiscFeatures(); HandleMiscFeatures();
// GPU clock should always be the same unless PCV has overwriten our change, so reset it // 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); SetClocks(isBoost);
} }
} }
void WaitForNextTick() void WaitForNextTick() {
{
if (board::GetHz(HocClkModule_MEM) > 665000000) if (board::GetHz(HocClkModule_MEM) > 665000000)
svcSleepThread(config::GetConfigValue(HocClkConfigValue_PollingIntervalMs) * 1000000ULL); svcSleepThread(config::GetConfigValue(HocClkConfigValue_PollingIntervalMs) * 1000000ULL);
else else
svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode
} }
} // namespace clockManager } // namespace clockManager

View File

@@ -28,6 +28,7 @@
#include <hocclk.h> #include <hocclk.h>
#include <switch.h> #include <switch.h>
#include "../util/lockable_mutex.h" #include "../util/lockable_mutex.h"
namespace clockManager { namespace clockManager {
@@ -37,7 +38,6 @@ namespace clockManager {
std::uint32_t list[HOCCLK_FREQ_LIST_MAX]; std::uint32_t list[HOCCLK_FREQ_LIST_MAX];
}; };
extern bool hasChanged; extern bool hasChanged;
// instance variables // instance variables
@@ -50,7 +50,6 @@ namespace clockManager {
extern std::uint64_t gLastPowerLogNs; extern std::uint64_t gLastPowerLogNs;
extern std::uint64_t gLastCsvWriteNs; extern std::uint64_t gLastCsvWriteNs;
void Initialize(); void Initialize();
void Exit(); void Exit();
@@ -62,8 +61,8 @@ namespace clockManager {
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile); std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile);
bool IsAssignableHz(HocClkModule module, std::uint32_t hz); bool IsAssignableHz(HocClkModule module, std::uint32_t hz);
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);
void Tick(); void Tick();
void WaitForNextTick(); void WaitForNextTick();
} } // namespace clockManager

View File

@@ -15,14 +15,15 @@
* *
*/ */
#include "governor.hpp"
#include "../hos/process_management.hpp" #include "../hos/process_management.hpp"
#include "governor.hpp"
#include <hocclk/clock_manager.h> #include <hocclk/clock_manager.h>
namespace governor { namespace governor {
#define POLL_NS 5'000'000 // 5 ms governor poll rate #define POLL_NS 5'000'000 // 5 ms governor poll rate
#define DOWN_HOLD_TICKS 10 // 50 ms how long to in POLL_NS to hold while ramping down #define DOWN_HOLD_TICKS 10 // 50 ms how long to in POLL_NS to hold while ramping down
#define STEP_UTIL 900 // multiplier for step calculations #define STEP_UTIL 900 // multiplier for step calculations
bool isGpuGovernorEnabled = false; bool isGpuGovernorEnabled = false;
bool isCpuGovernorEnabled = false; bool isCpuGovernorEnabled = false;
@@ -44,8 +45,10 @@ namespace governor {
} }
auto resolve = [](u8 app, u8 temp) -> u8 { auto resolve = [](u8 app, u8 temp) -> u8 {
if (temp == ComponentGovernor_Disabled) return ComponentGovernor_Disabled; if (temp == ComponentGovernor_Disabled)
if (temp != ComponentGovernor_DoNotOverride) return temp; return ComponentGovernor_Disabled;
if (temp != ComponentGovernor_DoNotOverride)
return temp;
return app; return app;
}; };
@@ -68,8 +71,10 @@ namespace governor {
if (newVrrGovernorState == false && lastVrrGovernorState == true) if (newVrrGovernorState == false && lastVrrGovernorState == true)
board::ResetToStockDisplay(); board::ResetToStockDisplay();
if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState || newVrrGovernorState != lastVrrGovernorState) { if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState ||
fileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled", newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled"); 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; lastCpuGovernorState = newCpuGovernorState;
lastGpuGovernorState = newGpuGovernorState; lastGpuGovernorState = newGpuGovernorState;
lastVrrGovernorState = newVrrGovernorState; lastVrrGovernorState = newVrrGovernorState;
@@ -81,7 +86,7 @@ namespace governor {
return (u32)(std::min(hz, static_cast<u64>(tableMaxHz))); return (u32)(std::min(hz, static_cast<u64>(tableMaxHz)));
} }
u32 TableIndexForHz(const clockManager::FreqTable& table, u32 targetHz) { u32 TableIndexForHz(const clockManager::FreqTable &table, u32 targetHz) {
for (u32 i = 0; i < table.count; i++) for (u32 i = 0; i < table.count; i++)
if (table.list[i] >= targetHz) if (table.list[i] >= targetHz)
return i; return i;
@@ -91,17 +96,13 @@ namespace governor {
u32 ResolveTargetHz(HocClkModule module) { u32 ResolveTargetHz(HocClkModule module) {
u32 hz = clockManager::gContext.overrideFreqs[module]; u32 hz = clockManager::gContext.overrideFreqs[module];
if (!hz) if (!hz)
hz = config::GetAutoClockHz( hz = config::GetAutoClockHz(clockManager::gContext.applicationId, module, clockManager::gContext.profile, false);
clockManager::gContext.applicationId, module,
clockManager::gContext.profile, false);
if (!hz) if (!hz)
hz = config::GetAutoClockHz( hz = config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, module, clockManager::gContext.profile, false);
HOCCLK_GLOBAL_PROFILE_TID, module,
clockManager::gContext.profile, false);
return hz; return hz;
} }
void GovernorThread(void* arg) { void GovernorThread(void *arg) {
(void)arg; (void)arg;
u32 cpuDownHoldRemaining = 0; u32 cpuDownHoldRemaining = 0;
@@ -135,8 +136,8 @@ namespace governor {
} else { } else {
isCpuGovernorInBoostMode = false; isCpuGovernorInBoostMode = false;
auto& table = clockManager::gFreqTable[HocClkModule_CPU]; auto &table = clockManager::gFreqTable[HocClkModule_CPU];
std::scoped_lock lock{clockManager::gContextMutex}; std::scoped_lock lock{ clockManager::gContextMutex };
u32 cpuLoad = board::GetPartLoad(HocClkPartLoad_CPUMax); u32 cpuLoad = board::GetPartLoad(HocClkPartLoad_CPUMax);
u32 tableMaxHz = table.list[table.count - 1]; u32 tableMaxHz = table.list[table.count - 1];
@@ -146,7 +147,7 @@ namespace governor {
if (targetHz && desiredHz > targetHz) if (targetHz && desiredHz > targetHz)
desiredHz = targetHz; desiredHz = targetHz;
if (maxHz && desiredHz > maxHz) if (maxHz && desiredHz > maxHz)
desiredHz = maxHz; desiredHz = maxHz;
u32 newHz = table.list[TableIndexForHz(table, desiredHz)]; u32 newHz = table.list[TableIndexForHz(table, desiredHz)];
@@ -191,8 +192,8 @@ namespace governor {
} }
if (isGpuGovernorEnabled) { if (isGpuGovernorEnabled) {
auto& table = clockManager::gFreqTable[HocClkModule_GPU]; auto &table = clockManager::gFreqTable[HocClkModule_GPU];
std::scoped_lock lock{clockManager::gContextMutex}; std::scoped_lock lock{ clockManager::gContextMutex };
u32 gpuLoad = board::GetPartLoad(HocClkPartLoad_GPU); u32 gpuLoad = board::GetPartLoad(HocClkPartLoad_GPU);
u32 tableMaxHz = table.list[table.count - 1]; u32 tableMaxHz = table.list[table.count - 1];
@@ -202,7 +203,7 @@ namespace governor {
if (targetHz && desiredHz > targetHz) if (targetHz && desiredHz > targetHz)
desiredHz = targetHz; desiredHz = targetHz;
if (maxHz && desiredHz > maxHz) if (maxHz && desiredHz > maxHz)
desiredHz = maxHz; desiredHz = maxHz;
u32 newHz = table.list[TableIndexForHz(table, desiredHz)]; u32 newHz = table.list[TableIndexForHz(table, desiredHz)];
@@ -244,13 +245,15 @@ namespace governor {
u8 fps = integrations::GetSaltyNXFPS(); u8 fps = integrations::GetSaltyNXFPS();
if (fps != 254) { if (fps != 254) {
std::scoped_lock lock{clockManager::gContextMutex}; std::scoped_lock lock{ clockManager::gContextMutex };
u32 targetHz = clockManager::gContext.overrideFreqs[HocClkModule_Display]; u32 targetHz = clockManager::gContext.overrideFreqs[HocClkModule_Display];
if (!targetHz) { 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) 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; u8 maxDisplay = targetHz ? (u8)targetHz : 60;
@@ -292,19 +295,11 @@ namespace governor {
} }
void startThreads() { void startThreads() {
threadCreate( threadCreate(&governorTHREAD, GovernorThread, nullptr, NULL, 0x2000, 0x3F, -2);
&governorTHREAD,
GovernorThread,
nullptr,
NULL,
0x2000,
0x3F,
-2
);
threadStart(&governorTHREAD); threadStart(&governorTHREAD);
} }
void exitThreads() { void exitThreads() {
threadClose(&governorTHREAD); 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 <cstring>
#include "../file/file_utils.hpp" #include <hocclk.h>
#include <switch.h>
#include "../board/board.hpp" #include "../board/board.hpp"
#include "../file/errors.hpp"
#include "../file/config.hpp" #include "../file/config.hpp"
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "../hos/integrations.hpp" #include "../hos/integrations.hpp"
#include "../util/lockable_mutex.h" #include "../util/lockable_mutex.h"
#include "clock_manager.hpp"
namespace governor { namespace governor {
extern bool isCpuGovernorInBoostMode; extern bool isCpuGovernorInBoostMode;
@@ -38,4 +39,4 @@ namespace governor {
void startThreads(); void startThreads();
void exitThreads(); void exitThreads();
void HandleGovernor(uint32_t targetHz); void HandleGovernor(uint32_t targetHz);
} } // namespace governor

View File

@@ -15,39 +15,26 @@
* *
*/ */
#include <switch.h>
#include <cstring> #include <cstring>
#include <switch.h>
#include "battery.h" #include "battery.h"
// Internal PSM service handle // Internal PSM service handle
static Service g_psmService = {0}; static Service g_psmService = { 0 };
static bool g_batteryInfoInitialized = false; static bool g_batteryInfoInitialized = false;
static const char* s_chargerTypeStrings[] = { static const char *s_chargerTypeStrings[] = {
"None", "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",
"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[] = { static const char *s_powerRoleStrings[] = {
"Unknown", "Unknown",
"Sink", "Sink",
"Source", "Source",
}; };
static const char* s_pdStateStrings[] = { static const char *s_pdStateStrings[] = { "Unknown", "New PDO Received", "No PD Source", "RDO Accepted" };
"Unknown",
"New PDO Received",
"No PD Source",
"RDO Accepted"
};
// Internal PSM command implementations // Internal PSM command implementations
static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) { static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) {
@@ -143,21 +130,21 @@ Result batteryInfoDisableFastCharging(void) {
return psmDisableFastBatteryCharging_internal(); return psmDisableFastBatteryCharging_internal();
} }
const char* batteryInfoGetChargerTypeString(BatteryChargerType type) { const char *batteryInfoGetChargerTypeString(BatteryChargerType type) {
if (type < 0 || type > ChargerType_Apple_2000mA) if (type < 0 || type > ChargerType_Apple_2000mA)
return "Unknown"; return "Unknown";
return s_chargerTypeStrings[type]; return s_chargerTypeStrings[type];
} }
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role) { const char *batteryInfoGetPowerRoleString(BatteryPowerRole role) {
if (role < PowerRole_Sink || role > PowerRole_Source) if (role < PowerRole_Sink || role > PowerRole_Source)
return s_powerRoleStrings[0]; return s_powerRoleStrings[0];
return s_powerRoleStrings[role]; return s_powerRoleStrings[role];
} }
const char* batteryInfoGetPDStateString(BatteryPDControllerState state) { const char *batteryInfoGetPDStateString(BatteryPDControllerState state) {
if (state < PDState_NewPDO || state > PDState_AcceptedRDO) if (state < PDState_NewPDO || state > PDState_AcceptedRDO)
return s_pdStateStrings[0]; return s_pdStateStrings[0];

View File

@@ -16,57 +16,57 @@
*/ */
#pragma once #pragma once
#include <switch.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <switch.h>
typedef enum { typedef enum {
BatteryFlag_NoHub = BIT(0), // Hub is disconnected BatteryFlag_NoHub = BIT(0), // Hub is disconnected
BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail
BatteryFlag_SPDSRC = BIT(12), // OTG BatteryFlag_SPDSRC = BIT(12), // OTG
BatteryFlag_ACC = BIT(16) // Accessory BatteryFlag_ACC = BIT(16) // Accessory
} BatteryChargeFlags; } BatteryChargeFlags;
typedef enum { typedef enum {
PDState_NewPDO = 1, // Received new Power Data Object PDState_NewPDO = 1, // Received new Power Data Object
PDState_NoPD = 2, // No Power Delivery source is detected PDState_NoPD = 2, // No Power Delivery source is detected
PDState_AcceptedRDO = 3 // Received and accepted Request Data Object PDState_AcceptedRDO = 3 // Received and accepted Request Data Object
} BatteryPDControllerState; } BatteryPDControllerState;
// Charger type detection // Charger type detection
typedef enum { typedef enum {
ChargerType_None = 0, ChargerType_None = 0,
ChargerType_PD = 1, ChargerType_PD = 1,
ChargerType_TypeC_1500mA = 2, ChargerType_TypeC_1500mA = 2,
ChargerType_TypeC_3000mA = 3, ChargerType_TypeC_3000mA = 3,
ChargerType_DCP = 4, // Dedicated Charging Port ChargerType_DCP = 4, // Dedicated Charging Port
ChargerType_CDP = 5, // Charging Downstream Port ChargerType_CDP = 5, // Charging Downstream Port
ChargerType_SDP = 6, // Standard Downstream Port ChargerType_SDP = 6, // Standard Downstream Port
ChargerType_Apple_500mA = 7, ChargerType_Apple_500mA = 7,
ChargerType_Apple_1000mA = 8, ChargerType_Apple_1000mA = 8,
ChargerType_Apple_2000mA = 9 ChargerType_Apple_2000mA = 9
} BatteryChargerType; } BatteryChargerType;
typedef enum { typedef enum {
PowerRole_Sink = 1, // Device is receiving power PowerRole_Sink = 1, // Device is receiving power
PowerRole_Source = 2 // Device is providing power PowerRole_Source = 2 // Device is providing power
} BatteryPowerRole; } BatteryPowerRole;
typedef struct { typedef struct {
int32_t InputCurrentLimit; // Input (Sink) current limit in mA int32_t InputCurrentLimit; // Input (Sink) current limit in mA
int32_t VBUSCurrentLimit; // Output (Source/VBUS/OTG) current limit in mA int32_t VBUSCurrentLimit; // Output (Source/VBUS/OTG) current limit in mA
int32_t ChargeCurrentLimit; // Battery charging current limit in mA int32_t ChargeCurrentLimit; // Battery charging current limit in mA
int32_t ChargeVoltageLimit; // Battery charging voltage limit in mV int32_t ChargeVoltageLimit; // Battery charging voltage limit in mV
int32_t unk_x10; // Unknown field (possibly enum) int32_t unk_x10; // Unknown field (possibly enum)
int32_t unk_x14; // Unknown field (possibly flags) int32_t unk_x14; // Unknown field (possibly flags)
BatteryPDControllerState PDControllerState; // PD Controller State BatteryPDControllerState PDControllerState; // PD Controller State
int32_t BatteryTemperature; // Battery temperature in milli-Celsius int32_t BatteryTemperature; // Battery temperature in milli-Celsius
int32_t RawBatteryCharge; // Battery charge in percentmille int32_t RawBatteryCharge; // Battery charge in percentmille
int32_t VoltageAvg; // Average voltage in mV int32_t VoltageAvg; // Average voltage in mV
int32_t BatteryAge; // Battery health (capacity full/design) in pcm int32_t BatteryAge; // Battery health (capacity full/design) in pcm
BatteryPowerRole PowerRole; // Current power role BatteryPowerRole PowerRole; // Current power role
BatteryChargerType ChargerType; // Type of charger connected BatteryChargerType ChargerType; // Type of charger connected
int32_t ChargerVoltageLimit; // Charger voltage limit in mV int32_t ChargerVoltageLimit; // Charger voltage limit in mV
int32_t ChargerCurrentLimit; // Charger current limit in mA int32_t ChargerCurrentLimit; // Charger current limit in mA
BatteryChargeFlags Flags; // Various status flags BatteryChargeFlags Flags; // Various status flags
} BatteryChargeInfo; } BatteryChargeInfo;
#define IS_BATTERY_CHARGING_ENABLED(info) (((info)->unk_x14 >> 8) & 1) #define IS_BATTERY_CHARGING_ENABLED(info) (((info)->unk_x14 >> 8) & 1)
@@ -96,6 +96,6 @@ Result batteryInfoEnableCharging(void);
Result batteryInfoDisableCharging(void); Result batteryInfoDisableCharging(void);
Result batteryInfoEnableFastCharging(void); Result batteryInfoEnableFastCharging(void);
Result batteryInfoDisableFastCharging(void); Result batteryInfoDisableFastCharging(void);
const char* batteryInfoGetChargerTypeString(BatteryChargerType type); const char *batteryInfoGetChargerTypeString(BatteryChargerType type);
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role); const char *batteryInfoGetPowerRoleString(BatteryPowerRole role);
const char* batteryInfoGetPDStateString(BatteryPDControllerState state); const char *batteryInfoGetPDStateString(BatteryPDControllerState state);

View File

@@ -22,293 +22,283 @@
#define _FUSE_H_ #define _FUSE_H_
#ifndef BIT #ifndef BIT
#define BIT(n) (1U<<(n)) #define BIT(n) (1U << (n))
#endif #endif
/*! Fuse registers. */ /*! Fuse registers. */
#define FUSE_CTRL 0x0 #define FUSE_CTRL 0x0
#define FUSE_ADDR 0x4 #define FUSE_ADDR 0x4
#define FUSE_RDATA 0x8 #define FUSE_RDATA 0x8
#define FUSE_WDATA 0xC #define FUSE_WDATA 0xC
#define FUSE_TIME_RD1 0x10 #define FUSE_TIME_RD1 0x10
#define FUSE_TIME_RD2 0x14 #define FUSE_TIME_RD2 0x14
#define FUSE_TIME_PGM1 0x18 #define FUSE_TIME_PGM1 0x18
#define FUSE_TIME_PGM2 0x1C #define FUSE_TIME_PGM2 0x1C
#define FUSE_PRIV2INTFC 0x20 #define FUSE_PRIV2INTFC 0x20
#define FUSE_PRIV2INTFC_START_DATA BIT(0) #define FUSE_PRIV2INTFC_START_DATA BIT(0)
#define FUSE_PRIV2INTFC_SKIP_RECORDS BIT(1) #define FUSE_PRIV2INTFC_SKIP_RECORDS BIT(1)
#define FUSE_FUSEBYPASS 0x24 #define FUSE_FUSEBYPASS 0x24
#define FUSE_PRIVATEKEYDISABLE 0x28 #define FUSE_PRIVATEKEYDISABLE 0x28
#define FUSE_PRIVKEY_DISABLE BIT(0) #define FUSE_PRIVKEY_DISABLE BIT(0)
#define FUSE_PRIVKEY_TZ_STICKY_BIT BIT(4) #define FUSE_PRIVKEY_TZ_STICKY_BIT BIT(4)
#define FUSE_DISABLEREGPROGRAM 0x2C #define FUSE_DISABLEREGPROGRAM 0x2C
#define FUSE_WRITE_ACCESS_SW 0x30 #define FUSE_WRITE_ACCESS_SW 0x30
#define FUSE_PWR_GOOD_SW 0x34 #define FUSE_PWR_GOOD_SW 0x34
#define FUSE_PRIV2RESHIFT 0x3C #define FUSE_PRIV2RESHIFT 0x3C
#define FUSE_FUSETIME_RD0 0x40 #define FUSE_FUSETIME_RD0 0x40
#define FUSE_FUSETIME_RD1 0x44 #define FUSE_FUSETIME_RD1 0x44
#define FUSE_FUSETIME_RD2 0x48 #define FUSE_FUSETIME_RD2 0x48
#define FUSE_FUSETIME_RD3 0x4C #define FUSE_FUSETIME_RD3 0x4C
#define FUSE_PRIVATE_KEY0_NONZERO 0x80 #define FUSE_PRIVATE_KEY0_NONZERO 0x80
#define FUSE_PRIVATE_KEY1_NONZERO 0x84 #define FUSE_PRIVATE_KEY1_NONZERO 0x84
#define FUSE_PRIVATE_KEY2_NONZERO 0x88 #define FUSE_PRIVATE_KEY2_NONZERO 0x88
#define FUSE_PRIVATE_KEY3_NONZERO 0x8C #define FUSE_PRIVATE_KEY3_NONZERO 0x8C
#define FUSE_PRIVATE_KEY4_NONZERO 0x90 #define FUSE_PRIVATE_KEY4_NONZERO 0x90
/*! Fuse Cached registers */ /*! Fuse Cached registers */
#define FUSE_RESERVED_ODM8_B01 0x98 // FUSE_READ_TZ Group 0. #define FUSE_RESERVED_ODM8_B01 0x98 // FUSE_READ_TZ Group 0.
#define FUSE_RESERVED_ODM9_B01 0x9C // FUSE_READ_TZ Group 0. #define FUSE_RESERVED_ODM9_B01 0x9C // FUSE_READ_TZ Group 0.
#define FUSE_RESERVED_ODM10_B01 0xA0 // FUSE_READ_TZ Group 0. #define FUSE_RESERVED_ODM10_B01 0xA0 // FUSE_READ_TZ Group 0.
#define FUSE_RESERVED_ODM11_B01 0xA4 // FUSE_READ_TZ Group 0. #define FUSE_RESERVED_ODM11_B01 0xA4 // FUSE_READ_TZ Group 0.
#define FUSE_RESERVED_ODM12_B01 0xA8 // FUSE_READ_TZ Group 1? Is value -1? #define FUSE_RESERVED_ODM12_B01 0xA8 // FUSE_READ_TZ Group 1? Is value -1?
#define FUSE_RESERVED_ODM13_B01 0xAC // FUSE_READ_TZ Group 1? Is value -1? #define FUSE_RESERVED_ODM13_B01 0xAC // FUSE_READ_TZ Group 1? Is value -1?
#define FUSE_RESERVED_ODM14_B01 0xB0 // FUSE_READ_TZ Group 1? Is value -1? #define FUSE_RESERVED_ODM14_B01 0xB0 // FUSE_READ_TZ Group 1? Is value -1?
#define FUSE_RESERVED_ODM15_B01 0xB4 // FUSE_READ_TZ Group 1? Is value -1? #define FUSE_RESERVED_ODM15_B01 0xB4 // FUSE_READ_TZ Group 1? Is value -1?
#define FUSE_RESERVED_ODM16_B01 0xB8 // FUSE_READ_TZ Group 2? Is value -1? #define FUSE_RESERVED_ODM16_B01 0xB8 // FUSE_READ_TZ Group 2? Is value -1?
#define FUSE_RESERVED_ODM17_B01 0xBC // FUSE_READ_TZ Group 2? Is value -1? #define FUSE_RESERVED_ODM17_B01 0xBC // FUSE_READ_TZ Group 2? Is value -1?
#define FUSE_RESERVED_ODM18_B01 0xC0 // FUSE_READ_TZ Group 2. #define FUSE_RESERVED_ODM18_B01 0xC0 // FUSE_READ_TZ Group 2.
#define FUSE_RESERVED_ODM19_B01 0xC4 // FUSE_READ_TZ Group 2. #define FUSE_RESERVED_ODM19_B01 0xC4 // FUSE_READ_TZ Group 2.
#define FUSE_RESERVED_ODM20_B01 0xC8 // FUSE_READ_TZ Group 3. #define FUSE_RESERVED_ODM20_B01 0xC8 // FUSE_READ_TZ Group 3.
#define FUSE_RESERVED_ODM21_B01 0xCC // FUSE_READ_TZ Group 3. #define FUSE_RESERVED_ODM21_B01 0xCC // FUSE_READ_TZ Group 3.
#define FUSE_KEK00_B01 0xD0 #define FUSE_KEK00_B01 0xD0
#define FUSE_KEK01_B01 0xD4 #define FUSE_KEK01_B01 0xD4
#define FUSE_KEK02_B01 0xD8 #define FUSE_KEK02_B01 0xD8
#define FUSE_KEK03_B01 0xDC #define FUSE_KEK03_B01 0xDC
#define FUSE_BEK00_B01 0xE0 #define FUSE_BEK00_B01 0xE0
#define FUSE_BEK01_B01 0xE4 #define FUSE_BEK01_B01 0xE4
#define FUSE_BEK02_B01 0xE8 #define FUSE_BEK02_B01 0xE8
#define FUSE_BEK03_B01 0xEC #define FUSE_BEK03_B01 0xEC
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4SVT_B01 0xF0 #define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4SVT_B01 0xF0
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4SVT_B01 0xF4 #define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4SVT_B01 0xF4
#define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4SVT_B01 0xF8 #define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4SVT_B01 0xF8
#define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4SVT_B01 0xFC #define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4SVT_B01 0xFC
#define FUSE_PRODUCTION_MODE 0x100 #define FUSE_PRODUCTION_MODE 0x100
#define FUSE_JTAG_SECUREID_VALID 0x104 #define FUSE_JTAG_SECUREID_VALID 0x104
#define FUSE_ODM_LOCK 0x108 #define FUSE_ODM_LOCK 0x108
#define FUSE_OPT_OPENGL_EN 0x10C #define FUSE_OPT_OPENGL_EN 0x10C
#define FUSE_SKU_INFO 0x110 #define FUSE_SKU_INFO 0x110
#define FUSE_CPU_SPEEDO_0_CALIB 0x114 #define FUSE_CPU_SPEEDO_0_CALIB 0x114
#define FUSE_CPU_IDDQ_CALIB 0x118 #define FUSE_CPU_IDDQ_CALIB 0x118
#define FUSE_RESERVED_ODM22_B01 0x11C // FUSE_READ_TZ Group 3. #define FUSE_RESERVED_ODM22_B01 0x11C // FUSE_READ_TZ Group 3.
#define FUSE_RESERVED_ODM23_B01 0x120 // FUSE_READ_TZ Group 3. #define FUSE_RESERVED_ODM23_B01 0x120 // FUSE_READ_TZ Group 3.
#define FUSE_RESERVED_ODM24_B01 0x124 // FUSE_READ_TZ Group 4. #define FUSE_RESERVED_ODM24_B01 0x124 // FUSE_READ_TZ Group 4.
#define FUSE_OPT_FT_REV 0x128 #define FUSE_OPT_FT_REV 0x128
#define FUSE_CPU_SPEEDO_1_CALIB 0x12C #define FUSE_CPU_SPEEDO_1_CALIB 0x12C
#define FUSE_CPU_SPEEDO_2_CALIB 0x130 #define FUSE_CPU_SPEEDO_2_CALIB 0x130
#define FUSE_SOC_SPEEDO_0_CALIB 0x134 #define FUSE_SOC_SPEEDO_0_CALIB 0x134
#define FUSE_SOC_SPEEDO_1_CALIB 0x138 #define FUSE_SOC_SPEEDO_1_CALIB 0x138
#define FUSE_SOC_SPEEDO_2_CALIB 0x13C #define FUSE_SOC_SPEEDO_2_CALIB 0x13C
#define FUSE_SOC_IDDQ_CALIB 0x140 #define FUSE_SOC_IDDQ_CALIB 0x140
#define FUSE_RESERVED_ODM25_B01 0x144 // FUSE_READ_TZ Group 4. #define FUSE_RESERVED_ODM25_B01 0x144 // FUSE_READ_TZ Group 4.
#define FUSE_FA 0x148 #define FUSE_FA 0x148
#define FUSE_RESERVED_PRODUCTION 0x14C #define FUSE_RESERVED_PRODUCTION 0x14C
#define FUSE_HDMI_LANE0_CALIB 0x150 #define FUSE_HDMI_LANE0_CALIB 0x150
#define FUSE_HDMI_LANE1_CALIB 0x154 #define FUSE_HDMI_LANE1_CALIB 0x154
#define FUSE_HDMI_LANE2_CALIB 0x158 #define FUSE_HDMI_LANE2_CALIB 0x158
#define FUSE_HDMI_LANE3_CALIB 0x15C #define FUSE_HDMI_LANE3_CALIB 0x15C
#define FUSE_ENCRYPTION_RATE 0x160 #define FUSE_ENCRYPTION_RATE 0x160
#define FUSE_PUBLIC_KEY0 0x164 #define FUSE_PUBLIC_KEY0 0x164
#define FUSE_PUBLIC_KEY1 0x168 #define FUSE_PUBLIC_KEY1 0x168
#define FUSE_PUBLIC_KEY2 0x16C #define FUSE_PUBLIC_KEY2 0x16C
#define FUSE_PUBLIC_KEY3 0x170 #define FUSE_PUBLIC_KEY3 0x170
#define FUSE_PUBLIC_KEY4 0x174 #define FUSE_PUBLIC_KEY4 0x174
#define FUSE_PUBLIC_KEY5 0x178 #define FUSE_PUBLIC_KEY5 0x178
#define FUSE_PUBLIC_KEY6 0x17C #define FUSE_PUBLIC_KEY6 0x17C
#define FUSE_PUBLIC_KEY7 0x180 #define FUSE_PUBLIC_KEY7 0x180
#define FUSE_TSENSOR1_CALIB 0x184 // CPU1. #define FUSE_TSENSOR1_CALIB 0x184 // CPU1.
#define FUSE_TSENSOR2_CALIB 0x188 // CPU2. #define FUSE_TSENSOR2_CALIB 0x188 // CPU2.
#define FUSE_OPT_SECURE_SCC_DIS_B01 0x18C #define FUSE_OPT_SECURE_SCC_DIS_B01 0x18C
#define FUSE_OPT_CP_REV 0x190 // FUSE style revision - ATE. 0x101 0x100 #define FUSE_OPT_CP_REV 0x190 // FUSE style revision - ATE. 0x101 0x100
#define FUSE_OPT_PFG 0x194 #define FUSE_OPT_PFG 0x194
#define FUSE_TSENSOR0_CALIB 0x198 // CPU0. #define FUSE_TSENSOR0_CALIB 0x198 // CPU0.
#define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19C #define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19C
#define FUSE_SECURITY_MODE 0x1A0 #define FUSE_SECURITY_MODE 0x1A0
#define FUSE_PRIVATE_KEY0 0x1A4 #define FUSE_PRIVATE_KEY0 0x1A4
#define FUSE_PRIVATE_KEY1 0x1A8 #define FUSE_PRIVATE_KEY1 0x1A8
#define FUSE_PRIVATE_KEY2 0x1AC #define FUSE_PRIVATE_KEY2 0x1AC
#define FUSE_PRIVATE_KEY3 0x1B0 #define FUSE_PRIVATE_KEY3 0x1B0
#define FUSE_PRIVATE_KEY4 0x1B4 #define FUSE_PRIVATE_KEY4 0x1B4
#define FUSE_ARM_JTAG_DIS 0x1B8 #define FUSE_ARM_JTAG_DIS 0x1B8
#define FUSE_BOOT_DEVICE_INFO 0x1BC #define FUSE_BOOT_DEVICE_INFO 0x1BC
#define FUSE_RESERVED_SW 0x1C0 #define FUSE_RESERVED_SW 0x1C0
#define FUSE_OPT_VP9_DISABLE 0x1C4 #define FUSE_OPT_VP9_DISABLE 0x1C4
#define FUSE_RESERVED_ODM0 0x1C8 #define FUSE_RESERVED_ODM0 0x1C8
#define FUSE_RESERVED_ODM1 0x1CC #define FUSE_RESERVED_ODM1 0x1CC
#define FUSE_RESERVED_ODM2 0x1D0 #define FUSE_RESERVED_ODM2 0x1D0
#define FUSE_RESERVED_ODM3 0x1D4 #define FUSE_RESERVED_ODM3 0x1D4
#define FUSE_RESERVED_ODM4 0x1D8 #define FUSE_RESERVED_ODM4 0x1D8
#define FUSE_RESERVED_ODM5 0x1DC #define FUSE_RESERVED_ODM5 0x1DC
#define FUSE_RESERVED_ODM6 0x1E0 #define FUSE_RESERVED_ODM6 0x1E0
#define FUSE_RESERVED_ODM7 0x1E4 #define FUSE_RESERVED_ODM7 0x1E4
#define FUSE_OBS_DIS 0x1E8 #define FUSE_OBS_DIS 0x1E8
#define FUSE_OPT_NVJTAG_PROTECTION_ENABLE_B01 0x1EC #define FUSE_OPT_NVJTAG_PROTECTION_ENABLE_B01 0x1EC
#define FUSE_USB_CALIB 0x1F0 #define FUSE_USB_CALIB 0x1F0
#define FUSE_SKU_DIRECT_CONFIG 0x1F4 #define FUSE_SKU_DIRECT_CONFIG 0x1F4
#define FUSE_KFUSE_PRIVKEY_CTRL 0x1F8 #define FUSE_KFUSE_PRIVKEY_CTRL 0x1F8
#define FUSE_PACKAGE_INFO 0x1FC // 1: MID, 2: DSC. #define FUSE_PACKAGE_INFO 0x1FC // 1: MID, 2: DSC.
#define FUSE_OPT_VENDOR_CODE 0x200 #define FUSE_OPT_VENDOR_CODE 0x200
#define FUSE_OPT_FAB_CODE 0x204 #define FUSE_OPT_FAB_CODE 0x204
#define FUSE_OPT_LOT_CODE_0 0x208 #define FUSE_OPT_LOT_CODE_0 0x208
#define FUSE_OPT_LOT_CODE_1 0x20C #define FUSE_OPT_LOT_CODE_1 0x20C
#define FUSE_OPT_WAFER_ID 0x210 #define FUSE_OPT_WAFER_ID 0x210
#define FUSE_OPT_X_COORDINATE 0x214 #define FUSE_OPT_X_COORDINATE 0x214
#define FUSE_OPT_Y_COORDINATE 0x218 #define FUSE_OPT_Y_COORDINATE 0x218
#define FUSE_OPT_SEC_DEBUG_EN 0x21C #define FUSE_OPT_SEC_DEBUG_EN 0x21C
#define FUSE_OPT_OPS_RESERVED 0x220 #define FUSE_OPT_OPS_RESERVED 0x220
#define FUSE_SATA_CALIB 0x224 #define FUSE_SATA_CALIB 0x224
#define FUSE_SPARE_REGISTER_ODM_B01 0x224 #define FUSE_SPARE_REGISTER_ODM_B01 0x224
#define FUSE_GPU_IDDQ_CALIB 0x228 #define FUSE_GPU_IDDQ_CALIB 0x228
#define FUSE_TSENSOR3_CALIB 0x22C // CPU3. #define FUSE_TSENSOR3_CALIB 0x22C // CPU3.
#define FUSE_CLOCK_BONDOUT0 0x230 #define FUSE_CLOCK_BONDOUT0 0x230
#define FUSE_CLOCK_BONDOUT1 0x234 #define FUSE_CLOCK_BONDOUT1 0x234
#define FUSE_RESERVED_ODM26_B01 0x238 // FUSE_READ_TZ Group 4. #define FUSE_RESERVED_ODM26_B01 0x238 // FUSE_READ_TZ Group 4.
#define FUSE_RESERVED_ODM27_B01 0x23C // FUSE_READ_TZ Group 4. #define FUSE_RESERVED_ODM27_B01 0x23C // FUSE_READ_TZ Group 4.
#define FUSE_RESERVED_ODM28_B01 0x240 // MAX77812 phase configuration. FUSE_READ_TZ Group 5. #define FUSE_RESERVED_ODM28_B01 0x240 // MAX77812 phase configuration. FUSE_READ_TZ Group 5.
#define FUSE_OPT_SAMPLE_TYPE 0x244 #define FUSE_OPT_SAMPLE_TYPE 0x244
#define FUSE_OPT_SUBREVISION 0x248 // "", "p", "q", "r". e.g: A01p. #define FUSE_OPT_SUBREVISION 0x248 // "", "p", "q", "r". e.g: A01p.
#define FUSE_OPT_SW_RESERVED_0 0x24C #define FUSE_OPT_SW_RESERVED_0 0x24C
#define FUSE_OPT_SW_RESERVED_1 0x250 #define FUSE_OPT_SW_RESERVED_1 0x250
#define FUSE_TSENSOR4_CALIB 0x254 // GPU. #define FUSE_TSENSOR4_CALIB 0x254 // GPU.
#define FUSE_TSENSOR5_CALIB 0x258 // MEM0. #define FUSE_TSENSOR5_CALIB 0x258 // MEM0.
#define FUSE_TSENSOR6_CALIB 0x25C // MEM1. #define FUSE_TSENSOR6_CALIB 0x25C // MEM1.
#define FUSE_TSENSOR7_CALIB 0x260 // PLLX. #define FUSE_TSENSOR7_CALIB 0x260 // PLLX.
#define FUSE_OPT_PRIV_SEC_DIS 0x264 #define FUSE_OPT_PRIV_SEC_DIS 0x264
#define FUSE_PKC_DISABLE 0x268 #define FUSE_PKC_DISABLE 0x268
#define FUSE_BOOT_SECURITY_INFO_B01 0x268 #define FUSE_BOOT_SECURITY_INFO_B01 0x268
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4HVT_B01 0x26C #define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4HVT_B01 0x26C
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4HVT_B01 0x270 #define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4HVT_B01 0x270
#define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4HVT_B01 0x274 #define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4HVT_B01 0x274
#define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4HVT_B01 0x278 #define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4HVT_B01 0x278
#define FUSE_FUSE2TSEC_DEBUG_DISABLE 0x27C #define FUSE_FUSE2TSEC_DEBUG_DISABLE 0x27C
#define FUSE_TSENSOR_COMMON 0x280 #define FUSE_TSENSOR_COMMON 0x280
#define FUSE_OPT_CP_BIN 0x284 #define FUSE_OPT_CP_BIN 0x284
#define FUSE_OPT_GPU_DISABLE 0x288 #define FUSE_OPT_GPU_DISABLE 0x288
#define FUSE_OPT_FT_BIN 0x28C #define FUSE_OPT_FT_BIN 0x28C
#define FUSE_OPT_DONE_MAP 0x290 #define FUSE_OPT_DONE_MAP 0x290
#define FUSE_RESERVED_ODM29_B01 0x294 // FUSE_READ_TZ Group 5? Is value -1? #define FUSE_RESERVED_ODM29_B01 0x294 // FUSE_READ_TZ Group 5? Is value -1?
#define FUSE_APB2JTAG_DISABLE 0x298 #define FUSE_APB2JTAG_DISABLE 0x298
#define FUSE_ODM_INFO 0x29C // Debug features disable. #define FUSE_ODM_INFO 0x29C // Debug features disable.
#define FUSE_ARM_CRYPT_DE_FEATURE 0x2A8 #define FUSE_ARM_CRYPT_DE_FEATURE 0x2A8
#define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4SVT_B01 0x2B0 #define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4SVT_B01 0x2B0
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4SVT_B01 0x2B4 #define FUSE_OPT_RAM_RCT_TSMCDP_PO4SVT_B01 0x2B4
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4SVT_B01 0x2B8 #define FUSE_OPT_RAM_WCT_TSMCDP_PO4SVT_B01 0x2B8
#define FUSE_OPT_RAM_KP_TSMCDP_PO4SVT_B01 0x2BC #define FUSE_OPT_RAM_KP_TSMCDP_PO4SVT_B01 0x2BC
#define FUSE_WOA_SKU_FLAG 0x2C0 #define FUSE_WOA_SKU_FLAG 0x2C0
#define FUSE_ECO_RESERVE_1 0x2C4 #define FUSE_ECO_RESERVE_1 0x2C4
#define FUSE_GCPLEX_CONFIG_FUSE 0x2C8 #define FUSE_GCPLEX_CONFIG_FUSE 0x2C8
#define FUSE_GPU_VPR_AUTO_FETCH_DIS BIT(0) #define FUSE_GPU_VPR_AUTO_FETCH_DIS BIT(0)
#define FUSE_GPU_VPR_ENABLED BIT(1) #define FUSE_GPU_VPR_ENABLED BIT(1)
#define FUSE_GPU_WPR_ENABLED BIT(2) #define FUSE_GPU_WPR_ENABLED BIT(2)
#define FUSE_PRODUCTION_MONTH 0x2CC #define FUSE_PRODUCTION_MONTH 0x2CC
#define FUSE_RAM_REPAIR_INDICATOR 0x2D0 #define FUSE_RAM_REPAIR_INDICATOR 0x2D0
#define FUSE_TSENSOR9_CALIB 0x2D4 // AOTAG. #define FUSE_TSENSOR9_CALIB 0x2D4 // AOTAG.
#define FUSE_VMIN_CALIBRATION 0x2DC #define FUSE_VMIN_CALIBRATION 0x2DC
#define FUSE_AGING_SENSOR_CALIBRATION 0x2E0 #define FUSE_AGING_SENSOR_CALIBRATION 0x2E0
#define FUSE_DEBUG_AUTHENTICATION 0x2E4 #define FUSE_DEBUG_AUTHENTICATION 0x2E4
#define FUSE_SECURE_PROVISION_INDEX 0x2E8 #define FUSE_SECURE_PROVISION_INDEX 0x2E8
#define FUSE_SECURE_PROVISION_INFO 0x2EC #define FUSE_SECURE_PROVISION_INFO 0x2EC
#define FUSE_OPT_GPU_DISABLE_CP1 0x2F0 #define FUSE_OPT_GPU_DISABLE_CP1 0x2F0
#define FUSE_SPARE_ENDIS 0x2F4 #define FUSE_SPARE_ENDIS 0x2F4
#define FUSE_ECO_RESERVE_0 0x2F8 // AID. #define FUSE_ECO_RESERVE_0 0x2F8 // AID.
#define FUSE_RESERVED_CALIB0 0x304 // GPCPLL ADC Calibration. #define FUSE_RESERVED_CALIB0 0x304 // GPCPLL ADC Calibration.
#define FUSE_RESERVED_CALIB1 0x308 #define FUSE_RESERVED_CALIB1 0x308
#define FUSE_OPT_GPU_TPC0_DISABLE 0x30C #define FUSE_OPT_GPU_TPC0_DISABLE 0x30C
#define FUSE_OPT_GPU_TPC0_DISABLE_CP1 0x310 #define FUSE_OPT_GPU_TPC0_DISABLE_CP1 0x310
#define FUSE_OPT_CPU_DISABLE 0x314 #define FUSE_OPT_CPU_DISABLE 0x314
#define FUSE_OPT_CPU_DISABLE_CP1 0x318 #define FUSE_OPT_CPU_DISABLE_CP1 0x318
#define FUSE_TSENSOR10_CALIB 0x31C #define FUSE_TSENSOR10_CALIB 0x31C
#define FUSE_TSENSOR10_CALIB_AUX 0x320 #define FUSE_TSENSOR10_CALIB_AUX 0x320
#define FUSE_OPT_RAM_SVOP_DP 0x324 #define FUSE_OPT_RAM_SVOP_DP 0x324
#define FUSE_OPT_RAM_SVOP_PDP 0x328 #define FUSE_OPT_RAM_SVOP_PDP 0x328
#define FUSE_OPT_RAM_SVOP_REG 0x32C #define FUSE_OPT_RAM_SVOP_REG 0x32C
#define FUSE_OPT_RAM_SVOP_SP 0x330 #define FUSE_OPT_RAM_SVOP_SP 0x330
#define FUSE_OPT_RAM_SVOP_SMPDP 0x334 #define FUSE_OPT_RAM_SVOP_SMPDP 0x334
#define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4HVT_B01 0x324 #define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4HVT_B01 0x324
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4HVT_B01 0x328 #define FUSE_OPT_RAM_RCT_TSMCDP_PO4HVT_B01 0x328
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4HVT_B01 0x32c #define FUSE_OPT_RAM_WCT_TSMCDP_PO4HVT_B01 0x32c
#define FUSE_OPT_RAM_KP_TSMCDP_PO4HVT_B01 0x330 #define FUSE_OPT_RAM_KP_TSMCDP_PO4HVT_B01 0x330
#define FUSE_OPT_RAM_SVOP_SP_B01 0x334 #define FUSE_OPT_RAM_SVOP_SP_B01 0x334
#define FUSE_OPT_GPU_TPC0_DISABLE_CP2 0x338 #define FUSE_OPT_GPU_TPC0_DISABLE_CP2 0x338
#define FUSE_OPT_GPU_TPC1_DISABLE 0x33C #define FUSE_OPT_GPU_TPC1_DISABLE 0x33C
#define FUSE_OPT_GPU_TPC1_DISABLE_CP1 0x340 #define FUSE_OPT_GPU_TPC1_DISABLE_CP1 0x340
#define FUSE_OPT_GPU_TPC1_DISABLE_CP2 0x344 #define FUSE_OPT_GPU_TPC1_DISABLE_CP2 0x344
#define FUSE_OPT_CPU_DISABLE_CP2 0x348 #define FUSE_OPT_CPU_DISABLE_CP2 0x348
#define FUSE_OPT_GPU_DISABLE_CP2 0x34C #define FUSE_OPT_GPU_DISABLE_CP2 0x34C
#define FUSE_USB_CALIB_EXT 0x350 #define FUSE_USB_CALIB_EXT 0x350
#define FUSE_RESERVED_FIELD 0x354 // RMA. #define FUSE_RESERVED_FIELD 0x354 // RMA.
#define FUSE_SPARE_REALIGNMENT_REG 0x37C #define FUSE_SPARE_REALIGNMENT_REG 0x37C
#define FUSE_SPARE_BIT_0 0x380 #define FUSE_SPARE_BIT_0 0x380
//... //...
#define FUSE_SPARE_BIT_31 0x3FC #define FUSE_SPARE_BIT_31 0x3FC
/*! Fuse commands. */ /*! Fuse commands. */
#define FUSE_IDLE 0x0 #define FUSE_IDLE 0x0
#define FUSE_READ 0x1 #define FUSE_READ 0x1
#define FUSE_WRITE 0x2 #define FUSE_WRITE 0x2
#define FUSE_SENSE 0x3 #define FUSE_SENSE 0x3
#define FUSE_CMD_MASK 0x3 #define FUSE_CMD_MASK 0x3
/*! Fuse status. */ /*! Fuse status. */
#define FUSE_STATUS_RESET 0 #define FUSE_STATUS_RESET 0
#define FUSE_STATUS_POST_RESET 1 #define FUSE_STATUS_POST_RESET 1
#define FUSE_STATUS_LOAD_ROW0 2 #define FUSE_STATUS_LOAD_ROW0 2
#define FUSE_STATUS_LOAD_ROW1 3 #define FUSE_STATUS_LOAD_ROW1 3
#define FUSE_STATUS_IDLE 4 #define FUSE_STATUS_IDLE 4
#define FUSE_STATUS_READ_SETUP 5 #define FUSE_STATUS_READ_SETUP 5
#define FUSE_STATUS_READ_STROBE 6 #define FUSE_STATUS_READ_STROBE 6
#define FUSE_STATUS_SAMPLE_FUSES 7 #define FUSE_STATUS_SAMPLE_FUSES 7
#define FUSE_STATUS_READ_HOLD 8 #define FUSE_STATUS_READ_HOLD 8
#define FUSE_STATUS_FUSE_SRC_SETUP 9 #define FUSE_STATUS_FUSE_SRC_SETUP 9
#define FUSE_STATUS_WRITE_SETUP 10 #define FUSE_STATUS_WRITE_SETUP 10
#define FUSE_STATUS_WRITE_ADDR_SETUP 11 #define FUSE_STATUS_WRITE_ADDR_SETUP 11
#define FUSE_STATUS_WRITE_PROGRAM 12 #define FUSE_STATUS_WRITE_PROGRAM 12
#define FUSE_STATUS_WRITE_ADDR_HOLD 13 #define FUSE_STATUS_WRITE_ADDR_HOLD 13
#define FUSE_STATUS_FUSE_SRC_HOLD 14 #define FUSE_STATUS_FUSE_SRC_HOLD 14
#define FUSE_STATUS_LOAD_RIR 15 #define FUSE_STATUS_LOAD_RIR 15
#define FUSE_STATUS_READ_BEFORE_WRITE_SETUP 16 #define FUSE_STATUS_READ_BEFORE_WRITE_SETUP 16
#define FUSE_STATUS_READ_DEASSERT_PD 17 #define FUSE_STATUS_READ_DEASSERT_PD 17
/*! Fuse cache registers. */ /*! Fuse cache registers. */
#define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x)) #define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x))
#define FUSE_ARRAY_WORDS_NUM 192 #define FUSE_ARRAY_WORDS_NUM 192
#define FUSE_ARRAY_WORDS_NUM_B01 256 #define FUSE_ARRAY_WORDS_NUM_B01 256
enum enum { FUSE_NX_HW_TYPE_ICOSA, FUSE_NX_HW_TYPE_IOWA, FUSE_NX_HW_TYPE_HOAG, FUSE_NX_HW_TYPE_AULA };
{
FUSE_NX_HW_TYPE_ICOSA,
FUSE_NX_HW_TYPE_IOWA,
FUSE_NX_HW_TYPE_HOAG,
FUSE_NX_HW_TYPE_AULA
};
enum enum { FUSE_NX_HW_STATE_PROD, FUSE_NX_HW_STATE_DEV };
{
FUSE_NX_HW_STATE_PROD,
FUSE_NX_HW_STATE_DEV
};
#endif #endif

View File

@@ -17,53 +17,53 @@
* *
*/ */
#include "gm20b.hpp"
#include "../mapping/mem_map.hpp" #include "../mapping/mem_map.hpp"
#include "gm20b.hpp"
namespace gm20b { namespace gm20b {
u64 gpu_base = 0; u64 gpu_base = 0;
#define GPU_PA 0x57000000 #define GPU_PA 0x57000000
#define GPU_SIZE 0x1000000 #define GPU_SIZE 0x1000000
#define GPU_TRIM_SYS_GPCPLL_CFG 0x00 #define GPU_TRIM_SYS_GPCPLL_CFG 0x00
#define GPU_TRIM_SYS_GPCPLL_COEFF 0x04 #define GPU_TRIM_SYS_GPCPLL_COEFF 0x04
#define GPU_TRIM_SYS_GPCPLL_CFG2 0x08 #define GPU_TRIM_SYS_GPCPLL_CFG2 0x08
#define GPU_TRIM_SYS_GPCPLL_CFG3 0x0C #define GPU_TRIM_SYS_GPCPLL_CFG3 0x0C
#define GPU_TRIM_SYS_GPCPLL_DVFS0 0x10 #define GPU_TRIM_SYS_GPCPLL_DVFS0 0x10
#define GPU_TRIM_SYS_GPCPLL_DVFS1 0x14 #define GPU_TRIM_SYS_GPCPLL_DVFS1 0x14
#define GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN 0x1C #define GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN 0x1C
#define GPU_TRIM_SYS_SEL_VCO 0x2C #define GPU_TRIM_SYS_SEL_VCO 0x2C
#define GPU_TRIM_SYS_GPC2CLK_OUT 0x250 #define GPU_TRIM_SYS_GPC2CLK_OUT 0x250
#define GPC_BCAST(x) (*(volatile u32 *)(gpu_base + 0x132800ul + (x))) #define GPC_BCAST(x) (*(volatile u32 *)(gpu_base + 0x132800ul + (x)))
#define GPU_TRIM_SYS_GPCPLL(x) (*(volatile u32 *)(gpu_base + 0x137000ul + (x))) #define GPU_TRIM_SYS_GPCPLL(x) (*(volatile u32 *)(gpu_base + 0x137000ul + (x)))
#define GPC_BCAST_GPCPLL_DVFS2 0x20 #define GPC_BCAST_GPCPLL_DVFS2 0x20
#define GPC_BCAST_NDIV_SLOWDOWN_DBG 0xa0 #define GPC_BCAST_NDIV_SLOWDOWN_DBG 0xa0
#define GPCPLL_CFG_ENABLE BIT(0) #define GPCPLL_CFG_ENABLE BIT(0)
#define GPCPLL_CFG_IDDQ BIT(1) #define GPCPLL_CFG_IDDQ BIT(1)
#define GPCPLL_CFG_SYNC_MODE BIT(2) #define GPCPLL_CFG_SYNC_MODE BIT(2)
#define GPCPLL_CFG_LOCK BIT(17) #define GPCPLL_CFG_LOCK BIT(17)
#define GPCPLL_CFG2_SDM_DIN_MASK 0x000000FFu #define GPCPLL_CFG2_SDM_DIN_MASK 0x000000FFu
#define GPCPLL_CFG2_SDM_DIN_NEW_MASK 0x007FFF00u #define GPCPLL_CFG2_SDM_DIN_NEW_MASK 0x007FFF00u
#define GPCPLL_CFG2_STEPA_SHIFT 24 #define GPCPLL_CFG2_STEPA_SHIFT 24
#define GPCPLL_CFG2_STEPA_MASK 0xFF000000u #define GPCPLL_CFG2_STEPA_MASK 0xFF000000u
#define GPCPLL_CFG3_STEPB_SHIFT 16 #define GPCPLL_CFG3_STEPB_SHIFT 16
#define GPCPLL_CFG3_STEPB_MASK 0x00FF0000u #define GPCPLL_CFG3_STEPB_MASK 0x00FF0000u
#define GPCPLL_DVFS0_DFS_COEFF_MASK 0x0000007Fu #define GPCPLL_DVFS0_DFS_COEFF_MASK 0x0000007Fu
#define NDIV_SLOWDOWN_SLOWDOWN_USING_PLL BIT(22) #define NDIV_SLOWDOWN_SLOWDOWN_USING_PLL BIT(22)
#define NDIV_SLOWDOWN_EN_DYNRAMP BIT(23) #define NDIV_SLOWDOWN_EN_DYNRAMP BIT(23)
#define DYNRAMP_DONE_SYNCED BIT(24) #define DYNRAMP_DONE_SYNCED BIT(24)
#define GPCPLL_DVFS2_DFS_EXT_STROBE BIT(16) #define GPCPLL_DVFS2_DFS_EXT_STROBE BIT(16)
#define RAMP_TIMEOUT_US 500 #define RAMP_TIMEOUT_US 500
static inline void _gpu_mask(u32 reg, u32 mask, u32 val) { static inline void _gpu_mask(u32 reg, u32 mask, u32 val) {
u32 tmp = GPU_TRIM_SYS_GPCPLL(reg); u32 tmp = GPU_TRIM_SYS_GPCPLL(reg);
@@ -78,12 +78,8 @@ namespace gm20b {
} }
static void _clk_setup_slide() { static void _clk_setup_slide() {
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, _gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_STEPA_MASK, 0x04u << GPCPLL_CFG2_STEPA_SHIFT);
GPCPLL_CFG2_STEPA_MASK, _gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG3, GPCPLL_CFG3_STEPB_MASK, 0x05u << GPCPLL_CFG3_STEPB_SHIFT);
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) { static bool _gpu_pllg_slide(u32 new_divn) {
@@ -95,9 +91,7 @@ namespace gm20b {
_clk_setup_slide(); _clk_setup_slide();
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, _gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL,
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_SDM_DIN_NEW_MASK, 0); _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; GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_COEFF) = coeff;
usleep(1); usleep(1);
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, _gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_EN_DYNRAMP, NDIV_SLOWDOWN_EN_DYNRAMP);
NDIV_SLOWDOWN_EN_DYNRAMP,
NDIV_SLOWDOWN_EN_DYNRAMP);
int ramp_timeout = RAMP_TIMEOUT_US; int ramp_timeout = RAMP_TIMEOUT_US;
bool success = false; 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_CFG2, GPCPLL_CFG2_SDM_DIN_MASK, 0);
} }
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, _gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP, 0);
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP,
0);
(void)GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN); (void)GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN);
return success; return success;
@@ -137,11 +127,11 @@ namespace gm20b {
if (!gpu_base) if (!gpu_base)
QueryMemoryMapping(&gpu_base, GPU_PA, GPU_SIZE); QueryMemoryMapping(&gpu_base, GPU_PA, GPU_SIZE);
const u32 osc_khz = 38400; // PLL Hz const u32 osc_khz = 38400; // PLL Hz
u32 coeff = GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_COEFF); u32 coeff = GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_COEFF);
u32 divm = coeff & 0xFF; u32 divm = coeff & 0xFF;
u32 divp = (coeff >> 16) & 0x3F; u32 divp = (coeff >> 16) & 0x3F;
if (divm == 0 || divp == 0) if (divm == 0 || divp == 0)
return false; return false;
@@ -149,9 +139,11 @@ namespace gm20b {
u32 new_divn = (u64)khz * divm * divp * 2 / osc_khz; u32 new_divn = (u64)khz * divm * divp * 2 / osc_khz;
// L4T clamps the registers here for some reason, do that // L4T clamps the registers here for some reason, do that
if (new_divn < 8) new_divn = 8; if (new_divn < 8)
if (new_divn > 255) new_divn = 255; new_divn = 8;
if (new_divn > 255)
new_divn = 255;
return _gpu_pllg_slide(new_divn); return _gpu_pllg_slide(new_divn);
} }
} } // namespace gm20b

View File

@@ -20,29 +20,29 @@
#include "pllmb.hpp" #include "pllmb.hpp"
namespace pllmb { namespace pllmb {
#define GET_BITS(VAL, HIGH, LOW) ((VAL & ((1UL << (HIGH + 1UL)) - 1UL)) >> LOW) #define GET_BITS(VAL, HIGH, LOW) ((VAL & ((1UL << (HIGH + 1UL)) - 1UL)) >> LOW)
#define GET_BIT(VAL, BIT) GET_BITS(VAL, BIT, BIT) #define GET_BIT(VAL, BIT) GET_BITS(VAL, BIT, BIT)
static inline volatile u32& REG(uintptr_t addr) { static inline volatile u32 &REG(uintptr_t addr) {
return *reinterpret_cast<volatile u32*>(addr); return *reinterpret_cast<volatile u32 *>(addr);
} }
// From jetson nano kernel // From jetson nano kernel
typedef enum { typedef enum {
/* divider = 2 */ /* divider = 2 */
CLK_PLLX = 5, CLK_PLLX = 5,
CLK_PLLM = 2, CLK_PLLM = 2,
CLK_PLLMB = 37, CLK_PLLMB = 37,
/* PLLX & PLLG are backup PLLs for CPU & GPU */ /* PLLX & PLLG are backup PLLs for CPU & GPU */
/* divider = 1 */ /* divider = 1 */
CLK_CCLK_G = 18, // A57 CPU cluster CLK_CCLK_G = 18, // A57 CPU cluster
CLK_EMC = 36, CLK_EMC = 36,
} PTO_ID; // PLL Test Output Register ID } PTO_ID; // PLL Test Output Register ID
/* See if GM20B clock GPC PLL regs are accessible. */ /* See if GM20B clock GPC PLL regs are accessible. */
#define PLLX_MISC0 0xE4 #define PLLX_MISC0 0xE4
#define PLLM_MISC2 0x9C #define PLLM_MISC2 0x9C
double ptoGetMHz(PTO_ID pto_id, u32 divider = 1, u32 presel_reg = 0, u32 presel_mask = 0) { double ptoGetMHz(PTO_ID pto_id, u32 divider = 1, u32 presel_reg = 0, u32 presel_mask = 0) {
u32 pre_val, val, presel_val; u32 pre_val, val, presel_val;
@@ -71,7 +71,7 @@ namespace pllmb {
REG(board::clkVirtAddr + 0x60) = val | BIT(9); REG(board::clkVirtAddr + 0x60) = val | BIT(9);
usleep(500); usleep(500);
while(REG(board::clkVirtAddr + 0x64) & BIT(31)) while (REG(board::clkVirtAddr + 0x64) & BIT(31))
; ;
val = REG(board::clkVirtAddr + 0x64); val = REG(board::clkVirtAddr + 0x64);
@@ -111,6 +111,6 @@ namespace pllmb {
u32 pllmb = ptoGetMHz(CLK_PLLMB, 2, PLLM_MISC2, BIT(9)); u32 pllmb = ptoGetMHz(CLK_PLLMB, 2, PLLM_MISC2, BIT(9));
u32 pllm = ptoGetMHz(CLK_PLLM, 2, PLLM_MISC2, BIT(8)); u32 pllm = ptoGetMHz(CLK_PLLM, 2, PLLM_MISC2, BIT(8));
return pllmb == 0 ? pllm : pllmb; // pllmb is zeroed out at times, fallback to pllm return pllmb == 0 ? pllm : pllmb; // pllmb is zeroed out at times, fallback to pllm
} }
} } // namespace pllmb

View File

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

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