From 419cf93502320584c834e8980f2477b1514cbeaa Mon Sep 17 00:00:00 2001 From: Shelley Chen Date: Wed, 11 Jan 2023 15:52:20 -0800 Subject: commonlib/storage: Add common eMMC functions Now that multiple platforms are trying to initialize eMMC in coreboot instead of depthcharge, lets move common functionality into commonlib instead of copying the same functionality between multiple platforms. Note for consistency, changed name of set_early_mmc_wake_status() to mmc_set_early_wake_status(). Also adding an mmc_send_cmd1() function for retrieving the Operating Conditions Register (OCR) contents. BUG=b:218406702 BRANCH=None TEST=emerge-herobrine coreboot chromeos-bootimage flash onto villager device and make sure still boots ChromeOS Change-Id: Id00535b05bbd379081712601ef10e762c1831747 Signed-off-by: Shelley Chen Reviewed-on: https://review.coreboot.org/c/coreboot/+/71827 Tested-by: build bot (Jenkins) Reviewed-by: Eric Lai --- src/commonlib/storage/mmc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/commonlib/storage/mmc.c') 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; +} -- cgit v1.2.3