[PATCH] sdio add regulator vsdio to dynamic control sdio power

STALE5495d

6 messages, 4 authors, 2011-07-22 · open the first message on its own page

[PATCH] sdio add regulator vsdio to dynamic control sdio power

From: Zhangfei Gao <hidden>
Date: 2011-07-21 02:34:31

sdio client has the requirement to dynamically power on/off
With regulator vsdio, so sdio client power on/off when mmc_power_up/down
Add brownstone support sdio with regulator vsdio, 

Zhangfei Gao (2):
  mmc: sdio add regulator vsdio
  ARM: mmp2: support sdio with regulator vsdio

 arch/arm/mach-mmp/brownstone.c |   60 ++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/host/sdhci.c       |   24 ++++++++++++++++
 include/linux/mmc/sdhci.h      |    2 +
 3 files changed, 84 insertions(+), 2 deletions(-)

[PATCH] mmc: sdio add regulator vsdio

From: Zhangfei Gao <hidden>
Date: 2011-07-21 02:34:32

sdio client may be required power on/off dynamically.
With regulator vsdio, sdio client power on/off could be executed by mmc_power_up/down

CC: Ohad Ben-Cohen <redacted>
Signed-off-by: Zhangfei Gao <redacted>
---
 drivers/mmc/host/sdhci.c  |   24 ++++++++++++++++++++++++
 include/linux/mmc/sdhci.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 790f959..61fff10 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1295,6 +1295,18 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 
 	sdhci_set_clock(host, ios->clock);
 
+	if (host->vsdio) {
+		if (ios->power_mode != host->power_mode_old) {
+			if (ios->power_mode == MMC_POWER_OFF)
+				regulator_disable(host->vsdio);
+
+			if (ios->power_mode == MMC_POWER_UP)
+				regulator_enable(host->vsdio);
+		}
+
+		host->power_mode_old = ios->power_mode;
+	}
+
 	if (ios->power_mode == MMC_POWER_OFF)
 		sdhci_set_power(host, -1);
 	else
@@ -2751,6 +2763,13 @@ int sdhci_add_host(struct sdhci_host *host)
 		regulator_enable(host->vmmc);
 	}
 
+	host->vsdio = regulator_get(mmc_dev(mmc), "vsdio");
+	if (IS_ERR(host->vsdio))
+		host->vsdio = NULL;
+	else
+		printk(KERN_INFO "%s: vsdio regulator found\n",
+			mmc_hostname(mmc));
+
 	sdhci_init(host, 0);
 
 #ifdef CONFIG_MMC_DEBUG
@@ -2842,6 +2861,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
 		regulator_put(host->vmmc);
 	}
 
