hocclk: format code
use clang format file provided for optimal formatting
This commit is contained in:
@@ -13,6 +13,7 @@ UseTab: Never
|
||||
IndentAccessModifiers: false
|
||||
AccessModifierOffset: 0
|
||||
NamespaceIndentation: All
|
||||
IndentPPDirectives: BeforeHash
|
||||
|
||||
BreakBeforeBraces: Attach
|
||||
BraceWrapping:
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,17 +24,16 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#include "cpp_util.hpp"
|
||||
#include "cpp_util.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <hocclk.h>
|
||||
|
||||
#include <hocclk/client/ipc.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,72 +24,62 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#define TESLA_INIT_IMPL
|
||||
#include <tesla.hpp>
|
||||
|
||||
#include "ui/gui/fatal_gui.h"
|
||||
#include "ui/gui/main_gui.h"
|
||||
|
||||
class AppOverlay : public tsl::Overlay
|
||||
{
|
||||
class AppOverlay : public tsl::Overlay {
|
||||
public:
|
||||
AppOverlay() {}
|
||||
~AppOverlay() {}
|
||||
AppOverlay() {
|
||||
}
|
||||
~AppOverlay() {
|
||||
}
|
||||
|
||||
//virtual void initServices() override {
|
||||
// rgltrInitialize();
|
||||
//}
|
||||
// virtual void initServices() override {
|
||||
// rgltrInitialize();
|
||||
// }
|
||||
|
||||
virtual void exitServices() override {
|
||||
hocclkIpcExit();
|
||||
virtual void exitServices() override {
|
||||
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
|
||||
{
|
||||
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.",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
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 (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>();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
return tsl::loop<AppOverlay>(argc, argv);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,20 +24,18 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include <hocclk/board.h>
|
||||
|
||||
#define FREQ_DEFAULT_TEXT "Do not override"
|
||||
|
||||
static inline std::string formatListFreqMHz(std::uint32_t mhz)
|
||||
{
|
||||
if(mhz == 0)
|
||||
{
|
||||
static inline std::string formatListFreqMHz(std::uint32_t mhz) {
|
||||
if (mhz == 0) {
|
||||
return FREQ_DEFAULT_TEXT;
|
||||
}
|
||||
|
||||
@@ -45,17 +43,17 @@ static inline std::string formatListFreqMHz(std::uint32_t mhz)
|
||||
return std::string(buf, snprintf(buf, sizeof(buf), "%u MHz", mhz));
|
||||
}
|
||||
|
||||
static inline std::string formatListFreqHz(uint32_t hz) { return formatListFreqMHz(hz / 1000000); }
|
||||
static inline std::string formatListFreqHz(uint32_t hz) {
|
||||
return formatListFreqMHz(hz / 1000000);
|
||||
}
|
||||
|
||||
static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit)
|
||||
{
|
||||
if(mhz == 0)
|
||||
static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit) {
|
||||
if (mhz == 0)
|
||||
return FREQ_DEFAULT_TEXT;
|
||||
|
||||
uint32_t mts = mhz * 2;
|
||||
char buf[24];
|
||||
switch(unit)
|
||||
{
|
||||
switch (unit) {
|
||||
case RamDisplayUnit_MHz:
|
||||
snprintf(buf, sizeof(buf), "%u MHz", mhz);
|
||||
break;
|
||||
@@ -70,18 +68,15 @@ static inline std::string formatListFreqMem(uint32_t mhz, RamDisplayUnit unit)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline std::string formatListFreqHzMem(uint32_t hz, RamDisplayUnit unit)
|
||||
{
|
||||
static inline std::string formatListFreqHzMem(uint32_t hz, RamDisplayUnit unit) {
|
||||
return formatListFreqMem(hz / 1000000, unit);
|
||||
}
|
||||
|
||||
static inline std::string formatMemClockKhzLabel(uint32_t khz, RamDisplayUnit unit)
|
||||
{
|
||||
static inline std::string formatMemClockKhzLabel(uint32_t khz, RamDisplayUnit unit) {
|
||||
uint32_t mhz = khz / 1000;
|
||||
uint32_t mts = khz / 500;
|
||||
char buf[32];
|
||||
switch(unit)
|
||||
{
|
||||
switch (unit) {
|
||||
case RamDisplayUnit_MHz:
|
||||
snprintf(buf, sizeof(buf), "%u MHz", mhz);
|
||||
break;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -28,53 +28,29 @@
|
||||
#include "base_menu_gui.h"
|
||||
#include "freq_choice_gui.h"
|
||||
#include "value_choice_gui.h"
|
||||
class AppProfileGui : public BaseMenuGui
|
||||
{
|
||||
class AppProfileGui : public BaseMenuGui {
|
||||
protected:
|
||||
std::uint64_t applicationId;
|
||||
HocClkTitleProfileList* profileList;
|
||||
void openFreqChoiceGui(tsl::elm::ListItem* listItem, HocClkProfile profile, HocClkModule module);
|
||||
void addModuleListItem(HocClkProfile profile, HocClkModule module);
|
||||
void addModuleListItemToggle(HocClkProfile profile, HocClkModule module);
|
||||
void openValueChoiceGui(
|
||||
tsl::elm::ListItem* listItem,
|
||||
std::uint32_t currentValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds = ValueThresholds(),
|
||||
bool enableThresholds = false,
|
||||
const std::map<std::uint32_t, std::string>& labels = {},
|
||||
const std::vector<NamedValue>& namedValues = {},
|
||||
bool showDefaultValue = true
|
||||
);
|
||||
std::string formatValueDisplay(
|
||||
std::uint32_t value,
|
||||
const std::vector<NamedValue>& namedValues,
|
||||
const std::string& suffix,
|
||||
std::uint32_t divisor,
|
||||
int decimalPlaces
|
||||
);
|
||||
void addModuleListItemValue(
|
||||
HocClkProfile profile,
|
||||
HocClkModule module,
|
||||
const std::string& categoryName,
|
||||
std::uint32_t min,
|
||||
std::uint32_t max,
|
||||
std::uint32_t step,
|
||||
const std::string& suffix,
|
||||
std::uint32_t divisor,
|
||||
int decimalPlaces,
|
||||
ValueThresholds thresholds,
|
||||
std::vector<NamedValue> namedValues = {},
|
||||
bool showDefaultValue = true
|
||||
);
|
||||
void addGovernorSection(HocClkProfile profile);
|
||||
void addProfileUI(HocClkProfile profile);
|
||||
std::uint64_t applicationId;
|
||||
HocClkTitleProfileList *profileList;
|
||||
void openFreqChoiceGui(tsl::elm::ListItem *listItem, HocClkProfile profile, HocClkModule module);
|
||||
void addModuleListItem(HocClkProfile profile, HocClkModule module);
|
||||
void addModuleListItemToggle(HocClkProfile profile, HocClkModule module);
|
||||
void openValueChoiceGui(tsl::elm::ListItem *listItem, std::uint32_t currentValue, const ValueRange &range, const std::string &categoryName,
|
||||
ValueChoiceListener listener, const ValueThresholds &thresholds = ValueThresholds(), bool enableThresholds = false,
|
||||
const std::map<std::uint32_t, std::string> &labels = {}, const std::vector<NamedValue> &namedValues = {},
|
||||
bool showDefaultValue = true);
|
||||
std::string formatValueDisplay(std::uint32_t value, const std::vector<NamedValue> &namedValues, const std::string &suffix, std::uint32_t divisor,
|
||||
int decimalPlaces);
|
||||
void addModuleListItemValue(HocClkProfile profile, HocClkModule module, const std::string &categoryName, std::uint32_t min, std::uint32_t max,
|
||||
std::uint32_t step, const std::string &suffix, std::uint32_t divisor, int decimalPlaces, ValueThresholds thresholds,
|
||||
std::vector<NamedValue> namedValues = {}, bool showDefaultValue = true);
|
||||
void addGovernorSection(HocClkProfile profile);
|
||||
void addProfileUI(HocClkProfile profile);
|
||||
|
||||
public:
|
||||
AppProfileGui(std::uint64_t applicationId, HocClkTitleProfileList* profileList);
|
||||
~AppProfileGui();
|
||||
void listUI() override;
|
||||
static void changeTo(std::uint64_t applicationId);
|
||||
void update() override;
|
||||
AppProfileGui(std::uint64_t applicationId, HocClkTitleProfileList *profileList);
|
||||
~AppProfileGui();
|
||||
void listUI() override;
|
||||
static void changeTo(std::uint64_t applicationId);
|
||||
void update() override;
|
||||
};
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
@@ -24,16 +24,18 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "base_gui.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);
|
||||
this->gui->preDraw(renderer);
|
||||
}
|
||||
|
||||
#include <tesla.hpp>
|
||||
#include <math.h>
|
||||
#include <tesla.hpp>
|
||||
|
||||
|
||||
#define LOGO_Y_REAL 65
|
||||
|
||||
@@ -53,8 +55,8 @@ void BaseFrame::draw(tsl::gfx::Renderer* renderer) {
|
||||
#define VERSION_FONT_SIZE 15
|
||||
|
||||
extern "C" {
|
||||
extern const u8 hoc_rgba[];
|
||||
extern const u32 hoc_rgba_size;
|
||||
extern const u8 hoc_rgba[];
|
||||
extern const u32 hoc_rgba_size;
|
||||
}
|
||||
|
||||
std::string getVersionString() {
|
||||
@@ -66,19 +68,13 @@ std::string getVersionString() {
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
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 STATIC_TEAL = 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 STATIC_TEAL = tsl::Color(7, 15, 15, 15);
|
||||
const std::string name = " Horizon OC";
|
||||
|
||||
static s32 drawDynamicUltraText(
|
||||
tsl::gfx::Renderer* renderer,
|
||||
s32 startX,
|
||||
s32 y,
|
||||
u32 fontSize,
|
||||
const tsl::Color& staticColor,
|
||||
bool useNotificationMethod = false)
|
||||
{
|
||||
static s32 drawDynamicUltraText(tsl::gfx::Renderer *renderer, s32 startX, s32 y, u32 fontSize, const tsl::Color &staticColor,
|
||||
bool useNotificationMethod = false) {
|
||||
static constexpr double cycleDuration = 1.6;
|
||||
|
||||
s32 currentX = startX;
|
||||
@@ -88,10 +84,10 @@ static s32 drawDynamicUltraText(
|
||||
|
||||
const double waveScale = 2.0 * M_PI / cycleDuration;
|
||||
|
||||
for (size_t i = 0; i < name.size(); i++)
|
||||
{
|
||||
for (size_t i = 0; i < name.size(); i++) {
|
||||
char letter = name[i];
|
||||
if (letter == '\0') break;
|
||||
if (letter == '\0')
|
||||
break;
|
||||
|
||||
double phase = waveScale * (timeNow + i * 0.12);
|
||||
|
||||
@@ -103,15 +99,9 @@ static s32 drawDynamicUltraText(
|
||||
double glow = (cos(phase * 1.5) + 1.0) * 0.5;
|
||||
double brightness = 0.75 + glow * 0.25;
|
||||
|
||||
u8 r = static_cast<u8>(
|
||||
((int)dynamicLogoRGB1.r + ((int)dynamicLogoRGB2.r - (int)dynamicLogoRGB1.r) * blend) * brightness
|
||||
);
|
||||
u8 g = static_cast<u8>(
|
||||
((int)dynamicLogoRGB1.g + ((int)dynamicLogoRGB2.g - (int)dynamicLogoRGB1.g) * blend) * brightness
|
||||
);
|
||||
u8 b = static_cast<u8>(
|
||||
((int)dynamicLogoRGB1.b + ((int)dynamicLogoRGB2.b - (int)dynamicLogoRGB1.b) * blend) * brightness
|
||||
);
|
||||
u8 r = static_cast<u8>(((int)dynamicLogoRGB1.r + ((int)dynamicLogoRGB2.r - (int)dynamicLogoRGB1.r) * blend) * brightness);
|
||||
u8 g = static_cast<u8>(((int)dynamicLogoRGB1.g + ((int)dynamicLogoRGB2.g - (int)dynamicLogoRGB1.g) * blend) * brightness);
|
||||
u8 b = static_cast<u8>(((int)dynamicLogoRGB1.b + ((int)dynamicLogoRGB2.b - (int)dynamicLogoRGB1.b) * blend) * brightness);
|
||||
|
||||
r = std::clamp<u8>(r, 0, 15);
|
||||
g = std::clamp<u8>(g, 0, 15);
|
||||
@@ -137,17 +127,10 @@ static s32 drawDynamicUltraText(
|
||||
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);
|
||||
|
||||
drawDynamicUltraText(
|
||||
renderer,
|
||||
LOGO_TEXT_X,
|
||||
TEXT_Y,
|
||||
LOGO_LABEL_FONT_SIZE,
|
||||
STATIC_TEAL,
|
||||
false
|
||||
);
|
||||
drawDynamicUltraText(renderer, LOGO_TEXT_X, TEXT_Y, LOGO_LABEL_FONT_SIZE, STATIC_TEAL, false);
|
||||
|
||||
static const std::string versionStr = "Version " + getVersionString() + " \"Gaea\"";
|
||||
static constexpr tsl::Color versionColor(9, 9, 9, 15);
|
||||
@@ -166,14 +149,12 @@ void BaseGui::preDraw(tsl::gfx::Renderer* renderer) {
|
||||
}
|
||||
}
|
||||
|
||||
tsl::elm::Element* BaseGui::createUI()
|
||||
{
|
||||
BaseFrame* rootFrame = new BaseFrame(this, this->headerHeight());
|
||||
tsl::elm::Element *BaseGui::createUI() {
|
||||
BaseFrame *rootFrame = new BaseFrame(this, this->headerHeight());
|
||||
rootFrame->setContent(this->baseUI());
|
||||
return rootFrame;
|
||||
}
|
||||
|
||||
void BaseGui::update()
|
||||
{
|
||||
void BaseGui::update() {
|
||||
this->refresh();
|
||||
}
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,32 +24,36 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tesla.hpp>
|
||||
#include "../elements/base_frame.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <tesla.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "../style.h"
|
||||
#include "../../ipc.h"
|
||||
#include "../elements/base_frame.h"
|
||||
#include "../style.h"
|
||||
|
||||
class BaseGui : public tsl::Gui
|
||||
{
|
||||
|
||||
class BaseGui : public tsl::Gui {
|
||||
public:
|
||||
BaseGui() {}
|
||||
~BaseGui() {}
|
||||
virtual void preDraw(tsl::gfx::Renderer* renderer);
|
||||
void update() override;
|
||||
tsl::elm::Element* createUI() override;
|
||||
virtual tsl::elm::Element* baseUI() = 0;
|
||||
virtual void refresh() {}
|
||||
virtual u16 headerHeight() const { return HOC_HEADER_HEIGHT; }
|
||||
BaseGui() {
|
||||
}
|
||||
~BaseGui() {
|
||||
}
|
||||
virtual void preDraw(tsl::gfx::Renderer *renderer);
|
||||
void update() override;
|
||||
tsl::elm::Element *createUI() override;
|
||||
virtual tsl::elm::Element *baseUI() = 0;
|
||||
virtual void refresh() {
|
||||
}
|
||||
virtual u16 headerHeight() const {
|
||||
return HOC_HEADER_HEIGHT;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
extern std::string getVersionString();
|
||||
|
||||
@@ -24,23 +24,24 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "../format.h"
|
||||
#include "base_menu_gui.h"
|
||||
#include "fatal_gui.h"
|
||||
#include "../format.h"
|
||||
|
||||
|
||||
#define TOP_Y_OFFSET 15
|
||||
|
||||
// Cache hardware model to avoid repeated syscalls
|
||||
|
||||
BaseMenuGui::BaseMenuGui() : tempColors{ tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), }
|
||||
{
|
||||
BaseMenuGui::BaseMenuGui()
|
||||
: tempColors{
|
||||
tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0), tsl::Color(0),
|
||||
} {
|
||||
tsl::initializeThemeVars();
|
||||
this->context = nullptr;
|
||||
this->lastContextUpdate = 0;
|
||||
this->listElement = nullptr;
|
||||
|
||||
|
||||
// Pre-cache hardware model during initialization
|
||||
IsAula();
|
||||
IsMariko();
|
||||
@@ -51,19 +52,19 @@ BaseMenuGui::BaseMenuGui() : tempColors{ tsl::Color(0), tsl::Color(0), tsl::Colo
|
||||
}
|
||||
|
||||
BaseMenuGui::~BaseMenuGui() {
|
||||
delete this->context; // delete handles nullptr automatically
|
||||
delete this->context; // delete handles nullptr automatically
|
||||
}
|
||||
|
||||
// Fast preDraw - just renders pre-computed strings
|
||||
void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
|
||||
void BaseMenuGui::preDraw(tsl::gfx::Renderer *renderer) {
|
||||
BaseGui::preDraw(renderer);
|
||||
|
||||
// All constants pre-calculated and cached
|
||||
const char* labels[] = {
|
||||
"App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board", "Skin", "Now", "Avg", "BAT", "PMIC", "Fan", IsAula() || this->context->isUsingRetroSuper ? "OLED" : "LCD", "FPS", "RES"
|
||||
};
|
||||
const char *labels[] = { "App ID", "Profile", "CPU", "GPU", "MEM", "SoC", "Board",
|
||||
"Skin", "Now", "Avg", "BAT", "PMIC", "Fan", IsAula() || this->context->isUsingRetroSuper ? "OLED" : "LCD",
|
||||
"FPS", "RES" };
|
||||
|
||||
static constexpr u32 dataPositions[6] = {63-3+3, 200-1, 344-1-3, 200-1, 342-1, 321-1};
|
||||
static constexpr u32 dataPositions[6] = { 63 - 3 + 3, 200 - 1, 344 - 1 - 3, 200 - 1, 342 - 1, 321 - 1 };
|
||||
|
||||
static u32 labelWidths[10];
|
||||
static bool positionsInitialized = false;
|
||||
@@ -74,14 +75,23 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
|
||||
}
|
||||
positionsInitialized = true;
|
||||
}
|
||||
static u32 positions[10] = {24-1, 310-labelWidths[1], 24-1, 192-labelWidths[3], 332-labelWidths[4], 24-1, 192 - labelWidths[6], 332-labelWidths[7], 192 - labelWidths[8], 332-labelWidths[9]};
|
||||
static u32 positions[10] = { 24 - 1,
|
||||
310 - labelWidths[1],
|
||||
24 - 1,
|
||||
192 - labelWidths[3],
|
||||
332 - labelWidths[4],
|
||||
24 - 1,
|
||||
192 - labelWidths[6],
|
||||
332 - labelWidths[7],
|
||||
192 - labelWidths[8],
|
||||
332 - labelWidths[9] };
|
||||
|
||||
static u32 maxProfileValueWidth = renderer->getTextDimensions("USB Charger", false, SMALL_TEXT_SIZE).first; // longest word
|
||||
static u32 maxProfileValueWidth = renderer->getTextDimensions("USB Charger", false, SMALL_TEXT_SIZE).first; // longest word
|
||||
|
||||
u32 y = 91 + TOP_Y_OFFSET;
|
||||
|
||||
// === 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
|
||||
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(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 ===
|
||||
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[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[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 ===
|
||||
|
||||
y += 20; // Direct assignment (149 + 20)
|
||||
y += 20; // Direct assignment (149 + 20)
|
||||
|
||||
// === VOLTAGES ===
|
||||
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[8], false, dataPositions[0], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU voltage
|
||||
renderer->drawString(displayStrings[9], false, dataPositions[1], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU voltage
|
||||
|
||||
renderer->drawStringWithColoredSections(displayStrings[10], false, {""}, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor, tsl::separatorColor);
|
||||
renderer->drawStringWithColoredSections(displayStrings[10], false, { "" }, dataPositions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor,
|
||||
tsl::separatorColor);
|
||||
|
||||
renderer->drawString(displayStrings[19], false, positions[2], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // CPU Usage
|
||||
renderer->drawString(displayStrings[17], false, positions[3], y, SMALL_TEXT_SIZE, tsl::infoTextColor); // GPU Usage
|
||||
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 ===
|
||||
// Labels
|
||||
@@ -141,59 +151,57 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) {
|
||||
|
||||
// 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[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[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
|
||||
|
||||
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
|
||||
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(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
|
||||
|
||||
y+=20;
|
||||
y += 20;
|
||||
|
||||
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(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
|
||||
|
||||
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(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[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(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
|
||||
void BaseMenuGui::refresh()
|
||||
{
|
||||
void BaseMenuGui::refresh() {
|
||||
const u64 ticks = armGetSystemTick();
|
||||
// Use cached comparison - 1 billion nanoseconds
|
||||
if (armTicksToNs(ticks - this->lastContextUpdate) <= 1000000000UL) [[likely]] {
|
||||
return; // Early exit for most calls
|
||||
return; // Early exit for most calls
|
||||
}
|
||||
|
||||
this->lastContextUpdate = ticks;
|
||||
@@ -224,22 +232,22 @@ void BaseMenuGui::refresh()
|
||||
strcpy(displayStrings[1], hocclkFormatProfile(context->profile, true));
|
||||
|
||||
// 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);
|
||||
|
||||
hz = context->freqs[HocClkModule_GPU]; // GPU
|
||||
hz = context->freqs[HocClkModule_GPU]; // GPU
|
||||
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 mhz = hz / 1000000U;
|
||||
std::uint32_t mts = mhz * 2;
|
||||
std::uint32_t tenth = (hz / 100000U) % 10U;
|
||||
if(unit == RamDisplayUnit_MTs)
|
||||
if (unit == RamDisplayUnit_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);
|
||||
else if(unit == RamDisplayUnit_MHzMTs) {
|
||||
else if (unit == RamDisplayUnit_MHzMTs) {
|
||||
hz = context->realFreqs[HocClkModule_MEM];
|
||||
mhz = hz / 1000000U;
|
||||
tenth = (hz / 100000U) % 10U;
|
||||
@@ -247,18 +255,18 @@ void BaseMenuGui::refresh()
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
hz = context->realFreqs[HocClkModule_GPU]; // GPU
|
||||
hz = context->realFreqs[HocClkModule_GPU]; // GPU
|
||||
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];
|
||||
mhz = hz / 1000000U;
|
||||
mts = mhz * 2;
|
||||
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);
|
||||
else
|
||||
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[9], "%.1f mV", context->voltages[HocClkVoltage_GPU] / 1000.0);
|
||||
|
||||
switch(configList.values[HocClkConfigValue_RAMVoltDisplayMode]) {
|
||||
switch (configList.values[HocClkConfigValue_RAMVoltDisplayMode]) {
|
||||
case RamDisplayMode_VDD2:
|
||||
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDD2] / 1000U, (context->voltages[HocClkVoltage_EMCVDD2] % 1000U) / 100U);
|
||||
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDD2] / 1000U,
|
||||
(context->voltages[HocClkVoltage_EMCVDD2] % 1000U) / 100U);
|
||||
break;
|
||||
case RamDisplayMode_VDDQ:
|
||||
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDDQ] / 1000U, (context->voltages[HocClkVoltage_EMCVDDQ] % 1000U) / 100U);
|
||||
sprintf(displayStrings[10], "%u.%u mV", context->voltages[HocClkVoltage_EMCVDDQ] / 1000U,
|
||||
(context->voltages[HocClkVoltage_EMCVDDQ] % 1000U) / 100U);
|
||||
break;
|
||||
default:
|
||||
strcpy(displayStrings[10], "N/A");
|
||||
@@ -280,15 +290,15 @@ void BaseMenuGui::refresh()
|
||||
}
|
||||
|
||||
// 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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
// Power
|
||||
sprintf(displayStrings[15], "%d mW", context->power[0]); // Now
|
||||
sprintf(displayStrings[16], "%d mW", context->power[1]); // Avg
|
||||
sprintf(displayStrings[15], "%d mW", context->power[0]); // Now
|
||||
sprintf(displayStrings[16], "%d mW", context->power[1]); // Avg
|
||||
|
||||
sprintf(displayStrings[17], "%u%%", context->partLoad[HocClkPartLoad_GPU] / 10);
|
||||
sprintf(displayStrings[18], "%u%%", context->partLoad[HocClkPartLoad_EMC] / 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);
|
||||
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[24], "%u%%", context->partLoad[HocClkPartLoad_FAN]);
|
||||
|
||||
sprintf(displayStrings[25], "%u Hz", context->realFreqs[HocClkModule_Display]);
|
||||
if(this->context->isSaltyNXInstalled) {
|
||||
if(context->fps == 254) {
|
||||
if (this->context->isSaltyNXInstalled) {
|
||||
if (context->fps == 254) {
|
||||
strcpy(displayStrings[26], "N/A");
|
||||
} else {
|
||||
memset(displayStrings[26], 0, sizeof(displayStrings[26]));
|
||||
@@ -323,8 +333,8 @@ void BaseMenuGui::refresh()
|
||||
}
|
||||
}
|
||||
|
||||
if(this->context->isSaltyNXInstalled) {
|
||||
if(context->resolutionHeight == 0) {
|
||||
if (this->context->isSaltyNXInstalled) {
|
||||
if (context->resolutionHeight == 0) {
|
||||
strcpy(displayStrings[27], "N/A");
|
||||
} else {
|
||||
memset(displayStrings[27], 0, sizeof(displayStrings[27]));
|
||||
@@ -343,12 +353,10 @@ void BaseMenuGui::refresh()
|
||||
millis = context->temps[HocClkThermalSensor_MEM];
|
||||
sprintf(displayStrings[30], "%u.%u", millis / 1000U, (millis % 1000U) / 100U);
|
||||
tempColors[HocClkThermalSensor_MEM] = tsl::GradientColor(millis * 0.001f);
|
||||
|
||||
}
|
||||
|
||||
tsl::elm::Element* BaseMenuGui::baseUI()
|
||||
{
|
||||
auto* list = new tsl::elm::List();
|
||||
tsl::elm::Element *BaseMenuGui::baseUI() {
|
||||
auto *list = new tsl::elm::List();
|
||||
this->listElement = list;
|
||||
this->listUI();
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,69 +24,66 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../ipc.h"
|
||||
#include "base_gui.h"
|
||||
|
||||
class BaseMenuGui : public BaseGui
|
||||
{
|
||||
class BaseMenuGui : public BaseGui {
|
||||
protected:
|
||||
|
||||
public:
|
||||
// u8 dockedHighestAllowedRefreshRate = 60;
|
||||
HocClkContext* context;
|
||||
std::uint64_t lastContextUpdate;
|
||||
HocClkConfigValueList configList;
|
||||
bool g_hardwareModelCached = false;
|
||||
bool g_isMariko = false;
|
||||
bool g_isAula = false;
|
||||
bool g_isHoag = false;
|
||||
SetSysProductModel HWmodel = SetSysProductModel_Invalid;
|
||||
|
||||
bool IsAula() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isAula = (HWmodel == SetSysProductModel_Aula);
|
||||
return g_isAula;
|
||||
}
|
||||
bool IsHoag() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isHoag = (HWmodel == SetSysProductModel_Hoag);
|
||||
return g_isHoag;
|
||||
}
|
||||
bool IsMariko() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isMariko = (HWmodel == SetSysProductModel_Iowa ||
|
||||
HWmodel == SetSysProductModel_Hoag ||
|
||||
HWmodel == SetSysProductModel_Calcio ||
|
||||
HWmodel == SetSysProductModel_Aula);
|
||||
// u8 dockedHighestAllowedRefreshRate = 60;
|
||||
HocClkContext *context;
|
||||
std::uint64_t lastContextUpdate;
|
||||
HocClkConfigValueList configList;
|
||||
bool g_hardwareModelCached = false;
|
||||
bool g_isMariko = false;
|
||||
bool g_isAula = false;
|
||||
bool g_isHoag = false;
|
||||
SetSysProductModel HWmodel = SetSysProductModel_Invalid;
|
||||
|
||||
return g_isMariko;
|
||||
bool IsAula() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isAula = (HWmodel == SetSysProductModel_Aula);
|
||||
return g_isAula;
|
||||
}
|
||||
bool IsHoag() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isHoag = (HWmodel == SetSysProductModel_Hoag);
|
||||
return g_isHoag;
|
||||
}
|
||||
bool IsMariko() {
|
||||
if (!g_hardwareModelCached) {
|
||||
setsysGetProductModel(&HWmodel);
|
||||
g_hardwareModelCached = true;
|
||||
}
|
||||
g_isMariko = (HWmodel == SetSysProductModel_Iowa || HWmodel == SetSysProductModel_Hoag || HWmodel == SetSysProductModel_Calcio ||
|
||||
HWmodel == SetSysProductModel_Aula);
|
||||
|
||||
bool IsErista() {
|
||||
return !IsMariko();
|
||||
}
|
||||
BaseMenuGui();
|
||||
~BaseMenuGui();
|
||||
void preDraw(tsl::gfx::Renderer* renderer) override;
|
||||
tsl::elm::List* listElement;
|
||||
tsl::elm::Element* baseUI() override;
|
||||
void refresh() override;
|
||||
virtual void listUI() = 0;
|
||||
u16 headerHeight() const override { return HOC_BOX_BOTTOM + 9; }
|
||||
return g_isMariko;
|
||||
}
|
||||
|
||||
bool IsErista() {
|
||||
return !IsMariko();
|
||||
}
|
||||
BaseMenuGui();
|
||||
~BaseMenuGui();
|
||||
void preDraw(tsl::gfx::Renderer *renderer) override;
|
||||
tsl::elm::List *listElement;
|
||||
tsl::elm::Element *baseUI() override;
|
||||
void refresh() override;
|
||||
virtual void listUI() = 0;
|
||||
u16 headerHeight() const override {
|
||||
return HOC_BOX_BOTTOM + 9;
|
||||
}
|
||||
|
||||
private:
|
||||
char displayStrings[48][32]; // Pre-formatted display strings
|
||||
tsl::Color tempColors[HocClkThermalSensor_EnumMax]; // Pre-computed temperature colors
|
||||
char displayStrings[48][32]; // Pre-formatted display strings
|
||||
tsl::Color tempColors[HocClkThermalSensor_EnumMax]; // Pre-computed temperature colors
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,8 +16,9 @@
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "misc_gui.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "misc_gui.h"
|
||||
|
||||
std::vector<std::string> ConfigInfoStrings(HocClkConfigValue val, bool isMariko, bool isHoag);
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,45 +24,37 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "fatal_gui.h"
|
||||
|
||||
FatalGui::FatalGui(const std::string message, const std::string info)
|
||||
{
|
||||
FatalGui::FatalGui(const std::string message, const std::string info) {
|
||||
this->message = message;
|
||||
this->info = info;
|
||||
}
|
||||
|
||||
void FatalGui::openWithResultCode(std::string tag, Result rc)
|
||||
{
|
||||
void FatalGui::openWithResultCode(std::string tag, Result rc) {
|
||||
char rcStr[32];
|
||||
std::string info = tag;
|
||||
info.append(rcStr, snprintf(rcStr, sizeof(rcStr), "\n\n[0x%x] %04d-%04d", rc, R_MODULE(rc), R_DESCRIPTION(rc)));
|
||||
|
||||
tsl::changeTo<FatalGui>(
|
||||
"Could not connect to hoc-clk sysmodule.\n\n"
|
||||
"\n"
|
||||
"Please make sure everything is\n\n"
|
||||
"correctly installed and enabled.",
|
||||
info
|
||||
);
|
||||
tsl::changeTo<FatalGui>("Could not connect to hoc-clk sysmodule.\n\n"
|
||||
"\n"
|
||||
"Please make sure everything is\n\n"
|
||||
"correctly installed and enabled.",
|
||||
info);
|
||||
}
|
||||
|
||||
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::Element *FatalGui::baseUI() {
|
||||
tsl::elm::CustomDrawer *drawer = new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, u16 x, u16 y, u16 w, u16 h) {
|
||||
renderer->drawString("\uE150", false, 40, 210, 40, TEXT_COLOR);
|
||||
renderer->drawString("Fatal error", false, 100, 210, 30, TEXT_COLOR);
|
||||
|
||||
std::uint32_t txtY = 255;
|
||||
if(!this->message.empty())
|
||||
{
|
||||
if (!this->message.empty()) {
|
||||
txtY += renderer->drawString(this->message.c_str(), false, 40, txtY, 23, TEXT_COLOR).second;
|
||||
txtY += 55;
|
||||
}
|
||||
|
||||
if(!this->info.empty())
|
||||
{
|
||||
if (!this->info.empty()) {
|
||||
renderer->drawString(this->info.c_str(), false, 40, txtY, 18, DESC_COLOR);
|
||||
}
|
||||
});
|
||||
@@ -70,11 +62,10 @@ tsl::elm::Element* FatalGui::baseUI()
|
||||
return drawer;
|
||||
}
|
||||
|
||||
bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight)
|
||||
{
|
||||
if((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B)
|
||||
{
|
||||
while(tsl::Overlay::get()->getCurrentGui() != nullptr) {
|
||||
bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft,
|
||||
HidAnalogStickState joyStickPosRight) {
|
||||
if ((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B) {
|
||||
while (tsl::Overlay::get()->getCurrentGui() != nullptr) {
|
||||
tsl::goBack();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,23 +24,23 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "base_gui.h"
|
||||
|
||||
class FatalGui : public BaseGui
|
||||
{
|
||||
class FatalGui : public BaseGui {
|
||||
protected:
|
||||
std::string message;
|
||||
std::string info;
|
||||
std::string message;
|
||||
std::string info;
|
||||
|
||||
public:
|
||||
FatalGui(const std::string message, const std::string info);
|
||||
~FatalGui() {}
|
||||
tsl::elm::Element* baseUI() override;
|
||||
bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight);
|
||||
static void openWithResultCode(std::string tag, Result rc);
|
||||
FatalGui(const std::string message, const std::string info);
|
||||
~FatalGui() {
|
||||
}
|
||||
tsl::elm::Element *baseUI() override;
|
||||
bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft,
|
||||
HidAnalogStickState joyStickPosRight);
|
||||
static void openWithResultCode(std::string tag, Result rc);
|
||||
};
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,21 +24,13 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "ult_ext.h"
|
||||
#include "freq_choice_gui.h"
|
||||
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
#include "freq_choice_gui.h"
|
||||
#include "ult_ext.h"
|
||||
|
||||
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
|
||||
std::uint32_t* hzList,
|
||||
std::uint32_t hzCount,
|
||||
HocClkModule module,
|
||||
FreqChoiceListener listener,
|
||||
bool checkMax,
|
||||
std::map<uint32_t, std::string> labels)
|
||||
{
|
||||
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, HocClkModule module, FreqChoiceListener listener,
|
||||
bool checkMax, std::map<uint32_t, std::string> labels) {
|
||||
this->selectedHz = selectedHz;
|
||||
this->hzList = hzList;
|
||||
this->hzCount = hzCount;
|
||||
@@ -46,18 +38,16 @@ FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
|
||||
this->listener = listener;
|
||||
this->checkMax = checkMax;
|
||||
this->labels = labels;
|
||||
this->configList = new HocClkConfigValueList {};
|
||||
this->configList = new HocClkConfigValueList{};
|
||||
}
|
||||
|
||||
FreqChoiceGui::~FreqChoiceGui()
|
||||
{
|
||||
FreqChoiceGui::~FreqChoiceGui() {
|
||||
delete this->configList;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety)
|
||||
{
|
||||
tsl::elm::ListItem *FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety) {
|
||||
std::string text;
|
||||
if(module == HocClkModule_MEM)
|
||||
if (module == HocClkModule_MEM)
|
||||
text = formatListFreqHzMem(hz, (RamDisplayUnit)this->configList->values[HocClkConfigValue_RamDisplayUnit]);
|
||||
else
|
||||
text = formatListFreqHz(hz);
|
||||
@@ -68,35 +58,32 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
|
||||
rightText = it->second;
|
||||
|
||||
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)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
switch (safety) {
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
// Make annotation grey
|
||||
if (!rightText.empty() && !selected)
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
else if(selected)
|
||||
else if (selected)
|
||||
listItem->setValueColor(tsl::infoTextColor);
|
||||
|
||||
listItem->setClickListener([this, hz](u64 keys)
|
||||
{
|
||||
listItem->setClickListener([this, hz](u64 keys) {
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(hz)) {
|
||||
tsl::goBack();
|
||||
@@ -109,8 +96,7 @@ tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool sel
|
||||
return listItem;
|
||||
}
|
||||
|
||||
void FreqChoiceGui::listUI()
|
||||
{
|
||||
void FreqChoiceGui::listUI() {
|
||||
hocclkIpcGetConfigValues(this->configList);
|
||||
|
||||
// Header based on CPU/GPU/MEM module
|
||||
@@ -118,11 +104,9 @@ void FreqChoiceGui::listUI()
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName));
|
||||
|
||||
// Default option
|
||||
this->listElement->addItem(
|
||||
this->createFreqListItem(0, this->selectedHz == 0, 0));
|
||||
this->listElement->addItem(this->createFreqListItem(0, this->selectedHz == 0, 0));
|
||||
|
||||
for (std::uint32_t i = 0; i < this->hzCount; i++)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < this->hzCount; i++) {
|
||||
std::uint32_t hz = this->hzList[i];
|
||||
uint32_t mhz = hz / 1000000;
|
||||
|
||||
@@ -160,17 +144,14 @@ void FreqChoiceGui::listUI()
|
||||
uint32_t danger_cpu;
|
||||
uint32_t danger_gpu;
|
||||
|
||||
if (IsMariko())
|
||||
{
|
||||
if (IsMariko()) {
|
||||
unsafe_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2398 : 1964;
|
||||
unsafe_gpu = 1229;
|
||||
danger_cpu = this->configList->values[KipConfigValue_marikoCpuUVHigh] ? 2500 : 2398;
|
||||
danger_gpu = 1306;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unsafe_cpu = this->configList->values[KipConfigValue_eristaCpuUV] ? 2092 : 1786;
|
||||
if(this->configList->values[KipConfigValue_eristaGpuUV] == GPUUVLevel_NoUV) {
|
||||
if (this->configList->values[KipConfigValue_eristaGpuUV] == GPUUVLevel_NoUV) {
|
||||
unsafe_gpu = 922;
|
||||
} else {
|
||||
unsafe_gpu = 961;
|
||||
@@ -202,16 +183,9 @@ void FreqChoiceGui::listUI()
|
||||
} else if (moduleName == "mem") {
|
||||
|
||||
safety = 0;
|
||||
|
||||
}
|
||||
|
||||
this->listElement->addItem(
|
||||
this->createFreqListItem(
|
||||
hz,
|
||||
(mhz == this->selectedHz / 1000000),
|
||||
safety
|
||||
)
|
||||
);
|
||||
this->listElement->addItem(this->createFreqListItem(hz, (mhz == this->selectedHz / 1000000), safety));
|
||||
}
|
||||
|
||||
this->listElement->jumpToItem("", "");
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,22 +24,21 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using FreqChoiceListener = std::function<bool(std::uint32_t hz)>;
|
||||
|
||||
class FreqChoiceGui : public BaseMenuGui
|
||||
{
|
||||
protected:
|
||||
HocClkConfigValueList* configList;
|
||||
class FreqChoiceGui : public BaseMenuGui {
|
||||
protected:
|
||||
HocClkConfigValueList *configList;
|
||||
std::uint32_t selectedHz;
|
||||
std::uint32_t* hzList;
|
||||
std::uint32_t *hzList;
|
||||
std::uint32_t hzCount;
|
||||
HocClkModule module;
|
||||
FreqChoiceListener listener;
|
||||
@@ -47,16 +46,11 @@ protected:
|
||||
|
||||
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:
|
||||
FreqChoiceGui(std::uint32_t selectedHz,
|
||||
std::uint32_t* hzList,
|
||||
std::uint32_t hzCount,
|
||||
HocClkModule module,
|
||||
FreqChoiceListener listener,
|
||||
bool checkMax = true,
|
||||
std::map<uint32_t, std::string> labels = {});
|
||||
public:
|
||||
FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, HocClkModule module, FreqChoiceListener listener,
|
||||
bool checkMax = true, std::map<uint32_t, std::string> labels = {});
|
||||
|
||||
~FreqChoiceGui();
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -25,50 +25,33 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "../../ipc.h"
|
||||
#include "base_menu_gui.h"
|
||||
#include "freq_choice_gui.h"
|
||||
#include <string>
|
||||
#include "value_choice_gui.h"
|
||||
class GlobalOverrideGui : public BaseMenuGui
|
||||
{
|
||||
class GlobalOverrideGui : public BaseMenuGui {
|
||||
protected:
|
||||
std::map<HocClkModule, std::tuple<std::string, std::uint32_t, int>> customFormatModules;
|
||||
tsl::elm::ListItem* listItems[HocClkModule_EnumMax];
|
||||
std::uint32_t listHz[HocClkModule_EnumMax];
|
||||
void openFreqChoiceGui(HocClkModule module);
|
||||
void addGovernorSection();
|
||||
void addModuleListItem(HocClkModule module);
|
||||
void addModuleToggleItem(HocClkModule module);
|
||||
void openValueChoiceGui(
|
||||
tsl::elm::ListItem* listItem,
|
||||
std::uint32_t currentValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds,
|
||||
bool enableThresholds,
|
||||
const std::map<std::uint32_t, std::string>& labels,
|
||||
const std::vector<NamedValue>& namedValues,
|
||||
bool showDefaultValue
|
||||
);
|
||||
void addModuleListItemValue(
|
||||
HocClkModule module,
|
||||
const std::string& categoryName,
|
||||
std::uint32_t min,
|
||||
std::uint32_t max,
|
||||
std::uint32_t step,
|
||||
const std::string& suffix,
|
||||
std::uint32_t divisor,
|
||||
int decimalPlaces,
|
||||
ValueThresholds thresholds = {},
|
||||
const std::vector<NamedValue>& namedValues = {},
|
||||
bool showDefaultValue = true
|
||||
);
|
||||
std::map<HocClkModule, std::tuple<std::string, std::uint32_t, int>> customFormatModules;
|
||||
tsl::elm::ListItem *listItems[HocClkModule_EnumMax];
|
||||
std::uint32_t listHz[HocClkModule_EnumMax];
|
||||
void openFreqChoiceGui(HocClkModule module);
|
||||
void addGovernorSection();
|
||||
void addModuleListItem(HocClkModule module);
|
||||
void addModuleToggleItem(HocClkModule module);
|
||||
void openValueChoiceGui(tsl::elm::ListItem *listItem, std::uint32_t currentValue, const ValueRange &range, const std::string &categoryName,
|
||||
ValueChoiceListener listener, const ValueThresholds &thresholds, bool enableThresholds,
|
||||
const std::map<std::uint32_t, std::string> &labels, const std::vector<NamedValue> &namedValues, bool showDefaultValue);
|
||||
void addModuleListItemValue(HocClkModule module, const std::string &categoryName, std::uint32_t min, std::uint32_t max, std::uint32_t step,
|
||||
const std::string &suffix, std::uint32_t divisor, int decimalPlaces, ValueThresholds thresholds = {},
|
||||
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true);
|
||||
|
||||
public:
|
||||
GlobalOverrideGui();
|
||||
~GlobalOverrideGui() {}
|
||||
void listUI() override;
|
||||
void refresh() override;
|
||||
void setModuleCustomFormat(HocClkModule module, const std::string& suffix, std::uint32_t divisor, int decimalPlaces);
|
||||
GlobalOverrideGui();
|
||||
~GlobalOverrideGui() {
|
||||
}
|
||||
void listUI() override;
|
||||
void refresh() override;
|
||||
void setModuleCustomFormat(HocClkModule module, const std::string &suffix, std::uint32_t divisor, int decimalPlaces);
|
||||
};
|
||||
@@ -16,72 +16,70 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "info_gui.h"
|
||||
#include "ult_ext.h"
|
||||
#include <sstream>
|
||||
|
||||
InfoGui::InfoGui(std::string title, std::vector<std::string> strings)
|
||||
: m_title(std::move(title)), m_strings(std::move(strings)) {}
|
||||
#include "info_gui.h"
|
||||
#include "ult_ext.h"
|
||||
|
||||
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;
|
||||
InfoGui::InfoGui(std::string title, std::vector<std::string> strings) : m_title(std::move(title)), m_strings(std::move(strings)) {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Preserve leading whitespace as an indent prefix for wrapped continuation lines.
|
||||
std::string indent;
|
||||
for (char c : text) {
|
||||
if (c == ' ') indent += ' ';
|
||||
else break;
|
||||
if (c == ' ')
|
||||
indent += ' ';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
std::vector<std::string> lines;
|
||||
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;
|
||||
while (ss >> word) {
|
||||
std::string candidate = (first && !indent.empty()) ? indent + word
|
||||
: line.empty() ? word
|
||||
: line + " " + word;
|
||||
std::string candidate = (first && !indent.empty()) ? indent + word : line.empty() ? word : line + " " + word;
|
||||
first = false;
|
||||
if (static_cast<s32>(candidate.size() * CHAR_W) <= maxWidth)
|
||||
line = std::move(candidate);
|
||||
else {
|
||||
if (!line.empty() && line != indent) lines.push_back(line);
|
||||
if (!line.empty() && line != indent)
|
||||
lines.push_back(line);
|
||||
line = indent + word;
|
||||
}
|
||||
}
|
||||
if (!line.empty() && line != indent) lines.push_back(line);
|
||||
if (lines.empty()) lines.emplace_back("");
|
||||
if (!line.empty() && line != indent)
|
||||
lines.push_back(line);
|
||||
if (lines.empty())
|
||||
lines.emplace_back("");
|
||||
return lines;
|
||||
}
|
||||
|
||||
void InfoGui::listUI()
|
||||
{
|
||||
void InfoGui::listUI() {
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(m_title));
|
||||
|
||||
const s32 maxWidth = tsl::cfg::FramebufferWidth - MARGIN_L - MARGIN_R;
|
||||
|
||||
for (const auto& para : m_strings) {
|
||||
for (const auto& lineText : wrapText(para, maxWidth)) {
|
||||
auto* d = new FocusableDrawer(
|
||||
[lineText](tsl::gfx::Renderer* r, s32 x, s32 y, s32 w, s32 h) {
|
||||
r->drawString((lineText + "\n").c_str(), false,
|
||||
x + MARGIN_L, y + LINE_H - 5,
|
||||
TEXT_SIZE, tsl::style::color::ColorText);
|
||||
});
|
||||
for (const auto ¶ : m_strings) {
|
||||
for (const auto &lineText : wrapText(para, maxWidth)) {
|
||||
auto *d = new FocusableDrawer([lineText](tsl::gfx::Renderer *r, s32 x, s32 y, s32 w, s32 h) {
|
||||
r->drawString((lineText + "\n").c_str(), false, x + MARGIN_L, y + LINE_H - 5, TEXT_SIZE, tsl::style::color::ColorText);
|
||||
});
|
||||
d->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, LINE_H);
|
||||
this->listElement->addItem(d, LINE_H);
|
||||
}
|
||||
|
||||
// paragraph gap
|
||||
auto* gap = new tsl::elm::CustomDrawer(
|
||||
[](tsl::gfx::Renderer*, s32, s32, s32, s32) {});
|
||||
auto *gap = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *, s32, s32, s32, s32) {});
|
||||
gap->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, PARA_GAP);
|
||||
this->listElement->addItem(gap, PARA_GAP);
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "base_menu_gui.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class InfoGui : public BaseMenuGui
|
||||
{
|
||||
public:
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
class InfoGui : public BaseMenuGui {
|
||||
public:
|
||||
InfoGui(std::string title, std::vector<std::string> strings);
|
||||
~InfoGui() = default;
|
||||
void listUI() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string m_title;
|
||||
std::vector<std::string> m_strings;
|
||||
};
|
||||
|
||||
@@ -12,140 +12,73 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
std::map<uint32_t, std::string> cpu_freq_label_m = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Boost Mode"},
|
||||
{1963000000, "Safe Max"},
|
||||
{2397000000, "Unsafe Max"},
|
||||
{2703000000, "Absolute Max"},
|
||||
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
|
||||
{ 1963000000, "Safe Max" }, { 2397000000, "Unsafe Max" }, { 2703000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> cpu_freq_label_m_uv = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Boost Mode"},
|
||||
{2397000000, "Safe Max"},
|
||||
{2499000000, "Unsafe Max"},
|
||||
{2703000000, "Absolute Max"},
|
||||
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
|
||||
{ 2397000000, "Safe Max" }, { 2499000000, "Unsafe Max" }, { 2703000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> cpu_freq_label_e = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Safe Max"},
|
||||
{2091000000, "Unsafe Max"},
|
||||
{2397000000, "Absolute Max"},
|
||||
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" },
|
||||
{ 1785000000, "Safe Max" }, { 2091000000, "Unsafe Max" }, { 2397000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> cpu_freq_label_e_uv = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Boost Mode"},
|
||||
{2091000000, "Safe Max"},
|
||||
{2193000000, "Unsafe Max"},
|
||||
{2397000000, "Absolute Max"},
|
||||
{ 612000000, "Sleep Mode" }, { 1020000000, "Stock" }, { 1224000000, "Dev OC" }, { 1785000000, "Boost Mode" },
|
||||
{ 2091000000, "Safe Max" }, { 2193000000, "Unsafe Max" }, { 2397000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_e = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{345600000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{422400000, "Handheld"},
|
||||
{460800000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{921600000, "Safe Max"},
|
||||
{960000000, "Unsafe Max"},
|
||||
{1075200000, "Absolute Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
|
||||
{ 422400000, "Handheld" }, { 460800000, "Handheld Safe Max" }, { 768000000, "Docked" }, { 921600000, "Safe Max" },
|
||||
{ 960000000, "Unsafe Max" }, { 1075200000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_e_uv = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{345600000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{422400000, "Handheld"},
|
||||
{460800000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{960000000, "Safe Max"},
|
||||
{1075200000, "Absolute Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" },
|
||||
{ 384000000, "Handheld" }, { 422400000, "Handheld" }, { 460800000, "Handheld Safe Max" },
|
||||
{ 768000000, "Docked" }, { 960000000, "Safe Max" }, { 1075200000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_m = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{345600000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{422400000, "Handheld"},
|
||||
{460800000, "Handheld"},
|
||||
{614400000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{998400000, "Safe Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" }, { 422400000, "Handheld" },
|
||||
{ 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" }, { 998400000, "Safe Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_m_slt = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{345600000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{422400000, "Handheld"},
|
||||
{460800000, "Handheld"},
|
||||
{614400000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{1075200000, "Safe Max"},
|
||||
{1305600000, "Unsafe Max"},
|
||||
{1536000000, "Absolute Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
|
||||
{ 422400000, "Handheld" }, { 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
|
||||
{ 1075200000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_m_hiopt = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{345600000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{422400000, "Handheld"},
|
||||
{460800000, "Handheld"},
|
||||
{614400000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{1152000000, "Safe Max"},
|
||||
{1305600000, "Unsafe Max"},
|
||||
{1536000000, "Absolute Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 345600000, "Handheld" }, { 384000000, "Handheld" },
|
||||
{ 422400000, "Handheld" }, { 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
|
||||
{ 1152000000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_m_highuv = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{460800000, "Handheld"},
|
||||
{614400000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{1228800000, "Safe Max"},
|
||||
{1305600000, "Unsafe Max"},
|
||||
{1536000000, "Absolute Max"},
|
||||
{ 76800000, "Boost Mode" }, { 307200000, "Handheld" }, { 384000000, "Handheld" },
|
||||
{ 460800000, "Handheld" }, { 614400000, "Handheld Safe Max" }, { 768000000, "Docked" },
|
||||
{ 1228800000, "Safe Max" }, { 1305600000, "Unsafe Max" }, { 1536000000, "Absolute Max" },
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string>* marikoUV[5] {
|
||||
&gpu_freq_label_m,
|
||||
&gpu_freq_label_m_slt,
|
||||
&gpu_freq_label_m_hiopt,
|
||||
&gpu_freq_label_m_hiopt,
|
||||
&gpu_freq_label_m_highuv,
|
||||
std::map<uint32_t, std::string> *marikoUV[5]{
|
||||
&gpu_freq_label_m, &gpu_freq_label_m_slt, &gpu_freq_label_m_hiopt, &gpu_freq_label_m_hiopt, &gpu_freq_label_m_highuv,
|
||||
};
|
||||
|
||||
|
||||
std::map<uint32_t, std::string>* eristaUV[3] {
|
||||
std::map<uint32_t, std::string> *eristaUV[3]{
|
||||
&gpu_freq_label_e,
|
||||
&gpu_freq_label_e_uv,
|
||||
&gpu_freq_label_e_uv,
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -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 "app_profile_gui.h"
|
||||
#include "fatal_gui.h"
|
||||
#include "global_override_gui.h"
|
||||
#include "main_gui.h"
|
||||
#include "misc_gui.h"
|
||||
#include "ult_ext.h"
|
||||
|
||||
tsl::elm::Element* MainGui::baseUI() {
|
||||
auto* list = new BoxClippedList();
|
||||
|
||||
tsl::elm::Element *MainGui::baseUI() {
|
||||
auto *list = new BoxClippedList();
|
||||
this->listElement = list;
|
||||
this->listUI();
|
||||
return list;
|
||||
}
|
||||
|
||||
void MainGui::listUI()
|
||||
{
|
||||
void MainGui::listUI() {
|
||||
// this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false);
|
||||
// enabledToggle->setStateChangedListener([this](bool state) {
|
||||
// Result rc = hocclkIpcSetEnabled(state);
|
||||
@@ -56,10 +54,9 @@ void MainGui::listUI()
|
||||
// });
|
||||
// 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) {
|
||||
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
|
||||
AppProfileGui::changeTo(this->context->applicationId);
|
||||
return true;
|
||||
}
|
||||
@@ -68,11 +65,9 @@ void MainGui::listUI()
|
||||
});
|
||||
this->listElement->addItem(appProfileItem);
|
||||
|
||||
|
||||
tsl::elm::ListItem* globalProfileItem = new tsl::elm::ListItem("Edit Global Profile");
|
||||
tsl::elm::ListItem *globalProfileItem = new tsl::elm::ListItem("Edit Global Profile");
|
||||
globalProfileItem->setClickListener([this](u64 keys) {
|
||||
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
|
||||
AppProfileGui::changeTo(HOCCLK_GLOBAL_PROFILE_TID);
|
||||
return true;
|
||||
}
|
||||
@@ -81,10 +76,9 @@ void MainGui::listUI()
|
||||
});
|
||||
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) {
|
||||
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
|
||||
tsl::changeTo<GlobalOverrideGui>();
|
||||
return true;
|
||||
}
|
||||
@@ -93,12 +87,11 @@ void MainGui::listUI()
|
||||
});
|
||||
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) {
|
||||
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
|
||||
tsl::changeTo<MiscGui>();
|
||||
return true;
|
||||
}
|
||||
@@ -107,10 +100,9 @@ void MainGui::listUI()
|
||||
});
|
||||
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) {
|
||||
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->context) {
|
||||
tsl::changeTo<AboutGui>();
|
||||
return true;
|
||||
}
|
||||
@@ -118,14 +110,12 @@ void MainGui::listUI()
|
||||
return false;
|
||||
});
|
||||
this->listElement->addItem(aboutItem);
|
||||
|
||||
}
|
||||
|
||||
void MainGui::refresh()
|
||||
{
|
||||
void MainGui::refresh() {
|
||||
BaseMenuGui::refresh();
|
||||
//if(this->context)
|
||||
// if(this->context)
|
||||
//{
|
||||
// this->enabledToggle->setState(this->context->enabled);
|
||||
//}
|
||||
// this->enabledToggle->setState(this->context->enabled);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,18 +24,20 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
class MainGui : public BaseMenuGui
|
||||
{
|
||||
class MainGui : public BaseMenuGui {
|
||||
public:
|
||||
MainGui() {}
|
||||
~MainGui() {}
|
||||
tsl::elm::Element* baseUI() override;
|
||||
void listUI() override;
|
||||
void refresh() override;
|
||||
u16 headerHeight() const override { return HOC_HEADER_HEIGHT - 25; }
|
||||
MainGui() {
|
||||
}
|
||||
~MainGui() {
|
||||
}
|
||||
tsl::elm::Element *baseUI() override;
|
||||
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
@@ -16,67 +16,51 @@
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../../ipc.h"
|
||||
#include "base_menu_gui.h"
|
||||
#include <initializer_list>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../../ipc.h"
|
||||
#include "base_menu_gui.h"
|
||||
#include "freq_choice_gui.h"
|
||||
#include "value_choice_gui.h"
|
||||
#include "info_gui.h"
|
||||
class MiscGui : public BaseMenuGui
|
||||
{
|
||||
public:
|
||||
#include "value_choice_gui.h"
|
||||
#include <initializer_list>
|
||||
#include <unordered_map>
|
||||
class MiscGui : public BaseMenuGui {
|
||||
public:
|
||||
MiscGui();
|
||||
~MiscGui();
|
||||
void listUI() override;
|
||||
void refresh() override;
|
||||
|
||||
protected:
|
||||
HocClkConfigValueList* configList;
|
||||
std::map<HocClkConfigValue, tsl::elm::ListItem*> configButtons;
|
||||
protected:
|
||||
HocClkConfigValueList *configList;
|
||||
std::map<HocClkConfigValue, tsl::elm::ListItem *> configButtons;
|
||||
std::map<HocClkConfigValue, ValueRange> configRanges;
|
||||
std::map<HocClkConfigValue, std::vector<NamedValue>> configNamedValues;
|
||||
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, tsl::elm::ToggleListItem *> configToggles;
|
||||
std::map<HocClkConfigValue, std::tuple<tsl::elm::TrackBar *, tsl::elm::ListItem *, std::vector<uint64_t>>> configTrackbars;
|
||||
std::set<HocClkConfigValue> configButtonSKeys;
|
||||
std::map<HocClkConfigValue, std::string> configButtonSSubtext;
|
||||
std::set<HocClkConfigValue> emcClockConfigs;
|
||||
|
||||
void addConfigToggle(HocClkConfigValue configVal, const char* altName, bool kip = false);
|
||||
void addConfigTrackbar(HocClkConfigValue configVal, const char* altName, const ValueRange& range, bool kip = true);
|
||||
void addMappedConfigTrackbar(HocClkConfigValue configVal, const char* altName,
|
||||
std::vector<u32> vals,
|
||||
std::initializer_list<std::string> names, bool kip = true);
|
||||
void addConfigButton(HocClkConfigValue configVal,
|
||||
const char* altName,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels = {},
|
||||
const std::vector<NamedValue>& namedValues = {},
|
||||
bool showDefaultValue = true,
|
||||
bool kip = false);
|
||||
void addConfigToggle(HocClkConfigValue configVal, const char *altName, bool kip = false);
|
||||
void addConfigTrackbar(HocClkConfigValue configVal, const char *altName, const ValueRange &range, bool kip = true);
|
||||
void addMappedConfigTrackbar(HocClkConfigValue configVal, const char *altName, std::vector<u32> vals, std::initializer_list<std::string> names,
|
||||
bool kip = true);
|
||||
void addConfigButton(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
|
||||
const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
|
||||
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, bool kip = false);
|
||||
|
||||
void addConfigButtonS(HocClkConfigValue configVal,
|
||||
const char* altName,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels = {},
|
||||
const std::vector<NamedValue>& namedValues = {},
|
||||
bool showDefaultValue = true,
|
||||
const char* subText = nullptr,
|
||||
bool kip = false);
|
||||
void addFreqButton(HocClkConfigValue configVal,
|
||||
const char* altName,
|
||||
HocClkModule module,
|
||||
const std::map<uint32_t, std::string>& labels = {});
|
||||
void addConfigButtonS(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
|
||||
const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
|
||||
const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, const char *subText = nullptr,
|
||||
bool kip = false);
|
||||
void addFreqButton(HocClkConfigValue configVal, const char *altName, HocClkModule module, const std::map<uint32_t, std::string> &labels = {});
|
||||
void updateConfigToggles();
|
||||
|
||||
tsl::elm::ToggleListItem* enabledToggle;
|
||||
tsl::elm::ToggleListItem *enabledToggle;
|
||||
u8 frameCounter = 60;
|
||||
bool shouldSaveKip = false;
|
||||
};
|
||||
|
||||
@@ -12,20 +12,24 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <tesla.hpp>
|
||||
|
||||
#include "../elements/base_frame.h"
|
||||
|
||||
|
||||
class TopAnchoredList : public tsl::elm::List {
|
||||
public:
|
||||
TopAnchoredList() { m_hasSetInitialFocusHack = true; }
|
||||
public:
|
||||
TopAnchoredList() {
|
||||
m_hasSetInitialFocusHack = true;
|
||||
}
|
||||
};
|
||||
class BoxClippedList : public tsl::elm::List {
|
||||
public:
|
||||
void draw(tsl::gfx::Renderer* renderer) override {
|
||||
public:
|
||||
void draw(tsl::gfx::Renderer *renderer) override {
|
||||
renderer->enableScissoring(0, HOC_BOX_BOTTOM, tsl::cfg::FramebufferWidth, tsl::cfg::FramebufferHeight - HOC_BOX_BOTTOM);
|
||||
tsl::elm::List::draw(renderer);
|
||||
renderer->disableScissoring();
|
||||
@@ -33,41 +37,37 @@ public:
|
||||
};
|
||||
|
||||
class CompactCategoryHeader : public tsl::elm::CategoryHeader {
|
||||
public:
|
||||
CompactCategoryHeader(const std::string& text) : tsl::elm::CategoryHeader(text) {}
|
||||
public:
|
||||
CompactCategoryHeader(const std::string &text) : tsl::elm::CategoryHeader(text) {
|
||||
}
|
||||
void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
|
||||
this->setBoundaries(this->getX(), this->getY(), this->getWidth(), 33);
|
||||
}
|
||||
};
|
||||
|
||||
class ImageElement : public tsl::elm::ListItem {
|
||||
private:
|
||||
const uint8_t* imgData;
|
||||
private:
|
||||
const uint8_t *imgData;
|
||||
uint32_t imgWidth, imgHeight;
|
||||
bool visible;
|
||||
|
||||
public:
|
||||
ImageElement(const uint8_t* data, uint32_t w, uint32_t h)
|
||||
: tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {}
|
||||
|
||||
|
||||
public:
|
||||
ImageElement(const uint8_t *data, uint32_t w, uint32_t h) : tsl::elm::ListItem(""), imgData(data), imgWidth(w), imgHeight(h), visible(true) {
|
||||
}
|
||||
|
||||
void setVisible(bool v) {
|
||||
visible = v;
|
||||
}
|
||||
|
||||
|
||||
virtual void draw(tsl::gfx::Renderer *renderer) override {
|
||||
if (!visible) return;
|
||||
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
// Draw image centered horizontally
|
||||
u16 centerX = this->getX() + (this->getWidth() - imgWidth) / 2;
|
||||
renderer->drawBitmap(
|
||||
centerX,
|
||||
this->getY() + 10,
|
||||
imgWidth,
|
||||
imgHeight,
|
||||
imgData
|
||||
);
|
||||
renderer->drawBitmap(centerX, this->getY() + 10, imgWidth, imgHeight, imgData);
|
||||
}
|
||||
|
||||
|
||||
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
|
||||
if (!visible) {
|
||||
// Take up no space when hidden
|
||||
@@ -77,37 +77,38 @@ public:
|
||||
tsl::elm::ListItem::layout(parentX, parentY, parentWidth, parentHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void drawHighlight(tsl::gfx::Renderer *renderer) override {
|
||||
// Do nothing - no highlight
|
||||
}
|
||||
|
||||
|
||||
virtual bool onClick(u64 keys) override {
|
||||
return false; // Non-clickable
|
||||
return false; // Non-clickable
|
||||
}
|
||||
|
||||
virtual Element* requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
|
||||
return nullptr; // Make it non-focusable
|
||||
|
||||
virtual Element *requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
|
||||
return nullptr; // Make it non-focusable
|
||||
}
|
||||
};
|
||||
|
||||
class HideableCategoryHeader : public tsl::elm::CategoryHeader {
|
||||
private:
|
||||
private:
|
||||
bool visible;
|
||||
|
||||
public:
|
||||
HideableCategoryHeader(const std::string& title)
|
||||
: tsl::elm::CategoryHeader(title), visible(true) {}
|
||||
|
||||
|
||||
public:
|
||||
HideableCategoryHeader(const std::string &title) : tsl::elm::CategoryHeader(title), visible(true) {
|
||||
}
|
||||
|
||||
void setVisible(bool v) {
|
||||
visible = v;
|
||||
}
|
||||
|
||||
|
||||
virtual void draw(tsl::gfx::Renderer *renderer) override {
|
||||
if (!visible) return;
|
||||
if (!visible)
|
||||
return;
|
||||
tsl::elm::CategoryHeader::draw(renderer);
|
||||
}
|
||||
|
||||
|
||||
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
|
||||
if (!visible) {
|
||||
this->setBoundaries(parentX, parentY, 0, 0);
|
||||
@@ -118,34 +119,34 @@ public:
|
||||
};
|
||||
|
||||
class FocusableDrawer : public tsl::elm::CustomDrawer {
|
||||
public:
|
||||
template<typename... Args>
|
||||
FocusableDrawer(Args&&... args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
|
||||
public:
|
||||
template <typename... Args> FocusableDrawer(Args &&...args) : tsl::elm::CustomDrawer(std::forward<Args>(args)...) {
|
||||
m_isItem = true;
|
||||
}
|
||||
Element* requestFocus(Element*, tsl::FocusDirection) override {
|
||||
Element *requestFocus(Element *, tsl::FocusDirection) override {
|
||||
return this;
|
||||
}
|
||||
void drawHighlight(tsl::gfx::Renderer*) override {}
|
||||
void drawHighlight(tsl::gfx::Renderer *) override {
|
||||
}
|
||||
};
|
||||
|
||||
class HideableCustomDrawer : public tsl::elm::Element {
|
||||
private:
|
||||
private:
|
||||
bool visible;
|
||||
u32 height;
|
||||
|
||||
public:
|
||||
HideableCustomDrawer(u32 h)
|
||||
: Element(), visible(true), height(h) {}
|
||||
|
||||
|
||||
public:
|
||||
HideableCustomDrawer(u32 h) : Element(), visible(true), height(h) {
|
||||
}
|
||||
|
||||
void setVisible(bool v) {
|
||||
visible = v;
|
||||
}
|
||||
|
||||
|
||||
virtual void draw(tsl::gfx::Renderer *renderer) override {
|
||||
// Empty drawer - just for spacing
|
||||
}
|
||||
|
||||
|
||||
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
|
||||
if (!visible) {
|
||||
this->setBoundaries(parentX, parentY, 0, 0);
|
||||
@@ -153,8 +154,8 @@ public:
|
||||
this->setBoundaries(parentX, parentY, parentWidth, height);
|
||||
}
|
||||
}
|
||||
|
||||
virtual Element* requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
|
||||
|
||||
virtual Element *requestFocus(Element *oldFocus, tsl::FocusDirection direction) override {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
@@ -16,44 +16,27 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "ult_ext.h"
|
||||
#include "value_choice_gui.h"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include "ult_ext.h"
|
||||
#include "value_choice_gui.h"
|
||||
|
||||
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds,
|
||||
bool enableThresholds,
|
||||
std::map<std::uint32_t, std::string> labels,
|
||||
std::vector<NamedValue> namedValues,
|
||||
bool showDefaultValue,
|
||||
bool showDNO)
|
||||
: selectedValue(selectedValue),
|
||||
range(range),
|
||||
categoryName(categoryName),
|
||||
listener(listener),
|
||||
thresholds(thresholds),
|
||||
enableThresholds(enableThresholds),
|
||||
labels(labels),
|
||||
namedValues(namedValues),
|
||||
showDefaultValue(showDefaultValue),
|
||||
showDNO(showDNO)
|
||||
{
|
||||
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
|
||||
const ValueThresholds &thresholds, bool enableThresholds, std::map<std::uint32_t, std::string> labels,
|
||||
std::vector<NamedValue> namedValues, bool showDefaultValue, bool showDNO)
|
||||
: selectedValue(selectedValue), range(range), categoryName(categoryName), listener(listener), thresholds(thresholds),
|
||||
enableThresholds(enableThresholds), labels(labels), namedValues(namedValues), showDefaultValue(showDefaultValue), showDNO(showDNO) {
|
||||
}
|
||||
|
||||
ValueChoiceGui::~ValueChoiceGui()
|
||||
{
|
||||
ValueChoiceGui::~ValueChoiceGui() {
|
||||
}
|
||||
|
||||
std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
{
|
||||
std::string ValueChoiceGui::formatValue(std::uint32_t value) {
|
||||
std::ostringstream oss;
|
||||
if(showDefaultValue) {
|
||||
if (showDefaultValue) {
|
||||
if (value == 0) {
|
||||
return this->showDNO ? FREQ_DEFAULT_TEXT : VALUE_DEFAULT_TEXT;
|
||||
}
|
||||
@@ -66,12 +49,11 @@ std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
|
||||
{
|
||||
if(thresholds.warning == 0 && thresholds.danger == 0) {
|
||||
int ValueChoiceGui::getSafetyLevel(std::uint32_t value) {
|
||||
if (thresholds.warning == 0 && thresholds.danger == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (value > thresholds.danger) {
|
||||
return 2;
|
||||
}
|
||||
@@ -81,8 +63,7 @@ int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety)
|
||||
{
|
||||
tsl::elm::ListItem *ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety) {
|
||||
std::string text = formatValue(value);
|
||||
std::string rightText = "";
|
||||
|
||||
@@ -92,34 +73,32 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
|
||||
}
|
||||
|
||||
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);
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, rightText, false);
|
||||
switch (safety) {
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
// Make annotation grey
|
||||
if (!rightText.empty() && !selected)
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
else if(selected)
|
||||
listItem->setValueColor(tsl::infoTextColor);
|
||||
|
||||
listItem->setClickListener([this, value](u64 keys)
|
||||
{
|
||||
else if (selected)
|
||||
listItem->setValueColor(tsl::infoTextColor);
|
||||
|
||||
listItem->setClickListener([this, value](u64 keys) {
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(value)) {
|
||||
tsl::goBack();
|
||||
@@ -131,37 +110,34 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
|
||||
return listItem;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& namedValue, bool selected, int safety)
|
||||
{
|
||||
tsl::elm::ListItem *ValueChoiceGui::createNamedValueListItem(const NamedValue &namedValue, bool selected, int safety) {
|
||||
std::string text = namedValue.name;
|
||||
if (selected) {
|
||||
const_cast<std::string&>(namedValue.rightText) = "\uE14B";
|
||||
const_cast<std::string &>(namedValue.rightText) = "\uE14B";
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, namedValue.rightText, false);
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
|
||||
tsl::elm::ListItem *listItem = new tsl::elm::ListItem(text, namedValue.rightText, false);
|
||||
switch (safety) {
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!namedValue.rightText.empty() && !selected)
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
else if(selected)
|
||||
listItem->setValueColor(tsl::infoTextColor);
|
||||
else if (selected)
|
||||
listItem->setValueColor(tsl::infoTextColor);
|
||||
|
||||
listItem->setClickListener([this, value = namedValue.value](u64 keys)
|
||||
{
|
||||
listItem->setClickListener([this, value = namedValue.value](u64 keys) {
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(value)) {
|
||||
tsl::goBack();
|
||||
@@ -173,8 +149,7 @@ tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& n
|
||||
return listItem;
|
||||
}
|
||||
|
||||
void ValueChoiceGui::listUI()
|
||||
{
|
||||
void ValueChoiceGui::listUI() {
|
||||
if (!categoryName.empty()) {
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
|
||||
}
|
||||
@@ -182,20 +157,19 @@ void ValueChoiceGui::listUI()
|
||||
if (showDefaultValue) {
|
||||
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;
|
||||
bool selected = (namedValue.value == this->selectedValue);
|
||||
this->listElement->addItem(this->createNamedValueListItem(namedValue, selected, safety));
|
||||
}
|
||||
|
||||
|
||||
if (namedValues.empty()) {
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
|
||||
{
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step) {
|
||||
int safety = getSafetyLevel(value);
|
||||
bool selected = (value == this->selectedValue);
|
||||
this->listElement->addItem(this->createValueListItem(value, selected, safety));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this->listElement->jumpToItem("", "\uE14B");
|
||||
}
|
||||
@@ -17,11 +17,12 @@
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
|
||||
@@ -34,33 +35,32 @@ struct ValueRange {
|
||||
std::string suffix;
|
||||
std::uint32_t divisor;
|
||||
int decimalPlaces;
|
||||
ValueRange()
|
||||
: min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {}
|
||||
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step,
|
||||
const std::string& suffix = "", std::uint32_t divisor = 1, int decimalPlaces = 0)
|
||||
: min(min), max(max), step(step), suffix(suffix),
|
||||
divisor(divisor), decimalPlaces(decimalPlaces) {}
|
||||
ValueRange() : min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {
|
||||
}
|
||||
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step, const std::string &suffix = "", std::uint32_t divisor = 1,
|
||||
int decimalPlaces = 0)
|
||||
: min(min), max(max), step(step), suffix(suffix), divisor(divisor), decimalPlaces(decimalPlaces) {
|
||||
}
|
||||
};
|
||||
|
||||
struct ValueThresholds {
|
||||
std::uint32_t warning;
|
||||
std::uint32_t danger;
|
||||
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0)
|
||||
: warning(warning), danger(danger) {}
|
||||
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0) : warning(warning), danger(danger) {
|
||||
}
|
||||
};
|
||||
|
||||
struct NamedValue {
|
||||
std::string name;
|
||||
std::uint32_t value;
|
||||
std::string rightText;
|
||||
|
||||
NamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
|
||||
: name(name), value(value), rightText(rightText) {}
|
||||
|
||||
NamedValue(const std::string &name, std::uint32_t value, const std::string &rightText = "") : name(name), value(value), rightText(rightText) {
|
||||
}
|
||||
};
|
||||
|
||||
class ValueChoiceGui : public BaseMenuGui
|
||||
{
|
||||
protected:
|
||||
class ValueChoiceGui : public BaseMenuGui {
|
||||
protected:
|
||||
std::uint32_t selectedValue;
|
||||
ValueRange range;
|
||||
std::string categoryName;
|
||||
@@ -68,47 +68,37 @@ protected:
|
||||
ValueThresholds thresholds;
|
||||
bool enableThresholds;
|
||||
std::map<std::uint32_t, std::string> labels;
|
||||
|
||||
|
||||
std::vector<NamedValue> namedValues;
|
||||
bool showDefaultValue = true;
|
||||
bool showDNO = false;
|
||||
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 *createValueListItem(std::uint32_t value, bool selected, int safety);
|
||||
tsl::elm::ListItem *createNamedValueListItem(const NamedValue &namedValue, bool selected, int safety);
|
||||
std::string formatValue(std::uint32_t value);
|
||||
int getSafetyLevel(std::uint32_t value);
|
||||
|
||||
public:
|
||||
ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds = ValueThresholds(),
|
||||
bool enableThresholds = false,
|
||||
std::map<std::uint32_t, std::string> labels = {},
|
||||
std::vector<NamedValue> namedValues = {},
|
||||
bool showDefaultValue = true,
|
||||
|
||||
public:
|
||||
ValueChoiceGui(std::uint32_t selectedValue, const ValueRange &range, const std::string &categoryName, ValueChoiceListener listener,
|
||||
const ValueThresholds &thresholds = ValueThresholds(), bool enableThresholds = false,
|
||||
std::map<std::uint32_t, std::string> labels = {}, std::vector<NamedValue> namedValues = {}, bool showDefaultValue = true,
|
||||
bool showDNO = false);
|
||||
~ValueChoiceGui();
|
||||
|
||||
void addNamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
|
||||
{
|
||||
|
||||
void addNamedValue(const std::string &name, std::uint32_t value, const std::string &rightText = "") {
|
||||
namedValues.emplace_back(name, value, rightText);
|
||||
}
|
||||
|
||||
void addNamedValues(const std::vector<NamedValue>& values)
|
||||
{
|
||||
|
||||
void addNamedValues(const std::vector<NamedValue> &values) {
|
||||
namedValues.insert(namedValues.end(), values.begin(), values.end());
|
||||
}
|
||||
|
||||
void clearNamedValues()
|
||||
{
|
||||
|
||||
void clearNamedValues() {
|
||||
namedValues.clear();
|
||||
}
|
||||
|
||||
void setShowDefaultValue(bool show)
|
||||
{
|
||||
|
||||
void setShowDefaultValue(bool show) {
|
||||
showDefaultValue = show;
|
||||
}
|
||||
|
||||
|
||||
void listUI() override;
|
||||
};
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,7 +24,6 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tesla.hpp>
|
||||
|
||||
@@ -24,31 +24,32 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <tmp451.h>
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include <battery.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
#include <i2c.h>
|
||||
#include <max17050.h>
|
||||
#include <notification.h>
|
||||
#include <pwm.h>
|
||||
#include <registers.h>
|
||||
#include <battery.h>
|
||||
#include "../display/display_refresh_rate.hpp"
|
||||
#include <notification.h>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../display/display_refresh_rate.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "../hos/integrations.hpp"
|
||||
#include "../hos/rgltr.h"
|
||||
#include "../tsensor/aotag.hpp"
|
||||
#include "../tsensor/soctherm.hpp"
|
||||
#include "board.hpp"
|
||||
#include "board_fuse.hpp"
|
||||
#include "board_load.hpp"
|
||||
#include "board_volt.hpp"
|
||||
#include "board_misc.hpp"
|
||||
#include "../tsensor/soctherm.hpp"
|
||||
#include "../tsensor/aotag.hpp"
|
||||
#include "../hos/integrations.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../hos/rgltr.h"
|
||||
#include "board_volt.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr;
|
||||
@@ -62,25 +63,25 @@ namespace board {
|
||||
|
||||
u32 fd = 0, fd2 = 0;
|
||||
|
||||
#define PMC_BASE 0x7000E400
|
||||
#define APB_MISC_GP_HIDREV 0x804
|
||||
#define GP_HIDREV_MAJOR_T210 0x1
|
||||
#define GP_HIDREV_MAJOR_T210B01 0x2
|
||||
#define APB_BASE 0x70000000
|
||||
#define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x))
|
||||
#define FUSE_OFFSET 0x800
|
||||
#define PMC_BASE 0x7000E400
|
||||
#define APB_MISC_GP_HIDREV 0x804
|
||||
#define GP_HIDREV_MAJOR_T210 0x1
|
||||
#define GP_HIDREV_MAJOR_T210B01 0x2
|
||||
#define APB_BASE 0x70000000
|
||||
#define FUSE_RESERVED_ODMX(x) (0x1C8 + 4 * (x))
|
||||
#define FUSE_OFFSET 0x800
|
||||
void FetchHardwareInfos() {
|
||||
ReadFuses(fuseData, fuseVirtAddr);
|
||||
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) {
|
||||
gSocType = HocClkSocType_Mariko;
|
||||
} else {
|
||||
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) {
|
||||
switch ((odm4 & 0xF0000) >> 16) {
|
||||
@@ -123,7 +124,7 @@ namespace board {
|
||||
rc = psmInitialize();
|
||||
ASSERT_RESULT_OK(rc, "psmInitialize");
|
||||
|
||||
if(HOSSVC_HAS_TC) {
|
||||
if (HOSSVC_HAS_TC) {
|
||||
rc = tcInitialize();
|
||||
ASSERT_RESULT_OK(rc, "tcInitialize");
|
||||
}
|
||||
@@ -170,7 +171,7 @@ namespace board {
|
||||
|
||||
batteryInfoInitialize();
|
||||
|
||||
tsensor::InitializeSoctherm(); // SOCTHERM must be init before AOTAG
|
||||
tsensor::InitializeSoctherm(); // SOCTHERM must be init before AOTAG
|
||||
|
||||
// PMC exosphere check
|
||||
SecmonArgs args = {};
|
||||
@@ -178,18 +179,21 @@ namespace board {
|
||||
args.X[1] = PMC_BASE;
|
||||
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);
|
||||
}
|
||||
|
||||
Result pwmCheck = 1;
|
||||
if (hosversionAtLeast(6,0,0) && R_SUCCEEDED(pwmInitialize())) {
|
||||
if (hosversionAtLeast(6, 0, 0) && R_SUCCEEDED(pwmInitialize())) {
|
||||
pwmCheck = pwmOpenSession2(&iCon, 0x3D000001);
|
||||
}
|
||||
|
||||
StartMiscThread(pwmCheck, &iCon);
|
||||
|
||||
display::DisplayRefreshConfig cfg = {.clkVirtAddr = clkVirtAddr, .dsiVirtAddr = dsiVirtAddr, .isLite = (GetConsoleType() == HocClkConsoleType_Hoag), .isRetroSUPER = integrations::GetRETROSuperStatus()};
|
||||
display::DisplayRefreshConfig cfg = { .clkVirtAddr = clkVirtAddr,
|
||||
.dsiVirtAddr = dsiVirtAddr,
|
||||
.isLite = (GetConsoleType() == HocClkConsoleType_Hoag),
|
||||
.isRetroSUPER = integrations::GetRETROSuperStatus() };
|
||||
display::Initialize(&cfg);
|
||||
|
||||
CacheDfllData();
|
||||
@@ -243,7 +247,7 @@ namespace board {
|
||||
args.X[1] = MC_REGISTER_BASE + MC_EMEM_CFG_0;
|
||||
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!");
|
||||
return false;
|
||||
}
|
||||
@@ -270,4 +274,4 @@ namespace board {
|
||||
return false; /* stub for now. */
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -26,18 +26,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "../mapping/mem_map.hpp"
|
||||
#include "board_freq.hpp"
|
||||
#include "board_fuse.hpp"
|
||||
#include "board_load.hpp"
|
||||
#include "board_name.hpp"
|
||||
#include "board_freq.hpp"
|
||||
#include "board_profile.hpp"
|
||||
#include "board_sensor.hpp"
|
||||
#include "board_volt.hpp"
|
||||
#include "board_profile.hpp"
|
||||
#include "../mapping/mem_map.hpp"
|
||||
#define HOSSVC_HAS_CLKRST (hosversionAtLeast(8,0,0))
|
||||
#define HOSSVC_HAS_TC (hosversionAtLeast(5,0,0))
|
||||
|
||||
#define HOSSVC_HAS_CLKRST (hosversionAtLeast(8, 0, 0))
|
||||
#define HOSSVC_HAS_TC (hosversionAtLeast(5, 0, 0))
|
||||
|
||||
namespace board {
|
||||
extern u64 clkVirtAddr, dsiVirtAddr, apbVirtAddr, fuseVirtAddr;
|
||||
@@ -46,7 +48,7 @@ namespace board {
|
||||
extern HocClkConsoleType gConsoleType;
|
||||
extern FuseData fuseData;
|
||||
extern u8 speedoBracket;
|
||||
|
||||
|
||||
void Initialize();
|
||||
void Exit();
|
||||
HocClkSocType GetSocType();
|
||||
@@ -58,4 +60,4 @@ namespace board {
|
||||
FuseData *GetFuseData();
|
||||
bool IsUsingRetroSuperDisplay();
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -24,24 +24,25 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
|
||||
#include "../display/display_refresh_rate.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../soc/gm20b.hpp"
|
||||
#include "../soc/pllmb.hpp"
|
||||
#include "board.hpp"
|
||||
#include "board_name.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../soc/pllmb.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include "../soc/gm20b.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
|
||||
namespace board {
|
||||
static u32 currentInjectedHz = 0;
|
||||
static u32 gMarikoGm20bCutoff = 1228800000;
|
||||
@@ -80,12 +81,12 @@ namespace board {
|
||||
ASSERT_RESULT_OK(pcvSetClockRate(moduleID, hz), "pcvSetClockRate");
|
||||
}
|
||||
|
||||
void HandleCpuUv()
|
||||
{
|
||||
void HandleCpuUv() {
|
||||
if (board::GetSocType() == HocClkSocType_Erista)
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); // Erista tbreak is always 1581MHz
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000); // Erista tbreak is always 1581MHz
|
||||
else
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
|
||||
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
|
||||
void SetHz(HocClkModule module, u32 hz) {
|
||||
@@ -101,7 +102,8 @@ namespace board {
|
||||
return;
|
||||
}
|
||||
|
||||
bool useGm20b = (module == HocClkModule_GPU) && (GetSocType() == HocClkSocType_Mariko) && (hz % 38400000 == 0) && (hz % 76800000 != 0) && hz < gMarikoGm20bCutoff;
|
||||
bool useGm20b = (module == HocClkModule_GPU) && (GetSocType() == HocClkSocType_Mariko) && (hz % 38400000 == 0) && (hz % 76800000 != 0) &&
|
||||
hz < gMarikoGm20bCutoff;
|
||||
|
||||
u32 pcvHz = useGm20b ? ((hz + 76800000 - 1) / 76800000) * 76800000 : hz;
|
||||
|
||||
@@ -129,7 +131,7 @@ namespace board {
|
||||
PcvSetHz(GetPcvModule(module), pcvHz);
|
||||
}
|
||||
}
|
||||
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv) && module == HocClkModule_CPU) {
|
||||
if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv) && module == HocClkModule_CPU) {
|
||||
HandleCpuUv();
|
||||
}
|
||||
if (useGm20b) {
|
||||
@@ -181,7 +183,9 @@ namespace board {
|
||||
case HocClkModule_GPU:
|
||||
return t210ClkGpuFreq();
|
||||
case HocClkModule_MEM:
|
||||
return config::GetConfigValue(HocClkConfigValue_MemoryFrequencyMeasurementMode) == MemoryFrequencyMeasurementMode_PLL ? pllmb::getRamClockRatePLLMB() : t210ClkMemFreq();
|
||||
return config::GetConfigValue(HocClkConfigValue_MemoryFrequencyMeasurementMode) == MemoryFrequencyMeasurementMode_PLL
|
||||
? pllmb::getRamClockRatePLLMB()
|
||||
: t210ClkMemFreq();
|
||||
case HocClkModule_Display:
|
||||
return GetDisplayRate(hz);
|
||||
default:
|
||||
@@ -197,7 +201,6 @@ namespace board {
|
||||
s32 tmpInMaxCount = maxCount;
|
||||
s32 tmpOutCount = 0;
|
||||
|
||||
|
||||
if (HOSSVC_HAS_CLKRST) {
|
||||
ClkrstSession session = {};
|
||||
|
||||
@@ -230,20 +233,20 @@ namespace board {
|
||||
|
||||
void ResetToStock() {
|
||||
Result rc;
|
||||
if (hosversionAtLeast(9,0,0)) {
|
||||
if (hosversionAtLeast(9, 0, 0)) {
|
||||
std::uint32_t confId = 0;
|
||||
rc = apmExtGetCurrentPerformanceConfiguration(&confId);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
|
||||
HocClkApmConfiguration* apmConfiguration = nullptr;
|
||||
HocClkApmConfiguration *apmConfiguration = nullptr;
|
||||
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];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!apmConfiguration) {
|
||||
if (!apmConfiguration) {
|
||||
ERROR_THROW("Unknown apm configuration: %x", confId);
|
||||
}
|
||||
|
||||
@@ -263,4 +266,4 @@ namespace board {
|
||||
void ResetToStockDisplay() {
|
||||
display::SetRate(60);
|
||||
}
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -25,16 +25,18 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../file/errors.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include "../file/errors.hpp"
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -46,12 +48,11 @@ namespace board {
|
||||
void GetFreqList(HocClkModule module, u32 *outList, u32 maxCount, u32 *outCount);
|
||||
u32 GetHighestDockedDisplayRate();
|
||||
void HandleCpuUv();
|
||||
|
||||
|
||||
void ResetToStock();
|
||||
void ResetToStockDisplay();
|
||||
|
||||
template <typename Getter>
|
||||
void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
|
||||
template <typename Getter> void ResetToStockModule(Getter getHzFunc, HocClkModule module) {
|
||||
Result rc = 0;
|
||||
|
||||
if (hosversionAtLeast(9, 0, 0)) {
|
||||
@@ -59,7 +60,7 @@ namespace board {
|
||||
rc = apmExtGetCurrentPerformanceConfiguration(&confId);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
|
||||
HocClkApmConfiguration* apmConfiguration = nullptr;
|
||||
HocClkApmConfiguration *apmConfiguration = nullptr;
|
||||
for (size_t i = 0; hocclk_g_apm_configurations[i].id; ++i) {
|
||||
|
||||
if (hocclk_g_apm_configurations[i].id == confId) {
|
||||
@@ -84,15 +85,15 @@ namespace board {
|
||||
}
|
||||
|
||||
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() {
|
||||
ResetToStockModule([](const HocClkApmConfiguration& cfg){ return cfg.gpu_hz; }, HocClkModule_GPU);
|
||||
ResetToStockModule([](const HocClkApmConfiguration &cfg) { return cfg.gpu_hz; }, HocClkModule_GPU);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -15,16 +15,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <fuse.h>
|
||||
#include "board_fuse.hpp"
|
||||
#include <cstring>
|
||||
#include <fuse.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "board.hpp"
|
||||
#include "board_fuse.hpp"
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
void SetGpuBracket(u16 speedo, u8 &gpuBracket) {
|
||||
if(GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
if (speedo <= 1624) {
|
||||
gpuBracket = 0;
|
||||
return;
|
||||
@@ -43,7 +45,7 @@ namespace board {
|
||||
/* >= 1754 */
|
||||
gpuBracket = 3;
|
||||
} else {
|
||||
switch(speedo) {
|
||||
switch (speedo) {
|
||||
case 1850 ... 1925:
|
||||
gpuBracket = 0;
|
||||
break;
|
||||
@@ -70,12 +72,12 @@ namespace board {
|
||||
speedo.cpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_0_CALIB);
|
||||
speedo.gpuSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_SPEEDO_2_CALIB);
|
||||
speedo.socSpeedo = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_SPEEDO_0_CALIB);
|
||||
speedo.cpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_IDDQ_CALIB) * 4;
|
||||
speedo.gpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_GPU_IDDQ_CALIB) * 5;
|
||||
speedo.socIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_IDDQ_CALIB) * 4;
|
||||
speedo.waferX = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_X_COORDINATE);
|
||||
speedo.waferY = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_Y_COORDINATE);
|
||||
speedo.waferX = (speedo.waferX & BIT(8)) ? (speedo.waferX - 512) : speedo.waferX;
|
||||
speedo.cpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_CPU_IDDQ_CALIB) * 4;
|
||||
speedo.gpuIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_GPU_IDDQ_CALIB) * 5;
|
||||
speedo.socIDDQ = *reinterpret_cast<u16 *>(fusePtr + FUSE_SOC_IDDQ_CALIB) * 4;
|
||||
speedo.waferX = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_X_COORDINATE);
|
||||
speedo.waferY = *reinterpret_cast<s16 *>(fusePtr + FUSE_OPT_Y_COORDINATE);
|
||||
speedo.waferX = (speedo.waferX & BIT(8)) ? (speedo.waferX - 512) : speedo.waferX;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -37,4 +37,4 @@ namespace board {
|
||||
void ReadFuses(FuseData &speedo, u64 fuseVa);
|
||||
void SetGpuBracket(u16 gpuSpeedo, u8 &gpuBracket);
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -24,22 +24,24 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <battery.h>
|
||||
#include <hocclk.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <math.h>
|
||||
#include <max17050.h>
|
||||
#include <minIni.h>
|
||||
#include <numeric>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "board.hpp"
|
||||
#include "board_misc.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
#include <numeric>
|
||||
#include <minIni.h>
|
||||
#include <battery.h>
|
||||
#include "board_misc.hpp"
|
||||
#include "board.hpp"
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -61,23 +63,24 @@ namespace board {
|
||||
constexpr double Systemtickfrequency = 19200000.0 * (static_cast<double>(CpuTimeOutNs) / 1'000'000'000.0);
|
||||
|
||||
void GpuLoadThread(void *ptr) {
|
||||
#define gpu_samples_average 8
|
||||
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
|
||||
uint32_t gpu_load_array[gpu_samples_average] = {0};
|
||||
#define gpu_samples_average 8
|
||||
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
|
||||
uint32_t gpu_load_array[gpu_samples_average] = { 0 };
|
||||
size_t i = 0;
|
||||
if (R_SUCCEEDED(nvCheck_load)) do {
|
||||
u32 temp;
|
||||
if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) {
|
||||
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);
|
||||
if (R_SUCCEEDED(nvCheck_load))
|
||||
do {
|
||||
u32 temp;
|
||||
if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) {
|
||||
gpu_load_array[i++ % gpu_samples_average] = temp;
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckCore(void *idletickPtr) {
|
||||
u64* idletick = static_cast<u64 *>(idletickPtr);
|
||||
while(true) {
|
||||
u64 *idletick = static_cast<u64 *>(idletickPtr);
|
||||
while (true) {
|
||||
u64 idletickA;
|
||||
u64 idletickB;
|
||||
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 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);
|
||||
return std::round(std::max({cpuUsage0, cpuUsage1, cpuUsage2}));
|
||||
return std::round(std::max({ cpuUsage0, cpuUsage1, cpuUsage2 }));
|
||||
}
|
||||
|
||||
u32 GetPartLoad(HocClkPartLoad loadSource) {
|
||||
switch(loadSource) {
|
||||
switch (loadSource) {
|
||||
case HocClkPartLoad_EMC:
|
||||
return t210EmcLoadAll();
|
||||
case HocClkPartLoad_EMCCpu:
|
||||
@@ -148,9 +151,9 @@ namespace board {
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr u32 NVschedCtrlEnable = 0x00000601;
|
||||
constexpr u32 NVschedCtrlEnable = 0x00000601;
|
||||
constexpr u32 NVschedCtrlDisable = 0x00000602;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method) {
|
||||
if (R_FAILED(nvCheckSched) && method == GpuSchedulingOverrideMethod_NvService) {
|
||||
@@ -160,7 +163,8 @@ namespace board {
|
||||
u32 temp;
|
||||
bool enabled = false;
|
||||
switch (mode) {
|
||||
case GpuSchedulingMode_DoNotOverride: break;
|
||||
case GpuSchedulingMode_DoNotOverride:
|
||||
break;
|
||||
case GpuSchedulingMode_Disabled:
|
||||
if (method == GpuSchedulingOverrideMethod_NvService) {
|
||||
nvIoctl(_fd2, NVschedCtrlDisable, &temp);
|
||||
@@ -198,4 +202,4 @@ namespace board {
|
||||
nvCheckSched = nvSched;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -37,4 +38,4 @@ namespace board {
|
||||
void SchedSetFD2(u32 fd2);
|
||||
void NvSchedSucceed(Result nvSched);
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <pwm.h>
|
||||
#include <cmath>
|
||||
#include <pwm.h>
|
||||
#include <switch.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -68,4 +68,4 @@ namespace board {
|
||||
threadClose(&miscThread);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <pwm.h>
|
||||
#include <switch.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -36,4 +36,4 @@ namespace board {
|
||||
void ExitMiscThread();
|
||||
u8 GetFanLevel();
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
@@ -50,4 +51,4 @@ namespace board {
|
||||
return hocclkFormatPowerSensor(sensor, pretty);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -35,4 +35,4 @@ namespace board {
|
||||
const char *GetThermalSensorName(HocClkThermalSensor sensor, bool pretty);
|
||||
const char *GetPowerSensorName(HocClkPowerSensor sensor, bool pretty);
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -24,16 +24,17 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "board.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -60,4 +61,4 @@ namespace board {
|
||||
return HocClkProfile_Handheld;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -28,7 +28,5 @@
|
||||
#include <hocclk.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
HocClkProfile GetProfile();
|
||||
|
||||
}
|
||||
|
||||
@@ -24,24 +24,26 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <tmp451.h>
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include <cmath>
|
||||
#include <battery.h>
|
||||
#include <cmath>
|
||||
#include <hocclk.h>
|
||||
#include <i2c.h>
|
||||
#include <max17050.h>
|
||||
#include <pwm.h>
|
||||
#include "board.hpp"
|
||||
#include "../tsensor/soctherm.hpp"
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../file/config.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../tsensor/aotag.hpp"
|
||||
#include "../tsensor/bq24193.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include "../tsensor/soctherm.hpp"
|
||||
#include "board.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -52,7 +54,7 @@ namespace board {
|
||||
tsensor::TSensorTemps temps = {};
|
||||
tsensor::ReadTSensors(temps);
|
||||
|
||||
switch(sensor) {
|
||||
switch (sensor) {
|
||||
case HocClkThermalSensor_SOC: {
|
||||
millis = tmp451TempSoc();
|
||||
break;
|
||||
@@ -127,4 +129,4 @@ namespace board {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -33,4 +33,4 @@ namespace board {
|
||||
s32 GetTemperatureMilli(HocClkThermalSensor sensor);
|
||||
s32 GetPowerMw(HocClkPowerSensor sensor);
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
*
|
||||
* Copyright (c) B3711
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
@@ -17,22 +17,24 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <battery.h>
|
||||
#include <cstring>
|
||||
#include <hocclk.h>
|
||||
#include <memmem.h>
|
||||
#include <registers.h>
|
||||
#include <cstring>
|
||||
#include <battery.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../hos/rgltr.h"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "board.hpp"
|
||||
#include "board_freq.hpp"
|
||||
#include "board_volt.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../hos/rgltr.h"
|
||||
|
||||
namespace board {
|
||||
|
||||
GpuVoltData voltData = {};
|
||||
u32 cpuVoltTable[32] = {}; // 32LUT
|
||||
u32 cpuVoltTable[32] = {}; // 32LUT
|
||||
u64 cldvfs;
|
||||
CpuDfllData cachedTune;
|
||||
|
||||
@@ -50,54 +52,30 @@ namespace board {
|
||||
u32 tune1_high;
|
||||
};
|
||||
|
||||
EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = { // <2118 CPU speedo
|
||||
{0xFFEAD0FF, 0x25501d0},
|
||||
{0xffff, 0x27007ff},
|
||||
{0xefff, 0x27407ff},
|
||||
{0xdfff, 0x27807ff},
|
||||
{0xdfdf, 0x27a07ff},
|
||||
{0xcfdf, 0x37007ff},
|
||||
EristaCpuUvEntry eristaCpuUvTableLowBracket[6] = {
|
||||
// <2118 CPU speedo
|
||||
{ 0xFFEAD0FF, 0x25501d0 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
|
||||
{ 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
|
||||
};
|
||||
|
||||
EristaCpuUvEntry eristaCpuUvTableHighBracket[6] = {
|
||||
{0xFFEAD0FF, 0x20091d9},
|
||||
{0xffff, 0x27007ff},
|
||||
{0xefff, 0x27407ff},
|
||||
{0xdfff, 0x27807ff},
|
||||
{0xdfdf, 0x27a07ff},
|
||||
{0xcfdf, 0x37007ff},
|
||||
{ 0xFFEAD0FF, 0x20091d9 }, { 0xffff, 0x27007ff }, { 0xefff, 0x27407ff },
|
||||
{ 0xdfff, 0x27807ff }, { 0xdfdf, 0x27a07ff }, { 0xcfdf, 0x37007ff },
|
||||
};
|
||||
|
||||
MarikoCpuUvEntry marikoCpuUvLow[12] = {
|
||||
{0xffa0, 0xffff, 0x21107ff, 0},
|
||||
{0x0, 0xffdf, 0x21107ff, 0x27207ff},
|
||||
{0xffdf, 0xffdf, 0x21107ff, 0x27307ff},
|
||||
{0xffff, 0xffdf, 0x21107ff, 0x27407ff},
|
||||
{0x0, 0xffdf, 0x21607ff, 0x27707ff},
|
||||
{0x0, 0xffdf, 0x21607ff, 0x27807ff},
|
||||
{0x0, 0xdfff, 0x21607ff, 0x27b07ff},
|
||||
{0xdfff, 0xdfff, 0x21707ff, 0x27b07ff},
|
||||
{0xdfff, 0xdfff, 0x21707ff, 0x27c07ff},
|
||||
{0xdfff, 0xdfff, 0x21707ff, 0x27d07ff},
|
||||
{0xdfff, 0xdfff, 0x21707ff, 0x27e07ff},
|
||||
{0xdfff, 0xdfff, 0x21707ff, 0x27f07ff},
|
||||
{ 0xffa0, 0xffff, 0x21107ff, 0 }, { 0x0, 0xffdf, 0x21107ff, 0x27207ff }, { 0xffdf, 0xffdf, 0x21107ff, 0x27307ff },
|
||||
{ 0xffff, 0xffdf, 0x21107ff, 0x27407ff }, { 0x0, 0xffdf, 0x21607ff, 0x27707ff }, { 0x0, 0xffdf, 0x21607ff, 0x27807ff },
|
||||
{ 0x0, 0xdfff, 0x21607ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27b07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27c07ff },
|
||||
{ 0xdfff, 0xdfff, 0x21707ff, 0x27d07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27e07ff }, { 0xdfff, 0xdfff, 0x21707ff, 0x27f07ff },
|
||||
};
|
||||
|
||||
MarikoCpuUvEntry marikoCpuUvHigh[12] = {
|
||||
{0x0, 0xffff, 0, 0},
|
||||
{0x0, 0xffdf, 0, 0x27207ff},
|
||||
{0x0, 0xffdf, 0, 0x27307ff},
|
||||
{0x0, 0xffdf, 0, 0x27407ff},
|
||||
{0x0, 0xffdf, 0, 0x27707ff},
|
||||
{0x0, 0xffdf, 0, 0x27807ff},
|
||||
{0x0, 0xdfff, 0, 0x27b07ff},
|
||||
{0x0, 0xdfff, 0, 0x27c07ff},
|
||||
{0x0, 0xdfff, 0, 0x27d07ff},
|
||||
{0x0, 0xdfff, 0, 0x27e07ff},
|
||||
{0x0, 0xdfff, 0, 0x27f07ff},
|
||||
{0x0, 0xdfff, 0, 0x27f07ff},
|
||||
{ 0x0, 0xffff, 0, 0 }, { 0x0, 0xffdf, 0, 0x27207ff }, { 0x0, 0xffdf, 0, 0x27307ff }, { 0x0, 0xffdf, 0, 0x27407ff },
|
||||
{ 0x0, 0xffdf, 0, 0x27707ff }, { 0x0, 0xffdf, 0, 0x27807ff }, { 0x0, 0xdfff, 0, 0x27b07ff }, { 0x0, 0xdfff, 0, 0x27c07ff },
|
||||
{ 0x0, 0xdfff, 0, 0x27d07ff }, { 0x0, 0xdfff, 0, 0x27e07ff }, { 0x0, 0xdfff, 0, 0x27f07ff }, { 0x0, 0xdfff, 0, 0x27f07ff },
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void CacheDfllData() {
|
||||
Result rc = QueryMemoryMapping(&cldvfs, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE);
|
||||
@@ -111,33 +89,33 @@ namespace board {
|
||||
|
||||
/* TODO: clean up this code. */
|
||||
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint) {
|
||||
u32* tune0_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
u32* tune1_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
|
||||
u32 *tune0_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
u32 *tune1_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetHz(HocClkModule_CPU) < tbreakPoint && (levelLow || levelHigh)) {
|
||||
if (levelLow) {
|
||||
*tune0_ptr = marikoCpuUvLow[levelLow-1].tune0_low;
|
||||
*tune1_ptr = marikoCpuUvLow[levelLow-1].tune1_low;
|
||||
*tune0_ptr = marikoCpuUvLow[levelLow - 1].tune0_low;
|
||||
*tune1_ptr = marikoCpuUvLow[levelLow - 1].tune1_low;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (levelLow) {
|
||||
*tune0_ptr = marikoCpuUvLow[levelLow-1].tune0_low;
|
||||
*tune1_ptr = marikoCpuUvLow[levelLow-1].tune1_low;
|
||||
*tune0_ptr = marikoCpuUvLow[levelLow - 1].tune0_low;
|
||||
*tune1_ptr = marikoCpuUvLow[levelLow - 1].tune1_low;
|
||||
}
|
||||
if (levelHigh) {
|
||||
*tune0_ptr = marikoCpuUvHigh[levelHigh-1].tune0_high;
|
||||
*tune1_ptr = marikoCpuUvHigh[levelHigh-1].tune1_high;
|
||||
*tune0_ptr = marikoCpuUvHigh[levelHigh - 1].tune0_high;
|
||||
*tune1_ptr = marikoCpuUvHigh[levelHigh - 1].tune1_high;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (GetHz(HocClkModule_CPU) < tbreakPoint || (!levelLow)) { // account for tbreak
|
||||
if (GetHz(HocClkModule_CPU) < tbreakPoint || (!levelLow)) { // account for tbreak
|
||||
*tune0_ptr = 0xCFFF;
|
||||
*tune1_ptr = 0xFF072201;
|
||||
return;
|
||||
} else if (GetHz(HocClkModule_CPU) >= tbreakPoint || (!levelHigh)) {
|
||||
*tune0_ptr = cachedTune.tune0High; // per console?
|
||||
*tune0_ptr = cachedTune.tune0High; // per console?
|
||||
*tune1_ptr = 0xFFF7FF3F;
|
||||
return;
|
||||
}
|
||||
@@ -210,9 +188,9 @@ namespace board {
|
||||
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
|
||||
} 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 out = 0;
|
||||
BatteryChargeInfo info;
|
||||
@@ -225,7 +203,7 @@ namespace board {
|
||||
out = I2c_BuckConverter_GetUvOut(&I2c_VDD2);
|
||||
break;
|
||||
case HocClkVoltage_CPU:
|
||||
if(GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_CPU);
|
||||
} else {
|
||||
rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Cpu);
|
||||
@@ -234,16 +212,16 @@ namespace board {
|
||||
}
|
||||
break;
|
||||
case HocClkVoltage_GPU:
|
||||
if(GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_GPU);
|
||||
} else {
|
||||
rgltrOpenSession(&s, PcvPowerDomainId_Max77621_Gpu);
|
||||
rgltrGetVoltage(&s, &out);
|
||||
rgltrCloseSession(&s);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HocClkVoltage_EMCVDDQ:
|
||||
if(GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
out = I2c_BuckConverter_GetUvOut(&I2c_Mariko_DRAM_VDDQ);
|
||||
} else {
|
||||
out = I2c_BuckConverter_GetUvOut(&I2c_VDD2);
|
||||
@@ -266,8 +244,8 @@ namespace board {
|
||||
Handle GetPcvHandle() {
|
||||
constexpr u64 PcvID = 0x10000000000001a;
|
||||
u64 processIDList[80]{};
|
||||
s32 processCount = 0;
|
||||
Handle handle = INVALID_HANDLE;
|
||||
s32 processCount = 0;
|
||||
Handle handle = INVALID_HANDLE;
|
||||
|
||||
DebugEventInfo debugEvent{};
|
||||
|
||||
@@ -306,9 +284,9 @@ namespace board {
|
||||
void CacheGpuVoltTable() {
|
||||
// Likely CPU regulator?
|
||||
UnkRegulator reg = {
|
||||
.voltageMin = 600000,
|
||||
.voltageMin = 600000,
|
||||
.voltageStep = 12500,
|
||||
.voltageMax = 1400000,
|
||||
.voltageMax = 1400000,
|
||||
};
|
||||
|
||||
Handle handle = GetPcvHandle();
|
||||
@@ -365,17 +343,17 @@ namespace board {
|
||||
}
|
||||
|
||||
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);
|
||||
handle = INVALID_HANDLE;
|
||||
|
||||
// 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]);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
return;
|
||||
@@ -420,35 +398,50 @@ namespace board {
|
||||
|
||||
u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket) {
|
||||
u32 baseVolt = 800;
|
||||
if(GetSocType() == HocClkSocType_Mariko) {
|
||||
if (GetSocType() == HocClkSocType_Mariko) {
|
||||
static const u32 ramTable[][22] = {
|
||||
{ 2133, 2200, 2266, 2300, 2366, 2400, 2433, 2466, 2533, 2566, 2600, 2633, 2700, 2733, 2766, 2833, 2866, 2900, 2933, 3033, 3066, 3100, }, // Bracket 0
|
||||
{ 2300, 2366, 2433, 2466, 2533, 2566, 2633, 2700, 2733, 2800, 2833, 2900, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3266, }, // Bracket 1
|
||||
{ 2433, 2466, 2533, 2566, 2600, 2666, 2766, 2800, 2833, 2866, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3300, 3333, 3366, }, // Bracket 2
|
||||
{ 2500, 2533, 2600, 2633, 2666, 2733, 2800, 2866, 2900, 2966, 3033, 3100, 3166, 3200, 3233, 3266, 3300, 3333, 3366, 3400, 3400, 3400, }, // Bracket 3
|
||||
{
|
||||
2133, 2200, 2266, 2300, 2366, 2400, 2433, 2466, 2533, 2566, 2600,
|
||||
2633, 2700, 2733, 2766, 2833, 2866, 2900, 2933, 3033, 3066, 3100,
|
||||
}, // Bracket 0
|
||||
{
|
||||
2300, 2366, 2433, 2466, 2533, 2566, 2633, 2700, 2733, 2800, 2833,
|
||||
2900, 2933, 2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3266,
|
||||
}, // Bracket 1
|
||||
{
|
||||
2433, 2466, 2533, 2566, 2600, 2666, 2766, 2800, 2833, 2866, 2933,
|
||||
2966, 3033, 3066, 3100, 3133, 3166, 3200, 3233, 3300, 3333, 3366,
|
||||
}, // Bracket 2
|
||||
{
|
||||
2500, 2533, 2600, 2633, 2666, 2733, 2800, 2866, 2900, 2966, 3033,
|
||||
3100, 3166, 3200, 3233, 3266, 3300, 3333, 3366, 3400, 3400, 3400,
|
||||
}, // Bracket 3
|
||||
};
|
||||
|
||||
static const u32 gpuVoltArray[] = { 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, };
|
||||
static const u32 gpuVoltArray[] = {
|
||||
590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800,
|
||||
};
|
||||
|
||||
if (freqMhz <= 1600) return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
|
||||
if (bracket >= std::size(ramTable)) bracket = 0;
|
||||
if (freqMhz <= 1600)
|
||||
return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
|
||||
if (bracket >= std::size(ramTable))
|
||||
bracket = 0;
|
||||
|
||||
u32 bracketStart = ramTable[bracket][0];
|
||||
|
||||
|
||||
u32 rampStartVolt = (bracket == 0) ? 535 : 525; // Do not touch!
|
||||
u32 rampSpan = 590 - rampStartVolt;
|
||||
|
||||
u32 rampStartVolt = (bracket == 0) ? 535 : 525; // Do not touch!
|
||||
u32 rampSpan = 590 - rampStartVolt;
|
||||
|
||||
if (freqMhz >= 1633 && freqMhz < bracketStart) {
|
||||
u32 raw = rampStartVolt + ((freqMhz - 1633) * rampSpan) / (bracketStart - 1633);
|
||||
u32 volt = ((raw + 2) / 5) * 5;
|
||||
if (volt < rampStartVolt) volt = rampStartVolt;
|
||||
if (volt > 590) volt = 590;
|
||||
if (volt < rampStartVolt)
|
||||
volt = rampStartVolt;
|
||||
if (volt > 590)
|
||||
volt = 590;
|
||||
return volt;
|
||||
}
|
||||
|
||||
|
||||
baseVolt = gpuVoltArray[std::size(gpuVoltArray) - 1];
|
||||
for (u32 i = 0; i < std::size(gpuVoltArray); ++i) {
|
||||
if (freqMhz <= ramTable[bracket][i]) {
|
||||
@@ -457,27 +450,104 @@ namespace board {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct DvfsEntry { u32 freq; u32 volt; };
|
||||
struct DvfsEntry {
|
||||
u32 freq;
|
||||
u32 volt;
|
||||
};
|
||||
static const DvfsEntry ramTable[][19] = {
|
||||
{ {1733,725}, {1800,730}, {1866,735}, {1920,740}, {1958,745}, {1996,750}, {2035,755}, {2073,760}, {2112,765}, {2131,770}, {2150,775}, {2169,780}, {2188,785}, {2227,790}, {2265,795}, {2304,800}, {2342,805}, {2380,810}, {2400,815} }, // Bracket 0
|
||||
{ {1733,715}, {1800,720}, {1866,725}, {1920,730}, {1958,735}, {1996,740}, {2035,745}, {2073,750}, {2112,755}, {2131,760}, {2150,765}, {2169,770}, {2188,775}, {2227,780}, {2265,785}, {2304,790}, {2342,795}, {2380,800}, {2400,805} }, // Bracket 1
|
||||
{ {1733,705}, {1800,710}, {1866,715}, {1920,720}, {1958,725}, {1996,730}, {2035,735}, {2073,740}, {2112,745}, {2131,750}, {2150,755}, {2169,760}, {2188,765}, {2227,770}, {2265,775}, {2304,780}, {2342,785}, {2380,790}, {2400,795} }, // Bracket 2
|
||||
{ {1733,695}, {1800,700}, {1866,705}, {1920,710}, {1958,715}, {1996,720}, {2035,725}, {2073,730}, {2112,735}, {2131,740}, {2150,745}, {2169,750}, {2188,755}, {2227,760}, {2265,765}, {2304,770}, {2342,775}, {2380,780}, {2400,785} }, // Bracket 3
|
||||
{ { 1733, 725 },
|
||||
{ 1800, 730 },
|
||||
{ 1866, 735 },
|
||||
{ 1920, 740 },
|
||||
{ 1958, 745 },
|
||||
{ 1996, 750 },
|
||||
{ 2035, 755 },
|
||||
{ 2073, 760 },
|
||||
{ 2112, 765 },
|
||||
{ 2131, 770 },
|
||||
{ 2150, 775 },
|
||||
{ 2169, 780 },
|
||||
{ 2188, 785 },
|
||||
{ 2227, 790 },
|
||||
{ 2265, 795 },
|
||||
{ 2304, 800 },
|
||||
{ 2342, 805 },
|
||||
{ 2380, 810 },
|
||||
{ 2400, 815 } }, // Bracket 0
|
||||
{ { 1733, 715 },
|
||||
{ 1800, 720 },
|
||||
{ 1866, 725 },
|
||||
{ 1920, 730 },
|
||||
{ 1958, 735 },
|
||||
{ 1996, 740 },
|
||||
{ 2035, 745 },
|
||||
{ 2073, 750 },
|
||||
{ 2112, 755 },
|
||||
{ 2131, 760 },
|
||||
{ 2150, 765 },
|
||||
{ 2169, 770 },
|
||||
{ 2188, 775 },
|
||||
{ 2227, 780 },
|
||||
{ 2265, 785 },
|
||||
{ 2304, 790 },
|
||||
{ 2342, 795 },
|
||||
{ 2380, 800 },
|
||||
{ 2400, 805 } }, // Bracket 1
|
||||
{ { 1733, 705 },
|
||||
{ 1800, 710 },
|
||||
{ 1866, 715 },
|
||||
{ 1920, 720 },
|
||||
{ 1958, 725 },
|
||||
{ 1996, 730 },
|
||||
{ 2035, 735 },
|
||||
{ 2073, 740 },
|
||||
{ 2112, 745 },
|
||||
{ 2131, 750 },
|
||||
{ 2150, 755 },
|
||||
{ 2169, 760 },
|
||||
{ 2188, 765 },
|
||||
{ 2227, 770 },
|
||||
{ 2265, 775 },
|
||||
{ 2304, 780 },
|
||||
{ 2342, 785 },
|
||||
{ 2380, 790 },
|
||||
{ 2400, 795 } }, // Bracket 2
|
||||
{ { 1733, 695 },
|
||||
{ 1800, 700 },
|
||||
{ 1866, 705 },
|
||||
{ 1920, 710 },
|
||||
{ 1958, 715 },
|
||||
{ 1996, 720 },
|
||||
{ 2035, 725 },
|
||||
{ 2073, 730 },
|
||||
{ 2112, 735 },
|
||||
{ 2131, 740 },
|
||||
{ 2150, 745 },
|
||||
{ 2169, 750 },
|
||||
{ 2188, 755 },
|
||||
{ 2227, 760 },
|
||||
{ 2265, 765 },
|
||||
{ 2304, 770 },
|
||||
{ 2342, 775 },
|
||||
{ 2380, 780 },
|
||||
{ 2400, 785 } }, // Bracket 3
|
||||
};
|
||||
|
||||
if (freqMhz <= 1600) return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
|
||||
if (bracket >= std::size(ramTable)) bracket = 0;
|
||||
if (freqMhz <= 1600)
|
||||
return 0; // DVFS doesnt work below 1600MHz, it will just use vMin
|
||||
if (bracket >= std::size(ramTable))
|
||||
bracket = 0;
|
||||
|
||||
const auto& entries = ramTable[bracket];
|
||||
const auto &entries = ramTable[bracket];
|
||||
baseVolt = entries[std::size(entries) - 1].volt;
|
||||
for (const auto& entry : entries) {
|
||||
for (const auto &entry : entries) {
|
||||
if (freqMhz <= entry.freq) {
|
||||
baseVolt = entry.volt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return baseVolt;
|
||||
}
|
||||
}
|
||||
} // namespace board
|
||||
@@ -16,8 +16,9 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -37,9 +38,9 @@ namespace board {
|
||||
u32 tune0High;
|
||||
u32 tune1Low;
|
||||
u32 tune1High;
|
||||
// u32 tune_high_min_millivolts;
|
||||
// u32 tune_high_margin_millivolts;
|
||||
// u64 dvco_calibration_max;
|
||||
// u32 tune_high_min_millivolts;
|
||||
// u32 tune_high_margin_millivolts;
|
||||
// u64 dvco_calibration_max;
|
||||
};
|
||||
|
||||
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint);
|
||||
@@ -50,4 +51,4 @@ namespace board {
|
||||
void PcvHijackGpuVolts(u32 vmin);
|
||||
u32 GetMinimumGpuVmin(u32 freqMhz, u32 bracket);
|
||||
|
||||
}
|
||||
} // namespace board
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "aula.hpp"
|
||||
@@ -23,26 +23,24 @@
|
||||
// I *think* HOS changes this in some ways, so look into it more
|
||||
|
||||
namespace AulaDisplay {
|
||||
#define MMIO_REG32(base, off) *(vu32 *)((base) + (off))
|
||||
#define DSI(off) MMIO_REG32(board::dsiVirtAddr, (off) << 2u)
|
||||
#define DSI_WR_DATA 0xA
|
||||
#define DSI_TRIGGER 0x13
|
||||
#define MMIO_REG32(base, off) *(vu32 *)((base) + (off))
|
||||
#define DSI(off) MMIO_REG32(board::dsiVirtAddr, (off) << 2u)
|
||||
#define DSI_WR_DATA 0xA
|
||||
#define DSI_TRIGGER 0x13
|
||||
|
||||
void _display_dsi_send_cmd(u8 cmd, u32 param, u32 wait) {
|
||||
DSI(DSI_WR_DATA) = (param << 8) | cmd;
|
||||
DSI(DSI_TRIGGER) = DSI_TRIGGER_HOST;
|
||||
|
||||
if (wait)
|
||||
svcSleepThread(wait * 1000); // usleep-equivalant
|
||||
svcSleepThread(wait * 1000); // usleep-equivalant
|
||||
}
|
||||
|
||||
void SetDisplayColorMode(AulaColorMode mode) {
|
||||
if(mode == AulaDisplayColorMode_DoNotOverride)
|
||||
if (mode == AulaDisplayColorMode_DoNotOverride)
|
||||
return;
|
||||
// send display command to change color mode.
|
||||
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM,
|
||||
MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
|
||||
|
||||
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE_PARAM, MIPI_DCS_PRIV_SM_SET_COLOR_MODE | (mode << 8), 0);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace AulaDisplay
|
||||
@@ -12,10 +12,10 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include "../board/board.hpp"
|
||||
|
||||
namespace AulaDisplay {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,26 +12,27 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "display_refresh_rate.hpp"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "display_refresh_rate.hpp"
|
||||
|
||||
namespace display {
|
||||
#define DSI_CLOCK_HZ 234000000llu
|
||||
#define NVDISP_GET_MODE2 0x803C021B
|
||||
#define NVDISP_SET_MODE2 0x403C021C
|
||||
#define NVDISP_VALIDATE_MODE2 0xC03C021D
|
||||
#define NVDISP_GET_MODE_DB2 0xEF20021E
|
||||
#define NVDISP_GET_PANEL_DATA 0xC01C0226
|
||||
#define DSI_CLOCK_HZ 234000000llu
|
||||
#define NVDISP_GET_MODE2 0x803C021B
|
||||
#define NVDISP_SET_MODE2 0x403C021C
|
||||
#define NVDISP_VALIDATE_MODE2 0xC03C021D
|
||||
#define NVDISP_GET_MODE_DB2 0xEF20021E
|
||||
#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 uint8_t g_dockedHighestRefreshRate = 60;
|
||||
@@ -41,7 +42,8 @@ namespace display {
|
||||
static bool g_canChangeRefreshRateDocked = false;
|
||||
static uint8_t g_lastVActiveSet = 0;
|
||||
|
||||
static const uint8_t g_dockedRefreshRates[] = {40, 45, 50, 55, 60, 70, 72, 75, 80, 90, 95, 100, 110, 120, 130, 140, 144, 150, 160, 165, 170, 180, 190, 200, 210, 220, 230, 240};
|
||||
static const uint8_t g_dockedRefreshRates[] = { 40, 45, 50, 55, 60, 70, 72, 75, 80, 90, 95, 100, 110, 120,
|
||||
130, 140, 144, 150, 160, 165, 170, 180, 190, 200, 210, 220, 230, 240 };
|
||||
// Calculate with this tool:
|
||||
|
||||
// https://tomverbeure.github.io/video_timings_calculator?horiz_pixels=1920&vert_pixels=1080&refresh_rate=240&margins=false&interlaced=false&bpc=8&color_fmt=rgb444&video_opt=false&custom_hblank=80&custom_vblank=6
|
||||
@@ -59,83 +61,85 @@ namespace display {
|
||||
} DockedTimings;
|
||||
*/
|
||||
static const DockedTimings g_dockedTimings1080p[] = {
|
||||
{8, 32, 40, 7, 8, 6, 0, 88080}, // 40Hz
|
||||
{8, 32, 40, 9, 8, 6, 0, 99270}, // 45Hz
|
||||
{528, 44, 148, 4, 5, 36, 31, 148500}, // 50Hz
|
||||
{8, 32, 40, 15, 8, 6, 0, 121990}, // 55Hz
|
||||
{88, 44, 148, 4, 5, 36, 16, 148500}, // 60Hz
|
||||
{8, 32, 40, 22, 8, 6, 0, 156240}, // 70Hz
|
||||
{8, 32, 40, 23, 8, 6, 0, 160848}, // 72Hz
|
||||
{8, 32, 40, 25, 8, 6, 0, 167850}, // 75Hz
|
||||
{8, 32, 40, 28, 8, 6, 0, 179520}, // 80Hz
|
||||
{8, 32, 40, 33, 8, 6, 0, 202860}, // 90Hz
|
||||
{8, 32, 40, 36, 8, 6, 0, 214700}, // 95Hz
|
||||
{528, 44, 148, 4, 5, 36, 64, 297000}, // 100Hz
|
||||
{8, 32, 40, 44, 8, 6, 0, 250360}, // 110Hz
|
||||
{88, 44, 148, 4, 5, 36, 63, 297000}, // 120Hz
|
||||
{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, 63, 8, 6, 0, 333216}, //144Hz 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, 75, 8, 6, 0, 385770}, //165Hz 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, 90, 8, 6, 0, 449920}, //190Hz 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, 108, 8, 6, 0, 528880}, //220Hz 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, 7, 8, 6, 0, 88080 }, // 40Hz
|
||||
{ 8, 32, 40, 9, 8, 6, 0, 99270 }, // 45Hz
|
||||
{ 528, 44, 148, 4, 5, 36, 31, 148500 }, // 50Hz
|
||||
{ 8, 32, 40, 15, 8, 6, 0, 121990 }, // 55Hz
|
||||
{ 88, 44, 148, 4, 5, 36, 16, 148500 }, // 60Hz
|
||||
{ 8, 32, 40, 22, 8, 6, 0, 156240 }, // 70Hz
|
||||
{ 8, 32, 40, 23, 8, 6, 0, 160848 }, // 72Hz
|
||||
{ 8, 32, 40, 25, 8, 6, 0, 167850 }, // 75Hz
|
||||
{ 8, 32, 40, 28, 8, 6, 0, 179520 }, // 80Hz
|
||||
{ 8, 32, 40, 33, 8, 6, 0, 202860 }, // 90Hz
|
||||
{ 8, 32, 40, 36, 8, 6, 0, 214700 }, // 95Hz
|
||||
{ 528, 44, 148, 4, 5, 36, 64, 297000 }, // 100Hz
|
||||
{ 8, 32, 40, 44, 8, 6, 0, 250360 }, // 110Hz
|
||||
{ 88, 44, 148, 4, 5, 36, 63, 297000 }, // 120Hz
|
||||
{ 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, 63, 8, 6, 0, 333216 }, // 144Hz 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, 75, 8, 6, 0, 385770 }, // 165Hz 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, 90, 8, 6, 0, 449920 }, // 190Hz 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, 108, 8, 6, 0, 528880 }, // 220Hz CVT-RBv2
|
||||
{ 8, 32, 40, 114, 8, 6, 0, 555680 }, // 230Hz 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?
|
||||
};
|
||||
|
||||
// These timings *should* work but are untested
|
||||
static const HandheldTimings g_handheldTimingsRETRO[] = {
|
||||
{72, 136, 72, 1, 660, 9, 78000}, // 40Hz
|
||||
{72, 136, 72, 1, 612, 9, 77982}, // 41Hz
|
||||
{72, 136, 72, 1, 567, 9, 77994}, // 42Hz
|
||||
{72, 136, 72, 1, 524, 9, 78002}, // 43Hz
|
||||
{72, 136, 72, 1, 483, 9, 78012}, // 44Hz
|
||||
{72, 136, 72, 1, 443, 9, 77985}, // 45Hz
|
||||
{72, 136, 72, 1, 406, 9, 78016}, // 46Hz
|
||||
{72, 136, 72, 1, 370, 9, 78020}, // 47Hz
|
||||
{72, 136, 72, 1, 335, 9, 78000}, // 48Hz
|
||||
{72, 136, 72, 1, 302, 9, 78008}, // 49Hz
|
||||
{72, 136, 72, 1, 270, 9, 78000}, // 50Hz
|
||||
{72, 136, 72, 1, 239, 9, 77979}, // 51Hz
|
||||
{72, 136, 72, 1, 210, 9, 78000}, // 52Hz
|
||||
{72, 136, 72, 1, 182, 9, 78016}, // 53Hz
|
||||
{72, 136, 72, 1, 154, 9, 77976}, // 54Hz
|
||||
{72, 136, 72, 1, 128, 9, 77990}, // 55Hz
|
||||
{72, 136, 72, 1, 103, 9, 78008}, // 56Hz
|
||||
{72, 136, 72, 1, 78, 9, 77976}, // 57Hz
|
||||
{72, 136, 72, 1, 55, 9, 78010}, // 58Hz
|
||||
{72, 136, 72, 1, 32, 9, 77998}, // 59Hz
|
||||
{72, 136, 72, 1, 10, 9, 78000}, // 60Hz
|
||||
{ 72, 136, 72, 1, 660, 9, 78000 }, // 40Hz
|
||||
{ 72, 136, 72, 1, 612, 9, 77982 }, // 41Hz
|
||||
{ 72, 136, 72, 1, 567, 9, 77994 }, // 42Hz
|
||||
{ 72, 136, 72, 1, 524, 9, 78002 }, // 43Hz
|
||||
{ 72, 136, 72, 1, 483, 9, 78012 }, // 44Hz
|
||||
{ 72, 136, 72, 1, 443, 9, 77985 }, // 45Hz
|
||||
{ 72, 136, 72, 1, 406, 9, 78016 }, // 46Hz
|
||||
{ 72, 136, 72, 1, 370, 9, 78020 }, // 47Hz
|
||||
{ 72, 136, 72, 1, 335, 9, 78000 }, // 48Hz
|
||||
{ 72, 136, 72, 1, 302, 9, 78008 }, // 49Hz
|
||||
{ 72, 136, 72, 1, 270, 9, 78000 }, // 50Hz
|
||||
{ 72, 136, 72, 1, 239, 9, 77979 }, // 51Hz
|
||||
{ 72, 136, 72, 1, 210, 9, 78000 }, // 52Hz
|
||||
{ 72, 136, 72, 1, 182, 9, 78016 }, // 53Hz
|
||||
{ 72, 136, 72, 1, 154, 9, 77976 }, // 54Hz
|
||||
{ 72, 136, 72, 1, 128, 9, 77990 }, // 55Hz
|
||||
{ 72, 136, 72, 1, 103, 9, 78008 }, // 56Hz
|
||||
{ 72, 136, 72, 1, 78, 9, 77976 }, // 57Hz
|
||||
{ 72, 136, 72, 1, 55, 9, 78010 }, // 58Hz
|
||||
{ 72, 136, 72, 1, 32, 9, 77998 }, // 59Hz
|
||||
{ 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) {
|
||||
for (size_t i = 0; i < sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]); i++) {
|
||||
if (g_dockedRefreshRates[i] == refreshRate) return i;
|
||||
if (g_dockedRefreshRates[i] == refreshRate)
|
||||
return i;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
static void _changeOledElvssSettings(const uint32_t* offsets, const uint32_t* value, uint32_t size, uint32_t start) {
|
||||
if (!g_config.dsiVirtAddr || !value || !size) return;
|
||||
static void _changeOledElvssSettings(const uint32_t *offsets, const uint32_t *value, uint32_t size, uint32_t start) {
|
||||
if (!g_config.dsiVirtAddr || !value || !size)
|
||||
return;
|
||||
|
||||
volatile uint32_t* dsi = (uint32_t*)g_config.dsiVirtAddr;
|
||||
|
||||
#define DSI_VIDEO_MODE_CONTROL 0x4E
|
||||
#define DSI_WR_DATA 0xA
|
||||
#define DSI_TRIGGER 0x13
|
||||
#define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15
|
||||
#define MIPI_DSI_DCS_LONG_WRITE 0x39
|
||||
#define MIPI_DCS_PRIV_SM_SET_REG_OFFSET 0xB0
|
||||
#define MIPI_DCS_PRIV_SM_SET_ELVSS 0xB1
|
||||
volatile uint32_t *dsi = (uint32_t *)g_config.dsiVirtAddr;
|
||||
|
||||
#define DSI_VIDEO_MODE_CONTROL 0x4E
|
||||
#define DSI_WR_DATA 0xA
|
||||
#define DSI_TRIGGER 0x13
|
||||
#define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15
|
||||
#define MIPI_DSI_DCS_LONG_WRITE 0x39
|
||||
#define MIPI_DCS_PRIV_SM_SET_REG_OFFSET 0xB0
|
||||
#define MIPI_DCS_PRIV_SM_SET_ELVSS 0xB1
|
||||
|
||||
dsi[DSI_VIDEO_MODE_CONTROL] = true;
|
||||
svcSleepThread(20000000);
|
||||
@@ -164,9 +168,10 @@ namespace display {
|
||||
g_config.isDocked = isDocked;
|
||||
}
|
||||
|
||||
bool Initialize(const DisplayRefreshConfig* config) {
|
||||
if (!config) return false;
|
||||
|
||||
bool Initialize(const DisplayRefreshConfig *config) {
|
||||
if (!config)
|
||||
return false;
|
||||
|
||||
g_config = *config;
|
||||
g_initialized = true;
|
||||
return true;
|
||||
@@ -175,34 +180,38 @@ namespace display {
|
||||
void CorrectOledGamma(uint32_t refresh_rate) {
|
||||
static uint32_t last_refresh_rate = 60;
|
||||
static int counter = 0;
|
||||
|
||||
|
||||
if (g_config.isDocked || refresh_rate < 45 || refresh_rate > 60) {
|
||||
last_refresh_rate = 60;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (counter != 9) {
|
||||
counter++;
|
||||
return;
|
||||
}
|
||||
counter = 0;
|
||||
|
||||
uint32_t offsets[] = {0x1A, 0x24, 0x25};
|
||||
uint32_t values[] = {2, 0, 0x83};
|
||||
|
||||
uint32_t offsets[] = { 0x1A, 0x24, 0x25 };
|
||||
uint32_t values[] = { 2, 0, 0x83 };
|
||||
|
||||
if (refresh_rate == 60) {
|
||||
if (last_refresh_rate == 60) return;
|
||||
if (last_refresh_rate == 60)
|
||||
return;
|
||||
} else if (refresh_rate == 45) {
|
||||
if (last_refresh_rate == 45) return;
|
||||
uint32_t vals[] = {4, 1, 0};
|
||||
if (last_refresh_rate == 45)
|
||||
return;
|
||||
uint32_t vals[] = { 4, 1, 0 };
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else if (refresh_rate == 50) {
|
||||
if (last_refresh_rate == 50) return;
|
||||
uint32_t vals[] = {3, 1, 0};
|
||||
if (last_refresh_rate == 50)
|
||||
return;
|
||||
uint32_t vals[] = { 3, 1, 0 };
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else if (refresh_rate == 55) {
|
||||
if (last_refresh_rate == 55) return;
|
||||
uint32_t vals[] = {3, 1, 0};
|
||||
if (last_refresh_rate == 55)
|
||||
return;
|
||||
uint32_t vals[] = { 3, 1, 0 };
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else {
|
||||
return;
|
||||
@@ -227,69 +236,72 @@ namespace display {
|
||||
static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
||||
uint8_t highestRefreshRate = 60;
|
||||
uint32_t fd = fd_in;
|
||||
|
||||
if(!fd) nvOpen(&fd, "/dev/nvdisp-disp1");
|
||||
NvdcModeDB2 db2 = {0};
|
||||
|
||||
if (!fd)
|
||||
nvOpen(&fd, "/dev/nvdisp-disp1");
|
||||
NvdcModeDB2 db2 = { 0 };
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
|
||||
|
||||
|
||||
if (rc == 0) {
|
||||
for (size_t i = 0; i < db2.num_modes; i++) {
|
||||
if (db2.modes[i].hActive < 1920 || db2.modes[i].vActive < 1080)
|
||||
if (db2.modes[i].hActive < 1920 || db2.modes[i].vActive < 1080)
|
||||
continue;
|
||||
|
||||
|
||||
uint32_t v_total = db2.modes[i].vActive + db2.modes[i].vSyncWidth + db2.modes[i].vFrontPorch + db2.modes[i].vBackPorch;
|
||||
uint32_t h_total = db2.modes[i].hActive + db2.modes[i].hSyncWidth + db2.modes[i].hFrontPorch + db2.modes[i].hBackPorch;
|
||||
double refreshRate = round((double)(db2.modes[i].pclkKHz * 1000) / (double)(v_total * h_total));
|
||||
|
||||
if (highestRefreshRate < (uint8_t)refreshRate)
|
||||
|
||||
if (highestRefreshRate < (uint8_t)refreshRate)
|
||||
highestRefreshRate = (uint8_t)refreshRate;
|
||||
}
|
||||
} else {
|
||||
g_dockedHighestRefreshRate = 60;
|
||||
}
|
||||
|
||||
|
||||
const size_t numRates = sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]);
|
||||
if (highestRefreshRate > g_dockedRefreshRates[numRates - 1])
|
||||
if (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);
|
||||
|
||||
|
||||
struct dpaux_read_0x100 {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned int lane_count : 5;
|
||||
unsigned int unk1 : 2;
|
||||
unsigned int isFramingEnhanced : 1;
|
||||
unsigned char downspread;
|
||||
unsigned char training_pattern;
|
||||
unsigned char lane_pattern[4];
|
||||
unsigned char unk2[8];
|
||||
} set;
|
||||
} dpaux = {6, 0x100, 0x10};
|
||||
|
||||
} dpaux = { 6, 0x100, 0x10 };
|
||||
|
||||
rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
if (rc == 0) {
|
||||
g_dockedLinkRate = dpaux.set.link_rate;
|
||||
// if (display_b.hActive == 1920 && display_b.vActive == 1080 && highestRefreshRate > 75 && dpaux.set.link_rate < 20 && )
|
||||
// if (display_b.hActive == 1920 && display_b.vActive == 1080 && highestRefreshRate > 75 && dpaux.set.link_rate < 20 && )
|
||||
// highestRefreshRate = 75;
|
||||
}
|
||||
|
||||
if (!fd_in) nvClose(fd);
|
||||
|
||||
if (!fd_in)
|
||||
nvClose(fd);
|
||||
g_dockedHighestRefreshRate = highestRefreshRate;
|
||||
}
|
||||
|
||||
static bool _setPLLDHandheldRefreshRate(uint32_t new_refreshRate) {
|
||||
if (!g_config.clkVirtAddr) return false;
|
||||
if (!g_config.clkVirtAddr)
|
||||
return false;
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
struct dpaux_read {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
@@ -298,24 +310,26 @@ namespace display {
|
||||
unsigned int rev_minor : 4;
|
||||
unsigned int rev_major : 4;
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned int lane_count : 5;
|
||||
unsigned int unk1 : 2;
|
||||
unsigned int isFramingEnhanced : 1;
|
||||
unsigned char unk2[13];
|
||||
} DPCD;
|
||||
} dpaux = {6, 0, 0x10};
|
||||
|
||||
} dpaux = { 6, 0, 0x10 };
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
if (rc != 0x75c) return false;
|
||||
if (rc != 0x75c)
|
||||
return false;
|
||||
|
||||
PLLD_BASE base = { 0 };
|
||||
PLLD_MISC misc = { 0 };
|
||||
memcpy(&base, (void *)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
PLLD_BASE base = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&base, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
uint32_t value = ((base.PLLD_DIVN / base.PLLD_DIVM) * 10) / 4;
|
||||
if (value == 0 || value == 80) return false;
|
||||
if (value == 0 || value == 80)
|
||||
return false;
|
||||
|
||||
if (new_refreshRate > g_handheldModeRefreshRate.max) {
|
||||
new_refreshRate = g_handheldModeRefreshRate.max;
|
||||
@@ -337,7 +351,8 @@ namespace display {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!skip) new_refreshRate = 60;
|
||||
if (!skip)
|
||||
new_refreshRate = 60;
|
||||
}
|
||||
|
||||
uint32_t pixelClock = (9375 * ((4096 * ((2 * base.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * base.PLLD_DIVM);
|
||||
@@ -354,35 +369,34 @@ namespace display {
|
||||
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));
|
||||
|
||||
memcpy((void*)(g_config.clkVirtAddr + 0xD0), &base, 4);
|
||||
memcpy((void*)(g_config.clkVirtAddr + 0xDC), &misc, 4);
|
||||
memcpy((void *)(g_config.clkVirtAddr + 0xD0), &base, 4);
|
||||
memcpy((void *)(g_config.clkVirtAddr + 0xDC), &misc, 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _setNvDispDockedRefreshRate(uint32_t new_refreshRate) {
|
||||
if (g_config.isLite || !g_canChangeRefreshRateDocked)
|
||||
return false;
|
||||
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NvdcMode2 display_b = {0};
|
||||
|
||||
NvdcMode2 display_b = { 0 };
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||
if (rc != 0) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!((display_b.vActive == 480 && display_b.hActive == 720) ||
|
||||
(display_b.vActive == 720 && display_b.hActive == 1280) ||
|
||||
(display_b.vActive == 1080 && display_b.hActive == 1920))) {
|
||||
|
||||
if (!((display_b.vActive == 480 && display_b.hActive == 720) || (display_b.vActive == 720 && display_b.hActive == 1280) ||
|
||||
(display_b.vActive == 1080 && display_b.hActive == 1920))) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
@@ -394,15 +408,15 @@ namespace display {
|
||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
uint32_t refreshRateNow = ((display_b.pclkKHz) * 1000 + 999) / (h_total * v_total);
|
||||
|
||||
|
||||
int8_t itr = -1;
|
||||
const size_t numRates = sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]);
|
||||
|
||||
|
||||
// Find closest matching refresh rate
|
||||
if ((new_refreshRate <= 60) && ((60 % new_refreshRate) == 0)) {
|
||||
itr = _getDockedRefreshRateIterator(60);
|
||||
}
|
||||
|
||||
|
||||
if (itr == -1) {
|
||||
for (size_t i = 0; i < numRates; i++) {
|
||||
uint8_t val = g_dockedRefreshRates[i];
|
||||
@@ -412,7 +426,7 @@ namespace display {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (itr == -1) {
|
||||
if (!g_config.matchLowestDocked) {
|
||||
itr = _getDockedRefreshRateIterator(60);
|
||||
@@ -425,9 +439,10 @@ namespace display {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itr == -1) itr = _getDockedRefreshRateIterator(60);
|
||||
|
||||
|
||||
if (itr == -1)
|
||||
itr = _getDockedRefreshRateIterator(60);
|
||||
|
||||
// Clamp to highest allowed refresh rate
|
||||
if (g_dockedRefreshRates[itr] > g_dockedHighestRefreshRate) {
|
||||
for (int8_t i = itr; i >= 0; i--) {
|
||||
@@ -437,7 +452,7 @@ namespace display {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (refreshRateNow == g_dockedRefreshRates[itr]) {
|
||||
nvClose(fd);
|
||||
return true;
|
||||
@@ -460,46 +475,47 @@ namespace display {
|
||||
display_b.sync = 3;
|
||||
display_b.bitsPerPixel = 24;
|
||||
}
|
||||
|
||||
|
||||
rc = nvIoctl(fd, NVDISP_VALIDATE_MODE2, &display_b);
|
||||
if (rc == 0) {
|
||||
rc = nvIoctl(fd, NVDISP_SET_MODE2, &display_b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _setNvDispHandheldRefreshRate(uint32_t new_refreshRate) {
|
||||
if (!g_config.isRetroSUPER) return false;
|
||||
|
||||
if (!g_config.isRetroSUPER)
|
||||
return false;
|
||||
|
||||
if (!g_config.displaySync) {
|
||||
g_wasRetroSuperTurnedOff = false;
|
||||
} else if (g_wasRetroSuperTurnedOff) {
|
||||
svcSleepThread(2000000000);
|
||||
g_wasRetroSuperTurnedOff = false;
|
||||
}
|
||||
|
||||
|
||||
svcSleepThread(1000000000);
|
||||
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NvdcMode2 display_b = {0};
|
||||
|
||||
NvdcMode2 display_b = { 0 };
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||
if (rc != 0) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ((display_b.vActive == 1280 && display_b.hActive == 720) == false) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
@@ -529,7 +545,8 @@ namespace display {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!skip) new_refreshRate = 60;
|
||||
if (!skip)
|
||||
new_refreshRate = 60;
|
||||
}
|
||||
|
||||
if (new_refreshRate == refreshRateNow) {
|
||||
@@ -552,25 +569,25 @@ namespace display {
|
||||
nvIoctl(fd, NVDISP_SET_MODE2, &display_b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetRate(uint32_t new_refreshRate) {
|
||||
if (!new_refreshRate || !g_initialized) return false;
|
||||
if (!new_refreshRate || !g_initialized)
|
||||
return false;
|
||||
|
||||
uint32_t fd = 0;
|
||||
|
||||
|
||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
struct dpaux_read {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
@@ -579,48 +596,49 @@ namespace display {
|
||||
unsigned int rev_minor : 4;
|
||||
unsigned int rev_major : 4;
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned int lane_count : 5;
|
||||
unsigned int unk1 : 2;
|
||||
unsigned int isFramingEnhanced : 1;
|
||||
unsigned char unk2[13];
|
||||
} DPCD;
|
||||
} dpaux = {6, 0, 0x10};
|
||||
|
||||
} dpaux = { 6, 0, 0x10 };
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
|
||||
|
||||
if (rc != 0) {
|
||||
if (!g_config.isRetroSUPER) {
|
||||
return _setPLLDHandheldRefreshRate(new_refreshRate);
|
||||
} else {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
if (!g_config.isRetroSUPER) {
|
||||
return _setPLLDHandheldRefreshRate(new_refreshRate);
|
||||
} else {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
} else {
|
||||
if(g_config.isDocked)
|
||||
if (g_config.isDocked)
|
||||
return _setNvDispDockedRefreshRate(new_refreshRate);
|
||||
else
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetRate(uint32_t* out_refreshRate, bool internal) {
|
||||
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr) return false;
|
||||
bool GetRate(uint32_t *out_refreshRate, bool internal) {
|
||||
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr)
|
||||
return false;
|
||||
static uint32_t value = 60;
|
||||
|
||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||
uint32_t fd = 0;
|
||||
PLLD_BASE temp = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
PLLD_BASE temp = { 0 };
|
||||
PLLD_MISC misc = { 0 };
|
||||
memcpy(&temp, (void *)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
||||
|
||||
|
||||
if (value != 0 && value != 80) {
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
NvdcMode2 display_b = {0};
|
||||
NvdcMode2 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 v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
@@ -634,21 +652,21 @@ namespace display {
|
||||
} else {
|
||||
g_wasRetroSuperTurnedOff = true;
|
||||
}
|
||||
}
|
||||
else if ((!g_config.isPossiblySpoofedRetro) || (g_config.isPossiblySpoofedRetro && !g_config.isRetroSUPER)) {
|
||||
PLLD_BASE temp = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
} else if ((!g_config.isPossiblySpoofedRetro) || (g_config.isPossiblySpoofedRetro && !g_config.isRetroSUPER)) {
|
||||
PLLD_BASE temp = { 0 };
|
||||
PLLD_MISC misc = { 0 };
|
||||
memcpy(&temp, (void *)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void *)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
||||
|
||||
|
||||
if (value == 0 || value == 80) {
|
||||
// Docked mode
|
||||
if (g_config.isLite) return false;
|
||||
|
||||
if (g_config.isLite)
|
||||
return false;
|
||||
|
||||
g_config.isDocked = true;
|
||||
|
||||
|
||||
if (!g_canChangeRefreshRateDocked) {
|
||||
uint32_t fd = 0;
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
@@ -658,19 +676,19 @@ namespace display {
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned int lane_count : 5;
|
||||
unsigned int unk1 : 2;
|
||||
unsigned int isFramingEnhanced : 1;
|
||||
unsigned char downspread;
|
||||
unsigned char training_pattern;
|
||||
unsigned char lane_pattern[4];
|
||||
unsigned char unk2[8];
|
||||
} set;
|
||||
} dpaux = {6, 0x100, 0x10};
|
||||
|
||||
} dpaux = { 6, 0x100, 0x10 };
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
|
||||
|
||||
if (rc == 0) {
|
||||
_getDockedHighestRefreshRate(0);
|
||||
g_canChangeRefreshRateDocked = true;
|
||||
@@ -682,24 +700,24 @@ namespace display {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(internal) {
|
||||
if (internal) {
|
||||
*out_refreshRate = value;
|
||||
return true;
|
||||
}
|
||||
uint32_t fd = 0;
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
NvdcMode2 display_b = {0};
|
||||
NvdcMode2 display_b = { 0 };
|
||||
if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) {
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (g_lastVActive != display_b.vActive) {
|
||||
g_lastVActive = display_b.vActive;
|
||||
_getDockedHighestRefreshRate(fd);
|
||||
}
|
||||
|
||||
|
||||
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 pixelClock = display_b.pclkKHz * 1000 + 999;
|
||||
@@ -711,16 +729,14 @@ namespace display {
|
||||
} else {
|
||||
value = 60;
|
||||
}
|
||||
}
|
||||
else if (!g_config.isRetroSUPER) {
|
||||
} else if (!g_config.isRetroSUPER) {
|
||||
// Handheld mode
|
||||
g_config.isDocked = false;
|
||||
g_canChangeRefreshRateDocked = false;
|
||||
|
||||
|
||||
uint32_t pixelClock = (9375ULL * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
|
||||
value = pixelClock / (DSI_CLOCK_HZ / 60);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -733,4 +749,4 @@ namespace display {
|
||||
g_initialized = false;
|
||||
memset(&g_config, 0, sizeof(g_config));
|
||||
}
|
||||
}
|
||||
} // namespace display
|
||||
@@ -12,14 +12,14 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
namespace display {
|
||||
typedef struct {
|
||||
uint16_t hFrontPorch;
|
||||
@@ -71,35 +71,35 @@ namespace display {
|
||||
} NvdcModeDB2;
|
||||
|
||||
typedef struct {
|
||||
unsigned int PLLD_DIVM: 8;
|
||||
unsigned int reserved_1: 3;
|
||||
unsigned int PLLD_DIVN: 8;
|
||||
unsigned int reserved_2: 1;
|
||||
unsigned int PLLD_DIVP: 3;
|
||||
unsigned int CSI_CLK_SRC: 1;
|
||||
unsigned int reserved_3: 1;
|
||||
unsigned int PLL_D: 1;
|
||||
unsigned int reserved_4: 1;
|
||||
unsigned int PLLD_LOCK: 1;
|
||||
unsigned int reserved_5: 1;
|
||||
unsigned int PLLD_REF_DIS: 1;
|
||||
unsigned int PLLD_ENABLE: 1;
|
||||
unsigned int PLLD_BYPASS: 1;
|
||||
unsigned int PLLD_DIVM : 8;
|
||||
unsigned int reserved_1 : 3;
|
||||
unsigned int PLLD_DIVN : 8;
|
||||
unsigned int reserved_2 : 1;
|
||||
unsigned int PLLD_DIVP : 3;
|
||||
unsigned int CSI_CLK_SRC : 1;
|
||||
unsigned int reserved_3 : 1;
|
||||
unsigned int PLL_D : 1;
|
||||
unsigned int reserved_4 : 1;
|
||||
unsigned int PLLD_LOCK : 1;
|
||||
unsigned int reserved_5 : 1;
|
||||
unsigned int PLLD_REF_DIS : 1;
|
||||
unsigned int PLLD_ENABLE : 1;
|
||||
unsigned int PLLD_BYPASS : 1;
|
||||
} PLLD_BASE;
|
||||
|
||||
typedef struct {
|
||||
signed int PLLD_SDM_DIN: 16;
|
||||
unsigned int PLLD_EN_SDM: 1;
|
||||
unsigned int PLLD_LOCK_OVERRIDE: 1;
|
||||
unsigned int PLLD_EN_LCKDET: 1;
|
||||
unsigned int PLLD_FREQLOCK: 1;
|
||||
unsigned int PLLD_IDDQ: 1;
|
||||
unsigned int PLLD_ENABLE_CLK: 1;
|
||||
unsigned int PLLD_KVCO: 1;
|
||||
unsigned int PLLD_KCP: 2;
|
||||
unsigned int PLLD_PTS: 2;
|
||||
unsigned int PLLD_LDPULSE_ADJ: 3;
|
||||
unsigned int reserved: 2;
|
||||
signed int PLLD_SDM_DIN : 16;
|
||||
unsigned int PLLD_EN_SDM : 1;
|
||||
unsigned int PLLD_LOCK_OVERRIDE : 1;
|
||||
unsigned int PLLD_EN_LCKDET : 1;
|
||||
unsigned int PLLD_FREQLOCK : 1;
|
||||
unsigned int PLLD_IDDQ : 1;
|
||||
unsigned int PLLD_ENABLE_CLK : 1;
|
||||
unsigned int PLLD_KVCO : 1;
|
||||
unsigned int PLLD_KCP : 2;
|
||||
unsigned int PLLD_PTS : 2;
|
||||
unsigned int PLLD_LDPULSE_ADJ : 3;
|
||||
unsigned int reserved : 2;
|
||||
} PLLD_MISC;
|
||||
|
||||
typedef struct {
|
||||
@@ -116,12 +116,12 @@ namespace display {
|
||||
bool displaySyncDocked;
|
||||
bool displaySyncDockedOutOfFocus60;
|
||||
} DisplayRefreshConfig;
|
||||
bool Initialize(const DisplayRefreshConfig* config);
|
||||
bool Initialize(const DisplayRefreshConfig *config);
|
||||
void SetDockedState(bool isDocked);
|
||||
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);
|
||||
void CorrectOledGamma(uint32_t refresh_rate);
|
||||
void SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p);
|
||||
void Shutdown(void);
|
||||
}
|
||||
} // namespace display
|
||||
@@ -24,29 +24,30 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "config.hpp"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <initializer_list>
|
||||
#include <minIni.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <map>
|
||||
#include <max17050.h>
|
||||
#include <minIni.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../board/board.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "config.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include <initializer_list>
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace config {
|
||||
|
||||
@@ -57,7 +58,7 @@ namespace config {
|
||||
bool gLoaded = false;
|
||||
std::string gPath;
|
||||
time_t gMtime = 0;
|
||||
std::atomic_bool gEnabled{false};
|
||||
std::atomic_bool gEnabled{ false };
|
||||
std::uint32_t gOverrideFreqs[HocClkModule_EnumMax];
|
||||
std::map<std::tuple<std::uint64_t, HocClkProfile, HocClkModule>, std::uint32_t> gProfileMHzMap;
|
||||
std::map<std::uint64_t, std::uint8_t> gProfileCountMap;
|
||||
@@ -83,11 +84,12 @@ namespace config {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint32_t FindClockHzFromProfiles(std::uint64_t tid, HocClkModule module, std::initializer_list<HocClkProfile> profiles, u32 mhzMultiplier = 1000000) {
|
||||
std::uint32_t FindClockHzFromProfiles(std::uint64_t tid, HocClkModule module, std::initializer_list<HocClkProfile> profiles,
|
||||
u32 mhzMultiplier = 1000000) {
|
||||
std::uint32_t mhz = 0;
|
||||
|
||||
if (gLoaded) {
|
||||
for (auto profile: profiles) {
|
||||
for (auto profile : profiles) {
|
||||
mhz = FindClockMHz(tid, module, profile);
|
||||
if (mhz) {
|
||||
break;
|
||||
@@ -98,7 +100,7 @@ namespace config {
|
||||
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;
|
||||
std::uint64_t input;
|
||||
if (!strcmp(section, CONFIG_VAL_SECTION)) {
|
||||
@@ -129,14 +131,14 @@ namespace config {
|
||||
HocClkModule parsedModule = HocClkModule_EnumMax;
|
||||
|
||||
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);
|
||||
|
||||
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++) {
|
||||
const char* moduleCode = board::GetModuleName((HocClkModule)module, false);
|
||||
const char *moduleCode = board::GetModuleName((HocClkModule)module, false);
|
||||
size_t moduleCodeLen = strlen(moduleCode);
|
||||
if (!strncmp(subkey, moduleCode, moduleCodeLen) && subkey[moduleCodeLen] == '\0') {
|
||||
parsedProfile = (HocClkProfile)profile;
|
||||
@@ -191,7 +193,7 @@ namespace config {
|
||||
gLoaded = true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Initialize() {
|
||||
gPath = FILE_CONFIG_DIR "/config.ini";
|
||||
@@ -209,12 +211,12 @@ namespace config {
|
||||
}
|
||||
|
||||
void Exit() {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
Close();
|
||||
}
|
||||
|
||||
bool Refresh() {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
if (!gLoaded || gMtime != CheckModificationTime()) {
|
||||
Load();
|
||||
return true;
|
||||
@@ -223,30 +225,34 @@ namespace config {
|
||||
}
|
||||
|
||||
bool HasProfilesLoaded() {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
return gLoaded;
|
||||
}
|
||||
|
||||
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) {
|
||||
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_HandheldChargingUSB:
|
||||
return FindClockHzFromProfiles(tid, module, {HocClkProfile_HandheldChargingUSB, HocClkProfile_HandheldCharging, HocClkProfile_Handheld}, returnRaw ? 1 : 1000000);
|
||||
return FindClockHzFromProfiles(tid, module,
|
||||
{ HocClkProfile_HandheldChargingUSB, HocClkProfile_HandheldCharging, HocClkProfile_Handheld },
|
||||
returnRaw ? 1 : 1000000);
|
||||
case HocClkProfile_HandheldChargingOfficial:
|
||||
return FindClockHzFromProfiles(tid, module, {HocClkProfile_HandheldChargingOfficial, HocClkProfile_HandheldCharging, HocClkProfile_Handheld}, returnRaw ? 1 : 1000000);
|
||||
return FindClockHzFromProfiles(tid, module,
|
||||
{ HocClkProfile_HandheldChargingOfficial, HocClkProfile_HandheldCharging, HocClkProfile_Handheld },
|
||||
returnRaw ? 1 : 1000000);
|
||||
case HocClkProfile_Docked:
|
||||
return FindClockHzFromProfiles(tid, module, {HocClkProfile_Docked}, returnRaw ? 1 : 1000000);
|
||||
return FindClockHzFromProfiles(tid, module, { HocClkProfile_Docked }, returnRaw ? 1 : 1000000);
|
||||
default:
|
||||
ERROR_THROW("Unhandled HocClkProfile: %u", profile);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList* out_profiles) {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList *out_profiles) {
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
for (unsigned int profile = 0; profile < HocClkProfile_EnumMax; profile++) {
|
||||
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
|
||||
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) {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList *profiles, bool immediate) {
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
uint8_t numProfiles = 0;
|
||||
|
||||
char section[17] = {0};
|
||||
char section[17] = { 0 };
|
||||
snprintf(section, sizeof(section), "%016lX", tid);
|
||||
|
||||
std::vector<std::string> keys;
|
||||
@@ -266,16 +272,15 @@ namespace config {
|
||||
keys.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 module = 0; module < HocClkModule_EnumMax; module++) {
|
||||
if (*mhz) {
|
||||
numProfiles++;
|
||||
|
||||
std::string key = std::string(board::GetProfileName((HocClkProfile)profile, false)) +
|
||||
"_" +
|
||||
board::GetModuleName((HocClkModule)module, false);
|
||||
std::string key =
|
||||
std::string(board::GetProfileName((HocClkProfile)profile, false)) + "_" + board::GetModuleName((HocClkModule)module, false);
|
||||
std::string value = std::to_string(*mhz);
|
||||
|
||||
keys.push_back(key);
|
||||
@@ -285,8 +290,8 @@ namespace config {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const char*> keyPointers;
|
||||
std::vector<const char*> valuePointers;
|
||||
std::vector<const char *> keyPointers;
|
||||
std::vector<const char *> valuePointers;
|
||||
keyPointers.reserve(keys.size() + 1);
|
||||
valuePointers.reserve(values.size() + 1);
|
||||
|
||||
@@ -337,45 +342,45 @@ namespace config {
|
||||
|
||||
void SetOverrideHz(HocClkModule module, std::uint32_t hz) {
|
||||
ASSERT_ENUM_VALID(HocClkModule, module);
|
||||
std::scoped_lock lock{gOverrideMutex};
|
||||
std::scoped_lock lock{ gOverrideMutex };
|
||||
gOverrideFreqs[module] = hz;
|
||||
}
|
||||
|
||||
std::uint32_t GetOverrideHz(HocClkModule module) {
|
||||
ASSERT_ENUM_VALID(HocClkModule, module);
|
||||
std::scoped_lock lock{gOverrideMutex};
|
||||
std::scoped_lock lock{ gOverrideMutex };
|
||||
return gOverrideFreqs[module];
|
||||
}
|
||||
|
||||
std::uint64_t GetConfigValue(HocClkConfigValue kval) {
|
||||
ASSERT_ENUM_VALID(HocClkConfigValue, kval);
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
return configValues[kval];
|
||||
}
|
||||
|
||||
const char* GetConfigValueName(HocClkConfigValue kval, bool pretty) {
|
||||
const char *GetConfigValueName(HocClkConfigValue kval, bool pretty) {
|
||||
ASSERT_ENUM_VALID(HocClkConfigValue, kval);
|
||||
return hocclkFormatConfigValue(kval, pretty);
|
||||
}
|
||||
|
||||
void GetConfigValues(HocClkConfigValueList* out_configValues) {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
void GetConfigValues(HocClkConfigValueList *out_configValues) {
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) {
|
||||
out_configValues->values[kval] = configValues[kval];
|
||||
}
|
||||
}
|
||||
|
||||
bool SetConfigValues(HocClkConfigValueList* configValues, bool immediate) {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
bool SetConfigValues(HocClkConfigValueList *configValues, bool immediate) {
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
|
||||
std::vector<const char*> iniKeys;
|
||||
std::vector<const char *> iniKeys;
|
||||
std::vector<std::string> iniValues;
|
||||
iniKeys.reserve(HocClkConfigValue_EnumMax + 1);
|
||||
iniValues.reserve(HocClkConfigValue_EnumMax);
|
||||
|
||||
for (unsigned int kval = 0; kval < HocClkConfigValue_EnumMax; kval++) {
|
||||
if (!hocclkValidConfigValue((HocClkConfigValue)kval, configValues->values[kval]) ||
|
||||
configValues->values[kval] == hocclkDefaultConfigValue((HocClkConfigValue)kval)) {
|
||||
configValues->values[kval] == hocclkDefaultConfigValue((HocClkConfigValue)kval)) {
|
||||
continue;
|
||||
}
|
||||
iniValues.push_back(std::to_string(configValues->values[kval]));
|
||||
@@ -384,9 +389,9 @@ namespace config {
|
||||
|
||||
iniKeys.push_back(NULL);
|
||||
|
||||
std::vector<const char*> valuePointers;
|
||||
std::vector<const char *> valuePointers;
|
||||
valuePointers.reserve(iniValues.size() + 1);
|
||||
for (const auto& val : iniValues) {
|
||||
for (const auto &val : iniValues) {
|
||||
valuePointers.push_back(val.c_str());
|
||||
}
|
||||
valuePointers.push_back(NULL);
|
||||
@@ -414,11 +419,11 @@ namespace config {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
|
||||
std::uint64_t defaultValue = hocclkDefaultConfigValue(kval);
|
||||
|
||||
std::vector<const char*> iniKeys;
|
||||
std::vector<const char *> iniKeys;
|
||||
std::vector<std::string> iniValues;
|
||||
iniKeys.reserve(2);
|
||||
iniValues.reserve(1);
|
||||
@@ -427,9 +432,9 @@ namespace config {
|
||||
iniValues.push_back("");
|
||||
iniKeys.push_back(NULL);
|
||||
|
||||
std::vector<const char*> valuePointers;
|
||||
std::vector<const char *> valuePointers;
|
||||
valuePointers.reserve(iniValues.size() + 1);
|
||||
for (const auto& val : iniValues) {
|
||||
for (const auto &val : iniValues) {
|
||||
valuePointers.push_back(val.c_str());
|
||||
}
|
||||
valuePointers.push_back(NULL);
|
||||
@@ -453,9 +458,9 @@ namespace config {
|
||||
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;
|
||||
iniKeys.reserve(2);
|
||||
iniValues.reserve(1);
|
||||
@@ -464,7 +469,7 @@ namespace config {
|
||||
iniValues.push_back(std::to_string(value));
|
||||
iniKeys.push_back(NULL);
|
||||
|
||||
std::vector<const char*> valuePointers;
|
||||
std::vector<const char *> valuePointers;
|
||||
valuePointers.reserve(2);
|
||||
valuePointers.push_back(iniValues[0].c_str());
|
||||
valuePointers.push_back(NULL);
|
||||
@@ -480,8 +485,8 @@ namespace config {
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeleteKey(const char* section, const char* key) {
|
||||
std::scoped_lock lock{gConfigMutex};
|
||||
void DeleteKey(const char *section, const char *key) {
|
||||
std::scoped_lock lock{ gConfigMutex };
|
||||
ini_puts(section, key, NULL, gPath.c_str());
|
||||
}
|
||||
}
|
||||
} // namespace config
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace config {
|
||||
bool HasProfilesLoaded();
|
||||
|
||||
std::uint8_t GetProfileCount(std::uint64_t tid);
|
||||
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList* out_profiles);
|
||||
bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList* profiles, bool immediate);
|
||||
void GetProfiles(std::uint64_t tid, HocClkTitleProfileList *out_profiles);
|
||||
bool SetProfiles(std::uint64_t tid, HocClkTitleProfileList *profiles, bool immediate);
|
||||
std::uint32_t GetAutoClockHz(std::uint64_t tid, HocClkModule module, HocClkProfile profile, bool returnRaw);
|
||||
|
||||
void SetEnabled(bool enabled);
|
||||
@@ -50,13 +50,13 @@ namespace config {
|
||||
std::uint32_t GetOverrideHz(HocClkModule module);
|
||||
|
||||
std::uint64_t GetConfigValue(HocClkConfigValue val);
|
||||
const char* GetConfigValueName(HocClkConfigValue val, bool pretty);
|
||||
void GetConfigValues(HocClkConfigValueList* out_configValues);
|
||||
bool SetConfigValues(HocClkConfigValueList* configValues, bool immediate);
|
||||
const char *GetConfigValueName(HocClkConfigValue val, bool pretty);
|
||||
void GetConfigValues(HocClkConfigValueList *out_configValues);
|
||||
bool SetConfigValues(HocClkConfigValueList *configValues, bool immediate);
|
||||
bool ResetConfigValue(HocClkConfigValue kval);
|
||||
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];
|
||||
|
||||
}
|
||||
} // namespace config
|
||||
|
||||
@@ -24,13 +24,14 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "file_utils.hpp"
|
||||
|
||||
namespace errors {
|
||||
void ThrowException(const char* format, ...) {
|
||||
void ThrowException(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
fileUtils::LogLine(format, args);
|
||||
@@ -38,4 +39,4 @@ namespace errors {
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
// throw std::runtime_error(msg);
|
||||
}
|
||||
}
|
||||
} // namespace errors
|
||||
|
||||
@@ -26,14 +26,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <stdexcept>
|
||||
#include <switch.h>
|
||||
|
||||
#define ERROR_THROW(format, ...) errors::ThrowException(format "\n in %s:%u", ##__VA_ARGS__, __FILE__, __LINE__)
|
||||
#define ERROR_RESULT_THROW(rc, format, ...) ERROR_THROW(format "\n RC: [0x%x] %04d-%04d", ##__VA_ARGS__, rc, R_MODULE(rc), R_DESCRIPTION(rc))
|
||||
#define ASSERT_RESULT_OK(rc, format, ...) \
|
||||
if (R_FAILED(rc)) \
|
||||
{ \
|
||||
#define ASSERT_RESULT_OK(rc, format, ...) \
|
||||
if (R_FAILED(rc)) { \
|
||||
ERROR_RESULT_THROW(rc, "ASSERT_RESULT_OK: " format, ##__VA_ARGS__); \
|
||||
}
|
||||
#define ASSERT_ENUM_VALID(n, v) \
|
||||
@@ -43,6 +42,6 @@
|
||||
|
||||
namespace errors {
|
||||
|
||||
void ThrowException(const char* format, ...);
|
||||
void ThrowException(const char *format, ...);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "file_utils.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "file_utils.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
|
||||
@@ -52,7 +53,7 @@ namespace fileUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* file = fopen(FILE_LOG_FLAG_PATH, "r");
|
||||
FILE *file = fopen(FILE_LOG_FLAG_PATH, "r");
|
||||
if (file) {
|
||||
g_log_enabled = true;
|
||||
fclose(file);
|
||||
@@ -63,11 +64,11 @@ namespace fileUtils {
|
||||
g_last_flag_check = now;
|
||||
}
|
||||
|
||||
void InitializeThreadFunc(void* args) {
|
||||
void InitializeThreadFunc(void *args) {
|
||||
Initialize();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool IsInitialized() {
|
||||
return g_has_initialized;
|
||||
@@ -77,8 +78,8 @@ namespace fileUtils {
|
||||
return g_log_enabled;
|
||||
}
|
||||
|
||||
void LogLine(const char* format, ...) {
|
||||
std::scoped_lock lock{g_log_mutex};
|
||||
void LogLine(const char *format, ...) {
|
||||
std::scoped_lock lock{ g_log_mutex };
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -86,7 +87,7 @@ namespace fileUtils {
|
||||
RefreshFlags(false);
|
||||
|
||||
if (g_log_enabled) {
|
||||
FILE* file = fopen(FILE_LOG_FILE_PATH, "a");
|
||||
FILE *file = fopen(FILE_LOG_FILE_PATH, "a");
|
||||
|
||||
if (file) {
|
||||
timespec now = {};
|
||||
@@ -102,10 +103,10 @@ namespace fileUtils {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void WriteContextToCsv(const HocClkContext* context) {
|
||||
std::scoped_lock lock{g_csv_mutex};
|
||||
void WriteContextToCsv(const HocClkContext *context) {
|
||||
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) {
|
||||
// Print header
|
||||
@@ -134,7 +135,8 @@ namespace fileUtils {
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
|
||||
fprintf(file, "%ld%03ld,%s,%016lx", now.tv_sec, now.tv_nsec / 1000000UL, hocclkFormatProfile(context->profile, false), context->applicationId);
|
||||
fprintf(file, "%ld%03ld,%s,%016lx", now.tv_sec, now.tv_nsec / 1000000UL, hocclkFormatProfile(context->profile, false),
|
||||
context->applicationId);
|
||||
|
||||
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
|
||||
fprintf(file, ",%d", context->freqs[module]);
|
||||
@@ -164,7 +166,7 @@ namespace fileUtils {
|
||||
}
|
||||
|
||||
void InitializeAsync() {
|
||||
Thread initThread = {0};
|
||||
Thread initThread = { 0 };
|
||||
threadCreate(&initThread, InitializeThreadFunc, NULL, NULL, 0x4000, 0x15, 0);
|
||||
threadStart(&initThread);
|
||||
}
|
||||
@@ -210,4 +212,4 @@ namespace fileUtils {
|
||||
fsExit();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace fileUtils
|
||||
|
||||
@@ -26,13 +26,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <cstdarg>
|
||||
#include <hocclk.h>
|
||||
#include <string>
|
||||
#include <switch.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
#define FILE_CONFIG_DIR "/config/" CONFIG_DIR
|
||||
#define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL)
|
||||
@@ -47,7 +47,7 @@ namespace fileUtils {
|
||||
bool IsInitialized();
|
||||
bool IsLogEnabled();
|
||||
void InitializeAsync();
|
||||
void LogLine(const char* format, ...);
|
||||
void WriteContextToCsv(const HocClkContext* context);
|
||||
void LogLine(const char *format, ...);
|
||||
void WriteContextToCsv(const HocClkContext *context);
|
||||
|
||||
}
|
||||
} // namespace fileUtils
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "kip.hpp"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../board/board.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../mgr/clock_manager.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include "kip.hpp"
|
||||
|
||||
|
||||
namespace kip {
|
||||
|
||||
bool kipAvailable = false;
|
||||
void SetKipData()
|
||||
{
|
||||
void SetKipData() {
|
||||
// TODO: figure out if this REALLY causes issues (i doubt it)
|
||||
// if(board::GetSocType() == HocClkSocType_Mariko) {
|
||||
// if(R_FAILED(I2c_BuckConverter_SetMvOut(&I2c_Mariko_DRAM_VDDQ, config::GetConfigValue(KipConfigValue_marikoEmcVddqVolt) / 1000))) {
|
||||
@@ -34,7 +34,7 @@ namespace kip {
|
||||
// }
|
||||
// }
|
||||
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) {
|
||||
notification::writeNotification("Horizon OC\nKip opening failed");
|
||||
@@ -50,7 +50,7 @@ namespace kip {
|
||||
return;
|
||||
}
|
||||
|
||||
u32 custRev = cust_get_cust_rev(&table);
|
||||
u32 custRev = cust_get_cust_rev(&table);
|
||||
u32 kipVersion = cust_get_kip_version(&table);
|
||||
if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
|
||||
fclose(fp);
|
||||
@@ -149,10 +149,11 @@ namespace kip {
|
||||
HocClkConfigValueList 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)) {
|
||||
fileUtils::LogLine("[kip] KIP data set. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32], configValues.values[KipConfigValue_custRev]);
|
||||
fileUtils::LogLine("[kip] KIP data set. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32],
|
||||
configValues.values[KipConfigValue_custRev]);
|
||||
for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
|
||||
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
|
||||
}
|
||||
@@ -164,9 +165,8 @@ namespace kip {
|
||||
|
||||
// I know this is very hacky, but the config system in the sysmodule doesn't really support writing
|
||||
|
||||
void GetKipData()
|
||||
{
|
||||
FILE* fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "rb");
|
||||
void GetKipData() {
|
||||
FILE *fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
notification::writeNotification("Horizon OC\nKip opening failed");
|
||||
@@ -192,22 +192,23 @@ namespace kip {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if ((u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip") != config::GetConfigValue(KipCrc32) && !config::GetConfigValue(HocClkConfigValue_IsFirstLoad)) {
|
||||
if ((u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip") != config::GetConfigValue(KipCrc32) &&
|
||||
!config::GetConfigValue(HocClkConfigValue_IsFirstLoad)) {
|
||||
MigrateKipData(cust_get_cust_rev(&table), cust_get_kip_version(&table));
|
||||
SetKipData();
|
||||
notification::writeNotification("Horizon OC\nKIP has been updated\nPlease reboot your console");
|
||||
return;
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
|
||||
notification::writeNotification("Horizon OC\nOutdated kip detected!\nPlease update Horizon OC");
|
||||
@@ -223,7 +224,7 @@ namespace kip {
|
||||
|
||||
clockManager::gContext.kipVersion = kipVersion;
|
||||
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_commonEmcMemVolt] = cust_get_common_emc_volt(&table);
|
||||
@@ -294,7 +295,8 @@ namespace kip {
|
||||
|
||||
if (sizeof(HocClkConfigValueList) <= sizeof(configValues)) {
|
||||
if (config::SetConfigValues(&configValues, true)) {
|
||||
fileUtils::LogLine("[kip] KIP loaded. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32], configValues.values[KipConfigValue_custRev]);
|
||||
fileUtils::LogLine("[kip] KIP loaded. CRC32: %ld (Cust Rev %ld)", configValues.values[KipCrc32],
|
||||
configValues.values[KipConfigValue_custRev]);
|
||||
for (u64 i = KipConfigValue_hpMode; i < HocClkConfigValue_EnumMax; i++) {
|
||||
fileUtils::LogLine("%s: %ld", hocclkFormatConfigValue((HocClkConfigValue)i, false), configValues.values[i]);
|
||||
}
|
||||
@@ -312,16 +314,17 @@ namespace kip {
|
||||
HocClkConfigValueList configValues;
|
||||
config::GetConfigValues(&configValues);
|
||||
u32 previousVersion = configValues.values[KipConfigValue_KipVersion];
|
||||
if(previousVersion < 240 && version >= 240) {
|
||||
if (previousVersion < 240 && version >= 240) {
|
||||
// <2.4.0 -> 2.4.0 migration
|
||||
|
||||
// add marikoGpuBootVolt with default value of 800mV
|
||||
configValues.values[KipConfigValue_marikoGpuBootVolt] = 800;
|
||||
|
||||
configValues.values[KipConfigValue_marikoGpuUV] += 2; // Raise UV levels
|
||||
configValues.values[KipConfigValue_commonGpuVoltOffset] = (u32)(-(s64)(configValues.values[KipConfigValue_commonGpuVoltOffset])); // Migrate GPU Volt Offset
|
||||
configValues.values[KipConfigValue_marikoGpuUV] += 2; // Raise UV levels
|
||||
configValues.values[KipConfigValue_commonGpuVoltOffset] =
|
||||
(u32)(-(s64)(configValues.values[KipConfigValue_commonGpuVoltOffset])); // Migrate GPU Volt Offset
|
||||
// Raise min cpu vmin
|
||||
if(configValues.values[KipConfigValue_eristaCpuVmin] < 750) {
|
||||
if (configValues.values[KipConfigValue_eristaCpuVmin] < 750) {
|
||||
configValues.values[KipConfigValue_eristaCpuVmin] = 750;
|
||||
}
|
||||
|
||||
@@ -332,5 +335,4 @@ namespace kip {
|
||||
}
|
||||
config::SetConfigValues(&configValues, true);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace kip
|
||||
|
||||
@@ -16,21 +16,23 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <crc32.h>
|
||||
#include <notification.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include <notification.h>
|
||||
#include <crc32.h>
|
||||
|
||||
|
||||
namespace kip {
|
||||
extern bool kipAvailable;
|
||||
|
||||
typedef struct {
|
||||
u8 cust[4];
|
||||
u8 cust[4];
|
||||
u32 custRev;
|
||||
u32 kipVersion;
|
||||
u32 hpMode;
|
||||
@@ -97,24 +99,25 @@ namespace kip {
|
||||
u32 reserved[60];
|
||||
} CustomizeTable;
|
||||
|
||||
#define CUST_MAGIC "CUST"
|
||||
#define CUST_MAGIC_LEN 4
|
||||
#define CUST_MAGIC "CUST"
|
||||
#define CUST_MAGIC_LEN 4
|
||||
|
||||
typedef struct {
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
long offset;
|
||||
CustomizeTable cached_table;
|
||||
bool has_cache;
|
||||
} 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];
|
||||
long pos = 0;
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
while (1) {
|
||||
size_t r = fread(buf, 1, sizeof(buf), f);
|
||||
if (r < CUST_MAGIC_LEN) break;
|
||||
if (r < CUST_MAGIC_LEN)
|
||||
break;
|
||||
|
||||
for (size_t i = 0; i <= r - CUST_MAGIC_LEN; i++) {
|
||||
if (memcmp(&buf[i], CUST_MAGIC, CUST_MAGIC_LEN) == 0) {
|
||||
@@ -130,23 +133,28 @@ namespace kip {
|
||||
|
||||
static long cachedCustOffset = -1;
|
||||
|
||||
static inline long cust_get_offset(FILE* f) {
|
||||
if (cachedCustOffset >= 0) return cachedCustOffset;
|
||||
static inline long cust_get_offset(FILE *f) {
|
||||
if (cachedCustOffset >= 0)
|
||||
return cachedCustOffset;
|
||||
long off;
|
||||
if (!cust_find_offset(f, &off)) return -1;
|
||||
if (!cust_find_offset(f, &off))
|
||||
return -1;
|
||||
cachedCustOffset = off;
|
||||
return off;
|
||||
}
|
||||
|
||||
static inline bool cust_read_table_f(FILE* f, CustomizeTable* out) {
|
||||
static inline bool cust_read_table_f(FILE *f, CustomizeTable *out) {
|
||||
long off = cust_get_offset(f);
|
||||
if (off < 0) return false;
|
||||
if (off < 0)
|
||||
return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
|
||||
if (off + (long)sizeof(CustomizeTable) > ftell(f))
|
||||
return false;
|
||||
|
||||
fseek(f, off, SEEK_SET);
|
||||
if (fread(out, 1, sizeof(CustomizeTable), f) != sizeof(CustomizeTable)) return false;
|
||||
if (fread(out, 1, sizeof(CustomizeTable), f) != sizeof(CustomizeTable))
|
||||
return false;
|
||||
|
||||
if (memcmp(out->cust, CUST_MAGIC, CUST_MAGIC_LEN) != 0) {
|
||||
cachedCustOffset = -1;
|
||||
@@ -155,12 +163,14 @@ namespace kip {
|
||||
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);
|
||||
if (off < 0) return false;
|
||||
if (off < 0)
|
||||
return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
|
||||
if (off + (long)sizeof(CustomizeTable) > ftell(f))
|
||||
return false;
|
||||
|
||||
fseek(f, off, SEEK_SET);
|
||||
bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
|
||||
@@ -168,246 +178,456 @@ namespace kip {
|
||||
return ok;
|
||||
}
|
||||
|
||||
static inline bool cust_read_table(const char* path, CustomizeTable* out) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) return false;
|
||||
static inline bool cust_read_table(const char *path, CustomizeTable *out) {
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f)
|
||||
return false;
|
||||
bool ok = cust_read_table_f(f, out);
|
||||
fclose(f);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static inline bool cust_write_table(const char* path, const CustomizeTable* in) {
|
||||
FILE* f = fopen(path, "r+b");
|
||||
if (!f) return false;
|
||||
static inline bool cust_write_table(const char *path, const CustomizeTable *in) {
|
||||
FILE *f = fopen(path, "r+b");
|
||||
if (!f)
|
||||
return false;
|
||||
bool ok = cust_write_table_f(f, in);
|
||||
fclose(f);
|
||||
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);
|
||||
}
|
||||
|
||||
#define CUST_WRITE_FIELD_BATCH(table, field, val) \
|
||||
do { \
|
||||
(table)->field = (val); \
|
||||
} while (0)
|
||||
#define CUST_WRITE_FIELD_BATCH(table, field, val) \
|
||||
do { \
|
||||
(table)->field = (val); \
|
||||
} while (0)
|
||||
|
||||
#define CUST_WRITE_FIELD(path, field, val) \
|
||||
do { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(path, &t)) return false; \
|
||||
t.field = (val); \
|
||||
return cust_write_table(path, &t); \
|
||||
} while (0)
|
||||
#define CUST_WRITE_FIELD(path, field, val) \
|
||||
do { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(path, &t)) \
|
||||
return false; \
|
||||
t.field = (val); \
|
||||
return cust_write_table(path, &t); \
|
||||
} while (0)
|
||||
|
||||
// static inline bool cust_set_cust_rev(const char* p, u32 v) { CUST_WRITE_FIELD(p, custRev, v); }
|
||||
// static inline bool cust_set_mtc_conf(const char* p, u32 v) { CUST_WRITE_FIELD(p, mtcConf, v); }
|
||||
static inline bool cust_set_hp_mode(const char* p, u32 v) { CUST_WRITE_FIELD(p, hpMode, v); }
|
||||
static inline bool cust_set_hp_mode(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, hpMode, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_common_emc_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, commonEmcMemVolt, v); }
|
||||
static inline bool cust_set_erista_emc_max(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaEmcMaxClock, v); }
|
||||
static inline bool cust_set_step_mode(const char* p, u32 v) { CUST_WRITE_FIELD(p, stepMode, v); }
|
||||
static inline bool cust_set_mariko_emc_max(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoEmcMaxClock, v); }
|
||||
static inline bool cust_set_mariko_emc_vddq(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoEmcVddqVolt, v); }
|
||||
static inline bool cust_set_emc_dvb_shift(const char* p, u32 v) { CUST_WRITE_FIELD(p, emcDvbShift, v); }
|
||||
static inline bool cust_set_common_emc_volt(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, commonEmcMemVolt, v);
|
||||
}
|
||||
static inline bool cust_set_erista_emc_max(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaEmcMaxClock, v);
|
||||
}
|
||||
static inline bool cust_set_step_mode(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, stepMode, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_emc_max(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoEmcMaxClock, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_emc_vddq(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoEmcVddqVolt, v);
|
||||
}
|
||||
static inline bool cust_set_emc_dvb_shift(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, emcDvbShift, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_tRCD(const char* p, u32 v) { CUST_WRITE_FIELD(p, t1_tRCD, v); }
|
||||
static inline bool cust_set_tRP(const char* p, u32 v) { CUST_WRITE_FIELD(p, t2_tRP, v); }
|
||||
static inline bool cust_set_tRAS(const char* p, u32 v) { CUST_WRITE_FIELD(p, t3_tRAS, v); }
|
||||
static inline bool cust_set_tRRD(const char* p, u32 v) { CUST_WRITE_FIELD(p, t4_tRRD, v); }
|
||||
static inline bool cust_set_tRFC(const char* p, u32 v) { CUST_WRITE_FIELD(p, t5_tRFC, v); }
|
||||
static inline bool cust_set_tRTW(const char* p, u32 v) { CUST_WRITE_FIELD(p, t6_tRTW, v); }
|
||||
static inline bool cust_set_tWTR(const char* p, u32 v) { CUST_WRITE_FIELD(p, t7_tWTR, v); }
|
||||
static inline bool cust_set_tREFI(const char* p, u32 v) { CUST_WRITE_FIELD(p, t8_tREFI, v); }
|
||||
static inline bool cust_set_tRP_cap(const char* p, u32 v) { CUST_WRITE_FIELD(p, t2_tRP_cap, v); }
|
||||
static inline bool cust_set_timing_emc_tbreak(const char* p, u32 v) { CUST_WRITE_FIELD(p, timingEmcTbreak, v); }
|
||||
static inline bool cust_set_low_tRTW(const char* p, u32 v) { CUST_WRITE_FIELD(p, low_t6_tRTW, v); }
|
||||
static inline bool cust_set_low_tWTR(const char* p, u32 v) { CUST_WRITE_FIELD(p, low_t7_tWTR, v); }
|
||||
static inline bool cust_set_tRTW_fine_tune(const char* p, u32 v) { CUST_WRITE_FIELD(p, t6_tRTW_fine_tune, v); }
|
||||
static inline bool cust_set_tWTR_fine_tune(const char* p, u32 v) { CUST_WRITE_FIELD(p, t7_tWTR_fine_tune, v); }
|
||||
static inline bool cust_set_tRCD(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t1_tRCD, v);
|
||||
}
|
||||
static inline bool cust_set_tRP(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t2_tRP, v);
|
||||
}
|
||||
static inline bool cust_set_tRAS(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t3_tRAS, v);
|
||||
}
|
||||
static inline bool cust_set_tRRD(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t4_tRRD, v);
|
||||
}
|
||||
static inline bool cust_set_tRFC(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t5_tRFC, v);
|
||||
}
|
||||
static inline bool cust_set_tRTW(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t6_tRTW, v);
|
||||
}
|
||||
static inline bool cust_set_tWTR(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t7_tWTR, v);
|
||||
}
|
||||
static inline bool cust_set_tREFI(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t8_tREFI, v);
|
||||
}
|
||||
static inline bool cust_set_tRP_cap(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t2_tRP_cap, v);
|
||||
}
|
||||
static inline bool cust_set_timing_emc_tbreak(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, timingEmcTbreak, v);
|
||||
}
|
||||
static inline bool cust_set_low_tRTW(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, low_t6_tRTW, v);
|
||||
}
|
||||
static inline bool cust_set_low_tWTR(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, low_t7_tWTR, v);
|
||||
}
|
||||
static inline bool cust_set_tRTW_fine_tune(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t6_tRTW_fine_tune, v);
|
||||
}
|
||||
static inline bool cust_set_tWTR_fine_tune(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, t7_tWTR_fine_tune, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_read_latency_1333(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1333, v); }
|
||||
static inline bool cust_set_read_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1600, v); }
|
||||
static inline bool cust_set_read_latency_1866(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency1866, v); }
|
||||
static inline bool cust_set_read_latency_2133(const char* p, u32 v) { CUST_WRITE_FIELD(p, readLatency2133, v); }
|
||||
static inline bool cust_set_read_latency_1333(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, readLatency1333, v);
|
||||
}
|
||||
static inline bool cust_set_read_latency_1600(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, readLatency1600, v);
|
||||
}
|
||||
static inline bool cust_set_read_latency_1866(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, readLatency1866, v);
|
||||
}
|
||||
static inline bool cust_set_read_latency_2133(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, readLatency2133, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_write_latency_1333(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1333, v); }
|
||||
static inline bool cust_set_write_latency_1600(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1600, v); }
|
||||
static inline bool cust_set_write_latency_1866(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency1866, v); }
|
||||
static inline bool cust_set_write_latency_2133(const char* p, u32 v) { CUST_WRITE_FIELD(p, writeLatency2133, v); }
|
||||
static inline bool cust_set_write_latency_1333(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, writeLatency1333, v);
|
||||
}
|
||||
static inline bool cust_set_write_latency_1600(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, writeLatency1600, v);
|
||||
}
|
||||
static inline bool cust_set_write_latency_1866(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, writeLatency1866, v);
|
||||
}
|
||||
static inline bool cust_set_write_latency_2133(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, writeLatency2133, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_erista_cpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuUV, v); }
|
||||
static inline bool cust_set_eristaCpuVmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuVmin, v); }
|
||||
static inline bool cust_set_erista_cpu_max_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuMaxVolt, v); }
|
||||
static inline bool cust_set_eristaCpuUnlock(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuUnlock, v); }
|
||||
static inline bool cust_set_erista_cpu_uv(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaCpuUV, v);
|
||||
}
|
||||
static inline bool cust_set_eristaCpuVmin(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaCpuVmin, v);
|
||||
}
|
||||
static inline bool cust_set_erista_cpu_max_volt(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaCpuMaxVolt, v);
|
||||
}
|
||||
static inline bool cust_set_eristaCpuUnlock(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaCpuUnlock, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_mariko_cpu_uv_low(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuUVLow, v); }
|
||||
static inline bool cust_set_mariko_cpu_uv_high(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuUVHigh, v); }
|
||||
static inline bool cust_set_mariko_cpu_low_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuLowVmin, v); }
|
||||
static inline bool cust_set_mariko_cpu_high_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuHighVmin, v); }
|
||||
static inline bool cust_set_mariko_cpu_max_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxVolt, v); }
|
||||
static inline bool cust_set_erista_cpu_boost(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaCpuBoostClock, v); }
|
||||
static inline bool cust_set_mariko_cpu_boost(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuBoostClock, v); }
|
||||
static inline bool cust_set_mariko_cpu_uv_low(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuUVLow, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_cpu_uv_high(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuUVHigh, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_cpu_low_vmin(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuLowVmin, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_cpu_high_vmin(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuHighVmin, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_cpu_max_volt(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuMaxVolt, v);
|
||||
}
|
||||
static inline bool cust_set_erista_cpu_boost(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaCpuBoostClock, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_cpu_boost(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuBoostClock, v);
|
||||
}
|
||||
|
||||
static inline bool cust_set_erista_gpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaGpuUV, v); }
|
||||
static inline bool cust_set_erista_gpu_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, eristaGpuVmin, v); }
|
||||
static inline bool cust_set_mariko_gpu_uv(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuUV, v); }
|
||||
static inline bool cust_set_mariko_gpu_vmin(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuVmin, v); }
|
||||
static inline bool cust_set_mariko_gpu_boot_volt(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuBootVolt, v); }
|
||||
static inline bool cust_set_mariko_gpu_vmax(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoGpuVmax, v); }
|
||||
static inline bool cust_set_common_gpu_offset(const char* p, u32 v) { CUST_WRITE_FIELD(p, commonGpuVoltOffset, v); }
|
||||
static inline bool cust_set_marikoCpuMaxClock(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoCpuMaxClock, v); }
|
||||
static inline bool cust_set_marikoSocVmax(const char* p, u32 v) { CUST_WRITE_FIELD(p, marikoSocVmax, v); }
|
||||
static inline bool cust_set_erista_gpu_uv(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaGpuUV, v);
|
||||
}
|
||||
static inline bool cust_set_erista_gpu_vmin(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, eristaGpuVmin, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_gpu_uv(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoGpuUV, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_gpu_vmin(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoGpuVmin, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_gpu_boot_volt(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoGpuBootVolt, v);
|
||||
}
|
||||
static inline bool cust_set_mariko_gpu_vmax(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoGpuVmax, v);
|
||||
}
|
||||
static inline bool cust_set_common_gpu_offset(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, commonGpuVoltOffset, v);
|
||||
}
|
||||
static inline bool cust_set_marikoCpuMaxClock(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoCpuMaxClock, v);
|
||||
}
|
||||
static inline bool cust_set_marikoSocVmax(const char *p, u32 v) {
|
||||
CUST_WRITE_FIELD(p, marikoSocVmax, v);
|
||||
}
|
||||
|
||||
/* GPU VOLT ARRAY HELPERS */
|
||||
static inline bool cust_set_erista_gpu_volt(const char* p, int idx, u32 v) {
|
||||
if (idx < 0 || idx >= 27) return false;
|
||||
static inline bool cust_set_erista_gpu_volt(const char *p, int idx, u32 v) {
|
||||
if (idx < 0 || idx >= 27)
|
||||
return false;
|
||||
CustomizeTable t;
|
||||
if (!cust_read_table(p, &t)) return false;
|
||||
if (!cust_read_table(p, &t))
|
||||
return false;
|
||||
t.eristaGpuVoltArray[idx] = v;
|
||||
return cust_write_table(p, &t);
|
||||
}
|
||||
|
||||
static inline bool cust_set_mariko_gpu_volt(const char* p, int idx, u32 v) {
|
||||
if (idx < 0 || idx >= 24) return false;
|
||||
static inline bool cust_set_mariko_gpu_volt(const char *p, int idx, u32 v) {
|
||||
if (idx < 0 || idx >= 24)
|
||||
return false;
|
||||
CustomizeTable t;
|
||||
if (!cust_read_table(p, &t)) return false;
|
||||
if (!cust_read_table(p, &t))
|
||||
return false;
|
||||
t.marikoGpuVoltArray[idx] = v;
|
||||
return cust_write_table(p, &t);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_field(const CustomizeTable* t, u32 offset) {
|
||||
if (!t) return 0;
|
||||
return *(u32*)((u8*)t + offset);
|
||||
static inline u32 cust_get_field(const CustomizeTable *t, u32 offset) {
|
||||
if (!t)
|
||||
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_kip_version(const CustomizeTable* t) { return CUST_GET_FIELD(t, kipVersion); }
|
||||
static inline u32 cust_get_cust_rev(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, custRev);
|
||||
}
|
||||
static inline u32 cust_get_kip_version(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, kipVersion);
|
||||
}
|
||||
// static inline u32 cust_get_mtc_conf(const CustomizeTable* t) { return CUST_GET_FIELD(t, mtcConf); }
|
||||
static inline u32 cust_get_hp_mode(const CustomizeTable* t) { return CUST_GET_FIELD(t, hpMode); }
|
||||
static inline u32 cust_get_hp_mode(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, hpMode);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_common_emc_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, commonEmcMemVolt); }
|
||||
static inline u32 cust_get_erista_emc_max(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaEmcMaxClock); }
|
||||
static inline u32 cust_get_step_mode(const CustomizeTable* t) { return CUST_GET_FIELD(t, stepMode); }
|
||||
static inline u32 cust_get_mariko_emc_max(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoEmcMaxClock); }
|
||||
static inline u32 cust_get_mariko_emc_vddq(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoEmcVddqVolt); }
|
||||
static inline u32 cust_get_emc_dvb_shift(const CustomizeTable* t) { return CUST_GET_FIELD(t, emcDvbShift); }
|
||||
static inline u32 cust_get_common_emc_volt(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, commonEmcMemVolt);
|
||||
}
|
||||
static inline u32 cust_get_erista_emc_max(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaEmcMaxClock);
|
||||
}
|
||||
static inline u32 cust_get_step_mode(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, stepMode);
|
||||
}
|
||||
static inline u32 cust_get_mariko_emc_max(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoEmcMaxClock);
|
||||
}
|
||||
static inline u32 cust_get_mariko_emc_vddq(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoEmcVddqVolt);
|
||||
}
|
||||
static inline u32 cust_get_emc_dvb_shift(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, emcDvbShift);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_tRCD(const CustomizeTable* t) { return CUST_GET_FIELD(t, t1_tRCD); }
|
||||
static inline u32 cust_get_tRP(const CustomizeTable* t) { return CUST_GET_FIELD(t, t2_tRP); }
|
||||
static inline u32 cust_get_tRAS(const CustomizeTable* t) { return CUST_GET_FIELD(t, t3_tRAS); }
|
||||
static inline u32 cust_get_tRRD(const CustomizeTable* t) { return CUST_GET_FIELD(t, t4_tRRD); }
|
||||
static inline u32 cust_get_tRFC(const CustomizeTable* t) { return CUST_GET_FIELD(t, t5_tRFC); }
|
||||
static inline u32 cust_get_tRTW(const CustomizeTable* t) { return CUST_GET_FIELD(t, t6_tRTW); }
|
||||
static inline u32 cust_get_tWTR(const CustomizeTable* t) { return CUST_GET_FIELD(t, t7_tWTR); }
|
||||
static inline u32 cust_get_tREFI(const CustomizeTable* t) { return CUST_GET_FIELD(t, t8_tREFI); }
|
||||
static inline u32 cust_get_tRP_cap(const CustomizeTable* t) { return CUST_GET_FIELD(t, t2_tRP_cap); }
|
||||
static inline u32 cust_get_timing_emc_tbreak(const CustomizeTable* t) { return CUST_GET_FIELD(t, timingEmcTbreak); }
|
||||
static inline u32 cust_get_low_t6_tRTW(const CustomizeTable* t) { return CUST_GET_FIELD(t, low_t6_tRTW); }
|
||||
static inline u32 cust_get_low_t7_tWTR(const CustomizeTable* t) { return CUST_GET_FIELD(t, low_t7_tWTR); }
|
||||
static inline u32 cust_get_tRTW_fine_tune(const CustomizeTable* t) { return CUST_GET_FIELD(t, t6_tRTW_fine_tune); }
|
||||
static inline u32 cust_get_tWTR_fine_tune(const CustomizeTable* t) { return CUST_GET_FIELD(t, t7_tWTR_fine_tune); }
|
||||
static inline u32 cust_get_tRCD(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t1_tRCD);
|
||||
}
|
||||
static inline u32 cust_get_tRP(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t2_tRP);
|
||||
}
|
||||
static inline u32 cust_get_tRAS(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t3_tRAS);
|
||||
}
|
||||
static inline u32 cust_get_tRRD(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t4_tRRD);
|
||||
}
|
||||
static inline u32 cust_get_tRFC(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t5_tRFC);
|
||||
}
|
||||
static inline u32 cust_get_tRTW(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t6_tRTW);
|
||||
}
|
||||
static inline u32 cust_get_tWTR(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t7_tWTR);
|
||||
}
|
||||
static inline u32 cust_get_tREFI(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t8_tREFI);
|
||||
}
|
||||
static inline u32 cust_get_tRP_cap(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t2_tRP_cap);
|
||||
}
|
||||
static inline u32 cust_get_timing_emc_tbreak(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, timingEmcTbreak);
|
||||
}
|
||||
static inline u32 cust_get_low_t6_tRTW(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, low_t6_tRTW);
|
||||
}
|
||||
static inline u32 cust_get_low_t7_tWTR(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, low_t7_tWTR);
|
||||
}
|
||||
static inline u32 cust_get_tRTW_fine_tune(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t6_tRTW_fine_tune);
|
||||
}
|
||||
static inline u32 cust_get_tWTR_fine_tune(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, t7_tWTR_fine_tune);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_read_latency_1333(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1333); }
|
||||
static inline u32 cust_get_read_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1600); }
|
||||
static inline u32 cust_get_read_latency_1866(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency1866); }
|
||||
static inline u32 cust_get_read_latency_2133(const CustomizeTable* t) { return CUST_GET_FIELD(t, readLatency2133); }
|
||||
static inline u32 cust_get_read_latency_1333(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, readLatency1333);
|
||||
}
|
||||
static inline u32 cust_get_read_latency_1600(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, readLatency1600);
|
||||
}
|
||||
static inline u32 cust_get_read_latency_1866(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, readLatency1866);
|
||||
}
|
||||
static inline u32 cust_get_read_latency_2133(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, readLatency2133);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_write_latency_1333(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1333); }
|
||||
static inline u32 cust_get_write_latency_1600(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1600); }
|
||||
static inline u32 cust_get_write_latency_1866(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency1866); }
|
||||
static inline u32 cust_get_write_latency_2133(const CustomizeTable* t) { return CUST_GET_FIELD(t, writeLatency2133); }
|
||||
static inline u32 cust_get_write_latency_1333(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, writeLatency1333);
|
||||
}
|
||||
static inline u32 cust_get_write_latency_1600(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, writeLatency1600);
|
||||
}
|
||||
static inline u32 cust_get_write_latency_1866(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, writeLatency1866);
|
||||
}
|
||||
static inline u32 cust_get_write_latency_2133(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, writeLatency2133);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_erista_cpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuUV); }
|
||||
static inline u32 cust_get_eristaCpuVmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuVmin); }
|
||||
static inline u32 cust_get_erista_cpu_max_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuMaxVolt); }
|
||||
static inline u32 cust_get_eristaCpuUnlock(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuUnlock); }
|
||||
static inline u32 cust_get_erista_cpu_uv(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaCpuUV);
|
||||
}
|
||||
static inline u32 cust_get_eristaCpuVmin(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaCpuVmin);
|
||||
}
|
||||
static inline u32 cust_get_erista_cpu_max_volt(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaCpuMaxVolt);
|
||||
}
|
||||
static inline u32 cust_get_eristaCpuUnlock(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaCpuUnlock);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_mariko_cpu_uv_low(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuUVLow); }
|
||||
static inline u32 cust_get_mariko_cpu_uv_high(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuUVHigh); }
|
||||
static inline u32 cust_get_mariko_cpu_low_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuLowVmin); }
|
||||
static inline u32 cust_get_mariko_cpu_high_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuHighVmin); }
|
||||
static inline u32 cust_get_mariko_cpu_max_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxVolt); }
|
||||
static inline u32 cust_get_erista_cpu_boost(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaCpuBoostClock); }
|
||||
static inline u32 cust_get_mariko_cpu_boost(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuBoostClock); }
|
||||
static inline u32 cust_get_table_conf(const CustomizeTable* t) { return CUST_GET_FIELD(t, tableConf); }
|
||||
static inline u32 cust_get_mariko_cpu_uv_low(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuUVLow);
|
||||
}
|
||||
static inline u32 cust_get_mariko_cpu_uv_high(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuUVHigh);
|
||||
}
|
||||
static inline u32 cust_get_mariko_cpu_low_vmin(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuLowVmin);
|
||||
}
|
||||
static inline u32 cust_get_mariko_cpu_high_vmin(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuHighVmin);
|
||||
}
|
||||
static inline u32 cust_get_mariko_cpu_max_volt(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuMaxVolt);
|
||||
}
|
||||
static inline u32 cust_get_erista_cpu_boost(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaCpuBoostClock);
|
||||
}
|
||||
static inline u32 cust_get_mariko_cpu_boost(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuBoostClock);
|
||||
}
|
||||
static inline u32 cust_get_table_conf(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, tableConf);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_erista_gpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaGpuUV); }
|
||||
static inline u32 cust_get_erista_gpu_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, eristaGpuVmin); }
|
||||
static inline u32 cust_get_mariko_gpu_uv(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuUV); }
|
||||
static inline u32 cust_get_mariko_gpu_vmin(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuVmin); }
|
||||
static inline u32 cust_get_mariko_gpu_boot_volt(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuBootVolt); }
|
||||
static inline u32 cust_get_mariko_gpu_vmax(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoGpuVmax); }
|
||||
static inline u32 cust_get_common_gpu_offset(const CustomizeTable* t) { return CUST_GET_FIELD(t, commonGpuVoltOffset); }
|
||||
static inline u32 cust_get_marikoCpuMaxClock(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoCpuMaxClock); }
|
||||
static inline u32 cust_get_marikoSocVmax(const CustomizeTable* t) { return CUST_GET_FIELD(t, marikoSocVmax); }
|
||||
static inline u32 cust_get_erista_gpu_uv(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaGpuUV);
|
||||
}
|
||||
static inline u32 cust_get_erista_gpu_vmin(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, eristaGpuVmin);
|
||||
}
|
||||
static inline u32 cust_get_mariko_gpu_uv(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoGpuUV);
|
||||
}
|
||||
static inline u32 cust_get_mariko_gpu_vmin(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoGpuVmin);
|
||||
}
|
||||
static inline u32 cust_get_mariko_gpu_boot_volt(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoGpuBootVolt);
|
||||
}
|
||||
static inline u32 cust_get_mariko_gpu_vmax(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoGpuVmax);
|
||||
}
|
||||
static inline u32 cust_get_common_gpu_offset(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, commonGpuVoltOffset);
|
||||
}
|
||||
static inline u32 cust_get_marikoCpuMaxClock(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoCpuMaxClock);
|
||||
}
|
||||
static inline u32 cust_get_marikoSocVmax(const CustomizeTable *t) {
|
||||
return CUST_GET_FIELD(t, marikoSocVmax);
|
||||
}
|
||||
|
||||
static inline u32 cust_get_erista_gpu_volt(const CustomizeTable* t, int idx) {
|
||||
if (!t || idx < 0 || idx >= 27) return 0;
|
||||
static inline u32 cust_get_erista_gpu_volt(const CustomizeTable *t, int idx) {
|
||||
if (!t || idx < 0 || idx >= 27)
|
||||
return 0;
|
||||
return t->eristaGpuVoltArray[idx];
|
||||
}
|
||||
|
||||
static inline u32 cust_get_mariko_gpu_volt(const CustomizeTable* t, int idx) {
|
||||
if (!t || idx < 0 || idx >= 24) return 0;
|
||||
static inline u32 cust_get_mariko_gpu_volt(const CustomizeTable *t, int idx) {
|
||||
if (!t || idx < 0 || idx >= 24)
|
||||
return 0;
|
||||
return t->marikoGpuVoltArray[idx];
|
||||
}
|
||||
|
||||
#define DECL_ERISTA_GPU_VOLT_HELPER(freq, idx) \
|
||||
static inline bool cust_set_erista_gpu_volt_##freq( \
|
||||
const char* p, u32 v) { \
|
||||
return cust_set_erista_gpu_volt(p, idx, v); \
|
||||
#define DECL_ERISTA_GPU_VOLT_HELPER(freq, idx) \
|
||||
static inline bool cust_set_erista_gpu_volt_##freq(const char *p, u32 v) { \
|
||||
return cust_set_erista_gpu_volt(p, idx, v); \
|
||||
}
|
||||
|
||||
#define DECL_MARIKO_GPU_VOLT_HELPER(freq, idx) \
|
||||
static inline bool cust_set_mariko_gpu_volt_##freq( \
|
||||
const char* p, u32 v) { \
|
||||
return cust_set_mariko_gpu_volt(p, idx, v); \
|
||||
#define DECL_MARIKO_GPU_VOLT_HELPER(freq, idx) \
|
||||
static inline bool cust_set_mariko_gpu_volt_##freq(const char *p, u32 v) { \
|
||||
return cust_set_mariko_gpu_volt(p, idx, v); \
|
||||
}
|
||||
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(76800, 0)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(115200, 1)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(153600, 2)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(192000, 3)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(230400, 4)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(268800, 5)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(307200, 6)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(345600, 7)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(384000, 8)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(422400, 9)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(460800, 10)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(499200, 11)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(537600, 12)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(576000, 13)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(614400, 14)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(652800, 15)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(691200, 16)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(729600, 17)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(768000, 18)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(806400, 19)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(844800, 20)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(883200, 21)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(921600, 22)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(960000, 23)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(998400, 24)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(76800, 0)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(115200, 1)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(153600, 2)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(192000, 3)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(230400, 4)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(268800, 5)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(307200, 6)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(345600, 7)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(384000, 8)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(422400, 9)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(460800, 10)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(499200, 11)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(537600, 12)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(576000, 13)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(614400, 14)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(652800, 15)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(691200, 16)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(729600, 17)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(768000, 18)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(806400, 19)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(844800, 20)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(883200, 21)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(921600, 22)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(960000, 23)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(998400, 24)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(1036800, 25)
|
||||
DECL_ERISTA_GPU_VOLT_HELPER(1075200, 26)
|
||||
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(76800, 0)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(153600, 1)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(230400, 2)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(307200, 3)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(384000, 4)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(460800, 5)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(537600, 6)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(614400, 7)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(691200, 8)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(768000, 9)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(844800, 10)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(921600, 11)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(998400, 12)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(76800, 0)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(153600, 1)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(230400, 2)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(307200, 3)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(384000, 4)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(460800, 5)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(537600, 6)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(614400, 7)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(691200, 8)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(768000, 9)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(844800, 10)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(921600, 11)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(998400, 12)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(1075200, 13)
|
||||
DECL_MARIKO_GPU_VOLT_HELPER(1152000, 14)
|
||||
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(1536000, 23)
|
||||
|
||||
#define DECL_ERISTA_GPU_VOLT_GET(freq, idx) \
|
||||
static inline u32 cust_get_erista_gpu_volt_##freq##_val(const char* p) { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(p, &t)) return 0; \
|
||||
return cust_get_erista_gpu_volt(&t, idx); \
|
||||
#define DECL_ERISTA_GPU_VOLT_GET(freq, idx) \
|
||||
static inline u32 cust_get_erista_gpu_volt_##freq##_val(const char *p) { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(p, &t)) \
|
||||
return 0; \
|
||||
return cust_get_erista_gpu_volt(&t, idx); \
|
||||
}
|
||||
#define DECL_MARIKO_GPU_VOLT_GET(freq, idx) \
|
||||
static inline u32 cust_get_mariko_gpu_volt_##freq##_val(const char* p) { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(p, &t)) return 0; \
|
||||
return cust_get_mariko_gpu_volt(&t, idx); \
|
||||
#define DECL_MARIKO_GPU_VOLT_GET(freq, idx) \
|
||||
static inline u32 cust_get_mariko_gpu_volt_##freq##_val(const char *p) { \
|
||||
CustomizeTable t; \
|
||||
if (!cust_read_table(p, &t)) \
|
||||
return 0; \
|
||||
return cust_get_mariko_gpu_volt(&t, idx); \
|
||||
}
|
||||
|
||||
DECL_ERISTA_GPU_VOLT_GET(76800, 0)
|
||||
DECL_ERISTA_GPU_VOLT_GET(115200, 1)
|
||||
DECL_ERISTA_GPU_VOLT_GET(153600, 2)
|
||||
DECL_ERISTA_GPU_VOLT_GET(192000, 3)
|
||||
DECL_ERISTA_GPU_VOLT_GET(230400, 4)
|
||||
DECL_ERISTA_GPU_VOLT_GET(268800, 5)
|
||||
DECL_ERISTA_GPU_VOLT_GET(307200, 6)
|
||||
DECL_ERISTA_GPU_VOLT_GET(345600, 7)
|
||||
DECL_ERISTA_GPU_VOLT_GET(384000, 8)
|
||||
DECL_ERISTA_GPU_VOLT_GET(422400, 9)
|
||||
DECL_ERISTA_GPU_VOLT_GET(460800, 10)
|
||||
DECL_ERISTA_GPU_VOLT_GET(499200, 11)
|
||||
DECL_ERISTA_GPU_VOLT_GET(537600, 12)
|
||||
DECL_ERISTA_GPU_VOLT_GET(576000, 13)
|
||||
DECL_ERISTA_GPU_VOLT_GET(614400, 14)
|
||||
DECL_ERISTA_GPU_VOLT_GET(652800, 15)
|
||||
DECL_ERISTA_GPU_VOLT_GET(691200, 16)
|
||||
DECL_ERISTA_GPU_VOLT_GET(729600, 17)
|
||||
DECL_ERISTA_GPU_VOLT_GET(768000, 18)
|
||||
DECL_ERISTA_GPU_VOLT_GET(806400, 19)
|
||||
DECL_ERISTA_GPU_VOLT_GET(844800, 20)
|
||||
DECL_ERISTA_GPU_VOLT_GET(883200, 21)
|
||||
DECL_ERISTA_GPU_VOLT_GET(921600, 22)
|
||||
DECL_ERISTA_GPU_VOLT_GET(960000, 23)
|
||||
DECL_ERISTA_GPU_VOLT_GET(998400, 24)
|
||||
DECL_ERISTA_GPU_VOLT_GET(76800, 0)
|
||||
DECL_ERISTA_GPU_VOLT_GET(115200, 1)
|
||||
DECL_ERISTA_GPU_VOLT_GET(153600, 2)
|
||||
DECL_ERISTA_GPU_VOLT_GET(192000, 3)
|
||||
DECL_ERISTA_GPU_VOLT_GET(230400, 4)
|
||||
DECL_ERISTA_GPU_VOLT_GET(268800, 5)
|
||||
DECL_ERISTA_GPU_VOLT_GET(307200, 6)
|
||||
DECL_ERISTA_GPU_VOLT_GET(345600, 7)
|
||||
DECL_ERISTA_GPU_VOLT_GET(384000, 8)
|
||||
DECL_ERISTA_GPU_VOLT_GET(422400, 9)
|
||||
DECL_ERISTA_GPU_VOLT_GET(460800, 10)
|
||||
DECL_ERISTA_GPU_VOLT_GET(499200, 11)
|
||||
DECL_ERISTA_GPU_VOLT_GET(537600, 12)
|
||||
DECL_ERISTA_GPU_VOLT_GET(576000, 13)
|
||||
DECL_ERISTA_GPU_VOLT_GET(614400, 14)
|
||||
DECL_ERISTA_GPU_VOLT_GET(652800, 15)
|
||||
DECL_ERISTA_GPU_VOLT_GET(691200, 16)
|
||||
DECL_ERISTA_GPU_VOLT_GET(729600, 17)
|
||||
DECL_ERISTA_GPU_VOLT_GET(768000, 18)
|
||||
DECL_ERISTA_GPU_VOLT_GET(806400, 19)
|
||||
DECL_ERISTA_GPU_VOLT_GET(844800, 20)
|
||||
DECL_ERISTA_GPU_VOLT_GET(883200, 21)
|
||||
DECL_ERISTA_GPU_VOLT_GET(921600, 22)
|
||||
DECL_ERISTA_GPU_VOLT_GET(960000, 23)
|
||||
DECL_ERISTA_GPU_VOLT_GET(998400, 24)
|
||||
DECL_ERISTA_GPU_VOLT_GET(1036800, 25)
|
||||
DECL_ERISTA_GPU_VOLT_GET(1075200, 26)
|
||||
|
||||
DECL_MARIKO_GPU_VOLT_GET(76800, 0)
|
||||
DECL_MARIKO_GPU_VOLT_GET(153600, 1)
|
||||
DECL_MARIKO_GPU_VOLT_GET(230400, 2)
|
||||
DECL_MARIKO_GPU_VOLT_GET(307200, 3)
|
||||
DECL_MARIKO_GPU_VOLT_GET(384000, 4)
|
||||
DECL_MARIKO_GPU_VOLT_GET(460800, 5)
|
||||
DECL_MARIKO_GPU_VOLT_GET(537600, 6)
|
||||
DECL_MARIKO_GPU_VOLT_GET(614400, 7)
|
||||
DECL_MARIKO_GPU_VOLT_GET(691200, 8)
|
||||
DECL_MARIKO_GPU_VOLT_GET(768000, 9)
|
||||
DECL_MARIKO_GPU_VOLT_GET(844800, 10)
|
||||
DECL_MARIKO_GPU_VOLT_GET(921600, 11)
|
||||
DECL_MARIKO_GPU_VOLT_GET(998400, 12)
|
||||
DECL_MARIKO_GPU_VOLT_GET(76800, 0)
|
||||
DECL_MARIKO_GPU_VOLT_GET(153600, 1)
|
||||
DECL_MARIKO_GPU_VOLT_GET(230400, 2)
|
||||
DECL_MARIKO_GPU_VOLT_GET(307200, 3)
|
||||
DECL_MARIKO_GPU_VOLT_GET(384000, 4)
|
||||
DECL_MARIKO_GPU_VOLT_GET(460800, 5)
|
||||
DECL_MARIKO_GPU_VOLT_GET(537600, 6)
|
||||
DECL_MARIKO_GPU_VOLT_GET(614400, 7)
|
||||
DECL_MARIKO_GPU_VOLT_GET(691200, 8)
|
||||
DECL_MARIKO_GPU_VOLT_GET(768000, 9)
|
||||
DECL_MARIKO_GPU_VOLT_GET(844800, 10)
|
||||
DECL_MARIKO_GPU_VOLT_GET(921600, 11)
|
||||
DECL_MARIKO_GPU_VOLT_GET(998400, 12)
|
||||
DECL_MARIKO_GPU_VOLT_GET(1075200, 13)
|
||||
DECL_MARIKO_GPU_VOLT_GET(1152000, 14)
|
||||
DECL_MARIKO_GPU_VOLT_GET(1228800, 15)
|
||||
@@ -488,4 +710,4 @@ namespace kip {
|
||||
void MigrateKipData(u32 custRev, u32 version);
|
||||
void SetKipData();
|
||||
void GetKipData();
|
||||
}
|
||||
} // namespace kip
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,60 +24,50 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include "apm_ext.h"
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
static Service g_apmSrv;
|
||||
static Service g_apmSysSrv;
|
||||
static atomic_size_t g_refCnt;
|
||||
|
||||
Result apmExtInitialize(void)
|
||||
{
|
||||
Result apmExtInitialize(void) {
|
||||
g_refCnt++;
|
||||
|
||||
if (serviceIsActive(&g_apmSrv))
|
||||
{
|
||||
if (serviceIsActive(&g_apmSrv)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result rc = 0;
|
||||
|
||||
rc = smGetService(&g_apmSrv, "apm");
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = smGetService(&g_apmSysSrv, "apm:sys");
|
||||
}
|
||||
|
||||
if (R_FAILED(rc))
|
||||
{
|
||||
if (R_FAILED(rc)) {
|
||||
apmExtExit();
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void apmExtExit(void)
|
||||
{
|
||||
if (--g_refCnt == 0)
|
||||
{
|
||||
void apmExtExit(void) {
|
||||
if (--g_refCnt == 0) {
|
||||
serviceClose(&g_apmSrv);
|
||||
serviceClose(&g_apmSysSrv);
|
||||
}
|
||||
}
|
||||
|
||||
Result apmExtGetPerformanceMode(u32* out_mode)
|
||||
{
|
||||
Result apmExtGetPerformanceMode(u32 *out_mode) {
|
||||
return serviceDispatchOut(&g_apmSrv, 1, *out_mode);
|
||||
}
|
||||
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode)
|
||||
{
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode) {
|
||||
return serviceDispatchIn(&g_apmSysSrv, 0, mode);
|
||||
}
|
||||
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf)
|
||||
{
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf) {
|
||||
return serviceDispatchOut(&g_apmSysSrv, 7, *out_conf);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,12 +24,10 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch.h>
|
||||
@@ -37,19 +35,19 @@ extern "C"
|
||||
Result apmExtInitialize(void);
|
||||
void apmExtExit(void);
|
||||
|
||||
Result apmExtGetPerformanceMode(u32* out_mode);
|
||||
Result apmExtGetPerformanceMode(u32 *out_mode);
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode);
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf);
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode);
|
||||
Result apmExtSysSetCpuBoostMode(u32 mode);
|
||||
|
||||
Result apmExtGetPerformanceMode(u32 *out_mode);
|
||||
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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,26 +24,24 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <hocclk/apm.h>
|
||||
|
||||
HocClkApmConfiguration hocclk_g_apm_configurations[] = {
|
||||
{0x00010000, 1020000000, 384000000, 1600000000},
|
||||
{0x00010001, 1020000000, 768000000, 1600000000},
|
||||
{0x00010002, 1224000000, 691200000, 1600000000},
|
||||
{0x00020000, 1020000000, 230400000, 1600000000},
|
||||
{0x00020001, 1020000000, 307200000, 1600000000},
|
||||
{0x00020002, 1224000000, 230400000, 1600000000},
|
||||
{0x00020003, 1020000000, 307200000, 1331200000},
|
||||
{0x00020004, 1020000000, 384000000, 1331200000},
|
||||
{0x00020005, 1020000000, 307200000, 1065600000},
|
||||
{0x00020006, 1020000000, 384000000, 1065600000},
|
||||
{0x92220007, 1020000000, 460800000, 1600000000},
|
||||
{0x92220008, 1020000000, 460800000, 1331200000},
|
||||
{0x92220009, 1785000000, 76800000, 1600000000},
|
||||
{0x9222000A, 1785000000, 76800000, 1331200000},
|
||||
{0x9222000B, 1020000000, 76800000, 1600000000},
|
||||
{0x9222000C, 1020000000, 76800000, 1331200000},
|
||||
{0, 0, 0, 0},
|
||||
{ 0x00010000, 1020000000, 384000000, 1600000000 },
|
||||
{ 0x00010001, 1020000000, 768000000, 1600000000 },
|
||||
{ 0x00010002, 1224000000, 691200000, 1600000000 },
|
||||
{ 0x00020000, 1020000000, 230400000, 1600000000 },
|
||||
{ 0x00020001, 1020000000, 307200000, 1600000000 },
|
||||
{ 0x00020002, 1224000000, 230400000, 1600000000 },
|
||||
{ 0x00020003, 1020000000, 307200000, 1331200000 },
|
||||
{ 0x00020004, 1020000000, 384000000, 1331200000 },
|
||||
{ 0x00020005, 1020000000, 307200000, 1065600000 },
|
||||
{ 0x00020006, 1020000000, 384000000, 1065600000 },
|
||||
{ 0x92220007, 1020000000, 460800000, 1600000000 },
|
||||
{ 0x92220008, 1020000000, 460800000, 1331200000 },
|
||||
{ 0x92220009, 1785000000, 76800000, 1600000000 },
|
||||
{ 0x9222000A, 1785000000, 76800000, 1331200000 },
|
||||
{ 0x9222000B, 1020000000, 76800000, 1600000000 },
|
||||
{ 0x9222000C, 1020000000, 76800000, 1331200000 },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
|
||||
@@ -15,16 +15,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "integrations.hpp"
|
||||
#include <sys/stat.h>
|
||||
#include <SaltyNX.h>
|
||||
|
||||
#include "integrations.hpp"
|
||||
#include "process_management.hpp"
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace integrations {
|
||||
|
||||
namespace {
|
||||
|
||||
NxFpsSharedBlock* gNxFps = nullptr;
|
||||
NxFpsSharedBlock *gNxFps = nullptr;
|
||||
SharedMemory gSharedMemory = {};
|
||||
bool gSharedMemoryUsed = false;
|
||||
Handle gRemoteSharedMemory = 1;
|
||||
@@ -38,7 +39,8 @@ namespace integrations {
|
||||
svcCloseHandle(saltysd);
|
||||
break;
|
||||
}
|
||||
if (i == 66) return false;
|
||||
if (i == 66)
|
||||
return false;
|
||||
svcSleepThread(1'000'000);
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ namespace integrations {
|
||||
void SearchSharedMemoryBlock(uintptr_t base) {
|
||||
ptrdiff_t search_offset = 0;
|
||||
while (search_offset < 0x1000) {
|
||||
gNxFps = (NxFpsSharedBlock*)(base + search_offset);
|
||||
gNxFps = (NxFpsSharedBlock *)(base + search_offset);
|
||||
if (gNxFps->MAGIC == 0x465053)
|
||||
return;
|
||||
search_offset += 4;
|
||||
@@ -74,21 +76,21 @@ namespace integrations {
|
||||
gSharedMemoryUsed = true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool GetSysDockState() {
|
||||
struct stat st = {0};
|
||||
struct stat st = { 0 };
|
||||
return stat("sdmc:/atmosphere/contents/42000000000000A0/flags/boot2.flag", &st) == 0;
|
||||
}
|
||||
|
||||
bool GetSaltyNXState() {
|
||||
struct stat st = {0};
|
||||
struct stat st = { 0 };
|
||||
return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0;
|
||||
}
|
||||
|
||||
bool GetRETROSuperStatus() {
|
||||
struct stat st = {0};
|
||||
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this
|
||||
struct stat st = { 0 };
|
||||
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this
|
||||
}
|
||||
|
||||
void LoadSaltyNX() {
|
||||
@@ -143,13 +145,15 @@ namespace integrations {
|
||||
resolutionLookup = 1;
|
||||
return 0;
|
||||
} else if (resolutionLookup == 1) {
|
||||
if (gNxFps->renderCalls[0].calls != 0xFFFF) resolutionLookup = 2;
|
||||
else return 0;
|
||||
if (gNxFps->renderCalls[0].calls != 0xFFFF)
|
||||
resolutionLookup = 2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return gNxFps->renderCalls[0].height == 0 ? gNxFps->viewportCalls[0].height : gNxFps->renderCalls[0].height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace integrations
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
namespace integrations {
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace integrations {
|
||||
uint8_t SetActiveBuffers;
|
||||
union {
|
||||
struct {
|
||||
bool handheld: 1;
|
||||
bool docked: 1;
|
||||
unsigned int reserved: 6;
|
||||
bool handheld : 1;
|
||||
bool docked : 1;
|
||||
unsigned int reserved : 6;
|
||||
} NX_PACKED ds;
|
||||
uint8_t general;
|
||||
} displaySync;
|
||||
@@ -66,4 +66,4 @@ namespace integrations {
|
||||
u8 GetSaltyNXFPS();
|
||||
u16 GetSaltyNXResolutionHeight();
|
||||
|
||||
}
|
||||
} // namespace integrations
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
namespace notification {
|
||||
void writeNotification(const std::string& message) {
|
||||
static const char* flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
|
||||
void writeNotification(const std::string &message) {
|
||||
static const char *flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
|
||||
|
||||
FILE* flagFile = fopen(flagPath, "r");
|
||||
FILE *flagFile = fopen(flagPath, "r");
|
||||
if (!flagFile) {
|
||||
return;
|
||||
}
|
||||
@@ -31,7 +30,7 @@ namespace notification {
|
||||
std::string filename = "hoc-" + std::to_string(std::time(nullptr)) + ".notify";
|
||||
std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename;
|
||||
|
||||
FILE* file = fopen(fullPath.c_str(), "w");
|
||||
FILE *file = fopen(fullPath.c_str(), "w");
|
||||
if (file) {
|
||||
fprintf(file, "{\n");
|
||||
fprintf(file, " \"text\": \"%s\",\n", message.c_str());
|
||||
@@ -40,4 +39,4 @@ namespace notification {
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace notification
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
namespace notification {
|
||||
void writeNotification(const std::string& message);
|
||||
void writeNotification(const std::string &message);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -26,24 +26,23 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Switch Power domains (max77620):
|
||||
* Name | Usage | uV step | uV min | uV default | uV max | Init
|
||||
*-------+---------------+---------+--------+------------+---------+------------------
|
||||
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (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)
|
||||
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
|
||||
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
|
||||
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
|
||||
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
|
||||
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
|
||||
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
|
||||
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
|
||||
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
|
||||
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
|
||||
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv)
|
||||
*/
|
||||
|
||||
* Switch Power domains (max77620):
|
||||
* Name | Usage | uV step | uV min | uV default | uV max | Init
|
||||
*-------+---------------+---------+--------+------------+---------+------------------
|
||||
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (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)
|
||||
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
|
||||
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
|
||||
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
|
||||
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
|
||||
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
|
||||
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
|
||||
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
|
||||
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
|
||||
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (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.
|
||||
|
||||
@@ -66,15 +65,15 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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_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
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
PcvPowerDomain_Max77620_Sd0 = 0,
|
||||
PcvPowerDomain_Max77620_Sd1 = 1,
|
||||
PcvPowerDomain_Max77620_Sd2 = 2,
|
||||
PcvPowerDomain_Max77620_Sd3 = 3,
|
||||
PcvPowerDomain_Max77620_Sd0 = 0,
|
||||
PcvPowerDomain_Max77620_Sd1 = 1,
|
||||
PcvPowerDomain_Max77620_Sd2 = 2,
|
||||
PcvPowerDomain_Max77620_Sd3 = 3,
|
||||
PcvPowerDomain_Max77620_Ldo0 = 4,
|
||||
PcvPowerDomain_Max77620_Ldo1 = 5,
|
||||
PcvPowerDomain_Max77620_Ldo2 = 6,
|
||||
@@ -84,18 +83,18 @@ typedef enum {
|
||||
PcvPowerDomain_Max77620_Ldo6 = 10,
|
||||
PcvPowerDomain_Max77620_Ldo7 = 11,
|
||||
PcvPowerDomain_Max77620_Ldo8 = 12,
|
||||
PcvPowerDomain_Max77621_Cpu = 13,
|
||||
PcvPowerDomain_Max77621_Gpu = 14,
|
||||
PcvPowerDomain_Max77812_Cpu = 15,
|
||||
PcvPowerDomain_Max77812_Gpu = 16,
|
||||
PcvPowerDomain_Max77621_Cpu = 13,
|
||||
PcvPowerDomain_Max77621_Gpu = 14,
|
||||
PcvPowerDomain_Max77812_Cpu = 15,
|
||||
PcvPowerDomain_Max77812_Gpu = 16,
|
||||
PcvPowerDomain_Max77812_Dram = 17,
|
||||
} PowerDomain;
|
||||
|
||||
typedef enum {
|
||||
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
|
||||
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
|
||||
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
|
||||
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
|
||||
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
|
||||
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
|
||||
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
|
||||
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
|
||||
PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0,
|
||||
PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1,
|
||||
PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2,
|
||||
@@ -105,9 +104,9 @@ typedef enum {
|
||||
PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6,
|
||||
PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7,
|
||||
PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8,
|
||||
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
|
||||
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
|
||||
} PowerDomainId;
|
||||
@@ -24,19 +24,20 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "process_management.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include <cstring>
|
||||
|
||||
#include "../file/errors.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "process_management.hpp"
|
||||
|
||||
|
||||
namespace processManagement {
|
||||
|
||||
namespace {
|
||||
constexpr u64 Qlaunch = 0x0100000000001000ULL;
|
||||
constexpr u64 Qlaunch = 0x0100000000001000ULL;
|
||||
constexpr u32 IsQlaunch = 0x20f;
|
||||
Service pdmqryClone;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Initialize() {
|
||||
Result rc = 0;
|
||||
@@ -50,11 +51,10 @@ namespace processManagement {
|
||||
rc = pdmqryInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pdmqryInitialize");
|
||||
|
||||
Service* pdmqrySrv = pdmqryGetServiceSession();
|
||||
Service *pdmqrySrv = pdmqryGetServiceSession();
|
||||
serviceClone(pdmqrySrv, &pdmqryClone);
|
||||
serviceClose(pdmqrySrv);
|
||||
memcpy(pdmqrySrv, &pdmqryClone, sizeof(Service));
|
||||
|
||||
}
|
||||
|
||||
void WaitForQLaunch() {
|
||||
@@ -62,12 +62,12 @@ namespace processManagement {
|
||||
u64 pid = 0;
|
||||
do {
|
||||
rc = pmdmntGetProcessId(&pid, Qlaunch);
|
||||
svcSleepThread(50 * 1000000ULL); // 50ms
|
||||
svcSleepThread(50 * 1000000ULL); // 50ms
|
||||
} while (R_FAILED(rc));
|
||||
}
|
||||
|
||||
// Ty to Masa for this function!
|
||||
Result isApplicationOutOfFocus(bool* outOfFocus) {
|
||||
Result isApplicationOutOfFocus(bool *outOfFocus) {
|
||||
static s32 last_total_entries = 0;
|
||||
static bool isOutOfFocus = false;
|
||||
s32 total_entries = 0;
|
||||
@@ -77,12 +77,15 @@ namespace processManagement {
|
||||
u64 PIDnow;
|
||||
|
||||
Result rc = pmdmntGetApplicationProcessId(&PIDnow);
|
||||
if(R_FAILED(rc)) return rc;
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
rc = pmdmntGetProgramId(&TIDnow, PIDnow);
|
||||
if(R_FAILED(rc)) return rc;
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
rc = pdmqryGetAvailablePlayEventRange(&total_entries, &start_entry_index, &end_entry_index);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
if (total_entries == last_total_entries) {
|
||||
*outOfFocus = isOutOfFocus;
|
||||
return 0;
|
||||
@@ -92,13 +95,16 @@ namespace processManagement {
|
||||
PdmPlayEvent events[16];
|
||||
s32 out = 0;
|
||||
s32 start_entry = end_entry_index - 15;
|
||||
if (start_entry < 0) start_entry = 0;
|
||||
if (start_entry < 0)
|
||||
start_entry = 0;
|
||||
rc = pdmqryQueryPlayEvent(start_entry, events, sizeof(events) / sizeof(events[0]), &out);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
if (out == 0) return 1;
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
if (out == 0)
|
||||
return 1;
|
||||
|
||||
int itr = -1;
|
||||
for (int i = out-1; i >= 0; i--) {
|
||||
for (int i = out - 1; i >= 0; i--) {
|
||||
if (events[i].play_event_type != PdmPlayEventType_Applet)
|
||||
continue;
|
||||
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[1] = events[i].event_data.applet.program_id[0];
|
||||
|
||||
|
||||
|
||||
if (TID.full != (TIDnow & ~0xFFF))
|
||||
continue;
|
||||
else {
|
||||
@@ -121,9 +125,11 @@ namespace processManagement {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (itr == -1) return 1;
|
||||
if (itr == -1)
|
||||
return 1;
|
||||
|
||||
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus || events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
|
||||
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus ||
|
||||
events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
|
||||
*outOfFocus = isOut;
|
||||
isOutOfFocus = isOut;
|
||||
return 0;
|
||||
@@ -158,4 +164,4 @@ namespace processManagement {
|
||||
pdmqryExit();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace processManagement
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
@@ -33,7 +32,7 @@ namespace processManagement {
|
||||
void Initialize();
|
||||
void WaitForQLaunch();
|
||||
u64 GetCurrentApplicationId();
|
||||
Result isApplicationOutOfFocus(bool* outOfFocus);
|
||||
Result isApplicationOutOfFocus(bool *outOfFocus);
|
||||
void Exit();
|
||||
|
||||
}
|
||||
} // namespace processManagement
|
||||
|
||||
@@ -12,44 +12,55 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "psm_ext.h"
|
||||
|
||||
const char* PsmPowerRoleToStr(PsmPowerRole role) {
|
||||
const char *PsmPowerRoleToStr(PsmPowerRole role) {
|
||||
switch (role) {
|
||||
case PsmPowerRole_Sink: return "Sink";
|
||||
case PsmPowerRole_Source: return "Source";
|
||||
default: return "Unknown";
|
||||
case PsmPowerRole_Sink:
|
||||
return "Sink";
|
||||
case PsmPowerRole_Source:
|
||||
return "Source";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
|
||||
const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
|
||||
switch (type) {
|
||||
case PsmInfoChargerType_None: return "None";
|
||||
case PsmInfoChargerType_PD: return "USB-C PD";
|
||||
case PsmInfoChargerType_None:
|
||||
return "None";
|
||||
case PsmInfoChargerType_PD:
|
||||
return "USB-C PD";
|
||||
case PsmInfoChargerType_TypeC_1500mA:
|
||||
case PsmInfoChargerType_TypeC_3000mA: return "USB-C";
|
||||
case PsmInfoChargerType_DCP: return "USB DCP";
|
||||
case PsmInfoChargerType_CDP: return "USB CDP";
|
||||
case PsmInfoChargerType_SDP: return "USB SDP";
|
||||
case PsmInfoChargerType_TypeC_3000mA:
|
||||
return "USB-C";
|
||||
case PsmInfoChargerType_DCP:
|
||||
return "USB DCP";
|
||||
case PsmInfoChargerType_CDP:
|
||||
return "USB CDP";
|
||||
case PsmInfoChargerType_SDP:
|
||||
return "USB SDP";
|
||||
case PsmInfoChargerType_Apple_500mA:
|
||||
case PsmInfoChargerType_Apple_1000mA:
|
||||
case PsmInfoChargerType_Apple_2000mA: return "Apple";
|
||||
default: return "Unknown";
|
||||
case PsmInfoChargerType_Apple_2000mA:
|
||||
return "Apple";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo* info) {
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo *info) {
|
||||
return info->ChargerType != PsmInfoChargerType_None;
|
||||
}
|
||||
|
||||
bool PsmIsCharging(const PsmChargeInfo* info) {
|
||||
bool PsmIsCharging(const PsmChargeInfo *info) {
|
||||
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
|
||||
}
|
||||
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info) {
|
||||
if (!PsmIsChargerConnected(info))
|
||||
return PsmBatteryState_Discharging;
|
||||
if (!PsmIsCharging(info))
|
||||
@@ -57,11 +68,15 @@ PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
|
||||
return PsmBatteryState_FastCharging;
|
||||
}
|
||||
|
||||
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) {
|
||||
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info) {
|
||||
switch (PsmGetBatteryState(info)) {
|
||||
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
|
||||
case PsmBatteryState_ChargingPaused:return "| |";
|
||||
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶
|
||||
default: return "?";
|
||||
case PsmBatteryState_Discharging:
|
||||
return "\u25c0"; // ◀
|
||||
case PsmBatteryState_ChargingPaused:
|
||||
return "| |";
|
||||
case PsmBatteryState_FastCharging:
|
||||
return "\u25b6"; // ▶
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -20,75 +20,68 @@
|
||||
#include <switch.h>
|
||||
|
||||
typedef enum {
|
||||
PsmPDC_NewPDO = 1, //Received new Power Data Object
|
||||
PsmPDC_NoPD = 2, //No Power Delivery source is detected
|
||||
PsmPDC_AcceptedRDO = 3 //Received and accepted Request Data Object
|
||||
} PsmChargeInfoPDC; //BM92T series
|
||||
PsmPDC_NewPDO = 1, // Received new Power Data Object
|
||||
PsmPDC_NoPD = 2, // No Power Delivery source is detected
|
||||
PsmPDC_AcceptedRDO = 3 // Received and accepted Request Data Object
|
||||
} PsmChargeInfoPDC; // BM92T series
|
||||
|
||||
typedef enum { PsmPowerRole_Sink = 1, PsmPowerRole_Source = 2 } PsmPowerRole;
|
||||
|
||||
const char *PsmPowerRoleToStr(PsmPowerRole role);
|
||||
|
||||
typedef enum {
|
||||
PsmPowerRole_Sink = 1,
|
||||
PsmPowerRole_Source = 2
|
||||
} PsmPowerRole;
|
||||
|
||||
const char* PsmPowerRoleToStr(PsmPowerRole role);
|
||||
|
||||
typedef enum {
|
||||
PsmInfoChargerType_None = 0,
|
||||
PsmInfoChargerType_PD = 1,
|
||||
PsmInfoChargerType_None = 0,
|
||||
PsmInfoChargerType_PD = 1,
|
||||
PsmInfoChargerType_TypeC_1500mA = 2,
|
||||
PsmInfoChargerType_TypeC_3000mA = 3,
|
||||
PsmInfoChargerType_DCP = 4,
|
||||
PsmInfoChargerType_CDP = 5,
|
||||
PsmInfoChargerType_SDP = 6,
|
||||
PsmInfoChargerType_Apple_500mA = 7,
|
||||
PsmInfoChargerType_DCP = 4,
|
||||
PsmInfoChargerType_CDP = 5,
|
||||
PsmInfoChargerType_SDP = 6,
|
||||
PsmInfoChargerType_Apple_500mA = 7,
|
||||
PsmInfoChargerType_Apple_1000mA = 8,
|
||||
PsmInfoChargerType_Apple_2000mA = 9
|
||||
} PsmInfoChargerType;
|
||||
|
||||
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type);
|
||||
const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type);
|
||||
|
||||
typedef enum {
|
||||
PsmFlags_NoHub = BIT(0), //If hub is disconnected
|
||||
PsmFlags_Rail = BIT(8), //At least one Joy-con is charging from rail
|
||||
PsmFlags_SPDSRC = BIT(12), //OTG
|
||||
PsmFlags_ACC = BIT(16) //Accessory
|
||||
PsmFlags_NoHub = BIT(0), // If hub is disconnected
|
||||
PsmFlags_Rail = BIT(8), // At least one Joy-con is charging from rail
|
||||
PsmFlags_SPDSRC = BIT(12), // OTG
|
||||
PsmFlags_ACC = BIT(16) // Accessory
|
||||
} PsmChargeInfoFlags;
|
||||
|
||||
typedef struct {
|
||||
int32_t InputCurrentLimit; //Input (Sink) 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 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_x14; //Possibly flags
|
||||
PsmChargeInfoPDC PDCState; //Power Delivery Controller State
|
||||
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 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 InputCurrentLimit; // Input (Sink) 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 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_x14; // Possibly flags
|
||||
PsmChargeInfoPDC PDCState; // Power Delivery Controller State
|
||||
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 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)
|
||||
PsmPowerRole PowerRole;
|
||||
PsmInfoChargerType ChargerType;
|
||||
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA
|
||||
PsmChargeInfoFlags Flags; //Unknown flags
|
||||
int32_t ChargerVoltageLimit; // Charger and external device voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; // Charger and external device current limit in mA
|
||||
PsmChargeInfoFlags Flags; // Unknown flags
|
||||
} PsmChargeInfo;
|
||||
|
||||
typedef enum {
|
||||
Psm_EnableBatteryCharging = 2,
|
||||
Psm_DisableBatteryCharging = 3,
|
||||
Psm_EnableFastBatteryCharging = 10,
|
||||
Psm_DisableFastBatteryCharging = 11,
|
||||
Psm_GetBatteryChargeInfoFields = 17,
|
||||
Psm_EnableBatteryCharging = 2,
|
||||
Psm_DisableBatteryCharging = 3,
|
||||
Psm_EnableFastBatteryCharging = 10,
|
||||
Psm_DisableFastBatteryCharging = 11,
|
||||
Psm_GetBatteryChargeInfoFields = 17,
|
||||
} IPsmServerCmd;
|
||||
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo* info);
|
||||
bool PsmIsCharging(const PsmChargeInfo* info);
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo *info);
|
||||
bool PsmIsCharging(const PsmChargeInfo *info);
|
||||
|
||||
typedef enum {
|
||||
PsmBatteryState_Discharging,
|
||||
PsmBatteryState_ChargingPaused,
|
||||
PsmBatteryState_FastCharging
|
||||
} PsmBatteryState;
|
||||
typedef enum { PsmBatteryState_Discharging, PsmBatteryState_ChargingPaused, PsmBatteryState_FastCharging } PsmBatteryState;
|
||||
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info);
|
||||
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info);
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info);
|
||||
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info);
|
||||
@@ -12,11 +12,12 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||
#include <switch.h>
|
||||
|
||||
#include "../util/service_guard.h"
|
||||
#include "pwm.h"
|
||||
|
||||
@@ -32,18 +33,15 @@ void _pwmCleanup(void) {
|
||||
serviceClose(&g_pwmSrv);
|
||||
}
|
||||
|
||||
Service* pwmGetServiceSession(void) {
|
||||
Service *pwmGetServiceSession(void) {
|
||||
return &g_pwmSrv;
|
||||
}
|
||||
|
||||
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code) {
|
||||
return serviceDispatchIn(&g_pwmSrv, 2, device_code,
|
||||
.out_num_objects = 1,
|
||||
.out_objects = &out->s,
|
||||
);
|
||||
return serviceDispatchIn(&g_pwmSrv, 2, device_code, .out_num_objects = 1, .out_objects = &out->s, );
|
||||
}
|
||||
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out) {
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out) {
|
||||
return serviceDispatchOut(&c->s, 7, *out);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -29,11 +29,11 @@ typedef struct {
|
||||
|
||||
Result pwmInitialize(void);
|
||||
void pwmExit(void);
|
||||
Service* pwmGetServiceSession(void);
|
||||
Service *pwmGetServiceSession(void);
|
||||
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code);
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out);
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out);
|
||||
void pwmChannelSessionClose(PwmChannelSession *c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -12,13 +12,15 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
#include "pcv_types.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
Service s;
|
||||
} RgltrSession;
|
||||
@@ -27,12 +29,12 @@ Result rgltrInitialize(void);
|
||||
|
||||
void rgltrExit(void);
|
||||
|
||||
Service* rgltrGetServiceSession(void);
|
||||
Service *rgltrGetServiceSession(void);
|
||||
|
||||
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
|
||||
void rgltrCloseSession(RgltrSession* session);
|
||||
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt);
|
||||
Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id);
|
||||
void rgltrCloseSession(RgltrSession *session);
|
||||
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt);
|
||||
Result rgltrGetPowerModuleNumLimit(u32 *out);
|
||||
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out);
|
||||
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt);
|
||||
Result rgltrCancelVoltageRequest(RgltrSession* session);
|
||||
Result rgltrGetVoltageEnabled(RgltrSession *session, u32 *out);
|
||||
Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt);
|
||||
Result rgltrCancelVoltageRequest(RgltrSession *session);
|
||||
@@ -12,13 +12,15 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#include "rgltr.h"
|
||||
#include "rgltr_services.h" // for extern Service g_rgltrSrv, etc.
|
||||
|
||||
|
||||
// Global service handle
|
||||
Service g_rgltrSrv;
|
||||
|
||||
@@ -33,18 +35,12 @@ void rgltrExit(void) {
|
||||
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;
|
||||
return serviceDispatchIn(
|
||||
&g_rgltrSrv,
|
||||
0,
|
||||
in,
|
||||
.out_num_objects = 1,
|
||||
.out_objects = &session_out->s
|
||||
);
|
||||
return serviceDispatchIn(&g_rgltrSrv, 0, in, .out_num_objects = 1, .out_objects = &session_out->s);
|
||||
}
|
||||
|
||||
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
|
||||
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt) {
|
||||
u32 temp = 0;
|
||||
Result rc = serviceDispatchOut(&session->s, 4, temp);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
@@ -53,14 +49,14 @@ Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt) {
|
||||
Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt) {
|
||||
return serviceDispatchIn(&session->s, 5, microvolt);
|
||||
}
|
||||
|
||||
Result rgltrCancelVoltageRequest(RgltrSession* session) {
|
||||
Result rgltrCancelVoltageRequest(RgltrSession *session) {
|
||||
return serviceDispatch(&session->s, 6);
|
||||
}
|
||||
|
||||
void rgltrCloseSession(RgltrSession* session) {
|
||||
void rgltrCloseSession(RgltrSession *session) {
|
||||
serviceClose(&session->s);
|
||||
}
|
||||
@@ -12,21 +12,23 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#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;
|
||||
|
||||
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);
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,22 +24,15 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "i2c.h"
|
||||
|
||||
#define I2C_CMD_SND 0
|
||||
#define I2C_CMD_RCV 1
|
||||
|
||||
Result i2csessionExtRegReceive(I2cSession* s, u8 in, void* out, u8 out_size)
|
||||
{
|
||||
u8 cmdlist[5] = {
|
||||
I2C_CMD_SND | (I2cTransactionOption_Start << 6),
|
||||
sizeof(in),
|
||||
in,
|
||||
Result i2csessionExtRegReceive(I2cSession *s, u8 in, void *out, u8 out_size) {
|
||||
u8 cmdlist[5] = { I2C_CMD_SND | (I2cTransactionOption_Start << 6), sizeof(in), in,
|
||||
|
||||
I2C_CMD_RCV | (I2cTransactionOption_All << 6),
|
||||
out_size
|
||||
};
|
||||
I2C_CMD_RCV | (I2cTransactionOption_All << 6), out_size };
|
||||
|
||||
return i2csessionExecuteCommandList(s, out, out_size, cmdlist, sizeof(cmdlist));
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,17 +24,15 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "i2cDrv.h"
|
||||
|
||||
@@ -37,8 +37,12 @@ Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) {
|
||||
}
|
||||
|
||||
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
|
||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||
struct { u8 val; } __attribute__((packed)) rec;
|
||||
struct {
|
||||
u8 reg;
|
||||
} __attribute__((packed)) cmd;
|
||||
struct {
|
||||
u8 val;
|
||||
} __attribute__((packed)) rec;
|
||||
|
||||
I2cSession _session;
|
||||
Result res = i2cOpenSession(&_session, dev);
|
||||
@@ -63,8 +67,12 @@ Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
|
||||
}
|
||||
|
||||
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) {
|
||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||
struct { u16 val; } __attribute__((packed)) rec;
|
||||
struct {
|
||||
u8 reg;
|
||||
} __attribute__((packed)) cmd;
|
||||
struct {
|
||||
u16 val;
|
||||
} __attribute__((packed)) rec;
|
||||
|
||||
I2cSession _session;
|
||||
Result res = i2cOpenSession(&_session, dev);
|
||||
@@ -94,20 +102,20 @@ float I2c_Max17050_GetBatteryCurrent() {
|
||||
if (res)
|
||||
return 0.f;
|
||||
|
||||
const float SenseResistor = 5.; // in uOhm
|
||||
const float CGain = 1.99993;
|
||||
const float SenseResistor = 5.; // in uOhm
|
||||
const float CGain = 1.99993;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
if (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;
|
||||
}
|
||||
|
||||
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain) {
|
||||
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain *domain) {
|
||||
u8 val;
|
||||
// Retry 5 times if received POR value
|
||||
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);
|
||||
}
|
||||
|
||||
u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain* domain) {
|
||||
u32 I2c_BuckConverter_GetUvOut(const I2c_BuckConverter_Domain *domain) {
|
||||
u8 val;
|
||||
// Retry 5 times if received POR value
|
||||
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);
|
||||
}
|
||||
|
||||
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt) {
|
||||
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain *domain, u32 mvolt) {
|
||||
u8 val;
|
||||
Result res = I2cRead_OutU8(domain->device, domain->reg, &val);
|
||||
if (R_FAILED(res))
|
||||
@@ -179,7 +187,7 @@ u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
|
||||
// Adjustment is required
|
||||
u8 raw = 0;
|
||||
|
||||
if (ma > MA_RANGE_MAX) // capping
|
||||
if (ma > MA_RANGE_MAX) // capping
|
||||
ma = MA_RANGE_MAX;
|
||||
|
||||
bool pct20 = ma <= (MA_RANGE_MIN - 64);
|
||||
@@ -188,8 +196,8 @@ u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
|
||||
raw |= 0x1;
|
||||
}
|
||||
|
||||
ma -= ma % 100; // round to 100
|
||||
ma -= (MA_RANGE_MIN - 64); // ceiling
|
||||
ma -= ma % 100; // round to 100
|
||||
ma -= (MA_RANGE_MIN - 64); // ceiling
|
||||
raw |= (ma >> 6) << 2;
|
||||
|
||||
return raw;
|
||||
@@ -223,14 +231,21 @@ Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) {
|
||||
|
||||
// Converts mA to the raw value for bits [2:0] of REG00
|
||||
static u8 I2c_Bq24193_Convert_InputmA_Raw(u32 ma) {
|
||||
if (ma <= 100) return 0b000;
|
||||
if (ma <= 150) return 0b001;
|
||||
if (ma <= 500) return 0b010;
|
||||
if (ma <= 900) return 0b011;
|
||||
if (ma <= 1200) return 0b100;
|
||||
if (ma <= 1500) return 0b101;
|
||||
if (ma <= 2000) return 0b110;
|
||||
return 0b111; // 3000mA max
|
||||
if (ma <= 100)
|
||||
return 0b000;
|
||||
if (ma <= 150)
|
||||
return 0b001;
|
||||
if (ma <= 500)
|
||||
return 0b010;
|
||||
if (ma <= 900)
|
||||
return 0b011;
|
||||
if (ma <= 1200)
|
||||
return 0b100;
|
||||
if (ma <= 1500)
|
||||
return 0b101;
|
||||
if (ma <= 2000)
|
||||
return 0b110;
|
||||
return 0b111; // 3000mA max
|
||||
}
|
||||
|
||||
Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
|
||||
@@ -239,35 +254,51 @@ Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
|
||||
return 0;
|
||||
|
||||
u8 raw;
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193,
|
||||
BQ24193_INPUT_SOURCE_CONTROL_REG,
|
||||
&raw);
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_INPUT_SOURCE_CONTROL_REG, &raw);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
raw &= ~0x07;
|
||||
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
|
||||
Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma) {
|
||||
u8 raw;
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193,BQ24193_INPUT_SOURCE_CONTROL_REG,&raw);
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_INPUT_SOURCE_CONTROL_REG, &raw);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
switch (raw & 0x07) {
|
||||
case 0b000: *ma = 100; break;
|
||||
case 0b001: *ma = 150; break;
|
||||
case 0b010: *ma = 500; break;
|
||||
case 0b011: *ma = 900; break;
|
||||
case 0b100: *ma = 1200; break;
|
||||
case 0b101: *ma = 1500; break;
|
||||
case 0b110: *ma = 2000; break;
|
||||
case 0b111: *ma = 3000; break;
|
||||
default: *ma = 0; break;
|
||||
case 0b000:
|
||||
*ma = 100;
|
||||
break;
|
||||
case 0b001:
|
||||
*ma = 150;
|
||||
break;
|
||||
case 0b010:
|
||||
*ma = 500;
|
||||
break;
|
||||
case 0b011:
|
||||
*ma = 900;
|
||||
break;
|
||||
case 0b100:
|
||||
*ma = 1200;
|
||||
break;
|
||||
case 0b101:
|
||||
*ma = 1500;
|
||||
break;
|
||||
case 0b110:
|
||||
*ma = 2000;
|
||||
break;
|
||||
case 0b111:
|
||||
*ma = 3000;
|
||||
break;
|
||||
default:
|
||||
*ma = 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ const u8 MAX17050_CURRENT_REG = 0x0A;
|
||||
// Buck Converter
|
||||
typedef enum I2c_BuckConverter_Reg {
|
||||
I2c_Max77620_SD0VOLT_REG = 0x16,
|
||||
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_Max77621_VOLT_REG = 0x00,
|
||||
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_Max77621_VOLT_REG = 0x00,
|
||||
I2c_Max77812_CPUVOLT_REG = 0x26,
|
||||
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;
|
||||
|
||||
typedef struct I2c_BuckConverter_Domain {
|
||||
@@ -40,22 +40,32 @@ typedef struct I2c_BuckConverter_Domain {
|
||||
u8 por_val;
|
||||
} I2c_BuckConverter_Domain;
|
||||
|
||||
const I2c_BuckConverter_Domain I2c_SOC = { I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000, };
|
||||
const I2c_BuckConverter_Domain I2c_VDD2 = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000, };
|
||||
const I2c_BuckConverter_Domain I2c_Display = { I2cDevice_Max77620Pmic, I2c_Max77620_LDO0VOLT_REG, 0x3F, 25000, 800000, 1325000, };
|
||||
const I2c_BuckConverter_Domain I2c_Erista_CPU = { I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
|
||||
const I2c_BuckConverter_Domain I2c_Erista_GPU = { I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
|
||||
const I2c_BuckConverter_Domain I2c_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 };
|
||||
const I2c_BuckConverter_Domain I2c_SOC = {
|
||||
I2cDevice_Max77620Pmic, I2c_Max77620_SD0VOLT_REG, 0x7F, 12500, 600000, 1400000,
|
||||
};
|
||||
const I2c_BuckConverter_Domain I2c_VDD2 = {
|
||||
I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1350000,
|
||||
};
|
||||
const I2c_BuckConverter_Domain I2c_Display = {
|
||||
I2cDevice_Max77620Pmic, I2c_Max77620_LDO0VOLT_REG, 0x3F, 25000, 800000, 1325000,
|
||||
};
|
||||
const I2c_BuckConverter_Domain I2c_Erista_CPU = {
|
||||
I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000,
|
||||
};
|
||||
const I2c_BuckConverter_Domain I2c_Erista_GPU = {
|
||||
I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000,
|
||||
};
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_CPU = { I2cDevice_Max77812_2, I2c_Max77812_CPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_GPU = { I2cDevice_Max77812_2, I2c_Max77812_GPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDDQ = { I2cDevice_Max77812_2, I2c_Max77812_MEMVOLT_REG, 0xFF, 5000, 250000, 700000, 0x78 };
|
||||
|
||||
u32 I2c_BuckConverter_GetMvOut(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);
|
||||
u32 I2c_BuckConverter_GetMvOut(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);
|
||||
|
||||
// Bq24193 Battery management
|
||||
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_SetFastChargeCurrentLimit(u32 ma);
|
||||
|
||||
@@ -22,15 +22,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "max17050.h"
|
||||
#include "i2c.h"
|
||||
#include "max17050.h"
|
||||
|
||||
#define MAX17050_WAIT_NS 1000000000UL
|
||||
|
||||
#define MAX17050_VCELL 0x09
|
||||
#define MAX17050_Current 0x0A
|
||||
#define MAX17050_VCELL 0x09
|
||||
#define MAX17050_Current 0x0A
|
||||
#define MAX17050_AvgCurrent 0x0B
|
||||
#define MAX17050_AvgVCELL 0x19
|
||||
#define MAX17050_AvgVCELL 0x19
|
||||
|
||||
#define MAX17050_BOARD_CGAIN 2
|
||||
#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_avg = 0;
|
||||
|
||||
static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
|
||||
{
|
||||
static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg) {
|
||||
s64 ma, mv;
|
||||
u16 values[3] = {0};
|
||||
u16 values[3] = { 0 };
|
||||
|
||||
Result rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_VCELL, values, sizeof(values));
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
ma = (s16)values[1];
|
||||
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN);
|
||||
|
||||
@@ -57,13 +55,11 @@ static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
|
||||
*out_mw_now = ma * mv / 1000000;
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = i2csessionExtRegReceive(&g_i2c_session, MAX17050_AvgVCELL, values, sizeof(u16));
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
ma = (s16)values[2];
|
||||
ma = ma * 1562500 / (MAX17050_BOARD_SNS_RESISTOR_UOHM * MAX17050_BOARD_CGAIN);
|
||||
|
||||
@@ -75,50 +71,42 @@ static Result _max17050_get_power(s32 *out_mw_now, s32 *out_mw_avg)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void _max17050_update()
|
||||
{
|
||||
static void _max17050_update() {
|
||||
u64 ticks = armGetSystemTick();
|
||||
if(armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS)
|
||||
{
|
||||
if (armTicksToNs(ticks - g_update_ticks) <= MAX17050_WAIT_NS) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_update_ticks = ticks;
|
||||
|
||||
if(!serviceIsActive(&g_i2c_session.s))
|
||||
{
|
||||
if (!serviceIsActive(&g_i2c_session.s)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_max17050_get_power(&g_power_now, &g_power_avg);
|
||||
}
|
||||
|
||||
Result max17050Initialize(void)
|
||||
{
|
||||
Result max17050Initialize(void) {
|
||||
Result rc = i2cInitialize();
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = i2cOpenSession(&g_i2c_session, I2cDevice_Max17050);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void max17050Exit(void)
|
||||
{
|
||||
void max17050Exit(void) {
|
||||
i2csessionClose(&g_i2c_session);
|
||||
i2cExit();
|
||||
}
|
||||
|
||||
s32 max17050PowerNow(void)
|
||||
{
|
||||
s32 max17050PowerNow(void) {
|
||||
_max17050_update();
|
||||
return g_power_now;
|
||||
}
|
||||
|
||||
s32 max17050PowerAvg(void)
|
||||
{
|
||||
s32 max17050PowerAvg(void) {
|
||||
_max17050_update();
|
||||
return g_power_avg;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,12 +24,10 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tmp451.h"
|
||||
#include "i2c.h"
|
||||
#include "tmp451.h"
|
||||
|
||||
#define TMP451_WAIT_NS 1000000000UL
|
||||
|
||||
#define TMP451_PCB_TEMP_REG 0x00
|
||||
#define TMP451_SOC_TEMP_REG 0x01
|
||||
#define TMP451_PCB_TEMP_REG 0x00
|
||||
#define TMP451_SOC_TEMP_REG 0x01
|
||||
|
||||
#define TMP451_SOC_TMP_DEC_REG 0x10
|
||||
#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_soc = 0;
|
||||
|
||||
static Result _tmp451_get_temp(u8 reg, u8 dec_reg, s32* out)
|
||||
{
|
||||
static Result _tmp451_get_temp(u8 reg, u8 dec_reg, s32 *out) {
|
||||
u8 val = 0;
|
||||
Result rc = i2csessionExtRegReceive(&g_i2c_session, reg, &val, sizeof(val));
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = (s32)val * 1000;
|
||||
rc = i2csessionExtRegReceive(&g_i2c_session, dec_reg, &val, sizeof(val));
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out += ((s32)(val >> 4) * 625) / 10;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void _tmp451_update()
|
||||
{
|
||||
static void _tmp451_update() {
|
||||
u64 ticks = armGetSystemTick();
|
||||
if(armTicksToNs(ticks - g_update_ticks) <= TMP451_WAIT_NS)
|
||||
{
|
||||
if (armTicksToNs(ticks - g_update_ticks) <= TMP451_WAIT_NS) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_update_ticks = ticks;
|
||||
|
||||
if(!serviceIsActive(&g_i2c_session.s))
|
||||
{
|
||||
if (!serviceIsActive(&g_i2c_session.s)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,32 +65,27 @@ static void _tmp451_update()
|
||||
_tmp451_get_temp(TMP451_SOC_TEMP_REG, TMP451_SOC_TMP_DEC_REG, &g_temp_soc);
|
||||
}
|
||||
|
||||
Result tmp451Initialize(void)
|
||||
{
|
||||
Result tmp451Initialize(void) {
|
||||
Result rc = i2cInitialize();
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = i2cOpenSession(&g_i2c_session, I2cDevice_Tmp451);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void tmp451Exit(void)
|
||||
{
|
||||
void tmp451Exit(void) {
|
||||
i2csessionClose(&g_i2c_session);
|
||||
i2cExit();
|
||||
}
|
||||
|
||||
s32 tmp451TempPcb(void)
|
||||
{
|
||||
s32 tmp451TempPcb(void) {
|
||||
_tmp451_update();
|
||||
return g_temp_pcb;
|
||||
}
|
||||
|
||||
s32 tmp451TempSoc(void)
|
||||
{
|
||||
s32 tmp451TempSoc(void) {
|
||||
_tmp451_update();
|
||||
return g_temp_soc;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,12 +24,10 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,14 +24,12 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "ipc_server.h"
|
||||
#include <string.h>
|
||||
|
||||
Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions)
|
||||
{
|
||||
if(max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1))
|
||||
{
|
||||
#include "ipc_server.h"
|
||||
|
||||
Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions) {
|
||||
if (max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1)) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
@@ -40,27 +38,22 @@ Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions)
|
||||
server->count = 0;
|
||||
|
||||
Result rc = smRegisterService(&server->handles[0], server->srvName, false, max_sessions);
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
server->count = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result ipcServerExit(IpcServer* server)
|
||||
{
|
||||
for(u32 i = 0; i < server->count; i++)
|
||||
{
|
||||
Result ipcServerExit(IpcServer *server) {
|
||||
for (u32 i = 0; i < server->count; i++) {
|
||||
svcCloseHandle(server->handles[i]);
|
||||
}
|
||||
server->count = 0;
|
||||
return smUnregisterService(server->srvName);
|
||||
}
|
||||
|
||||
static Result _ipcServerAddSession(IpcServer* server, Handle session)
|
||||
{
|
||||
if(server->count >= server->max)
|
||||
{
|
||||
static Result _ipcServerAddSession(IpcServer *server, Handle session) {
|
||||
if (server->count >= server->max) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
|
||||
}
|
||||
|
||||
@@ -69,84 +62,70 @@ static Result _ipcServerAddSession(IpcServer* server, Handle session)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result _ipcServerDeleteSession(IpcServer* server, u32 index)
|
||||
{
|
||||
if(!index || index >= server->count)
|
||||
{
|
||||
static Result _ipcServerDeleteSession(IpcServer *server, u32 index) {
|
||||
if (!index || index >= server->count) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
svcCloseHandle(server->handles[index]);
|
||||
|
||||
for(u32 j = index; j < (server->count - 1); j++)
|
||||
{
|
||||
for (u32 j = index; j < (server->count - 1); j++) {
|
||||
server->handles[j] = server->handles[j + 1];
|
||||
}
|
||||
server->count--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result _ipcServerParseRequest(IpcServerRequest* r)
|
||||
{
|
||||
u8* base = armGetTls();
|
||||
static Result _ipcServerParseRequest(IpcServerRequest *r) {
|
||||
u8 *base = armGetTls();
|
||||
|
||||
r->hipc = hipcParseRequest(base);
|
||||
r->data.cmdId = 0;
|
||||
r->data.size = 0;
|
||||
r->data.ptr = NULL;
|
||||
r->data.ptr = NULL;
|
||||
|
||||
if(r->hipc.meta.type == CmifCommandType_Request)
|
||||
{
|
||||
IpcServerRawHeader* header = cmifGetAlignedDataStart(r->hipc.data.data_words, base);
|
||||
if (r->hipc.meta.type == CmifCommandType_Request) {
|
||||
IpcServerRawHeader *header = cmifGetAlignedDataStart(r->hipc.data.data_words, base);
|
||||
size_t dataSize = r->hipc.meta.num_data_words * 4;
|
||||
|
||||
if(!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC)
|
||||
{
|
||||
if (!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
r->data.cmdId = header->cmdId;
|
||||
if(dataSize > sizeof(IpcServerRawHeader))
|
||||
{
|
||||
if (dataSize > sizeof(IpcServerRawHeader)) {
|
||||
r->data.size = dataSize - sizeof(IpcServerRawHeader);
|
||||
r->data.ptr = ((u8*)header) + sizeof(IpcServerRawHeader);
|
||||
r->data.ptr = ((u8 *)header) + sizeof(IpcServerRawHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _ipcServerPrepareResponse(Result rc, void* data, size_t dataSize)
|
||||
{
|
||||
u8* base = armGetTls();
|
||||
HipcRequest hipc = hipcMakeRequestInline(base,
|
||||
.type = CmifCommandType_Request,
|
||||
.num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4,
|
||||
);
|
||||
static void _ipcServerPrepareResponse(Result rc, void *data, size_t dataSize) {
|
||||
u8 *base = armGetTls();
|
||||
HipcRequest hipc =
|
||||
hipcMakeRequestInline(base, .type = CmifCommandType_Request, .num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4, );
|
||||
|
||||
IpcServerRawHeader* rawHeader = cmifGetAlignedDataStart(hipc.data_words, base);
|
||||
IpcServerRawHeader *rawHeader = cmifGetAlignedDataStart(hipc.data_words, base);
|
||||
rawHeader->magic = CMIF_OUT_HEADER_MAGIC;
|
||||
rawHeader->result = rc;
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
memcpy(((u8*)rawHeader) + sizeof(IpcServerRawHeader), data, dataSize);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
memcpy(((u8 *)rawHeader) + sizeof(IpcServerRawHeader), data, dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
static Result _ipcServerProcessNewSession(IpcServer* server)
|
||||
{
|
||||
static Result _ipcServerProcessNewSession(IpcServer *server) {
|
||||
Handle session;
|
||||
Result rc = svcAcceptSession(&session, server->handles[0]);
|
||||
if(R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session)))
|
||||
{
|
||||
if (R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session))) {
|
||||
svcCloseHandle(session);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandler handler, void* userdata, u32 handleIndex)
|
||||
{
|
||||
static Result _ipcServerProcessSession(IpcServer *server, IpcServerRequestHandler handler, void *userdata, u32 handleIndex) {
|
||||
s32 unusedIndex;
|
||||
IpcServerRequest r;
|
||||
size_t dataSize = 0;
|
||||
@@ -154,21 +133,14 @@ static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandle
|
||||
bool close = false;
|
||||
|
||||
Result rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 1, 0, UINT64_MAX);
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = _ipcServerParseRequest(&r);
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
switch(r.hipc.meta.type)
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
switch (r.hipc.meta.type) {
|
||||
case CmifCommandType_Request:
|
||||
_ipcServerPrepareResponse(
|
||||
handler(userdata, &r, data, &dataSize),
|
||||
data,
|
||||
dataSize
|
||||
);
|
||||
_ipcServerPrepareResponse(handler(userdata, &r, data, &dataSize), data, dataSize);
|
||||
break;
|
||||
case CmifCommandType_Close:
|
||||
_ipcServerPrepareResponse(0, NULL, 0);
|
||||
@@ -180,42 +152,33 @@ static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandle
|
||||
}
|
||||
|
||||
rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 0, server->handles[handleIndex], 0);
|
||||
if(rc == KERNELRESULT(TimedOut))
|
||||
{
|
||||
if (rc == KERNELRESULT(TimedOut)) {
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(R_FAILED(rc) || close)
|
||||
{
|
||||
if (R_FAILED(rc) || close) {
|
||||
_ipcServerDeleteSession(server, handleIndex);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata)
|
||||
{
|
||||
Result ipcServerProcess(IpcServer *server, IpcServerRequestHandler handler, void *userdata) {
|
||||
s32 handleIndex = -1;
|
||||
Result rc = svcWaitSynchronization(&handleIndex, server->handles, server->count, UINT64_MAX);
|
||||
|
||||
if(R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count))
|
||||
{
|
||||
if (R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count)) {
|
||||
rc = MAKERESULT(Module_Libnx, LibnxError_NotFound);
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if(handleIndex)
|
||||
{
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (handleIndex) {
|
||||
rc = _ipcServerProcessSession(server, handler, userdata, handleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rc = _ipcServerProcessNewSession(server);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,55 +24,48 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u64 magic;
|
||||
union
|
||||
{
|
||||
union {
|
||||
u64 cmdId;
|
||||
u64 result;
|
||||
};
|
||||
} IpcServerRawHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
SmServiceName srvName;
|
||||
Handle handles[MAX_WAIT_OBJECTS];
|
||||
u32 max;
|
||||
u32 count;
|
||||
} IpcServer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u64 cmdId;
|
||||
void* ptr;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
} IpcServerRequestData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
HipcParsedRequest hipc;
|
||||
IpcServerRequestData data;
|
||||
} 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 ipcServerExit(IpcServer* server);
|
||||
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata);
|
||||
Result ipcServerParseCommand(const IpcServerRequest* r, size_t* out_datasize, void** out_data, u64* out_cmd);
|
||||
Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions);
|
||||
Result ipcServerExit(IpcServer *server);
|
||||
Result ipcServerProcess(IpcServer *server, IpcServerRequestHandler handler, void *userdata);
|
||||
Result ipcServerParseCommand(const IpcServerRequest *r, size_t *out_datasize, void **out_data, u64 *out_cmd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -24,21 +24,22 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "ipc_service.hpp"
|
||||
#include <cstring>
|
||||
#include <switch.h>
|
||||
#include "../hos/apm_ext.h"
|
||||
#include <i2c.h>
|
||||
#include <t210.h>
|
||||
#include <max17050.h>
|
||||
#include <switch.h>
|
||||
#include <t210.h>
|
||||
#include <tmp451.h>
|
||||
|
||||
#include "../file/config.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../file/kip.hpp"
|
||||
#include "../hos/apm_ext.h"
|
||||
#include "../mgr/clock_manager.hpp"
|
||||
#include "ipc_service.hpp"
|
||||
#include <ipc_server.h>
|
||||
#include <lockable_mutex.h>
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../mgr/clock_manager.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include "../file/kip.hpp"
|
||||
namespace ipcService {
|
||||
|
||||
namespace {
|
||||
@@ -48,19 +49,19 @@ namespace ipcService {
|
||||
LockableMutex gThreadMutex;
|
||||
IpcServer gServer;
|
||||
|
||||
Result GetApiVersion(u32* out_version) {
|
||||
Result GetApiVersion(u32 *out_version) {
|
||||
*out_version = HOCCLK_IPC_API_VERSION;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result GetVersionString(char* out_buf, size_t bufSize) {
|
||||
Result GetVersionString(char *out_buf, size_t bufSize) {
|
||||
if (bufSize) {
|
||||
strncpy(out_buf, TARGET_VERSION, bufSize-1);
|
||||
strncpy(out_buf, TARGET_VERSION, bufSize - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result GetCurrentContext(HocClkContext* out_ctx) {
|
||||
Result GetCurrentContext(HocClkContext *out_ctx) {
|
||||
*out_ctx = clockManager::GetCurrentContext();
|
||||
return 0;
|
||||
}
|
||||
@@ -70,7 +71,7 @@ namespace ipcService {
|
||||
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()) {
|
||||
return HOCCLK_ERROR(ConfigNotLoaded);
|
||||
}
|
||||
@@ -78,7 +79,7 @@ namespace ipcService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result GetProfiles(std::uint64_t* tid, HocClkTitleProfileList* out_profiles) {
|
||||
Result GetProfiles(std::uint64_t *tid, HocClkTitleProfileList *out_profiles) {
|
||||
if (!config::HasProfilesLoaded()) {
|
||||
return HOCCLK_ERROR(ConfigNotLoaded);
|
||||
}
|
||||
@@ -86,7 +87,7 @@ namespace ipcService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result SetProfiles(HocClkIpc_SetProfiles_Args* args) {
|
||||
Result SetProfiles(HocClkIpc_SetProfiles_Args *args) {
|
||||
if (!config::HasProfilesLoaded()) {
|
||||
return HOCCLK_ERROR(ConfigNotLoaded);
|
||||
}
|
||||
@@ -97,12 +98,12 @@ namespace ipcService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result SetEnabled(std::uint8_t* enabled) {
|
||||
Result SetEnabled(std::uint8_t *enabled) {
|
||||
config::SetEnabled(*enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result SetOverride(HocClkIpc_SetOverride_Args* args) {
|
||||
Result SetOverride(HocClkIpc_SetOverride_Args *args) {
|
||||
if (!HOCCLK_ENUM_VALID(HocClkModule, args->module)) {
|
||||
return HOCCLK_ERROR(Generic);
|
||||
}
|
||||
@@ -110,7 +111,7 @@ namespace ipcService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result GetConfigValuesHandler(HocClkConfigValueList* out_configValues) {
|
||||
Result GetConfigValuesHandler(HocClkConfigValueList *out_configValues) {
|
||||
if (!config::HasProfilesLoaded()) {
|
||||
return HOCCLK_ERROR(ConfigNotLoaded);
|
||||
}
|
||||
@@ -118,7 +119,7 @@ namespace ipcService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result SetConfigValuesHandler(HocClkConfigValueList* configValues) {
|
||||
Result SetConfigValuesHandler(HocClkConfigValueList *configValues) {
|
||||
if (!config::HasProfilesLoaded()) {
|
||||
return HOCCLK_ERROR(ConfigNotLoaded);
|
||||
}
|
||||
@@ -129,30 +130,28 @@ namespace ipcService {
|
||||
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)) {
|
||||
return HOCCLK_ERROR(Generic);
|
||||
}
|
||||
if (args->maxCount != size/sizeof(*out_list)) {
|
||||
if (args->maxCount != size / sizeof(*out_list)) {
|
||||
return HOCCLK_ERROR(Generic);
|
||||
}
|
||||
clockManager::GetFreqList(args->module, out_list, args->maxCount, out_count);
|
||||
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;
|
||||
switch (r->data.cmdId) {
|
||||
case HocClkIpcCmd_GetApiVersion:
|
||||
*out_dataSize = sizeof(u32);
|
||||
return GetApiVersion((u32*)out_data);
|
||||
return GetApiVersion((u32 *)out_data);
|
||||
|
||||
case HocClkIpcCmd_GetVersionString:
|
||||
if (r->hipc.meta.num_recv_buffers >= 1) {
|
||||
return GetVersionString(
|
||||
(char*)hipcGetBufferAddress(r->hipc.data.recv_buffers),
|
||||
hipcGetBufferSize(r->hipc.data.recv_buffers)
|
||||
);
|
||||
return GetVersionString((char *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
|
||||
hipcGetBufferSize(r->hipc.data.recv_buffers));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -160,7 +159,7 @@ namespace ipcService {
|
||||
if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) {
|
||||
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
|
||||
if (bufSize >= sizeof(HocClkContext)) {
|
||||
return GetCurrentContext((HocClkContext*)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
return GetCurrentContext((HocClkContext *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -171,7 +170,7 @@ namespace ipcService {
|
||||
case HocClkIpcCmd_GetProfileCount:
|
||||
if (r->data.size >= sizeof(std::uint64_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;
|
||||
|
||||
@@ -179,26 +178,27 @@ namespace ipcService {
|
||||
if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) {
|
||||
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
|
||||
if (bufSize >= sizeof(HocClkTitleProfileList)) {
|
||||
return GetProfiles((std::uint64_t*)r->data.ptr, (HocClkTitleProfileList*)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
return GetProfiles((std::uint64_t *)r->data.ptr,
|
||||
(HocClkTitleProfileList *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case HocClkIpcCmd_SetProfiles:
|
||||
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;
|
||||
|
||||
case HocClkIpcCmd_SetEnabled:
|
||||
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;
|
||||
|
||||
case HocClkIpcCmd_SetOverride:
|
||||
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;
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace ipcService {
|
||||
if (r->hipc.meta.num_recv_buffers >= 1) {
|
||||
size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers);
|
||||
if (bufSize >= sizeof(HocClkConfigValueList)) {
|
||||
return GetConfigValuesHandler((HocClkConfigValueList*)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
return GetConfigValuesHandler((HocClkConfigValueList *)hipcGetBufferAddress(r->hipc.data.recv_buffers));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -215,7 +215,7 @@ namespace ipcService {
|
||||
if (r->hipc.meta.num_send_buffers >= 1) {
|
||||
size_t bufSize = hipcGetBufferSize(r->hipc.data.send_buffers);
|
||||
if (bufSize >= sizeof(HocClkConfigValueList)) {
|
||||
return SetConfigValuesHandler((HocClkConfigValueList*)hipcGetBufferAddress(r->hipc.data.send_buffers));
|
||||
return SetConfigValuesHandler((HocClkConfigValueList *)hipcGetBufferAddress(r->hipc.data.send_buffers));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -223,12 +223,9 @@ namespace ipcService {
|
||||
case HocClkIpcCmd_GetFreqList:
|
||||
if (r->data.size >= sizeof(HocClkIpc_GetFreqList_Args) && r->hipc.meta.num_recv_buffers >= 1) {
|
||||
*out_dataSize = sizeof(std::uint32_t);
|
||||
return GetFreqList(
|
||||
(HocClkIpc_GetFreqList_Args*)r->data.ptr,
|
||||
(std::uint32_t*)hipcGetBufferAddress(r->hipc.data.recv_buffers),
|
||||
hipcGetBufferSize(r->hipc.data.recv_buffers),
|
||||
(std::uint32_t*)out_data
|
||||
);
|
||||
return GetFreqList((HocClkIpc_GetFreqList_Args *)r->data.ptr,
|
||||
(std::uint32_t *)hipcGetBufferAddress(r->hipc.data.recv_buffers),
|
||||
hipcGetBufferSize(r->hipc.data.recv_buffers), (std::uint32_t *)out_data);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -243,7 +240,7 @@ namespace ipcService {
|
||||
return HOCCLK_ERROR(Generic);
|
||||
}
|
||||
|
||||
void ProcessThreadFunc(void* arg) {
|
||||
void ProcessThreadFunc(void *arg) {
|
||||
(void)arg;
|
||||
Result rc;
|
||||
while (true) {
|
||||
@@ -259,7 +256,7 @@ namespace ipcService {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Initialize() {
|
||||
std::int32_t priority;
|
||||
@@ -281,7 +278,7 @@ namespace ipcService {
|
||||
}
|
||||
|
||||
void SetRunning(bool running) {
|
||||
std::scoped_lock lock{gThreadMutex};
|
||||
std::scoped_lock lock{ gThreadMutex };
|
||||
if (gRunning == running) {
|
||||
return;
|
||||
}
|
||||
@@ -297,4 +294,4 @@ namespace ipcService {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace ipcService
|
||||
|
||||
@@ -35,4 +35,4 @@ namespace ipcService {
|
||||
void Exit();
|
||||
void SetRunning(bool running);
|
||||
|
||||
}
|
||||
} // namespace ipcService
|
||||
|
||||
@@ -27,115 +27,106 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#include "board/board.hpp"
|
||||
#include "file/config.hpp"
|
||||
#include "file/errors.hpp"
|
||||
#include "file/file_utils.hpp"
|
||||
#include "board/board.hpp"
|
||||
#include "hos/process_management.hpp"
|
||||
#include "mgr/clock_manager.hpp"
|
||||
#include "ipc/ipc_service.hpp"
|
||||
#include "file/config.hpp"
|
||||
#include "mgr/clock_manager.hpp"
|
||||
|
||||
|
||||
#define INNER_HEAP_SIZE 0x40000
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void virtmemSetup(void);
|
||||
extern "C" {
|
||||
void virtmemSetup(void);
|
||||
|
||||
extern std::uint32_t __start__;
|
||||
extern std::uint32_t __start__;
|
||||
|
||||
std::uint32_t __nx_applet_type = AppletType_None;
|
||||
TimeServiceType __nx_time_service_type = TimeServiceType_System;
|
||||
std::uint32_t __nx_fs_num_sessions = 1;
|
||||
u32 __nx_nv_transfermem_size = 0x8000;
|
||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||
NvServiceType __nx_nv_service_type = NvServiceType_Factory;
|
||||
std::uint32_t __nx_applet_type = AppletType_None;
|
||||
TimeServiceType __nx_time_service_type = TimeServiceType_System;
|
||||
std::uint32_t __nx_fs_num_sessions = 1;
|
||||
u32 __nx_nv_transfermem_size = 0x8000;
|
||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||
NvServiceType __nx_nv_service_type = NvServiceType_Factory;
|
||||
|
||||
// Ty to MasaGratoR for this!
|
||||
// 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__Unwind_Resume();
|
||||
void* __real___gxx_personality_v0();
|
||||
// Ty to MasaGratoR for this!
|
||||
// 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__Unwind_Resume();
|
||||
void *__real___gxx_personality_v0();
|
||||
|
||||
void __wrap___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)) {
|
||||
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();
|
||||
}
|
||||
void __wrap___cxa_throw(void *thrown_exception, void *pvar, void (*dest)(void *)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Result rc = fileUtils::Initialize();
|
||||
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) {
|
||||
Result rc = fileUtils::Initialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalThrow(rc);
|
||||
return 1;
|
||||
}
|
||||
config::Initialize();
|
||||
config::Refresh(); // Get config from file
|
||||
config::Refresh(); // Get config from file
|
||||
|
||||
board::Initialize();
|
||||
processManagement::Initialize();
|
||||
@@ -145,7 +136,6 @@ int main(int argc, char** argv)
|
||||
clockManager::Initialize();
|
||||
ipcService::Initialize();
|
||||
|
||||
|
||||
clockManager::SetRunning(true);
|
||||
config::SetEnabled(true);
|
||||
ipcService::SetRunning(true);
|
||||
@@ -154,8 +144,7 @@ int main(int argc, char** argv)
|
||||
// InitFanController(table);
|
||||
// StartFanControllerThread();
|
||||
|
||||
while (clockManager::Running())
|
||||
{
|
||||
while (clockManager::Running()) {
|
||||
clockManager::Tick();
|
||||
clockManager::WaitForNextTick();
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#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;
|
||||
return svcQueryMemoryMapping(virtaddr, &out_size, physaddr, size);
|
||||
} else {
|
||||
|
||||
@@ -18,5 +18,5 @@
|
||||
#pragma once
|
||||
#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);
|
||||
|
||||
@@ -24,32 +24,31 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "clock_manager.hpp"
|
||||
#include <cstring>
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../board/board.hpp"
|
||||
#include "../hos/process_management.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../ipc/ipc_service.hpp"
|
||||
#include "../file/kip.hpp"
|
||||
#include <i2c.h>
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../display/display_refresh_rate.hpp"
|
||||
#include <cstdio>
|
||||
#include <crc32.h>
|
||||
#include "../file/config.hpp"
|
||||
#include "../hos/integrations.hpp"
|
||||
#include "../util/lockable_mutex.h"
|
||||
#include "../file/kip.hpp"
|
||||
#include "governor.hpp"
|
||||
#include "../display/aula.hpp"
|
||||
#include "../soc/gm20b.hpp"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <i2c.h>
|
||||
|
||||
#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 {
|
||||
|
||||
|
||||
bool gRunning = false;
|
||||
LockableMutex gContextMutex;
|
||||
HocClkContext gContext = {};
|
||||
@@ -59,22 +58,20 @@ namespace clockManager {
|
||||
std::uint64_t gLastPowerLogNs = 0;
|
||||
std::uint64_t gLastCsvWriteNs = 0;
|
||||
|
||||
bool IsAssignableHz(HocClkModule module, std::uint32_t hz)
|
||||
{
|
||||
bool IsAssignableHz(HocClkModule module, std::uint32_t hz) {
|
||||
switch (module) {
|
||||
case HocClkModule_CPU:
|
||||
return hz >= 500000000;
|
||||
case HocClkModule_MEM:
|
||||
return hz >= 665600000;
|
||||
default:
|
||||
return true;
|
||||
case HocClkModule_CPU:
|
||||
return hz >= 500000000;
|
||||
case HocClkModule_MEM:
|
||||
return hz >= 665600000;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile)
|
||||
{
|
||||
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile) {
|
||||
if (config::GetConfigValue(HocClkConfigValue_UncappedClocks)) {
|
||||
return ~0; // Integer limit, uncapped clocks ON
|
||||
return ~0; // Integer limit, uncapped clocks ON
|
||||
} else {
|
||||
if (module == HocClkModule_GPU) {
|
||||
if (profile < HocClkProfile_HandheldCharging) {
|
||||
@@ -82,7 +79,7 @@ namespace clockManager {
|
||||
case HocClkSocType_Erista:
|
||||
return 460800000;
|
||||
case HocClkSocType_Mariko:
|
||||
if(board::GetConsoleType() == HocClkConsoleType_Hoag) {
|
||||
if (board::GetConsoleType() == HocClkConsoleType_Hoag) {
|
||||
switch (config::GetConfigValue(KipConfigValue_marikoGpuUV)) {
|
||||
case 0 ... 2:
|
||||
return 614400000;
|
||||
@@ -144,8 +141,7 @@ namespace clockManager {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint32_t GetNearestHz(HocClkModule module, std::uint32_t inHz, std::uint32_t maxHz)
|
||||
{
|
||||
std::uint32_t GetNearestHz(HocClkModule module, std::uint32_t inHz, std::uint32_t maxHz) {
|
||||
std::uint32_t *freqs = &gFreqTable[module].list[0];
|
||||
size_t count = gFreqTable[module].count - 1;
|
||||
|
||||
@@ -163,21 +159,20 @@ namespace clockManager {
|
||||
return freqs[i];
|
||||
}
|
||||
|
||||
void ResetToStockClocks()
|
||||
{
|
||||
void ResetToStockClocks() {
|
||||
board::ResetToStockCpu();
|
||||
if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
|
||||
if (board::GetSocType() == HocClkSocType_Erista)
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
else
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
|
||||
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
|
||||
bool ConfigIntervalTimeout(HocClkConfigValue intervalMsConfigValue, std::uint64_t ns, std::uint64_t *lastLogNs)
|
||||
{
|
||||
bool ConfigIntervalTimeout(HocClkConfigValue intervalMsConfigValue, std::uint64_t ns, std::uint64_t *lastLogNs) {
|
||||
std::uint64_t logInterval = config::GetConfigValue(intervalMsConfigValue) * 1000000ULL;
|
||||
bool shouldLog = logInterval && ((ns - *lastLogNs) > logInterval);
|
||||
|
||||
@@ -188,9 +183,8 @@ namespace clockManager {
|
||||
return shouldLog;
|
||||
}
|
||||
|
||||
void RefreshFreqTableRow(HocClkModule module)
|
||||
{
|
||||
std::scoped_lock lock{gContextMutex};
|
||||
void RefreshFreqTableRow(HocClkModule module) {
|
||||
std::scoped_lock lock{ gContextMutex };
|
||||
|
||||
std::uint32_t freqs[HOCCLK_FREQ_LIST_MAX];
|
||||
std::uint32_t count;
|
||||
@@ -201,15 +195,16 @@ namespace clockManager {
|
||||
std::uint32_t *hz = &gFreqTable[module].list[0];
|
||||
gFreqTable[module].count = 0;
|
||||
|
||||
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko
|
||||
&& config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) {
|
||||
constexpr u32 kStep = 38400000;
|
||||
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Mariko &&
|
||||
config::GetConfigValue(HocClkConfigValue_MarikoMiddleFreqs)) {
|
||||
constexpr u32 kStep = 38400000;
|
||||
constexpr u32 kPcvStep = 76800000;
|
||||
u32 kMax = ~0;
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
for (u32 j = 0; j < count; j++) {
|
||||
if (freqs[j] + kStep == freqs[i]) {
|
||||
if (freqs[j] < kMax) kMax = freqs[j];
|
||||
if (freqs[j] < kMax)
|
||||
kMax = freqs[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -217,7 +212,8 @@ namespace clockManager {
|
||||
if (kMax == ~0u) {
|
||||
kMax = 0;
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
if (freqs[i] > kMax) kMax = freqs[i];
|
||||
if (freqs[i] > kMax)
|
||||
kMax = freqs[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,40 +256,27 @@ namespace clockManager {
|
||||
|
||||
// Workaround for PCV bug involving 38.4mhz step rate on erista
|
||||
if (module == HocClkModule_GPU && board::GetSocType() == HocClkSocType_Erista) {
|
||||
static const struct {
|
||||
u32 hz;
|
||||
HocClkConfigValue kval;
|
||||
static const struct {
|
||||
u32 hz;
|
||||
HocClkConfigValue kval;
|
||||
} eristaGpuVoltMap[] = {
|
||||
{ 76800000, KipConfigValue_g_volt_e_76800 },
|
||||
{ 115200000, KipConfigValue_g_volt_e_115200 },
|
||||
{ 153600000, KipConfigValue_g_volt_e_153600 },
|
||||
{ 192000000, KipConfigValue_g_volt_e_192000 },
|
||||
{ 230400000, KipConfigValue_g_volt_e_230400 },
|
||||
{ 268800000, KipConfigValue_g_volt_e_268800 },
|
||||
{ 307200000, KipConfigValue_g_volt_e_307200 },
|
||||
{ 345600000, KipConfigValue_g_volt_e_345600 },
|
||||
{ 384000000, KipConfigValue_g_volt_e_384000 },
|
||||
{ 422400000, KipConfigValue_g_volt_e_422400 },
|
||||
{ 460800000, KipConfigValue_g_volt_e_460800 },
|
||||
{ 499200000, KipConfigValue_g_volt_e_499200 },
|
||||
{ 537600000, KipConfigValue_g_volt_e_537600 },
|
||||
{ 576000000, KipConfigValue_g_volt_e_576000 },
|
||||
{ 614400000, KipConfigValue_g_volt_e_614400 },
|
||||
{ 652800000, KipConfigValue_g_volt_e_652800 },
|
||||
{ 691200000, KipConfigValue_g_volt_e_691200 },
|
||||
{ 729600000, KipConfigValue_g_volt_e_729600 },
|
||||
{ 768000000, KipConfigValue_g_volt_e_768000 },
|
||||
{ 806400000, KipConfigValue_g_volt_e_806400 },
|
||||
{ 844800000, KipConfigValue_g_volt_e_844800 },
|
||||
{ 883200000, KipConfigValue_g_volt_e_883200 },
|
||||
{ 921600000, KipConfigValue_g_volt_e_921600 },
|
||||
{ 960000000, KipConfigValue_g_volt_e_960000 },
|
||||
{ 998400000, KipConfigValue_g_volt_e_998400 },
|
||||
{1036800000, KipConfigValue_g_volt_e_1036800 },
|
||||
{1075200000, KipConfigValue_g_volt_e_1075200 },
|
||||
{ 76800000, KipConfigValue_g_volt_e_76800 }, { 115200000, KipConfigValue_g_volt_e_115200 },
|
||||
{ 153600000, KipConfigValue_g_volt_e_153600 }, { 192000000, KipConfigValue_g_volt_e_192000 },
|
||||
{ 230400000, KipConfigValue_g_volt_e_230400 }, { 268800000, KipConfigValue_g_volt_e_268800 },
|
||||
{ 307200000, KipConfigValue_g_volt_e_307200 }, { 345600000, KipConfigValue_g_volt_e_345600 },
|
||||
{ 384000000, KipConfigValue_g_volt_e_384000 }, { 422400000, KipConfigValue_g_volt_e_422400 },
|
||||
{ 460800000, KipConfigValue_g_volt_e_460800 }, { 499200000, KipConfigValue_g_volt_e_499200 },
|
||||
{ 537600000, KipConfigValue_g_volt_e_537600 }, { 576000000, KipConfigValue_g_volt_e_576000 },
|
||||
{ 614400000, KipConfigValue_g_volt_e_614400 }, { 652800000, KipConfigValue_g_volt_e_652800 },
|
||||
{ 691200000, KipConfigValue_g_volt_e_691200 }, { 729600000, KipConfigValue_g_volt_e_729600 },
|
||||
{ 768000000, KipConfigValue_g_volt_e_768000 }, { 806400000, KipConfigValue_g_volt_e_806400 },
|
||||
{ 844800000, KipConfigValue_g_volt_e_844800 }, { 883200000, KipConfigValue_g_volt_e_883200 },
|
||||
{ 921600000, KipConfigValue_g_volt_e_921600 }, { 960000000, KipConfigValue_g_volt_e_960000 },
|
||||
{ 998400000, KipConfigValue_g_volt_e_998400 }, { 1036800000, KipConfigValue_g_volt_e_1036800 },
|
||||
{ 1075200000, KipConfigValue_g_volt_e_1075200 },
|
||||
};
|
||||
bool skip = false;
|
||||
for (auto& entry : eristaGpuVoltMap) {
|
||||
for (auto &entry : eristaGpuVoltMap) {
|
||||
if (entry.hz == freqs[i]) {
|
||||
if (config::GetConfigValue(entry.kval) == 2000) {
|
||||
skip = true;
|
||||
@@ -301,7 +284,8 @@ namespace clockManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (skip) continue;
|
||||
if (skip)
|
||||
continue;
|
||||
}
|
||||
|
||||
*hz = freqs[i];
|
||||
@@ -314,14 +298,15 @@ namespace clockManager {
|
||||
fileUtils::LogLine("[mgr] count = %u", gFreqTable[module].count);
|
||||
}
|
||||
|
||||
bool HandleSafetyFeatures(bool isBoost)
|
||||
{
|
||||
if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) && config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
|
||||
bool HandleSafetyFeatures(bool isBoost) {
|
||||
if (((tmp451TempSoc() / 1000) > (int)config::GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) &&
|
||||
config::GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
|
||||
ResetToStockClocks();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (config::GetConfigValue(HocClkConfigValue_AutoRAMCPUOverclock) && !isBoost && !governor::isCpuGovernorEnabled && (board::GetSocType() == HocClkSocType_Mariko)) {
|
||||
if (config::GetConfigValue(HocClkConfigValue_AutoRAMCPUOverclock) && !isBoost && !governor::isCpuGovernorEnabled &&
|
||||
(board::GetSocType() == HocClkSocType_Mariko)) {
|
||||
u32 ramHz = gContext.freqs[HocClkModule_MEM];
|
||||
u32 threshold = (u32)config::GetConfigValue(HocClkConfigValue_AutoRamCpuRamOCThreshold) * 1000;
|
||||
if (ramHz >= threshold) {
|
||||
@@ -339,31 +324,30 @@ namespace clockManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void HandleMiscFeatures()
|
||||
{
|
||||
void HandleMiscFeatures() {
|
||||
|
||||
// these dont need to run that often, so dont bother
|
||||
static u32 tick = 0;
|
||||
if(++tick > 10) {
|
||||
tick = 0;
|
||||
// these dont need to run that often, so dont bother
|
||||
static u32 tick = 0;
|
||||
if (++tick > 10) {
|
||||
tick = 0;
|
||||
|
||||
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
|
||||
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
|
||||
}
|
||||
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
|
||||
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
|
||||
}
|
||||
|
||||
if (config::GetConfigValue(HocClkConfigValue_InputCurrentLimit)) {
|
||||
I2c_Bq24193_SetInputCurrentLimit(config::GetConfigValue(HocClkConfigValue_InputCurrentLimit));
|
||||
}
|
||||
if (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)
|
||||
AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset));
|
||||
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
|
||||
board::HandleCpuUv();
|
||||
if (board::GetConsoleType() == HocClkConsoleType_Aula)
|
||||
AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset));
|
||||
if (config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
|
||||
board::HandleCpuUv();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyGpuDvfs(u32 targetHz) {
|
||||
s32 dvfsOffset = config::GetConfigValue(HocClkConfigValue_DVFSOffset);
|
||||
@@ -394,11 +378,9 @@ namespace clockManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DVFSReset()
|
||||
{
|
||||
void DVFSReset() {
|
||||
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];
|
||||
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) {
|
||||
case HocClkModule_CPU:
|
||||
if (!(isBoost || (config::GetConfigValue(HocClkConfigValue_OverwriteBoostMode) && isBoost)))
|
||||
@@ -426,7 +407,9 @@ namespace clockManager {
|
||||
if (board::GetSocType() == HocClkSocType_Erista)
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
else
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow), config::GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(config::GetConfigValue(KipConfigValue_marikoCpuUVLow),
|
||||
config::GetConfigValue(KipConfigValue_marikoCpuUVHigh),
|
||||
board::CalculateTbreak(config::GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
break;
|
||||
case HocClkModule_GPU:
|
||||
@@ -434,7 +417,7 @@ namespace clockManager {
|
||||
break;
|
||||
case HocClkModule_MEM:
|
||||
board::ResetToStockMem();
|
||||
if(!didHijackPcv) {
|
||||
if (!didHijackPcv) {
|
||||
DVFSReset();
|
||||
didHijackPcv = true;
|
||||
}
|
||||
@@ -449,8 +432,7 @@ namespace clockManager {
|
||||
}
|
||||
}
|
||||
|
||||
void SetClocks(bool isBoost)
|
||||
{
|
||||
void SetClocks(bool isBoost) {
|
||||
std::uint32_t targetHz = 0;
|
||||
std::uint32_t maxHz = 0;
|
||||
std::uint32_t nearestHz = 0;
|
||||
@@ -461,16 +443,16 @@ namespace clockManager {
|
||||
if (skipCpuDueToBoost) {
|
||||
board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU));
|
||||
prepareBoostExit = true;
|
||||
return; // Return if we aren't overwriting boost mode
|
||||
return; // Return if we aren't overwriting boost mode
|
||||
}
|
||||
|
||||
if (prepareBoostExit) {
|
||||
board::SetHz(HocClkModule_CPU, board::GetHz(HocClkModule_CPU));
|
||||
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++) {
|
||||
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)
|
||||
returnRaw = true;
|
||||
@@ -521,12 +503,9 @@ namespace clockManager {
|
||||
nearestHz = GetNearestHz((HocClkModule)module, targetHz, maxHz);
|
||||
|
||||
if (nearestHz != gContext.freqs[module]) {
|
||||
fileUtils::LogLine(
|
||||
"[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)",
|
||||
board::GetModuleName((HocClkModule)module, true),
|
||||
nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10,
|
||||
targetHz / 1000000, targetHz / 100000 - targetHz / 1000000 * 10
|
||||
);
|
||||
fileUtils::LogLine("[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)", board::GetModuleName((HocClkModule)module, true),
|
||||
nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10, targetHz / 1000000,
|
||||
targetHz / 100000 - targetHz / 1000000 * 10);
|
||||
|
||||
// The logic MUST be done in this order otherwise you WILL get crashes
|
||||
if (module == HocClkModule_MEM && targetHz > oldHz && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
@@ -544,7 +523,7 @@ namespace clockManager {
|
||||
ApplyGpuDvfs(targetHz);
|
||||
}
|
||||
|
||||
if(module == HocClkModule_MEM && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack)
|
||||
if (module == HocClkModule_MEM && config::GetConfigValue(HocClkConfigValue_DVFSMode) == DVFSMode_Hijack)
|
||||
didHijackPcv = false;
|
||||
}
|
||||
} else {
|
||||
@@ -553,8 +532,7 @@ namespace clockManager {
|
||||
}
|
||||
}
|
||||
|
||||
bool RefreshContext()
|
||||
{
|
||||
bool RefreshContext() {
|
||||
bool hasChanged = false;
|
||||
|
||||
std::uint32_t mode = 0;
|
||||
@@ -589,7 +567,8 @@ namespace clockManager {
|
||||
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
|
||||
hz = board::GetHz((HocClkModule)module);
|
||||
if (hz != 0 && hz != gContext.freqs[module]) {
|
||||
fileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
fileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000,
|
||||
hz / 100000 - hz / 1000000 * 10);
|
||||
gContext.freqs[module] = hz;
|
||||
|
||||
if (module < HocClkModuleStable_EnumMax) {
|
||||
@@ -601,7 +580,8 @@ namespace clockManager {
|
||||
hz = config::GetOverrideHz((HocClkModule)module);
|
||||
if (hz != gContext.overrideFreqs[module]) {
|
||||
if (hz) {
|
||||
fileUtils::LogLine("[mgr] %s override change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
fileUtils::LogLine("[mgr] %s override change: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), hz / 1000000,
|
||||
hz / 100000 - hz / 1000000 * 10);
|
||||
}
|
||||
gContext.overrideFreqs[module] = hz;
|
||||
|
||||
@@ -620,7 +600,8 @@ namespace clockManager {
|
||||
for (unsigned int sensor = 0; sensor < HocClkThermalSensor_EnumMax; sensor++) {
|
||||
millis = board::GetTemperatureMilli((HocClkThermalSensor)sensor);
|
||||
if (shouldLogTemp) {
|
||||
fileUtils::LogLine("[mgr] %s temp: %u.%u °C", board::GetThermalSensorName((HocClkThermalSensor)sensor, true), millis / 1000, (millis - millis / 1000 * 1000) / 100);
|
||||
fileUtils::LogLine("[mgr] %s temp: %u.%u °C", board::GetThermalSensorName((HocClkThermalSensor)sensor, true), millis / 1000,
|
||||
(millis - millis / 1000 * 1000) / 100);
|
||||
}
|
||||
gContext.temps[sensor] = millis;
|
||||
|
||||
@@ -650,7 +631,8 @@ namespace clockManager {
|
||||
for (unsigned int module = 0; module < HocClkModule_EnumMax; module++) {
|
||||
realHz = board::GetRealHz((HocClkModule)module);
|
||||
if (shouldLogFreq) {
|
||||
fileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), realHz / 1000000, realHz / 100000 - realHz / 1000000 * 10);
|
||||
fileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", board::GetModuleName((HocClkModule)module, true), realHz / 1000000,
|
||||
realHz / 100000 - realHz / 1000000 * 10);
|
||||
}
|
||||
gContext.realFreqs[module] = realHz;
|
||||
|
||||
@@ -694,18 +676,17 @@ namespace clockManager {
|
||||
if (gContext.isSaltyNXInstalled)
|
||||
gContext.fps = integrations::GetSaltyNXFPS();
|
||||
else
|
||||
gContext.fps = 254; // N/A
|
||||
gContext.fps = 254; // N/A
|
||||
|
||||
if (gContext.isSaltyNXInstalled)
|
||||
gContext.resolutionHeight = integrations::GetSaltyNXResolutionHeight();
|
||||
else
|
||||
gContext.resolutionHeight = 0; // N/A
|
||||
gContext.resolutionHeight = 0; // N/A
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
void Initialize() {
|
||||
gContext = {};
|
||||
gContext.applicationId = 0;
|
||||
gContext.profile = HocClkProfile_Handheld;
|
||||
@@ -743,8 +724,9 @@ namespace clockManager {
|
||||
gContext.dramID = board::GetDramID();
|
||||
gContext.isDram8GB = board::IsDram8GB();
|
||||
gContext.consoleType = board::GetConsoleType();
|
||||
|
||||
board::SetGpuSchedulingMode((GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling), (GpuSchedulingOverrideMethod)config::GetConfigValue(HocClkConfigValue_GPUSchedulingMethod));
|
||||
|
||||
board::SetGpuSchedulingMode((GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling),
|
||||
(GpuSchedulingOverrideMethod)config::GetConfigValue(HocClkConfigValue_GPUSchedulingMethod));
|
||||
gContext.gpuSchedulingMode = (GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling);
|
||||
|
||||
gContext.isSysDockInstalled = integrations::GetSysDockState();
|
||||
@@ -757,38 +739,32 @@ namespace clockManager {
|
||||
governor::startThreads();
|
||||
}
|
||||
|
||||
void Exit()
|
||||
{
|
||||
void Exit() {
|
||||
governor::exitThreads();
|
||||
}
|
||||
|
||||
HocClkContext GetCurrentContext()
|
||||
{
|
||||
std::scoped_lock lock{gContextMutex};
|
||||
HocClkContext GetCurrentContext() {
|
||||
std::scoped_lock lock{ gContextMutex };
|
||||
return gContext;
|
||||
}
|
||||
|
||||
void SetRunning(bool running)
|
||||
{
|
||||
void SetRunning(bool running) {
|
||||
gRunning = running;
|
||||
}
|
||||
|
||||
bool Running()
|
||||
{
|
||||
bool Running() {
|
||||
return gRunning;
|
||||
}
|
||||
|
||||
void GetFreqList(HocClkModule module, std::uint32_t *list, std::uint32_t maxCount, std::uint32_t *outCount)
|
||||
{
|
||||
void GetFreqList(HocClkModule module, std::uint32_t *list, std::uint32_t maxCount, std::uint32_t *outCount) {
|
||||
ASSERT_ENUM_VALID(HocClkModule, module);
|
||||
|
||||
*outCount = std::min(maxCount, gFreqTable[module].count);
|
||||
memcpy(list, &gFreqTable[module].list[0], *outCount * sizeof(gFreqTable[0].list[0]));
|
||||
}
|
||||
|
||||
void Tick()
|
||||
{
|
||||
std::scoped_lock lock{gContextMutex};
|
||||
void Tick() {
|
||||
std::scoped_lock lock{ gContextMutex };
|
||||
std::uint32_t mode = 0;
|
||||
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
@@ -797,18 +773,18 @@ namespace clockManager {
|
||||
|
||||
bool shouldSkipClockSet = HandleSafetyFeatures(isBoost);
|
||||
HandleMiscFeatures();
|
||||
|
||||
|
||||
// GPU clock should always be the same unless PCV has overwriten our change, so reset it
|
||||
if ((RefreshContext() || config::Refresh() || (board::GetRealHz(HocClkModule_GPU) != gContext.freqs[HocClkModule_GPU])) && !shouldSkipClockSet) {
|
||||
if ((RefreshContext() || config::Refresh() || (board::GetRealHz(HocClkModule_GPU) != gContext.freqs[HocClkModule_GPU])) &&
|
||||
!shouldSkipClockSet) {
|
||||
SetClocks(isBoost);
|
||||
}
|
||||
}
|
||||
|
||||
void WaitForNextTick()
|
||||
{
|
||||
void WaitForNextTick() {
|
||||
if (board::GetHz(HocClkModule_MEM) > 665000000)
|
||||
svcSleepThread(config::GetConfigValue(HocClkConfigValue_PollingIntervalMs) * 1000000ULL);
|
||||
else
|
||||
svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode
|
||||
svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode
|
||||
}
|
||||
} // namespace clockManager
|
||||
} // namespace clockManager
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "../util/lockable_mutex.h"
|
||||
|
||||
namespace clockManager {
|
||||
@@ -37,7 +38,6 @@ namespace clockManager {
|
||||
std::uint32_t list[HOCCLK_FREQ_LIST_MAX];
|
||||
};
|
||||
|
||||
|
||||
extern bool hasChanged;
|
||||
|
||||
// instance variables
|
||||
@@ -50,7 +50,6 @@ namespace clockManager {
|
||||
extern std::uint64_t gLastPowerLogNs;
|
||||
extern std::uint64_t gLastCsvWriteNs;
|
||||
|
||||
|
||||
void Initialize();
|
||||
void Exit();
|
||||
|
||||
@@ -62,8 +61,8 @@ namespace clockManager {
|
||||
std::uint32_t GetMaxAllowedHz(HocClkModule module, HocClkProfile profile);
|
||||
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 WaitForNextTick();
|
||||
}
|
||||
} // namespace clockManager
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "governor.hpp"
|
||||
#include "../hos/process_management.hpp"
|
||||
#include "governor.hpp"
|
||||
#include <hocclk/clock_manager.h>
|
||||
|
||||
namespace governor {
|
||||
|
||||
#define POLL_NS 5'000'000 // 5 ms – governor poll rate
|
||||
#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 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 STEP_UTIL 900 // multiplier for step calculations
|
||||
|
||||
bool isGpuGovernorEnabled = false;
|
||||
bool isCpuGovernorEnabled = false;
|
||||
@@ -44,8 +45,10 @@ namespace governor {
|
||||
}
|
||||
|
||||
auto resolve = [](u8 app, u8 temp) -> u8 {
|
||||
if (temp == ComponentGovernor_Disabled) return ComponentGovernor_Disabled;
|
||||
if (temp != ComponentGovernor_DoNotOverride) return temp;
|
||||
if (temp == ComponentGovernor_Disabled)
|
||||
return ComponentGovernor_Disabled;
|
||||
if (temp != ComponentGovernor_DoNotOverride)
|
||||
return temp;
|
||||
return app;
|
||||
};
|
||||
|
||||
@@ -68,8 +71,10 @@ namespace governor {
|
||||
if (newVrrGovernorState == false && lastVrrGovernorState == true)
|
||||
board::ResetToStockDisplay();
|
||||
|
||||
if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState || newVrrGovernorState != lastVrrGovernorState) {
|
||||
fileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled", newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled");
|
||||
if (newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState ||
|
||||
newVrrGovernorState != lastVrrGovernorState) {
|
||||
fileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled",
|
||||
newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled");
|
||||
lastCpuGovernorState = newCpuGovernorState;
|
||||
lastGpuGovernorState = newGpuGovernorState;
|
||||
lastVrrGovernorState = newVrrGovernorState;
|
||||
@@ -81,7 +86,7 @@ namespace governor {
|
||||
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++)
|
||||
if (table.list[i] >= targetHz)
|
||||
return i;
|
||||
@@ -91,17 +96,13 @@ namespace governor {
|
||||
u32 ResolveTargetHz(HocClkModule module) {
|
||||
u32 hz = clockManager::gContext.overrideFreqs[module];
|
||||
if (!hz)
|
||||
hz = config::GetAutoClockHz(
|
||||
clockManager::gContext.applicationId, module,
|
||||
clockManager::gContext.profile, false);
|
||||
hz = config::GetAutoClockHz(clockManager::gContext.applicationId, module, clockManager::gContext.profile, false);
|
||||
if (!hz)
|
||||
hz = config::GetAutoClockHz(
|
||||
HOCCLK_GLOBAL_PROFILE_TID, module,
|
||||
clockManager::gContext.profile, false);
|
||||
hz = config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, module, clockManager::gContext.profile, false);
|
||||
return hz;
|
||||
}
|
||||
|
||||
void GovernorThread(void* arg) {
|
||||
void GovernorThread(void *arg) {
|
||||
(void)arg;
|
||||
|
||||
u32 cpuDownHoldRemaining = 0;
|
||||
@@ -135,8 +136,8 @@ namespace governor {
|
||||
} else {
|
||||
isCpuGovernorInBoostMode = false;
|
||||
|
||||
auto& table = clockManager::gFreqTable[HocClkModule_CPU];
|
||||
std::scoped_lock lock{clockManager::gContextMutex};
|
||||
auto &table = clockManager::gFreqTable[HocClkModule_CPU];
|
||||
std::scoped_lock lock{ clockManager::gContextMutex };
|
||||
|
||||
u32 cpuLoad = board::GetPartLoad(HocClkPartLoad_CPUMax);
|
||||
u32 tableMaxHz = table.list[table.count - 1];
|
||||
@@ -146,7 +147,7 @@ namespace governor {
|
||||
|
||||
if (targetHz && desiredHz > targetHz)
|
||||
desiredHz = targetHz;
|
||||
if (maxHz && desiredHz > maxHz)
|
||||
if (maxHz && desiredHz > maxHz)
|
||||
desiredHz = maxHz;
|
||||
|
||||
u32 newHz = table.list[TableIndexForHz(table, desiredHz)];
|
||||
@@ -191,8 +192,8 @@ namespace governor {
|
||||
}
|
||||
|
||||
if (isGpuGovernorEnabled) {
|
||||
auto& table = clockManager::gFreqTable[HocClkModule_GPU];
|
||||
std::scoped_lock lock{clockManager::gContextMutex};
|
||||
auto &table = clockManager::gFreqTable[HocClkModule_GPU];
|
||||
std::scoped_lock lock{ clockManager::gContextMutex };
|
||||
|
||||
u32 gpuLoad = board::GetPartLoad(HocClkPartLoad_GPU);
|
||||
u32 tableMaxHz = table.list[table.count - 1];
|
||||
@@ -202,7 +203,7 @@ namespace governor {
|
||||
|
||||
if (targetHz && desiredHz > targetHz)
|
||||
desiredHz = targetHz;
|
||||
if (maxHz && desiredHz > maxHz)
|
||||
if (maxHz && desiredHz > maxHz)
|
||||
desiredHz = maxHz;
|
||||
|
||||
u32 newHz = table.list[TableIndexForHz(table, desiredHz)];
|
||||
@@ -244,13 +245,15 @@ namespace governor {
|
||||
u8 fps = integrations::GetSaltyNXFPS();
|
||||
|
||||
if (fps != 254) {
|
||||
std::scoped_lock lock{clockManager::gContextMutex};
|
||||
std::scoped_lock lock{ clockManager::gContextMutex };
|
||||
|
||||
u32 targetHz = clockManager::gContext.overrideFreqs[HocClkModule_Display];
|
||||
if (!targetHz) {
|
||||
targetHz = config::GetAutoClockHz(clockManager::gContext.applicationId, HocClkModule_Display, clockManager::gContext.profile, false);
|
||||
targetHz = config::GetAutoClockHz(clockManager::gContext.applicationId, HocClkModule_Display,
|
||||
clockManager::gContext.profile, false);
|
||||
if (!targetHz)
|
||||
targetHz = config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, HocClkModule_Display, clockManager::gContext.profile, false);
|
||||
targetHz =
|
||||
config::GetAutoClockHz(HOCCLK_GLOBAL_PROFILE_TID, HocClkModule_Display, clockManager::gContext.profile, false);
|
||||
}
|
||||
|
||||
u8 maxDisplay = targetHz ? (u8)targetHz : 60;
|
||||
@@ -292,19 +295,11 @@ namespace governor {
|
||||
}
|
||||
|
||||
void startThreads() {
|
||||
threadCreate(
|
||||
&governorTHREAD,
|
||||
GovernorThread,
|
||||
nullptr,
|
||||
NULL,
|
||||
0x2000,
|
||||
0x3F,
|
||||
-2
|
||||
);
|
||||
threadCreate(&governorTHREAD, GovernorThread, nullptr, NULL, 0x2000, 0x3F, -2);
|
||||
threadStart(&governorTHREAD);
|
||||
}
|
||||
|
||||
void exitThreads() {
|
||||
threadClose(&governorTHREAD);
|
||||
}
|
||||
}
|
||||
} // namespace governor
|
||||
|
||||
@@ -15,17 +15,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <hocclk.h>
|
||||
#include "../board/board.hpp"
|
||||
#include "clock_manager.hpp"
|
||||
#include <cstring>
|
||||
#include "../file/file_utils.hpp"
|
||||
#include <hocclk.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "../board/board.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../file/config.hpp"
|
||||
#include "../file/errors.hpp"
|
||||
#include "../file/file_utils.hpp"
|
||||
#include "../hos/integrations.hpp"
|
||||
#include "../util/lockable_mutex.h"
|
||||
#include "clock_manager.hpp"
|
||||
|
||||
|
||||
namespace governor {
|
||||
extern bool isCpuGovernorInBoostMode;
|
||||
@@ -38,4 +39,4 @@ namespace governor {
|
||||
void startThreads();
|
||||
void exitThreads();
|
||||
void HandleGovernor(uint32_t targetHz);
|
||||
}
|
||||
} // namespace governor
|
||||
@@ -15,39 +15,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <cstring>
|
||||
#include <switch.h>
|
||||
|
||||
#include "battery.h"
|
||||
|
||||
// Internal PSM service handle
|
||||
static Service g_psmService = {0};
|
||||
static Service g_psmService = { 0 };
|
||||
static bool g_batteryInfoInitialized = false;
|
||||
|
||||
static const char* s_chargerTypeStrings[] = {
|
||||
"None",
|
||||
"Power Delivery",
|
||||
"USB-C @ 1.5A",
|
||||
"USB-C @ 3.0A",
|
||||
"USB-DCP",
|
||||
"USB-CDP",
|
||||
"USB-SDP",
|
||||
"Apple @ 0.5A",
|
||||
"Apple @ 1.0A",
|
||||
"Apple @ 2.0A",
|
||||
static const char *s_chargerTypeStrings[] = {
|
||||
"None", "Power Delivery", "USB-C @ 1.5A", "USB-C @ 3.0A", "USB-DCP", "USB-CDP", "USB-SDP", "Apple @ 0.5A", "Apple @ 1.0A", "Apple @ 2.0A",
|
||||
};
|
||||
|
||||
static const char* s_powerRoleStrings[] = {
|
||||
static const char *s_powerRoleStrings[] = {
|
||||
"Unknown",
|
||||
"Sink",
|
||||
"Source",
|
||||
};
|
||||
|
||||
static const char* s_pdStateStrings[] = {
|
||||
"Unknown",
|
||||
"New PDO Received",
|
||||
"No PD Source",
|
||||
"RDO Accepted"
|
||||
};
|
||||
static const char *s_pdStateStrings[] = { "Unknown", "New PDO Received", "No PD Source", "RDO Accepted" };
|
||||
|
||||
// Internal PSM command implementations
|
||||
static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) {
|
||||
@@ -143,21 +130,21 @@ Result batteryInfoDisableFastCharging(void) {
|
||||
return psmDisableFastBatteryCharging_internal();
|
||||
}
|
||||
|
||||
const char* batteryInfoGetChargerTypeString(BatteryChargerType type) {
|
||||
const char *batteryInfoGetChargerTypeString(BatteryChargerType type) {
|
||||
if (type < 0 || type > ChargerType_Apple_2000mA)
|
||||
return "Unknown";
|
||||
|
||||
return s_chargerTypeStrings[type];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role) {
|
||||
const char *batteryInfoGetPowerRoleString(BatteryPowerRole role) {
|
||||
if (role < PowerRole_Sink || role > PowerRole_Source)
|
||||
return s_powerRoleStrings[0];
|
||||
|
||||
return s_powerRoleStrings[role];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPDStateString(BatteryPDControllerState state) {
|
||||
const char *batteryInfoGetPDStateString(BatteryPDControllerState state) {
|
||||
if (state < PDState_NewPDO || state > PDState_AcceptedRDO)
|
||||
return s_pdStateStrings[0];
|
||||
|
||||
|
||||
@@ -16,57 +16,57 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <switch.h>
|
||||
typedef enum {
|
||||
BatteryFlag_NoHub = BIT(0), // Hub is disconnected
|
||||
BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail
|
||||
BatteryFlag_SPDSRC = BIT(12), // OTG
|
||||
BatteryFlag_ACC = BIT(16) // Accessory
|
||||
BatteryFlag_NoHub = BIT(0), // Hub is disconnected
|
||||
BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail
|
||||
BatteryFlag_SPDSRC = BIT(12), // OTG
|
||||
BatteryFlag_ACC = BIT(16) // Accessory
|
||||
} BatteryChargeFlags;
|
||||
|
||||
typedef enum {
|
||||
PDState_NewPDO = 1, // Received new Power Data Object
|
||||
PDState_NoPD = 2, // No Power Delivery source is detected
|
||||
PDState_NewPDO = 1, // Received new Power Data Object
|
||||
PDState_NoPD = 2, // No Power Delivery source is detected
|
||||
PDState_AcceptedRDO = 3 // Received and accepted Request Data Object
|
||||
} BatteryPDControllerState;
|
||||
|
||||
// Charger type detection
|
||||
typedef enum {
|
||||
ChargerType_None = 0,
|
||||
ChargerType_PD = 1,
|
||||
ChargerType_None = 0,
|
||||
ChargerType_PD = 1,
|
||||
ChargerType_TypeC_1500mA = 2,
|
||||
ChargerType_TypeC_3000mA = 3,
|
||||
ChargerType_DCP = 4, // Dedicated Charging Port
|
||||
ChargerType_CDP = 5, // Charging Downstream Port
|
||||
ChargerType_SDP = 6, // Standard Downstream Port
|
||||
ChargerType_Apple_500mA = 7,
|
||||
ChargerType_DCP = 4, // Dedicated Charging Port
|
||||
ChargerType_CDP = 5, // Charging Downstream Port
|
||||
ChargerType_SDP = 6, // Standard Downstream Port
|
||||
ChargerType_Apple_500mA = 7,
|
||||
ChargerType_Apple_1000mA = 8,
|
||||
ChargerType_Apple_2000mA = 9
|
||||
} BatteryChargerType;
|
||||
typedef enum {
|
||||
PowerRole_Sink = 1, // Device is receiving power
|
||||
PowerRole_Sink = 1, // Device is receiving power
|
||||
PowerRole_Source = 2 // Device is providing power
|
||||
} BatteryPowerRole;
|
||||
|
||||
typedef struct {
|
||||
int32_t InputCurrentLimit; // Input (Sink) 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 ChargeVoltageLimit; // Battery charging voltage limit in mV
|
||||
int32_t unk_x10; // Unknown field (possibly enum)
|
||||
int32_t unk_x14; // Unknown field (possibly flags)
|
||||
BatteryPDControllerState PDControllerState; // PD Controller State
|
||||
int32_t BatteryTemperature; // Battery temperature in milli-Celsius
|
||||
int32_t RawBatteryCharge; // Battery charge in percentmille
|
||||
int32_t VoltageAvg; // Average voltage in mV
|
||||
int32_t BatteryAge; // Battery health (capacity full/design) in pcm
|
||||
BatteryPowerRole PowerRole; // Current power role
|
||||
BatteryChargerType ChargerType; // Type of charger connected
|
||||
int32_t ChargerVoltageLimit; // Charger voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; // Charger current limit in mA
|
||||
BatteryChargeFlags Flags; // Various status flags
|
||||
int32_t InputCurrentLimit; // Input (Sink) 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 ChargeVoltageLimit; // Battery charging voltage limit in mV
|
||||
int32_t unk_x10; // Unknown field (possibly enum)
|
||||
int32_t unk_x14; // Unknown field (possibly flags)
|
||||
BatteryPDControllerState PDControllerState; // PD Controller State
|
||||
int32_t BatteryTemperature; // Battery temperature in milli-Celsius
|
||||
int32_t RawBatteryCharge; // Battery charge in percentmille
|
||||
int32_t VoltageAvg; // Average voltage in mV
|
||||
int32_t BatteryAge; // Battery health (capacity full/design) in pcm
|
||||
BatteryPowerRole PowerRole; // Current power role
|
||||
BatteryChargerType ChargerType; // Type of charger connected
|
||||
int32_t ChargerVoltageLimit; // Charger voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; // Charger current limit in mA
|
||||
BatteryChargeFlags Flags; // Various status flags
|
||||
} BatteryChargeInfo;
|
||||
|
||||
#define IS_BATTERY_CHARGING_ENABLED(info) (((info)->unk_x14 >> 8) & 1)
|
||||
@@ -96,6 +96,6 @@ Result batteryInfoEnableCharging(void);
|
||||
Result batteryInfoDisableCharging(void);
|
||||
Result batteryInfoEnableFastCharging(void);
|
||||
Result batteryInfoDisableFastCharging(void);
|
||||
const char* batteryInfoGetChargerTypeString(BatteryChargerType type);
|
||||
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role);
|
||||
const char* batteryInfoGetPDStateString(BatteryPDControllerState state);
|
||||
const char *batteryInfoGetChargerTypeString(BatteryChargerType type);
|
||||
const char *batteryInfoGetPowerRoleString(BatteryPowerRole role);
|
||||
const char *batteryInfoGetPDStateString(BatteryPDControllerState state);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2018 balika011
|
||||
* Copyright (c) 2019-2025 CTCaer
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
@@ -22,293 +22,283 @@
|
||||
#define _FUSE_H_
|
||||
|
||||
#ifndef BIT
|
||||
#define BIT(n) (1U<<(n))
|
||||
#define BIT(n) (1U << (n))
|
||||
#endif
|
||||
|
||||
/*! Fuse registers. */
|
||||
#define FUSE_CTRL 0x0
|
||||
#define FUSE_ADDR 0x4
|
||||
#define FUSE_RDATA 0x8
|
||||
#define FUSE_WDATA 0xC
|
||||
#define FUSE_TIME_RD1 0x10
|
||||
#define FUSE_TIME_RD2 0x14
|
||||
#define FUSE_TIME_PGM1 0x18
|
||||
#define FUSE_TIME_PGM2 0x1C
|
||||
#define FUSE_PRIV2INTFC 0x20
|
||||
#define FUSE_PRIV2INTFC_START_DATA BIT(0)
|
||||
#define FUSE_PRIV2INTFC_SKIP_RECORDS BIT(1)
|
||||
#define FUSE_FUSEBYPASS 0x24
|
||||
#define FUSE_PRIVATEKEYDISABLE 0x28
|
||||
#define FUSE_PRIVKEY_DISABLE BIT(0)
|
||||
#define FUSE_PRIVKEY_TZ_STICKY_BIT BIT(4)
|
||||
#define FUSE_DISABLEREGPROGRAM 0x2C
|
||||
#define FUSE_WRITE_ACCESS_SW 0x30
|
||||
#define FUSE_PWR_GOOD_SW 0x34
|
||||
#define FUSE_PRIV2RESHIFT 0x3C
|
||||
#define FUSE_FUSETIME_RD0 0x40
|
||||
#define FUSE_FUSETIME_RD1 0x44
|
||||
#define FUSE_FUSETIME_RD2 0x48
|
||||
#define FUSE_FUSETIME_RD3 0x4C
|
||||
#define FUSE_PRIVATE_KEY0_NONZERO 0x80
|
||||
#define FUSE_PRIVATE_KEY1_NONZERO 0x84
|
||||
#define FUSE_PRIVATE_KEY2_NONZERO 0x88
|
||||
#define FUSE_PRIVATE_KEY3_NONZERO 0x8C
|
||||
#define FUSE_PRIVATE_KEY4_NONZERO 0x90
|
||||
#define FUSE_CTRL 0x0
|
||||
#define FUSE_ADDR 0x4
|
||||
#define FUSE_RDATA 0x8
|
||||
#define FUSE_WDATA 0xC
|
||||
#define FUSE_TIME_RD1 0x10
|
||||
#define FUSE_TIME_RD2 0x14
|
||||
#define FUSE_TIME_PGM1 0x18
|
||||
#define FUSE_TIME_PGM2 0x1C
|
||||
#define FUSE_PRIV2INTFC 0x20
|
||||
#define FUSE_PRIV2INTFC_START_DATA BIT(0)
|
||||
#define FUSE_PRIV2INTFC_SKIP_RECORDS BIT(1)
|
||||
#define FUSE_FUSEBYPASS 0x24
|
||||
#define FUSE_PRIVATEKEYDISABLE 0x28
|
||||
#define FUSE_PRIVKEY_DISABLE BIT(0)
|
||||
#define FUSE_PRIVKEY_TZ_STICKY_BIT BIT(4)
|
||||
#define FUSE_DISABLEREGPROGRAM 0x2C
|
||||
#define FUSE_WRITE_ACCESS_SW 0x30
|
||||
#define FUSE_PWR_GOOD_SW 0x34
|
||||
#define FUSE_PRIV2RESHIFT 0x3C
|
||||
#define FUSE_FUSETIME_RD0 0x40
|
||||
#define FUSE_FUSETIME_RD1 0x44
|
||||
#define FUSE_FUSETIME_RD2 0x48
|
||||
#define FUSE_FUSETIME_RD3 0x4C
|
||||
#define FUSE_PRIVATE_KEY0_NONZERO 0x80
|
||||
#define FUSE_PRIVATE_KEY1_NONZERO 0x84
|
||||
#define FUSE_PRIVATE_KEY2_NONZERO 0x88
|
||||
#define FUSE_PRIVATE_KEY3_NONZERO 0x8C
|
||||
#define FUSE_PRIVATE_KEY4_NONZERO 0x90
|
||||
|
||||
/*! Fuse Cached registers */
|
||||
#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_ODM10_B01 0xA0 // 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_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_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_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_ODM19_B01 0xC4 // FUSE_READ_TZ Group 2.
|
||||
#define FUSE_RESERVED_ODM20_B01 0xC8 // FUSE_READ_TZ Group 3.
|
||||
#define FUSE_RESERVED_ODM21_B01 0xCC // FUSE_READ_TZ Group 3.
|
||||
#define FUSE_KEK00_B01 0xD0
|
||||
#define FUSE_KEK01_B01 0xD4
|
||||
#define FUSE_KEK02_B01 0xD8
|
||||
#define FUSE_KEK03_B01 0xDC
|
||||
#define FUSE_BEK00_B01 0xE0
|
||||
#define FUSE_BEK01_B01 0xE4
|
||||
#define FUSE_BEK02_B01 0xE8
|
||||
#define FUSE_BEK03_B01 0xEC
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4SVT_B01 0xF0
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4SVT_B01 0xF4
|
||||
#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_ODM10_B01 0xA0 // 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_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_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_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_ODM19_B01 0xC4 // FUSE_READ_TZ Group 2.
|
||||
#define FUSE_RESERVED_ODM20_B01 0xC8 // FUSE_READ_TZ Group 3.
|
||||
#define FUSE_RESERVED_ODM21_B01 0xCC // FUSE_READ_TZ Group 3.
|
||||
#define FUSE_KEK00_B01 0xD0
|
||||
#define FUSE_KEK01_B01 0xD4
|
||||
#define FUSE_KEK02_B01 0xD8
|
||||
#define FUSE_KEK03_B01 0xDC
|
||||
#define FUSE_BEK00_B01 0xE0
|
||||
#define FUSE_BEK01_B01 0xE4
|
||||
#define FUSE_BEK02_B01 0xE8
|
||||
#define FUSE_BEK03_B01 0xEC
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4SVT_B01 0xF0
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4SVT_B01 0xF4
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4SVT_B01 0xF8
|
||||
#define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4SVT_B01 0xFC
|
||||
|
||||
#define FUSE_PRODUCTION_MODE 0x100
|
||||
#define FUSE_JTAG_SECUREID_VALID 0x104
|
||||
#define FUSE_ODM_LOCK 0x108
|
||||
#define FUSE_OPT_OPENGL_EN 0x10C
|
||||
#define FUSE_SKU_INFO 0x110
|
||||
#define FUSE_CPU_SPEEDO_0_CALIB 0x114
|
||||
#define FUSE_CPU_IDDQ_CALIB 0x118
|
||||
#define FUSE_PRODUCTION_MODE 0x100
|
||||
#define FUSE_JTAG_SECUREID_VALID 0x104
|
||||
#define FUSE_ODM_LOCK 0x108
|
||||
#define FUSE_OPT_OPENGL_EN 0x10C
|
||||
#define FUSE_SKU_INFO 0x110
|
||||
#define FUSE_CPU_SPEEDO_0_CALIB 0x114
|
||||
#define FUSE_CPU_IDDQ_CALIB 0x118
|
||||
|
||||
#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_ODM24_B01 0x124 // FUSE_READ_TZ Group 4.
|
||||
#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_ODM24_B01 0x124 // FUSE_READ_TZ Group 4.
|
||||
|
||||
#define FUSE_OPT_FT_REV 0x128
|
||||
#define FUSE_CPU_SPEEDO_1_CALIB 0x12C
|
||||
#define FUSE_CPU_SPEEDO_2_CALIB 0x130
|
||||
#define FUSE_SOC_SPEEDO_0_CALIB 0x134
|
||||
#define FUSE_SOC_SPEEDO_1_CALIB 0x138
|
||||
#define FUSE_SOC_SPEEDO_2_CALIB 0x13C
|
||||
#define FUSE_SOC_IDDQ_CALIB 0x140
|
||||
#define FUSE_OPT_FT_REV 0x128
|
||||
#define FUSE_CPU_SPEEDO_1_CALIB 0x12C
|
||||
#define FUSE_CPU_SPEEDO_2_CALIB 0x130
|
||||
#define FUSE_SOC_SPEEDO_0_CALIB 0x134
|
||||
#define FUSE_SOC_SPEEDO_1_CALIB 0x138
|
||||
#define FUSE_SOC_SPEEDO_2_CALIB 0x13C
|
||||
#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_RESERVED_PRODUCTION 0x14C
|
||||
#define FUSE_HDMI_LANE0_CALIB 0x150
|
||||
#define FUSE_HDMI_LANE1_CALIB 0x154
|
||||
#define FUSE_HDMI_LANE2_CALIB 0x158
|
||||
#define FUSE_HDMI_LANE3_CALIB 0x15C
|
||||
#define FUSE_ENCRYPTION_RATE 0x160
|
||||
#define FUSE_PUBLIC_KEY0 0x164
|
||||
#define FUSE_PUBLIC_KEY1 0x168
|
||||
#define FUSE_PUBLIC_KEY2 0x16C
|
||||
#define FUSE_PUBLIC_KEY3 0x170
|
||||
#define FUSE_PUBLIC_KEY4 0x174
|
||||
#define FUSE_PUBLIC_KEY5 0x178
|
||||
#define FUSE_PUBLIC_KEY6 0x17C
|
||||
#define FUSE_PUBLIC_KEY7 0x180
|
||||
#define FUSE_TSENSOR1_CALIB 0x184 // CPU1.
|
||||
#define FUSE_TSENSOR2_CALIB 0x188 // CPU2.
|
||||
#define FUSE_FA 0x148
|
||||
#define FUSE_RESERVED_PRODUCTION 0x14C
|
||||
#define FUSE_HDMI_LANE0_CALIB 0x150
|
||||
#define FUSE_HDMI_LANE1_CALIB 0x154
|
||||
#define FUSE_HDMI_LANE2_CALIB 0x158
|
||||
#define FUSE_HDMI_LANE3_CALIB 0x15C
|
||||
#define FUSE_ENCRYPTION_RATE 0x160
|
||||
#define FUSE_PUBLIC_KEY0 0x164
|
||||
#define FUSE_PUBLIC_KEY1 0x168
|
||||
#define FUSE_PUBLIC_KEY2 0x16C
|
||||
#define FUSE_PUBLIC_KEY3 0x170
|
||||
#define FUSE_PUBLIC_KEY4 0x174
|
||||
#define FUSE_PUBLIC_KEY5 0x178
|
||||
#define FUSE_PUBLIC_KEY6 0x17C
|
||||
#define FUSE_PUBLIC_KEY7 0x180
|
||||
#define FUSE_TSENSOR1_CALIB 0x184 // CPU1.
|
||||
#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_PFG 0x194
|
||||
#define FUSE_TSENSOR0_CALIB 0x198 // CPU0.
|
||||
#define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19C
|
||||
#define FUSE_SECURITY_MODE 0x1A0
|
||||
#define FUSE_PRIVATE_KEY0 0x1A4
|
||||
#define FUSE_PRIVATE_KEY1 0x1A8
|
||||
#define FUSE_PRIVATE_KEY2 0x1AC
|
||||
#define FUSE_PRIVATE_KEY3 0x1B0
|
||||
#define FUSE_PRIVATE_KEY4 0x1B4
|
||||
#define FUSE_ARM_JTAG_DIS 0x1B8
|
||||
#define FUSE_BOOT_DEVICE_INFO 0x1BC
|
||||
#define FUSE_RESERVED_SW 0x1C0
|
||||
#define FUSE_OPT_VP9_DISABLE 0x1C4
|
||||
#define FUSE_OPT_CP_REV 0x190 // FUSE style revision - ATE. 0x101 0x100
|
||||
#define FUSE_OPT_PFG 0x194
|
||||
#define FUSE_TSENSOR0_CALIB 0x198 // CPU0.
|
||||
#define FUSE_FIRST_BOOTROM_PATCH_SIZE 0x19C
|
||||
#define FUSE_SECURITY_MODE 0x1A0
|
||||
#define FUSE_PRIVATE_KEY0 0x1A4
|
||||
#define FUSE_PRIVATE_KEY1 0x1A8
|
||||
#define FUSE_PRIVATE_KEY2 0x1AC
|
||||
#define FUSE_PRIVATE_KEY3 0x1B0
|
||||
#define FUSE_PRIVATE_KEY4 0x1B4
|
||||
#define FUSE_ARM_JTAG_DIS 0x1B8
|
||||
#define FUSE_BOOT_DEVICE_INFO 0x1BC
|
||||
#define FUSE_RESERVED_SW 0x1C0
|
||||
#define FUSE_OPT_VP9_DISABLE 0x1C4
|
||||
|
||||
#define FUSE_RESERVED_ODM0 0x1C8
|
||||
#define FUSE_RESERVED_ODM1 0x1CC
|
||||
#define FUSE_RESERVED_ODM2 0x1D0
|
||||
#define FUSE_RESERVED_ODM3 0x1D4
|
||||
#define FUSE_RESERVED_ODM4 0x1D8
|
||||
#define FUSE_RESERVED_ODM5 0x1DC
|
||||
#define FUSE_RESERVED_ODM6 0x1E0
|
||||
#define FUSE_RESERVED_ODM7 0x1E4
|
||||
#define FUSE_RESERVED_ODM0 0x1C8
|
||||
#define FUSE_RESERVED_ODM1 0x1CC
|
||||
#define FUSE_RESERVED_ODM2 0x1D0
|
||||
#define FUSE_RESERVED_ODM3 0x1D4
|
||||
#define FUSE_RESERVED_ODM4 0x1D8
|
||||
#define FUSE_RESERVED_ODM5 0x1DC
|
||||
#define FUSE_RESERVED_ODM6 0x1E0
|
||||
#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_USB_CALIB 0x1F0
|
||||
#define FUSE_SKU_DIRECT_CONFIG 0x1F4
|
||||
#define FUSE_KFUSE_PRIVKEY_CTRL 0x1F8
|
||||
#define FUSE_PACKAGE_INFO 0x1FC // 1: MID, 2: DSC.
|
||||
#define FUSE_OPT_VENDOR_CODE 0x200
|
||||
#define FUSE_OPT_FAB_CODE 0x204
|
||||
#define FUSE_OPT_LOT_CODE_0 0x208
|
||||
#define FUSE_OPT_LOT_CODE_1 0x20C
|
||||
#define FUSE_OPT_WAFER_ID 0x210
|
||||
#define FUSE_OPT_X_COORDINATE 0x214
|
||||
#define FUSE_OPT_Y_COORDINATE 0x218
|
||||
#define FUSE_OPT_SEC_DEBUG_EN 0x21C
|
||||
#define FUSE_OPT_OPS_RESERVED 0x220
|
||||
#define FUSE_SATA_CALIB 0x224
|
||||
#define FUSE_USB_CALIB 0x1F0
|
||||
#define FUSE_SKU_DIRECT_CONFIG 0x1F4
|
||||
#define FUSE_KFUSE_PRIVKEY_CTRL 0x1F8
|
||||
#define FUSE_PACKAGE_INFO 0x1FC // 1: MID, 2: DSC.
|
||||
#define FUSE_OPT_VENDOR_CODE 0x200
|
||||
#define FUSE_OPT_FAB_CODE 0x204
|
||||
#define FUSE_OPT_LOT_CODE_0 0x208
|
||||
#define FUSE_OPT_LOT_CODE_1 0x20C
|
||||
#define FUSE_OPT_WAFER_ID 0x210
|
||||
#define FUSE_OPT_X_COORDINATE 0x214
|
||||
#define FUSE_OPT_Y_COORDINATE 0x218
|
||||
#define FUSE_OPT_SEC_DEBUG_EN 0x21C
|
||||
#define FUSE_OPT_OPS_RESERVED 0x220
|
||||
#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_TSENSOR3_CALIB 0x22C // CPU3.
|
||||
#define FUSE_CLOCK_BONDOUT0 0x230
|
||||
#define FUSE_CLOCK_BONDOUT1 0x234
|
||||
#define FUSE_GPU_IDDQ_CALIB 0x228
|
||||
#define FUSE_TSENSOR3_CALIB 0x22C // CPU3.
|
||||
#define FUSE_CLOCK_BONDOUT0 0x230
|
||||
#define FUSE_CLOCK_BONDOUT1 0x234
|
||||
|
||||
#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_ODM28_B01 0x240 // MAX77812 phase configuration. FUSE_READ_TZ Group 5.
|
||||
#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_ODM28_B01 0x240 // MAX77812 phase configuration. FUSE_READ_TZ Group 5.
|
||||
|
||||
#define FUSE_OPT_SAMPLE_TYPE 0x244
|
||||
#define FUSE_OPT_SUBREVISION 0x248 // "", "p", "q", "r". e.g: A01p.
|
||||
#define FUSE_OPT_SW_RESERVED_0 0x24C
|
||||
#define FUSE_OPT_SW_RESERVED_1 0x250
|
||||
#define FUSE_TSENSOR4_CALIB 0x254 // GPU.
|
||||
#define FUSE_TSENSOR5_CALIB 0x258 // MEM0.
|
||||
#define FUSE_TSENSOR6_CALIB 0x25C // MEM1.
|
||||
#define FUSE_TSENSOR7_CALIB 0x260 // PLLX.
|
||||
#define FUSE_OPT_PRIV_SEC_DIS 0x264
|
||||
#define FUSE_PKC_DISABLE 0x268
|
||||
#define FUSE_OPT_SAMPLE_TYPE 0x244
|
||||
#define FUSE_OPT_SUBREVISION 0x248 // "", "p", "q", "r". e.g: A01p.
|
||||
#define FUSE_OPT_SW_RESERVED_0 0x24C
|
||||
#define FUSE_OPT_SW_RESERVED_1 0x250
|
||||
#define FUSE_TSENSOR4_CALIB 0x254 // GPU.
|
||||
#define FUSE_TSENSOR5_CALIB 0x258 // MEM0.
|
||||
#define FUSE_TSENSOR6_CALIB 0x25C // MEM1.
|
||||
#define FUSE_TSENSOR7_CALIB 0x260 // PLLX.
|
||||
#define FUSE_OPT_PRIV_SEC_DIS 0x264
|
||||
#define FUSE_PKC_DISABLE 0x268
|
||||
|
||||
#define FUSE_BOOT_SECURITY_INFO_B01 0x268
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4HVT_B01 0x26C
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4HVT_B01 0x270
|
||||
#define FUSE_BOOT_SECURITY_INFO_B01 0x268
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCSP_PO4HVT_B01 0x26C
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCSP_PO4HVT_B01 0x270
|
||||
#define FUSE_OPT_RAM_RTSEL_TSMCPDP_PO4HVT_B01 0x274
|
||||
#define FUSE_OPT_RAM_MTSEL_TSMCPDP_PO4HVT_B01 0x278
|
||||
|
||||
#define FUSE_FUSE2TSEC_DEBUG_DISABLE 0x27C
|
||||
#define FUSE_TSENSOR_COMMON 0x280
|
||||
#define FUSE_OPT_CP_BIN 0x284
|
||||
#define FUSE_OPT_GPU_DISABLE 0x288
|
||||
#define FUSE_OPT_FT_BIN 0x28C
|
||||
#define FUSE_OPT_DONE_MAP 0x290
|
||||
#define FUSE_FUSE2TSEC_DEBUG_DISABLE 0x27C
|
||||
#define FUSE_TSENSOR_COMMON 0x280
|
||||
#define FUSE_OPT_CP_BIN 0x284
|
||||
#define FUSE_OPT_GPU_DISABLE 0x288
|
||||
#define FUSE_OPT_FT_BIN 0x28C
|
||||
#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_ODM_INFO 0x29C // Debug features disable.
|
||||
#define FUSE_ARM_CRYPT_DE_FEATURE 0x2A8
|
||||
#define FUSE_APB2JTAG_DISABLE 0x298
|
||||
#define FUSE_ODM_INFO 0x29C // Debug features disable.
|
||||
#define FUSE_ARM_CRYPT_DE_FEATURE 0x2A8
|
||||
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4SVT_B01 0x2B0
|
||||
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4SVT_B01 0x2B4
|
||||
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4SVT_B01 0x2B8
|
||||
#define FUSE_OPT_RAM_KP_TSMCDP_PO4SVT_B01 0x2BC
|
||||
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4SVT_B01 0x2B4
|
||||
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4SVT_B01 0x2B8
|
||||
#define FUSE_OPT_RAM_KP_TSMCDP_PO4SVT_B01 0x2BC
|
||||
|
||||
#define FUSE_WOA_SKU_FLAG 0x2C0
|
||||
#define FUSE_ECO_RESERVE_1 0x2C4
|
||||
#define FUSE_GCPLEX_CONFIG_FUSE 0x2C8
|
||||
#define FUSE_GPU_VPR_AUTO_FETCH_DIS BIT(0)
|
||||
#define FUSE_GPU_VPR_ENABLED BIT(1)
|
||||
#define FUSE_GPU_WPR_ENABLED BIT(2)
|
||||
#define FUSE_PRODUCTION_MONTH 0x2CC
|
||||
#define FUSE_RAM_REPAIR_INDICATOR 0x2D0
|
||||
#define FUSE_TSENSOR9_CALIB 0x2D4 // AOTAG.
|
||||
#define FUSE_VMIN_CALIBRATION 0x2DC
|
||||
#define FUSE_AGING_SENSOR_CALIBRATION 0x2E0
|
||||
#define FUSE_DEBUG_AUTHENTICATION 0x2E4
|
||||
#define FUSE_SECURE_PROVISION_INDEX 0x2E8
|
||||
#define FUSE_SECURE_PROVISION_INFO 0x2EC
|
||||
#define FUSE_OPT_GPU_DISABLE_CP1 0x2F0
|
||||
#define FUSE_SPARE_ENDIS 0x2F4
|
||||
#define FUSE_ECO_RESERVE_0 0x2F8 // AID.
|
||||
#define FUSE_RESERVED_CALIB0 0x304 // GPCPLL ADC Calibration.
|
||||
#define FUSE_RESERVED_CALIB1 0x308
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE 0x30C
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE_CP1 0x310
|
||||
#define FUSE_OPT_CPU_DISABLE 0x314
|
||||
#define FUSE_OPT_CPU_DISABLE_CP1 0x318
|
||||
#define FUSE_TSENSOR10_CALIB 0x31C
|
||||
#define FUSE_TSENSOR10_CALIB_AUX 0x320
|
||||
#define FUSE_OPT_RAM_SVOP_DP 0x324
|
||||
#define FUSE_OPT_RAM_SVOP_PDP 0x328
|
||||
#define FUSE_OPT_RAM_SVOP_REG 0x32C
|
||||
#define FUSE_OPT_RAM_SVOP_SP 0x330
|
||||
#define FUSE_OPT_RAM_SVOP_SMPDP 0x334
|
||||
#define FUSE_WOA_SKU_FLAG 0x2C0
|
||||
#define FUSE_ECO_RESERVE_1 0x2C4
|
||||
#define FUSE_GCPLEX_CONFIG_FUSE 0x2C8
|
||||
#define FUSE_GPU_VPR_AUTO_FETCH_DIS BIT(0)
|
||||
#define FUSE_GPU_VPR_ENABLED BIT(1)
|
||||
#define FUSE_GPU_WPR_ENABLED BIT(2)
|
||||
#define FUSE_PRODUCTION_MONTH 0x2CC
|
||||
#define FUSE_RAM_REPAIR_INDICATOR 0x2D0
|
||||
#define FUSE_TSENSOR9_CALIB 0x2D4 // AOTAG.
|
||||
#define FUSE_VMIN_CALIBRATION 0x2DC
|
||||
#define FUSE_AGING_SENSOR_CALIBRATION 0x2E0
|
||||
#define FUSE_DEBUG_AUTHENTICATION 0x2E4
|
||||
#define FUSE_SECURE_PROVISION_INDEX 0x2E8
|
||||
#define FUSE_SECURE_PROVISION_INFO 0x2EC
|
||||
#define FUSE_OPT_GPU_DISABLE_CP1 0x2F0
|
||||
#define FUSE_SPARE_ENDIS 0x2F4
|
||||
#define FUSE_ECO_RESERVE_0 0x2F8 // AID.
|
||||
#define FUSE_RESERVED_CALIB0 0x304 // GPCPLL ADC Calibration.
|
||||
#define FUSE_RESERVED_CALIB1 0x308
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE 0x30C
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE_CP1 0x310
|
||||
#define FUSE_OPT_CPU_DISABLE 0x314
|
||||
#define FUSE_OPT_CPU_DISABLE_CP1 0x318
|
||||
#define FUSE_TSENSOR10_CALIB 0x31C
|
||||
#define FUSE_TSENSOR10_CALIB_AUX 0x320
|
||||
#define FUSE_OPT_RAM_SVOP_DP 0x324
|
||||
#define FUSE_OPT_RAM_SVOP_PDP 0x328
|
||||
#define FUSE_OPT_RAM_SVOP_REG 0x32C
|
||||
#define FUSE_OPT_RAM_SVOP_SP 0x330
|
||||
#define FUSE_OPT_RAM_SVOP_SMPDP 0x334
|
||||
|
||||
#define FUSE_OPT_RAM_WTSEL_TSMCPDP_PO4HVT_B01 0x324
|
||||
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4HVT_B01 0x328
|
||||
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4HVT_B01 0x32c
|
||||
#define FUSE_OPT_RAM_KP_TSMCDP_PO4HVT_B01 0x330
|
||||
#define FUSE_OPT_RAM_SVOP_SP_B01 0x334
|
||||
#define FUSE_OPT_RAM_RCT_TSMCDP_PO4HVT_B01 0x328
|
||||
#define FUSE_OPT_RAM_WCT_TSMCDP_PO4HVT_B01 0x32c
|
||||
#define FUSE_OPT_RAM_KP_TSMCDP_PO4HVT_B01 0x330
|
||||
#define FUSE_OPT_RAM_SVOP_SP_B01 0x334
|
||||
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE_CP2 0x338
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE 0x33C
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE_CP1 0x340
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE_CP2 0x344
|
||||
#define FUSE_OPT_CPU_DISABLE_CP2 0x348
|
||||
#define FUSE_OPT_GPU_DISABLE_CP2 0x34C
|
||||
#define FUSE_USB_CALIB_EXT 0x350
|
||||
#define FUSE_RESERVED_FIELD 0x354 // RMA.
|
||||
#define FUSE_SPARE_REALIGNMENT_REG 0x37C
|
||||
#define FUSE_SPARE_BIT_0 0x380
|
||||
#define FUSE_OPT_GPU_TPC0_DISABLE_CP2 0x338
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE 0x33C
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE_CP1 0x340
|
||||
#define FUSE_OPT_GPU_TPC1_DISABLE_CP2 0x344
|
||||
#define FUSE_OPT_CPU_DISABLE_CP2 0x348
|
||||
#define FUSE_OPT_GPU_DISABLE_CP2 0x34C
|
||||
#define FUSE_USB_CALIB_EXT 0x350
|
||||
#define FUSE_RESERVED_FIELD 0x354 // RMA.
|
||||
#define FUSE_SPARE_REALIGNMENT_REG 0x37C
|
||||
#define FUSE_SPARE_BIT_0 0x380
|
||||
//...
|
||||
#define FUSE_SPARE_BIT_31 0x3FC
|
||||
#define FUSE_SPARE_BIT_31 0x3FC
|
||||
|
||||
/*! Fuse commands. */
|
||||
#define FUSE_IDLE 0x0
|
||||
#define FUSE_READ 0x1
|
||||
#define FUSE_WRITE 0x2
|
||||
#define FUSE_SENSE 0x3
|
||||
#define FUSE_IDLE 0x0
|
||||
#define FUSE_READ 0x1
|
||||
#define FUSE_WRITE 0x2
|
||||
#define FUSE_SENSE 0x3
|
||||
#define FUSE_CMD_MASK 0x3
|
||||
|
||||
/*! Fuse status. */
|
||||
#define FUSE_STATUS_RESET 0
|
||||
#define FUSE_STATUS_POST_RESET 1
|
||||
#define FUSE_STATUS_LOAD_ROW0 2
|
||||
#define FUSE_STATUS_LOAD_ROW1 3
|
||||
#define FUSE_STATUS_IDLE 4
|
||||
#define FUSE_STATUS_READ_SETUP 5
|
||||
#define FUSE_STATUS_READ_STROBE 6
|
||||
#define FUSE_STATUS_SAMPLE_FUSES 7
|
||||
#define FUSE_STATUS_READ_HOLD 8
|
||||
#define FUSE_STATUS_FUSE_SRC_SETUP 9
|
||||
#define FUSE_STATUS_WRITE_SETUP 10
|
||||
#define FUSE_STATUS_WRITE_ADDR_SETUP 11
|
||||
#define FUSE_STATUS_WRITE_PROGRAM 12
|
||||
#define FUSE_STATUS_WRITE_ADDR_HOLD 13
|
||||
#define FUSE_STATUS_FUSE_SRC_HOLD 14
|
||||
#define FUSE_STATUS_LOAD_RIR 15
|
||||
#define FUSE_STATUS_RESET 0
|
||||
#define FUSE_STATUS_POST_RESET 1
|
||||
#define FUSE_STATUS_LOAD_ROW0 2
|
||||
#define FUSE_STATUS_LOAD_ROW1 3
|
||||
#define FUSE_STATUS_IDLE 4
|
||||
#define FUSE_STATUS_READ_SETUP 5
|
||||
#define FUSE_STATUS_READ_STROBE 6
|
||||
#define FUSE_STATUS_SAMPLE_FUSES 7
|
||||
#define FUSE_STATUS_READ_HOLD 8
|
||||
#define FUSE_STATUS_FUSE_SRC_SETUP 9
|
||||
#define FUSE_STATUS_WRITE_SETUP 10
|
||||
#define FUSE_STATUS_WRITE_ADDR_SETUP 11
|
||||
#define FUSE_STATUS_WRITE_PROGRAM 12
|
||||
#define FUSE_STATUS_WRITE_ADDR_HOLD 13
|
||||
#define FUSE_STATUS_FUSE_SRC_HOLD 14
|
||||
#define FUSE_STATUS_LOAD_RIR 15
|
||||
#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. */
|
||||
#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
|
||||
|
||||
enum
|
||||
{
|
||||
FUSE_NX_HW_TYPE_ICOSA,
|
||||
FUSE_NX_HW_TYPE_IOWA,
|
||||
FUSE_NX_HW_TYPE_HOAG,
|
||||
FUSE_NX_HW_TYPE_AULA
|
||||
};
|
||||
enum { FUSE_NX_HW_TYPE_ICOSA, FUSE_NX_HW_TYPE_IOWA, FUSE_NX_HW_TYPE_HOAG, FUSE_NX_HW_TYPE_AULA };
|
||||
|
||||
enum
|
||||
{
|
||||
FUSE_NX_HW_STATE_PROD,
|
||||
FUSE_NX_HW_STATE_DEV
|
||||
};
|
||||
enum { FUSE_NX_HW_STATE_PROD, FUSE_NX_HW_STATE_DEV };
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,56 +14,56 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "gm20b.hpp"
|
||||
#include "../mapping/mem_map.hpp"
|
||||
#include "gm20b.hpp"
|
||||
|
||||
|
||||
namespace gm20b {
|
||||
u64 gpu_base = 0;
|
||||
#define GPU_PA 0x57000000
|
||||
#define GPU_SIZE 0x1000000
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG 0x00
|
||||
#define GPU_TRIM_SYS_GPCPLL_COEFF 0x04
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG2 0x08
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG3 0x0C
|
||||
#define GPU_TRIM_SYS_GPCPLL_DVFS0 0x10
|
||||
#define GPU_TRIM_SYS_GPCPLL_DVFS1 0x14
|
||||
#define GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN 0x1C
|
||||
#define GPU_TRIM_SYS_SEL_VCO 0x2C
|
||||
#define GPU_TRIM_SYS_GPC2CLK_OUT 0x250
|
||||
#define GPU_PA 0x57000000
|
||||
#define GPU_SIZE 0x1000000
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG 0x00
|
||||
#define GPU_TRIM_SYS_GPCPLL_COEFF 0x04
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG2 0x08
|
||||
#define GPU_TRIM_SYS_GPCPLL_CFG3 0x0C
|
||||
#define GPU_TRIM_SYS_GPCPLL_DVFS0 0x10
|
||||
#define GPU_TRIM_SYS_GPCPLL_DVFS1 0x14
|
||||
#define GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN 0x1C
|
||||
#define GPU_TRIM_SYS_SEL_VCO 0x2C
|
||||
#define GPU_TRIM_SYS_GPC2CLK_OUT 0x250
|
||||
|
||||
#define GPC_BCAST(x) (*(volatile u32 *)(gpu_base + 0x132800ul + (x)))
|
||||
#define GPU_TRIM_SYS_GPCPLL(x) (*(volatile u32 *)(gpu_base + 0x137000ul + (x)))
|
||||
#define GPC_BCAST(x) (*(volatile u32 *)(gpu_base + 0x132800ul + (x)))
|
||||
#define GPU_TRIM_SYS_GPCPLL(x) (*(volatile u32 *)(gpu_base + 0x137000ul + (x)))
|
||||
|
||||
#define GPC_BCAST_GPCPLL_DVFS2 0x20
|
||||
#define GPC_BCAST_NDIV_SLOWDOWN_DBG 0xa0
|
||||
#define GPC_BCAST_GPCPLL_DVFS2 0x20
|
||||
#define GPC_BCAST_NDIV_SLOWDOWN_DBG 0xa0
|
||||
|
||||
#define GPCPLL_CFG_ENABLE BIT(0)
|
||||
#define GPCPLL_CFG_IDDQ BIT(1)
|
||||
#define GPCPLL_CFG_SYNC_MODE BIT(2)
|
||||
#define GPCPLL_CFG_LOCK BIT(17)
|
||||
#define GPCPLL_CFG_ENABLE BIT(0)
|
||||
#define GPCPLL_CFG_IDDQ BIT(1)
|
||||
#define GPCPLL_CFG_SYNC_MODE BIT(2)
|
||||
#define GPCPLL_CFG_LOCK BIT(17)
|
||||
|
||||
#define GPCPLL_CFG2_SDM_DIN_MASK 0x000000FFu
|
||||
#define GPCPLL_CFG2_SDM_DIN_NEW_MASK 0x007FFF00u
|
||||
#define GPCPLL_CFG2_STEPA_SHIFT 24
|
||||
#define GPCPLL_CFG2_STEPA_MASK 0xFF000000u
|
||||
#define GPCPLL_CFG2_SDM_DIN_MASK 0x000000FFu
|
||||
#define GPCPLL_CFG2_SDM_DIN_NEW_MASK 0x007FFF00u
|
||||
#define GPCPLL_CFG2_STEPA_SHIFT 24
|
||||
#define GPCPLL_CFG2_STEPA_MASK 0xFF000000u
|
||||
|
||||
#define GPCPLL_CFG3_STEPB_SHIFT 16
|
||||
#define GPCPLL_CFG3_STEPB_MASK 0x00FF0000u
|
||||
#define GPCPLL_CFG3_STEPB_SHIFT 16
|
||||
#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_EN_DYNRAMP BIT(23)
|
||||
#define NDIV_SLOWDOWN_SLOWDOWN_USING_PLL BIT(22)
|
||||
#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) {
|
||||
u32 tmp = GPU_TRIM_SYS_GPCPLL(reg);
|
||||
@@ -78,12 +78,8 @@ namespace gm20b {
|
||||
}
|
||||
|
||||
static void _clk_setup_slide() {
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2,
|
||||
GPCPLL_CFG2_STEPA_MASK,
|
||||
0x04u << GPCPLL_CFG2_STEPA_SHIFT);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG3,
|
||||
GPCPLL_CFG3_STEPB_MASK,
|
||||
0x05u << GPCPLL_CFG3_STEPB_SHIFT);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_STEPA_MASK, 0x04u << GPCPLL_CFG2_STEPA_SHIFT);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG3, GPCPLL_CFG3_STEPB_MASK, 0x05u << GPCPLL_CFG3_STEPB_SHIFT);
|
||||
}
|
||||
|
||||
static bool _gpu_pllg_slide(u32 new_divn) {
|
||||
@@ -95,9 +91,7 @@ namespace gm20b {
|
||||
|
||||
_clk_setup_slide();
|
||||
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
|
||||
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL,
|
||||
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL);
|
||||
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_SDM_DIN_NEW_MASK, 0);
|
||||
|
||||
@@ -106,9 +100,7 @@ namespace gm20b {
|
||||
GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_COEFF) = coeff;
|
||||
|
||||
usleep(1);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
|
||||
NDIV_SLOWDOWN_EN_DYNRAMP,
|
||||
NDIV_SLOWDOWN_EN_DYNRAMP);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_EN_DYNRAMP, NDIV_SLOWDOWN_EN_DYNRAMP);
|
||||
|
||||
int ramp_timeout = RAMP_TIMEOUT_US;
|
||||
bool success = false;
|
||||
@@ -125,9 +117,7 @@ namespace gm20b {
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_CFG2, GPCPLL_CFG2_SDM_DIN_MASK, 0);
|
||||
}
|
||||
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN,
|
||||
NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP,
|
||||
0);
|
||||
_gpu_mask(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN, NDIV_SLOWDOWN_SLOWDOWN_USING_PLL | NDIV_SLOWDOWN_EN_DYNRAMP, 0);
|
||||
(void)GPU_TRIM_SYS_GPCPLL(GPU_TRIM_SYS_GPCPLL_NDIV_SLOWDOWN);
|
||||
|
||||
return success;
|
||||
@@ -137,11 +127,11 @@ namespace gm20b {
|
||||
if (!gpu_base)
|
||||
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 divm = coeff & 0xFF;
|
||||
u32 divp = (coeff >> 16) & 0x3F;
|
||||
u32 divm = coeff & 0xFF;
|
||||
u32 divp = (coeff >> 16) & 0x3F;
|
||||
|
||||
if (divm == 0 || divp == 0)
|
||||
return false;
|
||||
@@ -149,9 +139,11 @@ namespace gm20b {
|
||||
u32 new_divn = (u64)khz * divm * divp * 2 / osc_khz;
|
||||
|
||||
// L4T clamps the registers here for some reason, do that
|
||||
if (new_divn < 8) new_divn = 8;
|
||||
if (new_divn > 255) new_divn = 255;
|
||||
if (new_divn < 8)
|
||||
new_divn = 8;
|
||||
if (new_divn > 255)
|
||||
new_divn = 255;
|
||||
|
||||
return _gpu_pllg_slide(new_divn);
|
||||
}
|
||||
}
|
||||
} // namespace gm20b
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <../board/board.hpp>
|
||||
|
||||
@@ -14,35 +14,35 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pllmb.hpp"
|
||||
|
||||
namespace pllmb {
|
||||
#define GET_BITS(VAL, HIGH, LOW) ((VAL & ((1UL << (HIGH + 1UL)) - 1UL)) >> LOW)
|
||||
#define GET_BIT(VAL, BIT) GET_BITS(VAL, BIT, BIT)
|
||||
#define GET_BITS(VAL, HIGH, LOW) ((VAL & ((1UL << (HIGH + 1UL)) - 1UL)) >> LOW)
|
||||
#define GET_BIT(VAL, BIT) GET_BITS(VAL, BIT, BIT)
|
||||
|
||||
static inline volatile u32& REG(uintptr_t addr) {
|
||||
return *reinterpret_cast<volatile u32*>(addr);
|
||||
static inline volatile u32 ®(uintptr_t addr) {
|
||||
return *reinterpret_cast<volatile u32 *>(addr);
|
||||
}
|
||||
|
||||
// From jetson nano kernel
|
||||
typedef enum {
|
||||
/* divider = 2 */
|
||||
CLK_PLLX = 5,
|
||||
CLK_PLLM = 2,
|
||||
CLK_PLLX = 5,
|
||||
CLK_PLLM = 2,
|
||||
CLK_PLLMB = 37,
|
||||
/* PLLX & PLLG are backup PLLs for CPU & GPU */
|
||||
/* divider = 1 */
|
||||
CLK_CCLK_G = 18, // A57 CPU cluster
|
||||
CLK_EMC = 36,
|
||||
} PTO_ID; // PLL Test Output Register ID
|
||||
CLK_CCLK_G = 18, // A57 CPU cluster
|
||||
CLK_EMC = 36,
|
||||
} PTO_ID; // PLL Test Output Register ID
|
||||
|
||||
/* See if GM20B clock GPC PLL regs are accessible. */
|
||||
|
||||
#define PLLX_MISC0 0xE4
|
||||
#define PLLM_MISC2 0x9C
|
||||
#define PLLX_MISC0 0xE4
|
||||
#define PLLM_MISC2 0x9C
|
||||
|
||||
double ptoGetMHz(PTO_ID pto_id, u32 divider = 1, u32 presel_reg = 0, u32 presel_mask = 0) {
|
||||
u32 pre_val, val, presel_val;
|
||||
@@ -71,7 +71,7 @@ namespace pllmb {
|
||||
REG(board::clkVirtAddr + 0x60) = val | BIT(9);
|
||||
usleep(500);
|
||||
|
||||
while(REG(board::clkVirtAddr + 0x64) & BIT(31))
|
||||
while (REG(board::clkVirtAddr + 0x64) & BIT(31))
|
||||
;
|
||||
|
||||
val = REG(board::clkVirtAddr + 0x64);
|
||||
@@ -111,6 +111,6 @@ namespace pllmb {
|
||||
|
||||
u32 pllmb = ptoGetMHz(CLK_PLLMB, 2, PLLM_MISC2, BIT(9));
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user