From 06dcc6bc176ad365114bb6a50a3f31d78fc8cb50 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 20 Nov 2020 22:47:30 -0800 Subject: [PATCH] exo/mariko fatal: disable backlight before we do screen re-init --- .../mariko_fatal/source/fatal_display.cpp | 76 +++++++++++++++++-- .../mariko_fatal/source/fatal_display.hpp | 1 - exosphere/mariko_fatal/source/fatal_main.cpp | 1 - stratosphere/boot/source/boot_main.cpp | 2 - 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/exosphere/mariko_fatal/source/fatal_display.cpp b/exosphere/mariko_fatal/source/fatal_display.cpp index 43f014fe0..e4086757b 100644 --- a/exosphere/mariko_fatal/source/fatal_display.cpp +++ b/exosphere/mariko_fatal/source/fatal_display.cpp @@ -173,7 +173,7 @@ namespace ams::secmon::fatal { } } - void FinalizeFrameBuffer() { + [[maybe_unused]] void FinalizeFrameBuffer() { /* We don't actually support finalizing the framebuffer, so do nothing here. */ } @@ -260,17 +260,79 @@ namespace ams::secmon::fatal { } } - } + void FinalizeDisplay() { + /* TODO: What other configuration is needed, if any? */ + + /* Configure LCD pinmux tristate + passthrough. */ + reg::ClearBits(g_apb_misc_regs + PINMUX_AUX_NFC_EN, reg::EncodeMask(PINMUX_REG_BITS_MASK(AUX_TRISTATE))); + reg::ClearBits(g_apb_misc_regs + PINMUX_AUX_NFC_INT, reg::EncodeMask(PINMUX_REG_BITS_MASK(AUX_TRISTATE))); + reg::ClearBits(g_apb_misc_regs + PINMUX_AUX_LCD_BL_PWM, reg::EncodeMask(PINMUX_REG_BITS_MASK(AUX_TRISTATE))); + reg::ClearBits(g_apb_misc_regs + PINMUX_AUX_LCD_BL_EN, reg::EncodeMask(PINMUX_REG_BITS_MASK(AUX_TRISTATE))); + reg::ClearBits(g_apb_misc_regs + PINMUX_AUX_LCD_RST, reg::EncodeMask(PINMUX_REG_BITS_MASK(AUX_TRISTATE))); + + if (fuse::GetHardwareType() == fuse::HardwareType_Five) { + /* Configure LCD backlight. */ + reg::SetBits(g_gpio_regs + GPIO_PORT6_CNF_1, 0x4); + reg::SetBits(g_gpio_regs + GPIO_PORT6_OE_1, 0x4); + } else { + /* Configure LCD power, VDD. */ + reg::SetBits(g_gpio_regs + GPIO_PORT3_CNF_0, 0x3); + reg::SetBits(g_gpio_regs + GPIO_PORT3_OE_0, 0x3); + reg::SetBits(g_gpio_regs + GPIO_PORT3_OUT_0, 0x1); + util::WaitMicroSeconds(10'000ul); + + reg::SetBits(g_gpio_regs + GPIO_PORT3_OUT_0, 0x2); + util::WaitMicroSeconds(10'000ul); + + /* Configure LCD backlight. */ + reg::SetBits(g_gpio_regs + GPIO_PORT6_CNF_1, 0x7); + reg::SetBits(g_gpio_regs + GPIO_PORT6_OE_1, 0x7); + reg::SetBits(g_gpio_regs + GPIO_PORT6_OUT_1, 0x2); + } + + /* Disable the LCD backlight. */ + if (GetLcdVendor() == 0x2050) { + /* TODO: We're not sure display is alive. How to manage this? */ + /* This is probably incorrect backlight disable for hw-type 5. */ + reg::ClearBits(g_gpio_regs + GPIO_PORT6_OUT_1, 0x1); + } else { + reg::ClearBits(g_gpio_regs + GPIO_PORT6_OUT_1, 0x1); + } + + /* Disable backlight RST/Voltage. */ + reg::ClearBits(g_gpio_regs + GPIO_PORT6_OUT_1, 0x4); + if (GetLcdVendor() == 0x2050) { + util::WaitMicroSeconds(30'000ul); + } else { + util::WaitMicroSeconds(10'000ul); + reg::ClearBits(g_gpio_regs + GPIO_PORT3_OUT_0, 0x2); + util::WaitMicroSeconds(10'000ul); + reg::ClearBits(g_gpio_regs + GPIO_PORT3_OUT_0, 0x1); + util::WaitMicroSeconds(10'000ul); + } + + /* Cut clock to DSI. */ + reg::Write(g_clk_rst_regs + CLK_RST_CONTROLLER_RST_DEV_H_SET, CLK_RST_REG_BITS_ENUM(RST_DEV_H_SET_SET_MIPI_CAL_RST, ENABLE), + CLK_RST_REG_BITS_ENUM(RST_DEV_H_SET_SET_DSI_RST, ENABLE)); + + reg::Write(g_clk_rst_regs + CLK_RST_CONTROLLER_CLK_ENB_H_CLR, CLK_RST_REG_BITS_ENUM(CLK_ENB_H_CLR_CLR_CLK_ENB_MIPI_CAL, ENABLE), + CLK_RST_REG_BITS_ENUM(CLK_ENB_H_CLR_CLR_CLK_ENB_DSI, ENABLE)); + + reg::Write(g_clk_rst_regs + CLK_RST_CONTROLLER_RST_DEV_L_SET, CLK_RST_REG_BITS_ENUM(RST_DEV_L_SET_SET_HOST1X_RST, ENABLE), + CLK_RST_REG_BITS_ENUM(RST_DEV_L_SET_SET_DISP1_RST, ENABLE)); + + reg::Write(g_clk_rst_regs + CLK_RST_CONTROLLER_CLK_ENB_L_CLR, CLK_RST_REG_BITS_ENUM(CLK_ENB_L_CLR_CLR_CLK_ENB_HOST1X, ENABLE), + CLK_RST_REG_BITS_ENUM(CLK_ENB_L_CLR_CLR_CLK_ENB_DISP1, ENABLE)); + + reg::Write(g_dsi_regs + sizeof(u32) * DSI_PAD_CONTROL_0, (DSI_PAD_CONTROL_VS1_PULLDN_CLK | DSI_PAD_CONTROL_VS1_PULLDN(0xF) | DSI_PAD_CONTROL_VS1_PDIO_CLK | DSI_PAD_CONTROL_VS1_PDIO(0xF))); + reg::Write(g_dsi_regs + sizeof(u32) * DSI_POWER_CONTROL, 0); + } - void FinalizeDisplay() { - FinalizeFrameBuffer(); - /* TODO */ - AMS_SECMON_LOG("FinalizeDisplay not yet implemented\n"); } void InitializeDisplay() { /* Ensure that the display is finalized. */ - /* TODO */ + FinalizeDisplay(); /* Setup the framebuffer. */ InitializeFrameBuffer(); diff --git a/exosphere/mariko_fatal/source/fatal_display.hpp b/exosphere/mariko_fatal/source/fatal_display.hpp index 048a06c44..f2d6d6e1c 100644 --- a/exosphere/mariko_fatal/source/fatal_display.hpp +++ b/exosphere/mariko_fatal/source/fatal_display.hpp @@ -24,6 +24,5 @@ namespace ams::secmon::fatal { void InitializeDisplay(); void ShowDisplay(const ams::impl::FatalErrorContext *f_ctx, const Result save_result); - void FinalizeDisplay(); } diff --git a/exosphere/mariko_fatal/source/fatal_main.cpp b/exosphere/mariko_fatal/source/fatal_main.cpp index 7afde1017..34f5b998f 100644 --- a/exosphere/mariko_fatal/source/fatal_main.cpp +++ b/exosphere/mariko_fatal/source/fatal_main.cpp @@ -77,7 +77,6 @@ namespace ams::secmon::fatal { AMS_SECMON_LOG("Showing Display, LCD Vendor = %04x\n", GetLcdVendor()); InitializeDisplay(); ShowDisplay(f_ctx, result); - FinalizeDisplay(); } /* Ensure we have nothing waiting to be logged. */ diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 2e639196c..b5d3e8c21 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -241,8 +241,6 @@ int main(int argc, char **argv) /* Finalize the i2c server library. */ boot::FinalizeI2cDriverLibrary(); - AMS_ABORT_UNLESS(spl::GetSocType() != spl::SocType_Mariko); - /* Tell PM to start boot2. */ R_ABORT_UNLESS(pmshellNotifyBootFinished());