+	if (host->vsdio) {
+		regulator_disable(host->vsdio);
+		regulator_put(host->vsdio);
+	}
+
 	kfree(host->adma_desc);
 	kfree(host->align_buffer);
 
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index 13c13f8..bea07c7 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -94,6 +94,8 @@ struct sdhci_host {
 	const struct sdhci_ops *ops;	/* Low level hw interface */
 
 	struct regulator *vmmc;	/* Power regulator */
+	struct regulator *vsdio;	/* sdio Power regulator */
+	unsigned char power_mode_old;	/* power supply mode */
 
 	/* Internal data */
 	struct mmc_host *mmc;	/* MMC structure */
-- 
1.6.0.4

[PATCH] ARM: mmp2: support sdio with regulator vsdio

From: Zhangfei Gao <hidden>
Date: 2011-07-21 02:34:33

Add regulator vsdio, which controled by mmc core to handle sdio chip power

Test With CONFIG_PM_RUNTIME=y
8787 power is enabled if any client module over sdio is insmod, and disbled automatically after all client modules over sdio are rmmod
Also 8787 power could be controled by mmc_start/stop_host

Signed-off-by: Zhangfei Gao <redacted>
---
 arch/arm/mach-mmp/brownstone.c |   60 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mach-mmp/brownstone.c b/arch/arm/mach-mmp/brownstone.c
index c79162a..63315e2 100644
--- a/arch/arm/mach-mmp/brownstone.c
+++ b/arch/arm/mach-mmp/brownstone.c
@@ -89,6 +89,9 @@ static unsigned long brownstone_pin_config[] __initdata = {
 	GPIO41_MMC2_CMD | MFP_PULL_HIGH,
 	GPIO42_MMC2_CLK,
 
+	GPIO57_GPIO | MFP_LPM_DRIVE_HIGH | MFP_PULL_HIGH,
+	GPIO58_GPIO | MFP_LPM_DRIVE_HIGH | MFP_PULL_HIGH,
+
 	/* MMC2 */
 	GPIO165_MMC3_DAT7 | MFP_PULL_HIGH,
 	GPIO162_MMC3_DAT6 | MFP_PULL_HIGH,
@@ -180,12 +183,66 @@ static struct sdhci_pxa_platdata mmp2_sdh_platdata_mmc0 = {
 	.clk_delay_cycles = 0x1f,
 };
 
+static struct sdhci_pxa_platdata mmp2_sdh_platdata_mmc1 = {
+	.flags = PXA_FLAG_CARD_PERMANENT,
+};
+
 static struct sdhci_pxa_platdata mmp2_sdh_platdata_mmc2 = {
 	.clk_delay_cycles = 0x1f,
 	.flags = PXA_FLAG_CARD_PERMANENT
 		| PXA_FLAG_SD_8_BIT_CAPABLE_SLOT,
 };
 
+static struct regulator_consumer_supply sdio_power_supplies[] = {
+	REGULATOR_SUPPLY("vsdio", "sdhci-pxav3.1"),
+};
+
+static struct regulator_init_data sdio_power_data = {
+	.constraints	= {
+		.valid_ops_mask		= REGULATOR_CHANGE_STATUS,
+	},
+	.num_consumer_supplies	= ARRAY_SIZE(sdio_power_supplies),
+	.consumer_supplies	= sdio_power_supplies,
+};
+
+static struct fixed_voltage_config sdio_power = {
+	.supply_name		= "vsdio",
+	.microvolts		= 3000000,
+	.gpio			= mfp_to_gpio(MFP_PIN_GPIO57),
+	.enable_high		= 1,
+	.enabled_at_boot	= 0,
+	.init_data		= &sdio_power_data,
+};
+
+static struct platform_device sdio_power_device = {
+	.name		= "reg-fixed-voltage",
+	.id		= 2,
+	.dev = {
+		.platform_data = &sdio_power,
+	},
+};
+
+static int __init brownstone_init_mmc(void)
+{
+	/*
+	 * PDn: GPIO58; RESETn: GPIO57
+	 * 8787, RESETn keeps high, PDn control power
+	 * on: PDn 1; off: PDn 0;
+	 */
+	int RESETn = mfp_to_gpio(MFP_PIN_GPIO58);
+
+	if (gpio_request(RESETn, "sdio RESETn")) {
+		pr_err("Failed to request sdio RESETn gpio\n");
+		return -EIO;
+	}
+	gpio_direction_output(RESETn, 1);
+	gpio_free(RESETn);
+
+	platform_device_register(&sdio_power_device);
+	mmp2_add_sdhost(0, &mmp2_sdh_platdata_mmc0); /* SD/MMC */
+	mmp2_add_sdhost(1, &mmp2_sdh_platdata_mmc1); /* sdio */
+	mmp2_add_sdhost(2, &mmp2_sdh_platdata_mmc2); /* eMMC */
+}
 
 static void __init brownstone_init(void)
 {
@@ -195,8 +252,7 @@ static void __init brownstone_init(void)
 	mmp2_add_uart(1);
 	mmp2_add_uart(3);
 	mmp2_add_twsi(1, NULL, ARRAY_AND_SIZE(brownstone_twsi1_info));
-	mmp2_add_sdhost(0, &mmp2_sdh_platdata_mmc0); /* SD/MMC */
-	mmp2_add_sdhost(2, &mmp2_sdh_platdata_mmc2); /* eMMC */
+	brownstone_init_mmc();
 
 	/* enable 5v regulator */
 	platform_device_register(&brownstone_v_5vp_device);
-- 
1.6.0.4

[PATCH] mmc: sdio add regulator vsdio

From: Daniel Drake <hidden>
Date: 2011-07-22 06:50:14

On 21 July 2011 03:34, Zhangfei Gao [off-list ref] wrote:
sdio client may be required power on/off dynamically.
With regulator vsdio, sdio client power on/off could be executed by mmc_power_up/down
I think you can/should do this with vmmc. When the device gets powered
down (e.g. in runtime suspend), the voltage should be cut, so it
should be possible to use the existing regulator.

I also looked at doing this before, when it looked like we would have
to manipulate a GPIO reset line for SD8686. I decided that the current
vmmc implementation in sdhci wasn't quite complete enough, but it
wouldn't be much effort to correct this.

Daniel

[PATCH] mmc: sdio add regulator vsdio

From: zhangfei gao <hidden>
Date: 2011-07-22 07:25:08

On Fri, Jul 22, 2011 at 2:50 PM, Daniel Drake [off-list ref] wrote:
On 21 July 2011 03:34, Zhangfei Gao [off-list ref] wrote:
quoted
sdio client may be required power on/off dynamically.
With regulator vsdio, sdio client power on/off could be executed by mmc_power_up/down
I think you can/should do this with vmmc. When the device gets powered
down (e.g. in runtime suspend), the voltage should be cut, so it
should be possible to use the existing regulator.
Have considered re-use vmmc before,
Consider dynamically power control only required for sdio, so use
vsdio to exclude potential issue to sd/mmc.
Anyway, will try re-use vmmc.
I also looked at doing this before, when it looked like we would have
to manipulate a GPIO reset line for SD8686. I decided that the current
vmmc implementation in sdhci wasn't quite complete enough, but it
wouldn't be much effort to correct this.

Daniel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

[PATCH] mmc: sdio add regulator vsdio

From: Philip Rakity <hidden>
Date: 2011-07-22 16:05:56

Could we have an architecture discussion about how this is supposed to be done and a picture please !
(a pointer to good working code would be nice)

On brownstone the SDIO 8787 power is supplied by a ldo which is dedicated to the internal SDIO chip.  
The Power GPIO (PDn) is an on/off switch for the 8787.  It does not affect the power from the ldo.

What is the responsibility of the 8787 SDIO driver for power management ?  It is obviously called at
probe / init time.  Is it supposed to turn on power ?  I realize that it may not be aware of what device
to power on?  Does it register a call back ?  Is it responsible for turning itself on/off at suspend/resume
time?   Thought about open time but the firmware needs to be loaded before the device can respond.
Is firmware loading done at the right place ?  Should it be done at open and NOT at probe? That way
the driver could look present and open might handle firmware loading and power control.

What is the responsibilty of MMC layer.  Obviously it needs to supply power to the device on the bus.
Is there supposed to be a callback in the board file that handles these specifics ?  Would this call back
then call then set the ldo on and turn on the 8787 ?


regards,

Philip

 

On Jul 21, 2011, at 11:50 PM, Daniel Drake wrote:
On 21 July 2011 03:34, Zhangfei Gao [off-list ref] wrote:
quoted
sdio client may be required power on/off dynamically.
With regulator vsdio, sdio client power on/off could be executed by mmc_power_up/down
I think you can/should do this with vmmc. When the device gets powered
down (e.g. in runtime suspend), the voltage should be cut, so it
should be possible to use the existing regulator.

I also looked at doing this before, when it looked like we would have
to manipulate a GPIO reset line for SD8686. I decided that the current
vmmc implementation in sdhci wasn't quite complete enough, but it
wouldn't be much effort to correct this.

Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help