Skip to content

Commit

Permalink
[driver] MMCv2 driver WIP 4/4
Browse files Browse the repository at this point in the history
  • Loading branch information
SamulKyull authored and SamulKyull committed Jun 15, 2024
1 parent 1cf0332 commit d3f4d74
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 129 deletions.
9 changes: 1 addition & 8 deletions board/avaota-a1/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ sunxi_sdhci_t sdhci0 = {
.gpio_cd = {GPIO_PIN(GPIO_PORTF, 6), GPIO_INPUT},
.cd_level = GPIO_LEVEL_LOW,
},
.timing_data = {
.freq_id = MMC_CLK_25M,
.odly = 0,
.sdly = 0,
.spd_md_id = MMC_DS26_SDR12,
.auto_timing = TRUE,
},
};

sunxi_sdhci_t sdhci2 = {
Expand All @@ -87,7 +80,7 @@ sunxi_sdhci_t sdhci2 = {
.clk_ctrl_base = CCU_BASE + CCU_SMHC_BGR_REG,
.clk_base = CCU_BASE + CCU_SMHC2_CLK_REG,
.sdhci_mmc_type = MMC_TYPE_EMMC,
.max_clk = 50 * 1000 * 1000,
.max_clk = 25 * 1000 * 1000,
.width = SMHC_WIDTH_8BIT,
.dma_des_addr = SDRAM_BASE + 0x30080000,
.pinctrl = {
Expand Down
4 changes: 1 addition & 3 deletions include/drivers/mmc/sys-sdhci.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ typedef struct sunxi_sdhci_pinctrl {
typedef struct sunxi_sdhci_timing {
uint32_t odly;
uint32_t sdly;
uint32_t spd_md_id;
uint32_t freq_id;
uint8_t auto_timing;
} sunxi_sdhci_timing_t;

Expand All @@ -116,7 +114,7 @@ typedef struct sunxi_sdhci {
/* Private data */
mmc_t *mmc;
sunxi_sdhci_host_t *mmc_host;
sunxi_sdhci_timing_t timing_data;
sunxi_sdhci_timing_t *timing_data;
} sunxi_sdhci_t;

/**
Expand Down
9 changes: 5 additions & 4 deletions include/drivers/reg/reg-smhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
#define SMHC_RINT_AUTO_COMMAND_DONE (0x1 << 14)
#define SMHC_RINT_END_BIT_ERROR (0x1 << 15)
#define SMHC_RINT_SDIO_INTERRUPT (0x1 << 16)
#define SMHC_RINT_R1B_BUSY_CLEAR (0x1 << 17)
#define SMHC_RINT_CARD_INSERT (0x1 << 30)
#define SMHC_RINT_CARD_REMOVE (0x1 << 31)
#define SMHC_RINT_INTERRUPT_ERROR_BIT \
(SMHC_RINT_RESP_ERROR | SMHC_RINT_RESP_CRC_ERROR | \
SMHC_RINT_DATA_CRC_ERROR | SMHC_RINT_RESP_TIMEOUT | \
SMHC_RINT_DATA_TIMEOUT | SMHC_RINT_VOLTAGE_CHANGE_DONE | \
SMHC_RINT_FIFO_RUN_ERROR | SMHC_RINT_HARD_WARE_LOCKED | \
SMHC_RINT_START_BIT_ERROR | SMHC_RINT_END_BIT_ERROR) /* 0xbfc2 */
SMHC_RINT_DATA_TIMEOUT | SMHC_RINT_FIFO_RUN_ERROR | \
SMHC_RINT_HARD_WARE_LOCKED | SMHC_RINT_START_BIT_ERROR | \
SMHC_RINT_END_BIT_ERROR) /* 0xbbc2 */
#define SMHC_RINT_INTERRUPT_DONE_BIT \
(SMHC_RINT_AUTO_COMMAND_DONE | SMHC_RINT_DATA_OVER | \
SMHC_RINT_COMMAND_DONE | SMHC_RINT_VOLTAGE_CHANGE_DONE)
Expand Down Expand Up @@ -261,4 +262,4 @@ typedef struct {
volatile uint32_t vers; /* (0x300) SMHC Version Register */
} sdhci_reg_t;

#endif // __REG_SMHC_H__
#endif// __REG_SMHC_H__
45 changes: 9 additions & 36 deletions src/drivers/mmc/sys-mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,28 +1612,18 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) {
} else {
/* EMMC */
if (mmc->card_caps & MMC_MODE_8BIT) {
mmc->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_HS400;
mmc->speed_mode = MMC_HS400;
if ((mmc->card_caps & MMC_MODE_HS400)) {
/* firstly, switch to HS-DDR 8 bit */
err = sunxi_mmc_mmc_switch_bus_width(sdhci, MMC_HSDDR52_DDR50, SMHC_WIDTH_8BIT);
if (err) {
printk_error("SMHC: HS400 switch to DDR mode fail\n");
return err;
}

/* then, switch to HS400 */
err = sunxi_mmc_mmc_switch_bus_mode(sdhci, MMC_HS400, SMHC_WIDTH_8BIT);
/* Set the card to use 8 bit */
if ((mmc->card_caps & MMC_MODE_DDR_52MHz)) {
/* Set the card to use 8 bit ddr */
err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_DDR_8);
if (err) {
printk_error("SMHC: switch to HS400 mode fail\n");
printk_error("SMHC: switch bus width failed\n");
return err;
}
mmc->tran_speed = sdhci->max_clk;

sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_8BIT);
} else {
/* Set the card to use 8 bit */
} else if ((mmc->card_caps & MMC_MODE_DDR_52MHz)) {
/* Set the card to use 8 bit ddr */
err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_DDR_8);
err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
if (err) {
printk_error("SMHC: switch bus width failed\n");
return err;
Expand Down Expand Up @@ -1752,7 +1742,7 @@ int sunxi_mmc_init(void *sdhci_hdl) {
return err;
}
}

printk_debug("SMHC: Try to init SD Card\n");
err = sunxi_mmc_send_if_cond(sdhci);
if (err) {
Expand All @@ -1778,23 +1768,6 @@ int sunxi_mmc_init(void *sdhci_hdl) {
printk_error("SMHC%d: SD/MMC Probe failed, err %d\n", sdhci->id, err);
}

#define CONFIG_SDMMC_SPEED_TEST_SIZE 4096

memset((void *) 0x40000000, 0xff, 0x20000);

uint32_t start = time_ms();
sunxi_mmc_read_blocks(sdhci, (uint8_t *) (0x40000000), 0, CONFIG_SDMMC_SPEED_TEST_SIZE);
uint32_t test_time = time_ms() - start;

printk_debug("SDMMC: speedtest %uKB in %ums at %uKB/S\n",
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / 1024, test_time,
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / test_time);

while (1) {
/* code */
}


return err;
}

Expand Down
Loading

0 comments on commit d3f4d74

Please sign in to comment.