diff --git a/board/avaota-a1/board.c b/board/avaota-a1/board.c index be3a28de..4d00348e 100644 --- a/board/avaota-a1/board.c +++ b/board/avaota-a1/board.c @@ -58,8 +58,8 @@ sunxi_sdhci_t sdhci0 = { .clk_ctrl_base = CCU_BASE + CCU_SMHC_BGR_REG, .clk_base = CCU_BASE + CCU_SMHC0_CLK_REG, .sdhci_mmc_type = MMC_TYPE_SD, - .max_clk = 200 * 1000 * 1000, - .width = SMHC_WIDTH_4BIT, + .max_clk = MMC_CLK_50M, + .width = 50000000, .dma_des_addr = SDRAM_BASE + 0x30080000, .pinctrl = { .gpio_clk = {GPIO_PIN(GPIO_PORTF, 2), GPIO_PERIPH_MUX2}, @@ -80,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 = 25 * 1000 * 1000, + .max_clk = 25000000, .width = SMHC_WIDTH_8BIT, .dma_des_addr = SDRAM_BASE + 0x30080000, .pinctrl = { diff --git a/include/drivers/mmc/sys-mmc.h b/include/drivers/mmc/sys-mmc.h index 70bf7dab..a4ba910f 100644 --- a/include/drivers/mmc/sys-mmc.h +++ b/include/drivers/mmc/sys-mmc.h @@ -378,20 +378,20 @@ typedef struct mmc { int sunxi_mmc_init(void *sdhci_hdl); /** - * @brief Reads blocks from the SD/MMC card. + * @brief Read blocks from the Sunxi MMC block device * - * This function reads blocks from the SD/MMC card starting from the specified block address. - * It supports reading multiple blocks and handles high capacity cards appropriately. + * This function reads a specified number of blocks from the Sunxi MMC block device + * and stores the data into the destination buffer. * - * @param sdhci Pointer to the SDHCI controller structure. - * @param dst Pointer to the destination buffer where the data will be stored. - * @param start Start block address from where to read the data. - * @param blkcnt Number of blocks to read. - * @return Number of blocks read on success, 0 otherwise. + * @param sdhci Pointer to the Sunxi SD Host Controller instance + * @param dst Pointer to the destination buffer where the read data will be stored + * @param start The starting block number to read from + * @param blkcnt The number of blocks to read + * + * @return Returns 0 on success, or an error code if the operation fails */ uint32_t sunxi_mmc_blk_read(void *sdhci, void *dst, uint32_t start, uint32_t blkcnt); - #ifdef __cplusplus } #endif// __cplusplus diff --git a/include/drivers/mmc/sys-sdcard.h b/include/drivers/mmc/sys-sdcard.h index 5e9a33d5..70e15084 100644 --- a/include/drivers/mmc/sys-sdcard.h +++ b/include/drivers/mmc/sys-sdcard.h @@ -28,22 +28,33 @@ typedef struct { extern sdmmc_pdata_t card0; /** - * Initialize the SDMMC controller with the specified platform data and SDHCI driver. + * @brief Initialize the SD/MMC interface * - * @param data Pointer to the SDMMC platform data structure. - * @param hci Pointer to the SDHCI driver instance. - * @return 0 if successful, or an error code if failed. + * Initializes the SD/MMC interface using the provided data structure and SD Host Controller instance. + * It sets the SD Host Controller instance and the online status in the data structure, and then initializes + * the MMC device. If the initialization is successful, it prints a message indicating the type of card detected + * and returns 0; otherwise, it returns -1. + * + * @param data Pointer to the SD/MMC platform data structure + * @param hci Pointer to the Sunxi SD Host Controller instance + * + * @return Returns 0 on success, or -1 if the initialization fails */ int sdmmc_init(sdmmc_pdata_t *data, sunxi_sdhci_t *hci); /** - * Read data from the SDMMC card into the provided buffer. + * @brief Read blocks from the SD/MMC device + * + * Reads a specified number of blocks from the SD/MMC device using the provided platform data structure, + * destination buffer, block number, and block count. It calls the underlying function for reading blocks + * from the Sunxi MMC block device and returns the result. + * + * @param data Pointer to the SD/MMC platform data structure + * @param buf Pointer to the destination buffer where the read data will be stored + * @param blkno The starting block number to read from + * @param blkcnt The number of blocks to read * - * @param data Pointer to the SDMMC platform data structure. - * @param buf Pointer to the destination buffer to store the read data. - * @param blkno The starting block number to read from. - * @param blkcnt The number of blocks to read. - * @return The total number of bytes read, or an error code if failed. + * @return Returns 0 on success, or an error code if the operation fails */ uint32_t sdmmc_blk_read(sdmmc_pdata_t *data, uint8_t *buf, uint32_t blkno, uint32_t blkcnt); diff --git a/src/drivers/mmc/sys-mmc.c b/src/drivers/mmc/sys-mmc.c index 8edf99a8..7b3cea0b 100644 --- a/src/drivers/mmc/sys-mmc.c +++ b/src/drivers/mmc/sys-mmc.c @@ -187,19 +187,19 @@ static int sunxi_mmc_send_status(sunxi_sdhci_t *sdhci, uint32_t timeout) { do { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC%u: Send status failed\n", sdhci->id); + printk_warning("SMHC%u: Send status failed\n", sdhci->id); return err; } else if (cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) break; mdelay(1); if (cmd.response[0] & MMC_STATUS_MASK) { - printk_error("SMHC%u: Status Error: 0x%08X\n", sdhci->id, cmd.response[0]); + printk_warning("SMHC%u: Status Error: 0x%08X\n", sdhci->id, cmd.response[0]); return COMM_ERR; } } while (timeout--); if (!timeout) { - printk_error("SMHC%u: Timeout waiting card ready\n", sdhci->id); + printk_warning("SMHC%u: Timeout waiting card ready\n", sdhci->id); return TIMEOUT; } @@ -269,7 +269,7 @@ static uint32_t sunxi_mmc_read_blocks(sunxi_sdhci_t *sdhci, void *dst, uint32_t data.flags = MMC_DATA_READ; if (sunxi_sdhci_xfer(sdhci, &cmd, &data)) { - printk_error("SMHC: read block failed\n"); + printk_warning("SMHC: read block failed\n"); return 0; } @@ -279,7 +279,7 @@ static uint32_t sunxi_mmc_read_blocks(sunxi_sdhci_t *sdhci, void *dst, uint32_t cmd.resp_type = MMC_RSP_R1b; cmd.flags = 0; if (sunxi_sdhci_xfer(sdhci, &cmd, NULL)) { - printk_error("SMHC: failed to send stop command\n"); + printk_warning("SMHC: failed to send stop command\n"); return 0; } @@ -312,7 +312,7 @@ static int sunxi_mmc_go_idle(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: idle failed\n"); + printk_warning("SMHC: idle failed\n"); return err; } mdelay(2); @@ -347,7 +347,7 @@ static int sunxi_mmc_sd_send_op_cond(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send app cmd failed\n"); + printk_warning("SMHC: send app cmd failed\n"); return err; } @@ -365,7 +365,7 @@ static int sunxi_mmc_sd_send_op_cond(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send cmd41 failed\n"); + printk_warning("SMHC: send cmd41 failed\n"); return err; } @@ -374,7 +374,7 @@ static int sunxi_mmc_sd_send_op_cond(sunxi_sdhci_t *sdhci) { } while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);// Wait for card initialization and decrement timeout if (timeout <= 0) { - printk_error("SMHC: wait card init failed\n"); + printk_warning("SMHC: wait card init failed\n"); return UNUSABLE_ERR; } @@ -393,7 +393,7 @@ static int sunxi_mmc_sd_send_op_cond(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: spi read ocr failed\n"); + printk_warning("SMHC: spi read ocr failed\n"); return err; } } @@ -440,7 +440,7 @@ static int sunxi_mmc_mmc_send_op_cond(sunxi_sdhci_t *sdhci) { // Send command to check card capabilities err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send op cond failed\n"); + printk_warning("SMHC: send op cond failed\n"); return err; } @@ -460,7 +460,7 @@ static int sunxi_mmc_mmc_send_op_cond(sunxi_sdhci_t *sdhci) { // Send command to check card capabilities err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send op cond failed\n"); + printk_warning("SMHC: send op cond failed\n"); return err; } @@ -469,7 +469,7 @@ static int sunxi_mmc_mmc_send_op_cond(sunxi_sdhci_t *sdhci) { } while (!(cmd.response[0] & OCR_BUSY) && timeout--);// Wait for card initialization and decrement timeout if (timeout <= 0) { - printk_error("SMHC: wait for mmc init failed\n"); + printk_warning("SMHC: wait for mmc init failed\n"); return UNUSABLE_ERR;// Indicate failure to initialize the card within the timeout } @@ -532,7 +532,7 @@ static int sunxi_mmc_send_ext_csd(sunxi_sdhci_t *sdhci, char *ext_csd) { err = sunxi_sdhci_xfer(sdhci, &cmd, &data); if (err) - printk_error("SMHC: send ext csd failed\n"); + printk_warning("SMHC: send ext csd failed\n"); return err;// Return the error code (0 if successful) } @@ -569,14 +569,14 @@ static int sunxi_mmc_switch(sunxi_sdhci_t *sdhci, uint8_t set, uint8_t index, ui // Send the SWITCH command to the card ret = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (ret) { - printk_error("SMHC: switch failed\n"); + printk_warning("SMHC: switch failed\n"); } /* for re-update sample phase */ // Update clock phase after sending command 6 ret = sunxi_sdhci_update_phase(sdhci); if (ret) { - printk_error("SMHC: update clock failed after send cmd6\n"); + printk_warning("SMHC: update clock failed after send cmd6\n"); return ret; } @@ -624,7 +624,7 @@ static int sunxi_mmc_mmc_change_freq(sunxi_sdhci_t *sdhci) { // Get the extended CSD data from the card err = sunxi_mmc_send_ext_csd(sdhci, ext_csd); if (err) { - printk_error("SMHC: get ext csd failed\n"); + printk_warning("SMHC: get ext csd failed\n"); return err; } @@ -640,14 +640,14 @@ static int sunxi_mmc_mmc_change_freq(sunxi_sdhci_t *sdhci) { } while (retry--); if (err) { - printk_error("SMHC: change to hs failed\n"); + printk_warning("SMHC: change to hs failed\n"); return err; } // Check if the frequency change was successful err = sunxi_mmc_send_ext_csd(sdhci, ext_csd); if (err) { - printk_error("SMHC: send ext csd faild\n"); + printk_warning("SMHC: send ext csd faild\n"); return err; } @@ -751,7 +751,7 @@ static int sunxi_mmc_sd_change_freq(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: Send app cmd failed\n"); + printk_warning("SMHC: Send app cmd failed\n"); return err; } @@ -773,7 +773,7 @@ static int sunxi_mmc_sd_change_freq(sunxi_sdhci_t *sdhci) { if (err) { if (timeout--) goto retry_scr; - printk_error("SMHC: Send scr failed\n"); + printk_warning("SMHC: Send scr failed\n"); return err; } @@ -807,7 +807,7 @@ static int sunxi_mmc_sd_change_freq(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_sd_switch(sdhci, SD_SWITCH_CHECK, 0, 1, (uint8_t *) &switch_status); if (err) { - printk_error("SMHC: Check high speed status faild\n"); + printk_warning("SMHC: Check high speed status faild\n"); return err; } @@ -823,13 +823,13 @@ static int sunxi_mmc_sd_change_freq(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_sd_switch(sdhci, SD_SWITCH_SWITCH, 0, 1, (uint8_t *) &switch_status); if (err) { - printk_error("SMHC: switch to high speed failed\n"); + printk_warning("SMHC: switch to high speed failed\n"); return err; } err = sunxi_sdhci_update_phase(sdhci); if (err) { - printk_error("SMHC: update clock failed after send cmd6 to switch to sd high speed mode\n"); + printk_warning("SMHC: update clock failed after send cmd6 to switch to sd high speed mode\n"); return err; } @@ -939,7 +939,7 @@ static int sunxi_mmc_mmc_switch_ds(sunxi_sdhci_t *sdhci) { // Check if card supports DS mode if (!(mmc->card_caps && MMC_MODE_HS)) { - printk_error("SMHC: Card does not support DS mode\n"); + printk_warning("SMHC: Card does not support DS mode\n"); return -1; } @@ -947,7 +947,7 @@ static int sunxi_mmc_mmc_switch_ds(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_BC); if (err) { - printk_error("SMHC: Failed to change to DS mode\n"); + printk_warning("SMHC: Failed to change to DS mode\n"); return err; } @@ -976,7 +976,7 @@ static int sunxi_mmc_mmc_switch_hs(sunxi_sdhci_t *sdhci) { // Check if card supports HS mode if (!(mmc->card_caps && MMC_MODE_HS_52MHz)) { - printk_error("SMHC: Card does not support HS mode\n"); + printk_warning("SMHC: Card does not support HS mode\n"); return -1; } @@ -984,7 +984,7 @@ static int sunxi_mmc_mmc_switch_hs(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS); if (err) { - printk_error("SMHC: Failed to change to HS mode\n"); + printk_warning("SMHC: Failed to change to HS mode\n"); return err; } @@ -1013,7 +1013,7 @@ static int sunxi_mmc_mmc_switch_hs200(sunxi_sdhci_t *sdhci) { // Check if card supports HS200 mode if (!(mmc->card_caps && MMC_MODE_HS200)) { - printk_error("SMHC: Card does not support HS200 mode\n"); + printk_warning("SMHC: Card does not support HS200 mode\n"); return -1; } @@ -1021,7 +1021,7 @@ static int sunxi_mmc_mmc_switch_hs200(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200); if (err) { - printk_error("SMHC: Failed to change to HS200 mode\n"); + printk_warning("SMHC: Failed to change to HS200 mode\n"); return err; } @@ -1050,7 +1050,7 @@ static int sunxi_mmc_mmc_switch_hs400(sunxi_sdhci_t *sdhci) { // Check if card supports HS400 mode if (!(mmc->card_caps && MMC_MODE_HS400)) { - printk_error("SMHC: Card does not support HS400 mode\n"); + printk_warning("SMHC: Card does not support HS400 mode\n"); return -1; } @@ -1058,7 +1058,7 @@ static int sunxi_mmc_mmc_switch_hs400(sunxi_sdhci_t *sdhci) { err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS400); if (err) { - printk_error("SMHC: Failed to change to HS400 mode\n"); + printk_warning("SMHC: Failed to change to HS400 mode\n"); return err; } @@ -1173,7 +1173,7 @@ static int sunxi_mmc_mmc_switch_bus_width(sunxi_sdhci_t *sdhci, uint32_t spd_mod err = sunxi_mmc_check_bus_width(sdhci, emmc_hs_ddr, width); if (err) { - printk_error("SMHC: bus witdh param error.\n"); + printk_warning("SMHC: bus witdh param error.\n"); return -1; } @@ -1194,7 +1194,7 @@ static int sunxi_mmc_mmc_switch_bus_width(sunxi_sdhci_t *sdhci, uint32_t spd_mod err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, val); if (err) { - printk_error("SMHC: set bus witdh error.\n"); + printk_warning("SMHC: set bus witdh error.\n"); return -1; } if (spd_mode == MMC_HSDDR52_DDR50) { @@ -1235,14 +1235,14 @@ static int sunxi_mmc_mmc_switch_bus_mode(sunxi_sdhci_t *sdhci, uint32_t spd_mode err = sunxi_mmc_mmc_switch_speed_mode(sdhci, spd_mode); if (err) { - printk_error("SMHC: Switch speed mode failed\n"); + printk_warning("SMHC: Switch speed mode failed\n"); return err; } err = sunxi_mmc_mmc_switch_bus_width(sdhci, spd_mode, width); if (err) { - printk_error("SMHC: Switch bus width\n"); + printk_warning("SMHC: Switch bus width\n"); return err; } @@ -1261,7 +1261,7 @@ static int sunxi_mmc_mmc_switch_bus_mode(sunxi_sdhci_t *sdhci, uint32_t spd_mode * @param sdhci Pointer to the SD/MMC host controller structure. * @return Returns 0 upon success, an error code if an error occurs. */ -static int sunxi_mmc_send_if_cond(sunxi_sdhci_t *sdhci) { +static int sunxi_mmc_sd_send_if_cond(sunxi_sdhci_t *sdhci) { mmc_t *mmc = sdhci->mmc; mmc_cmd_t cmd; int err = 0; @@ -1275,7 +1275,7 @@ static int sunxi_mmc_send_if_cond(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send if cond failed\n"); + printk_warning("SMHC: send if cond failed\n"); return err; } @@ -1325,7 +1325,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { mmc_t *mmc = sdhci->mmc; int err = 0; int timeout = 1000; - uint32_t capacity, cmult, csize; + uint64_t capacity = 0, cmult = 0, csize = 0; const char *strver = "unknown"; mmc_cmd_t cmd; @@ -1340,7 +1340,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: Put the Card in Identify Mode failed\n"); + printk_warning("SMHC: Put the Card in Identify Mode failed\n"); return -1; } @@ -1355,12 +1355,12 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR; cmd.cmdarg = mmc->rca << 16; cmd.resp_type = MMC_RSP_R6; - cmd.flags = MMC_DATA_READ; + cmd.flags = 0; err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: send rca failed\n"); + printk_warning("SMHC: send rca failed\n"); return err; } @@ -1373,7 +1373,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { cmd.cmdidx = MMC_CMD_SEND_CSD; cmd.resp_type = MMC_RSP_R2; cmd.cmdarg = mmc->rca << 16; - cmd.flags = MMC_DATA_READ; + cmd.flags = 0; err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); @@ -1381,7 +1381,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { sunxi_mmc_send_status(sdhci, timeout); if (err) { - printk_error("SMHC: MMC get csd failed\n"); + printk_warning("SMHC: MMC get csd failed\n"); return err; } @@ -1462,15 +1462,11 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { err = sunxi_sdhci_xfer(sdhci, &cmd, NULL); if (err) { - printk_error("SMHC: Select the card failed\n"); + printk_warning("SMHC: Select the card failed\n"); return err; } } - if (!sunxi_mmc_device_is_sd(mmc)) { - /* TODO MMC Timing update */ - } - sunxi_mmc_set_clock(sdhci, 25000000); /* @@ -1518,14 +1514,16 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { strver = "5.1"; break; } + } else { + printk_debug("SMHC: Read ext csd fail"); } if (!err & (ext_csd[EXT_CSD_REV] >= 2)) { - mmc->capacity = ext_csd[EXT_CSD_SEC_CNT] << 0 | - ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | - ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | - ext_csd[EXT_CSD_SEC_CNT + 3] << 24; - mmc->capacity *= 1 << UNSTUFF_BITS(mmc->csd, 80, 4); + capacity = ext_csd[EXT_CSD_SEC_CNT] << 0 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | + ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; + capacity *= mmc->read_bl_len; + if ((capacity >> 20) > 2 * 1024) + mmc->capacity = capacity; } /* @@ -1533,7 +1531,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { * group size from ext_csd directly, or calculate * the group size from the csd value. */ - if (ext_csd[175]) + if (ext_csd[EXT_CSD_ERASE_GROUP_DEF]) mmc->erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * 512 * 1024; else { int erase_gsz, erase_gmul; @@ -1555,14 +1553,14 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { } if (err) { - printk_error("SMHC: Change speed mode failed\n"); + printk_warning("SMHC: Change speed mode failed\n"); return err; } /* for re-update sample phase */ err = sunxi_sdhci_update_phase(sdhci); if (err) { - printk_error("SMHC: update clock failed\n"); + printk_warning("SMHC: update clock failed\n"); return err; } @@ -1612,12 +1610,13 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { } else { /* EMMC */ if (mmc->card_caps & MMC_MODE_8BIT) { + printk_trace("SMHC: set mmc bus width 8: %s\n", (mmc->card_caps & MMC_MODE_DDR_52MHz) ? "DDR" : "SDR"); /* 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 bus width failed\n"); + printk_warning("SMHC: switch bus width failed\n"); return err; } sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_8BIT); @@ -1625,17 +1624,18 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { /* Set the card to use 8 bit */ 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"); + printk_warning("SMHC: switch bus width failed\n"); return err; } sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_8BIT); } } else if (mmc->card_caps & MMC_MODE_4BIT) { + printk_trace("SMHC: set mmc bus width 4: %s\n", (mmc->card_caps & MMC_MODE_DDR_52MHz) ? "DDR" : "SDR"); if ((mmc->card_caps & MMC_MODE_DDR_52MHz)) { /* Set the card to use 4 bit ddr */ err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_DDR_4); if (err) { - printk_error("SMHC: switch bus width failed\n"); + printk_warning("SMHC: switch bus width failed\n"); return err; } sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_4BIT); @@ -1643,25 +1643,19 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { /* Set the card to use 4 bit */ err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4); if (err) { - printk_error("SMHC: switch bus width failed\n"); + printk_warning("SMHC: switch bus width failed\n"); return err; } sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_4BIT); } - } else { - /* Set the card to use 8 bit */ - err = sunxi_mmc_switch(sdhci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8); - - if (err) { - printk_error("SMHC: witch bus width8 failed\n"); - return err; - } - sunxi_mmc_set_bus_width(sdhci, SMHC_WIDTH_8BIT); } if (mmc->card_caps & MMC_MODE_HS400) { + printk_trace("SMHC: speed set to max clk: %dHz\n", sdhci->max_clk); mmc->tran_speed = sdhci->max_clk; - } else if (mmc->card_caps & MMC_MODE_DDR_52MHz) { + } + + if (mmc->card_caps & MMC_MODE_DDR_52MHz) { mmc->tran_speed = 52000000; } else if (mmc->card_caps & MMC_MODE_HS) { if (mmc->card_caps & MMC_MODE_HS_52MHz) { @@ -1674,7 +1668,6 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { } } - printk_trace("SMHC: set clock to %u\n", mmc->tran_speed); sunxi_mmc_set_clock(sdhci, mmc->tran_speed); @@ -1685,11 +1678,7 @@ static int sunxi_mmc_probe(sunxi_sdhci_t *sdhci) { printk_debug("SD/MMC card at the '%s' host controller:\r\n", sdhci->name); printk_debug(" Attached is a %s%s card\r\n", mmc->version & SD_VERSION_SD ? "SD" : "MMC", mmc->version & SD_VERSION_SD ? "" : strver); - if (mmc->capacity / (f64) 1000000000.0 < 4) - printk_info(" Capacity: %.1fMB\n", (f32) ((f64) mmc->capacity / (f64) 1000000.0)); - else - printk_info(" Capacity: %.1fGB\n", (f32) ((f64) mmc->capacity / (f64) 1000000000.0)); - + printk_info(" Capacity: %.2fGB\n", (f64) (mmc->lba >> 11) / (f64) 1024.f); sunxi_mmc_show_card_info(sdhci); return 0; @@ -1717,7 +1706,7 @@ int sunxi_mmc_init(void *sdhci_hdl) { err = sunxi_sdhci_core_init(sdhci); if (err) { - printk_error("SMHC: host init failed\n"); + printk_warning("SMHC: host init failed\n"); return err; } @@ -1727,7 +1716,7 @@ int sunxi_mmc_init(void *sdhci_hdl) { err = sunxi_mmc_go_idle(sdhci); if (err) { - printk_error("SMHC: Reset card fail\n"); + printk_warning("SMHC: Reset card fail\n"); return err; } @@ -1737,40 +1726,53 @@ int sunxi_mmc_init(void *sdhci_hdl) { /* if is SDHCI0 in PF port try SD Card CD pin */ if (sdhci->pinctrl.gpio_cd.pin != 0) { if (sdhci->id == 0 && sunxi_gpio_read(sdhci->pinctrl.gpio_cd.pin) != GPIO_LEVEL_LOW) { - printk_error("SMHC: SD Card Get CD error %d\n", sunxi_gpio_read(sdhci->pinctrl.gpio_cd.pin)); + printk_warning("SMHC: SD Card Get CD error %d\n", sunxi_gpio_read(sdhci->pinctrl.gpio_cd.pin)); err = -1; return err; } } printk_debug("SMHC: Try to init SD Card\n"); - err = sunxi_mmc_send_if_cond(sdhci); + err = sunxi_mmc_sd_send_if_cond(sdhci); if (err) { - printk_error("SMHC%d: SD Card did not respond to voltage select\n", sdhci->id); + printk_warning("SMHC%d: SD Card did not respond to voltage select\n", sdhci->id); return -1; } err = sunxi_mmc_sd_send_op_cond(sdhci); if (err) { - printk_error("SMHC%d: SD Card did not respond to voltage select\n", sdhci->id); + printk_warning("SMHC%d: SD Card did not respond to voltage select\n", sdhci->id); return -1; } } else if (sdhci->sdhci_mmc_type == MMC_TYPE_EMMC) { printk_debug("SMHC: Try to init eMMC Card\n"); err = sunxi_mmc_mmc_send_op_cond(sdhci); if (err) { - printk_error("SMHC%d: MMC did not respond to voltage select\n", sdhci->id); + printk_warning("SMHC%d: MMC did not respond to voltage select\n", sdhci->id); return -1; } } err = sunxi_mmc_probe(sdhci); if (err) { - printk_error("SMHC%d: SD/MMC Probe failed, err %d\n", sdhci->id, err); + printk_warning("SMHC%d: SD/MMC Probe failed, err %d\n", sdhci->id, err); } return err; } +/** + * @brief Read blocks from the Sunxi MMC block device + * + * This function reads a specified number of blocks from the Sunxi MMC block device + * and stores the data into the destination buffer. + * + * @param sdhci Pointer to the Sunxi SD Host Controller instance + * @param dst Pointer to the destination buffer where the read data will be stored + * @param start The starting block number to read from + * @param blkcnt The number of blocks to read + * + * @return Returns 0 on success, or an error code if the operation fails + */ uint32_t sunxi_mmc_blk_read(void *sdhci, void *dst, uint32_t start, uint32_t blkcnt) { return sunxi_mmc_read_blocks((sunxi_sdhci_t *) sdhci, dst, start, blkcnt); } \ No newline at end of file diff --git a/src/drivers/mmc/sys-sdcard.c b/src/drivers/mmc/sys-sdcard.c index 558abda1..7afc5538 100644 --- a/src/drivers/mmc/sys-sdcard.c +++ b/src/drivers/mmc/sys-sdcard.c @@ -18,6 +18,19 @@ sdmmc_pdata_t card0; +/** + * @brief Initialize the SD/MMC interface + * + * Initializes the SD/MMC interface using the provided data structure and SD Host Controller instance. + * It sets the SD Host Controller instance and the online status in the data structure, and then initializes + * the MMC device. If the initialization is successful, it prints a message indicating the type of card detected + * and returns 0; otherwise, it returns -1. + * + * @param data Pointer to the SD/MMC platform data structure + * @param hci Pointer to the Sunxi SD Host Controller instance + * + * @return Returns 0 on success, or -1 if the initialization fails + */ int sdmmc_init(sdmmc_pdata_t *data, sunxi_sdhci_t *hci) { data->hci = hci; data->online = false; @@ -30,6 +43,20 @@ int sdmmc_init(sdmmc_pdata_t *data, sunxi_sdhci_t *hci) { return -1; } +/** + * @brief Read blocks from the SD/MMC device + * + * Reads a specified number of blocks from the SD/MMC device using the provided platform data structure, + * destination buffer, block number, and block count. It calls the underlying function for reading blocks + * from the Sunxi MMC block device and returns the result. + * + * @param data Pointer to the SD/MMC platform data structure + * @param buf Pointer to the destination buffer where the read data will be stored + * @param blkno The starting block number to read from + * @param blkcnt The number of blocks to read + * + * @return Returns 0 on success, or an error code if the operation fails + */ uint32_t sdmmc_blk_read(sdmmc_pdata_t *data, uint8_t *buf, uint32_t blkno, uint32_t blkcnt) { return sunxi_mmc_blk_read(data->hci, buf, blkno, blkcnt); -} \ No newline at end of file +} diff --git a/src/drivers/mmc/sys-sdhci.c b/src/drivers/mmc/sys-sdhci.c index 380b188b..fdf1246f 100644 --- a/src/drivers/mmc/sys-sdhci.c +++ b/src/drivers/mmc/sys-sdhci.c @@ -36,11 +36,11 @@ static int sunxi_sdhci_clk_enable(sunxi_sdhci_t *sdhci) { uint32_t reg_val; /* Configure AHB clock */ reg_val = readl(mmc_host->hclkbase); - reg_val |= (1 << (sdhci->id)); + reg_val |= BIT(sdhci->id); writel(reg_val, mmc_host->hclkbase); reg_val = readl(mmc_host->hclkrst); - reg_val |= (1 << (16 + sdhci->id)); + reg_val |= BIT(16 + sdhci->id); writel(reg_val, mmc_host->hclkrst); /* Configure module clock */ @@ -74,7 +74,7 @@ static int sunxi_sdhci_update_clk(sunxi_sdhci_t *sdhci) { /* Check status */ if (mmc_host->reg->cmd & SMHC_CMD_START) { - printk_error("SMHC: mmc %d update clk failed\n", sdhci->id); + printk_debug("SMHC: mmc %d update clk failed\n", sdhci->id); return -1; } @@ -84,14 +84,15 @@ static int sunxi_sdhci_update_clk(sunxi_sdhci_t *sdhci) { } /** - * @brief Configure timing settings for timing mode 4 in the SDHC controller. - * - * This function configures timing settings for timing mode 4 in the SDHC controller. - * It calculates the delay based on the speed mode and frequency parameters and sets - * the appropriate values in the timing data structure. Additionally, it sets the - * output delay (`odly`) based on the speed mode and returns 0 on success or -1 on failure. - * - * @param sdhci Pointer to the SDHC structure. + * @brief Calculate the timing configuration for Sunxi SD Host Controller using timing mode 4. + * + * This function calculates the timing configuration for the Sunxi SD Host Controller when operating + * in timing mode 4 based on the speed mode and frequency. It updates the timing data with the calculated delay. + * + * @param sdhci A pointer to the Sunxi SD Host Controller structure. + * @param spd_md_id The speed mode ID. + * @param freq_id The frequency ID. + * * @return 0 on success, -1 on failure. */ static int sunxi_sdhci_get_timing_config_timing_4(sunxi_sdhci_t *sdhci, const uint32_t spd_md_id, const uint32_t freq_id) { @@ -103,7 +104,7 @@ static int sunxi_sdhci_get_timing_config_timing_4(sunxi_sdhci_t *sdhci, const ui /* Check if the controller ID is MMC_CONTROLLER_2 and if timing mode and frequency ID are valid */ if ((sdhci->id != MMC_CONTROLLER_2) || (spd_md_id > MMC_HS400) || (freq_id > MMC_MAX_SPD_MD_NUM)) { - printk_error("SMHC: timing 4 not supported for this configuration\n"); + printk_debug("SMHC: timing 4 not supported for this configuration\n"); return -1; } @@ -116,7 +117,7 @@ static int sunxi_sdhci_get_timing_config_timing_4(sunxi_sdhci_t *sdhci, const ui if (freq_id <= MMC_CLK_25M) { dly = 0; } else { - printk_error("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); + printk_debug("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); ret = -1; } } else if (spd_md_id == MMC_HSSDR52_SDR25) { @@ -125,18 +126,18 @@ static int sunxi_sdhci_get_timing_config_timing_4(sunxi_sdhci_t *sdhci, const ui } else if (freq_id == MMC_CLK_50M) { dly = 15; } else { - printk_error("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); + printk_debug("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); ret = -1; } } else if (spd_md_id == MMC_HSDDR52_DDR50) { if (freq_id <= MMC_CLK_25M) { dly = 0; } else { - printk_error("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); + printk_debug("SMHC: wrong frequency %d at speed mode %d\n", freq_id, spd_md_id); ret = -1; } } else { - printk_error("SMHC: wrong speed mode %d\n", spd_md_id); + printk_debug("SMHC: wrong speed mode %d\n", spd_md_id); ret = -1; } } @@ -157,14 +158,16 @@ static int sunxi_sdhci_get_timing_config_timing_4(sunxi_sdhci_t *sdhci, const ui return ret; } - /** - * @brief Get timing configuration for the SDHC controller. - * - * This function retrieves the timing configuration for the specified SDHC controller. - * - * @param sdhci Pointer to the SDHC controller structure. - * @return Returns 0 on success, -1 on failure. + * @brief Get the timing configuration for the Sunxi SD Host Controller + * + * This function retrieves the timing configuration for the Sunxi SD Host Controller based on the provided parameters. + * + * @param sdhci Pointer to the Sunxi SD Host Controller instance + * @param spd_md_id Speed mode ID + * @param freq_id Frequency ID + * + * @return Returns 0 on success, or an error code if the operation fails */ static int sunxi_sdhci_get_timing_config(sunxi_sdhci_t *sdhci, uint32_t spd_md_id, uint32_t freq_id) { int ret = 0; @@ -174,30 +177,31 @@ static int sunxi_sdhci_get_timing_config(sunxi_sdhci_t *sdhci, uint32_t spd_md_i // Check for specific conditions based on the controller ID and timing mode if ((sdhci->id == 2) && mmc_host->timing_mode == SUNXI_MMC_TIMING_MODE_4) { - /* When using eMMC and SMHC2, config it as timing 4 */ + /* When using eMMC and SMHC2, configure it as timing 4 */ ret = sunxi_sdhci_get_timing_config_timing_4(sdhci, spd_md_id, freq_id); if (ret) { - printk_error("SMHC: Config timing TM4 fail\n"); + printk_debug("SMHC: Configuring timing TM4 failed\n"); } } else if ((sdhci->id == 0) && (mmc_host->timing_mode == SUNXI_MMC_TIMING_MODE_1)) { // Check timing data and adjust configuration if necessary if ((spd_md_id <= MMC_HSSDR52_SDR25) && (freq_id <= MMC_CLK_50M)) { - /* if timing less than SDR25, use default odly */ + /* If timing is less than SDR25, use default odly */ timing_data->odly = 0; timing_data->sdly = 0; ret = 0; } else { - printk_warning("SMHC: SMHC0 does not support input spd mode %d\n", spd_md_id); + printk_warning("SMHC: SMHC0 does not support input speed mode %d\n", spd_md_id); ret = -1; } } else { - printk_error("SMHC: timing setting failed, parameter error\n"); + printk_debug("SMHC: Timing setting failed due to parameter error\n"); ret = -1; } return ret; } + /** * @brief Set the SDHC controller's clock frequency. * @@ -244,7 +248,7 @@ static int sunxi_sdhci_set_mclk(sunxi_sdhci_t *sdhci, uint32_t clk_hz) { default: n = 0; m = 0; - printk_error("SMHC: requested frequency does not match: freq=%d\n", clk_hz); + printk_debug("SMHC: requested frequency does not match: freq=%d\n", clk_hz); break; } @@ -290,7 +294,7 @@ static uint32_t sunxi_sdhci_get_mclk(sunxi_sdhci_t *sdhci) { clk_hz = (sdhci->id == 2) ? 600000000 : 300000000; break; default: - printk_error("SMHC: wrong clock source %u\n", src); + printk_debug("SMHC: wrong clock source %u\n", src); break; } @@ -299,12 +303,15 @@ static uint32_t sunxi_sdhci_get_mclk(sunxi_sdhci_t *sdhci) { } /** - * @brief Configure the delay for the SDHC controller based on timing mode. - * - * This function configures the delay for the SDHC controller based on the timing mode. - * - * @param sdhci Pointer to the SDHC controller structure. - * @return 0 on success, -1 on failure. + * @brief Configure delay for the Sunxi SD Host Controller + * + * This function configures the delay settings for the Sunxi SD Host Controller based on the provided parameters. + * + * @param sdhci Pointer to the Sunxi SD Host Controller instance + * @param spd_md_id Speed mode ID + * @param freq_id Frequency ID + * + * @return Returns 0 on success, or an error code if the operation fails */ static int sunxi_sdhci_config_delay(sunxi_sdhci_t *sdhci, uint32_t spd_md_id, uint32_t freq_id) { int ret = 0; @@ -357,12 +364,12 @@ static int sunxi_sdhci_config_delay(sunxi_sdhci_t *sdhci, uint32_t spd_md_id, ui timing_data->sdly = 0xff; if ((ret = sunxi_sdhci_get_timing_config(sdhci, spd_md_id, freq_id)) != 0) { - printk_error("SMHC: getting timing param error %d\n", ret); + printk_debug("SMHC: getting timing param error %d\n", ret); return -1; } if ((timing_data->odly == 0xff) || (timing_data->sdly == 0xff)) { - printk_error("SMHC: getting timing config error\n"); + printk_debug("SMHC: getting timing config error\n"); return -1; } @@ -384,12 +391,12 @@ static int sunxi_sdhci_config_delay(sunxi_sdhci_t *sdhci, uint32_t spd_md_id, ui timing_data->odly = 0xff; timing_data->sdly = 0xff; if ((ret = sunxi_sdhci_get_timing_config(sdhci, spd_md_id, freq_id)) != 0) { - printk_error("SMHC: getting timing param error %d\n", ret); + printk_debug("SMHC: getting timing param error %d\n", ret); return -1; } if ((timing_data->odly == 0xff) || (timing_data->sdly == 0xff)) { - printk_error("SMHC: getting timing config error\n"); + printk_debug("SMHC: getting timing config error\n"); return -1; } @@ -544,7 +551,7 @@ static int sunxi_sdhci_config_clock(sunxi_sdhci_t *sdhci, uint32_t clk) { // Update clock settings if (sunxi_sdhci_update_clk(sdhci)) { - printk_error("SMHC: Failed to update clock settings\n"); + printk_debug("SMHC: Failed to update clock settings\n"); return -1; } @@ -552,11 +559,11 @@ static int sunxi_sdhci_config_clock(sunxi_sdhci_t *sdhci, uint32_t clk) { if (mmc_host->timing_mode == SUNXI_MMC_TIMING_MODE_1 || mmc_host->timing_mode == SUNXI_MMC_TIMING_MODE_3 || mmc_host->timing_mode == SUNXI_MMC_TIMING_MODE_4) { if (sunxi_sdhci_clock_mode(sdhci, clk)) { - printk_error("SMHC: Failed to configure clock mode\n"); + printk_debug("SMHC: Failed to configure clock mode\n"); return -1; } } else { - printk_error("SMHC: Timing mode not supported\n"); + printk_debug("SMHC: Timing mode not supported\n"); return -1; } @@ -565,7 +572,7 @@ static int sunxi_sdhci_config_clock(sunxi_sdhci_t *sdhci, uint32_t clk) { // Check if clock update after configuration fails if (sunxi_sdhci_update_clk(sdhci)) { - printk_error("SMHC: Failed to update clock settings after configuration\n"); + printk_debug("SMHC: Failed to update clock settings after configuration\n"); return -1; } @@ -733,7 +740,7 @@ static int sunxi_sunxi_sdhci_trans_data_cpu(sunxi_sdhci_t *sdhci, mmc_data_t *da } if (mmc_host->reg->status & SMHC_STATUS_FIFO_EMPTY) { if (time_us() >= timeout) { - printk_error("SMHC: read by CPU failed, timeout, index %u\n", i); + printk_debug("SMHC: read by CPU failed, timeout, index %u\n", i); } return -1; } @@ -835,13 +842,13 @@ static int sunxi_sunxi_sdhci_trans_data_dma(sunxi_sdhci_t *sdhci, mmc_data_t *da /* Enable DMA */ - mmc_host->reg->idst = 0x337; + // mmc_host->reg->idst = 0x337; mmc_host->reg->gctrl |= (SMHC_GCTRL_DMA_ENABLE | SMHC_GCTRL_DMA_RESET); timeout = time_us() + SMHC_TIMEOUT; while (mmc_host->reg->gctrl & SMHC_GCTRL_DMA_RESET) { if (time_us() > timeout) { - printk_error("SMHC: wait for dma rst timeout\n"); + printk_debug("SMHC: wait for dma rst timeout\n"); return -1; } } @@ -851,7 +858,7 @@ static int sunxi_sunxi_sdhci_trans_data_dma(sunxi_sdhci_t *sdhci, mmc_data_t *da timeout = time_us() + SMHC_TIMEOUT; while (mmc_host->reg->dmac & SMHC_IDMAC_SOFT_RESET) { if (time_us() > timeout) { - printk_error("SMHC: wait for dma soft rst timeout\n"); + printk_debug("SMHC: wait for dma soft rst timeout\n"); return -1; } } @@ -892,7 +899,7 @@ void sunxi_sdhci_set_ios(sunxi_sdhci_t *sdhci) { // Configure clock and handle errors if (mmc->clock && sunxi_sdhci_config_clock(sdhci, mmc->clock)) { - printk_error("SMHC: update clock failed\n"); + printk_debug("SMHC: update clock failed\n"); mmc_host->fatal_err = 1; return; } @@ -933,7 +940,7 @@ int sunxi_sdhci_core_init(sunxi_sdhci_t *sdhci) { mmc_host->reg->gctrl = 0x7; while (mmc_host->reg->gctrl & 0x7) { if (time_us() > timeout) { - printk_error("SMHC: controller reset timeout\n"); + printk_debug("SMHC: controller reset timeout\n"); return -1; } } @@ -989,7 +996,7 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { /* Check if have fatal error */ if (mmc_host->fatal_err) { - printk_error("SMHC: SMHC into error, cmd send failed\n"); + printk_debug("SMHC: SMHC into error, cmd send failed\n"); return -1; } @@ -1032,7 +1039,7 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { if (data) { /* Check data desc align */ if ((uint32_t) data->b.dest & 0x3) { - printk_error("SMHC: data dest is not 4 byte align\n"); + printk_debug("SMHC: data dest is not 4 byte align\n"); error_code = -1; goto out; } @@ -1082,7 +1089,7 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { if (ret) { error_code = mmc_host->reg->rint & SMHC_RINT_INTERRUPT_ERROR_BIT; - printk_warning("SMHC: error 0x%x status 0x%x\n", error_code & SMHC_RINT_INTERRUPT_ERROR_BIT, error_code & ~SMHC_RINT_INTERRUPT_ERROR_BIT); + printk_debug("SMHC: error 0x%x status 0x%x\n", error_code & SMHC_RINT_INTERRUPT_ERROR_BIT, error_code & ~SMHC_RINT_INTERRUPT_ERROR_BIT); if (!error_code) { error_code = 0xffffffff; } @@ -1099,9 +1106,9 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { error_code = 0xffffffff; } if (time_us() > timeout) - printk_error("SMHC: stage 1 data timeout, error %08x\n", error_code); + printk_debug("SMHC: stage 1 data timeout, error %08x\n", error_code); else - printk_error("SMHC: stage 1 status get interrupt, error 0x%08x\n", error_code); + printk_debug("SMHC: stage 1 status get interrupt, error 0x%08x\n", error_code); goto out; } } while (!(status & SMHC_RINT_COMMAND_DONE)); @@ -1117,9 +1124,9 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { error_code = 0xffffffff; } if (time_us() > timeout) - printk_error("SMHC: stage 2 data timeout, error %08x\n", error_code); + printk_debug("SMHC: stage 2 data timeout, error %08x\n", error_code); else - printk_error("SMHC: stage 2 status get interrupt, error 0x%08x\n", error_code); + printk_debug("SMHC: stage 2 status get interrupt, error 0x%08x\n", error_code); goto out; } @@ -1141,7 +1148,7 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { if (!error_code) { error_code = 0xffffffff; } - printk_error("SMHC: wait dma timeout, error %08x\n", error_code); + printk_debug("SMHC: wait dma timeout, error %08x\n", error_code); goto out; } done = status & BIT(1); @@ -1158,7 +1165,7 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { if (!error_code) { error_code = 0xffffffff; } - printk_error("SMHC: busy timeout, status %08x\n", status); + printk_debug("SMHC: busy timeout, status %08x\n", status); goto out; } } while (status & SMHC_STATUS_CARD_DATA_BUSY); @@ -1199,12 +1206,12 @@ int sunxi_sdhci_xfer(sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data) { timeout = time_us() + SMHC_TIMEOUT; while (mmc_host->reg->gctrl & SMHC_GCTRL_HARDWARE_RESET) { if (time_us() > timeout) { - printk_error("SMHC: controller error reset timeout\n"); + printk_debug("SMHC: controller error reset timeout\n"); return -1; } } sunxi_sdhci_update_clk(sdhci); - printk_error("SMHC: CMD 0x%08x, error 0x%08x\n", cmd->cmdidx, error_code); + printk_debug("SMHC: CMD 0x%08x, error 0x%08x\n", cmd->cmdidx, error_code); } mmc_host->reg->rint = 0xffffffff; @@ -1252,7 +1259,7 @@ int sunxi_sdhci_update_phase(sunxi_sdhci_t *sdhci) { int sunxi_sdhci_init(sunxi_sdhci_t *sdhci) { /* Check if controller ID is correct */ if (sdhci->id > MMC_CONTROLLER_2) { - printk_error("SMHC: Unsupported MAX Controller reached\n"); + printk_debug("SMHC: Unsupported MAX Controller reached\n"); return -1; }