Skip to contentSkip to conversation

mmc: sdhci: fixes and enhancements

PATCH Superseded Kevin Liu 2 participants 11 messages Sep 19, 2012

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Kevin Liu

author
#0 lore raw

cover mmc: sdhci: fixes and enhancements

This patchset does as follows:
[PATCH 1/6] mmc: sdhci-pxav3: fix build error
[PATCH 2/6] mmc: sdhci: fix transfer mode setting bug for cmds w/o data transfer [PATCH 3/6] mmc: sdhci: set regulator min/max voltage according to spec [PATCH 4/6] mmc: sdhci: refine code for sd clock disable/enable in set ios [PATCH 5/6] mmc: sdhci: keep the saved clock var up to date
[PATCH 6/6] mmc: sdhci: fix null return check of regulator_get

Kevin Liu (6):
mmc: sdhci-pxav3: fix build error
mmc: sdhci: fix transfer mode setting bug for cmds w/o data transfer
mmc: sdhci: set regulator min/max voltage according to spec
mmc: sdhci: refine code for sd clock disable/enable in set ios
mmc: sdhci: keep the saved clock var up to date
mmc: sdhci: fix null return check of regulator_get

 drivers/mmc/host/sdhci-pxav3.c |    2 +
 drivers/mmc/host/sdhci.c       |   79 ++++++++++++++++++++--------------------
 2 files changed, 41 insertions(+), 40 deletions(-)
author
#1 lore raw

PATCH 1/6 mmc: sdhci-pxav3: fix build error

From: Kevin Liu <[email protected]>

Commit 18c75479 introduced build error with slot-gpio.h missing and pdata undeclared

---
 drivers/mmc/host/sdhci-pxav3.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci-pxav3.c +2 -0
index 223a5d4..f69d6c1 100644
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
 #include "sdhci-pltfm.h"
@@ -317,6 +318,7 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
 	struct sdhci_host *host = platform_get_drvdata(pdev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_pxa *pxa = pltfm_host->priv;
+	struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
 
 	sdhci_remove_host(host, 1);
 
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/6] mmc: sdhci-pxav3: fix build error

Hi,

Quoted 23 lines · Kevin Liu

From: Kevin Liu <[email protected]>

Commit 18c75479 introduced build error with slot-gpio.h missing and pdata undeclared

---
 drivers/mmc/host/sdhci-pxav3.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci-pxav3.c +1 -0
index 223a5d4..f69d6c1 100644
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
 #include "sdhci-pltfm.h"

drivers/mmc/host/sdhci-pxav3.c static int __devexit sdhci_pxav3_remove(struct platform_device *pdev) · line 323

Quoted 6 lines
drivers/mmc/host/sdhci-pxav3.c +1 -0
@@ -317,6 +318,7 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
 	struct sdhci_host *host = platform_get_drvdata(pdev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_pxa *pxa = pltfm_host->priv;
+	struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
 
 	sdhci_remove_host(host, 1);

Thanks very much for catching this, Kevin -- I'll fold this change into the original patch to avoid breaking bisection.

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child
author
#3 lore raw

PATCH 2/6 mmc: sdhci: fix transfer mode setting bug for cmds w/o data transfer

In reply to Kevin Liu

From: Kevin Liu <[email protected]>

Commands without data transfer like cmd5/cmd7 will use previous transfer mode setting, which may lead to error since some bits may have been set unexpectedly.
For example, cmd5 following cmd18/cmd25 will have timeout error since audo cmd23 has been enabled.

---
 drivers/mmc/host/sdhci.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +14 -8
index 0e15c79..2f844e5 100644
@@ -886,8 +886,21 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	u16 mode;
 	struct mmc_data *data = cmd->data;
 
-	if (data == NULL)
+	if (data == NULL) {
+		if (cmd->opcode == MMC_SEND_TUNING_BLOCK ||
+			cmd->opcode == MMC_SEND_TUNING_BLOCK_HS200)
+			/*
+			 * The tuning block is sent by the card to the host
+			 * controller. So we set the TRNS_READ bit in the
+			 * Transfer Mode register. This also takes care of
+			 * setting DMA Enable and Multi Block Select in the
+			 * same register to 0.
+			 */
+			sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE);
+		else
+			sdhci_writew(host, 0, SDHCI_TRANSFER_MODE);
 		return;
+	}
 
 	WARN_ON(!host->data);
 
@@ -1850,13 +1863,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 				     SDHCI_BLOCK_SIZE);
 		}
 
-		/*
-		 * The tuning block is sent by the card to the host controller.
-		 * So we set the TRNS_READ bit in the Transfer Mode register.
-		 * This also takes care of setting DMA Enable and Multi Block
-		 * Select in the same register to 0.
-		 */
-		sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE);
 
 		sdhci_send_command(host, &cmd);
 
Signature · 1 line
1.7.0.4
author
#4 lore raw

PATCH 3/6 mmc: sdhci: set regulator min/max voltage according to spec

In reply to Kevin Liu

From: Kevin Liu <[email protected]>

