Skip to contentSkip to conversation

Extend sdhci-esdhc-imx card_detect and write_protect support for mx5

PATCH Superseded Shawn Guo 6 participants 14 messages Jun 20, 2011 – Jun 21, 2011

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v3 cover Extend sdhci-esdhc-imx card_detect and write_protect support for mx5

The card-present polling for sdhci based driver is very expensive in terms of the impact to system performance. We observe a few system performance issues from Freescale and Linaro on mx5 platforms, which have been proved card polling related.

The patch set extends the current sdhci-esdhc-imx card_detect and write_protect support to cover mx5 platforms, and solves above performance issues.

Changes since v2:
* Fix the issue reported by Arnaud Patard:
http://article.gmane.org/gmane.linux.ports.arm.kernel/120790

Changes since v1:
* Rebase on today's linux-next
* Take the suggestion from Arnaud Patard to add default pdata in imx_add_sdhci_esdhc_imx(), to avoid touching every single board file for the platform_data changes
* Add comment for sdhci.c change
* Change ESDHC_CD(WP)_SIGNAL to ESDHC_CD(WP)_CONTROLLER for a more descriptive name
* Add missing NONE case handling in esdhc_pltfm_get_ro
* Improve a couple comment wording per suggestion from Wolfram Sang

Shawn Guo (4):
mmc: sdhci: fix interrupt storm from card detection
mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared
mmc: sdhci-esdhc-imx: remove "WP" from flag ESDHC_FLAG_GPIO_FOR_CD_WP
mmc: sdhci-esdhc-imx: extend card_detect and write_protect support for mx5

 arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c     |    3 +-
 arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c     |    3 +-
 arch/arm/mach-imx/mach-mx25_3ds.c                  |    2 +
 arch/arm/mach-imx/mach-pcm043.c                    |    2 +
 arch/arm/mach-mx5/board-mx51_babbage.c             |   14 +-
 arch/arm/mach-mx5/board-mx53_loco.c                |    4 +
 .../plat-mxc/devices/platform-sdhci-esdhc-imx.c    |   12 ++
 arch/arm/plat-mxc/include/mach/esdhc.h             |   25 +++-
 drivers/mmc/host/sdhci-esdhc-imx.c                 |  136 ++++++++++++--------
 drivers/mmc/host/sdhci.c                           |   27 ++++-
 10 files changed, 161 insertions(+), 67 deletions(-)
author
#1 lore raw

PATCH v3 1/4 mmc: sdhci: fix interrupt storm from card detection

The issue was initially found by Eric Benard as below.

http://permalink.gmane.org/gmane.linux.ports.arm.kernel/108031

Not sure about other SDHCI based controller, but on Freescale eSDHC, the SDHCI_INT_CARD_INSERT bits will be immediately set again when it gets cleared, if a card is inserted. The driver need to mask the irq to prevent interrupt storm which will freeze the system. And the SDHCI_INT_CARD_REMOVE gets the same situation.

The patch fixes the problem based on the initial idea from Eric Benard.

---
 drivers/mmc/host/sdhci.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +23 -4
index 91d9892..d94e2b4 100644
@@ -127,7 +127,9 @@ static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs)
 
 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
 {
-	u32 irqs = SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT;
+	u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
+		      SDHCI_CARD_PRESENT;
+	u32 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
 
 	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
 		return;
@@ -2154,13 +2156,30 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 		mmc_hostname(host->mmc), intmask);
 
 	if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
+		u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
+			      SDHCI_CARD_PRESENT;
+
+		/*
+		 * There is a observation on i.mx esdhc.  INSERT bit will be
+		 * immediately set again when it gets cleared, if a card is
+		 * inserted.  We have to mask the irq to prevent interrupt
+		 * storm which will freeze the system.  And the REMOVE gets
+		 * the same situation.
+		 *
+		 * More testing are needed here to ensure it works for other
+		 * platforms though.
+		 */
+		sdhci_mask_irqs(host, present ? SDHCI_INT_CARD_INSERT :
+						SDHCI_INT_CARD_REMOVE);
+		sdhci_unmask_irqs(host, present ? SDHCI_INT_CARD_REMOVE :
+						  SDHCI_INT_CARD_INSERT);
+
 		sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
-			SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
+			     SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
+		intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
 		tasklet_schedule(&host->card_tasklet);
 	}
 
-	intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
-
 	if (intmask & SDHCI_INT_CMD_MASK) {
 		sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
 			SDHCI_INT_STATUS);
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v3 1/4 mmc: sdhci: fix interrupt storm from card detection

