libsdhcdrivers: Actively initialize bus width The default bus width of the card after power up or GO_IDLE (CMD0) is 1 bit. As the HostController is initialzed to 4-bit bus width, the card also needs to switch to 4-bit mode.
diff --git a/libsdhcdrivers/src/mmc.c b/libsdhcdrivers/src/mmc.c index 22d518d..ce09f7a 100644 --- a/libsdhcdrivers/src/mmc.c +++ b/libsdhcdrivers/src/mmc.c
@@ -256,12 +256,17 @@ cmd.rsp_type = MMC_RSP_TYPE_R1b; host_send_command(card, &cmd, NULL, NULL); - /* Set Bus width */ + /** + * The default bus width of the card after power up or GO_IDLE (CMD0) is + * 1 bit. As the HostController is initialzed to 4-bit bus width, + * the card also needs to switch to 4-bit mode. + */ cmd.index = MMC_APP_CMD; cmd.arg = card->raw_rca << 16; cmd.rsp_type = MMC_RSP_TYPE_R1; host_send_command(card, &cmd, NULL, NULL); cmd.index = SD_SET_BUS_WIDTH; + cmd.arg = MMC_MODE_4BIT; host_send_command(card, &cmd, NULL, NULL); /* Set read/write block length for byte addressed standard capacity cards */
diff --git a/libsdhcdrivers/src/mmc.h b/libsdhcdrivers/src/mmc.h index 602172c..ea53a81 100644 --- a/libsdhcdrivers/src/mmc.h +++ b/libsdhcdrivers/src/mmc.h
@@ -75,6 +75,10 @@ #define MMC_VDD_30_31 (1 << 18) #define MMC_VDD_29_30 (1 << 17) +/* Bus width */ +#define MMC_MODE_8BIT 0x04 +#define MMC_MODE_4BIT 0x02 + enum mmc_rsp_type { MMC_RSP_TYPE_NONE = 0,
diff --git a/libsdhcdrivers/src/sdhc.c b/libsdhcdrivers/src/sdhc.c index 7710ef7..08f8d87 100644 --- a/libsdhcdrivers/src/sdhc.c +++ b/libsdhcdrivers/src/sdhc.c
@@ -625,6 +625,11 @@ /* TODO: Select Voltage Level */ + /* Set bus width */ + val = readl(host->base + PROT_CTRL); + val |= MMC_MODE_4BIT; + writel(val, host->base + PROT_CTRL); + /* Wait until the Command and Data Lines are ready. */ while ((readl(host->base + PRES_STATE) & PRES_STATE_CDIHB) || (readl(host->base + PRES_STATE) & PRES_STATE_CIHB));