mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-28 20:40:24 +00:00
i2c: begin skeleton device driver framework
This commit is contained in:
parent
21fac86080
commit
4a2daa4810
18 changed files with 656 additions and 1 deletions
|
@ -51,6 +51,7 @@
|
|||
#include <stratosphere/gpio.hpp>
|
||||
#include <stratosphere/hid.hpp>
|
||||
#include <stratosphere/hos.hpp>
|
||||
#include <stratosphere/i2c.hpp>
|
||||
#include <stratosphere/kvdb.hpp>
|
||||
#include <stratosphere/ldr.hpp>
|
||||
#include <stratosphere/lr.hpp>
|
||||
|
|
25
libraries/libstratosphere/include/stratosphere/i2c.hpp
Normal file
25
libraries/libstratosphere/include/stratosphere/i2c.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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/i2c/i2c_types.hpp>
|
||||
#include <stratosphere/i2c/i2c_select_device_name.hpp>
|
||||
#include <stratosphere/i2c/sf/i2c_sf_i_session.hpp>
|
||||
#include <stratosphere/i2c/sf/i2c_sf_i_manager.hpp>
|
||||
#include <stratosphere/i2c/server/i2c_server_api.hpp>
|
||||
#include <stratosphere/i2c/driver/i2c_select_driver_api.hpp>
|
||||
#include <stratosphere/i2c/driver/i2c_driver_client_api.hpp>
|
||||
#include <stratosphere/i2c/i2c_api.hpp>
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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::board::nintendo_nx {
|
||||
|
||||
void Initialize();
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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 {
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <stratosphere/ddsf.hpp>
|
||||
|
||||
namespace ams::i2c::driver {
|
||||
|
||||
class I2cDeviceProperty : public ::ams::ddsf::IDevice {
|
||||
NON_COPYABLE(I2cDeviceProperty);
|
||||
NON_MOVEABLE(I2cDeviceProperty);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::I2cDeviceProperty, ::ams::ddsf::IDevice);
|
||||
private:
|
||||
u16 address;
|
||||
AddressingMode addressing_mode;
|
||||
util::IntrusiveListNode device_property_list_node;
|
||||
public:
|
||||
using DevicePropertyListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&I2cDeviceProperty::device_property_list_node>;
|
||||
using DevicePropertyList = typename DevicePropertyListTraits::ListType;
|
||||
friend class util::IntrusiveList<I2cDeviceProperty, util::IntrusiveListMemberTraitsDeferredAssert<&I2cDeviceProperty::device_property_list_node>>;
|
||||
public:
|
||||
I2cDeviceProperty() : IDevice(false), address(0), addressing_mode(AddressingMode_SevenBit), device_property_list_node() { /* ... */ }
|
||||
I2cDeviceProperty(u16 addr, AddressingMode m) : IDevice(false), address(addr), addressing_mode(m), device_property_list_node() { /* ... */ }
|
||||
|
||||
virtual ~I2cDeviceProperty() { /* ... */ }
|
||||
|
||||
u16 GetAddress() const {
|
||||
return this->address;
|
||||
}
|
||||
|
||||
AddressingMode GetAddressingMode() const {
|
||||
return this->addressing_mode;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <stratosphere/ddsf.hpp>
|
||||
|
||||
namespace ams::i2c::driver {
|
||||
|
||||
class I2cDeviceProperty;
|
||||
|
||||
class II2cDriver : public ::ams::ddsf::IDriver {
|
||||
NON_COPYABLE(II2cDriver);
|
||||
NON_MOVEABLE(II2cDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::II2cDriver, ::ams::ddsf::IDriver);
|
||||
public:
|
||||
II2cDriver() : IDriver() { /* ... */ }
|
||||
virtual ~II2cDriver() { /* ... */ }
|
||||
|
||||
virtual void InitializeDriver() = 0;
|
||||
virtual void FinalizeDriver() = 0;
|
||||
|
||||
virtual Result Open() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual Result Send(I2cDeviceProperty *device, const void *src, size_t src_size, TransactionOption option) = 0;
|
||||
virtual Result Receive(void *dst, size_t dst_size, I2cDeviceProperty *device, TransactionOption option) = 0;
|
||||
|
||||
virtual os::SdkMutex &GetTransactionOrderMutex() = 0;
|
||||
|
||||
virtual void SuspendBus();
|
||||
virtual void SuspendPowerBus();
|
||||
|
||||
virtual void ResumeBus();
|
||||
virtual void ResumePowerBus();
|
||||
|
||||
virtual const DeviceCode &GetDeviceCode() const = 0;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <stratosphere/i2c/driver/i2c_i_i2c_driver.hpp>
|
||||
#include <stratosphere/i2c/driver/i2c_i2c_device_property.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
|
||||
|
||||
#include <stratosphere/i2c/driver/board/nintendo_nx/i2c_driver_api.hpp>
|
||||
|
||||
namespace ams::i2c::driver::board {
|
||||
|
||||
using namespace ams::i2c::driver::board::nintendo_nx;
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown board for ams::gpio::driver::"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <stratosphere/i2c/sf/i2c_sf_i_manager.hpp>
|
||||
|
||||
namespace ams::i2c {
|
||||
|
||||
void InitializeWith(std::shared_ptr<i2c::sf::IManager> &&sp, std::shared_ptr<i2c::sf::IManager> &&sp_pcv);
|
||||
void InitializeEmpty();
|
||||
|
||||
void Finalize();
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* 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 {
|
||||
|
||||
enum I2cDevice : u32 {
|
||||
I2cDevice_ClassicController = 0,
|
||||
I2cDevice_Ftm3bd56 = 1,
|
||||
I2cDevice_Tmp451 = 2,
|
||||
I2cDevice_Nct72 = 3,
|
||||
I2cDevice_Alc5639 = 4,
|
||||
I2cDevice_Max77620Rtc = 5,
|
||||
I2cDevice_Max77620Pmic = 6,
|
||||
I2cDevice_Max77621Cpu = 7,
|
||||
I2cDevice_Max77621Gpu = 8,
|
||||
I2cDevice_Bq24193 = 9,
|
||||
I2cDevice_Max17050 = 10,
|
||||
I2cDevice_Bm92t30mwv = 11,
|
||||
I2cDevice_Ina226Vdd15v0Hb = 12,
|
||||
|
||||
I2cDevice_Ina226VsysCpuDs = 13,
|
||||
I2cDevice_Ina226VddCpuAp = 13,
|
||||
|
||||
I2cDevice_Ina226VsysGpuDs = 14,
|
||||
I2cDevice_Ina226VddGpuAp = 14,
|
||||
|
||||
I2cDevice_Ina226VsysDdrDs = 15,
|
||||
I2cDevice_Ina226VddDdr1V1Pmic = 15,
|
||||
|
||||
I2cDevice_Ina226VsysAp = 16,
|
||||
I2cDevice_Ina226VsysBlDs = 17,
|
||||
I2cDevice_Bh1730 = 18,
|
||||
|
||||
I2cDevice_Ina226VsysCore = 19,
|
||||
I2cDevice_Ina226VddCoreAp = 19,
|
||||
|
||||
I2cDevice_Ina226Soc1V8 = 20,
|
||||
I2cDevice_Ina226VddSoc1V8 = 20,
|
||||
|
||||
I2cDevice_Ina226Lpddr1V8 = 21,
|
||||
I2cDevice_Ina226Vdd1V8 = 21,
|
||||
|
||||
I2cDevice_Ina226Reg1V32 = 22,
|
||||
I2cDevice_Ina226Vdd3V3Sys = 23,
|
||||
I2cDevice_HdmiDdc = 24,
|
||||
I2cDevice_HdmiScdc = 25,
|
||||
I2cDevice_HdmiHdcp = 26,
|
||||
I2cDevice_Fan53528 = 27,
|
||||
I2cDevice_Max77812_3 = 28,
|
||||
I2cDevice_Max77812_2 = 29,
|
||||
I2cDevice_Ina226VddDdr0V6 = 30,
|
||||
I2cDevice_HoagNfcIc = 31, /* TODO */
|
||||
};
|
||||
|
||||
/* TODO: Better place for this? */
|
||||
constexpr inline const DeviceCode DeviceCode_ClassicController = 0x350000C9;
|
||||
constexpr inline const DeviceCode DeviceCode_Ftm3bd56 = 0x35000033;
|
||||
constexpr inline const DeviceCode DeviceCode_Tmp451 = 0x3E000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Nct72 = 0x3E000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Alc5639 = 0x33000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77620Rtc = 0x3B000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77620Pmic = 0x3A000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77621Cpu = 0x3A000003;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77621Gpu = 0x3A000004;
|
||||
constexpr inline const DeviceCode DeviceCode_Bq24193 = 0x39000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Max17050 = 0x39000033;
|
||||
constexpr inline const DeviceCode DeviceCode_Bm92t30mwv = 0x040000C9;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Vdd15v0Hb = 0x3F000401;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysCpuDs = 0x3F000001;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddCpuAp = 0x3F000001;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysGpuDs = 0x3F000002;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddGpuAp = 0x3F000002;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysDdrDs = 0x3F000003;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddDdr1V1Pmi = 0x3F000003;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysAp = 0x3F000402;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysBlDs = 0x3F000403;
|
||||
constexpr inline const DeviceCode DeviceCode_Bh1730 = 0x35000047;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VsysCore = 0x3F000404;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddCoreAp = 0x3F000404;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Soc1V8 = 0x3F000405;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddSoc1V8 = 0x3F000405;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Lpddr1V8 = 0x3F000406;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Vdd1V8 = 0x3F000406;
|
||||
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Reg1V32 = 0x3F000407;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226Vdd3V3Sys = 0x3F000408;
|
||||
constexpr inline const DeviceCode DeviceCode_HdmiDdc = 0x34000001;
|
||||
constexpr inline const DeviceCode DeviceCode_HdmiScdc = 0x34000002;
|
||||
constexpr inline const DeviceCode DeviceCode_HdmiHdcp = 0x34000003;
|
||||
constexpr inline const DeviceCode DeviceCode_Fan53528 = 0x3A000005;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77812_3 = 0x3A000002;
|
||||
constexpr inline const DeviceCode DeviceCode_Max77812_2 = 0x3A000006;
|
||||
constexpr inline const DeviceCode DeviceCode_Ina226VddDdr0V6 = 0x3F000409;
|
||||
constexpr inline const DeviceCode DeviceCode_HoagNfcIc = 0x36000001;
|
||||
|
||||
constexpr inline DeviceCode ConvertToDeviceCode(I2cDevice dv) {
|
||||
switch (dv) {
|
||||
case I2cDevice_ClassicController: return DeviceCode_ClassicController;
|
||||
case I2cDevice_Ftm3bd56: return DeviceCode_Ftm3bd56;
|
||||
case I2cDevice_Tmp451: return DeviceCode_Tmp451;
|
||||
case I2cDevice_Nct72: return DeviceCode_Nct72;
|
||||
case I2cDevice_Alc5639: return DeviceCode_Alc5639;
|
||||
case I2cDevice_Max77620Rtc: return DeviceCode_Max77620Rtc;
|
||||
case I2cDevice_Max77620Pmic: return DeviceCode_Max77620Pmic;
|
||||
case I2cDevice_Max77621Cpu: return DeviceCode_Max77621Cpu;
|
||||
case I2cDevice_Max77621Gpu: return DeviceCode_Max77621Gpu;
|
||||
case I2cDevice_Bq24193: return DeviceCode_Bq24193;
|
||||
case I2cDevice_Max17050: return DeviceCode_Max17050;
|
||||
case I2cDevice_Bm92t30mwv: return DeviceCode_Bm92t30mwv;
|
||||
case I2cDevice_Ina226Vdd15v0Hb: return DeviceCode_Ina226Vdd15v0Hb;
|
||||
case I2cDevice_Ina226VsysCpuDs: return DeviceCode_Ina226VsysCpuDs;
|
||||
case I2cDevice_Ina226VsysGpuDs: return DeviceCode_Ina226VsysGpuDs;
|
||||
case I2cDevice_Ina226VsysDdrDs: return DeviceCode_Ina226VsysDdrDs;
|
||||
case I2cDevice_Ina226VsysAp: return DeviceCode_Ina226VsysAp;
|
||||
case I2cDevice_Ina226VsysBlDs: return DeviceCode_Ina226VsysBlDs;
|
||||
case I2cDevice_Bh1730: return DeviceCode_Bh1730;
|
||||
case I2cDevice_Ina226VsysCore: return DeviceCode_Ina226VsysCore;
|
||||
case I2cDevice_Ina226Soc1V8: return DeviceCode_Ina226Soc1V8;
|
||||
case I2cDevice_Ina226Lpddr1V8: return DeviceCode_Ina226Lpddr1V8;
|
||||
case I2cDevice_Ina226Reg1V32: return DeviceCode_Ina226Reg1V32;
|
||||
case I2cDevice_Ina226Vdd3V3Sys: return DeviceCode_Ina226Vdd3V3Sys;
|
||||
case I2cDevice_HdmiDdc: return DeviceCode_HdmiDdc;
|
||||
case I2cDevice_HdmiScdc: return DeviceCode_HdmiScdc;
|
||||
case I2cDevice_HdmiHdcp: return DeviceCode_HdmiHdcp;
|
||||
case I2cDevice_Fan53528: return DeviceCode_Fan53528;
|
||||
case I2cDevice_Max77812_3: return DeviceCode_Max77812_3;
|
||||
case I2cDevice_Max77812_2: return DeviceCode_Max77812_2;
|
||||
case I2cDevice_Ina226VddDdr0V6: return DeviceCode_Ina226VddDdr0V6;
|
||||
case I2cDevice_HoagNfcIc: return DeviceCode_HoagNfcIc;
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
|
||||
#include <stratosphere/i2c/i2c_device_name.board.nintendo_nx.hpp>
|
||||
#else
|
||||
/* Error? */
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
namespace ams::i2c {
|
||||
|
||||
enum TransactionOption : u32 {
|
||||
TransactionOption_StartCondition = (1u << 0),
|
||||
TransactionOption_TopCondition = (1u << 1),
|
||||
TransactionOption_MaxBits = (1u << 30),
|
||||
};
|
||||
|
||||
enum AddressingMode : u32 {
|
||||
AddressingMode_SevenBit = 0,
|
||||
};
|
||||
|
||||
enum SpeedMode : u32 {
|
||||
SpeedMode_Normal = 100000,
|
||||
SpeedMode_Fast = 400000,
|
||||
SpeedMode_FastPlus = 1000000,
|
||||
SpeedMode_HighSpeed = 3400000,
|
||||
};
|
||||
|
||||
using I2cCommand = u8;
|
||||
|
||||
}
|
|
@ -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 <vapours.hpp>
|
||||
#include <stratosphere/i2c/i2c_types.hpp>
|
||||
#include <stratosphere/i2c/sf/i2c_sf_i_manager.hpp>
|
||||
|
||||
namespace ams::i2c::server {
|
||||
|
||||
std::shared_ptr<i2c::sf::IManager> GetServiceObject();
|
||||
std::shared_ptr<i2c::sf::IManager> GetServiceObjectPowerBus();
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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/ddsf/ddsf_types.hpp>
|
||||
#include <stratosphere/i2c/i2c_select_device_name.hpp>
|
||||
#include <stratosphere/i2c/sf/i2c_sf_i_session.hpp>
|
||||
|
||||
namespace ams::i2c::sf {
|
||||
|
||||
#define AMS_I2C_I_MANAGER_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out<std::shared_ptr<i2c::sf::ISession>> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out<std::shared_ptr<i2c::sf::ISession>> out, i2c::I2cDevice device) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, HasDevice, (ams::sf::Out<bool> out, i2c::I2cDevice device), hos::Version_Min, hos::Version_5_1_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 3, Result, HasDeviceForDev, (ams::sf::Out<bool> out, i2c::I2cDevice device), hos::Version_Min, hos::Version_5_1_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 4, Result, OpenSession2, (ams::sf::Out<std::shared_ptr<i2c::sf::ISession>> out, DeviceCode device_code), hos::Version_6_0_0 )
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(IManager, AMS_I2C_I_MANAGER_INTERFACE_INFO)
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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::sf {
|
||||
|
||||
#define AMS_I2C_I_SESSION_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, SendOld, (const ams::sf::InBuffer &in_data, i2c::TransactionOption option), hos::Version_Min, hos::Version_5_1_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, ReceiveOld, (const ams::sf::OutBuffer &out_data, i2c::TransactionOption option), hos::Version_Min, hos::Version_5_1_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, ExecuteCommandListOld, (const ams::sf::OutBuffer &rcv_buf, const ams::sf::InPointerArray<i2c::I2cCommand> &command_list), hos::Version_Min, hos::Version_5_1_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 10, Result, Send, (const ams::sf::InAutoSelectBuffer &in_data, i2c::TransactionOption option) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 11, Result, Receive, (const ams::sf::OutAutoSelectBuffer &out_data, i2c::TransactionOption option) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 12, Result, ExecuteCommandList, (const ams::sf::OutAutoSelectBuffer &rcv_buf, const ams::sf::InPointerArray<i2c::I2cCommand> &command_list) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 13, Result, SetRetryPolicy, (s32 max_retry_count, s32 retry_interval_ms), hos::Version_6_0_0 )
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(ISession, AMS_I2C_I_SESSION_INTERFACE_INFO)
|
||||
|
||||
}
|
|
@ -20,7 +20,6 @@ namespace ams::gpio {
|
|||
|
||||
namespace {
|
||||
|
||||
/* TODO: Manager object. */
|
||||
constinit os::SdkMutex g_init_mutex;
|
||||
constinit int g_initialize_count = 0;
|
||||
constinit bool g_remote = false;
|
||||
|
|
86
libraries/libstratosphere/source/i2c/i2c_client_api.cpp
Normal file
86
libraries/libstratosphere/source/i2c/i2c_client_api.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::i2c {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit os::SdkMutex g_init_mutex;
|
||||
constinit int g_initialize_count = 0;
|
||||
|
||||
constinit os::SdkMutex g_i2c_mutex;
|
||||
std::shared_ptr<sf::IManager> g_i2c_manager;
|
||||
constinit int g_i2c_count = 0;
|
||||
|
||||
constinit os::SdkMutex g_i2c_pcv_mutex;
|
||||
std::shared_ptr<sf::IManager> g_i2c_pcv_manager;
|
||||
constinit int g_i2c_pcv_count = 0;
|
||||
|
||||
}
|
||||
|
||||
void InitializeWith(std::shared_ptr<i2c::sf::IManager> &&sp, std::shared_ptr<i2c::sf::IManager> &&sp_pcv) {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
AMS_ABORT_UNLESS(g_initialize_count == 0);
|
||||
|
||||
{
|
||||
std::scoped_lock lk(g_i2c_mutex);
|
||||
g_i2c_manager = std::move(sp);
|
||||
AMS_ABORT_UNLESS(g_i2c_count == 0);
|
||||
g_i2c_count = 1;
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lk(g_i2c_pcv_mutex);
|
||||
g_i2c_pcv_manager = std::move(sp);
|
||||
AMS_ABORT_UNLESS(g_i2c_pcv_count == 0);
|
||||
g_i2c_pcv_count = 1;
|
||||
}
|
||||
|
||||
g_initialize_count = 1;
|
||||
}
|
||||
|
||||
void InitializeEmpty() {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
++g_initialize_count;
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
AMS_ASSERT(g_initialize_count > 0);
|
||||
|
||||
if ((--g_initialize_count) == 0) {
|
||||
{
|
||||
std::scoped_lock lk(g_i2c_mutex);
|
||||
AMS_ASSERT(g_i2c_count > 0);
|
||||
if ((--g_i2c_count) == 0) {
|
||||
g_i2c_manager.reset();
|
||||
}
|
||||
}
|
||||
{
|
||||
std::scoped_lock lk(g_i2c_pcv_mutex);
|
||||
AMS_ASSERT(g_i2c_pcv_count > 0);
|
||||
if ((--g_i2c_pcv_count) == 0) {
|
||||
g_i2c_pcv_manager.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -29,4 +29,15 @@ namespace ams::boot {
|
|||
gpio::driver::Initialize();
|
||||
}
|
||||
|
||||
void InitializeI2cDriverLibrary() {
|
||||
/* Initialize the i2c client library with the server manager object. */
|
||||
i2c::InitializeWith(i2c::server::GetServiceObject(), i2c::server::GetServiceObjectPowerBus());
|
||||
|
||||
/* Initialize the board driver without enabling interrupt handlers. */
|
||||
i2c::driver::board::Initialize();
|
||||
|
||||
/* Initialize the driver library. */
|
||||
i2c::driver::Initialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
namespace ams::boot {
|
||||
|
||||
void InitializeGpioDriverLibrary();
|
||||
void InitializeI2cDriverLibrary();
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue