From 732a6159f7b01f1ef4146c671e7ffc684e51f424 Mon Sep 17 00:00:00 2001 From: hexkyz Date: Sat, 20 Apr 2019 17:30:03 +0100 Subject: [PATCH] fusee: Properly finalize SDMMC1 (fixes 8.0.0 issues with PCV) --- fusee/fusee-primary/src/sdmmc/sdmmc_core.c | 3 +++ fusee/fusee-secondary/src/nxfs.c | 26 ++++++++++++++++++-- fusee/fusee-secondary/src/sdmmc/sdmmc_core.c | 3 +++ sept/sept-secondary/src/sdmmc/sdmmc_core.c | 3 +++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fusee/fusee-primary/src/sdmmc/sdmmc_core.c b/fusee/fusee-primary/src/sdmmc/sdmmc_core.c index 3c513de65..6e2093916 100644 --- a/fusee/fusee-primary/src/sdmmc/sdmmc_core.c +++ b/fusee/fusee-primary/src/sdmmc/sdmmc_core.c @@ -1202,6 +1202,9 @@ void sdmmc_finish(sdmmc_t *sdmmc) /* Power cycle for 100ms without power. */ mdelay(100); + + /* Disable the regulator. */ + max77620_regulator_enable(REGULATOR_LDO2, 0); } /* Force a register read to refresh the clock control value. */ diff --git a/fusee/fusee-secondary/src/nxfs.c b/fusee/fusee-secondary/src/nxfs.c index f35d5fe9a..4094b20e0 100644 --- a/fusee/fusee-secondary/src/nxfs.c +++ b/fusee/fusee-secondary/src/nxfs.c @@ -52,7 +52,8 @@ SdmmcPartitionNum g_current_emmc_partition = SDMMC_PARTITION_INVALID; static int mmc_partition_initialize(device_partition_t *devpart) { mmc_partition_info_t *mmcpart = (mmc_partition_info_t *)devpart->device_struct; - if (devpart->read_cipher != NULL || devpart->write_cipher != NULL) { + /* Allocate the crypto work buffer. */ + if ((devpart->read_cipher != NULL) || (devpart->write_cipher != NULL)) { devpart->crypto_work_buffer = memalign(16, devpart->sector_size * 16); if (devpart->crypto_work_buffer == NULL) { return ENOMEM; @@ -70,6 +71,7 @@ static int mmc_partition_initialize(device_partition_t *devpart) { g_ahb_redirect_enabled = true; } + /* Initialize hardware. */ if (mmcpart->device == &g_sd_device) { if (!g_sd_device_initialized) { int rc = sdmmc_device_sd_init(mmcpart->device, &g_sd_sdmmc, SDMMC_BUS_WIDTH_4BIT, SDMMC_SPEED_SDR104) ? 0 : EIO; @@ -94,13 +96,33 @@ static int mmc_partition_initialize(device_partition_t *devpart) { } static void mmc_partition_finalize(device_partition_t *devpart) { - free(devpart->crypto_work_buffer); + mmc_partition_info_t *mmcpart = (mmc_partition_info_t *)devpart->device_struct; + + /* Finalize hardware. */ + if (mmcpart->device == &g_sd_device) { + if (g_sd_device_initialized) { + sdmmc_device_finish(&g_sd_device); + g_sd_device_initialized = false; + } + devpart->initialized = false; + } else if (mmcpart->device == &g_emmc_device) { + if (g_emmc_device_initialized) { + sdmmc_device_finish(&g_emmc_device); + g_emmc_device_initialized = false; + } + devpart->initialized = false; + } /* Disable AHB redirection if necessary. */ if (g_ahb_redirect_enabled) { mc_disable_ahb_redirect(); g_ahb_redirect_enabled = false; } + + /* Free the crypto work buffer. */ + if (devpart->crypto_work_buffer != NULL) { + free(devpart->crypto_work_buffer); + } } static int mmc_partition_read(device_partition_t *devpart, void *dst, uint64_t sector, uint64_t num_sectors) { diff --git a/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c b/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c index 3c513de65..6e2093916 100644 --- a/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c +++ b/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c @@ -1202,6 +1202,9 @@ void sdmmc_finish(sdmmc_t *sdmmc) /* Power cycle for 100ms without power. */ mdelay(100); + + /* Disable the regulator. */ + max77620_regulator_enable(REGULATOR_LDO2, 0); } /* Force a register read to refresh the clock control value. */ diff --git a/sept/sept-secondary/src/sdmmc/sdmmc_core.c b/sept/sept-secondary/src/sdmmc/sdmmc_core.c index 3c513de65..6e2093916 100644 --- a/sept/sept-secondary/src/sdmmc/sdmmc_core.c +++ b/sept/sept-secondary/src/sdmmc/sdmmc_core.c @@ -1202,6 +1202,9 @@ void sdmmc_finish(sdmmc_t *sdmmc) /* Power cycle for 100ms without power. */ mdelay(100); + + /* Disable the regulator. */ + max77620_regulator_enable(REGULATOR_LDO2, 0); } /* Force a register read to refresh the clock control value. */