diff --git a/Source/hoc-clk/bpmpfw/out/bpmpfw.bin b/Source/hoc-clk/bpmpfw/out/bpmpfw.bin
index 64a8fc50..bb044fde 100644
Binary files a/Source/hoc-clk/bpmpfw/out/bpmpfw.bin and b/Source/hoc-clk/bpmpfw/out/bpmpfw.bin differ
diff --git a/Source/hoc-clk/bpmpfw/source/defs.hpp b/Source/hoc-clk/bpmpfw/source/defs.hpp
new file mode 100644
index 00000000..80bc15cd
--- /dev/null
+++ b/Source/hoc-clk/bpmpfw/source/defs.hpp
@@ -0,0 +1,26 @@
+/*
+ * 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 .
+ *
+ */
+
+#pragma once
+#include
+
+using u8 = std::uint8_t;
+using u16 = std::uint16_t;
+using u32 = std::uint32_t;
+using s8 = std::int8_t;
+using s16 = std::int16_t;
+using s32 = std::int32_t;
diff --git a/Source/hoc-clk/bpmpfw/source/main.cpp b/Source/hoc-clk/bpmpfw/source/main.cpp
index d329e669..72a25d0f 100644
--- a/Source/hoc-clk/bpmpfw/source/main.cpp
+++ b/Source/hoc-clk/bpmpfw/source/main.cpp
@@ -20,6 +20,7 @@
#include "libc_platform.hpp"
#include "regs.hpp"
+#include "sensors.hpp"
#include
@@ -34,7 +35,7 @@ namespace {
extern "C" void main() {
InitializeLibc();
- printf("[hoc-bpmpfw] Starting bpmpfw\n");
+ printf("[hoc-bpmpfw]: Starting bpmpfw\n");
HocClkBpmpSharedInfo &info = SharedInfo();
memset(&info, 0, sizeof(info));
@@ -42,6 +43,14 @@ extern "C" void main() {
info.magic = HOCCLK_BPMP_MAGIC; // written last
for (;;) {
+ const u32 temp1 = MMIO32(SocthermBase + SocthermSensorTemp1);
+ const u32 temp2 = MMIO32(SocthermBase + SocthermSensorTemp2);
+ info.tempCpu = TranslateSocthermTemp(static_cast(temp1 >> 16));
+ info.tempGpu = TranslateSocthermTemp(static_cast(temp1));
+ info.tempMem = TranslateSocthermTemp(static_cast(temp2 >> 16));
+ info.tempPllx = TranslateSocthermTemp(static_cast(temp2));
+
+ usleep(250000); // 250ms
}
}
diff --git a/Source/hoc-clk/bpmpfw/source/regs.hpp b/Source/hoc-clk/bpmpfw/source/regs.hpp
index a39389b2..24adffa2 100644
--- a/Source/hoc-clk/bpmpfw/source/regs.hpp
+++ b/Source/hoc-clk/bpmpfw/source/regs.hpp
@@ -16,11 +16,7 @@
*/
#pragma once
-#include
-
-using u8 = std::uint8_t;
-using u16 = std::uint16_t;
-using u32 = std::uint32_t;
+#include "defs.hpp"
#define MMIO32(addr) (*reinterpret_cast(addr))
@@ -39,6 +35,15 @@ constexpr u32 HaltUsec = (0u << 24);
MMIO32(FlowCtlrBase + FlowCtlrHaltCopEvents) = HaltModeWaitEvent | HaltUsec | (usec & 0xFFFFFFu);
}
+constexpr u32 TmrBase = 0x60005000;
+constexpr u32 TimerUsCntr1Us = 0x10;
+
+[[maybe_unused]] inline void usleep(u32 us) {
+ const u32 start = MMIO32(TmrBase + TimerUsCntr1Us);
+ while ((MMIO32(TmrBase + TimerUsCntr1Us) - start) <= us)
+ ;
+}
+
constexpr u32 UartBBase = 0x70006040;
constexpr u32 UartThr = 0x00;
constexpr u32 UartLsr = 0x14;
diff --git a/Source/hoc-clk/bpmpfw/source/sensors.hpp b/Source/hoc-clk/bpmpfw/source/sensors.hpp
new file mode 100644
index 00000000..64aad219
--- /dev/null
+++ b/Source/hoc-clk/bpmpfw/source/sensors.hpp
@@ -0,0 +1,34 @@
+/*
+ * 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 .
+ *
+ */
+
+#pragma once
+#include "regs.hpp"
+
+constexpr u32 SocthermBase = 0x700E2000;
+constexpr u32 SocthermSensorTemp1 = 0x1C8;
+constexpr u32 SocthermSensorTemp2 = 0x1CC;
+
+inline s32 TranslateSocthermTemp(u16 val) {
+ s32 t = ((val >> 8) & 0xFF) * 1000;
+ if (val & (1u << 7)) {
+ t += 500;
+ }
+ if (val & (1u << 0)) {
+ t = -t;
+ }
+ return t;
+}
diff --git a/Source/hoc-clk/common/include/hocclk/bpmp.h b/Source/hoc-clk/common/include/hocclk/bpmp.h
index b5cb8f4b..d2b5f862 100644
--- a/Source/hoc-clk/common/include/hocclk/bpmp.h
+++ b/Source/hoc-clk/common/include/hocclk/bpmp.h
@@ -27,9 +27,13 @@
* Any 64 bit data type is not permitted.
*/
typedef struct {
- u32 magic; // should be HOCCLK_BPMP_MAGIC once bpmpfw is running
- u32 status; // Reserved for error codes and such
- u32 reserved[6];
+ u32 magic; // should be HOCCLK_BPMP_MAGIC once bpmpfw is running
+ u32 status; // Reserved for error codes and such
+ s32 tempCpu;
+ s32 tempGpu;
+ s32 tempMem;
+ s32 tempPllx;
+ u32 reserved[2];
} HocClkBpmpSharedInfo;
static_assert(sizeof(HocClkBpmpSharedInfo) == 0x20);
diff --git a/Source/hoc-clk/sysmodule/src/bpmp/bpmp.cpp b/Source/hoc-clk/sysmodule/src/bpmp/bpmp.cpp
index 37b673a5..35a2a175 100644
--- a/Source/hoc-clk/sysmodule/src/bpmp/bpmp.cpp
+++ b/Source/hoc-clk/sysmodule/src/bpmp/bpmp.cpp
@@ -127,7 +127,7 @@ namespace bpmp {
}
s_isAwake = true;
- } else if (state == PscPmState_ReadySleep) {
+ } else if (state == PscPmState_ReadySleep || state == PscPmState_ReadyShutdown) {
RestoreStockState();
s_isAwake = false;
}
diff --git a/Source/hoc-clk/sysmodule/src/tsensor/soctherm.cpp b/Source/hoc-clk/sysmodule/src/tsensor/soctherm.cpp
index 6a053f46..af56a833 100644
--- a/Source/hoc-clk/sysmodule/src/tsensor/soctherm.cpp
+++ b/Source/hoc-clk/sysmodule/src/tsensor/soctherm.cpp
@@ -24,6 +24,7 @@
#include
#include "../board/board.hpp"
+#include "../bpmp/bpmp.hpp"
#include "../file/file_utils.hpp"
#include "../mapping/mem_map.hpp"
#include "soctherm.hpp"
@@ -413,15 +414,6 @@ namespace tsensor {
bool isMariko;
} // namespace
- bool IsDisabledThroughSleep() {
- return (ReadReg(carVa, CLK_RST_CONTROLLER_RST_DEVICES) & SWR_SOC_THERM_RST) ||
- !(ReadReg(carVa, CLK_RST_CONTROLLER_CLK_OUT_ENB) & CLK_ENB_SOC_THERM);
- }
-
- bool IsSensorEnabled() {
- return ReadReg(socthermVa, TSENSOR_TSENSOR_CLKEN);
- }
-
void EnableSensor(const TSensor *sensor, u32 sensorIdx) {
u32 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT;
WriteReg(socthermVa, sensor->base + SENSOR_CONFIG0, val);
@@ -434,21 +426,6 @@ namespace tsensor {
WriteReg(socthermVa, sensor->base + SENSOR_CONFIG2, calib[sensorIdx]);
}
- s32 TranslateTemp(u16 val) {
- s32 t;
-
- t = ((val & READBACK_VALUE_MASK) >> READBACK_VALUE_SHIFT) * 1000;
- if (val & READBACK_ADD_HALF) {
- t += 500;
- }
-
- if (val & READBACK_NEGATE) {
- t *= -1;
- }
-
- return t;
- }
-
void StartSensors() {
u32 pdiv, hotspot;
@@ -474,23 +451,15 @@ namespace tsensor {
}
void ReadTSensors(TSensorTemps &temps) {
- if (IsDisabledThroughSleep()) {
+ const HocClkBpmpSharedInfo *bpmpInfo = bpmp::GetSharedInfo();
+ if (bpmpInfo->magic != HOCCLK_BPMP_MAGIC) {
return;
}
- if (!IsSensorEnabled()) {
- StartSensors();
- }
-
- temps.cpu = TranslateTemp(ReadReg(socthermVa, SENSOR_TEMP1) >> 16);
- temps.gpu = TranslateTemp(ReadReg(socthermVa, SENSOR_TEMP1) & SENSOR_TEMP1_GPU_TEMP_MASK);
- temps.pllx = TranslateTemp(ReadReg(socthermVa, SENSOR_TEMP2) & SENSOR_TEMP2_PLLX_TEMP_MASK);
-
- if (board::GetSocType() == HocClkSocType_Erista) {
- temps.mem = TranslateTemp(ReadReg(socthermVa, SENSOR_TEMP2) >> 16);
- } else {
- temps.mem = -1;
- }
+ temps.cpu = bpmpInfo->tempCpu;
+ temps.gpu = bpmpInfo->tempGpu;
+ temps.pllx = bpmpInfo->tempPllx;
+ temps.mem = (board::GetSocType() == HocClkSocType_Erista) ? bpmpInfo->tempMem : bpmpInfo->tempPllx;
}
void InitializeSoctherm() {