Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"

This reverts commit 15b7df8ef1.
This commit is contained in:
souldbminersmwc
2025-11-09 16:14:52 -05:00
parent 22ec140738
commit 21a3f953d7
3804 changed files with 435 additions and 570162 deletions

View File

@@ -1,151 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "gpio_driver_core.hpp"
namespace ams::gpio::driver::impl {
namespace {
os::ThreadType g_interrupt_thread;
constexpr inline size_t InterruptThreadStackSize = os::MemoryPageSize;
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
gpio::driver::IGpioDriver::List &GetGpioDriverList() {
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(gpio::driver::IGpioDriver::List, s_gpio_driver_list);
return s_gpio_driver_list;
}
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
AMS_FUNCTION_LOCAL_STATIC(ddsf::EventHandlerManager, s_interrupt_handler_manager);
return s_interrupt_handler_manager;
}
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
AMS_FUNCTION_LOCAL_STATIC(ddsf::DeviceCodeEntryManager, s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
return s_device_code_entry_manager;
}
void InterruptThreadFunction(void *arg) {
AMS_UNUSED(arg);
GetInterruptHandlerManager().LoopAuto();
}
}
void InitializeDrivers() {
/* Ensure the event handler manager is initialized. */
GetInterruptHandlerManager().Initialize();
/* Initialize all registered drivers. */
for (auto &driver : GetGpioDriverList()) {
driver.SafeCastTo<IGpioDriver>().InitializeDriver();
}
/* Create the interrupt thread. */
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_interrupt_thread), InterruptThreadFunction, nullptr, g_interrupt_thread_stack, InterruptThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(gpio, InterruptHandler)));
os::SetThreadNamePointer(std::addressof(g_interrupt_thread), AMS_GET_SYSTEM_THREAD_NAME(gpio, InterruptHandler));
os::StartThread(std::addressof(g_interrupt_thread));
/* Wait for the interrupt thread to enter the loop. */
GetInterruptHandlerManager().WaitLoopEnter();
}
void FinalizeDrivers() {
/* Request the interrupt thread stop. */
GetInterruptHandlerManager().RequestStop();
os::WaitThread(std::addressof(g_interrupt_thread));
os::DestroyThread(std::addressof(g_interrupt_thread));
/* TODO: What else? */
AMS_ABORT();
}
void RegisterDriver(IGpioDriver *driver) {
AMS_ASSERT(driver != nullptr);
GetGpioDriverList().push_back(*driver);
}
void UnregisterDriver(IGpioDriver *driver) {
AMS_ASSERT(driver != nullptr);
if (driver->IsLinkedToList()) {
auto &list = GetGpioDriverList();
list.erase(list.iterator_to(*driver));
}
}
Result RegisterDeviceCode(DeviceCode device_code, Pad *pad) {
AMS_ASSERT(pad != nullptr);
R_TRY(GetDeviceCodeEntryManager().Add(device_code, pad));
R_SUCCEED();
}
bool UnregisterDeviceCode(DeviceCode device_code) {
return GetDeviceCodeEntryManager().Remove(device_code);
}
void RegisterInterruptHandler(ddsf::IEventHandler *handler) {
AMS_ASSERT(handler != nullptr);
GetInterruptHandlerManager().RegisterHandler(handler);
}
void UnregisterInterruptHandler(ddsf::IEventHandler *handler) {
AMS_ASSERT(handler != nullptr);
GetInterruptHandlerManager().UnregisterHandler(handler);
}
Result FindPad(Pad **out, DeviceCode device_code) {
/* Validate output. */
AMS_ASSERT(out != nullptr);
/* Find the device. */
ddsf::IDevice *device;
R_TRY(GetDeviceCodeEntryManager().FindDevice(std::addressof(device), device_code));
/* Set output. */
*out = device->SafeCastToPointer<Pad>();
R_SUCCEED();
}
Result FindPadByNumber(Pad **out, int pad_number) {
/* Validate output. */
AMS_ASSERT(out != nullptr);
/* Find the pad. */
bool found = false;
GetDeviceCodeEntryManager().ForEachEntry([&](ddsf::DeviceCodeEntry &entry) -> bool {
/* Convert the entry to a pad. */
auto &pad = entry.GetDevice().SafeCastTo<Pad>();
/* Check if the pad is the one we're looking for. */
if (pad.GetPadNumber() == pad_number) {
found = true;
*out = std::addressof(pad);
return false;
}
return true;
});
/* Check that we found the pad. */
R_UNLESS(found, ddsf::ResultDeviceCodeNotFound());
R_SUCCEED();
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::gpio::driver::impl {
void InitializeDrivers();
void FinalizeDrivers();
void RegisterDriver(IGpioDriver *driver);
void UnregisterDriver(IGpioDriver *driver);
Result RegisterDeviceCode(DeviceCode device_code, Pad *pad);
bool UnregisterDeviceCode(DeviceCode device_code);
void RegisterInterruptHandler(ddsf::IEventHandler *handler);
void UnregisterInterruptHandler(ddsf::IEventHandler *handler);
Result FindPad(Pad **out, DeviceCode device_code);
Result FindPadByNumber(Pad **out, int pad_number);
}

View File

@@ -1,151 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
namespace ams::gpio::driver::impl {
Result PadSessionImpl::Open(Pad *pad, ddsf::AccessMode access_mode) {
/* Check if the pad has any open sessions. */
const bool first_session = !pad->HasAnyOpenSession();
/* Open the session. */
R_TRY(ddsf::OpenSession(pad, this, access_mode));
auto pad_guard = SCOPE_GUARD { ddsf::CloseSession(this); };
/* If we're the first, we want to initialize the pad. */
if (first_session) {
R_TRY(pad->GetDriver().SafeCastTo<IGpioDriver>().InitializePad(pad));
}
/* We opened successfully. */
pad_guard.Cancel();
R_SUCCEED();
}
void PadSessionImpl::Close() {
/* If the session isn't open, nothing to do. */
if (!this->IsOpen()) {
return;
}
/* Unbind the interrupt, if it's bound. */
if (this->IsInterruptBound()) {
this->UnbindInterrupt();
}
/* Get the pad we're a session for. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
/* Close the session. */
ddsf::CloseSession(this);
/* If we were the last session on the pad, finalize the pad. */
if (!pad.HasAnyOpenSession()) {
pad.GetDriver().SafeCastTo<IGpioDriver>().FinalizePad(std::addressof(pad));
}
}
Result PadSessionImpl::BindInterrupt(os::SystemEventType *event) {
/* Acquire exclusive access to the relevant interrupt control mutex. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &mutex = pad.GetDriver().SafeCastTo<IGpioDriver>().GetInterruptControlMutex(pad);
std::scoped_lock lk(mutex);
/* Check that we're not already bound. */
R_UNLESS(!this->IsInterruptBound(), gpio::ResultAlreadyBound());
R_UNLESS(!this->GetDevice().SafeCastTo<Pad>().IsAnySessionBoundToInterrupt(), gpio::ResultAlreadyBound());
/* Create the system event. */
R_TRY(os::CreateSystemEvent(event, os::EventClearMode_ManualClear, true));
auto ev_guard = SCOPE_GUARD { os::DestroySystemEvent(event); };
/* Attach the event to our holder. */
m_event_holder.AttachEvent(event);
auto hl_guard = SCOPE_GUARD { m_event_holder.DetachEvent(); };
/* Update interrupt needed. */
R_TRY(this->UpdateDriverInterruptEnabled());
/* We succeeded. */
hl_guard.Cancel();
ev_guard.Cancel();
R_SUCCEED();
}
void PadSessionImpl::UnbindInterrupt() {
/* Acquire exclusive access to the relevant interrupt control mutex. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &mutex = pad.GetDriver().SafeCastTo<IGpioDriver>().GetInterruptControlMutex(pad);
std::scoped_lock lk(mutex);
/* If we're not bound, nothing to do. */
if (!this->IsInterruptBound()) {
return;
}
/* Detach and destroy the event */
os::DestroySystemEvent(m_event_holder.DetachEvent());
/* Update interrupt needed. */
R_ABORT_UNLESS(this->UpdateDriverInterruptEnabled());
}
Result PadSessionImpl::UpdateDriverInterruptEnabled() {
/* Check we have exclusive access to the relevant interrupt control mutex. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &driver = pad.GetDriver().SafeCastTo<IGpioDriver>();
AMS_ASSERT(driver.GetInterruptControlMutex(pad).IsLockedByCurrentThread());
/* Set interrupt enabled. */
R_RETURN(driver.SetInterruptEnabled(std::addressof(pad), pad.IsInterruptRequiredForDriver()));
}
Result PadSessionImpl::GetInterruptEnabled(bool *out) const {
*out = this->GetDevice().SafeCastTo<Pad>().IsInterruptEnabled();
R_SUCCEED();
}
Result PadSessionImpl::SetInterruptEnabled(bool en) {
/* Acquire exclusive access to the relevant interrupt control mutex. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &mutex = pad.GetDriver().SafeCastTo<IGpioDriver>().GetInterruptControlMutex(pad);
std::scoped_lock lk(mutex);
/* Set the interrupt enable. */
const bool prev = pad.IsInterruptEnabled();
pad.SetInterruptEnabled(en);
auto pad_guard = SCOPE_GUARD { pad.SetInterruptEnabled(prev); };
/* Update interrupt needed. */
R_TRY(this->UpdateDriverInterruptEnabled());
pad_guard.Cancel();
R_SUCCEED();
}
void PadSessionImpl::SignalInterruptBoundEvent() {
/* Check we have exclusive access to the relevant interrupt control mutex. */
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &driver = pad.GetDriver().SafeCastTo<IGpioDriver>();
AMS_ASSERT(driver.GetInterruptControlMutex(pad).IsLockedByCurrentThread());
AMS_UNUSED(pad, driver);
if (auto *event = m_event_holder.GetSystemEvent(); event != nullptr) {
os::SignalSystemEvent(event);
}
}
}