Use voltage range as below rather than a specific value 3.3v: (3.2v, 3.4v)
3.0v: (2.9v, 3.1v)
1.8v: (1.65v, 1.95v)

---
 drivers/mmc/host/sdhci.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
drivers/mmc/host/sdhci.c +9 -9
index 2f844e5..f50efa6 100644
@@ -1628,7 +1628,7 @@ static int sdhci_do_3_3v_signal_voltage_switch(struct sdhci_host *host,
 	sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
 
 	if (host->vqmmc) {
-		ret = regulator_set_voltage(host->vqmmc, 3300000, 3300000);
+		ret = regulator_set_voltage(host->vqmmc, 3200000, 3400000);
 		if (ret) {
 			pr_warning("%s: Switching to 3.3V signalling voltage "
 				   " failed\n", mmc_hostname(host->mmc));
@@ -1672,7 +1672,7 @@ static int sdhci_do_1_8v_signal_voltage_switch(struct sdhci_host *host,
 		 */
 		if (host->vqmmc)
 			ret = regulator_set_voltage(host->vqmmc,
-				1800000, 1800000);
+				1650000, 1950000);
 		else
 			ret = 0;
 
@@ -2856,7 +2856,7 @@ int sdhci_add_host(struct sdhci_host *host)
 		pr_info("%s: no vqmmc regulator found\n", mmc_hostname(mmc));
 		host->vqmmc = NULL;
 	}
-	else if (regulator_is_supported_voltage(host->vqmmc, 1800000, 1800000))
+	else if (regulator_is_supported_voltage(host->vqmmc, 1650000, 1950000))
 		regulator_enable(host->vqmmc);
 	else
 		caps[1] &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
@@ -2927,16 +2927,16 @@ int sdhci_add_host(struct sdhci_host *host)
 
 #ifdef CONFIG_REGULATOR
 	if (host->vmmc) {
-		ret = regulator_is_supported_voltage(host->vmmc, 3300000,
-			3300000);
+		ret = regulator_is_supported_voltage(host->vmmc, 3200000,
+			3400000);
 		if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330)))
 			caps[0] &= ~SDHCI_CAN_VDD_330;
-		ret = regulator_is_supported_voltage(host->vmmc, 3000000,
-			3000000);
+		ret = regulator_is_supported_voltage(host->vmmc, 2900000,
+			3100000);
 		if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300)))
 			caps[0] &= ~SDHCI_CAN_VDD_300;
-		ret = regulator_is_supported_voltage(host->vmmc, 1800000,
-			1800000);
+		ret = regulator_is_supported_voltage(host->vmmc, 1650000,
+			1950000);
 		if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180)))
 			caps[0] &= ~SDHCI_CAN_VDD_180;
 	}
Signature · 1 line
1.7.0.4
author
#5 lore raw

PATCH 4/6 mmc: sdhci: refine code for sd clock disable/enable in set ios

In reply to Kevin Liu

From: Kevin Liu <[email protected]>

With preset value enabled, there are two continuous times of sd clock disable/enable. They can be combined into one to save time and make code cleaner.

---
 drivers/mmc/host/sdhci.c |   29 +++++++++--------------------
 1 files changed, 9 insertions(+), 20 deletions(-)
drivers/mmc/host/sdhci.c +9 -20
index f50efa6..32dd505 100644
@@ -1449,33 +1449,22 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
 				ctrl_2 |= SDHCI_CTRL_DRV_TYPE_C;
 
 			sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
-		} else {
-			/*
-			 * According to SDHC Spec v3.00, if the Preset Value
-			 * Enable in the Host Control 2 register is set, we
-			 * need to reset SD Clock Enable before changing High
-			 * Speed Enable to avoid generating clock gliches.
-			 */
-
-			/* Reset SD Clock Enable */
-			clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
-			clk &= ~SDHCI_CLOCK_CARD_EN;
-			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
-
-			sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
-
-			/* Re-enable SD Clock */
-			clock = host->clock;
-			host->clock = 0;
-			sdhci_set_clock(host, clock);
 		}
 
-
 		/* Reset SD Clock Enable */
 		clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
 		clk &= ~SDHCI_CLOCK_CARD_EN;
 		sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
 
+		/*
+		 * According to SDHC Spec v3.00, if the Preset Value
+		 * Enable in the Host Control 2 register is set, we
+		 * need to reset SD Clock Enable before changing High
+		 * Speed Enable to avoid generating clock gliches.
+		 */
+		if (ctrl_2 & SDHCI_CTRL_PRESET_VAL_ENABLE)
+			sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+
 		if (host->ops->set_uhs_signaling)
 			host->ops->set_uhs_signaling(host, ios->timing);
 		else {
Signature · 1 line
1.7.0.4
author
#6 lore raw

PATCH 5/6 mmc: sdhci: keep the saved clock var up to date

In reply to Kevin Liu

From: Kevin Liu <[email protected]>

The clock rate set to the sdh controller may not exactly as requested by the mmc core, this patch make the clock rate saved in the mmc_ios and sdhci_host updated with the actual setting as in the controller. Thus "/sys/kernel/debug/mmcx/ios" and card detect prints can show the correct clock rate.

---
 drivers/mmc/host/sdhci.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/mmc/host/sdhci.c +5 -1
index 32dd505..4b5631e 100644
@@ -1199,7 +1199,10 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
 
 out:
-	host->clock = clock;
+	if (real_div)
+		host->clock = host->mmc->actual_clock;
+	else
+		host->clock = clock;
 }
 
 static int sdhci_set_power(struct sdhci_host *host, unsigned short power)
