提交 69041150 编写于 作者: U Ulf Hansson 提交者: Chris Ball

mmc: core: Move cached value of the negotiated ocr mask to card struct

The negotiated ocr mask is directly related to the card. Once a card
gets removed, the mask shall be dropped. By moving the cache of the ocr
mask from the host struct to the card struct we have accomplished this.
Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: NChris Ball <cjb@laptop.org>
上级 db4a0d05
...@@ -1574,9 +1574,10 @@ void mmc_power_off(struct mmc_host *host) ...@@ -1574,9 +1574,10 @@ void mmc_power_off(struct mmc_host *host)
/* /*
* Reset ocr mask to be the highest possible voltage supported for * Reset ocr mask to be the highest possible voltage supported for
* this mmc host. This value will be used at next power up. * this card. This value will be used at next power up.
*/ */
host->ocr = 1 << (fls(host->ocr_avail) - 1); if (host->card)
host->card->ocr = 1 << (fls(host->ocr_avail) - 1);
if (!mmc_host_is_spi(host)) { if (!mmc_host_is_spi(host)) {
host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
...@@ -2550,7 +2551,7 @@ int mmc_power_restore_host(struct mmc_host *host) ...@@ -2550,7 +2551,7 @@ int mmc_power_restore_host(struct mmc_host *host)
return -EINVAL; return -EINVAL;
} }
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
ret = host->bus_ops->power_restore(host); ret = host->bus_ops->power_restore(host);
mmc_bus_put(host); mmc_bus_put(host);
......
...@@ -934,6 +934,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, ...@@ -934,6 +934,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
goto err; goto err;
} }
card->ocr = ocr;
card->type = MMC_TYPE_MMC; card->type = MMC_TYPE_MMC;
card->rca = 1; card->rca = 1;
memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
...@@ -1533,9 +1534,9 @@ static int mmc_resume(struct mmc_host *host) ...@@ -1533,9 +1534,9 @@ static int mmc_resume(struct mmc_host *host)
BUG_ON(!host->card); BUG_ON(!host->card);
mmc_claim_host(host); mmc_claim_host(host);
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
mmc_select_voltage(host, host->ocr); mmc_select_voltage(host, host->card->ocr);
err = mmc_init_card(host, host->ocr, host->card); err = mmc_init_card(host, host->card->ocr, host->card);
mmc_release_host(host); mmc_release_host(host);
return err; return err;
...@@ -1579,7 +1580,7 @@ static int mmc_runtime_resume(struct mmc_host *host) ...@@ -1579,7 +1580,7 @@ static int mmc_runtime_resume(struct mmc_host *host)
mmc_claim_host(host); mmc_claim_host(host);
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
err = mmc_resume(host); err = mmc_resume(host);
if (err) if (err)
pr_err("%s: error %d doing aggessive resume\n", pr_err("%s: error %d doing aggessive resume\n",
...@@ -1595,7 +1596,7 @@ static int mmc_power_restore(struct mmc_host *host) ...@@ -1595,7 +1596,7 @@ static int mmc_power_restore(struct mmc_host *host)
host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
mmc_claim_host(host); mmc_claim_host(host);
ret = mmc_init_card(host, host->ocr, host->card); ret = mmc_init_card(host, host->card->ocr, host->card);
mmc_release_host(host); mmc_release_host(host);
return ret; return ret;
...@@ -1640,7 +1641,7 @@ static void mmc_attach_bus_ops(struct mmc_host *host) ...@@ -1640,7 +1641,7 @@ static void mmc_attach_bus_ops(struct mmc_host *host)
int mmc_attach_mmc(struct mmc_host *host) int mmc_attach_mmc(struct mmc_host *host)
{ {
int err; int err;
u32 ocr; u32 ocr, rocr;
BUG_ON(!host); BUG_ON(!host);
WARN_ON(!host->claimed); WARN_ON(!host->claimed);
...@@ -1677,12 +1678,12 @@ int mmc_attach_mmc(struct mmc_host *host) ...@@ -1677,12 +1678,12 @@ int mmc_attach_mmc(struct mmc_host *host)
ocr &= ~0x7F; ocr &= ~0x7F;
} }
host->ocr = mmc_select_voltage(host, ocr); rocr = mmc_select_voltage(host, ocr);
/* /*
* Can we support the voltage of the card? * Can we support the voltage of the card?
*/ */
if (!host->ocr) { if (!rocr) {
err = -EINVAL; err = -EINVAL;
goto err; goto err;
} }
...@@ -1690,7 +1691,7 @@ int mmc_attach_mmc(struct mmc_host *host) ...@@ -1690,7 +1691,7 @@ int mmc_attach_mmc(struct mmc_host *host)
/* /*
* Detect and init the card. * Detect and init the card.
*/ */
err = mmc_init_card(host, host->ocr, NULL); err = mmc_init_card(host, rocr, NULL);
if (err) if (err)
goto err; goto err;
......
...@@ -721,6 +721,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) ...@@ -721,6 +721,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
int err; int err;
u32 max_current; u32 max_current;
int retries = 10; int retries = 10;
u32 pocr = ocr;
try_again: try_again:
if (!retries) { if (!retries) {
...@@ -774,7 +775,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) ...@@ -774,7 +775,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
if (!mmc_host_is_spi(host) && rocr && if (!mmc_host_is_spi(host) && rocr &&
((*rocr & 0x41000000) == 0x41000000)) { ((*rocr & 0x41000000) == 0x41000000)) {
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
host->ocr); pocr);
if (err == -EAGAIN) { if (err == -EAGAIN) {
retries--; retries--;
goto try_again; goto try_again;
...@@ -936,6 +937,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, ...@@ -936,6 +937,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
if (IS_ERR(card)) if (IS_ERR(card))
return PTR_ERR(card); return PTR_ERR(card);
card->ocr = ocr;
card->type = MMC_TYPE_SD; card->type = MMC_TYPE_SD;
memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
} }
...@@ -1100,9 +1102,9 @@ static int mmc_sd_resume(struct mmc_host *host) ...@@ -1100,9 +1102,9 @@ static int mmc_sd_resume(struct mmc_host *host)
BUG_ON(!host->card); BUG_ON(!host->card);
mmc_claim_host(host); mmc_claim_host(host);
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
mmc_select_voltage(host, host->ocr); mmc_select_voltage(host, host->card->ocr);
err = mmc_sd_init_card(host, host->ocr, host->card); err = mmc_sd_init_card(host, host->card->ocr, host->card);
mmc_release_host(host); mmc_release_host(host);
return err; return err;
...@@ -1145,7 +1147,7 @@ static int mmc_sd_runtime_resume(struct mmc_host *host) ...@@ -1145,7 +1147,7 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
mmc_claim_host(host); mmc_claim_host(host);
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
err = mmc_sd_resume(host); err = mmc_sd_resume(host);
if (err) if (err)
pr_err("%s: error %d doing aggessive resume\n", pr_err("%s: error %d doing aggessive resume\n",
...@@ -1161,7 +1163,7 @@ static int mmc_sd_power_restore(struct mmc_host *host) ...@@ -1161,7 +1163,7 @@ static int mmc_sd_power_restore(struct mmc_host *host)
host->card->state &= ~MMC_STATE_HIGHSPEED; host->card->state &= ~MMC_STATE_HIGHSPEED;
mmc_claim_host(host); mmc_claim_host(host);
ret = mmc_sd_init_card(host, host->ocr, host->card); ret = mmc_sd_init_card(host, host->card->ocr, host->card);
mmc_release_host(host); mmc_release_host(host);
return ret; return ret;
...@@ -1206,7 +1208,7 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host) ...@@ -1206,7 +1208,7 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host)
int mmc_attach_sd(struct mmc_host *host) int mmc_attach_sd(struct mmc_host *host)
{ {
int err; int err;
u32 ocr; u32 ocr, rocr;
BUG_ON(!host); BUG_ON(!host);
WARN_ON(!host->claimed); WARN_ON(!host->claimed);
...@@ -1249,12 +1251,12 @@ int mmc_attach_sd(struct mmc_host *host) ...@@ -1249,12 +1251,12 @@ int mmc_attach_sd(struct mmc_host *host)
ocr &= ~MMC_VDD_165_195; ocr &= ~MMC_VDD_165_195;
} }
host->ocr = mmc_select_voltage(host, ocr); rocr = mmc_select_voltage(host, ocr);
/* /*
* Can we support the voltage(s) of the card(s)? * Can we support the voltage(s) of the card(s)?
*/ */
if (!host->ocr) { if (!rocr) {
err = -EINVAL; err = -EINVAL;
goto err; goto err;
} }
...@@ -1262,7 +1264,7 @@ int mmc_attach_sd(struct mmc_host *host) ...@@ -1262,7 +1264,7 @@ int mmc_attach_sd(struct mmc_host *host)
/* /*
* Detect and init the card. * Detect and init the card.
*/ */
err = mmc_sd_init_card(host, host->ocr, NULL); err = mmc_sd_init_card(host, rocr, NULL);
if (err) if (err)
goto err; goto err;
......
...@@ -594,6 +594,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, ...@@ -594,6 +594,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
int err; int err;
int retries = 10; int retries = 10;
u32 rocr = 0; u32 rocr = 0;
u32 ocr_card = ocr;
BUG_ON(!host); BUG_ON(!host);
WARN_ON(!host->claimed); WARN_ON(!host->claimed);
...@@ -762,6 +763,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, ...@@ -762,6 +763,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
card = oldcard; card = oldcard;
} }
card->ocr = ocr_card;
mmc_fixup_device(card, NULL); mmc_fixup_device(card, NULL);
if (card->type == MMC_TYPE_SD_COMBO) { if (card->type == MMC_TYPE_SD_COMBO) {
...@@ -984,8 +986,8 @@ static int mmc_sdio_resume(struct mmc_host *host) ...@@ -984,8 +986,8 @@ static int mmc_sdio_resume(struct mmc_host *host)
/* Restore power if needed */ /* Restore power if needed */
if (!mmc_card_keep_power(host)) { if (!mmc_card_keep_power(host)) {
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
mmc_select_voltage(host, host->ocr); mmc_select_voltage(host, host->card->ocr);
/* /*
* Tell runtime PM core we just powered up the card, * Tell runtime PM core we just powered up the card,
* since it still believes the card is powered off. * since it still believes the card is powered off.
...@@ -1003,7 +1005,7 @@ static int mmc_sdio_resume(struct mmc_host *host) ...@@ -1003,7 +1005,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
sdio_reset(host); sdio_reset(host);
mmc_go_idle(host); mmc_go_idle(host);
err = mmc_sdio_init_card(host, host->ocr, host->card, err = mmc_sdio_init_card(host, host->card->ocr, host->card,
mmc_card_keep_power(host)); mmc_card_keep_power(host));
} else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
/* We may have switched to 1-bit mode during suspend */ /* We may have switched to 1-bit mode during suspend */
...@@ -1043,7 +1045,7 @@ static int mmc_sdio_resume(struct mmc_host *host) ...@@ -1043,7 +1045,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
static int mmc_sdio_power_restore(struct mmc_host *host) static int mmc_sdio_power_restore(struct mmc_host *host)
{ {
int ret; int ret;
u32 ocr; u32 ocr, rocr;
BUG_ON(!host); BUG_ON(!host);
BUG_ON(!host->card); BUG_ON(!host->card);
...@@ -1080,13 +1082,13 @@ static int mmc_sdio_power_restore(struct mmc_host *host) ...@@ -1080,13 +1082,13 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
if (host->ocr_avail_sdio) if (host->ocr_avail_sdio)
host->ocr_avail = host->ocr_avail_sdio; host->ocr_avail = host->ocr_avail_sdio;
host->ocr = mmc_select_voltage(host, ocr & ~0x7F); rocr = mmc_select_voltage(host, ocr & ~0x7F);
if (!host->ocr) { if (!rocr) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
ret = mmc_sdio_init_card(host, host->ocr, host->card, ret = mmc_sdio_init_card(host, rocr, host->card,
mmc_card_keep_power(host)); mmc_card_keep_power(host));
if (!ret && host->sdio_irqs) if (!ret && host->sdio_irqs)
mmc_signal_sdio_irq(host); mmc_signal_sdio_irq(host);
...@@ -1107,7 +1109,7 @@ static int mmc_sdio_runtime_suspend(struct mmc_host *host) ...@@ -1107,7 +1109,7 @@ static int mmc_sdio_runtime_suspend(struct mmc_host *host)
static int mmc_sdio_runtime_resume(struct mmc_host *host) static int mmc_sdio_runtime_resume(struct mmc_host *host)
{ {
/* Restore power and re-initialize. */ /* Restore power and re-initialize. */
mmc_power_up(host, host->ocr); mmc_power_up(host, host->card->ocr);
return mmc_sdio_power_restore(host); return mmc_sdio_power_restore(host);
} }
...@@ -1130,7 +1132,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = { ...@@ -1130,7 +1132,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
int mmc_attach_sdio(struct mmc_host *host) int mmc_attach_sdio(struct mmc_host *host)
{ {
int err, i, funcs; int err, i, funcs;
u32 ocr; u32 ocr, rocr;
struct mmc_card *card; struct mmc_card *card;
BUG_ON(!host); BUG_ON(!host);
...@@ -1155,12 +1157,12 @@ int mmc_attach_sdio(struct mmc_host *host) ...@@ -1155,12 +1157,12 @@ int mmc_attach_sdio(struct mmc_host *host)
ocr &= ~0x7F; ocr &= ~0x7F;
} }
host->ocr = mmc_select_voltage(host, ocr); rocr = mmc_select_voltage(host, ocr);
/* /*
* Can we support the voltage(s) of the card(s)? * Can we support the voltage(s) of the card(s)?
*/ */
if (!host->ocr) { if (!rocr) {
err = -EINVAL; err = -EINVAL;
goto err; goto err;
} }
...@@ -1168,7 +1170,7 @@ int mmc_attach_sdio(struct mmc_host *host) ...@@ -1168,7 +1170,7 @@ int mmc_attach_sdio(struct mmc_host *host)
/* /*
* Detect and init the card. * Detect and init the card.
*/ */
err = mmc_sdio_init_card(host, host->ocr, NULL, 0); err = mmc_sdio_init_card(host, rocr, NULL, 0);
if (err) if (err)
goto err; goto err;
......
...@@ -240,6 +240,7 @@ struct mmc_part { ...@@ -240,6 +240,7 @@ struct mmc_part {
struct mmc_card { struct mmc_card {
struct mmc_host *host; /* the host this device belongs to */ struct mmc_host *host; /* the host this device belongs to */
struct device dev; /* the device */ struct device dev; /* the device */
u32 ocr; /* the current OCR setting */
unsigned int rca; /* relative card address of device */ unsigned int rca; /* relative card address of device */
unsigned int type; /* card type */ unsigned int type; /* card type */
#define MMC_TYPE_MMC 0 /* MMC card */ #define MMC_TYPE_MMC 0 /* MMC card */
......
...@@ -309,7 +309,6 @@ struct mmc_host { ...@@ -309,7 +309,6 @@ struct mmc_host {
spinlock_t lock; /* lock for claim and bus ops */ spinlock_t lock; /* lock for claim and bus ops */
struct mmc_ios ios; /* current io bus settings */ struct mmc_ios ios; /* current io bus settings */
u32 ocr; /* the current OCR setting */
/* group bitfields together to minimize padding */ /* group bitfields together to minimize padding */
unsigned int use_spi_crc:1; unsigned int use_spi_crc:1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册