move soctherm poll to bpmp
This commit is contained in:
1 parent
ba75b02c52
commit
49244b3baf
8 files changed
+95
-48
No files matched your search
Binary file not shown.
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "libc_platform.hpp"
|
#include "libc_platform.hpp"
|
||||||
#include "regs.hpp"
|
#include "regs.hpp"
|
||||||
|
#include "sensors.hpp"
|
||||||
|
|
||||||
#include <hocclk/bpmp.h>
|
#include <hocclk/bpmp.h>
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ namespace {
|
|||||||
extern "C" void main() {
|
extern "C" void main() {
|
||||||
InitializeLibc();
|
InitializeLibc();
|
||||||
|
|
||||||
printf("[hoc-bpmpfw] Starting bpmpfw\n");
|
printf("[hoc-bpmpfw]: Starting bpmpfw\n");
|
||||||
|
|
||||||
HocClkBpmpSharedInfo &info = SharedInfo();
|
HocClkBpmpSharedInfo &info = SharedInfo();
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
@@ -42,6 +43,14 @@ extern "C" void main() {
|
|||||||
info.magic = HOCCLK_BPMP_MAGIC; // written last
|
info.magic = HOCCLK_BPMP_MAGIC; // written last
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
const u32 temp1 = MMIO32(SocthermBase + SocthermSensorTemp1);
|
||||||
|
const u32 temp2 = MMIO32(SocthermBase + SocthermSensorTemp2);
|
||||||
|
|
||||||
|
info.tempCpu = TranslateSocthermTemp(static_cast<u16>(temp1 >> 16));
|
||||||
|
info.tempGpu = TranslateSocthermTemp(static_cast<u16>(temp1));
|
||||||
|
info.tempMem = TranslateSocthermTemp(static_cast<u16>(temp2 >> 16));
|
||||||
|
info.tempPllx = TranslateSocthermTemp(static_cast<u16>(temp2));
|
||||||
|
|
||||||
|
usleep(250000); // 250ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,11 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include "defs.hpp"
|
||||||
|
|
||||||
using u8 = std::uint8_t;
|
|
||||||
using u16 = std::uint16_t;
|
|
||||||
using u32 = std::uint32_t;
|
|
||||||
|
|
||||||
#define MMIO32(addr) (*reinterpret_cast<volatile u32 *>(addr))
|
#define MMIO32(addr) (*reinterpret_cast<volatile u32 *>(addr))
|
||||||
|
|
||||||
@@ -39,6 +35,15 @@ constexpr u32 HaltUsec = (0u << 24);
|
|||||||
MMIO32(FlowCtlrBase + FlowCtlrHaltCopEvents) = HaltModeWaitEvent | HaltUsec | (usec & 0xFFFFFFu);
|
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 UartBBase = 0x70006040;
|
||||||
constexpr u32 UartThr = 0x00;
|
constexpr u32 UartThr = 0x00;
|
||||||
constexpr u32 UartLsr = 0x14;
|
constexpr u32 UartLsr = 0x14;
|
||||||
|
|||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -27,9 +27,13 @@
|
|||||||
* Any 64 bit data type is not permitted.
|
* Any 64 bit data type is not permitted.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 magic; // should be HOCCLK_BPMP_MAGIC once bpmpfw is running
|
u32 magic; // should be HOCCLK_BPMP_MAGIC once bpmpfw is running
|
||||||
u32 status; // Reserved for error codes and such
|
u32 status; // Reserved for error codes and such
|
||||||
u32 reserved[6];
|
s32 tempCpu;
|
||||||
|
s32 tempGpu;
|
||||||
|
s32 tempMem;
|
||||||
|
s32 tempPllx;
|
||||||
|
u32 reserved[2];
|
||||||
} HocClkBpmpSharedInfo;
|
} HocClkBpmpSharedInfo;
|
||||||
|
|
||||||
static_assert(sizeof(HocClkBpmpSharedInfo) == 0x20);
|
static_assert(sizeof(HocClkBpmpSharedInfo) == 0x20);
|
||||||
@@ -127,7 +127,7 @@ namespace bpmp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s_isAwake = true;
|
s_isAwake = true;
|
||||||
} else if (state == PscPmState_ReadySleep) {
|
} else if (state == PscPmState_ReadySleep || state == PscPmState_ReadyShutdown) {
|
||||||
RestoreStockState();
|
RestoreStockState();
|
||||||
s_isAwake = false;
|
s_isAwake = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#include "../board/board.hpp"
|
#include "../board/board.hpp"
|
||||||
|
#include "../bpmp/bpmp.hpp"
|
||||||
#include "../file/file_utils.hpp"
|
#include "../file/file_utils.hpp"
|
||||||
#include "../mapping/mem_map.hpp"
|
#include "../mapping/mem_map.hpp"
|
||||||
#include "soctherm.hpp"
|
#include "soctherm.hpp"
|
||||||
@@ -413,15 +414,6 @@ namespace tsensor {
|
|||||||
bool isMariko;
|
bool isMariko;
|
||||||
} // namespace
|
} // 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) {
|
void EnableSensor(const TSensor *sensor, u32 sensorIdx) {
|
||||||
u32 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT;
|
u32 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT;
|
||||||
WriteReg(socthermVa, sensor->base + SENSOR_CONFIG0, val);
|
WriteReg(socthermVa, sensor->base + SENSOR_CONFIG0, val);
|
||||||
@@ -434,21 +426,6 @@ namespace tsensor {
|
|||||||
WriteReg(socthermVa, sensor->base + SENSOR_CONFIG2, calib[sensorIdx]);
|
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() {
|
void StartSensors() {
|
||||||
u32 pdiv, hotspot;
|
u32 pdiv, hotspot;
|
||||||
|
|
||||||
@@ -474,23 +451,15 @@ namespace tsensor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ReadTSensors(TSensorTemps &temps) {
|
void ReadTSensors(TSensorTemps &temps) {
|
||||||
if (IsDisabledThroughSleep()) {
|
const HocClkBpmpSharedInfo *bpmpInfo = bpmp::GetSharedInfo();
|
||||||
|
if (bpmpInfo->magic != HOCCLK_BPMP_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsSensorEnabled()) {
|
temps.cpu = bpmpInfo->tempCpu;
|
||||||
StartSensors();
|
temps.gpu = bpmpInfo->tempGpu;
|
||||||
}
|
temps.pllx = bpmpInfo->tempPllx;
|
||||||
|
temps.mem = (board::GetSocType() == HocClkSocType_Erista) ? bpmpInfo->tempMem : bpmpInfo->tempPllx;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeSoctherm() {
|
void InitializeSoctherm() {
|
||||||
|
|||||||
Reference in new issue
Block a user