diff --git a/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp b/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp index 97d6560c..8e71a691 100644 --- a/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp +++ b/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp @@ -33,8 +33,8 @@ //#define AMS_SDMMC_USE_OS_TIMER #define AMS_SDMMC_USE_UTIL_TIMER //#define AMS_SDMMC_ENABLE_MMC_HS400 - //#define AMS_SDMMC_ENABLE_SD_UHS_I - //#define AMS_SDMMC_SET_PLLC4_BASE + #define AMS_SDMMC_ENABLE_SD_UHS_I + #define AMS_SDMMC_SET_PLLC4_BASE //#define AMS_SDMMC_USE_SD_CARD_DETECTOR #elif defined(ATMOSPHERE_IS_MESOSPHERE) diff --git a/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp b/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp index 3a494281..d1ed02b9 100644 --- a/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp +++ b/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp @@ -264,6 +264,9 @@ namespace ams::sdmmc::impl::ClockResetController::reg { /* Check that we have registers we can write to. */ AMS_ABORT_UNLESS(g_clkrst_registers_address != 0); + AMS_LOG("Setting Clock source: target = %u, actual = %u, CLK_SOURCE = %08x\n", target_frequency_khz, *out_actual_frequency_khz, clk_m | static_cast(n)); + AMS_LOG("PLLC4_BASE: %08x\n", ams::reg::Read(g_clkrst_registers_address + CLK_RST_CONTROLLER_PLLC4_BASE)); + /* Update the clock source. */ switch (module) { case Module_Sdmmc1: ams::reg::Write(g_clkrst_registers_address + CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC1, clk_m | static_cast(n)); break; diff --git a/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp b/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp index 9bfff1ad..f45c8e18 100644 --- a/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp +++ b/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp @@ -494,9 +494,11 @@ namespace ams::sdmmc::impl { /* Check that we're in 4bit bus mode. */ IHostController *hc = BaseDeviceAccessor::GetHostController(); R_UNLESS(hc->GetBusWidth() == BusWidth_4Bit, sdmmc::ResultSdCardNot4BitBusWidthAtUhsIMode()); + AMS_LOG("%s\n", "BusWidth good\n"); /* Determine what speed mode/access mode we should switch to. */ R_TRY(this->IssueCommandCheckSupportedFunction(wb, wb_size)); + AMS_LOG("%s\n", "IssueCommandCheckSupportedFunction\n"); SwitchFunctionAccessMode target_am; SpeedMode target_sm; if (max_sm == SpeedMode_SdCardSdr104 && IsSupportedAccessMode(static_cast(wb), SwitchFunctionAccessMode_Sdr104)) { @@ -508,16 +510,21 @@ namespace ams::sdmmc::impl { } else { return sdmmc::ResultSdCardNotSupportSdr104AndSdr50(); } + AMS_LOG("Try Switch to %u %u\n", (u32)target_am, (u32)target_sm); /* Switch the access mode. */ R_TRY(this->SwitchAccessMode(target_am, wb, wb_size)); + AMS_LOG("%s\n", "SwitchAccessMode\n"); /* Set the host controller speed mode and perform tuning using command index 19. */ R_TRY(hc->SetSpeedMode(target_sm)); + AMS_LOG("%s\n", "SetSpeedMode\n"); R_TRY(hc->Tuning(target_sm, 19)); + AMS_LOG("%s\n", "Tuning\n"); /* Check status. */ R_TRY(BaseDeviceAccessor::IssueCommandSendStatus()); + AMS_LOG("%s\n", "IssueCommandSendStatus\n"); return ResultSuccess(); } @@ -573,65 +580,93 @@ namespace ams::sdmmc::impl { /* Wait 1ms for configuration to take. */ WaitMicroSeconds(1000); + AMS_LOG("%s\n", "Did hc->Startup()\n"); + /* Wait an additional 74 clocks for configuration to take. */ WaitClocks(74, hc->GetDeviceClockFrequencyKHz()); + AMS_LOG("%s\n", "Wait 74 clocks\n"); + /* Go to idle state. */ R_TRY(BaseDeviceAccessor::IssueCommandGoIdleState()); + AMS_LOG("%s\n", "Go Idle State\n"); + /* Check whether the spec is under 2.0. */ bool spec_under_2 = false; R_TRY_CATCH(this->IssueCommandSendIfCond()) { R_CATCH(sdmmc::ResultResponseTimeoutError) { spec_under_2 = true; } } R_END_TRY_CATCH; + AMS_LOG("%s\n", "Send If Cond\n"); + /* Set the rca to 0. */ this->sd_card_device.SetRca(0); + AMS_LOG("%s\n", "SetRca\n"); + /* Go to ready state. */ const bool can_use_uhs_i_mode = (max_bw != BusWidth_1Bit) && (max_sm == SpeedMode_SdCardSdr104 || max_sm == SpeedMode_SdCardSdr50); const bool uhs_i_supported = hc->IsSupportedTuning() && hc->IsSupportedBusPower(BusPower_1_8V); R_TRY(this->ChangeToReadyState(spec_under_2, can_use_uhs_i_mode && uhs_i_supported)); + AMS_LOG("%s\n", "ChangeToReadyState\n"); + /* Get the CID. */ R_TRY(BaseDeviceAccessor::IssueCommandAllSendCid(wb, wb_size)); this->sd_card_device.SetCid(wb, wb_size); + AMS_LOG("%s\n", "IssueCommandAllSendCid\n"); + /* Go to stby state and get the RCA. */ R_TRY(this->ChangeToStbyStateAndGetRca()); + AMS_LOG("%s\n", "ChangeToStbyStateAndGetRca\n"); + /* Get the CSD. */ R_TRY(BaseDeviceAccessor::IssueCommandSendCsd(wb, wb_size)); this->sd_card_device.SetCsd(wb, wb_size); + AMS_LOG("%s\n", "IssueCommandSendCsd\n"); R_TRY(this->SetMemoryCapacity(wb)); + AMS_LOG("%s\n", "SetMemoryCapacity\n"); + /* Set the host controller speed mode to default if we're not in uhs i mode. */ if (!this->sd_card_device.IsUhsIMode()) { R_TRY(hc->SetSpeedMode(SpeedMode_SdCardDefaultSpeed)); } + AMS_LOG("%s\n", "SetSpeedMode\n"); /* Issue select card command. */ R_TRY(BaseDeviceAccessor::IssueCommandSelectCard()); + AMS_LOG("%s\n", "IssueCommandSelectCard\n"); /* Set block length to sector size. */ R_TRY(BaseDeviceAccessor::IssueCommandSetBlockLenToSectorSize()); + AMS_LOG("%s\n", "IssueCommandSetBlockLenToSectorSize\n"); + /* Try to disconnect dat3 pullup resistor. */ TryDisconnectDat3PullUpResistor(); + AMS_LOG("%s\n", "TryDisconnectDat3PullUpResistor\n"); /* Get the SCR. */ R_TRY(this->GetScr(wb, wb_size)); const u8 sd_bw = GetSdBusWidths(static_cast(wb)); const bool spec_under_1_1 = IsLessThanSpecification1_1(static_cast(wb)); + AMS_LOG("%s\n", "GetScr\n"); /* Extend the bus width to the largest that we can. */ R_TRY(this->ExtendBusWidth(max_bw, sd_bw)); + AMS_LOG("%s\n", "ExtendBusWidth\n"); /* Extend the bus speed to as fast as we can. */ if (this->sd_card_device.IsUhsIMode()) { R_TRY(this->ExtendBusSpeedAtUhsIMode(max_sm, wb, wb_size)); + AMS_LOG("%s\n", "ExtendBusSpeedAtUhsIMode\n"); } else { R_TRY(this->ExtendBusSpeedAtNonUhsIMode(max_sm, spec_under_1_1, wb, wb_size)); + AMS_LOG("%s\n", "ExtendBusSpeedAtNonUhsIMode\n"); } /* Enable power saving. */ @@ -682,6 +717,8 @@ namespace ams::sdmmc::impl { return ResultSuccess(); } + AMS_LOG("Startup Failed, Result = %08x\n", result.GetValue()); + /* Check if we were removed. */ AMS_SDMMC_CHECK_SD_CARD_REMOVED(); diff --git a/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp b/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp index d69d498e..3e302ff6 100644 --- a/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp +++ b/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp @@ -458,7 +458,7 @@ namespace ams::sdmmc::impl { /* Set the buffer read ready enable, and read status to ensure it takes. */ reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.normal_int_enable, SD_REG_BITS_ENUM(NORMAL_INTERRUPT_BUFFER_READ_READY, ENABLED)); - reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status); + reg::Write(this->sdmmc_registers->sd_host_standard_registers.normal_int_status, reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status)); /* Issue command with clock disabled. */ reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, DISABLE)); @@ -578,6 +578,8 @@ namespace ams::sdmmc::impl { this->drive_strength_calibration_status = sdmmc::ResultSdmmcCompOpen(); } + AMS_LOG("[sdmmc] IsSocMariko(): %d\n", IsSocMariko()); + AMS_LOG("[sdmmc] AUTO_CAL_STATUS: %08x\n", reg::Read(this->sdmmc_registers->auto_cal_status)); break; } @@ -726,6 +728,9 @@ namespace ams::sdmmc::impl { /* Check that the dat lines are all low. */ R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.present_state, SD_REG_BITS_VALUE(PRESENT_STATE_DAT0_3_LINE_SIGNAL_LEVEL, 0b0000)), sdmmc::ResultSdCardNotReadyToVoltageSwitch()); + /* Set Speed Mode. */ + R_TRY(this->SetSpeedMode(SpeedMode_SdCardSdr12)); + /* Set voltage to 1.8V. */ SdHostStandardController::EnsureControl(); R_TRY(this->LowerBusPower()); @@ -746,7 +751,7 @@ namespace ams::sdmmc::impl { R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.host_control2, SD_REG_BITS_ENUM(HOST_CONTROL2_1_8V_SIGNALING_ENABLE, 1_8V_SIGNALING)), sdmmc::ResultSdHostStandardFailSwitchTo1_8V()); /* Enable clock, and wait 1ms. */ - reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, DISABLE)); + reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, ENABLE)); SdHostStandardController::EnsureControl(); WaitMicroSeconds(1000); @@ -858,6 +863,10 @@ namespace ams::sdmmc::impl { } } + AMS_LOG("normal_status: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status)); + AMS_LOG("error_status: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.error_int_status)); + AMS_LOG("HOST_CONTROL2: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.host_control2)); + /* Check if we're using the tuned clock. */ R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.host_control2, SD_REG_BITS_ENUM(HOST_CONTROL2_SAMPLING_CLOCK, USING_TUNED_CLOCK)), sdmmc::ResultTuningFailed()); @@ -889,7 +898,7 @@ namespace ams::sdmmc::impl { } /* If we're at 3.3V, lower to 1.8V. */ - { + if (this->current_bus_power == BusPower_3_3V) { /* pcv::ChangeVoltage(pcv::PowerControlTarget_SdCard, 1800000); */ this->power_controller->LowerBusPower(); diff --git a/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp b/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp index 4c5fba69..d007d9dd 100644 --- a/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp +++ b/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp @@ -394,7 +394,7 @@ namespace ams::sdmmc::impl { APB_MISC_REG_BITS_VALUE(GP_SDMMC1_PAD_CFGPADCTRL_CFG2TMC_SDMMC1_PAD_CAL_DRVUP, drvup)); /* Read to be sure our config takes. */ - reg::Read(apb_address + APB_MISC_GP_EMMC4_PAD_CFGPADCTRL); + reg::Read(apb_address + APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL); } public: Sdmmc1Controller() : SdmmcController(Sdmmc1RegistersPhysicalAddress) {