git subrepo pull --force emummc
subrepo: subdir: "emummc" merged: "2fc47cbb8" upstream: origin: "https://github.com/lulle2007200/emuMMC.git" branch: "develop" commit: "2fc47cbb8" git-subrepo: version: "0.4.9" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "30db3b8"
This commit is contained in:
72
emummc/source/emmc/nx_emmc.c
vendored
72
emummc/source/emmc/nx_emmc.c
vendored
@@ -18,6 +18,8 @@
|
||||
#include "../utils/types.h"
|
||||
#include "nx_emmc.h"
|
||||
|
||||
static u32 emmc_mode = EMMC_MMC_HS400;
|
||||
|
||||
int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf)
|
||||
{
|
||||
// The last LBA is inclusive.
|
||||
@@ -33,3 +35,73 @@ int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_o
|
||||
return 0;
|
||||
return sdmmc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||
}
|
||||
|
||||
int emmc_init_retry(bool power_cycle)
|
||||
{
|
||||
u32 bus_width = SDMMC_BUS_WIDTH_8;
|
||||
u32 type = SDHCI_TIMING_MMC_HS400;
|
||||
|
||||
// Power cycle SD eMMC.
|
||||
if (power_cycle)
|
||||
{
|
||||
emmc_mode--;
|
||||
nx_emmc_end();
|
||||
}
|
||||
|
||||
// Get init parameters.
|
||||
switch (emmc_mode)
|
||||
{
|
||||
case EMMC_INIT_FAIL: // Reset to max.
|
||||
return 0;
|
||||
case EMMC_1BIT_HS52:
|
||||
bus_width = SDMMC_BUS_WIDTH_1;
|
||||
type = SDHCI_TIMING_MMC_HS52;
|
||||
break;
|
||||
case EMMC_8BIT_HS52:
|
||||
type = SDHCI_TIMING_MMC_HS52;
|
||||
break;
|
||||
case EMMC_MMC_HS200:
|
||||
type = SDHCI_TIMING_MMC_HS200;
|
||||
break;
|
||||
case EMMC_MMC_HS400:
|
||||
type = SDHCI_TIMING_MMC_HS400;
|
||||
break;
|
||||
default:
|
||||
emmc_mode = EMMC_MMC_HS400;
|
||||
}
|
||||
|
||||
return sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, bus_width, type);
|
||||
}
|
||||
|
||||
void nx_emmc_end() { sdmmc_storage_end(&emmc_storage); }
|
||||
|
||||
bool nx_emmc_initialize(bool power_cycle)
|
||||
{
|
||||
// Reset mode in case of previous failure.
|
||||
if (emmc_mode == EMMC_INIT_FAIL)
|
||||
emmc_mode = EMMC_MMC_HS400;
|
||||
|
||||
if (power_cycle)
|
||||
nx_emmc_end();
|
||||
|
||||
int res = !emmc_init_retry(false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!res)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
if (emmc_mode == EMMC_INIT_FAIL)
|
||||
break;
|
||||
else
|
||||
res = !emmc_init_retry(true);
|
||||
}
|
||||
}
|
||||
|
||||
nx_emmc_end();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int nx_emmc_set_partition(u32 partition) { return sdmmc_storage_set_mmc_partition(&emmc_storage, partition); }
|
||||
|
||||
Reference in New Issue
Block a user