i2c: implement driver init api
This commit is contained in:
@@ -73,14 +73,6 @@ namespace ams::i2c::driver::board::nintendo_nx::impl {
|
||||
dd::PhysicalAddress GetRegistersPhysicalAddress() const { return this->registers_phys_addr; }
|
||||
size_t GetRegistersSize() const { return this->registers_size; }
|
||||
os::InterruptName GetInterruptName() const { return this->interrupt_name; }
|
||||
|
||||
void RemoveFrom(BusAccessorList &lst) {
|
||||
lst.erase(lst.iterator_to(*this));
|
||||
}
|
||||
|
||||
bool IsLinkedToList() const {
|
||||
return this->bus_accessor_list_node.IsLinked();
|
||||
}
|
||||
private:
|
||||
Result TryOpenRegulatorSession();
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "i2c_bus_accessor.hpp"
|
||||
#include "i2c_i_allocator.hpp"
|
||||
|
||||
namespace ams::i2c::driver::board::nintendo_nx::impl {
|
||||
|
||||
class I2cBusAccessorManager : public IAllocator<I2cBusAccessor::BusAccessorList> {
|
||||
/* ... */
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "i2c_i_allocator.hpp"
|
||||
|
||||
namespace ams::i2c::driver::board::nintendo_nx::impl {
|
||||
|
||||
class I2cDevicePropertyManager : public IAllocator<I2cDeviceProperty::DevicePropertyList> {
|
||||
/* ... */
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::i2c::driver::board::nintendo_nx::impl {
|
||||
|
||||
template<typename ListType>
|
||||
class IAllocator {
|
||||
private:
|
||||
using T = typename ListType::value_type;
|
||||
private:
|
||||
ams::MemoryResource *memory_resource;
|
||||
ListType list;
|
||||
mutable os::SdkMutex list_lock;
|
||||
public:
|
||||
IAllocator(ams::MemoryResource *mr) : memory_resource(mr), list(), list_lock() { /* ... */ }
|
||||
|
||||
~IAllocator() {
|
||||
/* TODO: Remove all entries, etc */
|
||||
AMS_ABORT("BusAccessorManager not destructible");
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
T *Allocate(Args &&...args) {
|
||||
std::scoped_lock lk(this->list_lock);
|
||||
|
||||
/* Allocate space for the object. */
|
||||
void *storage = this->memory_resource->Allocate(sizeof(T), alignof(T));
|
||||
AMS_ABORT_UNLESS(storage != nullptr);
|
||||
|
||||
/* Construct the object. */
|
||||
T *t = new (static_cast<T *>(storage)) T(std::forward<Args>(args)...);
|
||||
|
||||
/* Link the object into our list. */
|
||||
this->list.push_back(*t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
T *Find(F f) {
|
||||
std::scoped_lock lk(this->list_lock);
|
||||
|
||||
for (T &it : this->list) {
|
||||
if (f(static_cast<const T &>(it))) {
|
||||
return std::addressof(it);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* TODO: Support free */
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user