Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: core: Restructure and simplify code for mmc sleep|awake

The mmc_card_sleep|awake APIs are not being used since the support is
already properly encapsulated within the suspend sequence. Sleep|awake
command is also specific for eMMC.

We remove the sleep|awake bus_ops, the mmc_card_sleep|awake APIs and
move the code into the mmc specific core instead. This also includes
the mmc ops function, mmc_sleepawake. All releated functions have then
become static and we have got far less code to maintain.

Additionally this patch also simplifies the code from mmc_sleepawake,
since it is only used to put the card to sleep and not awake.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by

Ulf Hansson and committed by
Chris Ball
07a68216 c4d770d7

+41 -123
-46
drivers/mmc/core/core.c
··· 2550 2550 } 2551 2551 EXPORT_SYMBOL(mmc_power_restore_host); 2552 2552 2553 - int mmc_card_awake(struct mmc_host *host) 2554 - { 2555 - int err = -ENOSYS; 2556 - 2557 - if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 2558 - return 0; 2559 - 2560 - mmc_bus_get(host); 2561 - 2562 - if (host->bus_ops && !host->bus_dead && host->bus_ops->awake) 2563 - err = host->bus_ops->awake(host); 2564 - 2565 - mmc_bus_put(host); 2566 - 2567 - return err; 2568 - } 2569 - EXPORT_SYMBOL(mmc_card_awake); 2570 - 2571 - int mmc_card_sleep(struct mmc_host *host) 2572 - { 2573 - int err = -ENOSYS; 2574 - 2575 - if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 2576 - return 0; 2577 - 2578 - mmc_bus_get(host); 2579 - 2580 - if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep) 2581 - err = host->bus_ops->sleep(host); 2582 - 2583 - mmc_bus_put(host); 2584 - 2585 - return err; 2586 - } 2587 - EXPORT_SYMBOL(mmc_card_sleep); 2588 - 2589 - int mmc_card_can_sleep(struct mmc_host *host) 2590 - { 2591 - struct mmc_card *card = host->card; 2592 - 2593 - if (card && mmc_card_mmc(card) && card->ext_csd.rev >= 3) 2594 - return 1; 2595 - return 0; 2596 - } 2597 - EXPORT_SYMBOL(mmc_card_can_sleep); 2598 - 2599 2553 /* 2600 2554 * Flush the cache to the non-volatile storage. 2601 2555 */
-2
drivers/mmc/core/core.h
··· 16 16 #define MMC_CMD_RETRIES 3 17 17 18 18 struct mmc_bus_ops { 19 - int (*awake)(struct mmc_host *); 20 - int (*sleep)(struct mmc_host *); 21 19 void (*remove)(struct mmc_host *); 22 20 void (*detect)(struct mmc_host *); 23 21 int (*suspend)(struct mmc_host *);
+41 -36
drivers/mmc/core/mmc.c
··· 1321 1321 return err; 1322 1322 } 1323 1323 1324 + static int mmc_can_sleep(struct mmc_card *card) 1325 + { 1326 + return (card && card->ext_csd.rev >= 3); 1327 + } 1328 + 1329 + static int mmc_sleep(struct mmc_host *host) 1330 + { 1331 + struct mmc_command cmd = {0}; 1332 + struct mmc_card *card = host->card; 1333 + int err; 1334 + 1335 + if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 1336 + return 0; 1337 + 1338 + err = mmc_deselect_cards(host); 1339 + if (err) 1340 + return err; 1341 + 1342 + cmd.opcode = MMC_SLEEP_AWAKE; 1343 + cmd.arg = card->rca << 16; 1344 + cmd.arg |= 1 << 15; 1345 + 1346 + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1347 + err = mmc_wait_for_cmd(host, &cmd, 0); 1348 + if (err) 1349 + return err; 1350 + 1351 + /* 1352 + * If the host does not wait while the card signals busy, then we will 1353 + * will have to wait the sleep/awake timeout. Note, we cannot use the 1354 + * SEND_STATUS command to poll the status because that command (and most 1355 + * others) is invalid while the card sleeps. 1356 + */ 1357 + if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 1358 + mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); 1359 + 1360 + return err; 1361 + } 1362 + 1324 1363 static int mmc_can_poweroff_notify(const struct mmc_card *card) 1325 1364 { 1326 1365 return card && ··· 1462 1423 1463 1424 if (mmc_can_poweroff_notify(host->card)) 1464 1425 err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT); 1465 - else if (mmc_card_can_sleep(host)) 1466 - err = mmc_card_sleep(host); 1426 + else if (mmc_can_sleep(host->card)) 1427 + err = mmc_sleep(host); 1467 1428 else if (!mmc_host_is_spi(host)) 1468 1429 err = mmc_deselect_cards(host); 1469 1430 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); ··· 1553 1514 return ret; 1554 1515 } 1555 1516 1556 - static int mmc_sleep(struct mmc_host *host) 1557 - { 1558 - struct mmc_card *card = host->card; 1559 - int err = -ENOSYS; 1560 - 1561 - if (card && card->ext_csd.rev >= 3) { 1562 - err = mmc_card_sleepawake(host, 1); 1563 - if (err < 0) 1564 - pr_debug("%s: Error %d while putting card into sleep", 1565 - mmc_hostname(host), err); 1566 - } 1567 - 1568 - return err; 1569 - } 1570 - 1571 - static int mmc_awake(struct mmc_host *host) 1572 - { 1573 - struct mmc_card *card = host->card; 1574 - int err = -ENOSYS; 1575 - 1576 - if (card && card->ext_csd.rev >= 3) { 1577 - err = mmc_card_sleepawake(host, 0); 1578 - if (err < 0) 1579 - pr_debug("%s: Error %d while awaking sleeping card", 1580 - mmc_hostname(host), err); 1581 - } 1582 - 1583 - return err; 1584 - } 1585 - 1586 1517 static const struct mmc_bus_ops mmc_ops = { 1587 - .awake = mmc_awake, 1588 - .sleep = mmc_sleep, 1589 1518 .remove = mmc_remove, 1590 1519 .detect = mmc_detect, 1591 1520 .suspend = NULL, ··· 1563 1556 }; 1564 1557 1565 1558 static const struct mmc_bus_ops mmc_ops_unsafe = { 1566 - .awake = mmc_awake, 1567 - .sleep = mmc_sleep, 1568 1559 .remove = mmc_remove, 1569 1560 .detect = mmc_detect, 1570 1561 .suspend = mmc_suspend,
-34
drivers/mmc/core/mmc_ops.c
··· 59 59 return _mmc_select_card(host, NULL); 60 60 } 61 61 62 - int mmc_card_sleepawake(struct mmc_host *host, int sleep) 63 - { 64 - struct mmc_command cmd = {0}; 65 - struct mmc_card *card = host->card; 66 - int err; 67 - 68 - if (sleep) 69 - mmc_deselect_cards(host); 70 - 71 - cmd.opcode = MMC_SLEEP_AWAKE; 72 - cmd.arg = card->rca << 16; 73 - if (sleep) 74 - cmd.arg |= 1 << 15; 75 - 76 - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 77 - err = mmc_wait_for_cmd(host, &cmd, 0); 78 - if (err) 79 - return err; 80 - 81 - /* 82 - * If the host does not wait while the card signals busy, then we will 83 - * will have to wait the sleep/awake timeout. Note, we cannot use the 84 - * SEND_STATUS command to poll the status because that command (and most 85 - * others) is invalid while the card sleeps. 86 - */ 87 - if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 88 - mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); 89 - 90 - if (!sleep) 91 - err = mmc_select_card(card); 92 - 93 - return err; 94 - } 95 - 96 62 int mmc_go_idle(struct mmc_host *host) 97 63 { 98 64 int err;
-1
drivers/mmc/core/mmc_ops.h
··· 24 24 int mmc_send_cid(struct mmc_host *host, u32 *cid); 25 25 int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp); 26 26 int mmc_spi_set_crc(struct mmc_host *host, int use_crc); 27 - int mmc_card_sleepawake(struct mmc_host *host, int sleep); 28 27 int mmc_bus_test(struct mmc_card *card, u8 bus_width); 29 28 int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status); 30 29
-4
include/linux/mmc/host.h
··· 425 425 } 426 426 #endif 427 427 428 - int mmc_card_awake(struct mmc_host *host); 429 - int mmc_card_sleep(struct mmc_host *host); 430 - int mmc_card_can_sleep(struct mmc_host *host); 431 - 432 428 int mmc_pm_notify(struct notifier_block *notify_block, unsigned long, void *); 433 429 434 430 /* Module parameter */