All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3]mmc: implemented runtime pm for mmc host
@ 2011-01-14  8:23 Chuanxiao Dong
  2011-01-17 10:59 ` Tardy, Pierre
  0 siblings, 1 reply; 19+ messages in thread
From: Chuanxiao Dong @ 2011-01-14  8:23 UTC (permalink / raw)
  To: linux-mmc; +Cc: linux-kernel, cjb, ohad

MMC host need to power ungate host each time before sending a request and
try to power gate host each time after the request is done.

MMC host has a sysfs interface to let user specify the auto suspended delay.
Each slot of the host controller can have a different delay for runtime
suspended.

Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
---
 drivers/mmc/core/core.c |   15 +++++++++++++++
 drivers/mmc/core/host.c |   21 +++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 6625c05..e296c5a 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -133,6 +133,9 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
 			mrq->done(mrq);
 
 		mmc_host_clk_gate(host);
+
+		/* put the host after using */
+		pm_runtime_put(&host->class_dev);
 	}
 }
 
@@ -150,6 +153,12 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 		 mmc_hostname(host), mrq->cmd->opcode,
 		 mrq->cmd->arg, mrq->cmd->flags);
 
+	/*
+	 * Before touch any of host controller registers,
+	 * driver should make sure the host is powered up
+	 */
+	pm_runtime_get_sync(&host->class_dev);
+
 	if (mrq->data) {
 		pr_debug("%s:     blksz %d blocks %d flags %08x "
 			"tsac %d ms nsac %d\n",
@@ -1522,6 +1531,9 @@ void mmc_rescan(struct work_struct *work)
 	if (host->rescan_disable)
 		return;
 
+	/* power up host controller first */
+	pm_runtime_get_sync(&host->class_dev);
+
 	mmc_bus_get(host);
 
 	/*
@@ -1564,6 +1576,9 @@ void mmc_rescan(struct work_struct *work)
 	mmc_release_host(host);
 
  out:
+	/* power off host controller */
+	pm_runtime_put(&host->class_dev);
+
 	if (host->caps & MMC_CAP_NEEDS_POLL)
 		mmc_schedule_delayed_work(&host->detect, HZ);
 }
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index b3ac6c5..a27b811 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -19,6 +19,7 @@
 #include <linux/leds.h>
 #include <linux/slab.h>
 #include <linux/suspend.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -28,6 +29,14 @@
 
 #define cls_dev_to_mmc_host(d)	container_of(d, struct mmc_host, class_dev)
 
+static const struct dev_pm_ops host_pm = {
+	SET_RUNTIME_PM_OPS(
+		pm_generic_runtime_suspend,
+		pm_generic_runtime_resume,
+		pm_generic_runtime_idle
+	)
+};
+
 static void mmc_host_classdev_release(struct device *dev)
 {
 	struct mmc_host *host = cls_dev_to_mmc_host(dev);
@@ -37,6 +46,7 @@ static void mmc_host_classdev_release(struct device *dev)
 static struct class mmc_host_class = {
 	.name		= "mmc_host",
 	.dev_release	= mmc_host_classdev_release,
+	.pm = &host_pm,
 };
 
 int mmc_register_host_class(void)
@@ -334,6 +344,15 @@ int mmc_add_host(struct mmc_host *host)
 	if (err)
 		return err;
 
+	/* enable runtime pm */
+	err = pm_runtime_set_active(&host->class_dev);
+	if (err)
+		pr_err("err is %d when active mmc host\n", err);
+	else {
+		pm_runtime_enable(&host->class_dev);
+		pm_runtime_set_autosuspend_delay(&host->class_dev, 100);
+	}
+
 #ifdef CONFIG_DEBUG_FS
 	mmc_add_host_debugfs(host);
 #endif
@@ -363,6 +382,8 @@ void mmc_remove_host(struct mmc_host *host)
 	mmc_remove_host_debugfs(host);
 #endif
 
+	pm_runtime_disable(&host->class_dev);
+
 	device_del(&host->class_dev);
 
 	led_trigger_unregister_simple(host->led);
-- 
1.6.6.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-01-27 14:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-14  8:23 [PATCH v1 1/3]mmc: implemented runtime pm for mmc host Chuanxiao Dong
2011-01-17 10:59 ` Tardy, Pierre
2011-01-18  7:27   ` Dong, Chuanxiao
2011-01-18 16:39     ` Tardy, Pierre
2011-01-19  9:04       ` Dong, Chuanxiao
2011-01-19  9:45         ` Tardy, Pierre
2011-01-20  5:08           ` Chris Ball
2011-01-22 21:24             ` Ohad Ben-Cohen
2011-01-23  5:20               ` Nicolas Pitre
2011-01-23 20:06                 ` Tardy, Pierre
2011-01-24 14:55                   ` Nicolas Pitre
2011-01-23 20:39                 ` Ohad Ben-Cohen
2011-01-24 10:19                   ` Dong, Chuanxiao
2011-01-24 15:01                   ` Nicolas Pitre
2011-01-24 22:11             ` Linus Walleij
2011-01-25 21:34               ` Tardy, Pierre
2011-01-26 18:44                 ` Linus Walleij
2011-01-26 19:19                   ` Linus Walleij
2011-01-27 14:06                     ` Tardy, Pierre

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.