From affdea9244b083dea4119b98c1b78b46aedb7397 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 10 Nov 2020 05:02:41 -0800 Subject: [PATCH] boot: various bugfixes (b/w logo displays now) --- .../source/i2c/driver/impl/i2c_i2c_session_impl.cpp | 12 ++++++------ .../libstratosphere/source/i2c/i2c_client_api.cpp | 12 ++++++++---- .../source/i2c/i2c_command_list_formatter.cpp | 6 +++--- .../nintendo_nx/impl/pwm_impl_pwm_driver_api.cpp | 4 ++-- .../board/nintendo_nx/impl/pwm_pwm_driver_impl.cpp | 2 +- .../libvapours/include/vapours/tegra/tegra_i2c.hpp | 2 +- .../include/vapours/tegra/tegra_pinmux.hpp | 2 ++ stratosphere/boot/boot.json | 9 +++++++++ stratosphere/boot/source/boot_display.cpp | 5 +++++ stratosphere/boot/source/boot_driver_management.cpp | 12 ++++++++++-- 10 files changed, 47 insertions(+), 19 deletions(-) diff --git a/libraries/libstratosphere/source/i2c/driver/impl/i2c_i2c_session_impl.cpp b/libraries/libstratosphere/source/i2c/driver/impl/i2c_i2c_session_impl.cpp index 83c48991c..413cc4ad5 100644 --- a/libraries/libstratosphere/source/i2c/driver/impl/i2c_i2c_session_impl.cpp +++ b/libraries/libstratosphere/source/i2c/driver/impl/i2c_i2c_session_impl.cpp @@ -67,8 +67,8 @@ namespace ams::i2c::driver::impl { Result I2cSessionImpl::SendHandler(const u8 **cur_cmd, u8 **cur_dst) { /* Read the header bytes. */ - const util::BitPack8 hdr0{*(*cur_cmd++)}; - const util::BitPack8 hdr1{*(*cur_cmd++)}; + const util::BitPack8 hdr0{*((*cur_cmd)++)}; + const util::BitPack8 hdr1{*((*cur_cmd)++)}; /* Decode the header. */ const bool start = hdr0.Get(); @@ -86,8 +86,8 @@ namespace ams::i2c::driver::impl { Result I2cSessionImpl::ReceiveHandler(const u8 **cur_cmd, u8 **cur_dst) { /* Read the header bytes. */ - const util::BitPack8 hdr0{*(*cur_cmd++)}; - const util::BitPack8 hdr1{*(*cur_cmd++)}; + const util::BitPack8 hdr0{*((*cur_cmd)++)}; + const util::BitPack8 hdr1{*((*cur_cmd)++)}; /* Decode the header. */ const bool start = hdr0.Get(); @@ -105,13 +105,13 @@ namespace ams::i2c::driver::impl { Result I2cSessionImpl::ExtensionHandler(const u8 **cur_cmd, u8 **cur_dst) { /* Read the header bytes. */ - const util::BitPack8 hdr0{*(*cur_cmd++)}; + const util::BitPack8 hdr0{*((*cur_cmd)++)}; /* Execute the subcommand. */ switch (hdr0.Get()) { case i2c::impl::SubCommandId_Sleep: { - const util::BitPack8 param{*(*cur_cmd++)}; + const util::BitPack8 param{*((*cur_cmd)++)}; os::SleepThread(TimeSpan::FromMicroSeconds(param.Get())); } diff --git a/libraries/libstratosphere/source/i2c/i2c_client_api.cpp b/libraries/libstratosphere/source/i2c/i2c_client_api.cpp index f0acae7d3..e8d3a74a7 100644 --- a/libraries/libstratosphere/source/i2c/i2c_client_api.cpp +++ b/libraries/libstratosphere/source/i2c/i2c_client_api.cpp @@ -84,15 +84,19 @@ namespace ams::i2c { { std::scoped_lock lk(g_i2c_mutex); AMS_ASSERT(g_i2c_count > 0); - if ((--g_i2c_count) == 0) { - g_i2c_manager.reset(); + if (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(); + if (g_i2c_pcv_count > 0) { + if ((--g_i2c_pcv_count) == 0) { + g_i2c_pcv_manager.reset(); + } } } } diff --git a/libraries/libstratosphere/source/i2c/i2c_command_list_formatter.cpp b/libraries/libstratosphere/source/i2c/i2c_command_list_formatter.cpp index eaf6cbd33..37a6dc65b 100644 --- a/libraries/libstratosphere/source/i2c/i2c_command_list_formatter.cpp +++ b/libraries/libstratosphere/source/i2c/i2c_command_list_formatter.cpp @@ -32,7 +32,7 @@ namespace ams::i2c { util::BitPack8 *cmd_list = static_cast(this->command_list); /* Get references to the header. */ - auto &header0 = cmd_list[this->current_index++]; + auto &header0 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ @@ -54,7 +54,7 @@ namespace ams::i2c { util::BitPack8 *cmd_list = static_cast(this->command_list); /* Get references to the header. */ - auto &header0 = cmd_list[this->current_index++]; + auto &header0 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ @@ -80,7 +80,7 @@ namespace ams::i2c { util::BitPack8 *cmd_list = static_cast(this->command_list); /* Get references to the header. */ - auto &header0 = cmd_list[this->current_index++]; + auto &header0 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ diff --git a/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_impl_pwm_driver_api.cpp b/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_impl_pwm_driver_api.cpp index f292236c3..1b1849d10 100644 --- a/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_impl_pwm_driver_api.cpp +++ b/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_impl_pwm_driver_api.cpp @@ -25,8 +25,8 @@ namespace ams::pwm::driver::board::nintendo_nx::impl { constexpr inline size_t PwmRegistersSize = 0x100; constexpr const ChannelDefinition SupportedChannels[] = { - { pwm::DeviceCode_CpuFan, 0 }, - { pwm::DeviceCode_LcdBacklight, 1 }, + { pwm::DeviceCode_LcdBacklight, 0 }, + { pwm::DeviceCode_CpuFan, 1 }, }; } diff --git a/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_pwm_driver_impl.cpp b/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_pwm_driver_impl.cpp index 0c2e29198..353148e52 100644 --- a/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_pwm_driver_impl.cpp +++ b/libraries/libstratosphere/source/pwm/driver/board/nintendo_nx/impl/pwm_pwm_driver_impl.cpp @@ -141,7 +141,7 @@ namespace ams::pwm::driver::board::nintendo_nx::impl { AMS_ASSERT(device != nullptr); /* Validate the duty. */ - R_UNLESS(0 <= duty && duty < MaxDuty, pwm::ResultInvalidArgument()); + R_UNLESS(0 <= duty && duty <= MaxDuty, pwm::ResultInvalidArgument()); /* Acquire exclusive access to the device registers. */ std::scoped_lock lk(device->SafeCastTo()); diff --git a/libraries/libvapours/include/vapours/tegra/tegra_i2c.hpp b/libraries/libvapours/include/vapours/tegra/tegra_i2c.hpp index 5e09f7928..3f7bd2a15 100644 --- a/libraries/libvapours/include/vapours/tegra/tegra_i2c.hpp +++ b/libraries/libvapours/include/vapours/tegra/tegra_i2c.hpp @@ -54,7 +54,7 @@ DEFINE_I2C_REG(I2C_CNFG_LENGTH, 1, 3); DEFINE_I2C_REG_BIT_ENUM(I2C_CNFG_CMD1, 6, WRITE, READ); DEFINE_I2C_REG_BIT_ENUM(I2C_CNFG_SEND, 9, NOP, GO); -DEFINE_I2C_REG_BIT_ENUM(I2C_CNFG_PACKET_MODE_EN, 9, NOP, GO); +DEFINE_I2C_REG_BIT_ENUM(I2C_CNFG_PACKET_MODE_EN, 10, NOP, GO); DEFINE_I2C_REG_BIT_ENUM(I2C_CNFG_NEW_MASTER_FSM, 11, DISABLE, ENABLE); DEFINE_I2C_REG_THREE_BIT_ENUM(I2C_CNFG_DEBOUNCE_CNT, 12, NO_DEBOUNCE, DEBOUNCE_2T, DEBOUNCE_4T, DEBOUNCE_6T, DEBOUNCE_8T, DEBOUNCE_10T, DEBOUNCE_12T, DEBOUNCE_14T); diff --git a/libraries/libvapours/include/vapours/tegra/tegra_pinmux.hpp b/libraries/libvapours/include/vapours/tegra/tegra_pinmux.hpp index 137a8eaec..c79d2d17a 100644 --- a/libraries/libvapours/include/vapours/tegra/tegra_pinmux.hpp +++ b/libraries/libvapours/include/vapours/tegra/tegra_pinmux.hpp @@ -94,4 +94,6 @@ DEFINE_PINMUX_REG_TWO_BIT_ENUM(AUX_UART3_PM, 0, UARTC, SPI4, RSVD2, RSVD3); DEFINE_PINMUX_REG_TWO_BIT_ENUM(AUX_DVFS_PWM_PM, 0, RSVD0, CLDVFS, SPI3, RSVD3); +DEFINE_PINMUX_REG_TWO_BIT_ENUM(AUX_LCD_BL_PWM_PM, 0, DISPLAYA, PWM0, SOR0, RSVD3); + DEFINE_PINMUX_REG_TWO_BIT_ENUM(AUX_GPIO_PA6_PM, 0, SATA, RSVD1, RSVD2, RSVD3); diff --git a/stratosphere/boot/boot.json b/stratosphere/boot/boot.json index e3e6662f6..b8166d193 100644 --- a/stratosphere/boot/boot.json +++ b/stratosphere/boot/boot.json @@ -123,6 +123,15 @@ "is_io": true } }, + { + "type": "map", + "value": { + "address": "0x7000A000", + "size": "0x1000", + "is_ro": false, + "is_io": true + } + }, { "type": "map", "value": { diff --git a/stratosphere/boot/source/boot_display.cpp b/stratosphere/boot/source/boot_display.cpp index a6dc4d2f0..f6c72b96c 100644 --- a/stratosphere/boot/source/boot_display.cpp +++ b/stratosphere/boot/source/boot_display.cpp @@ -319,6 +319,11 @@ namespace ams::boot { reg::SetBits(g_gpio_regs + GPIO_PORT3_OUT_0, 0x2); os::SleepThread(TimeSpan::FromMilliSeconds(10)); + /* Configure LCD backlight to use PWM. */ + reg::ClearBits(g_gpio_regs + GPIO_PORT6_CNF_1, 0x1); + reg::Write(g_apb_misc_regs + PINMUX_AUX_LCD_BL_PWM, PINMUX_REG_BITS_ENUM(AUX_LCD_BL_PWM_PM, PWM0), + PINMUX_REG_BITS_ENUM(AUX_PUPD, PULL_DOWN)); + /* Configure LCD backlight. */ R_ABORT_UNLESS(pwm::driver::OpenSession(std::addressof(g_lcd_backlight_session), pwm::DeviceCode_LcdBacklight)); pwm::driver::SetPeriod(g_lcd_backlight_session, TimeSpan::FromNanoSeconds(33898)); diff --git a/stratosphere/boot/source/boot_driver_management.cpp b/stratosphere/boot/source/boot_driver_management.cpp index b556529e6..1382c1fe7 100644 --- a/stratosphere/boot/source/boot_driver_management.cpp +++ b/stratosphere/boot/source/boot_driver_management.cpp @@ -50,8 +50,16 @@ namespace ams::boot { } void FinalizeI2cDriverLibrary() { - /* TODO */ - AMS_ABORT(); + /* Finalize the i2c driver library. */ + i2c::driver::Finalize(); + + /* Finalize the i2c client library. */ + i2c::Finalize(); + + /* NOTE: Unknown finalize function is called here by Nintendo. */ + + /* Finalize the pwm client library. */ + pwm::Finalize(); } }