diff --git a/src/commonlib/storage/mmc.c b/src/commonlib/storage/mmc.c index 2aaa29245f..135105db96 100644 --- a/src/commonlib/storage/mmc.c +++ b/src/commonlib/storage/mmc.c @@ -4,6 +4,7 @@ * This code is controller independent */ +#include #include #include #include "mmc.h" @@ -529,3 +530,47 @@ const char *mmc_partition_name(struct storage_media *media, return ""; return partition_name[partition_number]; } + +void mmc_set_early_wake_status(int32_t status) +{ + int32_t *ms_cbmem; + + ms_cbmem = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(status)); + + if (!ms_cbmem) { + printk(BIOS_ERR, + "%s: Failed to add early mmc wake status to cbmem!\n", + __func__); + return; + } + + *ms_cbmem = status; +} + +int mmc_send_cmd1(struct storage_media *media) +{ + int err; + + /* Reset emmc, send CMD0 */ + if (sd_mmc_go_idle(media)) + goto out_err; + + /* Send CMD1 */ + err = mmc_send_op_cond(media); + if (err == 0) { + if (media->op_cond_response & OCR_HCS) + mmc_set_early_wake_status(MMC_STATUS_CMD1_READY_HCS); + else + mmc_set_early_wake_status(MMC_STATUS_CMD1_READY); + } else if (err == CARD_IN_PROGRESS) { + mmc_set_early_wake_status(MMC_STATUS_CMD1_IN_PROGRESS); + } else { + goto out_err; + } + + return 0; + +out_err: + mmc_set_early_wake_status(MMC_STATUS_NEED_RESET); + return -1; +} diff --git a/src/commonlib/storage/sd_mmc.h b/src/commonlib/storage/sd_mmc.h index 411a4a3052..909652d8a5 100644 --- a/src/commonlib/storage/sd_mmc.h +++ b/src/commonlib/storage/sd_mmc.h @@ -49,6 +49,8 @@ int mmc_set_bus_width(struct storage_media *media); int mmc_set_partition(struct storage_media *media, unsigned int partition_number); int mmc_update_capacity(struct storage_media *media); +void mmc_set_early_wake_status(int32_t status); +int mmc_send_cmd1(struct storage_media *media); /* SD card support routines */ int sd_change_freq(struct storage_media *media); diff --git a/src/soc/intel/common/block/scs/early_mmc.c b/src/soc/intel/common/block/scs/early_mmc.c index 4e765339ce..c0ca1374c3 100644 --- a/src/soc/intel/common/block/scs/early_mmc.c +++ b/src/soc/intel/common/block/scs/early_mmc.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include -#include #include #include #include @@ -41,22 +40,6 @@ static void disable_mmc_controller_bar(void) ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)); } -static void set_early_mmc_wake_status(int32_t status) -{ - int32_t *ms_cbmem; - - ms_cbmem = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(int)); - - if (ms_cbmem == NULL) { - printk(BIOS_ERR, - "%s: Failed to add early mmc wake status to cbmem!\n", - __func__); - return; - } - - *ms_cbmem = status; -} - int early_mmc_wake_hw(void) { struct storage_media media; @@ -108,7 +91,7 @@ int early_mmc_wake_hw(void) disable_mmc_controller_bar(); - set_early_mmc_wake_status(1); + mmc_set_early_wake_status(1); return 0; out_err: diff --git a/src/soc/mediatek/common/msdc.c b/src/soc/mediatek/common/msdc.c index c6f77abc5c..0d1dbb5049 100644 --- a/src/soc/mediatek/common/msdc.c +++ b/src/soc/mediatek/common/msdc.c @@ -3,7 +3,6 @@ * MTK MSDC Host Controller interface specific code */ #include -#include #include #include #include @@ -437,27 +436,9 @@ static void msdc_controller_init(struct msdc_ctrlr *host, void *base, void *top_ add_msdc(host); } -static void set_early_mmc_wake_status(int32_t status) -{ - int32_t *ms_cbmem; - - ms_cbmem = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(status)); - - if (!ms_cbmem) { - printk(BIOS_ERR, - "%s: Failed to add early mmc wake status to cbmem!\n", - __func__); - return; - } - - printk(BIOS_DEBUG, "Early init status = %d\n", status); - *ms_cbmem = status; -} - int mtk_emmc_early_init(void *base, void *top_base) { struct storage_media media = { 0 }; - int err; struct msdc_ctrlr msdc_host; struct sd_mmc_ctrlr *mmc_ctrlr = &msdc_host.sd_mmc_ctrlr; @@ -468,26 +449,6 @@ int mtk_emmc_early_init(void *base, void *top_base) SET_CLOCK(mmc_ctrlr, 400 * 1000); SET_BUS_WIDTH(mmc_ctrlr, 1); - /* Reset emmc, send CMD0 */ - if (sd_mmc_go_idle(&media)) - goto out_err; - /* Send CMD1 */ - err = mmc_send_op_cond(&media); - if (err == 0) { - if (media.op_cond_response & OCR_HCS) - set_early_mmc_wake_status(MMC_STATUS_CMD1_READY_HCS); - else - set_early_mmc_wake_status(MMC_STATUS_CMD1_READY); - } else if (err == CARD_IN_PROGRESS) { - set_early_mmc_wake_status(MMC_STATUS_CMD1_IN_PROGRESS); - } else { - goto out_err; - } - - return 0; - -out_err: - set_early_mmc_wake_status(MMC_STATUS_NEED_RESET); - return -1; + return mmc_send_cmd1(&media); }