diff --git a/Source/hoc-clk/bpmpfw/source/aotag.hpp b/Source/hoc-clk/bpmpfw/source/aotag.hpp new file mode 100644 index 00000000..1e159139 --- /dev/null +++ b/Source/hoc-clk/bpmpfw/source/aotag.hpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014 - 2017, NVIDIA CORPORATION. All rights reserved. + * 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" + +#include + +namespace aotag { + + constexpr u32 PmcBase = 0x7000E400; + constexpr u32 PmcTsensorStatus1 = 0x4AC; + + constexpr u32 Status1ValidBit = (1u << 31); + constexpr u32 Status1AbsShift = 8; + constexpr u32 Status1AbsMask = 0xFF; + constexpr u32 Status1FracBit = (1u << 7); + constexpr u32 Status1SignBit = (1u << 0); + + constexpr s32 InvalidSentinel = -125; + + inline void Update(HocClkBpmpSharedInfo &info) { + const u32 regval = MMIO32(PmcBase + PmcTsensorStatus1); + + if (!(regval & Status1ValidBit)) { + info.tempAO = InvalidSentinel; + return; + } + + const u32 abs = (regval >> Status1AbsShift) & Status1AbsMask; + const bool frac = (regval & Status1FracBit) != 0; + const bool negative = (regval & Status1SignBit) != 0; + + s32 temp = static_cast(abs) * 1000 + (frac ? 500 : 0); + if (negative) { + temp = -temp; + } + + info.tempAO = temp; + } + +} // namespace aotag diff --git a/Source/hoc-clk/bpmpfw/source/main.cpp b/Source/hoc-clk/bpmpfw/source/main.cpp index f4203f96..5dc4023b 100644 --- a/Source/hoc-clk/bpmpfw/source/main.cpp +++ b/Source/hoc-clk/bpmpfw/source/main.cpp @@ -19,6 +19,7 @@ #include #include "actmon.hpp" +#include "aotag.hpp" #include "bpmp_mmu.hpp" #include "freq.hpp" #include "libc_platform.hpp" @@ -53,6 +54,7 @@ void MainLoop(HocClkBpmpSharedInfo &info) { freq::Update(info); actmon::Update(info); + aotag::Update(info); msleep(250); } diff --git a/Source/hoc-clk/common/include/hocclk/bpmp.h b/Source/hoc-clk/common/include/hocclk/bpmp.h index c064f835..30c82ccd 100644 --- a/Source/hoc-clk/common/include/hocclk/bpmp.h +++ b/Source/hoc-clk/common/include/hocclk/bpmp.h @@ -41,7 +41,7 @@ typedef struct { u32 emcBwCpu; u32 emcBwGpu; u32 exitRequested; // Request BPMP-FW to shutdown for sleep mode - u32 reserved[1]; + s32 tempAO; } HocClkBpmpSharedInfo; static_assert(sizeof(HocClkBpmpSharedInfo) == 0x3C); diff --git a/Source/hoc-clk/sysmodule/src/tsensor/aotag.cpp b/Source/hoc-clk/sysmodule/src/tsensor/aotag.cpp index fbf03091..87aa66b2 100644 --- a/Source/hoc-clk/sysmodule/src/tsensor/aotag.cpp +++ b/Source/hoc-clk/sysmodule/src/tsensor/aotag.cpp @@ -22,6 +22,7 @@ #include +#include "../bpmp/bpmp.hpp" #include "../file/file_utils.hpp" #include "../mapping/mem_map.hpp" #include "aotag.hpp" @@ -214,24 +215,7 @@ namespace tsensor { return -126; } - u32 regval = 0, abs = 0, fraction = 0, valid = 0, sign = 0; - s32 temp = 0; - regval = ReadPmcReg(PMC_TSENSOR_STATUS1); - valid = REG_GET(regval, STATUS1_TEMP_VALID); - - if (!valid) { - return -125; - } - - abs = REG_GET(regval, STATUS1_TEMP_ABS); - fraction = REG_GET(regval, STATUS1_TEMP_FRAC); - sign = REG_GET(regval, STATUS1_TEMP_SIGN); - temp = (abs * 1000) + (fraction * 500); - if (sign) { - temp = (-1) * (temp); - } - - return temp; + return bpmp::GetSharedInfo()->tempAO; } bool IsInitialized() {