Quoted 24 lines · Shawn Guo

The issue was initially found by Eric Benard as below.

http://permalink.gmane.org/gmane.linux.ports.arm.kernel/108031

Not sure about other SDHCI based controller, but on Freescale eSDHC, the SDHCI_INT_CARD_INSERT bits will be immediately set again when it gets cleared, if a card is inserted. The driver need to mask the irq to prevent interrupt storm which will freeze the system. And the SDHCI_INT_CARD_REMOVE gets the same situation.

The patch fixes the problem based on the initial idea from Eric Benard.

---
drivers/mmc/host/sdhci.c | 27 +++++++++++++++++++++++----

1 files changed, 23 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 91d9892..d94e2b4 100644

drivers/mmc/host/sdhci.c static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs) · line 135

Quoted 10 lines
drivers/mmc/host/sdhci.c +3 -1
@@ -127,7 +127,9 @@ static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs)
 
 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
 {
-	u32 irqs = SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT;
+	u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
+		      SDHCI_CARD_PRESENT;
+	u32 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
 
 	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
 		return;

Accessing off chip registers is slow. It would be better to check for the quirk first and then read the present state register.

eg

	u32 present;
	u32 irqs;	
Quoted 8 lines
	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
		return;

present = sdhci_readl(host, SDHCI_PRESENT_STATE) &

		      SDHCI_CARD_PRESENT;


	irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;

Philip

#3 lore raw

PATCH v3 1/4 mmc: sdhci: fix interrupt storm from card detection

Quoted 42 lines · Philip Rakity
Quoted 24 lines · Shawn Guo

The issue was initially found by Eric Benard as below.

http://permalink.gmane.org/gmane.linux.ports.arm.kernel/108031

Not sure about other SDHCI based controller, but on Freescale eSDHC, the SDHCI_INT_CARD_INSERT bits will be immediately set again when it gets cleared, if a card is inserted. The driver need to mask the irq to prevent interrupt storm which will freeze the system. And the SDHCI_INT_CARD_REMOVE gets the same situation.

The patch fixes the problem based on the initial idea from Eric Benard.

---
drivers/mmc/host/sdhci.c | 27 +++++++++++++++++++++++----

1 files changed, 23 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 91d9892..d94e2b4 100644

drivers/mmc/host/sdhci.c static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs) · line 135

Quoted 10 lines
drivers/mmc/host/sdhci.c +3 -1
@@ -127,7 +127,9 @@ static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs)
 
 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
 {
-	u32 irqs = SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT;
+	u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
+		      SDHCI_CARD_PRESENT;
+	u32 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
 
 	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
 		return;

Accessing off chip registers is slow. It would be better to check for the quirk first and then read the present state register.

Quoted 14 lines

eg

	u32 present;
	u32 irqs;	
Quoted 8 lines
	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
		return;

present = sdhci_readl(host, SDHCI_PRESENT_STATE) &

		      SDHCI_CARD_PRESENT;


	irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;

Makes sense. Will do.

Signature · 2 lines
Regards,
Shawn
author
#4 lore raw

PATCH v3 2/4 mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared

In reply to Shawn Guo

The function esdhc_readl_le intends to clear bit SDHCI_CARD_PRESENT, when the card detect gpio tells there is no card. But it does not clear the bit actually. The patch gives a fix on that.

---
 drivers/mmc/host/sdhci-esdhc-imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +1 -1
index 248b8e5..94097c0 100644
@@ -84,7 +84,7 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
 		if (boarddata && gpio_is_valid(boarddata->cd_gpio)
 				&& gpio_get_value(boarddata->cd_gpio))
 			/* no card, if a valid gpio says so... */
-			val &= SDHCI_CARD_PRESENT;
+			val &= ~SDHCI_CARD_PRESENT;
 		else
 			/* ... in all other cases assume card is present */
 			val |= SDHCI_CARD_PRESENT;
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH v3 2/4 mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared

Quoted 5 lines · Shawn Guo

The function esdhc_readl_le intends to clear bit SDHCI_CARD_PRESENT, when the card detect gpio tells there is no card. But it does not clear the bit actually. The patch gives a fix on that.

For the third time ;)

Should go to stable.

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110621/e2753a7f/attachment.sig>
#6 lore raw

PATCH v3 2/4 mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared

Quoted 11 lines · Wolfram Sang
Quoted 5 lines · Shawn Guo

