From 327d64f22de012f66345898bcd96da634e2f8da9 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Fri, 20 Mar 2026 19:06:46 +0100 Subject: [PATCH] Rewrite: Add real volts --- .../sysmodule/src/board/board.hpp | 1 + .../sysmodule/src/board/board_init.cpp | 4 + .../sysmodule/src/board/board_volt.cpp | 98 +++++++++++++++++++ .../sysmodule/src/board/board_volt.hpp | 35 +++++++ 4 files changed, 138 insertions(+) create mode 100644 Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.cpp create mode 100644 Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.hpp diff --git a/Source/rewrite-hoc-clk/sysmodule/src/board/board.hpp b/Source/rewrite-hoc-clk/sysmodule/src/board/board.hpp index 1ea200d5..d12f161e 100644 --- a/Source/rewrite-hoc-clk/sysmodule/src/board/board.hpp +++ b/Source/rewrite-hoc-clk/sysmodule/src/board/board.hpp @@ -35,5 +35,6 @@ namespace board { void Initialize(); void Exit(); + SysClkSocType GetSocType(); } diff --git a/Source/rewrite-hoc-clk/sysmodule/src/board/board_init.cpp b/Source/rewrite-hoc-clk/sysmodule/src/board/board_init.cpp index b8f6bf5a..d7f7067f 100644 --- a/Source/rewrite-hoc-clk/sysmodule/src/board/board_init.cpp +++ b/Source/rewrite-hoc-clk/sysmodule/src/board/board_init.cpp @@ -182,4 +182,8 @@ namespace board { } } + SysClkSocType GetSocType() { + return gSocType; + } + } diff --git a/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.cpp b/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.cpp new file mode 100644 index 00000000..7007ea38 --- /dev/null +++ b/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.cpp @@ -0,0 +1,98 @@ +/* + * 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. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* -------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * , , + * wrote this file. As long as you retain this notice you can do whatever you + * want with this stuff. If you meet any of us some day, and you think this + * stuff is worth it, you can buy us a beer in return. - The sys-clk authors + * -------------------------------------------------------------------------- + */ + +#include +#include +#include "board.hpp" + +namespace board { + + u32 GetVoltage(HocClkVoltage voltage) { + RgltrSession session; + Result rc = 0; + u32 out = 0; + + switch (voltage) { + case HocClkVoltage_SOC: + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77620_Sd0); + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + break; + case HocClkVoltage_EMCVDD2: + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77620_Sd1); + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + break; + case HocClkVoltage_CPU: + if (GetSocType() == SysClkSocType_Mariko) { + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77621_Cpu); + } else { + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77812_Cpu); + } + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + break; + case HocClkVoltage_GPU: + if (GetSocType() == SysClkSocType_Mariko) { + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77621_Gpu); + } else { + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77812_Gpu); + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + } + break; + case HocClkVoltage_EMCVDDQ_MarikoOnly: + if (GetSocType() == SysClkSocType_Mariko) { + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77812_Dram); + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + } else { + out = GetVoltage(HocClkVoltage_EMCVDD2); + } + break; + case HocClkVoltage_Display: + rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77620_Ldo0); + ASSERT_RESULT_OK(rc, "rgltrOpenSession") + rgltrGetVoltage(&session, &out); + rgltrCloseSession(&session); + break; + case HocClkVoltage_Battery: + batteryInfoGetChargeInfo(&info); + out = info.VoltageAvg; + break; + default: + ASSERT_ENUM_VALID(HocClkVoltage, voltage); + } + + return out > 0 ? out : 0; + } + +} diff --git a/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.hpp b/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.hpp new file mode 100644 index 00000000..64e9872b --- /dev/null +++ b/Source/rewrite-hoc-clk/sysmodule/src/board/board_volt.hpp @@ -0,0 +1,35 @@ +/* + * 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. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* -------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * , , + * wrote this file. As long as you retain this notice you can do whatever you + * want with this stuff. If you meet any of us some day, and you think this + * stuff is worth it, you can buy us a beer in return. - The sys-clk authors + * -------------------------------------------------------------------------- + */ + +#pragma once +#include +#include + +namespace board { + + u32 GetVoltage(HocClkVoltage voltage); + +}