Skip to content

Commit

Permalink
Added adm1032 device
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo720 committed Aug 21, 2024
1 parent 1689004 commit fa5d740
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions src/hw/adm.cpp
Original file line number Diff line number Diff line change
@@ -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<uint16_t>
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;
}
16 changes: 16 additions & 0 deletions src/hw/adm.hpp
Original file line number Diff line number Diff line change
@@ -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<uint16_t> read_byte(uint8_t command) override;
};
7 changes: 6 additions & 1 deletion src/hw/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -23,7 +24,7 @@ concept is_cpu_t = std::is_same_v<T, cpu_t *>;
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)) {
Expand Down Expand Up @@ -106,6 +107,9 @@ class machine {
else if constexpr (std::is_same_v<T, smc>) {
return m_smc;
}
else if constexpr (std::is_same_v<T, adm>) {
return m_adm;
}
else if constexpr (std::is_same_v<T, nv2a>) {
return m_nv2a;
}
Expand Down Expand Up @@ -188,4 +192,5 @@ class machine {
smbus m_smbus;
eeprom m_eeprom;
smc m_smc;
adm m_adm;
};
1 change: 1 addition & 0 deletions src/hw/smbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ smbus::init()

m_devs[0x54] = &m_machine->get<eeprom>(); // eeprom
m_devs[0x10] = &m_machine->get<smc>(); // smc
m_devs[0x4C] = &m_machine->get<adm>(); // adm
reset();
return true;
}
7 changes: 7 additions & 0 deletions src/hw/smc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<adm>().read_byte((command - SMC_CPU_TEMPERATURE) ^ 1);
break;

case SMC_READ_SCRATCH:
value = m_regs[SMC_WRITE_SCRATCH];
break;
Expand Down
7 changes: 4 additions & 3 deletions src/hw/smc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "smbus.hpp"
#include <atomic>
#include <cstdint>


// NOTE: same state values as used internally by the smc, to avoid conversions
Expand All @@ -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();
Expand All @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions src/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum class log_module : int32_t {
smbus,
eeprom,
smc,
adm,
max,
};

Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit fa5d740

Please sign in to comment.