Skip to content

Commit e94cfef

Browse files
Ulf Hanssoncjb
authored andcommitted
mmc: block: Enable runtime pm for mmc blkdevice
Once the mmc blkdevice is being probed, runtime pm will be enabled. By using runtime autosuspend, the power save operations can be done when request inactivity occurs for a certain time. Right now the selected timeout value is set to 3 s. Obviously this value will likely need to be configurable somehow since it needs to be trimmed depending on the power save algorithm. For SD-combo cards, we are still leaving the enablement of runtime PM to the SDIO init sequence since it depends on the capabilities of the SDIO func driver. Moreover, when the blk device is being suspended, we make sure the device will be runtime resumed. The reason for doing this is that we want the host suspend sequence to be unaware of any runtime power save operations done for the card in this phase. Thus it can just handle the suspend as the card is fully powered from a runtime perspective. Finally, this patch prepares to make it possible to move BKOPS handling into the runtime callbacks for the mmc bus_ops. Thus IDLE BKOPS can be accomplished. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 12d01d0 commit e94cfef

6 files changed

Lines changed: 60 additions & 14 deletions

File tree

‎drivers/mmc/card/block.c‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/delay.h>
3535
#include <linux/capability.h>
3636
#include <linux/compat.h>
37+
#include <linux/pm_runtime.h>
3738

3839
#include <linux/mmc/ioctl.h>
3940
#include <linux/mmc/card.h>
@@ -224,7 +225,7 @@ static ssize_t power_ro_lock_store(struct device *dev,
224225
md = mmc_blk_get(dev_to_disk(dev));
225226
card = md->queue.card;
226227

227-
mmc_claim_host(card->host);
228+
mmc_get_card(card);
228229

229230
ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP,
230231
card->ext_csd.boot_ro_lock |
@@ -235,7 +236,7 @@ static ssize_t power_ro_lock_store(struct device *dev,
235236
else
236237
card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN;
237238

238-
mmc_release_host(card->host);
239+
mmc_put_card(card);
239240

240241
if (!ret) {
241242
pr_info("%s: Locking boot partition ro until next power on\n",
@@ -522,7 +523,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
522523

523524
mrq.cmd = &cmd;
524525

525-
mmc_claim_host(card->host);
526+
mmc_get_card(card);
526527

527528
err = mmc_blk_part_switch(card, md);
528529
if (err)
@@ -599,7 +600,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
599600
}
600601

601602
cmd_rel_host:
602-
mmc_release_host(card->host);
603+
mmc_put_card(card);
603604

604605
cmd_done:
605606
mmc_blk_put(md);
@@ -1921,7 +1922,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
19211922

19221923
if (req && !mq->mqrq_prev->req)
19231924
/* claim host only for the first request */
1924-
mmc_claim_host(card->host);
1925+
mmc_get_card(card);
19251926

19261927
ret = mmc_blk_part_switch(card, md);
19271928
if (ret) {
@@ -1965,7 +1966,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
19651966
* In case sepecial request, there is no reentry to
19661967
* the 'mmc_blk_issue_rq' with 'mqrq_prev->req'.
19671968
*/
1968-
mmc_release_host(card->host);
1969+
mmc_put_card(card);
19691970
return ret;
19701971
}
19711972

@@ -2362,6 +2363,19 @@ static int mmc_blk_probe(struct mmc_card *card)
23622363
if (mmc_add_disk(part_md))
23632364
goto out;
23642365
}
2366+
2367+
pm_runtime_set_autosuspend_delay(&card->dev, 3000);
2368+
pm_runtime_use_autosuspend(&card->dev);
2369+
2370+
/*
2371+
* Don't enable runtime PM for SD-combo cards here. Leave that
2372+
* decision to be taken during the SDIO init sequence instead.
2373+
*/
2374+
if (card->type != MMC_TYPE_SD_COMBO) {
2375+
pm_runtime_set_active(&card->dev);
2376+
pm_runtime_enable(&card->dev);
2377+
}
2378+
23652379
return 0;
23662380

23672381
out:
@@ -2375,9 +2389,13 @@ static void mmc_blk_remove(struct mmc_card *card)
23752389
struct mmc_blk_data *md = mmc_get_drvdata(card);
23762390

23772391
mmc_blk_remove_parts(card, md);
2392+
pm_runtime_get_sync(&card->dev);
23782393
mmc_claim_host(card->host);
23792394
mmc_blk_part_switch(card, md);
23802395
mmc_release_host(card->host);
2396+
if (card->type != MMC_TYPE_SD_COMBO)
2397+
pm_runtime_disable(&card->dev);
2398+
pm_runtime_put_noidle(&card->dev);
23812399
mmc_blk_remove_req(md);
23822400
mmc_set_drvdata(card, NULL);
23832401
}
@@ -2389,6 +2407,7 @@ static int mmc_blk_suspend(struct mmc_card *card)
23892407
struct mmc_blk_data *md = mmc_get_drvdata(card);
23902408

23912409
if (md) {
2410+
pm_runtime_get_sync(&card->dev);
23922411
mmc_queue_suspend(&md->queue);
23932412
list_for_each_entry(part_md, &md->part, part) {
23942413
mmc_queue_suspend(&part_md->queue);
@@ -2412,6 +2431,7 @@ static int mmc_blk_resume(struct mmc_card *card)
24122431
list_for_each_entry(part_md, &md->part, part) {
24132432
mmc_queue_resume(&part_md->queue);
24142433
}
2434+
pm_runtime_put(&card->dev);
24152435
}
24162436
return 0;
24172437
}

‎drivers/mmc/core/core.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,29 @@ void mmc_release_host(struct mmc_host *host)
970970
}
971971
EXPORT_SYMBOL(mmc_release_host);
972972

