From fa5d740f33ae0da56fc434ecdc6c852413ede3f9 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:59:34 +0200 Subject: [PATCH] Added adm1032 device --- CMakeLists.txt | 2 ++ src/hw/adm.cpp | 26 ++++++++++++++++++++++++++ src/hw/adm.hpp | 16 ++++++++++++++++ src/hw/machine.hpp | 7 ++++++- src/hw/smbus.cpp | 1 + src/hw/smc.cpp | 7 +++++++ src/hw/smc.hpp | 7 ++++--- src/logger.hpp | 2 ++ 8 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/hw/adm.cpp create mode 100644 src/hw/adm.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9102405..89dd70b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ set(HEADERS "${NXBX_ROOT_DIR}/src/xbe.hpp" "${NXBX_ROOT_DIR}/src/xiso.hpp" "${NXBX_ROOT_DIR}/src/xpartition.hpp" + "${NXBX_ROOT_DIR}/src/hw/adm.hpp" "${NXBX_ROOT_DIR}/src/hw/cmos.hpp" "${NXBX_ROOT_DIR}/src/hw/cpu.hpp" "${NXBX_ROOT_DIR}/src/hw/eeprom.hpp" @@ -96,6 +97,7 @@ set(SOURCES "${NXBX_ROOT_DIR}/src/xbe.cpp" "${NXBX_ROOT_DIR}/src/xiso.cpp" "${NXBX_ROOT_DIR}/src/xpartition.cpp" + "${NXBX_ROOT_DIR}/src/hw/adm.cpp" "${NXBX_ROOT_DIR}/src/hw/cmos.cpp" "${NXBX_ROOT_DIR}/src/hw/cpu.cpp" "${NXBX_ROOT_DIR}/src/hw/eeprom.cpp" diff --git a/src/hw/adm.cpp b/src/hw/adm.cpp new file mode 100644 index 0000000..7b8e15d --- /dev/null +++ b/src/hw/adm.cpp @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: 2024 ergo720 + +#include "machine.hpp" + +#define MODULE_NAME adm + + +std::optional +adm::read_byte(uint8_t command) +{ + switch (command) + { + case 0: + return 40; // motherboard temperature + + case 1: + return 45; // cpu temperature + + default: + nxbx_fatal("Unhandled read with command 0x%" PRIX8, command); + } + + return 0; +} diff --git a/src/hw/adm.hpp b/src/hw/adm.hpp new file mode 100644 index 0000000..8524d1f --- /dev/null +++ b/src/hw/adm.hpp @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: 2024 ergo720 + +#pragma once + +#include "smbus.hpp" + + +class adm : public smbus_device { +public: + adm(log_module module_name) : smbus_device(module_name) {} + void deinit() override {} + void reset() {} + std::optional read_byte(uint8_t command) override; +}; diff --git a/src/hw/machine.hpp b/src/hw/machine.hpp index 16fb9f9..c3125b2 100644 --- a/src/hw/machine.hpp +++ b/src/hw/machine.hpp @@ -13,6 +13,7 @@ #include "smbus.hpp" #include "eeprom.hpp" #include "smc.hpp" +#include "adm.hpp" #include "video/vga.hpp" #include "video/gpu/nv2a.hpp" @@ -23,7 +24,7 @@ concept is_cpu_t = std::is_same_v; class machine { public: machine() : m_cpu(this), m_pit(this), m_pic{ {this, 0, "MASTER PIC"}, {this, 1, "SLAVE PIC"} }, m_pci(this), m_cmos(this), m_nv2a(this), - m_vga(this), m_smbus(this), m_eeprom(log_module::eeprom), m_smc(log_module::smc) {} + m_vga(this), m_smbus(this), m_eeprom(log_module::eeprom), m_smc(this, log_module::smc), m_adm(log_module::adm) {} bool init(const init_info_t &init_info) { if (!m_cpu.init(init_info)) { @@ -106,6 +107,9 @@ class machine { else if constexpr (std::is_same_v) { return m_smc; } + else if constexpr (std::is_same_v) { + return m_adm; + } else if constexpr (std::is_same_v) { return m_nv2a; } @@ -188,4 +192,5 @@ class machine { smbus m_smbus; eeprom m_eeprom; smc m_smc; + adm m_adm; }; diff --git a/src/hw/smbus.cpp b/src/hw/smbus.cpp index 64c6f22..2e7d4f1 100644 --- a/src/hw/smbus.cpp +++ b/src/hw/smbus.cpp @@ -298,6 +298,7 @@ smbus::init() m_devs[0x54] = &m_machine->get(); // eeprom m_devs[0x10] = &m_machine->get(); // smc + m_devs[0x4C] = &m_machine->get(); // adm reset(); return true; } diff --git a/src/hw/smc.cpp b/src/hw/smc.cpp index 0e5576e..e7b18f9 100644 --- a/src/hw/smc.cpp +++ b/src/hw/smc.cpp @@ -14,6 +14,8 @@ #define SMC_FAN_SPEED 0x06 #define SMC_LED_OVERRIDE 0x07 #define SMC_LED_STATES 0x08 +#define SMC_CPU_TEMPERATURE 0x09 +#define SMC_MB_TEMPERATURE 0x0A #define SMC_WRITE_SCRATCH 0x0E #define SMC_READ_SCRATCH 0x0F #define SMC_READ_FAN_SPEED 0x10 @@ -51,6 +53,11 @@ smc::read_byte(uint8_t command) value = m_regs[command]; break; + case SMC_CPU_TEMPERATURE: + case SMC_MB_TEMPERATURE: + value = *m_machine->get().read_byte((command - SMC_CPU_TEMPERATURE) ^ 1); + break; + case SMC_READ_SCRATCH: value = m_regs[SMC_WRITE_SCRATCH]; break; diff --git a/src/hw/smc.hpp b/src/hw/smc.hpp index 1078631..e8311b7 100644 --- a/src/hw/smc.hpp +++ b/src/hw/smc.hpp @@ -6,7 +6,6 @@ #include "smbus.hpp" #include -#include // NOTE: same state values as used internally by the smc, to avoid conversions @@ -16,9 +15,11 @@ enum class tray_state : uint8_t { media_detect = 0x60, }; +class machine; + class smc : public smbus_device { public: - smc(log_module module_name) : smbus_device(module_name) {} + smc(machine *machine, log_module module_name) : smbus_device(module_name), m_machine(machine) {} bool init(); void deinit() override {} void reset(); @@ -27,7 +28,7 @@ class smc : public smbus_device { void update_tray_state(tray_state state, bool do_int); private: - //machine *const m_machine; + machine *const m_machine; static constexpr uint8_t m_version[3] = { 'P', '0', '5' }; uint8_t m_version_idx; uint8_t m_regs[34]; diff --git a/src/logger.hpp b/src/logger.hpp index 7984d54..9d23ce0 100644 --- a/src/logger.hpp +++ b/src/logger.hpp @@ -56,6 +56,7 @@ enum class log_module : int32_t { smbus, eeprom, smc, + adm, max, }; @@ -84,6 +85,7 @@ inline constexpr std::array module_to_str = { "SMBUS -> ", "EEPROM -> ", "SMC -> ", + "ADM -> ", }; static_assert(module_to_str.size() == (uint32_t)(log_module::max));