mmc: quirks: add new quirk that allows Cache disable

This change allows us to prevent cache enable for certain
cards that have broken cache functionality.

Change-Id: Iea3f8c8f4e5498a8742fa408a19e3e169d1fa8cb
Signed-off-by: Talel Shenhar <tatias@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
This commit is contained in:
Talel Shenhar 2015-02-04 17:59:23 +02:00 committed by Subhash Jadavani
parent 96c1215f25
commit 4a897cf6aa
3 changed files with 40 additions and 18 deletions

View file

@ -3354,7 +3354,8 @@ int mmc_flush_cache(struct mmc_card *card)
if (mmc_card_mmc(card) && if (mmc_card_mmc(card) &&
(card->ext_csd.cache_size > 0) && (card->ext_csd.cache_size > 0) &&
(card->ext_csd.cache_ctrl & 1)) { (card->ext_csd.cache_ctrl & 1) &&
(!(card->quirks & MMC_QUIRK_CACHE_DISABLE))) {
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
EXT_CSD_FLUSH_CACHE, 1, 0); EXT_CSD_FLUSH_CACHE, 1, 0);
if (err == -ETIMEDOUT) { if (err == -ETIMEDOUT) {

View file

@ -1816,26 +1816,46 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
* the existence of cache and it can be turned on. * the existence of cache and it can be turned on.
* If HPI is not supported then cache shouldn't be enabled. * If HPI is not supported then cache shouldn't be enabled.
*/ */
if (card->ext_csd.cache_size > 0 && card->ext_csd.hpi_en) { if (card->ext_csd.cache_size > 0) {
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, if (card->ext_csd.hpi_en &&
EXT_CSD_CACHE_CTRL, 1, (!(card->quirks & MMC_QUIRK_CACHE_DISABLE))) {
card->ext_csd.generic_cmd6_time); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
if (err && err != -EBADMSG) { EXT_CSD_CACHE_CTRL, 1,
pr_err("%s: %s: mmc_switch() for CACHE_CTRL fails %d\n", card->ext_csd.generic_cmd6_time);
if (err && err != -EBADMSG) {
pr_err("%s: %s: fail on CACHE_CTRL ON %d\n",
mmc_hostname(host), __func__, err); mmc_hostname(host), __func__, err);
goto free_card; goto free_card;
} }
/* /*
* Only if no error, cache is turned on successfully. * Only if no error, cache is turned on successfully.
*/ */
if (err) { if (err) {
pr_warn("%s: Cache is supported, but failed to turn on (%d)\n", pr_warn("%s: Cache is supported, but failed to turn on (%d)\n",
mmc_hostname(card->host), err); mmc_hostname(card->host), err);
card->ext_csd.cache_ctrl = 0; card->ext_csd.cache_ctrl = 0;
err = 0; err = 0;
} else {
card->ext_csd.cache_ctrl = 1;
}
} else { } else {
card->ext_csd.cache_ctrl = 1; /*
* mmc standard doesn't say what is the card default
* value for EXT_CSD_CACHE_CTRL.
* Hence, cache may be enabled by default by
* card vendors.
* Thus, it is best to explicitly disable cache in case
* we want to avoid cache.
*/
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
EXT_CSD_CACHE_CTRL, 0,
card->ext_csd.generic_cmd6_time);
if (err) {
pr_err("%s: %s: fail on CACHE_CTRL OFF %d\n",
mmc_hostname(host), __func__, err);
goto free_card;
}
} }
} }

View file

@ -308,6 +308,7 @@ struct mmc_card {
#define MMC_QUIRK_INAND_DATA_TIMEOUT (1<<13) /* For incorrect data timeout */ #define MMC_QUIRK_INAND_DATA_TIMEOUT (1<<13) /* For incorrect data timeout */
#define MMC_QUIRK_BROKEN_HPI (1 << 14) /* For devices which gets */ #define MMC_QUIRK_BROKEN_HPI (1 << 14) /* For devices which gets */
/* broken due to HPI feature */ /* broken due to HPI feature */
#define MMC_QUIRK_CACHE_DISABLE (1 << 14) /* prevent cache enable */
unsigned int erase_size; /* erase size in sectors */ unsigned int erase_size; /* erase size in sectors */