From e1b5d81d658f7e8fad760274e05c8a2ea5ffa503 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 31 Oct 2020 00:47:45 -0700 Subject: [PATCH] wec: implement wec driver components for boot sysmodule --- .../wec/wec_wake_event.board.nintendo_nx.hpp | 2 + .../libstratosphere/source/wec/wec_api.cpp | 116 ++++++++++++++++ .../include/vapours/dd/dd_io_mapping.hpp | 1 + .../libvapours/source/dd/dd_io_mapping.cpp | 65 ++++++++- stratosphere/boot/source/boot_main.cpp | 3 +- stratosphere/boot/source/boot_pmc_wrapper.cpp | 2 - .../boot/source/boot_wake_control_configs.inc | 35 ----- .../boot_wake_pin_configuration_calcio.inc | 69 ---------- .../boot_wake_pin_configuration_copper.inc | 69 ---------- .../boot_wake_pin_configuration_hoag.inc | 70 ---------- .../boot_wake_pin_configuration_icosa.inc | 69 ---------- .../boot_wake_pin_configuration_iowa.inc | 69 ---------- stratosphere/boot/source/boot_wake_pins.cpp | 130 ------------------ stratosphere/boot/source/boot_wake_pins.hpp | 23 ---- 14 files changed, 183 insertions(+), 540 deletions(-) create mode 100644 libraries/libstratosphere/source/wec/wec_api.cpp delete mode 100644 stratosphere/boot/source/boot_wake_control_configs.inc delete mode 100644 stratosphere/boot/source/boot_wake_pin_configuration_calcio.inc delete mode 100644 stratosphere/boot/source/boot_wake_pin_configuration_copper.inc delete mode 100644 stratosphere/boot/source/boot_wake_pin_configuration_hoag.inc delete mode 100644 stratosphere/boot/source/boot_wake_pin_configuration_icosa.inc delete mode 100644 stratosphere/boot/source/boot_wake_pin_configuration_iowa.inc delete mode 100644 stratosphere/boot/source/boot_wake_pins.cpp delete mode 100644 stratosphere/boot/source/boot_wake_pins.hpp diff --git a/libraries/libstratosphere/include/stratosphere/wec/wec_wake_event.board.nintendo_nx.hpp b/libraries/libstratosphere/include/stratosphere/wec/wec_wake_event.board.nintendo_nx.hpp index afee37412..80012f9c1 100644 --- a/libraries/libstratosphere/include/stratosphere/wec/wec_wake_event.board.nintendo_nx.hpp +++ b/libraries/libstratosphere/include/stratosphere/wec/wec_wake_event.board.nintendo_nx.hpp @@ -79,6 +79,8 @@ namespace ams::wec { WakeEvent_ModemWakeAp = 0x3D, WakeEvent_TouchInt = 0x3E, WakeEvent_MotionInt = 0x3F, + + WakeEvent_Count = 0x40, }; constexpr inline WakeEvent WakeEvent_None = static_cast(-1); diff --git a/libraries/libstratosphere/source/wec/wec_api.cpp b/libraries/libstratosphere/source/wec/wec_api.cpp new file mode 100644 index 000000000..3d65b2644 --- /dev/null +++ b/libraries/libstratosphere/source/wec/wec_api.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 . + */ +#include + +/* TODO: How much of this should be namespaced under BOARD_NINTENDO_NX? */ + +namespace ams::wec { + + namespace { + + constexpr inline dd::PhysicalAddress ApbdevPmc = 0x7000E400; + + constinit bool g_initialized = false; + + void UpdateControlBit(dd::PhysicalAddress phys_addr, u32 mask, bool flag) { + dd::ReadModifyWriteIoRegister(phys_addr, flag ? ~0u : 0u, mask); + dd::ReadIoRegister(phys_addr); + } + + void Initialize(bool blink) { + /* Initialize WAKE_DEBOUNCE_EN. */ + dd::WriteIoRegister(ApbdevPmc + APBDEV_PMC_WAKE_DEBOUNCE_EN, 0); + dd::ReadIoRegister(ApbdevPmc + APBDEV_PMC_WAKE_DEBOUNCE_EN); + + /* Initialize BLINK_TIMER. */ + dd::WriteIoRegister(ApbdevPmc + APBDEV_PMC_BLINK_TIMER, 0x08008800); + dd::ReadIoRegister(ApbdevPmc + APBDEV_PMC_BLINK_TIMER); + + /* Set control configs. */ + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0800, true); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0400, false); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0200, true); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0100, false); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0040, false); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0020, false); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL2, 0x4000, true); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL2, 0x0200, false); + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL2, 0x0001, true); + + /* Update blink bit in APBDEV_PMC_CNTRL. */ + UpdateControlBit(ApbdevPmc + APBDEV_PMC_CNTRL, 0x0080, blink); + + /* Update blink bit in APBDEV_PMC_DPD_PADS_ORIDE. */ + UpdateControlBit(ApbdevPmc + APBDEV_PMC_DPD_PADS_ORIDE, 0x100000, blink); + } + + } + + /* 0C, 160 */ + /* 10, 164 */ + /* DC, 170 */ + + void Initialize() { + /* Set initial wake configuration. */ + if (!g_initialized) { + Initialize(false); + g_initialized = true; + } + } + + void ClearWakeEvents() { + /* TODO */ + AMS_ABORT(); + } + + void WecRestoreForExitSuspend() { + /* TODO */ + AMS_ABORT(); + } + + void SetWakeEventLevel(wec::WakeEvent event, wec::WakeEventLevel level) { + if (g_initialized && event < wec::WakeEvent_Count) { + /* Determine the event index. */ + const bool which = static_cast(event) < BITSIZEOF(u32); + const u32 index = static_cast(event) & (BITSIZEOF(u32) - 1); + + /* Get the level and auto_mask offsets. */ + u32 level_ofs = which ? APBDEV_PMC_WAKE_LVL : APBDEV_PMC_WAKE2_LVL; + u32 auto_mask_ofs = which ? APBDEV_PMC_AUTO_WAKE_LVL_MASK : APBDEV_PMC_AUTO_WAKE2_LVL_MASK; + + /* If the level isn't auto, swap the offsets. */ + if (level != wec::WakeEventLevel_Auto) { + std::swap(level_ofs, auto_mask_ofs); + } + + /* Clear the bit in the level register. */ + UpdateControlBit(ApbdevPmc + level_ofs, (1u << index), false); + + /* Set or clear the bit in the auto mask register. */ + UpdateControlBit(ApbdevPmc + level_ofs, (1u << index), level != wec::WakeEventLevel_Low); + } + } + + void SetWakeEventEnabled(wec::WakeEvent event, bool en) { + if (g_initialized && event < wec::WakeEvent_Count) { + /* Set or clear the relevant enabled bit. */ + const u32 offset = static_cast(event) < BITSIZEOF(u32) ? APBDEV_PMC_WAKE_MASK : APBDEV_PMC_WAKE2_MASK; + const u32 index = static_cast(event) & (BITSIZEOF(u32) - 1); + UpdateControlBit(ApbdevPmc + offset, (1u << index), en); + } + } + +} diff --git a/libraries/libvapours/include/vapours/dd/dd_io_mapping.hpp b/libraries/libvapours/include/vapours/dd/dd_io_mapping.hpp index f82552bb0..4a3303774 100644 --- a/libraries/libvapours/include/vapours/dd/dd_io_mapping.hpp +++ b/libraries/libvapours/include/vapours/dd/dd_io_mapping.hpp @@ -22,5 +22,6 @@ namespace ams::dd { u32 ReadIoRegister(dd::PhysicalAddress phys_addr); void WriteIoRegister(dd::PhysicalAddress phys_addr, u32 value); + u32 ReadModifyWriteIoRegister(PhysicalAddress phys_addr, u32 value, u32 mask); } diff --git a/libraries/libvapours/source/dd/dd_io_mapping.cpp b/libraries/libvapours/source/dd/dd_io_mapping.cpp index 91358726c..1bbdeb8c0 100644 --- a/libraries/libvapours/source/dd/dd_io_mapping.cpp +++ b/libraries/libvapours/source/dd/dd_io_mapping.cpp @@ -70,13 +70,55 @@ namespace ams::dd { #endif } + namespace { + + #if defined(ATMOSPHERE_IS_STRATOSPHERE) + + #if defined(ATMOSPHERE_BOARD_NINTENDO_NX) + + constexpr dd::PhysicalAddress PmcPhysStart = 0x7000E400; + constexpr dd::PhysicalAddress PmcPhysLast = 0x7000EFFF; + + constexpr bool IsValidPmcPhysicalAddress(dd::PhysicalAddress phys_addr) { + return util::IsAligned(phys_addr, alignof(u32)) && PmcPhysStart <= phys_addr && phys_addr <= PmcPhysLast; + } + + u32 ReadWritePmcRegisterImpl(dd::PhysicalAddress phys_addr, u32 value, u32 mask) { + u32 out_value; + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value))); + return out_value; + } + + bool TryReadModifyWritePmcRegister(u32 *out, dd::PhysicalAddress phys_addr, u32 value, u32 mask) { + if (IsValidPmcPhysicalAddress(phys_addr)) { + *out = ReadWritePmcRegisterImpl(phys_addr, value, mask); + return true; + } else { + return false; + } + } + + #else + + bool TryReadModifyWritePmcRegister(u32 *out, dd::PhysicalAddress phys_addr, u32 value, u32 mask) { + AMS_UNUSED(out, phys_addr, value, mask); + return false; + } + + #endif + + #endif + } + u32 ReadIoRegister(dd::PhysicalAddress phys_addr) { #if defined(ATMOSPHERE_IS_EXOSPHERE) || defined(ATMOSPHERE_IS_MESOSPHERE) return reg::Read(dd::QueryIoMapping(phys_addr, sizeof(u32))); #elif defined(ATMOSPHERE_IS_STRATOSPHERE) u32 val; - R_ABORT_UNLESS(svc::ReadWriteRegister(std::addressof(val), phys_addr, 0, 0)); + if (!TryReadModifyWritePmcRegister(std::addressof(val), phys_addr, 0, 0)) { + R_ABORT_UNLESS(svc::ReadWriteRegister(std::addressof(val), phys_addr, 0, 0)); + } return val; #else @@ -90,7 +132,9 @@ namespace ams::dd { #elif defined(ATMOSPHERE_IS_STRATOSPHERE) u32 out_val; - R_ABORT_UNLESS(svc::ReadWriteRegister(std::addressof(out_val), phys_addr, 0xFFFFFFFF, value)); + if (!TryReadModifyWritePmcRegister(std::addressof(out_val), phys_addr, value, 0xFFFFFFFF)) { + R_ABORT_UNLESS(svc::ReadWriteRegister(std::addressof(out_val), phys_addr, 0xFFFFFFFF, value)); + } AMS_UNUSED(out_val); #else @@ -98,4 +142,21 @@ namespace ams::dd { #endif } + u32 ReadModifyWriteIoRegister(PhysicalAddress phys_addr, u32 value, u32 mask) { + #if defined(ATMOSPHERE_IS_EXOSPHERE) || defined(ATMOSPHERE_IS_MESOSPHERE) + AMS_UNUSED(phys_addr, value, mask); + AMS_ABORT("ReadModifyWriteIoRegister TODO under non-stratosphere"); + #elif defined(ATMOSPHERE_IS_STRATOSPHERE) + + u32 out_val; + if (!TryReadModifyWritePmcRegister(std::addressof(out_val), phys_addr, value, mask)) { + R_ABORT_UNLESS(svc::ReadWriteRegister(std::addressof(out_val), phys_addr, mask, value)); + } + return out_val; + + #else + #error "Unknown execution context for ams::dd::ReadModifyWriteIoRegister!" + #endif + } + } diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 2a5fd2c3f..0aeb3937d 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -22,7 +22,6 @@ #include "boot_fan_enable.hpp" #include "boot_repair_boot_images.hpp" #include "boot_splash_screen.hpp" -#include "boot_wake_pins.hpp" #include "pinmux/pinmux_initial_configuration.hpp" @@ -207,7 +206,7 @@ int main(int argc, char **argv) pinmux::SetInitialConfiguration(); /* Configure the PMC wake pin settings. */ - boot::SetInitialWakePinConfiguration(); + gpio::driver::SetInitialWakePinConfig(); /* Configure output clock. */ if (hw_type != spl::HardwareType::Copper && hw_type != spl::HardwareType::Calcio) { diff --git a/stratosphere/boot/source/boot_pmc_wrapper.cpp b/stratosphere/boot/source/boot_pmc_wrapper.cpp index 8feaedbe2..9b2685650 100644 --- a/stratosphere/boot/source/boot_pmc_wrapper.cpp +++ b/stratosphere/boot/source/boot_pmc_wrapper.cpp @@ -21,8 +21,6 @@ namespace ams::boot { namespace { /* Convenience definitions. */ - constexpr u32 SmcFunctionId_AtmosphereReadWriteRegister = 0xF0000002; - constexpr dd::PhysicalAddress PmcPhysStart = 0x7000E400; constexpr dd::PhysicalAddress PmcPhysLast = 0x7000EFFF; diff --git a/stratosphere/boot/source/boot_wake_control_configs.inc b/stratosphere/boot/source/boot_wake_control_configs.inc deleted file mode 100644 index 8bf77fa9e..000000000 --- a/stratosphere/boot/source/boot_wake_control_configs.inc +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -struct WakeControlConfig { - u32 reg_offset; - u32 mask_val; - bool flag_val; -}; - -constexpr WakeControlConfig WakeControlConfigs[] = { - {APBDEV_PMC_CNTRL, 0x0800, true}, - {APBDEV_PMC_CNTRL, 0x0400, false}, - {APBDEV_PMC_CNTRL, 0x0200, true}, - {APBDEV_PMC_CNTRL, 0x0100, false}, - {APBDEV_PMC_CNTRL, 0x0040, false}, - {APBDEV_PMC_CNTRL, 0x0020, false}, - {APBDEV_PMC_CNTRL2, 0x4000, true}, - {APBDEV_PMC_CNTRL2, 0x0200, false}, - {APBDEV_PMC_CNTRL2, 0x0001, true}, -}; - -constexpr size_t NumWakeControlConfigs = util::size(WakeControlConfigs); diff --git a/stratosphere/boot/source/boot_wake_pin_configuration_calcio.inc b/stratosphere/boot/source/boot_wake_pin_configuration_calcio.inc deleted file mode 100644 index abeb3e6c5..000000000 --- a/stratosphere/boot/source/boot_wake_pin_configuration_calcio.inc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -static constexpr WakePinConfig WakePinConfigsCalcio[] = { - {0x00, false, 0x02}, - {0x01, false, 0x02}, - {0x02, false, 0x02}, - {0x03, false, 0x02}, - {0x04, false, 0x02}, - {0x05, false, 0x02}, - {0x06, false, 0x02}, - {0x07, false, 0x02}, - {0x08, true, 0x01}, - {0x0A, false, 0x02}, - {0x0B, false, 0x02}, - {0x0C, false, 0x02}, - {0x0D, false, 0x02}, - {0x0E, true, 0x00}, - {0x0F, false, 0x02}, - {0x11, false, 0x02}, - {0x12, false, 0x02}, - {0x13, false, 0x02}, - {0x14, false, 0x02}, - {0x15, false, 0x02}, - {0x16, false, 0x02}, - {0x17, false, 0x02}, - {0x18, false, 0x02}, - {0x19, false, 0x02}, - {0x1A, false, 0x02}, - {0x1B, false, 0x00}, - {0x1C, false, 0x02}, - {0x21, false, 0x02}, - {0x22, false, 0x00}, - {0x23, true, 0x02}, - {0x24, false, 0x02}, - {0x2D, false, 0x02}, - {0x2E, false, 0x02}, - {0x2F, false, 0x02}, - {0x30, false, 0x02}, - {0x31, false, 0x02}, - {0x32, false, 0x02}, - {0x33, true, 0x00}, - {0x34, true, 0x00}, - {0x35, false, 0x02}, - {0x36, false, 0x02}, - {0x37, false, 0x02}, - {0x38, false, 0x02}, - {0x39, false, 0x00}, - {0x3A, false, 0x02}, - {0x3B, false, 0x02}, - {0x3D, false, 0x02}, - {0x3E, false, 0x02}, - {0x3F, false, 0x02}, -}; - -static constexpr size_t NumWakePinConfigsCalcio = util::size(WakePinConfigsCalcio); diff --git a/stratosphere/boot/source/boot_wake_pin_configuration_copper.inc b/stratosphere/boot/source/boot_wake_pin_configuration_copper.inc deleted file mode 100644 index 7105cb052..000000000 --- a/stratosphere/boot/source/boot_wake_pin_configuration_copper.inc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -static constexpr WakePinConfig WakePinConfigsCopper[] = { - {0x00, true, 0x02}, - {0x01, false, 0x02}, - {0x02, false, 0x02}, - {0x03, true, 0x02}, - {0x04, false, 0x02}, - {0x05, true, 0x02}, - {0x06, false, 0x02}, - {0x07, false, 0x02}, - {0x08, true, 0x02}, - {0x0A, false, 0x02}, - {0x0B, false, 0x02}, - {0x0C, false, 0x02}, - {0x0D, false, 0x02}, - {0x0E, true, 0x00}, - {0x0F, false, 0x02}, - {0x11, false, 0x02}, - {0x12, false, 0x02}, - {0x13, false, 0x02}, - {0x14, false, 0x02}, - {0x15, false, 0x02}, - {0x16, false, 0x02}, - {0x17, false, 0x02}, - {0x18, true, 0x02}, - {0x19, false, 0x02}, - {0x1A, false, 0x02}, - {0x1B, false, 0x00}, - {0x1C, false, 0x02}, - {0x21, false, 0x02}, - {0x22, false, 0x00}, - {0x23, false, 0x02}, - {0x24, false, 0x02}, - {0x2D, false, 0x02}, - {0x2E, false, 0x02}, - {0x2F, true, 0x02}, - {0x30, true, 0x02}, - {0x31, false, 0x02}, - {0x32, true, 0x02}, - {0x33, true, 0x00}, - {0x34, true, 0x00}, - {0x35, false, 0x02}, - {0x36, false, 0x02}, - {0x37, false, 0x02}, - {0x38, false, 0x02}, - {0x39, false, 0x02}, - {0x3A, false, 0x02}, - {0x3B, false, 0x02}, - {0x3D, false, 0x02}, - {0x3E, false, 0x02}, - {0x3F, false, 0x02}, -}; - -static constexpr size_t NumWakePinConfigsCopper = util::size(WakePinConfigsCopper); diff --git a/stratosphere/boot/source/boot_wake_pin_configuration_hoag.inc b/stratosphere/boot/source/boot_wake_pin_configuration_hoag.inc deleted file mode 100644 index c199fecd1..000000000 --- a/stratosphere/boot/source/boot_wake_pin_configuration_hoag.inc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -static constexpr WakePinConfig WakePinConfigsHoag[] = { - {0x00, false, 0x02}, - {0x01, false, 0x02}, - {0x02, false, 0x02}, - {0x03, false, 0x02}, - {0x04, true, 0x02}, - {0x05, true, 0x02}, - {0x06, false, 0x02}, - {0x07, true, 0x02}, - {0x08, true, 0x01}, - {0x0A, true, 0x02}, - {0x0B, false, 0x02}, - {0x0C, false, 0x02}, - {0x0D, false, 0x02}, - {0x0E, true, 0x00}, - {0x0F, false, 0x02}, - {0x11, false, 0x02}, - {0x12, false, 0x02}, - {0x13, false, 0x02}, - {0x14, false, 0x02}, - {0x15, false, 0x02}, - {0x16, false, 0x02}, - {0x17, false, 0x02}, - {0x18, false, 0x02}, - {0x19, false, 0x02}, - {0x1A, false, 0x02}, - {0x1B, true, 0x00}, - {0x1C, false, 0x02}, - {0x20, false, 0x02}, - {0x21, false, 0x02}, - {0x22, true, 0x00}, - {0x23, true, 0x02}, - {0x24, false, 0x02}, - {0x2D, false, 0x02}, - {0x2E, false, 0x02}, - {0x2F, false, 0x02}, - {0x30, true, 0x02}, - {0x31, false, 0x02}, - {0x32, false, 0x02}, - {0x33, true, 0x00}, - {0x34, true, 0x00}, - {0x35, false, 0x02}, - {0x36, false, 0x02}, - {0x37, false, 0x02}, - {0x38, false, 0x02}, - {0x39, true, 0x00}, - {0x3A, false, 0x02}, - {0x3B, false, 0x02}, - {0x3D, false, 0x02}, - {0x3E, false, 0x02}, - {0x3F, false, 0x02}, -}; - -static constexpr size_t NumWakePinConfigsHoag = util::size(WakePinConfigsHoag); diff --git a/stratosphere/boot/source/boot_wake_pin_configuration_icosa.inc b/stratosphere/boot/source/boot_wake_pin_configuration_icosa.inc deleted file mode 100644 index ddfb16a6f..000000000 --- a/stratosphere/boot/source/boot_wake_pin_configuration_icosa.inc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -static constexpr WakePinConfig WakePinConfigsIcosa[] = { - {0x00, false, 0x02}, - {0x01, false, 0x02}, - {0x02, false, 0x02}, - {0x03, false, 0x02}, - {0x04, true, 0x02}, - {0x05, false, 0x02}, - {0x06, true, 0x02}, - {0x07, true, 0x02}, - {0x08, true, 0x01}, - {0x0A, true, 0x02}, - {0x0B, false, 0x02}, - {0x0C, false, 0x02}, - {0x0D, false, 0x02}, - {0x0E, true, 0x00}, - {0x0F, false, 0x02}, - {0x11, false, 0x02}, - {0x12, false, 0x02}, - {0x13, false, 0x02}, - {0x14, false, 0x02}, - {0x15, false, 0x02}, - {0x16, false, 0x02}, - {0x17, false, 0x02}, - {0x18, false, 0x02}, - {0x19, false, 0x02}, - {0x1A, false, 0x02}, - {0x1B, true, 0x00}, - {0x1C, false, 0x02}, - {0x21, false, 0x02}, - {0x22, true, 0x00}, - {0x23, true, 0x02}, - {0x24, false, 0x02}, - {0x2D, false, 0x02}, - {0x2E, false, 0x02}, - {0x2F, false, 0x02}, - {0x30, true, 0x02}, - {0x31, false, 0x02}, - {0x32, false, 0x02}, - {0x33, true, 0x00}, - {0x34, true, 0x00}, - {0x35, false, 0x02}, - {0x36, false, 0x02}, - {0x37, false, 0x02}, - {0x38, false, 0x02}, - {0x39, false, 0x02}, - {0x3A, false, 0x02}, - {0x3B, false, 0x02}, - {0x3D, false, 0x02}, - {0x3E, false, 0x02}, - {0x3F, false, 0x02}, -}; - -static constexpr size_t NumWakePinConfigsIcosa = util::size(WakePinConfigsIcosa); diff --git a/stratosphere/boot/source/boot_wake_pin_configuration_iowa.inc b/stratosphere/boot/source/boot_wake_pin_configuration_iowa.inc deleted file mode 100644 index 53dbe0007..000000000 --- a/stratosphere/boot/source/boot_wake_pin_configuration_iowa.inc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ - -static constexpr WakePinConfig WakePinConfigsIowa[] = { - {0x00, false, 0x02}, - {0x01, false, 0x02}, - {0x02, false, 0x02}, - {0x03, false, 0x02}, - {0x04, true, 0x02}, - {0x05, false, 0x02}, - {0x06, true, 0x02}, - {0x07, true, 0x02}, - {0x08, true, 0x01}, - {0x0A, true, 0x02}, - {0x0B, false, 0x02}, - {0x0C, false, 0x02}, - {0x0D, false, 0x02}, - {0x0E, true, 0x00}, - {0x0F, false, 0x02}, - {0x11, false, 0x02}, - {0x12, false, 0x02}, - {0x13, false, 0x02}, - {0x14, false, 0x02}, - {0x15, false, 0x02}, - {0x16, false, 0x02}, - {0x17, false, 0x02}, - {0x18, false, 0x02}, - {0x19, false, 0x02}, - {0x1A, false, 0x02}, - {0x1B, true, 0x00}, - {0x1C, false, 0x02}, - {0x21, false, 0x02}, - {0x22, true, 0x00}, - {0x23, true, 0x02}, - {0x24, false, 0x02}, - {0x2D, false, 0x02}, - {0x2E, false, 0x02}, - {0x2F, false, 0x02}, - {0x30, true, 0x02}, - {0x31, false, 0x02}, - {0x32, false, 0x02}, - {0x33, true, 0x00}, - {0x34, true, 0x00}, - {0x35, false, 0x02}, - {0x36, false, 0x02}, - {0x37, false, 0x02}, - {0x38, false, 0x02}, - {0x39, false, 0x02}, - {0x3A, false, 0x02}, - {0x3B, false, 0x02}, - {0x3D, false, 0x02}, - {0x3E, false, 0x02}, - {0x3F, false, 0x02}, -}; - -static constexpr size_t NumWakePinConfigsIowa = util::size(WakePinConfigsIowa); diff --git a/stratosphere/boot/source/boot_wake_pins.cpp b/stratosphere/boot/source/boot_wake_pins.cpp deleted file mode 100644 index 59f710f90..000000000 --- a/stratosphere/boot/source/boot_wake_pins.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 . - */ -#include -#include "boot_pmc_wrapper.hpp" -#include "boot_wake_pins.hpp" - -namespace ams::boot { - - /* Include configuration into anonymous namespace. */ - namespace { - - struct WakePinConfig { - u32 index; - bool enabled; - u32 level; - }; - -#include "boot_wake_control_configs.inc" -#include "boot_wake_pin_configuration_icosa.inc" -#include "boot_wake_pin_configuration_copper.inc" -#include "boot_wake_pin_configuration_hoag.inc" -#include "boot_wake_pin_configuration_iowa.inc" -#include "boot_wake_pin_configuration_calcio.inc" - - } - - namespace { - - /* Helpers. */ - void UpdatePmcControlBit(const u32 reg_offset, const u32 mask_val, const bool flag) { - WritePmcRegister(PmcBase + reg_offset, flag ? std::numeric_limits::max() : 0, mask_val); - ReadPmcRegister(PmcBase + reg_offset); - } - - void InitializePmcWakeConfiguration(const bool is_blink) { - /* Initialize APBDEV_PMC_WAKE_DEBOUNCE_EN, do a dummy read. */ - WritePmcRegister(PmcBase + APBDEV_PMC_WAKE_DEBOUNCE_EN, 0); - ReadPmcRegister(PmcBase + APBDEV_PMC_WAKE_DEBOUNCE_EN); - - /* Initialize APBDEV_PMC_BLINK_TIMER, do a dummy read. */ - WritePmcRegister(PmcBase + APBDEV_PMC_BLINK_TIMER, 0x8008800); - ReadPmcRegister(PmcBase + APBDEV_PMC_BLINK_TIMER); - - /* Set control bits, do dummy reads. */ - for (size_t i = 0; i < NumWakeControlConfigs; i++) { - UpdatePmcControlBit(WakeControlConfigs[i].reg_offset, WakeControlConfigs[i].mask_val, WakeControlConfigs[i].flag_val); - } - - /* Set bit 0x80 in APBDEV_PMC_CNTRL based on is_blink, do dummy read. */ - UpdatePmcControlBit(APBDEV_PMC_CNTRL, 0x80, is_blink); - - /* Set bit 0x100000 in APBDEV_PMC_DPD_PADS_ORIDE based on is_blink, do dummy read. */ - UpdatePmcControlBit(APBDEV_PMC_DPD_PADS_ORIDE, 0x100000, is_blink); - } - - void SetWakeEventLevel(u32 index, u32 level) { - u32 pmc_wake_level_reg_offset = index <= 0x1F ? APBDEV_PMC_WAKE_LVL : APBDEV_PMC_WAKE2_LVL; - u32 pmc_wake_level_mask_reg_offset = index <= 0x1F ? APBDEV_PMC_AUTO_WAKE_LVL_MASK : APBDEV_PMC_AUTO_WAKE2_LVL_MASK; - if (level != 2) { - std::swap(pmc_wake_level_reg_offset, pmc_wake_level_mask_reg_offset); - } - - const u32 mask_val = (1 << (index & 0x1F)); - - /* Clear level reg bit. */ - UpdatePmcControlBit(pmc_wake_level_reg_offset, mask_val, false); - - /* Set or clear mask reg bit. */ - UpdatePmcControlBit(pmc_wake_level_mask_reg_offset, mask_val, level > 0); - } - - void SetWakeEventEnabled(u32 index, bool enabled) { - /* Set or clear enabled bit. */ - UpdatePmcControlBit(index <= 0x1F ? APBDEV_PMC_WAKE_MASK : APBDEV_PMC_WAKE2_MASK, (1 << (index & 0x1F)), enabled); - } - - } - - void SetInitialWakePinConfiguration() { - InitializePmcWakeConfiguration(false); - - /* Set wake event levels, wake event enables. */ - const WakePinConfig *configs = nullptr; - size_t num_configs = 0; - - switch (spl::GetHardwareType()) { - case spl::HardwareType::Icosa: - configs = WakePinConfigsIcosa; - num_configs = NumWakePinConfigsIcosa; - break; - case spl::HardwareType::Copper: - configs = WakePinConfigsCopper; - num_configs = NumWakePinConfigsCopper; - break; - case spl::HardwareType::Hoag: - configs = WakePinConfigsHoag; - num_configs = NumWakePinConfigsHoag; - break; - case spl::HardwareType::Iowa: - configs = WakePinConfigsIowa; - num_configs = NumWakePinConfigsIowa; - case spl::HardwareType::Calcio: - configs = WakePinConfigsCalcio; - num_configs = NumWakePinConfigsCalcio; - break; - AMS_UNREACHABLE_DEFAULT_CASE(); - } - - AMS_ABORT_UNLESS(configs != nullptr); - - for (size_t i = 0; i < num_configs; i++) { - SetWakeEventLevel(configs[i].index, configs[i].level); - SetWakeEventEnabled(configs[i].index, configs[i].enabled); - } - } - -} diff --git a/stratosphere/boot/source/boot_wake_pins.hpp b/stratosphere/boot/source/boot_wake_pins.hpp deleted file mode 100644 index 845ba09f6..000000000 --- a/stratosphere/boot/source/boot_wake_pins.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * 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 - -namespace ams::boot { - - void SetInitialWakePinConfiguration(); - -}