mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-29 14:05:17 -04:00
i2c/gpio: hook up open session for sf interface
This commit is contained in:
parent
b74b309a77
commit
42caa4ffd1
15 changed files with 571 additions and 16 deletions
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 <vapours.hpp>
|
||||
#include <stratosphere/i2c/i2c_types.hpp>
|
||||
|
||||
namespace ams::i2c::driver {
|
||||
|
||||
namespace impl {
|
||||
|
||||
constexpr inline size_t I2cSessionSize = 0x60;
|
||||
constexpr inline size_t I2cSessionAlign = 8;
|
||||
struct alignas(I2cSessionAlign) I2cSessionImplPadded;
|
||||
|
||||
}
|
||||
|
||||
struct I2cSession {
|
||||
util::TypedStorage<impl::I2cSessionImplPadded, impl::I2cSessionSize, impl::I2cSessionAlign> _impl;
|
||||
};
|
||||
|
||||
Result OpenSession(I2cSession *out, DeviceCode device_code);
|
||||
void CloseSession(I2cSession &session);
|
||||
|
||||
Result Send(I2cSession &session, const void *src, size_t src_size, TransactionOption option);
|
||||
Result Receive(void *dst, size_t dst_size, I2cSession &session, TransactionOption option);
|
||||
|
||||
Result ExecuteCommandList(void *dst, size_t dst_size, I2cSession &session, const void *src, size_t src_size);
|
||||
|
||||
Result SetRetryPolicy(I2cSession &session, int max_retry_count, int retry_interval_ms);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* 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 <vapours.hpp>
|
||||
#include <stratosphere/i2c/driver/i2c_bus_api.hpp>
|
||||
#include <stratosphere/ddsf.hpp>
|
||||
|
||||
namespace ams::i2c::driver {
|
||||
|
||||
class I2cDeviceProperty;
|
||||
|
||||
}
|
||||
|
||||
namespace ams::i2c::driver::impl {
|
||||
|
||||
class I2cSessionImpl : public ::ams::ddsf::ISession {
|
||||
NON_COPYABLE(I2cSessionImpl);
|
||||
NON_MOVEABLE(I2cSessionImpl);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::driver::impl::I2cSessionImpl, ::ams::ddsf::ISession);
|
||||
private:
|
||||
enum class Command {
|
||||
Send = 0,
|
||||
Receive = 1,
|
||||
};
|
||||
private:
|
||||
TimeSpan retry_interval;
|
||||
int max_retry_count;
|
||||
private:
|
||||
Result SendHandler(const u8 **cur_cmd, u8 **cur_dst);
|
||||
Result ReceiveHandler(const u8 **cur_cmd, u8 **cur_dst);
|
||||
Result ExtensionHandler(const u8 **cur_cmd, u8 **cur_dst);
|
||||
|
||||
Result ExecuteTransactionWithRetry(void *dst, Command command, const void *src, size_t size, TransactionOption option);
|
||||
public:
|
||||
I2cSessionImpl(int mr, TimeSpan rt) : retry_interval(rt), max_retry_count(mr) { /* ... */ }
|
||||
|
||||
~I2cSessionImpl() {
|
||||
this->Close();
|
||||
}
|
||||
|
||||
Result Open(I2cDeviceProperty *device, ddsf::AccessMode access_mode);
|
||||
void Close();
|
||||
|
||||
Result Send(const void *src, size_t src_size, TransactionOption option);
|
||||
Result Receive(void *dst, size_t dst_size, TransactionOption option);
|
||||
Result ExecuteCommandList(void *dst, size_t dst_size, const void *src, size_t src_size);
|
||||
Result SetRetryPolicy(int mr, int interval_ms);
|
||||
};
|
||||
static_assert( sizeof(I2cSessionImpl) <= I2cSessionSize);
|
||||
static_assert(alignof(I2cSessionImpl) <= I2cSessionAlign);
|
||||
|
||||
struct alignas(I2cSessionAlign) I2cSessionImplPadded {
|
||||
I2cSessionImpl _impl;
|
||||
u8 _padding[I2cSessionSize - sizeof(I2cSessionImpl)];
|
||||
};
|
||||
static_assert( sizeof(I2cSessionImplPadded) == I2cSessionSize);
|
||||
static_assert(alignof(I2cSessionImplPadded) == I2cSessionAlign);
|
||||
|
||||
ALWAYS_INLINE I2cSessionImpl &GetI2cSessionImpl(I2cSession &session) {
|
||||
return GetReference(session._impl)._impl;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const I2cSessionImpl &GetI2cSessionImpl(const I2cSession &session) {
|
||||
return GetReference(session._impl)._impl;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE I2cSessionImpl &GetOpenI2cSessionImpl(I2cSession &session) {
|
||||
auto &ref = GetReference(session._impl)._impl;
|
||||
AMS_ASSERT(ref.IsOpen());
|
||||
return ref;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const I2cSessionImpl &GetOpenI2cSessionImpl(const I2cSession &session) {
|
||||
const auto &ref = GetReference(session._impl)._impl;
|
||||
AMS_ASSERT(ref.IsOpen());
|
||||
return ref;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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 <vapours.hpp>
|
||||
#include <stratosphere/i2c/i2c_types.hpp>
|
||||
|
||||
namespace ams::i2c {
|
||||
|
||||
struct I2cSession {
|
||||
void *_session;
|
||||
};
|
||||
|
||||
Result OpenSession(I2cSession *out, DeviceCode device_code);
|
||||
void CloseSession(I2cSession &session);
|
||||
|
||||
Result Send(const I2cSession &session, const void *src, size_t src_size, TransactionOption option);
|
||||
Result Receive(void *dst, size_t dst_size, const I2cSession &session, TransactionOption option);
|
||||
|
||||
Result ExecuteCommandList(void *dst, size_t dst_size, const I2cSession &session, const void *src, size_t src_size);
|
||||
|
||||
void SetRetryPolicy(const I2cSession &session, int max_retry_count, int retry_interval_ms);
|
||||
|
||||
}
|
|
@ -194,4 +194,57 @@ namespace ams::i2c {
|
|||
}
|
||||
}
|
||||
|
||||
constexpr inline I2cDevice ConvertToI2cDevice(DeviceCode dc) {
|
||||
switch (dc.GetInternalValue()) {
|
||||
case DeviceCode_ClassicController.GetInternalValue(): return I2cDevice_ClassicController;
|
||||
case DeviceCode_Ftm3bd56 .GetInternalValue(): return I2cDevice_Ftm3bd56;
|
||||
case DeviceCode_Tmp451 .GetInternalValue(): return I2cDevice_Tmp451;
|
||||
/* case DeviceCode_Nct72 .GetInternalValue(): return I2cDevice_Nct72; */
|
||||
case DeviceCode_Alc5639 .GetInternalValue(): return I2cDevice_Alc5639;
|
||||
case DeviceCode_Max77620Rtc .GetInternalValue(): return I2cDevice_Max77620Rtc;
|
||||
case DeviceCode_Max77620Pmic .GetInternalValue(): return I2cDevice_Max77620Pmic;
|
||||
case DeviceCode_Max77621Cpu .GetInternalValue(): return I2cDevice_Max77621Cpu;
|
||||
case DeviceCode_Max77621Gpu .GetInternalValue(): return I2cDevice_Max77621Gpu;
|
||||
case DeviceCode_Bq24193 .GetInternalValue(): return I2cDevice_Bq24193;
|
||||
case DeviceCode_Max17050 .GetInternalValue(): return I2cDevice_Max17050;
|
||||
case DeviceCode_Bm92t30mwv .GetInternalValue(): return I2cDevice_Bm92t30mwv;
|
||||
case DeviceCode_Ina226Vdd15v0Hb .GetInternalValue(): return I2cDevice_Ina226Vdd15v0Hb;
|
||||
case DeviceCode_Ina226VsysCpuDs .GetInternalValue(): return I2cDevice_Ina226VsysCpuDs;
|
||||
case DeviceCode_Ina226VsysGpuDs .GetInternalValue(): return I2cDevice_Ina226VsysGpuDs;
|
||||
case DeviceCode_Ina226VsysDdrDs .GetInternalValue(): return I2cDevice_Ina226VsysDdrDs;
|
||||
case DeviceCode_Ina226VsysAp .GetInternalValue(): return I2cDevice_Ina226VsysAp;
|
||||
case DeviceCode_Ina226VsysBlDs .GetInternalValue(): return I2cDevice_Ina226VsysBlDs;
|
||||
case DeviceCode_Bh1730 .GetInternalValue(): return I2cDevice_Bh1730;
|
||||
case DeviceCode_Ina226VsysCore .GetInternalValue(): return I2cDevice_Ina226VsysCore;
|
||||
case DeviceCode_Ina226Soc1V8 .GetInternalValue(): return I2cDevice_Ina226Soc1V8;
|
||||
case DeviceCode_Ina226Lpddr1V8 .GetInternalValue(): return I2cDevice_Ina226Lpddr1V8;
|
||||
case DeviceCode_Ina226Reg1V32 .GetInternalValue(): return I2cDevice_Ina226Reg1V32;
|
||||
case DeviceCode_Ina226Vdd3V3Sys .GetInternalValue(): return I2cDevice_Ina226Vdd3V3Sys;
|
||||
case DeviceCode_HdmiDdc .GetInternalValue(): return I2cDevice_HdmiDdc;
|
||||
case DeviceCode_HdmiScdc .GetInternalValue(): return I2cDevice_HdmiScdc;
|
||||
case DeviceCode_HdmiHdcp .GetInternalValue(): return I2cDevice_HdmiHdcp;
|
||||
case DeviceCode_Fan53528 .GetInternalValue(): return I2cDevice_Fan53528;
|
||||
case DeviceCode_Max77812_3 .GetInternalValue(): return I2cDevice_Max77812_3;
|
||||
case DeviceCode_Max77812_2 .GetInternalValue(): return I2cDevice_Max77812_2;
|
||||
case DeviceCode_Ina226VddDdr0V6 .GetInternalValue(): return I2cDevice_Ina226VddDdr0V6;
|
||||
case DeviceCode_HoagNfcIc .GetInternalValue(): return I2cDevice_HoagNfcIc;
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool IsPowerBusDeviceCode(DeviceCode device_code) {
|
||||
switch (device_code.GetInternalValue()) {
|
||||
case DeviceCode_Max77620Pmic.GetInternalValue():
|
||||
case DeviceCode_Max77812_3 .GetInternalValue():
|
||||
case DeviceCode_Max77621Cpu .GetInternalValue():
|
||||
case DeviceCode_Max77621Gpu .GetInternalValue():
|
||||
case DeviceCode_Fan53528 .GetInternalValue():
|
||||
case DeviceCode_Max77812_2 .GetInternalValue():
|
||||
case DeviceCode_Max77620Rtc .GetInternalValue():
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue