[RFC 2/2] mmc: core: Add support for power sequences

Ulf Hansson ulf.hansson at linaro.org
Thu Jun 19 06:04:51 PDT 2014


The MMC subsystem uses a discoverable bus which sometimes means the
power sequences to enable power to the card, is far too complex to be
handled through the regular ->set_ios() callback.

To adress these scenarios, we try to fetch a pwrseq method while
parsing the common MMC DT bindings. If a such method is found we select
the corresponding state for it from mmc_power_up|off().

Signed-off-by: Ulf Hansson <ulf.hansson at linaro.org>
---
 drivers/mmc/core/core.c  |    7 +++++++
 drivers/mmc/core/host.c  |    5 +++++
 include/linux/mmc/host.h |    3 +++
 3 files changed, 15 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 7dc0c85..46558b5 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -29,6 +29,7 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/of.h>
+#include <linux/pwrseq.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
@@ -1533,6 +1534,9 @@ void mmc_power_up(struct mmc_host *host, u32 ocr)
 
 	mmc_host_clk_hold(host);
 
+	if (!IS_ERR(host->pwrseq))
+		pwrseq_select_state(host->pwrseq, PWRSEQ_POWER_ON);
+
 	host->ios.vdd = fls(ocr) - 1;
 	if (mmc_host_is_spi(host))
 		host->ios.chip_select = MMC_CS_HIGH;
@@ -1591,6 +1595,9 @@ void mmc_power_off(struct mmc_host *host)
 	host->ios.timing = MMC_TIMING_LEGACY;
 	mmc_set_ios(host);
 
+	if (!IS_ERR(host->pwrseq))
+		pwrseq_select_state(host->pwrseq, PWRSEQ_POWER_OFF);
+
 	/*
 	 * Some configurations, such as the 802.11 SDIO card in the OLPC
 	 * XO-1.5, require a short delay after poweroff before the card
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 95cceae..fdf8596 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -22,6 +22,7 @@
 #include <linux/leds.h>
 #include <linux/slab.h>
 #include <linux/suspend.h>
+#include <linux/pwrseq.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -317,6 +318,10 @@ int mmc_of_parse(struct mmc_host *host)
 	if (!host->parent || !host->parent->of_node)
 		return 0;
 
+	host->pwrseq = devm_pwrseq_get_optional(host->parent);
+	if (IS_ERR(host->pwrseq))
+		return PTR_ERR(host->pwrseq);
+
 	np = host->parent->of_node;
 
 	/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 7960424..306b78c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -195,9 +195,12 @@ struct mmc_supply {
 	struct regulator *vqmmc;	/* Optional Vccq supply */
 };
 
+struct pwrseq;
+
 struct mmc_host {
 	struct device		*parent;
 	struct device		class_dev;
+	struct pwrseq		*pwrseq;
 	int			index;
 	const struct mmc_host_ops *ops;
 	unsigned int		f_min;
-- 
1.7.9.5




More information about the linux-arm-kernel mailing list