The function esdhc_readl_le intends to clear bit SDHCI_CARD_PRESENT, when the card detect gpio tells there is no card. But it does not clear the bit actually. The patch gives a fix on that.

For the third time ;)

Sorry, my bad. Will add in v4.

Quoted 2 lines

Should go to stable.

I suppose that Chris will take care of it, otherwise please let me know what I should do. (I'm still new to the process)

Signature · 2 lines
Regards,
Shawn
#7 lore raw

PATCH v3 2/4 mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared

Hi Shawn,

Quoted 8 lines · Shawn Guo
Quoted 2 lines

Sorry, my bad. Will add in v4.

Quoted 2 lines

Should go to stable.

I suppose that Chris will take care of it, otherwise please let me know what I should do. (I'm still new to the process)

Just add:

to the commit message, please. (That's all that's necessary to get a patch seen by the stable@ maintainers.)

Thanks,

- Chris.

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

PATCH v3 2/4 mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared

In reply to Shawn Guo
Quoted 4 lines
Quoted 3 lines

Should go to stable.

I suppose that Chris will take care of it,

That's correct. You can add the cc as Chris suggested, so the maintainer knows that you think it should go to stable. The final decission is up to the maintainer, though.

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110621/158f175c/attachment.sig>
author
#9 lore raw

PATCH v3 3/4 mmc: sdhci-esdhc-imx: remove "WP" from flag ESDHC_FLAG_GPIO_FOR_CD_WP

In reply to Shawn Guo

The use of flag ESDHC_FLAG_GPIO_FOR_CD_WP is all CD related. It does not necessarily need to bother WP in the flag name.

---
 drivers/mmc/host/sdhci-esdhc-imx.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +4 -4
index 94097c0..79b7a9a 100644
@@ -29,7 +29,7 @@
 #define SDHCI_VENDOR_SPEC		0xC0
 #define  SDHCI_VENDOR_SPEC_SDIO_QUIRK	0x00000002
 
-#define ESDHC_FLAG_GPIO_FOR_CD_WP	(1 << 0)
+#define ESDHC_FLAG_GPIO_FOR_CD		(1 << 0)
 /*
  * The CMDTYPE of the CMD register (offset 0xE) should be set to
  * "11" when the STOP CMD12 is issued on imx53 to abort one
@@ -77,7 +77,7 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
 	u32 val = readl(host->ioaddr + reg);
 
 	if (unlikely((reg == SDHCI_PRESENT_STATE)
-			&& (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD_WP))) {
+			&& (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD))) {
 		struct esdhc_platform_data *boarddata =
 				host->mmc->parent->platform_data;
 
@@ -99,7 +99,7 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
 	struct pltfm_imx_data *imx_data = pltfm_host->priv;
 
 	if (unlikely((reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)
-			&& (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD_WP)))
+			&& (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD)))
 		/*
 		 * these interrupts won't work with a custom card_detect gpio
 		 * (only applied to mx25/35)
@@ -308,7 +308,7 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
 			goto no_card_detect_irq;
 		}
 
-		imx_data->flags |= ESDHC_FLAG_GPIO_FOR_CD_WP;
+		imx_data->flags |= ESDHC_FLAG_GPIO_FOR_CD;
 		/* Now we have a working card_detect again */
 		host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
 	}
Signature · 1 line
1.7.4.1
author
#10 lore raw

PATCH v3 4/4 mmc: sdhci-esdhc-imx: extend card_detect and write_protect support for mx5

In reply to Shawn Guo

The patch extends card_detect and write_protect support to get mx5 family and more scenarios supported. The changes include:

* Turn platform_data from optional to mandatory
* Add cd_types and wp_types into platform_data to cover more use cases
* Remove the use of flag ESDHC_FLAG_GPIO_FOR_CD
* Adjust some machine codes to adopt the platform_data changes
* Work around the issue that software reset will get card detection circuit stop working

With this patch, card_detect and write_protect gets supported on mx5 based platforms.

---
 arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c     |    3 +-
 arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c     |    3 +-
 arch/arm/mach-imx/mach-mx25_3ds.c                  |    2 +
 arch/arm/mach-imx/mach-pcm043.c                    |    2 +
 arch/arm/mach-mx5/board-mx51_babbage.c             |   14 ++-
 arch/arm/mach-mx5/board-mx53_loco.c                |    4 +
 .../plat-mxc/devices/platform-sdhci-esdhc-imx.c    |   12 ++
 arch/arm/plat-mxc/include/mach/esdhc.h             |   25 +++-
 drivers/mmc/host/sdhci-esdhc-imx.c                 |  134 ++++++++++++--------
 9 files changed, 137 insertions(+), 62 deletions(-)
arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c +2 -1
index 01ebcb3..66e8726 100644
@@ -225,7 +225,8 @@ struct imx_ssi_platform_data eukrea_mbimxsd_ssi_pdata __initconst = {
 
 static struct esdhc_platform_data sd1_pdata = {
 	.cd_gpio = GPIO_SD1CD,
-	.wp_gpio = -EINVAL,
+	.cd_type = ESDHC_CD_GPIO,
+	.wp_type = ESDHC_WP_NONE,
 };
 
 /*
arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c +2 -1
index 558eb52..0f0af02 100644
@@ -236,7 +236,8 @@ struct imx_ssi_platform_data eukrea_mbimxsd_ssi_pdata __initconst = {
 
 static struct esdhc_platform_data sd1_pdata = {
 	.cd_gpio = GPIO_SD1CD,
-	.wp_gpio = -EINVAL,
+	.cd_type = ESDHC_CD_GPIO,
+	.wp_type = ESDHC_WP_NONE,
 };
 
 /*
arch/arm/mach-imx/mach-mx25_3ds.c +2 -0
index 01534bb..7f66a91 100644
@@ -215,6 +215,8 @@ static const struct imxi2c_platform_data mx25_3ds_i2c0_data __initconst = {
 static const struct esdhc_platform_data mx25pdk_esdhc_pdata __initconst = {
 	.wp_gpio = SD1_GPIO_WP,
 	.cd_gpio = SD1_GPIO_CD,
+	.wp_type = ESDHC_WP_GPIO,
+	.cd_type = ESDHC_CD_GPIO,
 };
 
 static void __init mx25pdk_init(void)
arch/arm/mach-imx/mach-pcm043.c +2 -0
index 163cc31..660ec3e 100644
@@ -349,6 +349,8 @@ __setup("otg_mode=", pcm043_otg_mode);
 static struct esdhc_platform_data sd1_pdata = {
 	.wp_gpio = SD1_GPIO_WP,
 	.cd_gpio = SD1_GPIO_CD,
+	.wp_type = ESDHC_WP_GPIO,
+	.cd_type = ESDHC_CD_GPIO,
 };
 
 /*
arch/arm/mach-mx5/board-mx51_babbage.c +8 -6
index 15c6000..e400b09 100644
@@ -41,8 +41,6 @@
 #define BABBAGE_POWER_KEY	IMX_GPIO_NR(2, 21)
 #define BABBAGE_ECSPI1_CS0	IMX_GPIO_NR(4, 24)
 #define BABBAGE_ECSPI1_CS1	IMX_GPIO_NR(4, 25)
-#define BABBAGE_SD1_CD		IMX_GPIO_NR(1, 0)
-#define BABBAGE_SD1_WP		IMX_GPIO_NR(1, 1)
 #define BABBAGE_SD2_CD		IMX_GPIO_NR(1, 6)
 #define BABBAGE_SD2_WP		IMX_GPIO_NR(1, 5)
 
@@ -146,8 +144,9 @@ static iomux_v3_cfg_t mx51babbage_pads[] = {
 	MX51_PAD_SD1_DATA1__SD1_DATA1,
 	MX51_PAD_SD1_DATA2__SD1_DATA2,
 	MX51_PAD_SD1_DATA3__SD1_DATA3,
-	MX51_PAD_GPIO1_0__GPIO1_0,
-	MX51_PAD_GPIO1_1__GPIO1_1,
+	/* CD/WP from controller */
+	MX51_PAD_GPIO1_0__SD1_CD,
+	MX51_PAD_GPIO1_1__SD1_WP,
 
 	/* SD 2 */
 	MX51_PAD_SD2_CMD__SD2_CMD,
@@ -156,6 +155,7 @@ static iomux_v3_cfg_t mx51babbage_pads[] = {
 	MX51_PAD_SD2_DATA1__SD2_DATA1,
 	MX51_PAD_SD2_DATA2__SD2_DATA2,
 	MX51_PAD_SD2_DATA3__SD2_DATA3,
+	/* CD/WP gpio */
 	MX51_PAD_GPIO1_6__GPIO1_6,
 	MX51_PAD_GPIO1_5__GPIO1_5,
 
@@ -340,13 +340,15 @@ static const struct spi_imx_master mx51_babbage_spi_pdata __initconst = {
 };
 
 static const struct esdhc_platform_data mx51_babbage_sd1_data __initconst = {
-	.cd_gpio = BABBAGE_SD1_CD,
-	.wp_gpio = BABBAGE_SD1_WP,
+	.cd_type = ESDHC_CD_CONTROLLER,
+	.wp_type = ESDHC_WP_CONTROLLER,
 };
 
 static const struct esdhc_platform_data mx51_babbage_sd2_data __initconst = {
 	.cd_gpio = BABBAGE_SD2_CD,
 	.wp_gpio = BABBAGE_SD2_WP,
+	.cd_type = ESDHC_CD_GPIO,
+	.wp_type = ESDHC_WP_GPIO,
 };
 
 /*
arch/arm/mach-mx5/board-mx53_loco.c +4 -0
index 54be525..4e1d51d 100644
@@ -210,11 +210,15 @@ static const struct gpio_keys_platform_data loco_button_data __initconst = {
 
 static const struct esdhc_platform_data mx53_loco_sd1_data __initconst = {
 	.cd_gpio = LOCO_SD1_CD,
+	.cd_type = ESDHC_CD_GPIO,
+	.wp_type = ESDHC_WP_NONE,
 };
 
 static const struct esdhc_platform_data mx53_loco_sd3_data __initconst = {
 	.cd_gpio = LOCO_SD3_CD,
 	.wp_gpio = LOCO_SD3_WP,
+	.cd_type = ESDHC_CD_GPIO,
+	.wp_type = ESDHC_WP_GPIO,
 };
 
 static inline void mx53_loco_fec_reset(void)
arch/arm/plat-mxc/devices/platform-sdhci-esdhc-imx.c +12 -0
index 6b2940b..79d6d71 100644
@@ -65,6 +65,11 @@ imx53_sdhci_esdhc_imx_data[] __initconst = {
 };
 #endif /* ifdef CONFIG_SOC_IMX53 */
 
+static const struct esdhc_platform_data default_esdhc_pdata __initconst = {
+	.wp_type = ESDHC_WP_NONE,
+	.cd_type = ESDHC_CD_NONE,
+};
+
 struct platform_device *__init imx_add_sdhci_esdhc_imx(
 		const struct imx_sdhci_esdhc_imx_data *data,
 		const struct esdhc_platform_data *pdata)
@@ -81,6 +86,13 @@ struct platform_device *__init imx_add_sdhci_esdhc_imx(
 		},
 	};
 
+	/*
+	 * If machine does not provide pdata, use the default one
+	 * which means no WP/CD support
+	 */
+	if (!pdata)
+		pdata = &default_esdhc_pdata;
+
 	return imx_add_platform_device("sdhci-esdhc-imx", data->id, res,
 			ARRAY_SIZE(res), pdata, sizeof(*pdata));
 }
arch/arm/plat-mxc/include/mach/esdhc.h +21 -4
index 86003f4..aaf9748 100644
@@ -10,17 +10,34 @@
 #ifndef __ASM_ARCH_IMX_ESDHC_H
 #define __ASM_ARCH_IMX_ESDHC_H
 
+enum wp_types {
+	ESDHC_WP_NONE,		/* no WP, neither controller nor gpio */
+	ESDHC_WP_CONTROLLER,	/* mmc controller internal WP */
+	ESDHC_WP_GPIO,		/* external gpio pin for WP */
+};
+
+enum cd_types {
+	ESDHC_CD_NONE,		/* no CD, neither controller nor gpio */
+	ESDHC_CD_CONTROLLER,	/* mmc controller internal CD */
+	ESDHC_CD_GPIO,		/* external gpio pin for CD */
+	ESDHC_CD_PERMANENT,	/* no CD, card permanently wired to host */
+};
+
 /**
- * struct esdhc_platform_data - optional platform data for esdhc on i.MX
+ * struct esdhc_platform_data - platform data for esdhc on i.MX
  *
- * strongly recommended for i.MX25/35, not needed for other variants
+ * ESDHC_WP(CD)_CONTROLLER type is not available on i.MX25/35.
  *
- * @wp_gpio:	gpio for write_protect (-EINVAL if unused)
- * @cd_gpio:	gpio for card_detect interrupt (-EINVAL if unused)
+ * @wp_gpio:	gpio for write_protect
+ * @cd_gpio:	gpio for card_detect interrupt
+ * @wp_type:	type of write_protect method (see wp_types enum above)
+ * @cd_type:	type of card_detect method (see cd_types enum above)
  */
 
 struct esdhc_platform_data {
 	unsigned int wp_gpio;
 	unsigned int cd_gpio;
+	enum wp_types wp_type;
+	enum cd_types cd_type;
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
drivers/mmc/host/sdhci-esdhc-imx.c +84 -50

230 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#11 lore raw

v3 cover Extend sdhci-esdhc-imx card_detect and write_protect support for mx5

In reply to Shawn Guo

Hi Arnaud,

Would you please give a test on the series, as it fixed the issue you reported? TIA.

Signature · 2 lines
Regards,
Shawn
Quoted 46 lines · Shawn Guo

The card-present polling for sdhci based driver is very expensive in terms of the impact to system performance. We observe a few system performance issues from Freescale and Linaro on mx5 platforms, which have been proved card polling related.

The patch set extends the current sdhci-esdhc-imx card_detect and write_protect support to cover mx5 platforms, and solves above performance issues.

Changes since v2:
* Fix the issue reported by Arnaud Patard:

   http://article.gmane.org/gmane.linux.ports.arm.kernel/120790

Changes since v1:
* Rebase on today's linux-next
* Take the suggestion from Arnaud Patard to add default pdata in imx_add_sdhci_esdhc_imx(), to avoid touching every single board file for the platform_data changes
* Add comment for sdhci.c change
* Change ESDHC_CD(WP)_SIGNAL to ESDHC_CD(WP)_CONTROLLER for a more descriptive name
* Add missing NONE case handling in esdhc_pltfm_get_ro
* Improve a couple comment wording per suggestion from Wolfram Sang

Shawn Guo (4):
mmc: sdhci: fix interrupt storm from card detection
mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get cleared
mmc: sdhci-esdhc-imx: remove "WP" from flag ESDHC_FLAG_GPIO_FOR_CD_WP
mmc: sdhci-esdhc-imx: extend card_detect and write_protect support for mx5

 arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c     |    3 +-
 arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c     |    3 +-
 arch/arm/mach-imx/mach-mx25_3ds.c                  |    2 +
 arch/arm/mach-imx/mach-pcm043.c                    |    2 +
 arch/arm/mach-mx5/board-mx51_babbage.c             |   14 +-
 arch/arm/mach-mx5/board-mx53_loco.c                |    4 +
 .../plat-mxc/devices/platform-sdhci-esdhc-imx.c    |   12 ++
 arch/arm/plat-mxc/include/mach/esdhc.h             |   25 +++-
 drivers/mmc/host/sdhci-esdhc-imx.c                 |  136 ++++++++++++--------
 drivers/mmc/host/sdhci.c                           |   27 ++++-
 10 files changed, 161 insertions(+), 67 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

v3 cover Extend sdhci-esdhc-imx card_detect and write_protect support for mx5

Quoted 1 line · Shawn Guo

Hi Arnaud,

Hi,

Quoted 3 lines

Would you please give a test on the series, as it fixed the issue you reported? TIA.

I've tested it yesterday on my efika platforms and the issue is gone. Moreover, the differents card slot on theses platforms are using each card detect type (internally connected, gpio, no card detect) and they are all working as expected. I'm a little bit annoyed by the polling on the slot without card detect but this has nothing to do with this patchset.

Side note: turns out that the driver is using dev_warn when failing to get cd gpio/irq. Given that in theses cases, it jumps to no_card_detect_pin and makes the probe fail, maybe a dev_err would be better ?

Thanks,
Arnaud

#13 lore raw

v3 cover Extend sdhci-esdhc-imx card_detect and write_protect support for mx5

Quoted 10 lines · Arnaud Patard
Quoted 1 line · Shawn Guo

Hi Arnaud,

Hi,

Quoted 3 lines

Would you please give a test on the series, as it fixed the issue you reported? TIA.

Quoted 7 lines

I've tested it yesterday on my efika platforms and the issue is gone. Moreover, the differents card slot on theses platforms are using each card detect type (internally connected, gpio, no card detect) and they are all working as expected. I'm a little bit annoyed by the polling on the slot without card detect but this has nothing to do with this patchset.

That's great.

Quoted 5 lines

Side note: turns out that the driver is using dev_warn when failing to get cd gpio/irq. Given that in theses cases, it jumps to no_card_detect_pin and makes the probe fail, maybe a dev_err would be better ?

Though it's the existing code, I respect the comment and will make the change in the v4.

Quoted 2 lines

Thanks for testing.

Signature · 2 lines
Regards,
Shawn