mmc: Add support for JMicron 388 SD/MMC controller
PATCH 2/2 mmc: Test bus-width for old MMC devices
In reply to Takashi IwaiFrom: Aries Lee <[email protected]>
Some old MMC devices fail with the 4/8 bits the driver tries to use exclusively. This patch adds a test for the given bus setup and falls back to the lower bit mode (until 1-bit mode) when the test fails.
[Major rework and refactoring by tiwai]
--- drivers/mmc/core/mmc.c | 49 ++++++++++++--------- drivers/mmc/core/mmc_ops.c | 102 ++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/core/mmc_ops.h | 1 + 3 files changed, 131 insertions(+), 21 deletions(-)
drivers/mmc/core/mmc.c +28 -21
@@ -507,29 +507,36 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,*/ if ((card->csd.mmca_vsn >=CSD_SPEC_VER_4 ) && (host->caps & (MMC_CAP_4_BIT_DATA |MMC_CAP_8_BIT_DATA ))) { -unsigned ext_csd_bit, bus_width; - -if (host->caps &MMC_CAP_8_BIT_DATA ) { - ext_csd_bit =EXT_CSD_BUS_WIDTH_8 ; - bus_width =MMC_BUS_WIDTH_8 ; - }else { - ext_csd_bit =EXT_CSD_BUS_WIDTH_4 ; - bus_width =MMC_BUS_WIDTH_4 ; +static unsigned ext_csd_bits[] = { +EXT_CSD_BUS_WIDTH_8 , +EXT_CSD_BUS_WIDTH_4 , +EXT_CSD_BUS_WIDTH_1 + }; +static unsigned bus_widths[] = { +MMC_BUS_WIDTH_8 , +MMC_BUS_WIDTH_4 , +MMC_BUS_WIDTH_1 + }; +unsigned idx; + +if (host->caps &MMC_CAP_8_BIT_DATA ) + idx =0 ; +else + idx =1 ; +for (; idx <ARRAY_SIZE (bus_widths); idx++) { + err =mmc_switch (card,EXT_CSD_CMD_SET_NORMAL , +EXT_CSD_BUS_WIDTH , ext_csd_bits[idx]); +if (!err) { +mmc_set_bus_width (card->host, bus_widths[idx]); + err =mmc_bus_test (card, bus_widths[idx]); +if (!err) +break ; + } } - - err =mmc_switch (card,EXT_CSD_CMD_SET_NORMAL , -EXT_CSD_BUS_WIDTH , ext_csd_bit); - -if (err && err != -EBADMSG ) - goto free_card; -if (err) { -printk (KERN_WARNING "%s: switch to bus width %d " -"failed\n" ,mmc_hostname (card->host), -1 << bus_width); - err =0 ; - }else { -mmc_set_bus_width (card->host, bus_width); +printk (KERN_WARNING "%s: switch to bus width failed\n" , +mmc_hostname (card->host)); + goto free_card; } }
drivers/mmc/core/mmc_ops.c +102 -0
105 lines not on this page · raw message
drivers/mmc/core/mmc_ops.h +1 -0
@@ -26,6 +26,7 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid);int mmc_spi_read_ocr (struct mmc_host *host,int highcap,u32 *ocrp);int mmc_spi_set_crc (struct mmc_host *host,int use_crc);int mmc_card_sleepawake (struct mmc_host *host,int sleep); +int mmc_bus_test (struct mmc_card *card,u8 bus_width);#endif
Signature · 1 line
1.7.3.1
cover mmc: Add support for JMicron 388 SD/MMC controller
Hi,
this is a patch series to add the support for the new JMicron 388 SD/MMC controller. The first patch is to add the support for the new PCI device, including the quirks to handle different voltages per medium.
The second patch is for improving the handling of different bus- widths dynamically.
thanks,
Takashi
PATCH 1/2 mmc: Add support for JMicron 388 SD/MMC controller
JMicron 388 SD/MMC combo controller supports the 1.8V low-voltage for SD, but MMC doesn't work with the low-voltage, resulting in an error at probing.
This patch adds the support for multiple voltage mask per device type, so that SD works with 1.8V while MMC forces 3.3V. Here new ocr_avail_* fields for each device are introduced, so that the actual OCR mask is switched dynamically.
Also, the restriction of low-voltage in core/sd.c is removed when the bit is allowed explicitly via ocr_avail_sd mask.
This patch was rewritten from scratch based on Aries' original code.
--- drivers/mmc/core/mmc.c | 2 ++ drivers/mmc/core/sd.c | 5 ++++- drivers/mmc/core/sdio.c | 2 ++ drivers/mmc/host/sdhci-pci.c | 42 ++++++++++++++++++++++++++++++++++++------ drivers/mmc/host/sdhci.c | 11 +++++++++++ drivers/mmc/host/sdhci.h | 2 ++ include/linux/mmc/host.h | 3 +++ include/linux/pci_ids.h | 2 ++ 8 files changed, 62 insertions(+), 7 deletions(-)
drivers/mmc/core/mmc.c +2 -0
@@ -703,6 +703,8 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_attach_bus_ops (host); +if (host->ocr_avail_mmc) + host->ocr_avail = host->ocr_avail_mmc;/* * We need to get OCR a different way for SPI.
drivers/mmc/core/sd.c +4 -1
@@ -768,6 +768,8 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_sd_attach_bus_ops (host); +if (host->ocr_avail_sd) + host->ocr_avail = host->ocr_avail_sd;/* * We need to get OCR a different way for SPI.
@@ -791,7 +793,8 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr) ocr &= ~0x7F ; } -if (ocr &MMC_VDD_165_195 ) { +if ((ocr &MMC_VDD_165_195 ) && + !(host->ocr_avail_sd &MMC_VDD_165_195 )) {printk (KERN_WARNING "%s: SD card claims to support the " "incompletely defined 'low voltage range'. This " "will be ignored.\n" ,mmc_hostname (host));
drivers/mmc/core/sdio.c +2 -0
@@ -668,6 +668,8 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_attach_bus (host, &mmc_sdio_ops); +if (host->ocr_avail_sdio) + host->ocr_avail = host->ocr_avail_sdio;/* * Sanity check the voltages that the card claims to
drivers/mmc/host/sdhci-pci.c +36 -6
94 lines not on this page · raw message
drivers/mmc/host/sdhci.c +11 -0
@@ -1829,6 +1829,10 @@ int sdhci_add_host(struct sdhci_host *host)if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) mmc->caps |=MMC_CAP_NEEDS_POLL ; +/* normal SD controllers don't support 1.8V; exlcude here */ +if (!(host->quirks &SDHCI_QUIRK_MMC_VDD_180 )) + caps &= ~SDHCI_CAN_VDD_180 ; + mmc->ocr_avail =0 ;if (caps &SDHCI_CAN_VDD_330 ) mmc->ocr_avail |=MMC_VDD_32_33 |MMC_VDD_33_34 ;
@@ -1837,6 +1841,13 @@ int sdhci_add_host(struct sdhci_host *host)if (caps &SDHCI_CAN_VDD_180 ) mmc->ocr_avail |=MMC_VDD_165_195 ; + mmc->ocr_avail_sdio = mmc->ocr_avail; + mmc->ocr_avail_sd = mmc->ocr_avail; + mmc->ocr_avail_mmc = mmc->ocr_avail; +/* JMicron 388 combo supports 1.8V for SD but not for MMC */ +if (host->quirks &SDHCI_QUIRK_MMC_VDD_180 ) + mmc->ocr_avail_mmc &= ~MMC_VDD_165_195 ; +if (mmc->ocr_avail ==0 ) {printk (KERN_ERR "%s: Hardware doesn't report any " "support voltages.\n" ,mmc_hostname (mmc));
drivers/mmc/host/sdhci.h +2 -0
@@ -247,6 +247,8 @@ struct sdhci_host {#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)/* Controller doesn't have HISPD bit field in HI-SPEED SD card */ #define SDHCI_QUIRK_NO_HISPD_BIT (1<<29) +/* Controller doesn't support VDD 180 for MMC (for SD/MMC combo chips) */ +#define SDHCI_QUIRK_MMC_VDD_180 (1<<30)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
include/linux/mmc/host.h +3 -0
@@ -124,6 +124,9 @@ struct mmc_host {unsigned int f_min;unsigned int f_max;u32 ocr_avail; +u32 ocr_avail_sdio;/* SDIO-specific OCR */ +u32 ocr_avail_sd;/* SD-specific OCR */ +u32 ocr_avail_mmc;/* MMC-specific OCR */ struct notifier_block pm_notify;#define MMC_VDD_165_195 0x00000080/* VDD voltage 1.65 - 1.95 */
include/linux/pci_ids.h +2 -0
@@ -2358,6 +2358,8 @@#define PCI_DEVICE_ID_JMICRON_JMB38X_SD 0x2381#define PCI_DEVICE_ID_JMICRON_JMB38X_MMC 0x2382#define PCI_DEVICE_ID_JMICRON_JMB38X_MS 0x2383 +#define PCI_DEVICE_ID_JMICRON_JMB388_SD 0x2391 +#define PCI_DEVICE_ID_JMICRON_JMB388_ESD 0x2392#define PCI_VENDOR_ID_KORENIX 0x1982#define PCI_DEVICE_ID_KORENIX_JETCARDF0 0x1600
Signature · 1 line
1.7.3.1
drivers/mmc/host/sdhci.h struct sdhci_host { · line 251
Quoted 2 lines · Takashi Iwai
drivers/mmc/host/sdhci.h +2
-0+/* Controller doesn't support VDD 180 for MMC (for SD/MMC combo chips) */ +#define SDHCI_QUIRK_MMC_VDD_180 (1<<30)
Can't we handle this more generic? Like setting ocr_avail_* from sdhci-pci.c somehow (just brainstorming, didn't have a deeper look)? I'd like to avoid new quirks as much as possible.
Regards,
Wolfram
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
At Wed, 24 Nov 2010 10:59:35 +0100,
Quoted 9 lines · Wolfram Sang
Review
Quoted 2 lines · Takashi Iwai
(quoted diff) +2
-0+/* Controller doesn't support VDD 180 for MMC (for SD/MMC combo chips) */ +#define SDHCI_QUIRK_MMC_VDD_180 (1<<30)Can't we handle this more generic? Like setting ocr_avail_* from
sdhci-pci.csomehow (just brainstorming, didn't have a deeper look)? I'd like to avoid new quirks as much as possible.
OK, what about the one below?
thanks,
Takashi
===
Quoted 1 line
From
7521d3ccdd3373598b91125c049e3f0dfdeb2598Mon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Tue, 2 Nov 2010 09:10:20 +0100
Subject: [PATCH 1/2] mmc: Add support for JMicron 388 SD/MMC controller (v2)
JMicron 388 SD/MMC combo controller supports the 1.8V low-voltage for SD, but MMC doesn't work with the low-voltage, resulting in an error at probing.
This patch adds the support for multiple voltage mask per device type, so that SD works with 1.8V while MMC forces 3.3V. Here new ocr_avail_* fields for each device are introduced, so that the actual OCR mask is switched dynamically.
Also, the restriction of low-voltage in core/sd.c is removed when the bit is allowed explicitly via ocr_avail_sd mask.
This patch was rewritten from scratch based on Aries' original code.
---
v2: Keep ocr_avail_* in sdhci_host to avoid yet another quirk bit
drivers/mmc/core/mmc.c | 2 + drivers/mmc/core/sd.c | 5 +++- drivers/mmc/core/sdio.c | 2 + drivers/mmc/host/sdhci-pci.c | 47 ++++++++++++++++++++++++++++++++++++----- drivers/mmc/host/sdhci.c | 23 ++++++++++++++++---- drivers/mmc/host/sdhci.h | 4 +++ include/linux/mmc/host.h | 3 ++ include/linux/pci_ids.h | 2 + 8 files changed, 76 insertions(+), 12 deletions(-)
drivers/mmc/core/mmc.c +2 -0
@@ -703,6 +703,8 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_attach_bus_ops (host); +if (host->ocr_avail_mmc) + host->ocr_avail = host->ocr_avail_mmc;/* * We need to get OCR a different way for SPI.
drivers/mmc/core/sd.c +4 -1
@@ -768,6 +768,8 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_sd_attach_bus_ops (host); +if (host->ocr_avail_sd) + host->ocr_avail = host->ocr_avail_sd;/* * We need to get OCR a different way for SPI.
@@ -791,7 +793,8 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr) ocr &= ~0x7F ; } -if (ocr &MMC_VDD_165_195 ) { +if ((ocr &MMC_VDD_165_195 ) && + !(host->ocr_avail_sd &MMC_VDD_165_195 )) {printk (KERN_WARNING "%s: SD card claims to support the " "incompletely defined 'low voltage range'. This " "will be ignored.\n" ,mmc_hostname (host));
drivers/mmc/core/sdio.c +2 -0
@@ -668,6 +668,8 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)WARN_ON (!host->claimed);mmc_attach_bus (host, &mmc_sdio_ops); +if (host->ocr_avail_sdio) + host->ocr_avail = host->ocr_avail_sdio;/* * Sanity check the voltages that the card claims to
drivers/mmc/host/sdhci-pci.c +41 -6
97 lines not on this page · raw message
drivers/mmc/host/sdhci.c +18 -5
@@ -1691,7 +1691,7 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);int sdhci_add_host (struct sdhci_host *host) {struct mmc_host *mmc; -unsigned int caps; +unsigned int caps, ocr_avail;int ret;WARN_ON (host ==NULL );
@@ -1829,13 +1829,26 @@ int sdhci_add_host(struct sdhci_host *host)if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) mmc->caps |=MMC_CAP_NEEDS_POLL ; - mmc->ocr_avail =0 ; + ocr_avail =0 ;if (caps &SDHCI_CAN_VDD_330 ) - mmc->ocr_avail |=MMC_VDD_32_33 |MMC_VDD_33_34 ; + ocr_avail |=MMC_VDD_32_33 |MMC_VDD_33_34 ;if (caps &SDHCI_CAN_VDD_300 ) - mmc->ocr_avail |=MMC_VDD_29_30 |MMC_VDD_30_31 ; + ocr_avail |=MMC_VDD_29_30 |MMC_VDD_30_31 ;if (caps &SDHCI_CAN_VDD_180 ) - mmc->ocr_avail |=MMC_VDD_165_195 ; + ocr_avail |=MMC_VDD_165_195 ; + + mmc->ocr_avail = ocr_avail; + mmc->ocr_avail_sdio = ocr_avail; +if (host->ocr_avail_sdio) + mmc->ocr_avail_sdio &= host->ocr_avail_sdio; + mmc->ocr_avail_sd = ocr_avail; +if (host->ocr_avail_sd) + mmc->ocr_avail_sd &= host->ocr_avail_sd; +else /* normal SD controllers don't support 1.8V */ + mmc->ocr_avail_sd &= ~MMC_VDD_165_195 ; + mmc->ocr_avail_mmc = ocr_avail; +if (host->ocr_avail_mmc) + mmc->ocr_avail_sd &= host->ocr_avail_mmc;if (mmc->ocr_avail ==0 ) { printk(KERN_ERR "%s: Hardware doesn't report any "
drivers/mmc/host/sdhci.h +4 -0
@@ -303,6 +303,10 @@ struct sdhci_host {unsigned int caps;/* Alternative capabilities */ +unsigned int ocr_avail_sdio;/* OCR bit masks */ +unsigned int ocr_avail_sd; +unsigned int ocr_avail_mmc; +unsigned long private[0 ]____cacheline_aligned ; };
include/linux/mmc/host.h +3 -0
@@ -124,6 +124,9 @@ struct mmc_host {unsigned int f_min;unsigned int f_max;u32 ocr_avail; +u32 ocr_avail_sdio;/* SDIO-specific OCR */ +u32 ocr_avail_sd;/* SD-specific OCR */ +u32 ocr_avail_mmc;/* MMC-specific OCR */ struct notifier_block pm_notify;#define MMC_VDD_165_195 0x00000080/* VDD voltage 1.65 - 1.95 */
include/linux/pci_ids.h +2 -0
@@ -2358,6 +2358,8 @@#define PCI_DEVICE_ID_JMICRON_JMB38X_SD 0x2381#define PCI_DEVICE_ID_JMICRON_JMB38X_MMC 0x2382#define PCI_DEVICE_ID_JMICRON_JMB38X_MS 0x2383 +#define PCI_DEVICE_ID_JMICRON_JMB388_SD 0x2391 +#define PCI_DEVICE_ID_JMICRON_JMB388_ESD 0x2392#define PCI_VENDOR_ID_KORENIX 0x1982#define PCI_DEVICE_ID_KORENIX_JETCARDF0 0x1600
Signature · 1 line
1.7.3.1
Quoted 5 lines · Takashi Iwai
At Wed, 24 Nov 2010 10:59:35 +0100,
Quoted 3 lines · Wolfram Sang
On Wed, Nov 24, 2010 at 07:21:13AM +0100, Takashi Iwai wrote:
Quoted 8 lines
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* Controller doesn't support VDD 180 for MMC (for SD/MMC combo chips) */ +#define SDHCI_QUIRK_MMC_VDD_180 (1<<30)Can't we handle this more generic? Like setting ocr_avail_* from
sdhci-pci.csomehow (just brainstorming, didn't have a deeper look)? I'd like to avoid new quirks as much as possible.OK, what about the one below?
Looks better to me. (sadly, still from a glimpse, no thorough review)
Thanks!
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
In reply to Takashi IwaiHi Takashi, Philip,
Quoted 10 lines · Takashi Iwai
From: Aries Lee <[email protected]>
Some old MMC devices fail with the 4/8 bits the driver tries to use exclusively. This patch adds a test for the given bus setup and falls back to the lower bit mode (until 1-bit mode) when the test fails.
[Major rework and refactoring by tiwai]
Signed-off-by Aries Lee <[email protected]>Signed-off-by Takashi Iwai <[email protected]>
We have two independent patches for performing MMC bus-width testing now:
https://patchwork.kernel.org/patch/351781/
https://patchwork.kernel.org/patch/361702/
I'm planning on taking Takashi's since it looks a little cleaner; Philip, please could you take a look at Takashi's patch and add anything you think should be present from your own patch as a new incremental patch?
Thanks very much,
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
Hi Chris,
At Sun, 5 Dec 2010 04:02:24 +0000,
Quoted 12 lines · Chris Ball
Hi Takashi, Philip,
Quoted 8 lines · Takashi Iwai
From: Aries Lee <[email protected]>
Some old MMC devices fail with the 4/8 bits the driver tries to use exclusively. This patch adds a test for the given bus setup and falls back to the lower bit mode (until 1-bit mode) when the test fails.
[Major rework and refactoring by tiwai]
Quoted 7 lines
Quoted 2 lines
Signed-off-by Aries Lee <[email protected]>Signed-off-by Takashi Iwai <[email protected]>We have two independent patches for performing MMC bus-width testing now:
https://patchwork.kernel.org/patch/351781/
https://patchwork.kernel.org/patch/361702/
Yeah, Philip and I discussed shortly in a mail thread after that.
Quoted 3 lines
I'm planning on taking Takashi's since it looks a little cleaner; Philip, please could you take a look at Takashi's patch and add anything you think should be present from your own patch as a new incremental patch?
One missing thing in my (originally Aries') patch is the quirk bit to enable/disable the bus-width test. In Philip's latest patch, the default is off.
I'm also not sure whether this bus-width test should be enabled as default. I guess it's better for performance, so I'd vote for turning on as default. But, having a quirk for turning off would be safer for working around old hardware problems, of course.
thanks,
Takashi
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
Hi Takashi, Philip,
Quoted 4 lines · Takashi Iwai
Quoted 3 lines
I'm planning on taking Takashi's since it looks a little cleaner; Philip, please could you take a look at Takashi's patch and add anything you think should be present from your own patch as a new incremental patch?
Quoted 8 lines
One missing thing in my (originally Aries') patch is the quirk bit to enable/disable the bus-width test. In Philip's latest patch, the default is off.
I'm also not sure whether this bus-width test should be enabled as default. I guess it's better for performance, so I'd vote for turning on as default. But, having a quirk for turning off would be safer for working around old hardware problems, of course.
Sounds good, although we're trying hard not to add new quirk bits. I don't see a way around doing that here, though.
We've got plenty of time until the .38 release -- let's turn it on by default and test during .38-rc, and we can revisit whether to leave it on closer to the release. It's not as simple as "turning it on could cause problems so let's not do that", because we're *already* seeing problems from things like enabling 8-bit width on setups that don't support it.
Thanks!
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
Chris,
One other difference I have been told between the patches but NOT verified is
a) Takasi code was not tested with Dual Data Rate
b) Performance is not an issue since we are dealing with uSeconds and the code is called once when mmc is detected.
c) I will adapt my code to what Takahi did over the next few days and post changes to the CAP
d) The work was independent and done at the same time !! (amazing)
Quoted 31 lines · Chris Ball
Hi Takashi, Philip,
Quoted 4 lines · Takashi Iwai
Quoted 3 lines
I'm planning on taking Takashi's since it looks a little cleaner; Philip, please could you take a look at Takashi's patch and add anything you think should be present from your own patch as a new incremental patch?
Quoted 8 lines
One missing thing in my (originally Aries') patch is the quirk bit to enable/disable the bus-width test. In Philip's latest patch, the default is off.
I'm also not sure whether this bus-width test should be enabled as default. I guess it's better for performance, so I'd vote for turning on as default. But, having a quirk for turning off would be safer for working around old hardware problems, of course.
Sounds good, although we're trying hard not to add new quirk bits. I don't see a way around doing that here, though.
We've got plenty of time until the .38 release -- let's turn it on by default and test during .38-rc, and we can revisit whether to leave it on closer to the release. It's not as simple as "turning it on could cause problems so let's not do that", because we're *already* seeing problems from things like enabling 8-bit width on setups that don't support it.
Thanks!
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
At Wed, 24 Nov 2010 23:04:25 +0100,
Quoted 14 lines · Wolfram Sang
Quoted 12 lines · Takashi Iwai
At Wed, 24 Nov 2010 10:59:35 +0100,
Quoted 9 lines · Wolfram Sang
Review
Quoted 2 lines · Takashi Iwai
(quoted diff) +2
-0+/* Controller doesn't support VDD 180 for MMC (for SD/MMC combo chips) */ +#define SDHCI_QUIRK_MMC_VDD_180 (1<<30)Can't we handle this more generic? Like setting ocr_avail_* from
sdhci-pci.csomehow (just brainstorming, didn't have a deeper look)? I'd like to avoid new quirks as much as possible.
Quoted 3 lines
Quoted 1 line
OK, what about the one below?
Looks better to me. (sadly, still from a glimpse, no thorough review)
Chris, any chance to take a look at this?
thanks,
Takashi
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
In reply to Takashi IwaiQuoted 153 lines · Takashi Iwai
From: Aries Lee <[email protected]>
Some old MMC devices fail with the 4/8 bits the driver tries to use exclusively. This patch adds a test for the given bus setup and falls back to the lower bit mode (until 1-bit mode) when the test fails.
[Major rework and refactoring by tiwai]
Signed-off-by Aries Lee <[email protected]>Signed-off-by Takashi Iwai <[email protected]>---
drivers/mmc/core/mmc.c | 49 ++++++++++++---------drivers/mmc/core/mmc_ops.c| 102 ++++++++++++++++++++++++++++++++++++++++++++drivers/mmc/core/mmc_ops.h| 1 +3 files changed, 131 insertions(+), 21 deletions(-)drivers/mmc/core/mmc.c +0
-0@@ -507,29 +507,36 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,*/ if ((
card->csd.mmca_vsn>=CSD_SPEC_VER_4) && (host->caps& (MMC_CAP_4_BIT_DATA|MMC_CAP_8_BIT_DATA))) {
- unsignedext_csd_bit,bus_width;drivers/mmc/core/mmc.c +25
-7- - if (host->caps & MMC_CAP_8_BIT_DATA) { - ext_csd_bit = EXT_CSD_BUS_WIDTH_8; - bus_width = MMC_BUS_WIDTH_8; - } else { - ext_csd_bit = EXT_CSD_BUS_WIDTH_4; - bus_width = MMC_BUS_WIDTH_4; + static unsigned ext_csd_bits[] = { + EXT_CSD_BUS_WIDTH_8, + EXT_CSD_BUS_WIDTH_4, + EXT_CSD_BUS_WIDTH_1 + }; + static unsigned bus_widths[] = { + MMC_BUS_WIDTH_8, + MMC_BUS_WIDTH_4, + MMC_BUS_WIDTH_1 + }; + unsigned idx; + + if (host->caps & MMC_CAP_8_BIT_DATA) + idx = 0; + else + idx = 1; + for (; idx < ARRAY_SIZE(bus_widths); idx++) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BUS_WIDTH, ext_csd_bits[idx]); + if (!err) { + mmc_set_bus_width(card->host, bus_widths[idx]); + err = mmc_bus_test(card, bus_widths[idx]); + if (!err) + break; + }}
drivers/mmc/core/mmc.c +0
-7- - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_BUS_WIDTH, ext_csd_bit); - - if (err && err != -EBADMSG) - goto free_card; -if (err) {
- printk(KERN_WARNING "%s: switch to bus width %d "
- "failed\n",mmc_hostname(card->host),
- 1 <<bus_width);
- err = 0;
- } else {
-mmc_set_bus_width(card->host, bus_width);
+ printk(KERN_WARNING "%s: switch to bus width failed\n",
+ mmc_hostname(card->host));
+ gotofree_card;
}
}drivers/mmc/core/mmc_ops.c +67
-0@@ -462,3 +462,105 @@ int mmc_send_status(struct mmc_card *card, u32 *status) return 0; } +#define MMC_CMD_BUS_TEST_W 19 +#define MMC_CMD_BUS_TEST_R 14 + +static int +mmc_send_bus_test (struct mmc_card *card,struct mmc_host *host,u8 opcode, + u8 len) +{ + struct mmc_request mrq; + struct mmc_command cmd; + struct mmc_data data; + struct scatterlist sg; + u8 *data_buf; + u8 *test_buf; + int i, err; + static u8 testdata_8bit[8] = { 0x55, 0xaa, 0, 0, 0, 0, 0, 0 }; + static u8 testdata_4bit[4] = { 0x5a, 0, 0, 0 }; + + /* dma onto stack is unsafe/nonportable, but callers to this + * routine normally provide temporary on-stack buffers ... + */ + data_buf = kmalloc(len, GFP_KERNEL); + if (!data_buf) + return -ENOMEM; + + if (len == 8) + test_buf = testdata_8bit; + else if (len == 4) + test_buf = testdata_4bit; + else { + printk(KERN_ERR "%s: Invaild bus_width %d\n", + mmc_hostname(host), len); + return -EINVAL; + } + + if (opcode == MMC_CMD_BUS_TEST_W) + memcpy(data_buf, test_buf, len); + + memset(&mrq, 0, sizeof(struct mmc_request)); + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + mrq.cmd = &cmd; + mrq.data = &data; + cmd.opcode = opcode; + cmd.arg = 0; + + /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we + * rely on callers to never use this with "native" calls for reading + * CSD or CID. Native versions of those commands use the R2 type, + * not R1 plus a data block. + */ + cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; + + data.blksz = len; + data.blocks = 1; + if (opcode == MMC_CMD_BUS_TEST_R) + data.flags = MMC_DATA_READ; + else + data.flags = MMC_DATA_WRITE; + + data.sg = &sg; + data.sg_len = 1; + sg_init_one(&sg, data_buf, len); + mmc_wait_for_req(host, &mrq); + err = 0; + if (opcode == MMC_CMD_BUS_TEST_R) { + for (i = 0; i < len / 4; i++)
drivers/mmc/core/mmc_ops.c int mmc_send_status(struct mmc_card *card, u32 *status) · line 541
Quoted 10 lines
drivers/mmc/core/mmc_ops.c +10
-0+ if ((test_buf[i] ^ data_buf[i]) != 0xff) { + err = -EIO; + break; + } + } + kfree(data_buf); + + if (cmd.error) + return cmd.error; + if (data.error)
if (data.error && (data.error != -EILSEQ))
Could you add code here to ignore CRC error of CMD14.
According to spec, CRC bits from card are optional in CMD14, and it is ignored by host.
However some host still check and may get crc error here if card does not send.
Quoted 45 lines
drivers/mmc/core/mmc_ops.c +25
-0+ return data.error; + + return err; +} + +int mmc_bus_test (struct mmc_card *card,u8 bus_width) +{ + int err, width; + + if (bus_width == MMC_BUS_WIDTH_8) + width = 8; + else if (bus_width == MMC_BUS_WIDTH_4) + width = 4; + else if (bus_width == MMC_BUS_WIDTH_1) + return 0; /* no need for test */ + else + return -EINVAL; + err = mmc_send_bus_test(card, card->host, MMC_CMD_BUS_TEST_W, width); + if (err < 0) + return err; + err = mmc_send_bus_test(card, card->host, MMC_CMD_BUS_TEST_R, width); + return err; + + +}drivers/mmc/core/mmc_ops.h +1
-1@@ -26,6 +26,7 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid); int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp); int mmc_spi_set_crc(struct mmc_host *host, int use_crc); int mmc_card_sleepawake(struct mmc_host *host, int sleep); +int mmc_bus_test (struct mmc_card *card,u8 bus_width); #endif --1.7.3.1
--
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
Re: [PATCH 2/2] mmc: Test bus-width for old MMC devices
At Tue, 14 Dec 2010 23:03:42 -0500,
Quoted 167 lines · zhangfei gao
Quoted 153 lines · Takashi Iwai
From: Aries Lee <[email protected]>
Some old MMC devices fail with the 4/8 bits the driver tries to use exclusively. This patch adds a test for the given bus setup and falls back to the lower bit mode (until 1-bit mode) when the test fails.
[Major rework and refactoring by tiwai]
Signed-off-by Aries Lee <[email protected]>Signed-off-by Takashi Iwai <[email protected]>---
drivers/mmc/core/mmc.c | 49 ++++++++++++---------drivers/mmc/core/mmc_ops.c| 102 ++++++++++++++++++++++++++++++++++++++++++++drivers/mmc/core/mmc_ops.h| 1 +3 files changed, 131 insertions(+), 21 deletions(-)drivers/mmc/core/mmc.c +0
-0@@ -507,29 +507,36 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,*/ if ((
card->csd.mmca_vsn>=CSD_SPEC_VER_4) && (host->caps& (MMC_CAP_4_BIT_DATA|MMC_CAP_8_BIT_DATA))) {
- unsignedext_csd_bit,bus_width;drivers/mmc/core/mmc.c +25
-7- - if (host->caps & MMC_CAP_8_BIT_DATA) { - ext_csd_bit = EXT_CSD_BUS_WIDTH_8; - bus_width = MMC_BUS_WIDTH_8; - } else { - ext_csd_bit = EXT_CSD_BUS_WIDTH_4; - bus_width = MMC_BUS_WIDTH_4; + static unsigned ext_csd_bits[] = { + EXT_CSD_BUS_WIDTH_8, + EXT_CSD_BUS_WIDTH_4, + EXT_CSD_BUS_WIDTH_1 + }; + static unsigned bus_widths[] = { + MMC_BUS_WIDTH_8, + MMC_BUS_WIDTH_4, + MMC_BUS_WIDTH_1 + }; + unsigned idx; + + if (host->caps & MMC_CAP_8_BIT_DATA) + idx = 0; + else + idx = 1; + for (; idx < ARRAY_SIZE(bus_widths); idx++) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BUS_WIDTH, ext_csd_bits[idx]); + if (!err) { + mmc_set_bus_width(card->host, bus_widths[idx]); + err = mmc_bus_test(card, bus_widths[idx]); + if (!err) + break; + }}
drivers/mmc/core/mmc.c +0
-7- - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_BUS_WIDTH, ext_csd_bit); - - if (err && err != -EBADMSG) - goto free_card; -if (err) {
- printk(KERN_WARNING "%s: switch to bus width %d "
- "failed\n",mmc_hostname(card->host),
- 1 <<bus_width);
- err = 0;
- } else {
-mmc_set_bus_width(card->host, bus_width);
+ printk(KERN_WARNING "%s: switch to bus width failed\n",
+ mmc_hostname(card->host));
+ gotofree_card;
}
}drivers/mmc/core/mmc_ops.c +67
-0@@ -462,3 +462,105 @@ int mmc_send_status(struct mmc_card *card, u32 *status) return 0; } +#define MMC_CMD_BUS_TEST_W 19 +#define MMC_CMD_BUS_TEST_R 14 + +static int +mmc_send_bus_test (struct mmc_card *card,struct mmc_host *host,u8 opcode, + u8 len) +{ + struct mmc_request mrq; + struct mmc_command cmd; + struct mmc_data data; + struct scatterlist sg; + u8 *data_buf; + u8 *test_buf; + int i, err; + static u8 testdata_8bit[8] = { 0x55, 0xaa, 0, 0, 0, 0, 0, 0 }; + static u8 testdata_4bit[4] = { 0x5a, 0, 0, 0 }; + + /* dma onto stack is unsafe/nonportable, but callers to this + * routine normally provide temporary on-stack buffers ... + */ + data_buf = kmalloc(len, GFP_KERNEL); + if (!data_buf) + return -ENOMEM; + + if (len == 8) + test_buf = testdata_8bit; + else if (len == 4) + test_buf = testdata_4bit; + else { + printk(KERN_ERR "%s: Invaild bus_width %d\n", + mmc_hostname(host), len); + return -EINVAL; + } + + if (opcode == MMC_CMD_BUS_TEST_W) + memcpy(data_buf, test_buf, len); + + memset(&mrq, 0, sizeof(struct mmc_request)); + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + mrq.cmd = &cmd; + mrq.data = &data; + cmd.opcode = opcode; + cmd.arg = 0; + + /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we + * rely on callers to never use this with "native" calls for reading + * CSD or CID. Native versions of those commands use the R2 type, + * not R1 plus a data block. + */ + cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; + + data.blksz = len; + data.blocks = 1; + if (opcode == MMC_CMD_BUS_TEST_R) + data.flags = MMC_DATA_READ; + else + data.flags = MMC_DATA_WRITE; + + data.sg = &sg; + data.sg_len = 1; + sg_init_one(&sg, data_buf, len); + mmc_wait_for_req(host, &mrq); + err = 0; + if (opcode == MMC_CMD_BUS_TEST_R) { + for (i = 0; i < len / 4; i++)drivers/mmc/core/mmc_ops.c int mmc_send_status(struct mmc_card *card, u32 *status) · line 541
Quoted 10 lines
drivers/mmc/core/mmc_ops.c +10
-0+ if ((test_buf[i] ^ data_buf[i]) != 0xff) { + err = -EIO; + break; + } + } + kfree(data_buf); + + if (cmd.error) + return cmd.error; + if (data.error)if (data.error && (data.error != -EILSEQ))
Quoted 4 lines
Could you add code here to ignore CRC error of CMD14.
According to spec, CRC bits from card are optional in CMD14, and it is ignored by host.
However some host still check and may get crc error here if card does not send.
Philip corrected my patch and added such a check (in sdhci.c side). I'm going to resend the revised patch soon.
thanks,
Takashi