@@ -1375,6 +1378,7 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
 	}
 
 	sdhci_set_clock(host, ios->clock);
+	ios->clock = host->clock;
 
 	if (ios->power_mode == MMC_POWER_OFF)
 		vdd_bit = sdhci_set_power(host, -1);
Signature · 1 line
1.7.0.4
author
#7 lore raw

PATCH 6/6 mmc: sdhci: fix null return check of regulator_get

In reply to Kevin Liu

From: Kevin Liu <[email protected]>

regulator_get() returns NULL when CONFIG_REGULATOR not defined, which should be checked.

---
 drivers/mmc/host/sdhci.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
index 4b5631e..914147d 100644
@@ -2845,7 +2845,7 @@ int sdhci_add_host(struct sdhci_host *host)
 
 	/* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
 	host->vqmmc = regulator_get(mmc_dev(mmc), "vqmmc");
-	if (IS_ERR(host->vqmmc)) {
+	if (IS_ERR_OR_NULL(host->vqmmc)) {
 		pr_info("%s: no vqmmc regulator found\n", mmc_hostname(mmc));
 		host->vqmmc = NULL;
 	}
@@ -2912,7 +2912,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	ocr_avail = 0;
 
 	host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
-	if (IS_ERR(host->vmmc)) {
+	if (IS_ERR_OR_NULL(host->vmmc)) {
 		pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
 		host->vmmc = NULL;
 	} else
Signature · 1 line
1.7.0.4
#8 lore raw

Re: [PATCH 6/6] mmc: sdhci: fix null return check of regulator_get

Hi,

Quoted 25 lines · Kevin Liu

From: Kevin Liu <[email protected]>

regulator_get() returns NULL when CONFIG_REGULATOR not defined, which should be checked.

---
 drivers/mmc/host/sdhci.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +1 -1
index 4b5631e..914147d 100644
@@ -2845,7 +2845,7 @@ int sdhci_add_host(struct sdhci_host *host)
 
 	/* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
 	host->vqmmc = regulator_get(mmc_dev(mmc), "vqmmc");
-	if (IS_ERR(host->vqmmc)) {
+	if (IS_ERR_OR_NULL(host->vqmmc)) {
 		pr_info("%s: no vqmmc regulator found\n", mmc_hostname(mmc));
 		host->vqmmc = NULL;
 	}

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 2918

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -1
@@ -2912,7 +2912,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	ocr_avail = 0;
 
 	host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
-	if (IS_ERR(host->vmmc)) {
+	if (IS_ERR_OR_NULL(host->vmmc)) {
 		pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
 		host->vmmc = NULL;
 	} else

Why should it be checked? It looks like the only difference will be that everyone gets the printk, which isn't desirable -- x86 laptop users don't need to see a scary message about regulators.

Thanks,

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child
#9 lore raw
In reply to Kevin Liu

Hi,

Quoted 7 lines · Kevin Liu

This patchset does as follows:
[PATCH 1/6] mmc: sdhci-pxav3: fix build error
[PATCH 2/6] mmc: sdhci: fix transfer mode setting bug for cmds w/o data transfer [PATCH 3/6] mmc: sdhci: set regulator min/max voltage according to spec [PATCH 4/6] mmc: sdhci: refine code for sd clock disable/enable in set ios [PATCH 5/6] mmc: sdhci: keep the saved clock var up to date
[PATCH 6/6] mmc: sdhci: fix null return check of regulator_get

I'm worried that 2-5 might cause regressions for unexpected reasons, so I'll plan on merging these for 3.8 instead of 3.7 (assuming that no-one objects to them); hope that's okay.

Thanks,

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child
author
#10 lore raw

2012/9/19 Chris Ball <[email protected]>:

Quoted 11 lines

Hi,

Quoted 7 lines · Kevin Liu

This patchset does as follows:
[PATCH 1/6] mmc: sdhci-pxav3: fix build error
[PATCH 2/6] mmc: sdhci: fix transfer mode setting bug for cmds w/o data transfer [PATCH 3/6] mmc: sdhci: set regulator min/max voltage according to spec [PATCH 4/6] mmc: sdhci: refine code for sd clock disable/enable in set ios [PATCH 5/6] mmc: sdhci: keep the saved clock var up to date
[PATCH 6/6] mmc: sdhci: fix null return check of regulator_get

Quoted 4 lines

I'm worried that 2-5 might cause regressions for unexpected reasons, so I'll plan on merging these for 3.8 instead of 3.7 (assuming that no-one objects to them); hope that's okay.

Thanks
Kevin