973+
/*
974+
* This is a helper function, which fetches a runtime pm reference for the
975+
* card device and also claims the host.
976+
*/
977+
void mmc_get_card(struct mmc_card *card)
978+
{
979+
pm_runtime_get_sync(&card->dev);
980+
mmc_claim_host(card->host);
981+
}
982+
EXPORT_SYMBOL(mmc_get_card);
983+
984+
/*
985+
* This is a helper function, which releases the host and drops the runtime
986+
* pm reference for the card device.
987+
*/
988+
void mmc_put_card(struct mmc_card *card)
989+
{
990+
mmc_release_host(card->host);
991+
pm_runtime_mark_last_busy(&card->dev);
992+
pm_runtime_put_autosuspend(&card->dev);
993+
}
994+
EXPORT_SYMBOL(mmc_put_card);
995+
973996
/*
974997
* Internal function that does the actual ios call to the host driver,
975998
* optionally printing some debug output.

‎drivers/mmc/core/debugfs.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ static int mmc_dbg_card_status_get(void *data, u64 *val)
258258
u32 status;
259259
int ret;
260260

261-
mmc_claim_host(card->host);
261+
mmc_get_card(card);
262262

263263
ret = mmc_send_status(data, &status);
264264
if (!ret)
265265
*val = status;
266266

267-
mmc_release_host(card->host);
267+
mmc_put_card(card);
268268

269269
return ret;
270270
}
@@ -291,9 +291,9 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
291291
goto out_free;
292292
}
293293

294-
mmc_claim_host(card->host);
294+
mmc_get_card(card);
295295
err = mmc_send_ext_csd(card, ext_csd);
296-
mmc_release_host(card->host);
296+
mmc_put_card(card);
297297
if (err)
298298
goto out_free;
299299

‎drivers/mmc/core/mmc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,14 +1380,14 @@ static void mmc_detect(struct mmc_host *host)
13801380
BUG_ON(!host);
13811381
BUG_ON(!host->card);
13821382

1383-
mmc_claim_host(host);
1383+
mmc_get_card(host->card);
13841384

13851385
/*
13861386
* Just check if our card has been removed.
13871387
*/
13881388
err = _mmc_detect_card_removed(host);
13891389

1390-
mmc_release_host(host);
1390+
mmc_put_card(host->card);
13911391

13921392
if (err) {
13931393
mmc_remove(host);

‎drivers/mmc/core/sd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,14 @@ static void mmc_sd_detect(struct mmc_host *host)
10421042
BUG_ON(!host);
10431043
BUG_ON(!host->card);
10441044

1045-
mmc_claim_host(host);
1045+
mmc_get_card(host->card);
10461046

10471047
/*
10481048
* Just check if our card has been removed.
10491049
*/
10501050
err = _mmc_detect_card_removed(host);
10511051

1052-
mmc_release_host(host);
1052+
mmc_put_card(host->card);
10531053

10541054
if (err) {
10551055
mmc_sd_remove(host);

‎include/linux/mmc/core.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
190190
extern void mmc_release_host(struct mmc_host *host);
191191
extern int mmc_try_claim_host(struct mmc_host *host);
192192

193+
extern void mmc_get_card(struct mmc_card *card);
194+
extern void mmc_put_card(struct mmc_card *card);
195+
193196
extern int mmc_flush_cache(struct mmc_card *);
194197

195198
extern int mmc_detect_card_removed(struct mmc_host *host);

0 commit comments

Comments
 (0)