diff --git a/libraries/libstratosphere/include/stratosphere/i2c/driver/i2c_select_driver_api.hpp b/libraries/libstratosphere/include/stratosphere/i2c/driver/i2c_select_driver_api.hpp index 3606b11a1..ce5f587bd 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/driver/i2c_select_driver_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/driver/i2c_select_driver_api.hpp @@ -31,7 +31,7 @@ #else - #error "Unknown board for ams::gpio::driver::" + #error "Unknown board for ams::i2c::driver::" #endif diff --git a/libraries/libstratosphere/include/stratosphere/i2c/i2c_device_name.board.nintendo_nx.hpp b/libraries/libstratosphere/include/stratosphere/i2c/i2c_device_name.board.nintendo_nx.hpp index 46a6853cd..f9706f812 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/i2c_device_name.board.nintendo_nx.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/i2c_device_name.board.nintendo_nx.hpp @@ -19,6 +19,46 @@ namespace ams::i2c { + enum I2cBus { + I2cBus_I2c1 = 0, + I2cBus_I2c2 = 1, + I2cBus_I2c3 = 2, + I2cBus_I2c4 = 3, + I2cBus_I2c5 = 4, + I2cBus_I2c6 = 5, + }; + + constexpr inline const DeviceCode DeviceCode_I2c1 = 0x02000001; + constexpr inline const DeviceCode DeviceCode_I2c2 = 0x02000002; + constexpr inline const DeviceCode DeviceCode_I2c3 = 0x02000003; + constexpr inline const DeviceCode DeviceCode_I2c4 = 0x02000004; + constexpr inline const DeviceCode DeviceCode_I2c5 = 0x02000005; + constexpr inline const DeviceCode DeviceCode_I2c6 = 0x02000006; + + constexpr inline DeviceCode ConvertToDeviceCode(I2cBus bus) { + switch (bus) { + case I2cBus_I2c1: return DeviceCode_I2c1; + case I2cBus_I2c2: return DeviceCode_I2c2; + case I2cBus_I2c3: return DeviceCode_I2c3; + case I2cBus_I2c4: return DeviceCode_I2c4; + case I2cBus_I2c5: return DeviceCode_I2c5; + case I2cBus_I2c6: return DeviceCode_I2c6; + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + + constexpr inline DeviceCode ConvertToI2cBus(DeviceCode dc) { + switch (dc.GetInternalValue()) { + case DeviceCode_I2c1.GetInternalValue(): return I2cBus_I2c1; + case DeviceCode_I2c2.GetInternalValue(): return I2cBus_I2c2; + case DeviceCode_I2c3.GetInternalValue(): return I2cBus_I2c3; + case DeviceCode_I2c4.GetInternalValue(): return I2cBus_I2c4; + case DeviceCode_I2c5.GetInternalValue(): return I2cBus_I2c5; + case DeviceCode_I2c6.GetInternalValue(): return I2cBus_I2c6; + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + enum I2cDevice : u32 { I2cDevice_ClassicController = 0, I2cDevice_Ftm3bd56 = 1, diff --git a/libraries/libstratosphere/include/stratosphere/i2c/i2c_types.hpp b/libraries/libstratosphere/include/stratosphere/i2c/i2c_types.hpp index 9702d13fe..17bfc429d 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/i2c_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/i2c_types.hpp @@ -20,7 +20,7 @@ namespace ams::i2c { enum TransactionOption : u32 { TransactionOption_StartCondition = (1u << 0), - TransactionOption_TopCondition = (1u << 1), + TransactionOption_StopCondition = (1u << 1), TransactionOption_MaxBits = (1u << 30), }; @@ -29,7 +29,7 @@ namespace ams::i2c { }; enum SpeedMode : u32 { - SpeedMode_Normal = 100000, + SpeedMode_Standard = 100000, SpeedMode_Fast = 400000, SpeedMode_FastPlus = 1000000, SpeedMode_HighSpeed = 3400000, diff --git a/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_bus_device_map.inc b/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_bus_device_map.inc new file mode 100644 index 000000000..30170202b --- /dev/null +++ b/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_bus_device_map.inc @@ -0,0 +1,71 @@ +/* + * 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 . + */ + +/* NOTE: This file is auto-generated by i2cgen.py, do not edit manually. */ + +constexpr inline const I2cDeviceDefinition I2c1DeviceList[] = { + { DeviceCode_ClassicController, 0x52 }, + { DeviceCode_Nct72, 0x4C }, + { DeviceCode_Alc5639, 0x1C }, + { DeviceCode_Bq24193, 0x6B }, + { DeviceCode_Max17050, 0x36 }, + { DeviceCode_Bm92t30mwv, 0x18 }, +}; + +constexpr inline const I2cDeviceDefinition I2c2DeviceList[] = { + { DeviceCode_Ina226Vdd15v0Hb, 0x40 }, + { DeviceCode_Ina226VsysCpuDs, 0x41 }, + { DeviceCode_Ina226VsysGpuDs, 0x44 }, + { DeviceCode_Ina226VsysDdrDs, 0x45 }, + { DeviceCode_Ina226VsysAp, 0x46 }, + { DeviceCode_Ina226VsysBlDs, 0x47 }, + { DeviceCode_Bh1730, 0x29 }, + { DeviceCode_Ina226VsysCore, 0x48 }, + { DeviceCode_Ina226Soc1V8, 0x49 }, + { DeviceCode_Ina226Lpddr1V8, 0x4A }, + { DeviceCode_Ina226Reg1V32, 0x4B }, + { DeviceCode_Ina226Vdd3V3Sys, 0x4D }, + { DeviceCode_Ina226VddDdr0V6, 0x4E }, + { DeviceCode_HoagNfcIc, 0x08 }, +}; + +constexpr inline const I2cDeviceDefinition I2c3DeviceList[] = { + { DeviceCode_Ftm3bd56, 0x49 }, +}; + +constexpr inline const I2cDeviceDefinition I2c4DeviceList[] = { + { DeviceCode_HdmiDdc, 0x50 }, + { DeviceCode_HdmiScdc, 0x54 }, + { DeviceCode_HdmiHdcp, 0x3A }, +}; + +constexpr inline const I2cDeviceDefinition I2c5DeviceList[] = { + { DeviceCode_Max77620Rtc, 0x68 }, + { DeviceCode_Max77620Pmic, 0x3C }, + { DeviceCode_Max77621Cpu, 0x1B }, + { DeviceCode_Max77621Gpu, 0x1C }, + { DeviceCode_Fan53528, 0x52 }, + { DeviceCode_Max77812_3, 0x31 }, + { DeviceCode_Max77812_2, 0x33 }, +}; + +constexpr inline const I2cBusDefinition I2cBusList[] = { + { DeviceCode_I2c1, 0x7000C000, 0x100, SpeedMode_Standard, 70, I2c1DeviceList, util::size(I2c1DeviceList) }, + { DeviceCode_I2c2, 0x7000C400, 0x100, SpeedMode_Fast, 116, I2c2DeviceList, util::size(I2c2DeviceList) }, + { DeviceCode_I2c3, 0x7000C500, 0x100, SpeedMode_Fast, 124, I2c3DeviceList, util::size(I2c3DeviceList) }, + { DeviceCode_I2c4, 0x7000C700, 0x100, SpeedMode_Standard, 152, I2c4DeviceList, util::size(I2c4DeviceList) }, + { DeviceCode_I2c5, 0x7000D000, 0x100, SpeedMode_Fast, 85, I2c5DeviceList, util::size(I2c5DeviceList) }, +}; diff --git a/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_driver_api.cpp b/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_driver_api.cpp new file mode 100644 index 000000000..da96da9db --- /dev/null +++ b/libraries/libstratosphere/source/i2c/driver/board/nintendo_nx/i2c_driver_api.cpp @@ -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 . + */ +#include + +namespace ams::i2c::driver::board::nintendo_nx { + + namespace { + + struct I2cDeviceDefinition { + DeviceCode device_code; + u8 slave_address; + }; + + struct I2cBusDefinition { + DeviceCode device_code; + dd::PhysicalAddress registers_phys_addr; + size_t registers_size; + SpeedMode speed_mode; + os::InterruptName interrupt_name; + const I2cDeviceDefinition *devices; + size_t num_devices; + }; + + #include "i2c_bus_device_map.inc" + + } + + void Initialize() { + /* TODO */ + } + +}