Skip to contentSkip to conversation

add support for host controller v3.00

PATCH Superseded Arindam Nath 6 participants 125 messages Mar 4, 2011 – Mar 24, 2011 Page 1 of 4

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover add support for host controller v3.00

V2
----
[01/12]: Make saved_abort_cmd part of struct sdhci_host rather
than global variable.
[01/12]: Clear SDHCI_USE_SDMA _iff_ SDHCI_USE_ADMA is set. [01/12]: Set either Auto CMD23 or Auto CMD12, but not both, in
the Transfer Mode register.
[02/12]: Check host controller version before reading
SDHCI_CAPABILITIES_1.
[02/12]: Remove spinlock from sdhci_start_signal_voltage_switch
and use usleep_range() rather than mdelay().
[02/12]: Set S18R in OCR to 1 for all UHS-I modes. [02/12]: NULL pointer check for start_signal_voltage_switch(). [02/12]: Set MMC_CAP_UHS_SDR50 if MMC_CAP_UHS_SDR104 is set. [06/12]: Add checking for SDR25 in sd_set_bus_speed_mode(). [09/12]: Remove checking for MMC_SEND_TUNING_BLOCK within
sdhci_set_transfer_mode(), since cmd.data is set to NULL inside sdhci_execute_tuning().
[11/12]: Correctly set clk to SDHCI_PROG_CLOCK_MODE when host
controller supports Programmable Clock Mode.

V1
----
The patches below add support for Host Controller v3.00 as per the spec v3.00. It also adds support for UHS-I cards as per Physical Layer Specification v3.01.

Thanks for review.

Regards,
Arindam

Arindam Nath (12):
[PATCH 01/12] mmc: sdhci: add support for auto CMD23
[PATCH 02/12] mmc: sd: add support for signal voltage switch procedure [PATCH 03/12] mmc: sd: query function modes for uhs cards [PATCH 04/12] mmc: sd: add support for driver type selection [PATCH 05/12] mmc: sdhci: reset sdclk before setting high speed enable [PATCH 06/12] mmc: sd: add support for uhs bus speed mode selection [PATCH 07/12] mmc: sd: set current limit for uhs cards [PATCH 08/12] mmc: sd: report correct speed and capacity of uhs cards [PATCH 09/12] mmc: sd: add support for tuning during uhs initialization [PATCH 10/12] mmc: sdhci: enable preset value after uhs initialization [PATCH 11/12] mmc: sdhci: add support for programmable clock mode [PATCH 12/12] mmc: sdhci: add support for retuning mode 1

 drivers/mmc/core/bus.c    |   11 +-
 drivers/mmc/core/core.c   |    9 +
 drivers/mmc/core/core.h   |    1 +
 drivers/mmc/core/sd.c     |  436 +++++++++++++++++++++++++---
 drivers/mmc/core/sd.h     |    3 +-
 drivers/mmc/core/sd_ops.c |   32 ++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/core/sdio.c   |    3 +-
 drivers/mmc/host/sdhci.c  |  697 ++++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |   45 +++-
 include/linux/mmc/card.h  |   43 +++
 include/linux/mmc/host.h  |   26 ++
 include/linux/mmc/mmc.h   |    1 +
 include/linux/mmc/sd.h    |    3 +-
 include/linux/mmc/sdhci.h |   13 +
 15 files changed, 1228 insertions(+), 96 deletions(-)
#1 lore raw

PATCH v2 1/12 mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when SDHCI_USE_ADMA is set.

A new definition for SDHCI_ARGUMENT2 register has been added in v3.00 spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we will need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01, which specify whether the card supports CMD20 and/or CMD23. We use this as one of the conditions to decide whether to enable Auto CMD23 or not.

---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69 +++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
drivers/mmc/core/sd.c +6 -0
index d18c32b..b3f8a3c 100644
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}
 
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +64 -5

113 lines not on this page · raw message

drivers/mmc/host/sdhci.h +2 -0
index 6e0969e..223762c 100644
@@ -25,6 +25,7 @@
  */
 
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF))
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +4 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +1 -1
index 3fd85e0..178363b 100644
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system specification 1.0 - 1.01 */
 #define SCR_SPEC_VER_1		1	/* Implements system specification 1.10 */
-#define SCR_SPEC_VER_2		2	/* Implements system specification 2.00 */
+#define SCR_SPEC_VER_2		2	/* Implements system specification 2.00 - 3.0x */
 
 /*
  * SD bus widths
include/linux/mmc/sdhci.h +2 -0
index 83bd9f7..282d158 100644
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command saved for data error recovery */
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
Signature · 1 line
1.7.1
#2 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 46 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when SDHCI_USE_ADMA is set.

A new definition for SDHCI_ARGUMENT2 register has been added in v3.00 spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we will need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We use this as one of the conditions to decide whether to enable Auto CMD23 or not.

---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
drivers/mmc/core/sd.c +0 -0
index d18c32b..b3f8a3c 100644

drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card *card) · line 196

Quoted 9 lines
drivers/mmc/core/sd.c +6 -0
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}

Looks fine.

Quoted 33 lines
drivers/mmc/core/sd.c +0 -0
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +14 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct sdhci_host
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host *host,
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host · line 839

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT) &&
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
+
+	return 0;
+}

Just a thought. Shouldn't the name should say *cmd23_required? Because here you are not just checking the card capability but also checking if current command requires CMD23 or not.

Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -0
+
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 10 lines
drivers/mmc/host/sdhci.c +4 -3
 	if (data->blocks > 1) {
 		if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host->mrq))
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

Quoted 101 lines
drivers/mmc/host/sdhci.c +9 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2 register.
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks, SDHCI_ARGUMENT2);
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +2 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host *mmc,
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been specified in

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop multiple

block

drivers/mmc/host/sdhci.c +15 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned long
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +3 -2
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))
drivers/mmc/host/sdhci.c +4 -0
 			sdhci_transfer_pio(host);
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA flag */
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +1 -0
index 6e0969e..223762c 100644
@@ -25,6 +25,7 @@
  */
 
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz &

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +0 -0
index 8ce0827..22b0335 100644

include/linux/mmc/card.h struct mmc_ext_csd { · line 67

Quoted 10 lines
include/linux/mmc/card.h +4 -0
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)

Looks good. I am just curious about: spec says that UHS104 card must support CMD23. so are you handling this anywhere? Means what if card is detected as UHS104 card and if it doesn't set this CMD23 bit? Just an error condition.

include/linux/mmc/sd.h line 60

Quoted 10 lines
include/linux/mmc/card.h +0 -0
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +0 -0
index 3fd85e0..178363b 100644
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system

specification

Quoted 2 lines

1.0 - 1.01 */
#define SCR_SPEC_VER_1 1 /* Implements system

specification

Quoted 2 lines

1.10 */
-#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 2 lines

2.00 */
+#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 25 lines

2.00 - 3.0x */

/*
* SD bus widths

include/linux/mmc/sdhci.h +1 -0
index 83bd9f7..282d158 100644
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command saved

for data error recovery */

include/linux/mmc/sdhci.h +1 -1
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
--

1.7.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

#3 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Hi Subhash,

Quoted 108 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, March 09, 2011 5:52 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 16 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when SDHCI_USE_ADMA is set.

Quoted 4 lines

A new definition for SDHCI_ARGUMENT2 register has been added in v3.00 spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we

will

Quoted 6 lines

need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We use

this

Quoted 1 line

as one of the conditions to decide whether to enable Auto CMD23 or

not.

Quoted 17 lines
---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
drivers/mmc/core/sd.c +0 -0
index d18c32b..b3f8a3c 100644

drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card *card) · line 196

Quoted 9 lines
drivers/mmc/core/sd.c +6 -0
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}

Looks fine.

Quoted 40 lines
drivers/mmc/core/sd.c +0 -0
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +21 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct sdhci_host
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host *host,
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT) &&
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
Quoted 8 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) · line 838

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+
+	return 0;
+}

Just a thought. Shouldn't the name should say *cmd23_required? Because here
you are not just checking the card capability but also checking if current
command requires CMD23 or not.

Yes, *cmd23_required looks good to me. I will change the function name.

Quoted 125 lines
Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -0
+
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 10 lines
drivers/mmc/host/sdhci.c +4 -3
 	if (data->blocks > 1) {
 		if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host->mrq))
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host

Quoted 14 lines
drivers/mmc/host/sdhci.c +9 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2 register.
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks, SDHCI_ARGUMENT2);
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +0 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host

*mmc,

Quoted 66 lines
drivers/mmc/host/sdhci.c +2 -0
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been specified in

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop multiple

block

drivers/mmc/host/sdhci.c +15 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned long
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +3 -2
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))
drivers/mmc/host/sdhci.c +4 -0
 			sdhci_transfer_pio(host);
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA flag */
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +0 -0
index 6e0969e..223762c 100644

drivers/mmc/host/sdhci.h line 31

Quoted 7 lines
drivers/mmc/host/sdhci.h +1 -0
@@ -25,6 +25,7 @@
  */
 
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz

&

Quoted 15 lines

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +0 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
Quoted 15 lines

include/linux/mmc/card.h struct mmc_ext_csd { · line 67

Quoted 9 lines
include/linux/mmc/card.h +4 -0
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)

Looks good. I am just curious about: spec says that UHS104 card must support
CMD23. so are you handling this anywhere? Means what if card is detected as
UHS104 card and if it doesn't set this CMD23 bit? Just an error condition.

The description from Auto CMD23 Enable in the spec mentions card supporting CMD23 as a _required_ condition before using Auto CMD23. So I assume UHS104 cards should have this bit set for sure.

Thanks,
Arindam

#4 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

In reply to Arindam Nath

Arindam,

Capability to send CMD23 automatically is something specific to your controller.
CMD23 (SET_BLOCK_COUNT) is a new command added in SD3.0 spec and mandatory for SDR104 mode. Why are you not adding this command in core/block layer before sending multi byte read command to host controller driver?

Regards,
Subhash

Quoted 103 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when SDHCI_USE_ADMA is set.

A new definition for SDHCI_ARGUMENT2 register has been added in v3.00 spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we will need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We use this as one of the conditions to decide whether to enable Auto CMD23 or not.

---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
drivers/mmc/core/sd.c +6 -0
index d18c32b..b3f8a3c 100644
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}
 
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +25 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct sdhci_host
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host *host,
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT) &&
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
+
+	return 0;
+}
+
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 10 lines
drivers/mmc/host/sdhci.c +4 -3
 	if (data->blocks > 1) {
 		if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host->mrq))
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

Quoted 119 lines
drivers/mmc/host/sdhci.c +9 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2 register.
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks, SDHCI_ARGUMENT2);
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +2 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host *mmc,
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been specified in

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop multiple

block

drivers/mmc/host/sdhci.c +15 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned long
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +3 -2
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))
drivers/mmc/host/sdhci.c +4 -0
 			sdhci_transfer_pio(host);
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA flag */
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +1 -0
index 6e0969e..223762c 100644
@@ -25,6 +25,7 @@
  */
 
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz &

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +4 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +0 -0
index 3fd85e0..178363b 100644

include/linux/mmc/sd.h line 60

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system

specification

Quoted 2 lines

1.0 - 1.01 */
#define SCR_SPEC_VER_1 1 /* Implements system

specification

Quoted 2 lines

1.10 */
-#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 2 lines

2.00 */
+#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 25 lines

2.00 - 3.0x */

/*
* SD bus widths

include/linux/mmc/sdhci.h +1 -0
index 83bd9f7..282d158 100644
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command saved

for data error recovery */

include/linux/mmc/sdhci.h +1 -1
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
--

1.7.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

#5 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Hi Subhash,

Quoted 8 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:54 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 4 lines

Arindam,

Capability to send CMD23 automatically is something specific to your controller.

Auto CMD23 is different from ACMD23. Auto CMD23 is a feature added into Host Controller Spec v3.00, and the code follows the procedure to check the 4 preconditions required to enable Host to send CMD23 automatically. I had similar discussion on the community with Arnd few weeks back, and we agreed that this should be part of controller specific code.

Thanks,
Arindam

Quoted 288 lines

CMD23 (SET_BLOCK_COUNT) is a new command added in SD3.0 spec and mandatory
for SDR104 mode. Why are you not adding this command in core/block layer
before sending multi byte read command to host controller driver?

Regards,
Subhash

Quoted 16 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when SDHCI_USE_ADMA is set.

Quoted 4 lines

A new definition for SDHCI_ARGUMENT2 register has been added in v3.00 spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we

will

Quoted 6 lines

need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We use

this

Quoted 1 line

as one of the conditions to decide whether to enable Auto CMD23 or

not.

Quoted 76 lines
---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
drivers/mmc/core/sd.c +6 -0
index d18c32b..b3f8a3c 100644
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}
 
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +25 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct sdhci_host
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host *host,
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT) &&
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
+
+	return 0;
+}
+
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 10 lines
drivers/mmc/host/sdhci.c +4 -3
 	if (data->blocks > 1) {
 		if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host->mrq))
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host

Quoted 14 lines
drivers/mmc/host/sdhci.c +9 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2 register.
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks, SDHCI_ARGUMENT2);
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +0 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host

*mmc,

Quoted 66 lines
drivers/mmc/host/sdhci.c +2 -0
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been specified in

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop multiple

block

drivers/mmc/host/sdhci.c +15 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned long
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +3 -2
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))
drivers/mmc/host/sdhci.c +4 -0
 			sdhci_transfer_pio(host);
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA flag */
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +0 -0
index 6e0969e..223762c 100644

drivers/mmc/host/sdhci.h line 31

Quoted 7 lines
drivers/mmc/host/sdhci.h +1 -0
@@ -25,6 +25,7 @@
  */
 
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz

&

Quoted 32 lines

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +4 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +0 -0
index 3fd85e0..178363b 100644

include/linux/mmc/sd.h line 60

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system

specification

Quoted 2 lines

1.0 - 1.01 */
#define SCR_SPEC_VER_1 1 /* Implements system

specification

Quoted 2 lines

1.10 */
-#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 2 lines

2.00 */
+#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 21 lines

2.00 - 3.0x */

/*
* SD bus widths

include/linux/mmc/sdhci.h +1 -0
index 83bd9f7..282d158 100644
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command saved

for data error recovery */

include/linux/mmc/sdhci.h +1 -1
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
--

1.7.1

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc"

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 26 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 5:05 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Hi Subhash,

Quoted 8 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:54 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 4 lines

Arindam,

Capability to send CMD23 automatically is something specific to your controller.

Quoted 6 lines

Auto CMD23 is different from ACMD23. Auto CMD23 is a feature added into Host Controller Spec v3.00, and the code follows the procedure to check the 4 preconditions required to enable Host to send CMD23 automatically. I had similar discussion on the community with Arnd few weeks back, and we agreed that this should be part of controller specific code.

I am not talking about ACMD23 which is SET_WR_BLK_ERASE_COUNT. I am talking about newly added CMD23 (SET_BLOCK_COUNT) command in SD3.0. Shouldn't the logic to send this command be part of generic mmc layers (block/core) rather than at host controller driver level. It's good that your controller have the hw capability to send the CMD23 automatically but what about for controllers which doesn't have this type of capability available? Then it has to rely on the block/core layer to send the CMD23 before CMD19/CMD25. I think this should be part of block/core layer functionality in order to be SD3.01 spec compliant.

Quoted 301 lines

Thanks,
Arindam

Quoted 6 lines

CMD23 (SET_BLOCK_COUNT) is a new command added in SD3.0 spec and mandatory
for SDR104 mode. Why are you not adding this command in core/block layer
before sending multi byte read command to host controller driver?

Quoted 10 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 7 lines
Quoted 7 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the Transfer Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when

SDHCI_USE_ADMA

Quoted 3 lines
Quoted 3 lines

is set.

A new definition for SDHCI_ARGUMENT2 register has been added in

v3.00

Quoted 25 lines
Quoted 3 lines

spec, which is the same as SDHCI_DMA_ADDRESS. We program the block count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to stop multiple block transfers. But during error recovery procedure, we

will

Quoted 6 lines

need to send Abort command, so we use a variable saved_abort_cmd to save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We use

this

Quoted 1 line

as one of the conditions to decide whether to enable Auto CMD23 or

not.

Quoted 12 lines
---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
Quoted 5 lines

drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card

Quoted 5 lines
drivers/mmc/core/sd.c +0 -0
index d18c32b..b3f8a3c 100644
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card

*card)

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +6 -0
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}
 
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +0 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
Quoted 7 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct

Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -0
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct

sdhci_host

Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
Quoted 10 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host

*host,

Quoted 116 lines
Quoted 20 lines
drivers/mmc/host/sdhci.c +14 -0
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT) &&
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
+
+	return 0;
+}
+
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 10 lines
drivers/mmc/host/sdhci.c +4 -3
 	if (data->blocks > 1) {
 		if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host->mrq))
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host

Quoted 14 lines
drivers/mmc/host/sdhci.c +9 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2 register.
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks, SDHCI_ARGUMENT2);
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +0 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host

*mmc,

Quoted 68 lines
drivers/mmc/host/sdhci.c +2 -0
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been specified in

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop multiple

block

drivers/mmc/host/sdhci.c +15 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned long
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +3 -2
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))
drivers/mmc/host/sdhci.c +4 -0
 			sdhci_transfer_pio(host);
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA flag */
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +0 -0
index 6e0969e..223762c 100644
@@ -25,6 +25,7 @@
  */
 
Quoted 5 lines

drivers/mmc/host/sdhci.h

Quoted 5 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) |

(blksz

Quoted 66 lines

&

Quoted 32 lines

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +4 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +0 -0
index 3fd85e0..178363b 100644

include/linux/mmc/sd.h line 60

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system

specification

Quoted 2 lines

1.0 - 1.01 */
#define SCR_SPEC_VER_1 1 /* Implements system

specification

Quoted 2 lines

1.10 */
-#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 2 lines

2.00 */
+#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 21 lines

2.00 - 3.0x */

/*
* SD bus widths

include/linux/mmc/sdhci.h +1 -0
index 83bd9f7..282d158 100644
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command saved

for data error recovery */

include/linux/mmc/sdhci.h +1 -1
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
--

1.7.1

Quoted 2 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 4 lines

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Hi Subhash,

Quoted 46 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 5:23 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 8 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 5:05 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Quoted 10 lines

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:54 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 01/12] mmc: sdhci: add support for auto

CMD23

Quoted 4 lines
Quoted 4 lines

Arindam,

Capability to send CMD23 automatically is something specific to

your

Quoted 3 lines
Quoted 1 line

controller.

Auto CMD23 is different from ACMD23. Auto CMD23 is a feature added

into

Quoted 1 line

Host Controller Spec v3.00, and the code follows the procedure to

check

Quoted 2 lines

the 4 preconditions required to enable Host to send CMD23 automatically. I had similar discussion on the community with Arnd

few

Quoted 2 lines

weeks back, and we agreed that this should be part of controller specific code.

Quoted 16 lines

I am not talking about ACMD23 which is SET_WR_BLK_ERASE_COUNT. I am talking
about newly added CMD23 (SET_BLOCK_COUNT) command in SD3.0. Shouldn't the
logic to send this command be part of generic mmc layers (block/core) rather
than at host controller driver level. It's good that your controller have
the hw capability to send the CMD23 automatically but what about for controllers which doesn't have this type of capability available? Then it
has to rely on the block/core layer to send the CMD23 before CMD19/CMD25. I
think this should be part of block/core layer functionality in order to be
SD3.01 spec compliant.

I don't think I will be able to add the support for CMD23 in the mmc block layer right now. I will probably add the support in the next phase once the base support for SD3.0 is already in the kernel.

Thanks,
Arindam

Quoted 324 lines
Quoted 14 lines

Thanks,
Arindam

Quoted 9 lines

CMD23 (SET_BLOCK_COUNT) is a new command added in SD3.0 spec and mandatory
for SDR104 mode. Why are you not adding this command in core/block layer
before sending multi byte read command to host controller driver?

Regards,
Subhash

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 4 lines
Quoted 4 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23

Host Controller v3.00 and later support Auto CMD23 in the

Transfer

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

Mode register. Since Auto CMD23 can be used with or without DMA, and if used with DMA, it should _only_ be ADMA, we check against SDHCI_USE_SDMA not being set. This flag is reset when

SDHCI_USE_ADMA

Quoted 3 lines
Quoted 3 lines

is set.

A new definition for SDHCI_ARGUMENT2 register has been added in

v3.00

Quoted 1 line
Quoted 1 line

spec, which is the same as SDHCI_DMA_ADDRESS. We program the

block

Quoted 1 line
Quoted 1 line
Quoted 1 line

count for CMD23 in SDHCI_ARGUMENT2, so we don't need CMD12 to

stop

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

multiple block transfers. But during error recovery procedure, we

will

Quoted 1 line

need to send Abort command, so we use a variable saved_abort_cmd

to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

save the stop command to be used later.

Two bits are added to SCR register as per the Physical Layer Spec v3.01,
which specify whether the card supports CMD20 and/or CMD23. We

use

Quoted 2 lines
Quoted 2 lines

this

Quoted 1 line

as one of the conditions to decide whether to enable Auto CMD23

or

Quoted 60 lines
Quoted 13 lines

not.

Quoted 12 lines
---
 drivers/mmc/core/sd.c     |    6 ++++
 drivers/mmc/host/sdhci.c  |   69
+++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/host/sdhci.h  |    2 +
 include/linux/mmc/card.h  |    4 ++
 include/linux/mmc/sd.h    |    2 +-
 include/linux/mmc/sdhci.h |    2 +
 6 files changed, 79 insertions(+), 6 deletions(-)
Quoted 5 lines

drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card

Quoted 5 lines
drivers/mmc/core/sd.c +0 -0
index d18c32b..b3f8a3c 100644
@@ -188,6 +188,12 @@ static int mmc_decode_scr(struct mmc_card

*card)

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +6 -0
 	scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
 	scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
+	if (scr->sda_vsn == SCR_SPEC_VER_2) {
+		/* Check if Physical Layer Spec v3.0 is supported*/
+		scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1);
+		if (scr->sda_spec3)
+			scr->cmd_support = UNSTUFF_BITS(resp, 32, 2);
+	}
 
 	if (UNSTUFF_BITS(resp, 55, 1))
 		card->erased_byte = 0xFF;
drivers/mmc/host/sdhci.c +0 -0
index 9e15f41..8914a25 100644
@@ -25,6 +25,7 @@
 
Quoted 7 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct

Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -0
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
 
 #include "sdhci.h"
 
@@ -812,6 +813,30 @@ static void sdhci_prepare_data(struct

sdhci_host

Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
 *host, struct mmc_data *data)
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
Quoted 10 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+/*
+ * Does the Host Controller support Auto CMD23?
+ *
+ * There are four preconditions for Auto CMD23 to be supported:
+ *  1. Host Controller v3.00 or later
+ *  2. Card supports CMD23
+ *  3. If DMA is used, it should be ADMA
+ *  4. Only when CMD18 or CMD25 is issued
+ */
+static int sdhci_host_auto_cmd23_supported(struct sdhci_host

*host,

Quoted 6 lines
Quoted 6 lines

drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+	struct mmc_request *mrq)
+{
+	struct mmc_card *card = host->mmc->card;
+
+	if ((host->version >= SDHCI_SPEC_300) &&
+	   card && (card->scr.cmd_support & SD_SCR_CMD23_SUPPORT)

&&

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+	   !(host->flags & SDHCI_USE_SDMA) &&
+	   ((mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) ||
+	   (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		return 1;
+
+	return 0;
+}
+
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 853

Quoted 8 lines
drivers/mmc/host/sdhci.c +0 -0
 static void sdhci_set_transfer_mode(struct sdhci_host *host,
 	struct mmc_data *data)

{

drivers/mmc/host/sdhci.c +0 -0
@@ -825,10 +850,21 @@ static void sdhci_set_transfer_mode(struct
 sdhci_host *host,
 	mode = SDHCI_TRNS_BLK_CNT_EN;
 	if (data->blocks > 1) {
 		if (host->quirks &

SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)

Quoted 6 lines
Quoted 5 lines

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct sdhci_host *host,

Quoted 5 lines
drivers/mmc/host/sdhci.c +2 -3
-			mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
-		else
-			mode |= SDHCI_TRNS_MULTI;
+			mode |= SDHCI_TRNS_ACMD12;
+		else if (sdhci_host_auto_cmd23_supported(host, host-

mrq))

Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 858

Quoted 3 lines
drivers/mmc/host/sdhci.c +2 -0
 {
+			/*
+			 * Host Controller v3.00 can automatically send

CMD23

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 859

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+			 * before CMD18 or CMD25. For that, we need to

enable

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct · line 861

Quoted 2 lines
drivers/mmc/host/sdhci.c +2 -0
+			 * Auto CMD23 in the Transfer Mode register and
+			 * program the block count in Argument 2

register.

Quoted 3 lines
Quoted 3 lines

drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct sdhci_host *host,

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+			 */
+			mode |= SDHCI_TRNS_AUTO_CMD23;
+			sdhci_writel(host, data->blocks,

SDHCI_ARGUMENT2);

Quoted 10 lines
Quoted 10 lines

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host

Quoted 9 lines
drivers/mmc/host/sdhci.c +4 -0
+		}
+
+		mode |= SDHCI_TRNS_MULTI;
 	}
+
 	if (data->flags & MMC_DATA_READ)
drivers/mmc/host/sdhci.c +0 -0
 		mode |= SDHCI_TRNS_READ;
 	if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1131,6 +1167,23 @@ static void sdhci_request(struct mmc_host

*mmc,

Quoted 6 lines
Quoted 6 lines

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)

Quoted 6 lines
drivers/mmc/host/sdhci.c +2 -0
 struct mmc_request *mrq)
 #ifndef SDHCI_USE_LEDS_CLASS
 	sdhci_activate_led(host);
 #endif
+	/*
+	 * Since the block count for CMD23 has already been

specified in

Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c

Quoted 2 lines

the

drivers/mmc/host/sdhci.c +1 -0
+	 * Argument 2 register, we don't need CMD12 to stop

multiple

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

block

drivers/mmc/host/sdhci.c +10 -0
+	 * transfers.
+	 */
+	if (sdhci_host_auto_cmd23_supported(host, mrq)) {
+		if (mrq->stop) {
+			/*
+			 * Save the stop command here to be used during
+			 * error recovery
+			 */
+			host->saved_abort_cmd = mrq->data->stop;
+			mrq->data->stop = NULL;
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c static void sdhci_timeout_timer(unsigned

Quoted 8 lines
drivers/mmc/host/sdhci.c +4 -0
+			mrq->stop = NULL;
+		}
+	}
+
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
 		if (mrq->stop) {
 			mrq->data->stop = NULL;
@@ -1396,6 +1449,7 @@ static void sdhci_timeout_timer(unsigned

long

Quoted 9 lines
Quoted 9 lines

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct

Quoted 9 lines
drivers/mmc/host/sdhci.c +1 -0
 data)
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
+			host->data->stop = host->saved_abort_cmd;
 			sdhci_finish_data(host);
 		} else {
drivers/mmc/host/sdhci.c +0 -0
 			if (host->cmd)
@@ -1534,9 +1588,10 @@ static void sdhci_data_irq(struct

sdhci_host

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/mmc/host/sdhci.c +3 -2
 *host, u32 intmask)
 		host->data->error = -EIO;
 	}
 
-	if (host->data->error)
+	if (host->data->error) {
+		host->data->stop = host->saved_abort_cmd;
 		sdhci_finish_data(host);
-	else {
+	} else {
 		if (intmask & (SDHCI_INT_DATA_AVAIL |
 SDHCI_INT_SPACE_AVAIL))

sdhci_transfer_pio(host);

Quoted 1 line
Quoted 1 line

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 1 line
drivers/mmc/host/sdhci.c +0 -0
@@ -1792,6 +1847,10 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +1 -0
 		host->flags &= ~SDHCI_USE_ADMA;
 	}
 
+	/* If the host can perform ADMA operation, we reset SDMA

flag */

Quoted 61 lines
Quoted 13 lines
Quoted 13 lines
drivers/mmc/host/sdhci.c +3 -0
+	if (host->flags & SDHCI_USE_ADMA)
+		host->flags &= ~SDHCI_USE_SDMA;
+
 	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
 		if (host->ops->enable_dma) {
 			if (host->ops->enable_dma(host)) {
drivers/mmc/host/sdhci.h +0 -0
index 6e0969e..223762c 100644
@@ -25,6 +25,7 @@
  */
 
Quoted 5 lines

drivers/mmc/host/sdhci.h

Quoted 5 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_DMA_ADDRESS	0x00
+#define SDHCI_ARGUMENT2		SDHCI_DMA_ADDRESS
 
 #define SDHCI_BLOCK_SIZE	0x04
 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) |

(blksz

Quoted 42 lines

&

Quoted 32 lines

0xFFF))

drivers/mmc/host/sdhci.h +1 -0
@@ -37,6 +38,7 @@
 #define  SDHCI_TRNS_DMA		0x01
 #define  SDHCI_TRNS_BLK_CNT_EN	0x02
 #define  SDHCI_TRNS_ACMD12	0x04
+#define  SDHCI_TRNS_AUTO_CMD23	0x08
 #define  SDHCI_TRNS_READ	0x10
 #define  SDHCI_TRNS_MULTI	0x20
 
include/linux/mmc/card.h +4 -0
index 8ce0827..22b0335 100644
@@ -58,9 +58,13 @@ struct mmc_ext_csd {
 
 struct sd_scr {
 	unsigned char		sda_vsn;
+	unsigned char		sda_spec3;
 	unsigned char		bus_widths;
 #define SD_SCR_BUS_WIDTH_1	(1<<0)
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
+	unsigned char		cmd_support;
+#define SD_SCR_CMD20_SUPPORT	(1<<0)
+#define SD_SCR_CMD23_SUPPORT	(1<<1)
 };
 
 struct sd_ssr {
include/linux/mmc/sd.h +0 -0
index 3fd85e0..178363b 100644

include/linux/mmc/sd.h line 60

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
@@ -59,7 +59,7 @@
 
 #define SCR_SPEC_VER_0		0	/* Implements system

specification

Quoted 2 lines

1.0 - 1.01 */
#define SCR_SPEC_VER_1 1 /* Implements system

specification

Quoted 2 lines

1.10 */
-#define SCR_SPEC_VER_2 2 /* Implements system

specification

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

2.00 */
+#define SCR_SPEC_VER_2 2 /* Implements system

specification

Review

Quoted 5 lines

2.00 - 3.0x */

/*
* SD bus widths

(quoted diff) +0 -0

b/include/linux/mmc/sdhci.h

Quoted 8 lines
Quoted 8 lines

include/linux/mmc/sdhci.h struct sdhci_host { · line 148

Quoted 8 lines

index 83bd9f7..282d158 100644

include/linux/mmc/sdhci.h +1 -0
@@ -145,6 +145,8 @@ struct sdhci_host {
 	unsigned int            ocr_avail_sd;
 	unsigned int            ocr_avail_mmc;
 
+	struct mmc_command	*saved_abort_cmd; /* Abort command

saved

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

for data error recovery */

include/linux/mmc/sdhci.h +1 -1
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* __SDHCI_H */
--

1.7.1

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-

info.html

Quoted 2 lines
Quoted 1 line
#8 lore raw

PATCH v2 2/12 mmc: sd: add support for signal voltage switch procedure

In reply to Arindam Nath

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148 +++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +34 -3
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
 	int err;
+	u32 rocr;
 
 	/*
 	 * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 	if (!err)
 		ocr |= 1 << 30;
 
-	err = mmc_send_app_op_cond(host, ocr, NULL);
+	/* If the host can supply more than 150mA, XPC should be set to 1. */
+	if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+	    MMC_CAP_SET_XPC_180))
+		ocr |= 1 << 28;
+
+	err = mmc_send_app_op_cond(host, ocr, &rocr);
 	if (err)
 		return err;
 
+	/*
+	 * In case CCS and S18A in the response is set, start Signal Voltage
+	 * Switch procedure. SPI mode doesn't support CMD11.
+	 */
+	if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+		err = mmc_start_voltage_switch(host);
+		if (err)
+			return err;
+	}
+
 	if (mmc_host_is_spi(host))
 		err = mmc_send_cid(host, cid);
 	else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
 	}
 
 	/*
+	 * If the host supports one of UHS-I modes, request the card
+	 * to switch to 1.8V signaling level.
+	 */
+	if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+	    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+		host->ocr |= (1 << 24);
+
+	/*
 	 * Detect and init the card.
 	 */
 	err = mmc_sd_init_card(host, host->ocr, NULL);
-	if (err)
-		goto err;
+	if (err == -EAGAIN) {
+		/*
+		 * Retry initialization with S18R set to 0.
+		 */
+		host->ocr &= ~(1 << 24);
+		err = mmc_sd_init_card(host, host->ocr, NULL);
+		if (err)
+			goto err;
+	}
 
 	mmc_release_host(host);
 	err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +32 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
 	return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+	struct mmc_command cmd;
+	int err;
+
+	BUG_ON(!host);
+
+	/*
+	 * If the host does not provide signal voltage switch procedure, we
+	 * set S18R to 0, and then retry initialization sequence.
+	 */
+	if (!host->ops->start_signal_voltage_switch)
+		return -EAGAIN;
+
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
+	cmd.opcode = SD_SWITCH_VOLTAGE;
+	cmd.arg = 0;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+	err = mmc_wait_for_cmd(host, &cmd, 0);
+	if (err)
+		return err;
+
+	if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+		return -EIO;
+
+	err = host->ops->start_signal_voltage_switch(host);
+
+	return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
 	struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
 
drivers/mmc/host/sdhci.c +135 -13

230 lines not on this page · raw message

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE	0x00000800
 #define  SDHCI_CARD_PRESENT	0x00010000
 #define  SDHCI_WRITE_PROTECT	0x00080000
+#define  SDHCI_DATA_LVL_MASK	0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT	20
 
 #define SDHCI_HOST_CONTROL 	0x28
 #define  SDHCI_CTRL_LED		0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR	0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2		0x3E
+#define  SDHCI_CTRL_VDD_180		0x0008
 
 #define SDHCI_CAPABILITIES	0x40
 #define  SDHCI_TIMEOUT_CLK_MASK	0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180	0x04000000
 #define  SDHCI_CAN_64BIT	0x10000000
 
+#define  SDHCI_SUPPORT_SDR50	0x00000001
+#define  SDHCI_SUPPORT_SDR104	0x00000002
+#define  SDHCI_SUPPORT_DDR50	0x00000004
+
 #define SDHCI_CAPABILITIES_1	0x44
 
-#define SDHCI_MAX_CURRENT	0x48
+#define SDHCI_MAX_CURRENT		0x48
+#define  SDHCI_MAX_CURRENT_330_MASK	0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT	0
+#define  SDHCI_MAX_CURRENT_300_MASK	0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT	8
+#define  SDHCI_MAX_CURRENT_180_MASK	0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT	16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER	4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +10 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
 	/* optional callback for HC quirks */
 	void	(*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+	int	(*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
 						/* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD	(1 << 13)	/* Can power off after boot */
 #define MMC_CAP_BUS_WIDTH_TEST	(1 << 14)	/* CMD14/CMD19 bus width ok */
+#define MMC_CAP_UHS_SDR12	(1 << 15)	/* Host supports UHS SDR12 mode */
+#define MMC_CAP_UHS_SDR25	(1 << 16)	/* Host supports UHS SDR25 mode */
+#define MMC_CAP_UHS_SDR50	(1 << 17)	/* Host supports UHS SDR50 mode */
+#define MMC_CAP_UHS_SDR104	(1 << 18)	/* Host supports UHS SDR104 mode */
+#define MMC_CAP_UHS_DDR50	(1 << 19)	/* Host supports UHS DDR50 mode */
+#define MMC_CAP_SET_XPC_330	(1 << 20)	/* Host supports >150mA current at 3.3V */
+#define MMC_CAP_SET_XPC_300	(1 << 21)	/* Host supports >150mA current at 3.0V */
+#define MMC_CAP_SET_XPC_180	(1 << 22)	/* Host supports >150mA current at 1.8V */
 
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
 
include/linux/mmc/sd.h +1 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks. */
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6  */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7  */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1  */
 
   /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below   R1  */
Signature · 1 line
1.7.1
#9 lore raw

Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

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

Quoted 3 lines
drivers/mmc/host/sdhci.c +2 -0
+	if (host->version >= SDHCI_SPEC_300)
+		caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);

Now caps[1] can be uninitialized (didn't the compiler warn about this?) Maybe

	caps[1] = host->version... ? sdhci_readl() : 0

(or simply an else branch)?

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#10 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Wolfram,

Quoted 11 lines

-----Original Message-----
From: Wolfram Sang [mailto:[email protected]]
Sent: Friday, March 04, 2011 5:18 PM
To: Nath, Arindam
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 4 lines

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

Quoted 2 lines
drivers/mmc/host/sdhci.c +2 -0
+	if (host->version >= SDHCI_SPEC_300)
+		caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);

Now caps[1] can be uninitialized (didn't the compiler warn about this?)

Surprisingly, there was no compiler warning on my setup. I will take care of it.

Thanks,
Arindam

Quoted 15 lines

Maybe

	caps[1] = host->version... ? sdhci_readl() : 0

(or simply an else branch)?

Regards,

Wolfram

--
Pengutronix e.K. | Wolfram Sang
|
Industrial Linux Solutions | http://www.pengutronix.de/
|

#11 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

In reply to Arindam Nath

+1. Looks good to me from sd3.0 spec. prospective.

Quoted 500 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
 	int err;
+	u32 rocr;
 
 	/*
 	 * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
 	if (!err)
 		ocr |= 1 << 30;
 
-	err = mmc_send_app_op_cond(host, ocr, NULL);
+	/* If the host can supply more than 150mA, XPC should be set to

1. */

drivers/mmc/core/sd.c +7 -0
+	if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+	    MMC_CAP_SET_XPC_180))
+		ocr |= 1 << 28;
+
+	err = mmc_send_app_op_cond(host, ocr, &rocr);
 	if (err)
 		return err;
 
+	/*
+	 * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +25 -2
+	 * Switch procedure. SPI mode doesn't support CMD11.
+	 */
+	if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+		err = mmc_start_voltage_switch(host);
+		if (err)
+			return err;
+	}
+
 	if (mmc_host_is_spi(host))
 		err = mmc_send_cid(host, cid);
 	else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
 	}
 
 	/*
+	 * If the host supports one of UHS-I modes, request the card
+	 * to switch to 1.8V signaling level.
+	 */
+	if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+	    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+		host->ocr |= (1 << 24);
+
+	/*
 	 * Detect and init the card.
 	 */
 	err = mmc_sd_init_card(host, host->ocr, NULL);
-	if (err)
-		goto err;
+	if (err == -EAGAIN) {
+		/*
+		 * Retry initialization with S18R set to 0.
+		 */
+		host->ocr &= ~(1 << 24);
+		err = mmc_sd_init_card(host, host->ocr, NULL);
+		if (err)
+			goto err;
+	}
 
 	mmc_release_host(host);
 	err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +9 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,
 int width)
 	return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+	struct mmc_command cmd;
+	int err;
+
+	BUG_ON(!host);
+
+	/*
+	 * If the host does not provide signal voltage switch procedure,

we

drivers/mmc/core/sd_ops.c +23 -0
+	 * set S18R to 0, and then retry initialization sequence.
+	 */
+	if (!host->ops->start_signal_voltage_switch)
+		return -EAGAIN;
+
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
+	cmd.opcode = SD_SWITCH_VOLTAGE;
+	cmd.arg = 0;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+	err = mmc_wait_for_cmd(host, &cmd, 0);
+	if (err)
+		return err;
+
+	if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+		return -EIO;
+
+	err = host->ops->start_signal_voltage_switch(host);
+
+	return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
 	struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
drivers/mmc/host/sdhci.c +2 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
 	printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
 		sdhci_readw(host, SDHCI_COMMAND),
 		sdhci_readl(host, SDHCI_MAX_CURRENT));
+	printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+		sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
 	if (host->flags & SDHCI_USE_ADMA)

printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA
Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +48 -0
@@ -1337,11 +1339,70 @@ out:
 	spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+	struct sdhci_host *host;
+	u8 pwr;
+	u16 clk, ctrl;
+	u32 present_state;
+
+	host = mmc_priv(mmc);
+
+	/* Stop SDCLK */
+	host = mmc_priv(mmc);
+	clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	clk &= ~SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+	/* Check whether DAT[3:0] is 0000 */
+	present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+		/* Enable 1.8V Signal Enable in the Host Control2 register
 */
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		ctrl |= SDHCI_CTRL_VDD_180;
+		sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+		/* Wait for 5ms */
+		usleep_range(5000, 5500);
+
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		if (ctrl & SDHCI_CTRL_VDD_180) {
+			/* Provide SDCLK again and wait for 1ms*/
+			clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+			clk |= SDHCI_CLOCK_CARD_EN;
+			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+			usleep_range(1000, 1500);
+
+			/*
+			 * If DAT[3:0] level is 1111b, then the card was
+			 * successfully switched to 1.8V signaling.
+			 */
+			present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+			if ((present_state & SDHCI_DATA_LVL_MASK) ==
+			     SDHCI_DATA_LVL_MASK) {
+				return 0;
+			}
+		}
+	}
+
+	/*
+	 * If we are here, that means the switch to 1.8V signaling

failed. Stop

drivers/mmc/host/sdhci.c +1 -0
+	 * power to the card, and retry initialization sequence by

setting S18R

drivers/mmc/host/sdhci.c +10 -0
+	 * to 0.
+	 */
+	pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+	pwr &= ~SDHCI_POWER_ON;
+	sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+	return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
 	.request	= sdhci_request,
 	.set_ios	= sdhci_set_ios,
 	.get_ro		= sdhci_get_ro,
 	.enable_sdio_irq = sdhci_enable_sdio_irq,
+	.start_signal_voltage_switch	=

sdhci_start_signal_voltage_switch,
};

/********************************************************************** *******\

drivers/mmc/host/sdhci.c +4 -2
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;
-	unsigned int caps, ocr_avail;
+	u32 caps[2];
+	u32 max_current_caps;
+	unsigned int ocr_avail;
 	int ret;
 
 	WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
 			host->version);
 	}
 
-	caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+	caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

drivers/mmc/host/sdhci.c +6 -2
 		sdhci_readl(host, SDHCI_CAPABILITIES);
 
+	if (host->version >= SDHCI_SPEC_300)
+		caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
 	if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
 		host->flags |= SDHCI_USE_SDMA;
-	else if (!(caps & SDHCI_CAN_DO_SDMA))
+	else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
 		DBG("Controller doesn't have SDMA capability\n");
 	else
 		host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_SDMA;
 	}
 
-	if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+	if ((host->version >= SDHCI_SPEC_200) &&
+		(caps[0] & SDHCI_CAN_DO_ADMA2))
 		host->flags |= SDHCI_USE_ADMA;
 
drivers/mmc/host/sdhci.c +3 -3
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	if (host->version >= SDHCI_SPEC_300)
-		host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 	else
-		host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 
 	host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	host->timeout_clk =
-		(caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+		(caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
 	if (host->timeout_clk == 0) {
 		if (host->ops->get_timeout_clock) {

host->timeout_clk = host->ops-

Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +18 -3
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
 			return -ENODEV;
 		}
 	}
-	if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+	if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
 		host->timeout_clk *= 1000;
 
 	/*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
 		mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-	if (caps & SDHCI_CAN_DO_HISPD)
+	if (caps[0] & SDHCI_CAN_DO_HISPD)
 		mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
 	    mmc_card_is_removable(mmc))
 		mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+	/* UHS-I mode(s) supported by the host controller. */
+	if (host->version >= SDHCI_SPEC_300)
+		mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+	/* SDR104 supports also implies SDR50 support */
+	if (caps[1] & SDHCI_SUPPORT_SDR104)
+		mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+	else if (caps[1] & SDHCI_SUPPORT_SDR50)
+		mmc->caps |= MMC_CAP_UHS_SDR50;
+
+	if (caps[1] & SDHCI_SUPPORT_DDR50)
+		mmc->caps |= MMC_CAP_UHS_DDR50;
+
 	ocr_avail = 0;
-	if (caps & SDHCI_CAN_VDD_330)
+	/*
+	 * According to SD Host Controller spec v3.00, if the Host System
+	 * can afford more than 150mA, Host Driver should set XPC to 1.

Also

drivers/mmc/host/sdhci.c +1 -0
+	 * the value is meaningful only if Voltage Support in the

Capabilities

drivers/mmc/host/sdhci.c +1 -0
+	 * register is set. The actual current value is 4 times the

register

drivers/mmc/host/sdhci.c +41 -3
+	 * value.
+	 */
+	max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+	if (caps[0] & SDHCI_CAN_VDD_330) {
+		int max_current_330;
+
 		ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-	if (caps & SDHCI_CAN_VDD_300)
+
+		max_current_330 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_330_MASK) >>
+				   SDHCI_MAX_CURRENT_330_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_330 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_330;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_300) {
+		int max_current_300;
+
 		ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-	if (caps & SDHCI_CAN_VDD_180)
+
+		max_current_300 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_300_MASK) >>
+				   SDHCI_MAX_CURRENT_300_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_300 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_300;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_180) {
+		int max_current_180;
+
 		ocr_avail |= MMC_VDD_165_195;
 
+		max_current_180 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_180_MASK) >>
+				   SDHCI_MAX_CURRENT_180_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_180 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_180;
+	}
+
 	mmc->ocr_avail = ocr_avail;
 	mmc->ocr_avail_sdio = ocr_avail;
 	if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
 		mmc->max_blk_size = 2;
 	} else {
-		mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+		mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
 				SDHCI_MAX_BLOCK_SHIFT;
 		if (mmc->max_blk_size >= 3) {
 			printk(KERN_WARNING "%s: Invalid maximum block size,

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE	0x00000800
 #define  SDHCI_CARD_PRESENT	0x00010000
 #define  SDHCI_WRITE_PROTECT	0x00080000
+#define  SDHCI_DATA_LVL_MASK	0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT	20
 
 #define SDHCI_HOST_CONTROL 	0x28
 #define  SDHCI_CTRL_LED		0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR	0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2		0x3E
+#define  SDHCI_CTRL_VDD_180		0x0008
 
 #define SDHCI_CAPABILITIES	0x40
 #define  SDHCI_TIMEOUT_CLK_MASK	0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180	0x04000000
 #define  SDHCI_CAN_64BIT	0x10000000
 
+#define  SDHCI_SUPPORT_SDR50	0x00000001
+#define  SDHCI_SUPPORT_SDR104	0x00000002
+#define  SDHCI_SUPPORT_DDR50	0x00000004
+
 #define SDHCI_CAPABILITIES_1	0x44
 
-#define SDHCI_MAX_CURRENT	0x48
+#define SDHCI_MAX_CURRENT		0x48
+#define  SDHCI_MAX_CURRENT_330_MASK	0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT	0
+#define  SDHCI_MAX_CURRENT_300_MASK	0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT	8
+#define  SDHCI_MAX_CURRENT_180_MASK	0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT	16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER	4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +2 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
 	/* optional callback for HC quirks */
 	void	(*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+	int	(*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 2 lines
include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
 						/* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD	(1 << 13)	/* Can power off

after

Quoted 45 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus
width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS SDR12
mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS SDR25
mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50
mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104
mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50
mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA
current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA
current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA
current at 1.8V */

include/linux/mmc/host.h +0 -0
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
include/linux/mmc/sd.h +1 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks. */
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below R1
*/
--
1.7.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

#12 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 125 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of [email protected]
Sent: Wednesday, March 09, 2011 4:15 PM
To: 'Arindam Nath'; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

+1. Looks good to me from sd3.0 spec. prospective.

Quoted 110 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
 	int err;
+	u32 rocr;
 
 	/*
 	 * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
 	if (!err)
 		ocr |= 1 << 30;
 
-	err = mmc_send_app_op_cond(host, ocr, NULL);
+	/* If the host can supply more than 150mA, XPC should be set to

1. */

drivers/mmc/core/sd.c +7 -0
+	if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+	    MMC_CAP_SET_XPC_180))
+		ocr |= 1 << 28;
+
+	err = mmc_send_app_op_cond(host, ocr, &rocr);
 	if (err)
 		return err;
 
+	/*
+	 * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +17 -2
+	 * Switch procedure. SPI mode doesn't support CMD11.
+	 */
+	if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+		err = mmc_start_voltage_switch(host);
+		if (err)
+			return err;
+	}
+
 	if (mmc_host_is_spi(host))
 		err = mmc_send_cid(host, cid);
 	else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
 	}
 
 	/*
+	 * If the host supports one of UHS-I modes, request the card
+	 * to switch to 1.8V signaling level.
+	 */
+	if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+	    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+		host->ocr |= (1 << 24);
+
+	/*
 	 * Detect and init the card.
 	 */
 	err = mmc_sd_init_card(host, host->ocr, NULL);
-	if (err)
-		goto err;
+	if (err == -EAGAIN) {
Quoted 8 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 865

Quoted 8 lines
drivers/mmc/core/sd.c +8 -0
+		/*
+		 * Retry initialization with S18R set to 0.
+		 */
+		host->ocr &= ~(1 << 24);
+		err = mmc_sd_init_card(host, host->ocr, NULL);
+		if (err)
+			goto err;
+	}

Just a thought. Shouldn't we do setting of this b24 bit of OCR in mmc_sd_get_cid() function itself and if mmc_send_app_op_cond() returns error then reset b24 bit and retry mmc_send_app_op_cond() command.

Quoted 441 lines
Quoted 149 lines
drivers/mmc/core/sd.c +0 -0
 	mmc_release_host(host);
 	err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +9 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,
 int width)
 	return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+	struct mmc_command cmd;
+	int err;
+
+	BUG_ON(!host);
+
+	/*
+	 * If the host does not provide signal voltage switch procedure,

we

drivers/mmc/core/sd_ops.c +23 -0
+	 * set S18R to 0, and then retry initialization sequence.
+	 */
+	if (!host->ops->start_signal_voltage_switch)
+		return -EAGAIN;
+
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
+	cmd.opcode = SD_SWITCH_VOLTAGE;
+	cmd.arg = 0;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+	err = mmc_wait_for_cmd(host, &cmd, 0);
+	if (err)
+		return err;
+
+	if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+		return -EIO;
+
+	err = host->ops->start_signal_voltage_switch(host);
+
+	return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
 	struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
drivers/mmc/host/sdhci.c +2 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
 	printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
 		sdhci_readw(host, SDHCI_COMMAND),
 		sdhci_readl(host, SDHCI_MAX_CURRENT));
+	printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+		sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
 	if (host->flags & SDHCI_USE_ADMA)

printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA
Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +48 -0
@@ -1337,11 +1339,70 @@ out:
 	spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+	struct sdhci_host *host;
+	u8 pwr;
+	u16 clk, ctrl;
+	u32 present_state;
+
+	host = mmc_priv(mmc);
+
+	/* Stop SDCLK */
+	host = mmc_priv(mmc);
+	clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	clk &= ~SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+	/* Check whether DAT[3:0] is 0000 */
+	present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+		/* Enable 1.8V Signal Enable in the Host Control2 register
 */
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		ctrl |= SDHCI_CTRL_VDD_180;
+		sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+		/* Wait for 5ms */
+		usleep_range(5000, 5500);
+
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		if (ctrl & SDHCI_CTRL_VDD_180) {
+			/* Provide SDCLK again and wait for 1ms*/
+			clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+			clk |= SDHCI_CLOCK_CARD_EN;
+			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+			usleep_range(1000, 1500);
+
+			/*
+			 * If DAT[3:0] level is 1111b, then the card was
+			 * successfully switched to 1.8V signaling.
+			 */
+			present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+			if ((present_state & SDHCI_DATA_LVL_MASK) ==
+			     SDHCI_DATA_LVL_MASK) {
+				return 0;
+			}
+		}
+	}
+
+	/*
+	 * If we are here, that means the switch to 1.8V signaling

failed. Stop

drivers/mmc/host/sdhci.c +1 -0
+	 * power to the card, and retry initialization sequence by

setting S18R

drivers/mmc/host/sdhci.c +10 -0
+	 * to 0.
+	 */
+	pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+	pwr &= ~SDHCI_POWER_ON;
+	sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+	return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
 	.request	= sdhci_request,
 	.set_ios	= sdhci_set_ios,
 	.get_ro		= sdhci_get_ro,
 	.enable_sdio_irq = sdhci_enable_sdio_irq,
+	.start_signal_voltage_switch	=
Quoted 5 lines

sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 228 lines

*******\

drivers/mmc/host/sdhci.c +4 -2
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;
-	unsigned int caps, ocr_avail;
+	u32 caps[2];
+	u32 max_current_caps;
+	unsigned int ocr_avail;
 	int ret;
 
 	WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
 			host->version);
 	}
 
-	caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+	caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

drivers/mmc/host/sdhci.c +6 -2
 		sdhci_readl(host, SDHCI_CAPABILITIES);
 
+	if (host->version >= SDHCI_SPEC_300)
+		caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
 	if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
 		host->flags |= SDHCI_USE_SDMA;
-	else if (!(caps & SDHCI_CAN_DO_SDMA))
+	else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
 		DBG("Controller doesn't have SDMA capability\n");
 	else
 		host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_SDMA;
 	}
 
-	if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+	if ((host->version >= SDHCI_SPEC_200) &&
+		(caps[0] & SDHCI_CAN_DO_ADMA2))
 		host->flags |= SDHCI_USE_ADMA;
 
drivers/mmc/host/sdhci.c +3 -3
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	if (host->version >= SDHCI_SPEC_300)
-		host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 	else
-		host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 
 	host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	host->timeout_clk =
-		(caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+		(caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
 	if (host->timeout_clk == 0) {
 		if (host->ops->get_timeout_clock) {

host->timeout_clk = host->ops-

Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +18 -3
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
 			return -ENODEV;
 		}
 	}
-	if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+	if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
 		host->timeout_clk *= 1000;
 
 	/*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
 		mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-	if (caps & SDHCI_CAN_DO_HISPD)
+	if (caps[0] & SDHCI_CAN_DO_HISPD)
 		mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
 	    mmc_card_is_removable(mmc))
 		mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+	/* UHS-I mode(s) supported by the host controller. */
+	if (host->version >= SDHCI_SPEC_300)
+		mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+	/* SDR104 supports also implies SDR50 support */
+	if (caps[1] & SDHCI_SUPPORT_SDR104)
+		mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+	else if (caps[1] & SDHCI_SUPPORT_SDR50)
+		mmc->caps |= MMC_CAP_UHS_SDR50;
+
+	if (caps[1] & SDHCI_SUPPORT_DDR50)
+		mmc->caps |= MMC_CAP_UHS_DDR50;
+
 	ocr_avail = 0;
-	if (caps & SDHCI_CAN_VDD_330)
+	/*
+	 * According to SD Host Controller spec v3.00, if the Host System
+	 * can afford more than 150mA, Host Driver should set XPC to 1.

Also

drivers/mmc/host/sdhci.c +1 -0
+	 * the value is meaningful only if Voltage Support in the

Capabilities

drivers/mmc/host/sdhci.c +1 -0
+	 * register is set. The actual current value is 4 times the

register

drivers/mmc/host/sdhci.c +41 -3
+	 * value.
+	 */
+	max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+	if (caps[0] & SDHCI_CAN_VDD_330) {
+		int max_current_330;
+
 		ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-	if (caps & SDHCI_CAN_VDD_300)
+
+		max_current_330 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_330_MASK) >>
+				   SDHCI_MAX_CURRENT_330_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_330 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_330;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_300) {
+		int max_current_300;
+
 		ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-	if (caps & SDHCI_CAN_VDD_180)
+
+		max_current_300 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_300_MASK) >>
+				   SDHCI_MAX_CURRENT_300_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_300 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_300;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_180) {
+		int max_current_180;
+
 		ocr_avail |= MMC_VDD_165_195;
 
+		max_current_180 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_180_MASK) >>
+				   SDHCI_MAX_CURRENT_180_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_180 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_180;
+	}
+
 	mmc->ocr_avail = ocr_avail;
 	mmc->ocr_avail_sdio = ocr_avail;
 	if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
 		mmc->max_blk_size = 2;
 	} else {
-		mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+		mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
 				SDHCI_MAX_BLOCK_SHIFT;
 		if (mmc->max_blk_size >= 3) {
 			printk(KERN_WARNING "%s: Invalid maximum block size,

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE	0x00000800
 #define  SDHCI_CARD_PRESENT	0x00010000
 #define  SDHCI_WRITE_PROTECT	0x00080000
+#define  SDHCI_DATA_LVL_MASK	0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT	20
 
 #define SDHCI_HOST_CONTROL 	0x28
 #define  SDHCI_CTRL_LED		0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR	0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2		0x3E
+#define  SDHCI_CTRL_VDD_180		0x0008
 
 #define SDHCI_CAPABILITIES	0x40
 #define  SDHCI_TIMEOUT_CLK_MASK	0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180	0x04000000
 #define  SDHCI_CAN_64BIT	0x10000000
 
+#define  SDHCI_SUPPORT_SDR50	0x00000001
+#define  SDHCI_SUPPORT_SDR104	0x00000002
+#define  SDHCI_SUPPORT_DDR50	0x00000004
+
 #define SDHCI_CAPABILITIES_1	0x44
 
-#define SDHCI_MAX_CURRENT	0x48
+#define SDHCI_MAX_CURRENT		0x48
+#define  SDHCI_MAX_CURRENT_330_MASK	0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT	0
+#define  SDHCI_MAX_CURRENT_300_MASK	0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT	8
+#define  SDHCI_MAX_CURRENT_180_MASK	0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT	16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER	4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +2 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
 	/* optional callback for HC quirks */
 	void	(*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+	int	(*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 2 lines
include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
 						/* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD	(1 << 13)	/* Can power off

after

Quoted 6 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus
width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS SDR12
mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS SDR25

Quoted 8 lines

mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50
mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104
mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50
mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports

150mA

Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports

150mA

Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports

150mA

include/linux/mmc/sd.h line 17

Quoted 10 lines

current at 1.8V */

include/linux/mmc/host.h +0 -0
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks.

*/

Quoted 7 lines
include/linux/mmc/sd.h +1 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1
 */
Quoted 8 lines
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below R1
*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc"

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
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

#13 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 140 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Thursday, March 10, 2011 12:00 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of [email protected]
Sent: Wednesday, March 09, 2011 4:15 PM
To: 'Arindam Nath'; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 9 lines

+1. Looks good to me from sd3.0 spec. prospective.

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 108 lines
Quoted 108 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
  int err;
+ u32 rocr;
 
  /*
   * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
  if (!err)
          ocr |= 1 << 30;
 
- err = mmc_send_app_op_cond(host, ocr, NULL);
+ /* If the host can supply more than 150mA, XPC should be set to

1. */
+ if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |

drivers/mmc/core/sd.c +6 -0
+     MMC_CAP_SET_XPC_180))
+         ocr |= 1 << 28;
+
+ err = mmc_send_app_op_cond(host, ocr, &rocr);
  if (err)
          return err;
 
+ /*
+  * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +22 -2
+  * Switch procedure. SPI mode doesn't support CMD11.
+  */
+ if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+         err = mmc_start_voltage_switch(host);
+         if (err)
+                 return err;
+ }
+
  if (mmc_host_is_spi(host))
          err = mmc_send_cid(host, cid);
  else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
  }
 
  /*
+  * If the host supports one of UHS-I modes, request the card
+  * to switch to 1.8V signaling level.
+  */
+ if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+     MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+         host->ocr |= (1 << 24);
+
+ /*
   * Detect and init the card.
   */
  err = mmc_sd_init_card(host, host->ocr, NULL);
- if (err)
-         goto err;
+ if (err == -EAGAIN) {
+         /*
+          * Retry initialization with S18R set to 0.
+          */
+         host->ocr &= ~(1 << 24);
+         err = mmc_sd_init_card(host, host->ocr, NULL);
Quoted 8 lines
Quoted 3 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 865

Quoted 3 lines
drivers/mmc/core/sd.c +3 -0
+         if (err)
+                 goto err;
+ }

Just a thought. Shouldn't we do setting of this b24 bit of OCR in mmc_sd_get_cid() function itself and if mmc_send_app_op_cond() returns error
then reset b24 bit and retry mmc_send_app_op_cond() command.

This makes sense as per the spec. I will change it.

Thanks,
Arindam

Quoted 459 lines
Quoted 10 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card

Quoted 10 lines
drivers/mmc/core/sd.c +0 -0
  mmc_release_host(host);
  err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +0 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card

*card,

Quoted 30 lines
Quoted 30 lines
drivers/mmc/core/sd_ops.c +9 -0
 int width)
  return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+ struct mmc_command cmd;
+ int err;
+
+ BUG_ON(!host);
+
+ /*
+  * If the host does not provide signal voltage switch procedure,

we

drivers/mmc/core/sd_ops.c +16 -0
+  * set S18R to 0, and then retry initialization sequence.
+  */
+ if (!host->ops->start_signal_voltage_switch)
+         return -EAGAIN;
+
+ memset(&cmd, 0, sizeof(struct mmc_command));
+
+ cmd.opcode = SD_SWITCH_VOLTAGE;
+ cmd.arg = 0;
+ cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+ err = mmc_wait_for_cmd(host, &cmd, 0);
+ if (err)
+         return err;
+
+ if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 8 lines
drivers/mmc/core/sd_ops.c +7 -0
+         return -EIO;
+
+ err = host->ops->start_signal_voltage_switch(host);
+
+ return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32

*rocr)

Quoted 13 lines
Quoted 13 lines

{
struct mmc_command cmd;

drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
  u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
Quoted 7 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host

Quoted 7 lines
drivers/mmc/core/sd_ops.h +0 -0
 #endif
drivers/mmc/host/sdhci.c +0 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host

*host)

Quoted 80 lines
Quoted 80 lines
drivers/mmc/host/sdhci.c +2 -0
  printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
          sdhci_readw(host, SDHCI_COMMAND),
          sdhci_readl(host, SDHCI_MAX_CURRENT));
+ printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+         sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
  if (host->flags & SDHCI_USE_ADMA)
          printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +48 -0
@@ -1337,11 +1339,70 @@ out:
  spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+ struct sdhci_host *host;
+ u8 pwr;
+ u16 clk, ctrl;
+ u32 present_state;
+
+ host = mmc_priv(mmc);
+
+ /* Stop SDCLK */
+ host = mmc_priv(mmc);
+ clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+ clk &= ~SDHCI_CLOCK_CARD_EN;
+ sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+ /* Check whether DAT[3:0] is 0000 */
+ present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+ if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+         /* Enable 1.8V Signal Enable in the Host Control2 register
 */
+         ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+         ctrl |= SDHCI_CTRL_VDD_180;
+         sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+         /* Wait for 5ms */
+         usleep_range(5000, 5500);
+
+         ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+         if (ctrl & SDHCI_CTRL_VDD_180) {
+                 /* Provide SDCLK again and wait for 1ms*/
+                 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                 clk |= SDHCI_CLOCK_CARD_EN;
+                 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                 usleep_range(1000, 1500);
+
+                 /*
+                  * If DAT[3:0] level is 1111b, then the card was
+                  * successfully switched to 1.8V signaling.
+                  */
+                 present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                 if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                      SDHCI_DATA_LVL_MASK) {
+                         return 0;
+                 }
+         }
+ }
+
+ /*
+  * If we are here, that means the switch to 1.8V signaling

failed. Stop
+ * power to the card, and retry initialization sequence by setting S18R

drivers/mmc/host/sdhci.c +9 -0
+  * to 0.
+  */
+ pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+ pwr &= ~SDHCI_POWER_ON;
+ sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+ return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
  .request        = sdhci_request,
  .set_ios        = sdhci_set_ios,
Quoted 9 lines
Quoted 8 lines

.get_ro = sdhci_get_ro,
.enable_sdio_irq = sdhci_enable_sdio_irq,
+ .start_signal_voltage_switch =
sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 226 lines
Quoted 226 lines

*******\

drivers/mmc/host/sdhci.c +4 -2
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
  struct mmc_host *mmc;
- unsigned int caps, ocr_avail;
+ u32 caps[2];
+ u32 max_current_caps;
+ unsigned int ocr_avail;
  int ret;
 
  WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                  host->version);
  }
 
- caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+ caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

          sdhci_readl(host, SDHCI_CAPABILITIES);

+ if (host->version >= SDHCI_SPEC_300)

drivers/mmc/host/sdhci.c +5 -2
+         caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
  if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
          host->flags |= SDHCI_USE_SDMA;
- else if (!(caps & SDHCI_CAN_DO_SDMA))
+ else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
          DBG("Controller doesn't have SDMA capability\n");
  else
          host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
          host->flags &= ~SDHCI_USE_SDMA;
  }
 
- if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+ if ((host->version >= SDHCI_SPEC_200) &&
+         (caps[0] & SDHCI_CAN_DO_ADMA2))
          host->flags |= SDHCI_USE_ADMA;
 

if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&

drivers/mmc/host/sdhci.c +3 -3
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
  }
 
  if (host->version >= SDHCI_SPEC_300)
-         host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+         host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                  >> SDHCI_CLOCK_BASE_SHIFT;
  else
-         host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+         host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                  >> SDHCI_CLOCK_BASE_SHIFT;
 
  host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
  }
 
  host->timeout_clk =
-         (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+         (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
  if (host->timeout_clk == 0) {
          if (host->ops->get_timeout_clock) {
                  host->timeout_clk = host->ops-
Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +18 -3
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                  return -ENODEV;
          }
  }
- if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+ if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
          host->timeout_clk *= 1000;
 
  /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
  if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
          mmc->caps |= MMC_CAP_4_BIT_DATA;
 
- if (caps & SDHCI_CAN_DO_HISPD)
+ if (caps[0] & SDHCI_CAN_DO_HISPD)
          mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
  if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
      mmc_card_is_removable(mmc))
          mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+ /* UHS-I mode(s) supported by the host controller. */
+ if (host->version >= SDHCI_SPEC_300)
+         mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+ /* SDR104 supports also implies SDR50 support */
+ if (caps[1] & SDHCI_SUPPORT_SDR104)
+         mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+ else if (caps[1] & SDHCI_SUPPORT_SDR50)
+         mmc->caps |= MMC_CAP_UHS_SDR50;
+
+ if (caps[1] & SDHCI_SUPPORT_DDR50)
+         mmc->caps |= MMC_CAP_UHS_DDR50;
+
  ocr_avail = 0;
- if (caps & SDHCI_CAN_VDD_330)
+ /*
+  * According to SD Host Controller spec v3.00, if the Host System
+  * can afford more than 150mA, Host Driver should set XPC to 1.

Also
+ * the value is meaningful only if Voltage Support in the Capabilities
+ * register is set. The actual current value is 4 times the register

drivers/mmc/host/sdhci.c +41 -3
+  * value.
+  */
+ max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+ if (caps[0] & SDHCI_CAN_VDD_330) {
+         int max_current_330;
+
          ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
- if (caps & SDHCI_CAN_VDD_300)
+
+         max_current_330 = ((max_current_caps &
+                            SDHCI_MAX_CURRENT_330_MASK) >>
+                            SDHCI_MAX_CURRENT_330_SHIFT) *
+                            SDHCI_MAX_CURRENT_MULTIPLIER;
+
+         if (max_current_330 > 150)
+                 mmc->caps |= MMC_CAP_SET_XPC_330;
+ }
+ if (caps[0] & SDHCI_CAN_VDD_300) {
+         int max_current_300;
+
          ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
- if (caps & SDHCI_CAN_VDD_180)
+
+         max_current_300 = ((max_current_caps &
+                            SDHCI_MAX_CURRENT_300_MASK) >>
+                            SDHCI_MAX_CURRENT_300_SHIFT) *
+                            SDHCI_MAX_CURRENT_MULTIPLIER;
+
+         if (max_current_300 > 150)
+                 mmc->caps |= MMC_CAP_SET_XPC_300;
+ }
+ if (caps[0] & SDHCI_CAN_VDD_180) {
+         int max_current_180;
+
          ocr_avail |= MMC_VDD_165_195;
 
+         max_current_180 = ((max_current_caps &
+                            SDHCI_MAX_CURRENT_180_MASK) >>
+                            SDHCI_MAX_CURRENT_180_SHIFT) *
+                            SDHCI_MAX_CURRENT_MULTIPLIER;
+
+         if (max_current_180 > 150)
+                 mmc->caps |= MMC_CAP_SET_XPC_180;
+ }
+
  mmc->ocr_avail = ocr_avail;
  mmc->ocr_avail_sdio = ocr_avail;
  if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
  if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
          mmc->max_blk_size = 2;
  } else {
-         mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+         mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                          SDHCI_MAX_BLOCK_SHIFT;
          if (mmc->max_blk_size >= 3) {
                  printk(KERN_WARNING "%s: Invalid maximum block size,

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE    0x00000800
 #define  SDHCI_CARD_PRESENT      0x00010000
 #define  SDHCI_WRITE_PROTECT     0x00080000
+#define  SDHCI_DATA_LVL_MASK     0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT   20
 
 #define SDHCI_HOST_CONTROL       0x28
 #define  SDHCI_CTRL_LED          0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR 0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2              0x3E
+#define  SDHCI_CTRL_VDD_180              0x0008
 
 #define SDHCI_CAPABILITIES       0x40
 #define  SDHCI_TIMEOUT_CLK_MASK  0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180       0x04000000
 #define  SDHCI_CAN_64BIT 0x10000000
 
+#define  SDHCI_SUPPORT_SDR50     0x00000001
+#define  SDHCI_SUPPORT_SDR104    0x00000002
+#define  SDHCI_SUPPORT_DDR50     0x00000004
+
 #define SDHCI_CAPABILITIES_1     0x44
 
-#define SDHCI_MAX_CURRENT        0x48
+#define SDHCI_MAX_CURRENT                0x48
+#define  SDHCI_MAX_CURRENT_330_MASK      0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT     0
+#define  SDHCI_MAX_CURRENT_300_MASK      0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT     8
+#define  SDHCI_MAX_CURRENT_180_MASK      0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT     16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER   4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +2 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
  /* optional callback for HC quirks */
  void    (*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+ int     (*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
Quoted 9 lines

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 4 lines
include/linux/mmc/host.h +0 -0
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                          /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD   (1 << 13)       /* Can power off

after

Quoted 4 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus
width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS

DDR50

Quoted 13 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports

150mA

Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports

150mA

Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports

150mA

Quoted 4 lines

current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm features */

Quoted 8 lines

include/linux/mmc/sd.h line 17

Quoted 6 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks.

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines

include/linux/mmc/sd.h line 20

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 6 lines

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc"

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

In reply to Arindam Nath
Quoted 27 lines · Arindam Nath

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

Quoted 1 line

The patch can not work with generic card :(

Quoted 15 lines

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +

 drivers/mmc/host/sdhci.c  |  148 +++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +0 -0
index b3f8a3c..3e82599 100644

drivers/mmc/core/sd.c struct device_type sd_type = { · line 411

Quoted 4 lines
drivers/mmc/core/sd.c +1 -0
@@ -408,6 +408,7 @@ struct device_type sd_type = {
  int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
  {
        int err;
+       u32 rocr;

rocr not initialized here, or move to mmc_sd_init_card in following patch, it may be risky, since dependency.

Quoted 12 lines
drivers/mmc/core/sd.c +4 -1
        /*
         * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
        if (!err)
                ocr |= 1 << 30;
 
-       err = mmc_send_app_op_cond(host, ocr, NULL);
+       /* If the host can supply more than 150mA, XPC should be set to 1. */
+       if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+           MMC_CAP_SET_XPC_180))
+               ocr |= 1 << 28;

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) · line 444

Quoted 10 lines
drivers/mmc/core/sd.c +7 -0
+
+       err = mmc_send_app_op_cond(host, ocr, &rocr);
        if (err)
                return err;
 
+       /*
+        * In case CCS and S18A in the response is set, start Signal Voltage
+        * Switch procedure. SPI mode doesn't support CMD11.
+        */
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {

if (!mmc_host_is_spi(host) && (rocr & 0x41000000 == 0x41000000))
Currently your patch can not work with general card, for example rocr=0xc0ff8000 & 0x41000000 = 0x40000000, while what you want is both two bit are set.

Quoted 16 lines
drivers/mmc/core/sd.c +5 -0
+               err = mmc_start_voltage_switch(host);
+               if (err)
+                       return err;
+       }
+
        if (mmc_host_is_spi(host))
                err = mmc_send_cid(host, cid);

       else

drivers/mmc/core/sd.c +4 -0
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
        }
 
        /*
+        * If the host supports one of UHS-I modes, request the card
+        * to switch to 1.8V signaling level.
+        */
+       if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 857

Quoted 10 lines
drivers/mmc/core/sd.c +5 -2
+           MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+               host->ocr |= (1 << 24);
+
+       /*
         * Detect and init the card.
         */
        err = mmc_sd_init_card(host, host->ocr, NULL);
-       if (err)
-               goto err;
+       if (err == -EAGAIN) {

If other error happen, for example -ETIMEDOUT in current patch for general card, the following card can not be executed. kernel panic will happen in mmc_add_card for null pinter, since card is not allocated.
how about if (err) for safety?

Quoted 399 lines
drivers/mmc/core/sd.c +8 -0
+               /*
+                * Retry initialization with S18R set to 0.
+                */
+               host->ocr &= ~(1 << 24);
+               err = mmc_sd_init_card(host, host->ocr, NULL);
+               if (err)
+                       goto err;
+       }
 
        mmc_release_host(host);
        err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +32 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
        return 0;
  }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+       struct mmc_command cmd;
+       int err;
+
+       BUG_ON(!host);
+
+       /*
+        * If the host does not provide signal voltage switch procedure, we
+        * set S18R to 0, and then retry initialization sequence.
+        */
+       if (!host->ops->start_signal_voltage_switch)
+               return -EAGAIN;
+
+       memset(&cmd, 0, sizeof(struct mmc_command));
+
+       cmd.opcode = SD_SWITCH_VOLTAGE;
+       cmd.arg = 0;
+       cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+       err = mmc_wait_for_cmd(host, &cmd, 0);
+       if (err)
+               return err;
+
+       if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+               return -EIO;
+
+       err = host->ops->start_signal_voltage_switch(host);
+
+       return err;
+}
+
  int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
  {
        struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
  int mmc_sd_switch(struct mmc_card *card, int mode, int group,
        u8 value, u8 *resp);
  int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
  #endif
 
drivers/mmc/host/sdhci.c +69 -3
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
        printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr: 0x%08x\n",
                sdhci_readw(host, SDHCI_COMMAND),
                sdhci_readl(host, SDHCI_MAX_CURRENT));
+       printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+               sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
        if (host->flags & SDHCI_USE_ADMA)
                printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
@@ -1337,11 +1339,70 @@ out:
        spin_unlock_irqrestore(&host->lock, flags);
  }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+       struct sdhci_host *host;
+       u8 pwr;
+       u16 clk, ctrl;
+       u32 present_state;
+
+       host = mmc_priv(mmc);
+
+       /* Stop SDCLK */
+       host = mmc_priv(mmc);
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       clk &= ~SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       /* Check whether DAT[3:0] is 0000 */
+       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+       if (!((present_state & SDHCI_DATA_LVL_MASK) >> SDHCI_DATA_LVL_SHIFT)) {
+               /* Enable 1.8V Signal Enable in the Host Control2 register */
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               ctrl |= SDHCI_CTRL_VDD_180;
+               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+               /* Wait for 5ms */
+               usleep_range(5000, 5500);
+
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               if (ctrl & SDHCI_CTRL_VDD_180) {
+                       /* Provide SDCLK again and wait for 1ms*/
+                       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                       clk |= SDHCI_CLOCK_CARD_EN;
+                       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                       usleep_range(1000, 1500);
+
+                       /*
+                        * If DAT[3:0] level is 1111b, then the card was
+                        * successfully switched to 1.8V signaling.
+                        */
+                       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+                       if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                            SDHCI_DATA_LVL_MASK) {
+                               return 0;
+                       }
+               }
+       }
+
+       /*
+        * If we are here, that means the switch to 1.8V signaling failed. Stop
+        * power to the card, and retry initialization sequence by setting S18R
+        * to 0.
+        */
+       pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+       pwr &= ~SDHCI_POWER_ON;
+       sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+       return -EAGAIN;
+}
+
  static const struct mmc_host_ops sdhci_ops = {
        .request        = sdhci_request,
        .set_ios        = sdhci_set_ios,
        .get_ro         = sdhci_get_ro,
        .enable_sdio_irq = sdhci_enable_sdio_irq,
+       .start_signal_voltage_switch    = sdhci_start_signal_voltage_switch,
  };
 
  /*****************************************************************************\
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
  int sdhci_add_host(struct sdhci_host *host)
  {
        struct mmc_host *mmc;
-       unsigned int caps, ocr_avail;
+       u32 caps[2];
+       u32 max_current_caps;
+       unsigned int ocr_avail;
        int ret;
 
        WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                        host->version);
        }
 
-       caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+       caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
                sdhci_readl(host, SDHCI_CAPABILITIES);
 
+       if (host->version >= SDHCI_SPEC_300)
+               caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
        if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
                host->flags |= SDHCI_USE_SDMA;
-       else if (!(caps & SDHCI_CAN_DO_SDMA))
+       else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
                DBG("Controller doesn't have SDMA capability\n");

       else
               host->flags |= SDHCI_USE_SDMA;

drivers/mmc/host/sdhci.c +2 -1
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
                host->flags &= ~SDHCI_USE_SDMA;
        }
 
-       if ((host->version >= SDHCI_SPEC_200) && (caps & SDHCI_CAN_DO_ADMA2))
+       if ((host->version >= SDHCI_SPEC_200) &&
+               (caps[0] & SDHCI_CAN_DO_ADMA2))
                host->flags |= SDHCI_USE_ADMA;
 

       if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&

drivers/mmc/host/sdhci.c +1 -1
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
        }
 
        if (host->version >= SDHCI_SPEC_300)
-               host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                        >> SDHCI_CLOCK_BASE_SHIFT;

       else
-               host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;

       host->max_clk *= 1000000;

drivers/mmc/host/sdhci.c +0 -0
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
        }
 

       host->timeout_clk =
-               (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+               (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT; if (host->timeout_clk == 0) {
               if (host->ops->get_timeout_clock) { host->timeout_clk = host->ops->get_timeout_clock(host);

drivers/mmc/host/sdhci.c +2 -2
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                        return -ENODEV;
                }
        }
-       if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+       if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
                host->timeout_clk *= 1000;
 
        /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
        if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
                mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-       if (caps & SDHCI_CAN_DO_HISPD)
+       if (caps[0] & SDHCI_CAN_DO_HISPD)
                mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 

       if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && mmc_card_is_removable(mmc))
               mmc->caps |= MMC_CAP_NEEDS_POLL;

+       /* UHS-I mode(s) supported by the host controller. */
+       if (host->version >= SDHCI_SPEC_300)
+               mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;

drivers/mmc/host/sdhci.c +10 -0
+
+       /* SDR104 supports also implies SDR50 support */
+       if (caps[1] & SDHCI_SUPPORT_SDR104)
+               mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+       else if (caps[1] & SDHCI_SUPPORT_SDR50)
+               mmc->caps |= MMC_CAP_UHS_SDR50;
+
+       if (caps[1] & SDHCI_SUPPORT_DDR50)
+               mmc->caps |= MMC_CAP_UHS_DDR50;
+

       ocr_avail = 0;
-       if (caps & SDHCI_CAN_VDD_330)
+       /*
+        * According to SD Host Controller spec v3.00, if the Host System
+        * can afford more than 150mA, Host Driver should set XPC to 1. Also
+        * the value is meaningful only if Voltage Support in the Capabilities
+        * register is set. The actual current value is 4 times the register
+        * value.
+        */
+       max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);

drivers/mmc/host/sdhci.c +4 -0
+
+       if (caps[0] & SDHCI_CAN_VDD_330) {
+               int max_current_330;
+

               ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-       if (caps & SDHCI_CAN_VDD_300)

drivers/mmc/host/sdhci.c +12 -0
+
+               max_current_330 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_330_MASK) >>
+                                  SDHCI_MAX_CURRENT_330_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_330 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_330;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_300) {
+               int max_current_300;
+

               ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-       if (caps & SDHCI_CAN_VDD_180)

drivers/mmc/host/sdhci.c +12 -0
+
+               max_current_300 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_300_MASK) >>
+                                  SDHCI_MAX_CURRENT_300_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_300 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_300;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_180) {
+               int max_current_180;
+

               ocr_avail |= MMC_VDD_165_195;

+               max_current_180 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_180_MASK) >>
+                                  SDHCI_MAX_CURRENT_180_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;

drivers/mmc/host/sdhci.c +5 -0
+
+               if (max_current_180 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_180;
+       }
+

       mmc->ocr_avail = ocr_avail;
       mmc->ocr_avail_sdio = ocr_avail;
       if (host->ocr_avail_sdio)

drivers/mmc/host/sdhci.c +1 -1
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
        if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
                mmc->max_blk_size = 2;
        } else {
-               mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+               mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                                SDHCI_MAX_BLOCK_SHIFT;
                if (mmc->max_blk_size >= 3) {

                       printk(KERN_WARNING "%s: Invalid maximum block size, "

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
  #define  SDHCI_DATA_AVAILABLE  0x00000800
  #define  SDHCI_CARD_PRESENT    0x00010000
  #define  SDHCI_WRITE_PROTECT   0x00080000
+#define  SDHCI_DATA_LVL_MASK   0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT 20
 
  #define SDHCI_HOST_CONTROL     0x28
  #define  SDHCI_CTRL_LED                0x01
@@ -147,7 +149,8 @@
 
  #define SDHCI_ACMD12_ERR       0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2            0x3E
+#define  SDHCI_CTRL_VDD_180            0x0008
 
  #define SDHCI_CAPABILITIES     0x40
  #define  SDHCI_TIMEOUT_CLK_MASK        0x0000003F
@@ -168,9 +171,20 @@
  #define  SDHCI_CAN_VDD_180     0x04000000
  #define  SDHCI_CAN_64BIT       0x10000000
 
+#define  SDHCI_SUPPORT_SDR50   0x00000001
+#define  SDHCI_SUPPORT_SDR104  0x00000002
+#define  SDHCI_SUPPORT_DDR50   0x00000004
+
  #define SDHCI_CAPABILITIES_1   0x44
 
-#define SDHCI_MAX_CURRENT      0x48
+#define SDHCI_MAX_CURRENT              0x48
+#define  SDHCI_MAX_CURRENT_330_MASK    0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT   0
+#define  SDHCI_MAX_CURRENT_300_MASK    0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT   8
+#define  SDHCI_MAX_CURRENT_180_MASK    0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT   16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER 4
 
  /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +10 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
        /* optional callback for HC quirks */
        void    (*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+       int     (*start_signal_voltage_switch)(struct mmc_host *host);
  };
 
  struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                                /* DDR mode at 1.2V */
  #define MMC_CAP_POWER_OFF_CARD (1 << 13)       /* Can power off after boot */
  #define MMC_CAP_BUS_WIDTH_TEST (1 << 14)       /* CMD14/CMD19 bus width ok */
+#define MMC_CAP_UHS_SDR12      (1 << 15)       /* Host supports UHS SDR12 mode */
+#define MMC_CAP_UHS_SDR25      (1 << 16)       /* Host supports UHS SDR25 mode */
+#define MMC_CAP_UHS_SDR50      (1 << 17)       /* Host supports UHS SDR50 mode */
+#define MMC_CAP_UHS_SDR104     (1 << 18)       /* Host supports UHS SDR104 mode */
+#define MMC_CAP_UHS_DDR50      (1 << 19)       /* Host supports UHS DDR50 mode */
+#define MMC_CAP_SET_XPC_330    (1 << 20)       /* Host supports >150mA current at 3.3V */
+#define MMC_CAP_SET_XPC_300    (1 << 21)       /* Host supports >150mA current at 3.0V */
+#define MMC_CAP_SET_XPC_180    (1 << 22)       /* Host supports >150mA current at 1.8V */
 

       mmc_pm_flag_t           pm_caps;        /* supported pm features */

include/linux/mmc/sd.h +1 -1
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
  /* This is basically the same command as for MMC with some quirks. */
  #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6  */
  #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7  */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1  */
 
   /* class 10 */
  #define SD_SWITCH                 6   /* adtc [31:0] See below   R1  */
--

1.7.1

#15 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Zhangfei,

Quoted 53 lines

-----Original Message-----
From: zhangfei gao [mailto:[email protected]]
Sent: Wednesday, March 09, 2011 6:15 PM
To: Nath, Arindam
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 27 lines · Arindam Nath

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

Quoted 1 line

The patch can not work with generic card :(

Quoted 5 lines
---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148

+++++++++++++++++++++++++++++++++++++++++----

Quoted 5 lines
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
Quoted 11 lines

drivers/mmc/core/sd.c struct device_type sd_type = { · line 411

Quoted 9 lines
drivers/mmc/core/sd.c +1 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
       int err;
+       u32 rocr;

rocr not initialized here, or move to mmc_sd_init_card in following patch, it may be risky, since dependency.

I will move rocr to mmc_sd_get_cid().

Quoted 23 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32

Quoted 5 lines
drivers/mmc/core/sd.c +0 -0
       /*
        * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32

ocr, u32 *cid)

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 5 lines
drivers/mmc/core/sd.c +1 -1
       if (!err)
               ocr |= 1 << 30;
 
-       err = mmc_send_app_op_cond(host, ocr, NULL);
+       /* If the host can supply more than 150mA, XPC should be set

to 1. */

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 10 lines
drivers/mmc/core/sd.c +7 -0
+       if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+           MMC_CAP_SET_XPC_180))
+               ocr |= 1 << 28;
+
+       err = mmc_send_app_op_cond(host, ocr, &rocr);
       if (err)
               return err;
 
+       /*
+        * In case CCS and S18A in the response is set, start Signal

Voltage

Quoted 8 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) · line 444

Quoted 3 lines
drivers/mmc/core/sd.c +3 -0
+        * Switch procedure. SPI mode doesn't support CMD11.
+        */
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {

if (!mmc_host_is_spi(host) && (rocr & 0x41000000 == 0x41000000))
Currently your patch can not work with general card, for example rocr=0xc0ff8000 & 0x41000000 = 0x40000000, while what you want is both two bit are set.

Good catch. I will fix this. Thanks.

Quoted 28 lines
Quoted 10 lines
drivers/mmc/core/sd.c +5 -0
+               err = mmc_start_voltage_switch(host);
+               if (err)
+                       return err;
+       }
+
       if (mmc_host_is_spi(host))
               err = mmc_send_cid(host, cid);
       else

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 850

Quoted 8 lines
drivers/mmc/core/sd.c +5 -0
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
       }
 
       /*
+        * If the host supports one of UHS-I modes, request the card
+        * to switch to 1.8V signaling level.
+        */
+       if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+           MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 857

Quoted 9 lines
drivers/mmc/core/sd.c +4 -2
+               host->ocr |= (1 << 24);
+
+       /*
        * Detect and init the card.
        */
       err = mmc_sd_init_card(host, host->ocr, NULL);
-       if (err)
-               goto err;
+       if (err == -EAGAIN) {
Quoted 5 lines

If other error happen, for example -ETIMEDOUT in current patch for general card, the following card can not be executed. kernel panic will happen in mmc_add_card for null pinter, since card is not allocated.
how about if (err) for safety?

Yes, I will make the check more generic, or probably we won't need to once I move rocr to mmc_sd_get_cid().

Thanks,
Arindam

Quoted 445 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card,

Quoted 17 lines
drivers/mmc/core/sd.c +8 -0
+               /*
+                * Retry initialization with S18R set to 0.
+                */
+               host->ocr &= ~(1 << 24);
+               err = mmc_sd_init_card(host, host->ocr, NULL);
+               if (err)
+                       goto err;
+       }
 
       mmc_release_host(host);
       err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +0 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,

int width)

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 12 lines
drivers/mmc/core/sd_ops.c +9 -0
       return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+       struct mmc_command cmd;
+       int err;
+
+       BUG_ON(!host);
+
+       /*
+        * If the host does not provide signal voltage switch

procedure, we

drivers/mmc/core/sd_ops.h int mmc_app_send_scr(struct mmc_card *card, u32

Quoted 31 lines
drivers/mmc/core/sd_ops.c +23 -0
+        * set S18R to 0, and then retry initialization sequence.
+        */
+       if (!host->ops->start_signal_voltage_switch)
+               return -EAGAIN;
+
+       memset(&cmd, 0, sizeof(struct mmc_command));
+
+       cmd.opcode = SD_SWITCH_VOLTAGE;
+       cmd.arg = 0;
+       cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+       err = mmc_wait_for_cmd(host, &cmd, 0);
+       if (err)
+               return err;
+
+       if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+               return -EIO;
+
+       err = host->ops->start_signal_voltage_switch(host);
+
+       return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
       struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +0 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32

*scr);

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host *host) · line 85

Quoted 13 lines
drivers/mmc/core/sd_ops.h +1 -0
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
       u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
 
drivers/mmc/host/sdhci.c +0 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
       printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:

0x%08x\n",

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host *host)

Quoted 7 lines
drivers/mmc/host/sdhci.c +2 -0
               sdhci_readw(host, SDHCI_COMMAND),
               sdhci_readl(host, SDHCI_MAX_CURRENT));
+       printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+               sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
       if (host->flags & SDHCI_USE_ADMA)
               printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |

ADMA Ptr: 0x%08x\n",

Quoted 12 lines
drivers/mmc/host/sdhci.c +8 -0
@@ -1337,11 +1339,70 @@ out:
       spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+       struct sdhci_host *host;
+       u8 pwr;
+       u16 clk, ctrl;
+       u32 present_state;
+
+       host = mmc_priv(mmc);

drivers/mmc/host/sdhci.c out: · line 1359

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+       /* Stop SDCLK */
+       host = mmc_priv(mmc);
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       clk &= ~SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       /* Check whether DAT[3:0] is 0000 */
+       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+       if (!((present_state & SDHCI_DATA_LVL_MASK) >>

SDHCI_DATA_LVL_SHIFT)) {

drivers/mmc/host/sdhci.c out: · line 1360

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+               /* Enable 1.8V Signal Enable in the Host Control2

register */

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               ctrl |= SDHCI_CTRL_VDD_180;
+               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+               /* Wait for 5ms */
+               usleep_range(5000, 5500);
+

drivers/mmc/host/sdhci.c out:

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               if (ctrl & SDHCI_CTRL_VDD_180) {
+                       /* Provide SDCLK again and wait for 1ms*/
+                       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                       clk |= SDHCI_CLOCK_CARD_EN;
+                       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                       usleep_range(1000, 1500);
+
+                       /*
+                        * If DAT[3:0] level is 1111b, then the card

was

drivers/mmc/host/sdhci.c out:

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+                        * successfully switched to 1.8V signaling.
+                        */
+                       present_state = sdhci_readl(host,

SDHCI_PRESENT_STATE);

drivers/mmc/host/sdhci.c out:

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+                       if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                            SDHCI_DATA_LVL_MASK) {
+                               return 0;
+                       }
+               }
+       }
+
+       /*
+        * If we are here, that means the switch to 1.8V signaling

failed. Stop

drivers/mmc/host/sdhci.c out: · line 1390

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * power to the card, and retry initialization sequence by

setting S18R

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+        * to 0.
+        */
+       pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+       pwr &= ~SDHCI_POWER_ON;
+       sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);

drivers/mmc/host/sdhci.c out:

Quoted 10 lines
drivers/mmc/host/sdhci.c +5 -0
+
+       return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
       .request        = sdhci_request,
       .set_ios        = sdhci_set_ios,
       .get_ro         = sdhci_get_ro,
       .enable_sdio_irq = sdhci_enable_sdio_irq,
+       .start_signal_voltage_switch    =

sdhci_start_signal_voltage_switch,

drivers/mmc/host/sdhci.c out: · line 1408

Quoted 3 lines
drivers/mmc/host/sdhci.c +0 -0
 };
 
 

/*********************************************************************
********\

Quoted 12 lines
drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
       struct mmc_host *mmc;
-       unsigned int caps, ocr_avail;
+       u32 caps[2];
+       u32 max_current_caps;
+       unsigned int ocr_avail;
       int ret;
 
       WARN_ON(host == NULL);

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                       host->version);
       }
 
-       caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

Quoted 15 lines
drivers/mmc/host/sdhci.c +1 -0
+       caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps :

               sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/host/sdhci.c +4 -1
+       if (host->version >= SDHCI_SPEC_300)
+               caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
       if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
               host->flags |= SDHCI_USE_SDMA;
-       else if (!(caps & SDHCI_CAN_DO_SDMA))
+       else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
               DBG("Controller doesn't have SDMA capability\n");
       else
               host->flags |= SDHCI_USE_SDMA;

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
               host->flags &= ~SDHCI_USE_SDMA;
       }
 
-       if ((host->version >= SDHCI_SPEC_200) && (caps &

SDHCI_CAN_DO_ADMA2))

Quoted 19 lines
drivers/mmc/host/sdhci.c +4 -2
+       if ((host->version >= SDHCI_SPEC_200) &&
+               (caps[0] & SDHCI_CAN_DO_ADMA2))
               host->flags |= SDHCI_USE_ADMA;
 
       if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       if (host->version >= SDHCI_SPEC_300)
-               host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                       >> SDHCI_CLOCK_BASE_SHIFT;
       else
-               host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                       >> SDHCI_CLOCK_BASE_SHIFT;
 
       host->max_clk *= 1000000;

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       host->timeout_clk =
-               (caps & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+               (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 14 lines
drivers/mmc/host/sdhci.c +0 -0
       if (host->timeout_clk == 0) {
               if (host->ops->get_timeout_clock) {
                       host->timeout_clk = host->ops-

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +1 -1
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                       return -ENODEV;
               }
       }
-       if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+       if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
               host->timeout_clk *= 1000;
 
       /*

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
       if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
               mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-       if (caps & SDHCI_CAN_DO_HISPD)
+       if (caps[0] & SDHCI_CAN_DO_HISPD)
               mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 12 lines
drivers/mmc/host/sdhci.c +7 -0
       if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
           mmc_card_is_removable(mmc))
               mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+       /* UHS-I mode(s) supported by the host controller. */
+       if (host->version >= SDHCI_SPEC_300)
+               mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+       /* SDR104 supports also implies SDR50 support */
+       if (caps[1] & SDHCI_SUPPORT_SDR104)
+               mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;

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

Quoted 10 lines
drivers/mmc/host/sdhci.c +8 -1
+       else if (caps[1] & SDHCI_SUPPORT_SDR50)
+               mmc->caps |= MMC_CAP_UHS_SDR50;
+
+       if (caps[1] & SDHCI_SUPPORT_DDR50)
+               mmc->caps |= MMC_CAP_UHS_DDR50;
+
       ocr_avail = 0;
-       if (caps & SDHCI_CAN_VDD_330)
+       /*
+        * According to SD Host Controller spec v3.00, if the Host

System

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * can afford more than 150mA, Host Driver should set XPC to

1. Also

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * the value is meaningful only if Voltage Support in the

Capabilities

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * register is set. The actual current value is 4 times the

register

Quoted 56 lines
drivers/mmc/host/sdhci.c +41 -3
+        * value.
+        */
+       max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+       if (caps[0] & SDHCI_CAN_VDD_330) {
+               int max_current_330;
+
               ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-       if (caps & SDHCI_CAN_VDD_300)
+
+               max_current_330 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_330_MASK) >>
+                                  SDHCI_MAX_CURRENT_330_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_330 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_330;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_300) {
+               int max_current_300;
+
               ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-       if (caps & SDHCI_CAN_VDD_180)
+
+               max_current_300 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_300_MASK) >>
+                                  SDHCI_MAX_CURRENT_300_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_300 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_300;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_180) {
+               int max_current_180;
+
               ocr_avail |= MMC_VDD_165_195;
 
+               max_current_180 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_180_MASK) >>
+                                  SDHCI_MAX_CURRENT_180_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_180 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_180;
+       }
+
       mmc->ocr_avail = ocr_avail;
       mmc->ocr_avail_sdio = ocr_avail;
       if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
       if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
               mmc->max_blk_size = 2;
       } else {
-               mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+               mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK)
Quoted 1 line
Quoted 3 lines
                               SDHCI_MAX_BLOCK_SHIFT;
               if (mmc->max_blk_size >= 3) {
                       printk(KERN_WARNING "%s: Invalid maximum block

size, "

Quoted 50 lines
drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE  0x00000800
 #define  SDHCI_CARD_PRESENT    0x00010000
 #define  SDHCI_WRITE_PROTECT   0x00080000
+#define  SDHCI_DATA_LVL_MASK   0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT 20
 
 #define SDHCI_HOST_CONTROL     0x28
 #define  SDHCI_CTRL_LED                0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR       0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2            0x3E
+#define  SDHCI_CTRL_VDD_180            0x0008
 
 #define SDHCI_CAPABILITIES     0x40
 #define  SDHCI_TIMEOUT_CLK_MASK        0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180     0x04000000
 #define  SDHCI_CAN_64BIT       0x10000000
 
+#define  SDHCI_SUPPORT_SDR50   0x00000001
+#define  SDHCI_SUPPORT_SDR104  0x00000002
+#define  SDHCI_SUPPORT_DDR50   0x00000004
+
 #define SDHCI_CAPABILITIES_1   0x44
 
-#define SDHCI_MAX_CURRENT      0x48
+#define SDHCI_MAX_CURRENT              0x48
+#define  SDHCI_MAX_CURRENT_330_MASK    0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT   0
+#define  SDHCI_MAX_CURRENT_300_MASK    0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT   8
+#define  SDHCI_MAX_CURRENT_180_MASK    0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT   16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER 4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +0 -0
index bcb793e..ad7daa3 100644

include/linux/mmc/host.h struct mmc_host_ops { · line 119

Quoted 3 lines
include/linux/mmc/host.h +0 -0
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
       /* optional callback for HC quirks */
       void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

include/linux/mmc/host.h struct mmc_host_ops { · line 121

Quoted 2 lines
include/linux/mmc/host.h +2 -0
+
+       int     (*start_signal_voltage_switch)(struct mmc_host

*host);

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 6 lines
include/linux/mmc/host.h +0 -0
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                               /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD (1 << 13)       /* Can power off

after boot */

include/linux/mmc/host.h struct mmc_host { · line 177

Quoted 1 line
include/linux/mmc/host.h +0 -0
 #define MMC_CAP_BUS_WIDTH_TEST (1 << 14)       /* CMD14/CMD19 bus

width ok */

include/linux/mmc/host.h struct mmc_host { · line 178

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR12      (1 << 15)       /* Host supports UHS

SDR12 mode */

include/linux/mmc/host.h struct mmc_host { · line 179

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR25      (1 << 16)       /* Host supports UHS

SDR25 mode */

include/linux/mmc/host.h struct mmc_host { · line 180

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR50      (1 << 17)       /* Host supports UHS

SDR50 mode */

include/linux/mmc/host.h struct mmc_host { · line 181

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR104     (1 << 18)       /* Host supports UHS

SDR104 mode */

include/linux/mmc/host.h struct mmc_host { · line 182

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_DDR50      (1 << 19)       /* Host supports UHS

DDR50 mode */

Quoted 8 lines
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_SET_XPC_330    (1 << 20)       /* Host supports

150mA current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports
150mA current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports
150mA current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm

features */

include/linux/mmc/sd.h line 17

Quoted 7 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks.

*/

include/linux/mmc/sd.h line 18

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6

*/

include/linux/mmc/sd.h line 19

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7

*/

include/linux/mmc/sd.h line 20

Quoted 1 line
include/linux/mmc/sd.h +1 -0
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1

*/

include/linux/mmc/sd.h line 22

Quoted 3 lines
include/linux/mmc/sd.h +0 -0
  /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below   R1

*/

Quoted 4 lines
include/linux/mmc/sd.h +0 -1
--

1.7.1

#16 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

In reply to Arindam Nath

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD pads/pins should be changed from 3.3v to 1.8v. for this SD controller has to modify few bits in their controller registers and also have to set the voltage level of a regulator which is powering those pad/pins.

Now with you current patch, you are calling start_signal_voltage_switch mmc_ops when you want to switch from 3.3v to 1.8v and each controller driver would then perform above operation in their handler (modifying relevant controller register and setting the voltage level) along with SD3.0 spec requirements.

Now let's say after all above initialization and some data transfer with UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC card (with SDv2.0 support) then how will controller undone the above voltage switch operations (means changing pad/ping voltage level back from 1.8v to 3.3v)?

To avoid above issue, we can have one new entry in mmc_ios which specifies the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v). This entry would be set once start_signal_voltage_switch ops returns success. So now when card is removed and new card is inserted, at the start of initialization we should make sure that set_ios() gets called with this entry reset (0) which would make sure that CLK, DATA and CMD pads/pins voltage level back to 3.3v.

Regards,
Subhash

Quoted 500 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
 	int err;
+	u32 rocr;
 
 	/*
 	 * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
 	if (!err)
 		ocr |= 1 << 30;
 
-	err = mmc_send_app_op_cond(host, ocr, NULL);
+	/* If the host can supply more than 150mA, XPC should be set to

1. */

drivers/mmc/core/sd.c +7 -0
+	if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+	    MMC_CAP_SET_XPC_180))
+		ocr |= 1 << 28;
+
+	err = mmc_send_app_op_cond(host, ocr, &rocr);
 	if (err)
 		return err;
 
+	/*
+	 * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +25 -2
+	 * Switch procedure. SPI mode doesn't support CMD11.
+	 */
+	if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+		err = mmc_start_voltage_switch(host);
+		if (err)
+			return err;
+	}
+
 	if (mmc_host_is_spi(host))
 		err = mmc_send_cid(host, cid);
 	else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
 	}
 
 	/*
+	 * If the host supports one of UHS-I modes, request the card
+	 * to switch to 1.8V signaling level.
+	 */
+	if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+	    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+		host->ocr |= (1 << 24);
+
+	/*
 	 * Detect and init the card.
 	 */
 	err = mmc_sd_init_card(host, host->ocr, NULL);
-	if (err)
-		goto err;
+	if (err == -EAGAIN) {
+		/*
+		 * Retry initialization with S18R set to 0.
+		 */
+		host->ocr &= ~(1 << 24);
+		err = mmc_sd_init_card(host, host->ocr, NULL);
+		if (err)
+			goto err;
+	}
 
 	mmc_release_host(host);
 	err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +9 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,
 int width)
 	return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+	struct mmc_command cmd;
+	int err;
+
+	BUG_ON(!host);
+
+	/*
+	 * If the host does not provide signal voltage switch procedure,

we

drivers/mmc/core/sd_ops.c +23 -0
+	 * set S18R to 0, and then retry initialization sequence.
+	 */
+	if (!host->ops->start_signal_voltage_switch)
+		return -EAGAIN;
+
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
+	cmd.opcode = SD_SWITCH_VOLTAGE;
+	cmd.arg = 0;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+	err = mmc_wait_for_cmd(host, &cmd, 0);
+	if (err)
+		return err;
+
+	if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+		return -EIO;
+
+	err = host->ops->start_signal_voltage_switch(host);
+
+	return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
 	struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
drivers/mmc/host/sdhci.c +2 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
 	printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
 		sdhci_readw(host, SDHCI_COMMAND),
 		sdhci_readl(host, SDHCI_MAX_CURRENT));
+	printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+		sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
 	if (host->flags & SDHCI_USE_ADMA)

printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA
Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +48 -0
@@ -1337,11 +1339,70 @@ out:
 	spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+	struct sdhci_host *host;
+	u8 pwr;
+	u16 clk, ctrl;
+	u32 present_state;
+
+	host = mmc_priv(mmc);
+
+	/* Stop SDCLK */
+	host = mmc_priv(mmc);
+	clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	clk &= ~SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+	/* Check whether DAT[3:0] is 0000 */
+	present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+		/* Enable 1.8V Signal Enable in the Host Control2 register
 */
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		ctrl |= SDHCI_CTRL_VDD_180;
+		sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+		/* Wait for 5ms */
+		usleep_range(5000, 5500);
+
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+		if (ctrl & SDHCI_CTRL_VDD_180) {
+			/* Provide SDCLK again and wait for 1ms*/
+			clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+			clk |= SDHCI_CLOCK_CARD_EN;
+			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+			usleep_range(1000, 1500);
+
+			/*
+			 * If DAT[3:0] level is 1111b, then the card was
+			 * successfully switched to 1.8V signaling.
+			 */
+			present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+			if ((present_state & SDHCI_DATA_LVL_MASK) ==
+			     SDHCI_DATA_LVL_MASK) {
+				return 0;
+			}
+		}
+	}
+
+	/*
+	 * If we are here, that means the switch to 1.8V signaling

failed. Stop

drivers/mmc/host/sdhci.c +1 -0
+	 * power to the card, and retry initialization sequence by

setting S18R

drivers/mmc/host/sdhci.c +10 -0
+	 * to 0.
+	 */
+	pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+	pwr &= ~SDHCI_POWER_ON;
+	sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+	return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
 	.request	= sdhci_request,
 	.set_ios	= sdhci_set_ios,
 	.get_ro		= sdhci_get_ro,
 	.enable_sdio_irq = sdhci_enable_sdio_irq,
+	.start_signal_voltage_switch	=

sdhci_start_signal_voltage_switch,
};

/********************************************************************** *******\

drivers/mmc/host/sdhci.c +4 -2
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;
-	unsigned int caps, ocr_avail;
+	u32 caps[2];
+	u32 max_current_caps;
+	unsigned int ocr_avail;
 	int ret;
 
 	WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
 			host->version);
 	}
 
-	caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+	caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

drivers/mmc/host/sdhci.c +6 -2
 		sdhci_readl(host, SDHCI_CAPABILITIES);
 
+	if (host->version >= SDHCI_SPEC_300)
+		caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
 	if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
 		host->flags |= SDHCI_USE_SDMA;
-	else if (!(caps & SDHCI_CAN_DO_SDMA))
+	else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
 		DBG("Controller doesn't have SDMA capability\n");
 	else
 		host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
 		host->flags &= ~SDHCI_USE_SDMA;
 	}
 
-	if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+	if ((host->version >= SDHCI_SPEC_200) &&
+		(caps[0] & SDHCI_CAN_DO_ADMA2))
 		host->flags |= SDHCI_USE_ADMA;
 
drivers/mmc/host/sdhci.c +3 -3
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	if (host->version >= SDHCI_SPEC_300)
-		host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 	else
-		host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+		host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
 			>> SDHCI_CLOCK_BASE_SHIFT;
 
 	host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	}
 
 	host->timeout_clk =
-		(caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+		(caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
 	if (host->timeout_clk == 0) {
 		if (host->ops->get_timeout_clock) {

host->timeout_clk = host->ops-

Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +18 -3
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
 			return -ENODEV;
 		}
 	}
-	if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+	if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
 		host->timeout_clk *= 1000;
 
 	/*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
 		mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-	if (caps & SDHCI_CAN_DO_HISPD)
+	if (caps[0] & SDHCI_CAN_DO_HISPD)
 		mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
 	if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
 	    mmc_card_is_removable(mmc))
 		mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+	/* UHS-I mode(s) supported by the host controller. */
+	if (host->version >= SDHCI_SPEC_300)
+		mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+	/* SDR104 supports also implies SDR50 support */
+	if (caps[1] & SDHCI_SUPPORT_SDR104)
+		mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+	else if (caps[1] & SDHCI_SUPPORT_SDR50)
+		mmc->caps |= MMC_CAP_UHS_SDR50;
+
+	if (caps[1] & SDHCI_SUPPORT_DDR50)
+		mmc->caps |= MMC_CAP_UHS_DDR50;
+
 	ocr_avail = 0;
-	if (caps & SDHCI_CAN_VDD_330)
+	/*
+	 * According to SD Host Controller spec v3.00, if the Host System
+	 * can afford more than 150mA, Host Driver should set XPC to 1.

Also

drivers/mmc/host/sdhci.c +1 -0
+	 * the value is meaningful only if Voltage Support in the

Capabilities

drivers/mmc/host/sdhci.c +1 -0
+	 * register is set. The actual current value is 4 times the

register

drivers/mmc/host/sdhci.c +41 -3
+	 * value.
+	 */
+	max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+	if (caps[0] & SDHCI_CAN_VDD_330) {
+		int max_current_330;
+
 		ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-	if (caps & SDHCI_CAN_VDD_300)
+
+		max_current_330 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_330_MASK) >>
+				   SDHCI_MAX_CURRENT_330_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_330 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_330;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_300) {
+		int max_current_300;
+
 		ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-	if (caps & SDHCI_CAN_VDD_180)
+
+		max_current_300 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_300_MASK) >>
+				   SDHCI_MAX_CURRENT_300_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_300 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_300;
+	}
+	if (caps[0] & SDHCI_CAN_VDD_180) {
+		int max_current_180;
+
 		ocr_avail |= MMC_VDD_165_195;
 
+		max_current_180 = ((max_current_caps &
+				   SDHCI_MAX_CURRENT_180_MASK) >>
+				   SDHCI_MAX_CURRENT_180_SHIFT) *
+				   SDHCI_MAX_CURRENT_MULTIPLIER;
+
+		if (max_current_180 > 150)
+			mmc->caps |= MMC_CAP_SET_XPC_180;
+	}
+
 	mmc->ocr_avail = ocr_avail;
 	mmc->ocr_avail_sdio = ocr_avail;
 	if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
 		mmc->max_blk_size = 2;
 	} else {
-		mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+		mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
 				SDHCI_MAX_BLOCK_SHIFT;
 		if (mmc->max_blk_size >= 3) {
 			printk(KERN_WARNING "%s: Invalid maximum block size,

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE	0x00000800
 #define  SDHCI_CARD_PRESENT	0x00010000
 #define  SDHCI_WRITE_PROTECT	0x00080000
+#define  SDHCI_DATA_LVL_MASK	0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT	20
 
 #define SDHCI_HOST_CONTROL 	0x28
 #define  SDHCI_CTRL_LED		0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR	0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2		0x3E
+#define  SDHCI_CTRL_VDD_180		0x0008
 
 #define SDHCI_CAPABILITIES	0x40
 #define  SDHCI_TIMEOUT_CLK_MASK	0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180	0x04000000
 #define  SDHCI_CAN_64BIT	0x10000000
 
+#define  SDHCI_SUPPORT_SDR50	0x00000001
+#define  SDHCI_SUPPORT_SDR104	0x00000002
+#define  SDHCI_SUPPORT_DDR50	0x00000004
+
 #define SDHCI_CAPABILITIES_1	0x44
 
-#define SDHCI_MAX_CURRENT	0x48
+#define SDHCI_MAX_CURRENT		0x48
+#define  SDHCI_MAX_CURRENT_330_MASK	0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT	0
+#define  SDHCI_MAX_CURRENT_300_MASK	0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT	8
+#define  SDHCI_MAX_CURRENT_180_MASK	0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT	16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER	4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +2 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
 	/* optional callback for HC quirks */
 	void	(*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+	int	(*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 2 lines
include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
 						/* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD	(1 << 13)	/* Can power off

after

Quoted 45 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus
width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS SDR12
mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS SDR25
mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50
mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104
mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50
mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA
current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA
current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA
current at 1.8V */

include/linux/mmc/host.h +0 -0
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
include/linux/mmc/sd.h +1 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks. */
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below R1
*/
--
1.7.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

#17 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 37 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD pads/pins should
be changed from 3.3v to 1.8v. for this SD controller has to modify few bits
in their controller registers and also have to set the voltage level of a
regulator which is powering those pad/pins.

Now with you current patch, you are calling start_signal_voltage_switch mmc_ops when you want to switch from 3.3v to 1.8v and each controller driver
would then perform above operation in their handler (modifying relevant controller register and setting the voltage level) along with SD3.0 spec
requirements.

Now let's say after all above initialization and some data transfer with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the above voltage
switch operations (means changing pad/ping voltage level back from 1.8v to
3.3v)?

Quoted 11 lines

To avoid above issue, we can have one new entry in mmc_ios which specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v).
This entry would be set once start_signal_voltage_switch ops returns success. So now when card is removed and new card is inserted, at the start
of initialization we should make sure that set_ios() gets called with this
entry reset (0) which would make sure that CLK, DATA and CMD pads/pins voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we simply not reset 1.8V signaling enable in the Host Control2 register when a card is removed? Will that serve the purpose?

Thanks,
Arindam

Quoted 557 lines

Regards,
Subhash

Quoted 267 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
    int err;
+   u32 rocr;
 
    /*
     * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
    if (!err)
            ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be set to

1. */

drivers/mmc/core/sd.c +7 -0
+   if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;
 
+   /*
+    * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +25 -2
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
    }
 
    /*
+    * If the host supports one of UHS-I modes, request the card
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+           host->ocr |= (1 << 24);
+
+   /*
     * Detect and init the card.
     */
    err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
    mmc_release_host(host);
    err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +9 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,
 int width)
    return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch procedure,

we

drivers/mmc/core/sd_ops.c +23 -0
+    * set S18R to 0, and then retry initialization sequence.
+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+           return -EIO;
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
    struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
    u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
drivers/mmc/host/sdhci.c +2 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND),
            sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
    if (host->flags & SDHCI_USE_ADMA)
            printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +48 -0
@@ -1337,11 +1339,70 @@ out:
    spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host Control2 register
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
+                   /* Provide SDCLK again and wait for 1ms*/
+                   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the card was
+                    * successfully switched to 1.8V signaling.
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V signaling

failed. Stop
+ * power to the card, and retry initialization sequence by
setting S18R

drivers/mmc/host/sdhci.c +10 -0
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+   return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
    .get_ro         = sdhci_get_ro,
    .enable_sdio_irq = sdhci_enable_sdio_irq,
+   .start_signal_voltage_switch    =
Quoted 5 lines

sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 228 lines

*******\

drivers/mmc/host/sdhci.c +4 -2
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
    struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
    int ret;
 
    WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                    host->version);
    }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

            sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/host/sdhci.c +6 -2
+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
            host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
            DBG("Controller doesn't have SDMA capability\n");
    else
            host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
            host->flags &= ~SDHCI_USE_SDMA;
    }
 
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
            host->flags |= SDHCI_USE_ADMA;
 
    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
drivers/mmc/host/sdhci.c +3 -3
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
    }
 
    if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
 
    host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
    }
 
    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) {
                    host->timeout_clk = host->ops-
Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +18 -3
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                    return -ENODEV;
            }
    }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
            host->timeout_clk *= 1000;
 
    /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
    if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
            mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)
            mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
        mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;
+
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+
    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the Host System
+    * can afford more than 150mA, Host Driver should set XPC to 1.

Also
+ * the value is meaningful only if Voltage Support in the
Capabilities
+ * register is set. The actual current value is 4 times the
register

drivers/mmc/host/sdhci.c +41 -3
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+
            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK) >>
+                              SDHCI_MAX_CURRENT_330_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+
            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK) >>
+                              SDHCI_MAX_CURRENT_300_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+
            ocr_avail |= MMC_VDD_165_195;
 
+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK) >>
+                              SDHCI_MAX_CURRENT_180_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+
    mmc->ocr_avail = ocr_avail;
    mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
    if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
            mmc->max_blk_size = 2;
    } else {
-           mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+           mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                            SDHCI_MAX_BLOCK_SHIFT;
            if (mmc->max_blk_size >= 3) {
                    printk(KERN_WARNING "%s: Invalid maximum block size,

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE      0x00000800
 #define  SDHCI_CARD_PRESENT        0x00010000
 #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
 #define SDHCI_HOST_CONTROL         0x28
 #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
 #define SDHCI_CAPABILITIES 0x40
 #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180 0x04000000
 #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
 #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +2 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
    /* optional callback for HC quirks */
    void    (*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+   int     (*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 2 lines
include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
                                            /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can power off

after

Quoted 27 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus
width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS SDR12
mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS SDR25
mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50
mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104
mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50
mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA
current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA
current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA
current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm features */

include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644

include/linux/mmc/sd.h line 17

Quoted 1 line
include/linux/mmc/sd.h +0 -0
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks.

*/

Quoted 7 lines
include/linux/mmc/sd.h +1 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1
 */
Quoted 8 lines
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below R1
*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc"

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 67 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 9 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 5 lines

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD pads/pins should
be changed from 3.3v to 1.8v. for this SD controller has to modify

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage level

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 3 lines

mmc_ops when you want to switch from 3.3v to 1.8v and each controller driver
would then perform above operation in their handler (modifying

relevant

Quoted 11 lines

controller register and setting the voltage level) along with SD3.0 spec
requirements.

Now let's say after all above initialization and some data transfer with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the above voltage
switch operations (means changing pad/ping voltage level back from

1.8v

Quoted 13 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios which specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v).
This entry would be set once start_signal_voltage_switch ops returns success. So now when card is removed and new card is inserted, at the start
of initialization we should make sure that set_ios() gets called with this
entry reset (0) which would make sure that CLK, DATA and CMD

Quoted 6 lines

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we simply not reset 1.8V signaling enable in the Host Control2 register when a card is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is removed (assuming that there is no hardware based card detection available)? And I don't think host controller driver itself should take decision to revert back from 1.8v to 3.3v until core layer tells it do so.

Regarding clearing the bit in Host Control2 register, it's specific to your controller. Not all controllers/platform will have same bits and also some controller might have to do something extra than setting few bits in controller registers. In our case for switching from 3.3v to 1.8v, other than setting one of the controller register bit, we also need to set the voltage level of a regulator which is powering these interface pins CMD, DATA, CLK.

Quoted 599 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 88 lines
Quoted 88 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +2 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
    int err;
+   u32 rocr;
 
    /*
     * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32
 ocr, u32 *cid)
    if (!err)
            ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be set to

1. */

drivers/mmc/core/sd.c +7 -0
+   if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;
 
+   /*
+    * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +8 -0
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
    }
 
Quoted 6 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host)

Quoted 6 lines
drivers/mmc/core/sd.c +5 -0
    /*
+    * If the host supports one of UHS-I modes, request the card
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +12 -2
+           host->ocr |= (1 << 24);
+
+   /*
     * Detect and init the card.
     */
    err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
Quoted 7 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card

Quoted 7 lines
drivers/mmc/core/sd.c +0 -0
    mmc_release_host(host);
    err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +0 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card

*card,

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
 int width)
    return 0;
 }
 
Quoted 9 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 9 lines
drivers/mmc/core/sd_ops.c +9 -0
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch

procedure,

Quoted 17 lines
Quoted 17 lines

we

drivers/mmc/core/sd_ops.c +16 -0
+    * set S18R to 0, and then retry initialization sequence.
+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 8 lines
drivers/mmc/core/sd_ops.c +7 -0
+           return -EIO;
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32

*rocr)

Quoted 13 lines
Quoted 13 lines
 {
    struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
    u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
Quoted 7 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host

Quoted 7 lines
drivers/mmc/core/sd_ops.h +0 -0
 #endif
drivers/mmc/host/sdhci.c +0 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host

*host)

Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci.c +2 -0
    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND),
            sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
    if (host->flags & SDHCI_USE_ADMA)
            printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |

ADMA

Quoted 17 lines
Quoted 17 lines

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +12 -0
@@ -1337,11 +1339,70 @@ out:
    spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +7 -0
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host Control2

register

Quoted 10 lines
Quoted 10 lines
drivers/mmc/host/sdhci.c +9 -0
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+                   /* Provide SDCLK again and wait for 1ms*/
+                   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the card

was

Quoted 28 lines
Quoted 28 lines
drivers/mmc/host/sdhci.c +12 -0
+                    * successfully switched to 1.8V signaling.
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V signaling

failed. Stop
+ * power to the card, and retry initialization sequence by
setting S18R

drivers/mmc/host/sdhci.c +9 -0
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+   return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
Quoted 9 lines
Quoted 8 lines

.get_ro = sdhci_get_ro,
.enable_sdio_irq = sdhci_enable_sdio_irq,
+ .start_signal_voltage_switch =
sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 55 lines
Quoted 13 lines

*******\

drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
    struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
    int ret;
 
    WARN_ON(host == NULL);

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

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -1
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                    host->version);
    }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps

Quoted 36 lines

:

            sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/host/sdhci.c +6 -2
+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
            host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
            DBG("Controller doesn't have SDMA capability\n");
    else
            host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
            host->flags &= ~SDHCI_USE_SDMA;
    }
 
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
            host->flags |= SDHCI_USE_ADMA;
 
    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
drivers/mmc/host/sdhci.c +2 -2
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
    }
 
    if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
 
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +0 -1
    host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
    }
 
    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 14 lines
Quoted 14 lines
drivers/mmc/host/sdhci.c +1 -0
+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) {
                    host->timeout_clk = host->ops-
Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +1 -1
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                    return -ENODEV;
            }
    }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
            host->timeout_clk *= 1000;
 
Quoted 8 lines

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

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -1
    /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
    if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
            mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)
            mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 14 lines
Quoted 14 lines
drivers/mmc/host/sdhci.c +9 -0
    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
        mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;
Quoted 8 lines

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

Quoted 8 lines
drivers/mmc/host/sdhci.c +6 -1
+
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+
    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the Host

System

Quoted 56 lines
Quoted 56 lines
drivers/mmc/host/sdhci.c +1 -0
+    * can afford more than 150mA, Host Driver should set XPC to 1.

Also
+ * the value is meaningful only if Voltage Support in the
Capabilities
+ * register is set. The actual current value is 4 times the
register

drivers/mmc/host/sdhci.c +40 -2
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+
            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK) >>
+                              SDHCI_MAX_CURRENT_330_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+
            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK) >>
+                              SDHCI_MAX_CURRENT_300_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+
            ocr_avail |= MMC_VDD_165_195;
 
+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK) >>
+                              SDHCI_MAX_CURRENT_180_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+
    mmc->ocr_avail = ocr_avail;
    mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
Quoted 8 lines

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

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -1
    if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
            mmc->max_blk_size = 2;
    } else {
-           mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+           mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                            SDHCI_MAX_BLOCK_SHIFT;
            if (mmc->max_blk_size >= 3) {
                    printk(KERN_WARNING "%s: Invalid maximum block

size,

Quoted 46 lines
Quoted 46 lines

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE      0x00000800
 #define  SDHCI_CARD_PRESENT        0x00010000
 #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
 #define SDHCI_HOST_CONTROL         0x28
 #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
 #define SDHCI_CAPABILITIES 0x40
 #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180 0x04000000
 #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
 #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
 /* 4C-4F reserved for more max current */
 
Quoted 8 lines

include/linux/mmc/host.h struct mmc_host_ops { · line 119

Quoted 8 lines
include/linux/mmc/host.h +0 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
    /* optional callback for HC quirks */
    void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

Quoted 8 lines

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 8 lines
include/linux/mmc/host.h +2 -0
+
+   int     (*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                            /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can power

off

Quoted 3 lines

after

Quoted 2 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19

bus

Quoted 2 lines
Quoted 2 lines

width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS

DDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host

supports >150mA

Quoted 3 lines
Quoted 3 lines

current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm

features */

Quoted 9 lines

include/linux/mmc/sd.h line 17

Quoted 7 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks.

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines

include/linux/mmc/sd.h line 20

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 4 lines

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
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

#19 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 87 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 10 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 10 lines

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 5 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to modify

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage

level

Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 12 lines
Quoted 2 lines

driver
would then perform above operation in their handler (modifying

relevant

Quoted 9 lines

controller register and setting the voltage level) along with SD3.0 spec
requirements.

Now let's say after all above initialization and some data transfer with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the

above

Quoted 11 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level back from

1.8v

Quoted 8 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios which specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v).
This entry would be set once start_signal_voltage_switch ops

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is inserted, at

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets called

with

Quoted 5 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and CMD

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Quoted 7 lines
Quoted 1 line

Rather than following the procedure mentioned above, can we simply

not

Quoted 2 lines

reset 1.8V signaling enable in the Host Control2 register when a card is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is removed (assuming that there is no hardware based card detection available)?

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Quoted 8 lines

And I
don't think host controller driver itself should take decision to revert
back from 1.8v to 3.3v until core layer tells it do so.

Regarding clearing the bit in Host Control2 register, it's specific to your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be reset to set the signaling voltage back to 3.3V.

and also

Quoted 9 lines

some
controller might have to do something extra than setting few bits in controller registers. In our case for switching from 3.3v to 1.8v, other
than setting one of the controller register bit, we also need to set the
voltage level of a regulator which is powering these interface pins CMD,
DATA, CLK.

In that case I will modify the code to add an entry into mmc_ios as per your suggestion.

Thanks,
Arindam

Quoted 628 lines
Quoted 12 lines

Thanks,
Arindam

Quoted 5 lines

Regards,
Subhash

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 7 lines
Quoted 7 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The

spec

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by

default.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host

Control2

Quoted 12 lines
Quoted 6 lines
Quoted 6 lines

is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply

150mA.

Quoted 5 lines
Quoted 5 lines

This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will

switch

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register,

which

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +1 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
    int err;
+   u32 rocr;
 
Quoted 3 lines
Quoted 3 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host,

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
    /*
     * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host,

u32

Quoted 6 lines
Quoted 6 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 6 lines
drivers/mmc/core/sd.c +1 -1
 ocr, u32 *cid)
    if (!err)
            ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be set

to

Quoted 51 lines
Quoted 26 lines
Quoted 26 lines

1. */

drivers/mmc/core/sd.c +7 -0
+   if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;
 
+   /*
+    * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c +8 -0
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
    }
 
Quoted 6 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host)

Quoted 6 lines
drivers/mmc/core/sd.c +5 -0
    /*
+    * If the host supports one of UHS-I modes, request the card
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +12 -2
+           host->ocr |= (1 << 24);
+
+   /*
     * Detect and init the card.
     */
    err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
    mmc_release_host(host);
    err = mmc_add_card(host->card);
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.c

Quoted 45 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card

Quoted 4 lines

index 797cdb5..8a23e2e 100644

drivers/mmc/core/sd_ops.c +0 -0
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card

*card,

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
 int width)
    return 0;
 }
 
Quoted 9 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 9 lines
drivers/mmc/core/sd_ops.c +9 -0
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch

procedure,

Quoted 17 lines
Quoted 17 lines

we

drivers/mmc/core/sd_ops.c +16 -0
+    * set S18R to 0, and then retry initialization sequence.
+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 8 lines
drivers/mmc/core/sd_ops.c +7 -0
+           return -EIO;
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32

*rocr)

Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 {
    struct mmc_command cmd;
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.h

Quoted 27 lines
Quoted 10 lines
Quoted 10 lines

index ffc2305..3cfba59 100644

drivers/mmc/core/sd_ops.h +1 -0
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
    u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
Quoted 7 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host

Quoted 7 lines
drivers/mmc/core/sd_ops.h +0 -0
 #endif
drivers/mmc/host/sdhci.c +0 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host

*host)

Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci.c +2 -0
    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:
 0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND),
            sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
    if (host->flags & SDHCI_USE_ADMA)
            printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |
Quoted 7 lines

ADMA

Quoted 6 lines

drivers/mmc/host/sdhci.c out: · line 1342

Quoted 6 lines

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +1 -0
@@ -1337,11 +1339,70 @@ out:
    spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host

*mmc)

Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +11 -0
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +7 -0
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host Control2

register

Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +10 -0
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
+                   /* Provide SDCLK again and wait for 1ms*/
Quoted 46 lines
Quoted 7 lines

drivers/mmc/host/sdhci.c out:

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+                   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the card

was

Quoted 37 lines
Quoted 36 lines
drivers/mmc/host/sdhci.c +12 -0
+                    * successfully switched to 1.8V signaling.
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V signaling

failed. Stop
+ * power to the card, and retry initialization sequence by
setting S18R

drivers/mmc/host/sdhci.c +10 -0
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+   return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
    .get_ro         = sdhci_get_ro,
    .enable_sdio_irq = sdhci_enable_sdio_irq,
+   .start_signal_voltage_switch    =

sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*******\

drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
    struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
    int ret;
 
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
    WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
                    host->version);
    }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

Quoted 19 lines
Quoted 19 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 1888

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps

Quoted 17 lines

:

            sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/host/sdhci.c +4 -1
+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
            host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
            DBG("Controller doesn't have SDMA capability\n");
    else
            host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
            host->flags &= ~SDHCI_USE_SDMA;
    }
 
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci.c +2 -1
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
            host->flags |= SDHCI_USE_ADMA;
 
    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
drivers/mmc/host/sdhci.c +0 -0
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 32 lines
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +2 -2
    }
 
    if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
 
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +0 -1
    host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
    }
 
    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 14 lines
Quoted 14 lines
drivers/mmc/host/sdhci.c +1 -0
+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) {
                    host->timeout_clk = host->ops-
Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +1 -1
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                    return -ENODEV;
            }
    }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
            host->timeout_clk *= 1000;
 
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
    /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 22 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
    if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
            mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)
            mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 15 lines
Quoted 15 lines
drivers/mmc/host/sdhci.c +10 -0
    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
        mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;
+
Quoted 9 lines
Quoted 7 lines

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

Quoted 7 lines
drivers/mmc/host/sdhci.c +5 -1
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+
    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the Host

System

Quoted 1 line
Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+    * can afford more than 150mA, Host Driver should set XPC to

1.

Quoted 61 lines
Quoted 61 lines
Quoted 60 lines

Also
+ * the value is meaningful only if Voltage Support in the
Capabilities
+ * register is set. The actual current value is 4 times the
register

drivers/mmc/host/sdhci.c +41 -3
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+
            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK) >>
+                              SDHCI_MAX_CURRENT_330_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+
            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK) >>
+                              SDHCI_MAX_CURRENT_300_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+
            ocr_avail |= MMC_VDD_165_195;
 
+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK) >>
+                              SDHCI_MAX_CURRENT_180_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+
    mmc->ocr_avail = ocr_avail;
    mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
    if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
            mmc->max_blk_size = 2;
    } else {
-           mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+           mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK)
Quoted 3 lines
Quoted 3 lines

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

Quoted 3 lines
drivers/mmc/host/sdhci.c +0 -0
                            SDHCI_MAX_BLOCK_SHIFT;
            if (mmc->max_blk_size >= 3) {
                    printk(KERN_WARNING "%s: Invalid maximum

block

Quoted 53 lines

size,

Quoted 52 lines
Quoted 52 lines

"

drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE      0x00000800
 #define  SDHCI_CARD_PRESENT        0x00010000
 #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
 #define SDHCI_HOST_CONTROL         0x28
 #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
 #define SDHCI_CAPABILITIES 0x40
 #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180 0x04000000
 #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
 #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +0 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
Quoted 5 lines
Quoted 2 lines

include/linux/mmc/host.h struct mmc_host_ops { · line 119

Quoted 2 lines
include/linux/mmc/host.h +0 -0
    /* optional callback for HC quirks */
    void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

Quoted 2 lines
Quoted 2 lines
include/linux/mmc/host.h +2 -0
+
+   int     (*start_signal_voltage_switch)(struct mmc_host

*host);

Quoted 5 lines
Quoted 5 lines

include/linux/mmc/host.h struct mmc_host { · line 175

Quoted 5 lines
include/linux/mmc/host.h +0 -0
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                            /* DDR mode at 1.2V

*/

Quoted 5 lines
Quoted 1 line

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 1 line
include/linux/mmc/host.h +0 -0
 #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can power

off

Quoted 3 lines

after

Quoted 2 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /*

CMD14/CMD19

Quoted 28 lines

bus

Quoted 2 lines
Quoted 2 lines

width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS

DDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host

supports >150mA

Quoted 3 lines
Quoted 3 lines

current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm

Quoted 8 lines

features */

Quoted 7 lines

include/linux/mmc/sd.h line 17

Quoted 7 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some

quirks.

Quoted 13 lines
Quoted 2 lines

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines

include/linux/mmc/sd.h line 20

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below

Quoted 11 lines

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-

info.html

Quoted 5 lines
Quoted 1 line

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc"

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#20 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 110 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:59 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 19 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 12 lines
Quoted 12 lines

switch procedure

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

Quoted 9 lines

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 2 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to

modify

Quoted 4 lines
Quoted 3 lines

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage

level

Quoted 12 lines
Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 4 lines
Quoted 2 lines

driver
would then perform above operation in their handler (modifying

relevant

Quoted 1 line

controller register and setting the voltage level) along with

SD3.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

spec
requirements.

Now let's say after all above initialization and some data

transfer

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the

above

Quoted 2 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level back

from

Quoted 14 lines
Quoted 9 lines

1.8v

Quoted 8 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios which specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v).
This entry would be set once start_signal_voltage_switch ops

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is inserted, at

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets called

Quoted 9 lines

with

Quoted 6 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and CMD

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we simply

not

Quoted 1 line

reset 1.8V signaling enable in the Host Control2 register when a

card

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is

removed

Quoted 1 line

(assuming that there is no hardware based card detection available)?

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Sorry. But again I have to make this point clear. It's not necessary that all host controller implementation would be same as your host controller implementation. In our host controller we don't have any such status bit for card removal event.

Quoted 6 lines
Quoted 6 lines

And I
don't think host controller driver itself should take decision to revert
back from 1.8v to 3.3v until core layer tells it do so.

Quoted 8 lines
Quoted 1 line

Regarding clearing the bit in Host Control2 register, it's specific

to

Quoted 2 lines

your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be reset to set the signaling voltage back to 3.3V.

Same as my above comment.

Quoted 12 lines

and also

Quoted 9 lines

some
controller might have to do something extra than setting few bits in controller registers. In our case for switching from 3.3v to 1.8v, other
than setting one of the controller register bit, we also need to set the
voltage level of a regulator which is powering these interface pins CMD,
DATA, CLK.

Quoted 2 lines

In that case I will modify the code to add an entry into mmc_ios as per your suggestion.

What about removing start_signal_voltage_switch ops itself and just adding one entry in ios for voltage_switch? Whenever you want to switch the voltage level from 1.8v to 2.7v call set_ios() with this new entry set and when you want to go back from 1.8v to 2.7v call set_ios() with this new entry reset.

Quoted 674 lines

Thanks,
Arindam

Quoted 19 lines
Quoted 19 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

Quoted 3 lines
Quoted 3 lines

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The

spec

Quoted 1 line
Quoted 1 line
Quoted 1 line

doesn't mention about explicit support for SDR12 and SDR25 UHS-

I

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

modes, so the Host Controller v3.00 should support them by

default.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also if the controller support SDR104 mode, it will also

support

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SDR50 mode as well. So depending on the host support, we set

the

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

corresponding MMC_CAP_* flags. One more new register. Host

Control2

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We

also

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

need to set XPC (bit 28) of OCR in case the host can supply

150mA.

Quoted 4 lines
Quoted 4 lines

This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

signal voltage switch procedure, which if successfull, will

switch

Quoted 1 line
Quoted 1 line
Quoted 1 line

the card from 3.3V signalling to 1.8V signalling. Signal

voltage

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need

to

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

set 1.8V Signalling Enable (bit 3) of Host Control2 register,

which

Quoted 1 line
Quoted 1 line
Quoted 1 line

if remains set after 5ms, means the switch to 1.8V signalling

is

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +1 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
    int err;
+   u32 rocr;
 
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host,

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
    /*
     * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host,

u32

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +1 -1
 ocr, u32 *cid)
    if (!err)
            ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be

set

Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1. */
+ if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300

|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 9 lines
drivers/mmc/core/sd.c +6 -0
+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;
 
+   /*
+    * In case CCS and S18A in the response is set, start

Signal

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

Voltage

drivers/mmc/core/sd.c +8 -0
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
    }
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 846

Quoted 2 lines
drivers/mmc/core/sd.c +1 -0
    /*
+    * If the host supports one of UHS-I modes, request the

card

Quoted 72 lines
Quoted 23 lines
Quoted 4 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host)

Quoted 4 lines
drivers/mmc/core/sd.c +4 -0
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +12 -2
+           host->ocr |= (1 << 24);
+
+   /*
     * Detect and init the card.
     */
    err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
    mmc_release_host(host);
    err = mmc_add_card(host->card);
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.c

Quoted 45 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card

Quoted 4 lines

index 797cdb5..8a23e2e 100644

drivers/mmc/core/sd_ops.c +0 -0
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card

*card,

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
 int width)
    return 0;
 }
 
Quoted 9 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 9 lines
drivers/mmc/core/sd_ops.c +9 -0
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch

procedure,

Quoted 17 lines
Quoted 17 lines

we

drivers/mmc/core/sd_ops.c +16 -0
+    * set S18R to 0, and then retry initialization sequence.
+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 8 lines
drivers/mmc/core/sd_ops.c +7 -0
+           return -EIO;
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32

*rocr)

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 {
    struct mmc_command cmd;
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.h

Quoted 4 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.h int mmc_app_send_scr(struct mmc_card *card,

Quoted 4 lines

index ffc2305..3cfba59 100644

drivers/mmc/core/sd_ops.h +0 -0
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card,

u32

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
drivers/mmc/core/sd_ops.h +1 -0
 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
    u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.c

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host

Quoted 4 lines

index 8914a25..5487a0b 100644

drivers/mmc/host/sdhci.c +0 -0
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host

*host)

Quoted 1 line
Quoted 1 line
drivers/mmc/host/sdhci.c +0 -0
    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max

curr:

Quoted 36 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mmc/host/sdhci.c +2 -0
 0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND),
            sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
    if (host->flags & SDHCI_USE_ADMA)
            printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |
Quoted 7 lines

ADMA

Quoted 6 lines

drivers/mmc/host/sdhci.c out: · line 1342

Quoted 6 lines

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +1 -0
@@ -1337,11 +1339,70 @@ out:
    spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host

*mmc)

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +11 -0
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +7 -0
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host Control2

register

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +3 -0
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
+                   /* Provide SDCLK again and wait for 1ms*/
+                   clk = sdhci_readw(host,

SDHCI_CLOCK_CONTROL);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c out: · line 1375

Quoted 2 lines
drivers/mmc/host/sdhci.c +2 -0
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk,

SDHCI_CLOCK_CONTROL);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c out:

Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the

card

Quoted 6 lines
Quoted 6 lines

was

Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +4 -0
+                    * successfully switched to 1.8V signaling.
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state & SDHCI_DATA_LVL_MASK)

==

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/mmc/host/sdhci.c +8 -0
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V signaling

failed. Stop
+ * power to the card, and retry initialization sequence by
setting S18R

drivers/mmc/host/sdhci.c +9 -0
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+   return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
    .get_ro         = sdhci_get_ro,
    .enable_sdio_irq = sdhci_enable_sdio_irq,
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+ .start_signal_voltage_switch =
sdhci_start_signal_voltage_switch,
};

/**********************************************************************

Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*******\

drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
    struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
    int ret;
 
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
    WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
                    host->version);
    }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps
:

Quoted 5 lines
Quoted 5 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 1888

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps

Quoted 3 lines

:

            sdhci_readl(host, SDHCI_CAPABILITIES);
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 11 lines
drivers/mmc/host/sdhci.c +4 -1
+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
            host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
            DBG("Controller doesn't have SDMA capability\n");
    else
            host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci.c +2 -1
            host->flags &= ~SDHCI_USE_SDMA;
    }
 
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
            host->flags |= SDHCI_USE_ADMA;
 
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
drivers/mmc/host/sdhci.c +0 -0
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -1
    }
 
    if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+           host->max_clk = (caps[0] &

SDHCI_CLOCK_V3_BASE_MASK)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -1
                    >> SDHCI_CLOCK_BASE_SHIFT;
    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
                    >> SDHCI_CLOCK_BASE_SHIFT;
 
    host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
    }
 
    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >>
Quoted 8 lines
Quoted 8 lines

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 7 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -0
+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>
 SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) {
                    host->timeout_clk = host->ops-
Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +0 -0
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -1
                    return -ENODEV;
            }
    }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
            host->timeout_clk *= 1000;
 
Quoted 22 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
    /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 19 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
    if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
            mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)
            mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 12 lines
Quoted 12 lines
drivers/mmc/host/sdhci.c +7 -0
    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
        mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_SDR50;

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

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

Quoted 10 lines
drivers/mmc/host/sdhci.c +8 -1
+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;
+
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+
    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the Host

System

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 2042

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+    * can afford more than 150mA, Host Driver should set XPC

to

Quoted 43 lines

1.

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

Also
+ * the value is meaningful only if Voltage Support in the
Capabilities
+ * register is set. The actual current value is 4 times the
register

drivers/mmc/host/sdhci.c +31 -2
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+
            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK) >>
+                              SDHCI_MAX_CURRENT_330_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+
            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK) >>
+                              SDHCI_MAX_CURRENT_300_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+
            ocr_avail |= MMC_VDD_165_195;
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK) >>
+                              SDHCI_MAX_CURRENT_180_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci.c +4 -0
+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+
    mmc->ocr_avail = ocr_avail;
    mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
    if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
            mmc->max_blk_size = 2;
    } else {
-           mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK)
 
+           mmc->max_blk_size = (caps[0] &

SDHCI_MAX_BLOCK_MASK)

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
                            SDHCI_MAX_BLOCK_SHIFT;
            if (mmc->max_blk_size >= 3) {

printk(KERN_WARNING "%s: Invalid maximum

block

Quoted 3 lines

size,

Quoted 2 lines

Review

Quoted 2 lines

"

(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.h

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

index 223762c..95d70e6 100644

drivers/mmc/host/sdhci.h +16 -2
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE      0x00000800
 #define  SDHCI_CARD_PRESENT        0x00010000
 #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
 #define SDHCI_HOST_CONTROL         0x28
 #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
 #define SDHCI_CAPABILITIES 0x40
 #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180 0x04000000
 #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
 #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/host/sdhci.h +0 -0
 /* 4C-4F reserved for more max current */
 
(quoted diff) +0 -0

b/include/linux/mmc/host.h

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

include/linux/mmc/host.h struct mmc_host_ops { · line 119

Quoted 7 lines

index bcb793e..ad7daa3 100644

include/linux/mmc/host.h +0 -0
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
    /* optional callback for HC quirks */
    void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

Quoted 2 lines
Quoted 2 lines
include/linux/mmc/host.h +2 -0
+
+   int     (*start_signal_voltage_switch)(struct mmc_host
Quoted 8 lines

*host);

Quoted 5 lines
Quoted 5 lines

include/linux/mmc/host.h struct mmc_host { · line 175

Quoted 5 lines
include/linux/mmc/host.h +0 -0
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                            /* DDR mode at 1.2V

*/

Quoted 1 line
Quoted 1 line
Quoted 1 line
include/linux/mmc/host.h +0 -0
 #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can

power

Quoted 8 lines
Quoted 4 lines

off

Quoted 3 lines

after

Quoted 2 lines

boot */
#define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /*

CMD14/CMD19

Quoted 3 lines

bus

Quoted 2 lines
Quoted 2 lines

width ok */
+#define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports

UHS

Quoted 15 lines
Quoted 15 lines

DDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host

supports >150mA

Quoted 3 lines
Quoted 3 lines

current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm

features */

Quoted 1 line
Quoted 1 line
Quoted 27 lines
Quoted 6 lines
Quoted 6 lines

include/linux/mmc/sd.h line 17

Quoted 6 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some

quirks.

Quoted 20 lines
Quoted 2 lines

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines

include/linux/mmc/sd.h line 20

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */
   /* class 10 */

#define SD_SWITCH 6 /* adtc [31:0] See below

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe

linux-

Quoted 10 lines
Quoted 4 lines

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-

info.html

Quoted 5 lines
Quoted 1 line

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 4 lines

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw

Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 154 lines · Subhash Jadavani
Quoted 110 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:59 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Subhash,

Quoted 19 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 12 lines
Quoted 12 lines

switch procedure

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

Quoted 9 lines

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 2 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to

modify

Quoted 4 lines
Quoted 3 lines

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage

level

Quoted 12 lines
Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 4 lines
Quoted 2 lines

driver
would then perform above operation in their handler (modifying

relevant

Quoted 1 line

controller register and setting the voltage level) along with

SD3.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

spec
requirements.

Now let's say after all above initialization and some data

transfer

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the

above

Quoted 2 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level back

from

Quoted 14 lines
Quoted 9 lines

1.8v

Quoted 8 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios which specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v, 1 = 1.8v).
This entry would be set once start_signal_voltage_switch ops

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is inserted, at

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets called

Quoted 9 lines

with

Quoted 6 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and CMD

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we simply

not

Quoted 1 line

reset 1.8V signaling enable in the Host Control2 register when a

card

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is

removed

Quoted 1 line

(assuming that there is no hardware based card detection available)?

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Sorry. But again I have to make this point clear. It's not necessary that all host controller implementation would be same as your host controller implementation. In our host controller we don't have any such status bit for card removal event.

Quoted 6 lines
Quoted 6 lines

And I
don't think host controller driver itself should take decision to revert
back from 1.8v to 3.3v until core layer tells it do so.

Quoted 8 lines
Quoted 1 line

Regarding clearing the bit in Host Control2 register, it's specific

to

Quoted 2 lines

your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be reset to set the signaling voltage back to 3.3V.

Same as my above comment.

Quoted 12 lines

 and also

Quoted 9 lines

some
controller might have to do something extra than setting few bits in controller registers. In our case for switching from 3.3v to 1.8v, other
than setting one of the controller register bit, we also need to set the
voltage level of a regulator which is powering these interface pins CMD,
DATA, CLK.

Quoted 7 lines
Quoted 2 lines

In that case I will modify the code to add an entry into mmc_ios as per your suggestion.

What about removing start_signal_voltage_switch ops itself and just adding one entry in ios for voltage_switch? Whenever you want to switch the voltage level from 1.8v to 2.7v call set_ios() with this new entry set and when you want to go back from 1.8v to 2.7v call set_ios() with this new entry reset.

Not sure set_ios is a good place to change voltage, which need some time to wait for voltage to be stable, no matter voltage provided by controller or external pmic, while set_ios is protected by spin_lock. Besides, find start_signal_voltage_switch is not protected by spin_lock when accessing register, it would be not safe.

Quoted 678 lines
Quoted 675 lines

Thanks,
Arindam

Quoted 19 lines
Quoted 19 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

Quoted 3 lines
Quoted 3 lines

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

switch procedure

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The

spec

Quoted 1 line
Quoted 1 line
Quoted 1 line

doesn't mention about explicit support for SDR12 and SDR25 UHS-

I

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

modes, so the Host Controller v3.00 should support them by

default.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also if the controller support SDR104 mode, it will also

support

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SDR50 mode as well. So depending on the host support, we set

the

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

corresponding MMC_CAP_* flags. One more new register. Host

Control2

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We

also

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

need to set XPC (bit 28) of OCR in case the host can supply

150mA.

Quoted 4 lines
Quoted 4 lines

This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

signal voltage switch procedure, which if successfull, will

switch

Quoted 1 line
Quoted 1 line
Quoted 1 line

the card from 3.3V signalling to 1.8V signalling. Signal

voltage

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need

to

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

set 1.8V Signalling Enable (bit 3) of Host Control2 register,

which

Quoted 1 line
Quoted 1 line
Quoted 1 line

if remains set after 5ms, means the switch to 1.8V signalling

is

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +

 7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +1 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
  int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
  {
     int err;
+   u32 rocr;
 
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host,

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
     /*
      * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host,

u32

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +1 -1
 ocr, u32 *cid)
     if (!err)
             ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be

set

Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1. */
+   if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300

|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;

+   /*
+    * In case CCS and S18A in the response is set, start

Signal

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

Voltage
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else

drivers/mmc/core/sd.c +0 -0
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
     }
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 846

Quoted 2 lines
drivers/mmc/core/sd.c +1 -0
     /*
+    * If the host supports one of UHS-I modes, request the

card

Quoted 72 lines
Quoted 23 lines
Quoted 4 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host)

Quoted 4 lines
drivers/mmc/core/sd.c +4 -0
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +12 -2
+           host->ocr |= (1 << 24);
+
+   /*
      * Detect and init the card.
      */
     err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
     mmc_release_host(host);
     err = mmc_add_card(host->card);
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.c

Quoted 45 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card

Quoted 4 lines

index 797cdb5..8a23e2e 100644

drivers/mmc/core/sd_ops.c +0 -0
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card

*card,

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
 int width)
     return 0;
  }
 
Quoted 9 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 9 lines
drivers/mmc/core/sd_ops.c +9 -0
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch

procedure,

Quoted 17 lines
Quoted 17 lines

we
+    * set S18R to 0, and then retry initialization sequence.
+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;

drivers/mmc/core/sd_ops.c +12 -0
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines
Quoted 8 lines

+           return -EIO;

drivers/mmc/core/sd_ops.c +6 -0
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+

 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32

*rocr)

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines

 {
    struct mmc_command cmd;

(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.h

Quoted 4 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.h int mmc_app_send_scr(struct mmc_card *card,

Quoted 4 lines

index ffc2305..3cfba59 100644

drivers/mmc/core/sd_ops.h +0 -0
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card,

u32

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
drivers/mmc/core/sd_ops.h +1 -0
 *scr);
  int mmc_sd_switch(struct mmc_card *card, int mode, int group,
     u8 value, u8 *resp);
  int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
  #endif
(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.c

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host

Quoted 4 lines

index 8914a25..5487a0b 100644

drivers/mmc/host/sdhci.c +0 -0
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host

*host)

Quoted 1 line
Quoted 1 line

    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max

curr:

Quoted 36 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND), sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));

    if (host->flags & SDHCI_USE_ADMA) printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |

Quoted 7 lines

ADMA

Quoted 6 lines

drivers/mmc/host/sdhci.c out: · line 1342

Quoted 6 lines

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +1 -0
@@ -1337,11 +1339,70 @@ out:
     spin_unlock_irqrestore(&host->lock, flags);
  }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host

*mmc)

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +11 -0
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +7 -0
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host Control2

register

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +3 -0
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c out:

Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
+                   /* Provide SDCLK again and wait for 1ms*/
+                   clk = sdhci_readw(host,

SDHCI_CLOCK_CONTROL);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c out: · line 1375

Quoted 2 lines
drivers/mmc/host/sdhci.c +2 -0
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk,

SDHCI_CLOCK_CONTROL);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c out:

Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the

card

Quoted 6 lines
Quoted 6 lines

was

Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +4 -0
+                    * successfully switched to 1.8V signaling.
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state & SDHCI_DATA_LVL_MASK)

==

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/mmc/host/sdhci.c +8 -0
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V signaling

failed. Stop
+    * power to the card, and retry initialization sequence by setting S18R
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);

drivers/mmc/host/sdhci.c +4 -0
+
+   return -EAGAIN;
+}
+

 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
    .get_ro         = sdhci_get_ro,
    .enable_sdio_irq = sdhci_enable_sdio_irq,

Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+   .start_signal_voltage_switch    =
sdhci_start_signal_voltage_switch,
 };

/**********************************************************************

Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*******\

drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
  int sdhci_add_host(struct sdhci_host *host)
  {
     struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
     int ret;
 
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
     WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
                     host->version);
     }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps
:

Quoted 5 lines
Quoted 5 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 1888

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps

Quoted 3 lines

:
            sdhci_readl(host, SDHCI_CAPABILITIES);

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 11 lines

+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1); +
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA) host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA)) DBG("Controller doesn't have SDMA capability\n"); else
            host->flags |= SDHCI_USE_SDMA;

drivers/mmc/host/sdhci.c +0 -0
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci.c +2 -1
             host->flags &= ~SDHCI_USE_SDMA;
     }
 
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
             host->flags |= SDHCI_USE_ADMA;
 
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines

    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&

drivers/mmc/host/sdhci.c +0 -0
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -1
     }
 
     if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+           host->max_clk = (caps[0] &

SDHCI_CLOCK_V3_BASE_MASK)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci.c +0 -0
                     >> SDHCI_CLOCK_BASE_SHIFT;

    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;

    host->max_clk *= 1000000;

drivers/mmc/host/sdhci.c +0 -0
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
     }
 

    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >>

Quoted 8 lines
Quoted 8 lines

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 7 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 7 lines

+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) { host->timeout_clk = host->ops-

Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +0 -0
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/mmc/host/sdhci.c +1 -1
                     return -ENODEV;
             }
     }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
             host->timeout_clk *= 1000;
 
Quoted 22 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
     /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
     if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
             mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)

            mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 12 lines
Quoted 12 lines

    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;

+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25; +
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_SDR50;

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;

drivers/mmc/host/sdhci.c +4 -0
+
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+

    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the Host

System

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+    * can afford more than 150mA, Host Driver should set XPC

to

Quoted 43 lines

1.

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

Also
+    * the value is meaningful only if Voltage Support in the Capabilities
+    * register is set. The actual current value is 4 times the register
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);

drivers/mmc/host/sdhci.c +4 -0
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+

            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)

drivers/mmc/host/sdhci.c +12 -0
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK) >>
+                              SDHCI_MAX_CURRENT_330_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+

            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)

drivers/mmc/host/sdhci.c +12 -0
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK) >>
+                              SDHCI_MAX_CURRENT_300_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER;
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+

            ocr_avail |= MMC_VDD_165_195;

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK) >>
+                              SDHCI_MAX_CURRENT_180_SHIFT) *
+                              SDHCI_MAX_CURRENT_MULTIPLIER; +

Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 8 lines

+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+
    mmc->ocr_avail = ocr_avail; mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)

drivers/mmc/host/sdhci.c +0 -0
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
     if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
             mmc->max_blk_size = 2;
     } else {
-           mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK)
 
+           mmc->max_blk_size = (caps[0] &

SDHCI_MAX_BLOCK_MASK)

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
                             SDHCI_MAX_BLOCK_SHIFT;
             if (mmc->max_blk_size >= 3) {

                    printk(KERN_WARNING "%s: Invalid maximum

block

Quoted 3 lines

size,

Quoted 2 lines

Review

Quoted 2 lines

"

(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.h

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

index 223762c..95d70e6 100644

drivers/mmc/host/sdhci.h +16 -2
@@ -69,6 +69,8 @@
  #define  SDHCI_DATA_AVAILABLE      0x00000800
  #define  SDHCI_CARD_PRESENT        0x00010000
  #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
  #define SDHCI_HOST_CONTROL         0x28
  #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
  #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
  #define SDHCI_CAPABILITIES 0x40
  #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
  #define  SDHCI_CAN_VDD_180 0x04000000
  #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
  #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/host/sdhci.h +0 -0
  /* 4C-4F reserved for more max current */
 
(quoted diff) +0 -0

b/include/linux/mmc/host.h

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

index bcb793e..ad7daa3 100644

include/linux/mmc/host.h +0 -0
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
     /* optional callback for HC quirks */

    void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

Quoted 2 lines
Quoted 2 lines

+
+   int     (*start_signal_voltage_switch)(struct mmc_host

Quoted 8 lines

*host);

Quoted 5 lines
Quoted 5 lines

include/linux/mmc/host.h struct mmc_host { · line 175

Quoted 5 lines

 };

 struct mmc_card;

include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
                                             /* DDR mode at 1.2V

*/

Quoted 1 line
Quoted 1 line
Quoted 1 line
include/linux/mmc/host.h +0 -0
  #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can

power

Quoted 8 lines
Quoted 4 lines

off

Quoted 3 lines

after

Quoted 2 lines

boot */
 #define MMC_CAP_BUS_WIDTH_TEST     (1 << 14)       /*

CMD14/CMD19

Quoted 3 lines

bus

Quoted 2 lines
Quoted 2 lines

width ok */
+#define MMC_CAP_UHS_SDR12  (1 << 15)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25  (1 << 16)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50  (1 << 17)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50  (1 << 19)       /* Host supports

UHS

Quoted 15 lines
Quoted 15 lines

DDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330        (1 << 20)       /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300        (1 << 21)       /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180        (1 << 22)       /* Host

supports >150mA

Quoted 3 lines
Quoted 3 lines

current at 1.8V */

    mmc_pm_flag_t           pm_caps;        /* supported pm

features */

Quoted 1 line
Quoted 1 line
Quoted 27 lines
Quoted 6 lines
Quoted 6 lines

include/linux/mmc/sd.h line 17

Quoted 6 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
  /* This is basically the same command as for MMC with some

quirks.

Quoted 20 lines
Quoted 2 lines

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
  #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines

include/linux/mmc/sd.h line 20

Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
  #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */

   /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe

linux-

Quoted 10 lines
Quoted 4 lines

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-

info.html

Quoted 5 lines
Quoted 1 line

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 4 lines

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#22 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Zhangfei,

Quoted 191 lines

-----Original Message-----
From: zhangfei gao [mailto:[email protected]]
Sent: Wednesday, March 16, 2011 8:33 AM
To: Subhash Jadavani; Nath, Arindam
Cc: [email protected]; [email protected]; [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 9 lines · Subhash Jadavani
Quoted 9 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:59 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Hi Subhash,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 62 lines
Quoted 62 lines
Quoted 12 lines

switch procedure

Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 12 lines
Quoted 12 lines

switch procedure

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

Quoted 9 lines

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 2 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to

modify

Quoted 4 lines
Quoted 3 lines

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage

level

Quoted 12 lines
Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 4 lines
Quoted 2 lines

driver
would then perform above operation in their handler (modifying

relevant

Quoted 1 line

controller register and setting the voltage level) along with

SD3.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

spec
requirements.

Now let's say after all above initialization and some data

transfer

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the

above

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level back

from

Quoted 5 lines
Quoted 5 lines

1.8v

Quoted 4 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios

which

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v,

1 =

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

1.8v).
This entry would be set once start_signal_voltage_switch ops

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is inserted,

at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets

called

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

with

Quoted 6 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and CMD

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we

simply

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

not

Quoted 1 line

reset 1.8V signaling enable in the Host Control2 register when a

card

Quoted 3 lines
Quoted 1 line

is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is

removed

Quoted 1 line

(assuming that there is no hardware based card detection

available)?

Quoted 5 lines
Quoted 3 lines

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Sorry. But again I have to make this point clear. It's not necessary

that

Quoted 1 line

all host controller implementation would be same as your host

controller

Quoted 1 line

implementation. In our host controller we don't have any such status

bit for

Quoted 9 lines

card removal event.

Quoted 7 lines
Quoted 7 lines

And I
don't think host controller driver itself should take decision to revert
back from 1.8v to 3.3v until core layer tells it do so.

Regarding clearing the bit in Host Control2 register, it's

specific

Quoted 6 lines
Quoted 6 lines

to

Quoted 2 lines

your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be reset

to

Quoted 9 lines
Quoted 1 line

set the signaling voltage back to 3.3V.

Same as my above comment.

Quoted 4 lines

and also

Quoted 2 lines

some
controller might have to do something extra than setting few bits

in

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

controller registers. In our case for switching from 3.3v to 1.8v, other
than setting one of the controller register bit, we also need to

set

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the
voltage level of a regulator which is powering these interface

pins

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

CMD,
DATA, CLK.

In that case I will modify the code to add an entry into mmc_ios as

per

Quoted 3 lines
Quoted 1 line

your suggestion.

What about removing start_signal_voltage_switch ops itself and just

adding

Quoted 1 line

one entry in ios for voltage_switch? Whenever you want to switch the

voltage

Quoted 1 line

level from 1.8v to 2.7v call set_ios() with this new entry set and

when you

Quoted 8 lines
Quoted 1 line

want to go back from 1.8v to 2.7v call set_ios() with this new entry

reset.

Not sure set_ios is a good place to change voltage, which need some time to wait for voltage to be stable, no matter voltage provided by controller or external pmic, while set_ios is protected by spin_lock. Besides, find start_signal_voltage_switch is not protected by spin_lock when accessing register, it would be not safe.

I agree with you. Moreover, as Nicolas mentioned in one of the discussions before, during signal voltage switching, there should not be any concurrent access, so we don't need locking anyways. That's why the current implementation has done away with locking. I am planning to implement using a variable inside mmc_ios and not part of set_ios(). This should be able to cater to the needs of all host controllers.

Thanks,
Arindam

Quoted 733 lines
Quoted 25 lines
Quoted 25 lines

Thanks,
Arindam

Quoted 19 lines
Quoted 19 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

switch procedure

Host Controller v3.00 adds another Capabilities register.

Apart

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

from other things, this new register indicates whether the

Host

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Controller supports SDR50, SDR104, and DDR50 UHS-I modes.

The

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

spec

Quoted 1 line
Quoted 1 line
Quoted 1 line

doesn't mention about explicit support for SDR12 and SDR25

UHS-

Quoted 10 lines
Quoted 10 lines

I

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

modes, so the Host Controller v3.00 should support them by

default.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also if the controller support SDR104 mode, it will also

support

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SDR50 mode as well. So depending on the host support, we set

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

corresponding MMC_CAP_* flags. One more new register. Host

Control2

Quoted 1 line
Quoted 1 line
Quoted 1 line

is added in v3.00, which is used during Signal Voltage

Switch

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set

S18R

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to 1, we set S18R (bit 24) of OCR before sending ACMD41. We

also

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

need to set XPC (bit 28) of OCR in case the host can supply

150mA.

Quoted 1 line
Quoted 1 line

This support is indicated by the Maximum Current

Capabilities

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we

start

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

signal voltage switch procedure, which if successfull, will

switch

Quoted 1 line
Quoted 1 line
Quoted 1 line

the card from 3.3V signalling to 1.8V signalling. Signal

voltage

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we

need

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

set 1.8V Signalling Enable (bit 3) of Host Control2

register,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

which

Quoted 1 line
Quoted 1 line
Quoted 1 line

if remains set after 5ms, means the switch to 1.8V

signalling

Quoted 16 lines
Quoted 16 lines

is

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +
 7 files changed, 229 insertions(+), 18 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/mmc/core/sd.c struct device_type sd_type = { · line 408

Quoted 6 lines
drivers/mmc/core/sd.c +0 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32

*cid)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host

Quoted 7 lines
drivers/mmc/core/sd.c +1 -0
 {
    int err;
+   u32 rocr;
 
    /*
     * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host

*host,

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines

u32

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +1 -1
 ocr, u32 *cid)
    if (!err)
            ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be

set

Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1. */
+ if (host->caps & (MMC_CAP_SET_XPC_330 |

MMC_CAP_SET_XPC_300

Quoted 11 lines
Quoted 11 lines

|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/sd.c

Quoted 9 lines
drivers/mmc/core/sd.c +6 -0
+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr);
    if (err)
            return err;
 
+   /*
+    * In case CCS and S18A in the response is set, start

Signal

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Voltage

drivers/mmc/core/sd.c +4 -0
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);
Quoted 8 lines

8 lines not shown · raw message

587 lines not shown · raw message

Part of this message is not shown here. View the raw message.

#23 lore raw

Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 197 lines · Arindam

Hi Zhangfei,

Quoted 194 lines

-----Original Message-----
From: zhangfei gao [mailto:[email protected]]
Sent: Wednesday, March 16, 2011 8:33 AM
To: Subhash Jadavani; Nath, Arindam
Cc: [email protected]; [email protected]; [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 9 lines · Subhash Jadavani
Quoted 9 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:59 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Hi Subhash,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 62 lines
Quoted 62 lines
Quoted 12 lines

switch procedure

Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 12 lines
Quoted 12 lines

switch procedure

Hi Subhash,

Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

Quoted 9 lines

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Arindam,

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 2 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to

modify

Quoted 4 lines
Quoted 3 lines

few

Quoted 2 lines

bits
in their controller registers and also have to set the voltage

level

Quoted 12 lines
Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 4 lines
Quoted 2 lines

driver
would then perform above operation in their handler (modifying

relevant

Quoted 1 line

controller register and setting the voltage level) along with

SD3.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

spec
requirements.

Now let's say after all above initialization and some data

transfer

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

with
UHS-I card, card is removed from the slot. Now if I insert the SDHC/SDSC
card (with SDv2.0 support) then how will controller undone the

above

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level back

from

Quoted 5 lines
Quoted 5 lines

1.8v

Quoted 4 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios

which

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specifies
the voltage level required for CLK, DATA, CMD pins (0 = 3.3v,

1 =

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

1.8v).
This entry would be set once start_signal_voltage_switch ops

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is inserted,

at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets

called

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

with

Quoted 6 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and CMD

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we

simply

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

not

Quoted 1 line

reset 1.8V signaling enable in the Host Control2 register when a

card

Quoted 3 lines
Quoted 1 line

is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is

removed

Quoted 1 line

(assuming that there is no hardware based card detection

available)?

Quoted 5 lines
Quoted 3 lines

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Sorry. But again I have to make this point clear. It's not necessary

that

Quoted 1 line

all host controller implementation would be same as your host

controller

Quoted 1 line

implementation. In our host controller we don't have any such status

bit for

Quoted 9 lines

card removal event.

Quoted 7 lines
Quoted 7 lines

And I
don't think host controller driver itself should take decision to revert
back from 1.8v to 3.3v until core layer tells it do so.

Regarding clearing the bit in Host Control2 register, it's

specific

Quoted 6 lines
Quoted 6 lines

to

Quoted 2 lines

your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be reset

to

Quoted 9 lines
Quoted 1 line

set the signaling voltage back to 3.3V.

Same as my above comment.

Quoted 4 lines

 and also

Quoted 2 lines

some
controller might have to do something extra than setting few bits

in

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

controller registers. In our case for switching from 3.3v to 1.8v, other
than setting one of the controller register bit, we also need to

set

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the
voltage level of a regulator which is powering these interface

pins

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

CMD,
DATA, CLK.

In that case I will modify the code to add an entry into mmc_ios as

per

Quoted 3 lines
Quoted 1 line

your suggestion.

What about removing start_signal_voltage_switch ops itself and just

adding

Quoted 1 line

one entry in ios for voltage_switch? Whenever you want to switch the

voltage

Quoted 1 line

level from 1.8v to 2.7v call set_ios() with this new entry set and

when you

Quoted 1 line

want to go back from 1.8v to 2.7v call set_ios() with this new entry

reset.

Quoted 7 lines
Quoted 5 lines

Not sure set_ios is a good place to change voltage, which need some time to wait for voltage to be stable, no matter voltage provided by controller or external pmic, while set_ios is protected by spin_lock. Besides, find start_signal_voltage_switch is not protected by spin_lock when accessing register, it would be not safe.

I agree with you. Moreover, as Nicolas mentioned in one of the discussions before, during signal voltage switching, there should not be any concurrent access, so we don't need locking anyways. That's why the current implementation has done away with locking. I am planning to implement using a variable inside mmc_ios and not part of set_ios(). This should be able to cater to the needs of all host controllers.

How about add spin_lock/unlock outside of sleep and protect the register accessing?

Quoted 744 lines

Thanks,
Arindam

Quoted 721 lines
Quoted 25 lines
Quoted 25 lines

Thanks,
Arindam

Quoted 19 lines
Quoted 19 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

switch procedure

Host Controller v3.00 adds another Capabilities register.

Apart

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

from other things, this new register indicates whether the

Host

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Controller supports SDR50, SDR104, and DDR50 UHS-I modes.

The

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

spec

Quoted 1 line
Quoted 1 line
Quoted 1 line

doesn't mention about explicit support for SDR12 and SDR25

UHS-

Quoted 10 lines
Quoted 10 lines

I

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

modes, so the Host Controller v3.00 should support them by

default.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also if the controller support SDR104 mode, it will also

support

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SDR50 mode as well. So depending on the host support, we set

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

corresponding MMC_CAP_* flags. One more new register. Host

Control2

Quoted 1 line
Quoted 1 line
Quoted 1 line

is added in v3.00, which is used during Signal Voltage

Switch

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set

S18R

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to 1, we set S18R (bit 24) of OCR before sending ACMD41. We

also

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

need to set XPC (bit 28) of OCR in case the host can supply

150mA.

Quoted 1 line
Quoted 1 line

This support is indicated by the Maximum Current

Capabilities

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we

start

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

signal voltage switch procedure, which if successfull, will

switch

Quoted 1 line
Quoted 1 line
Quoted 1 line

the card from 3.3V signalling to 1.8V signalling. Signal

voltage

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we

need

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

set 1.8V Signalling Enable (bit 3) of Host Control2

register,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

which

Quoted 1 line
Quoted 1 line
Quoted 1 line

if remains set after 5ms, means the switch to 1.8V

signalling

Quoted 16 lines
Quoted 16 lines

is

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---
 drivers/mmc/core/sd.c     |   37 ++++++++++-
 drivers/mmc/core/sd_ops.c |   32 ++++++++++
 drivers/mmc/core/sd_ops.h |    1 +
 drivers/mmc/host/sdhci.c  |  148
+++++++++++++++++++++++++++++++++++++++++----
 drivers/mmc/host/sdhci.h  |   18 +++++-
 include/linux/mmc/host.h  |   10 +++
 include/linux/mmc/sd.h    |    1 +

 7 files changed, 229 insertions(+), 18 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +0 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {

 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32

*cid)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host

Quoted 7 lines

 {
    int err;
+   u32 rocr;

    /*
     * Since we're changing the OCR value, we seem to

drivers/mmc/core/sd.c +0 -0
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host

*host,

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines

u32

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +1 -1
 ocr, u32 *cid)
     if (!err)
             ocr |= 1 << 30;
 
-   err = mmc_send_app_op_cond(host, ocr, NULL);
+   /* If the host can supply more than 150mA, XPC should be

set

Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1. */
+   if (host->caps & (MMC_CAP_SET_XPC_330 |

MMC_CAP_SET_XPC_300

Quoted 11 lines
Quoted 11 lines

|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+       MMC_CAP_SET_XPC_180))
+           ocr |= 1 << 28;
+
+   err = mmc_send_app_op_cond(host, ocr, &rocr); if (err)
            return err;

+   /*
+    * In case CCS and S18A in the response is set, start

Signal

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Voltage
+    * Switch procedure. SPI mode doesn't support CMD11.
+    */
+   if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
+           err = mmc_start_voltage_switch(host);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host

Quoted 8 lines

+           if (err)
+                   return err;
+   }
+
    if (mmc_host_is_spi(host))
            err = mmc_send_cid(host, cid);
    else

drivers/mmc/core/sd.c +0 -0
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host

*host)

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host · line 846

Quoted 4 lines
drivers/mmc/core/sd.c +1 -0
     }
 
     /*
+    * If the host supports one of UHS-I modes, request the

card

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mmc/core/sd.c +3 -0
+    * to switch to 1.8V signaling level.
+    */
+   if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25

|

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 1 line

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host · line 850

Quoted 1 line
drivers/mmc/core/sd.c +1 -0
+       MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +12 -2
+           host->ocr |= (1 << 24);
+
+   /*
      * Detect and init the card.
      */
     err = mmc_sd_init_card(host, host->ocr, NULL);
-   if (err)
-           goto err;
+   if (err == -EAGAIN) {
+           /*
+            * Retry initialization with S18R set to 0.
+            */
+           host->ocr &= ~(1 << 24);
+           err = mmc_sd_init_card(host, host->ocr, NULL);
+           if (err)
+                   goto err;
+   }
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/core/sd.c +0 -0
     mmc_release_host(host);
     err = mmc_add_card(host->card);
(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.c

Quoted 4 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct

Quoted 4 lines

index 797cdb5..8a23e2e 100644

drivers/mmc/core/sd_ops.c +0 -0
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct

mmc_card

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

*card,

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
 int width)
     return 0;
  }
 
Quoted 9 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct · line 158

Quoted 9 lines
drivers/mmc/core/sd_ops.c +9 -0
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+   struct mmc_command cmd;
+   int err;
+
+   BUG_ON(!host);
+
+   /*
+    * If the host does not provide signal voltage switch

procedure,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

we
+    * set S18R to 0, and then retry initialization

sequence.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

+    */
+   if (!host->ops->start_signal_voltage_switch)
+           return -EAGAIN;

drivers/mmc/core/sd_ops.c +12 -0
+
+   memset(&cmd, 0, sizeof(struct mmc_command));
+
+   cmd.opcode = SD_SWITCH_VOLTAGE;
+   cmd.arg = 0;
+   cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+   err = mmc_wait_for_cmd(host, &cmd, 0);
+   if (err)
+           return err;
+
+   if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+           return -EIO;

drivers/mmc/core/sd_ops.c +6 -0
+
+   err = host->ops->start_signal_voltage_switch(host);
+
+   return err;
+}
+

 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr,

u32

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

*rocr)

Quoted 3 lines

Review

Quoted 3 lines

 {
    struct mmc_command cmd;

(quoted diff) +0 -0

b/drivers/mmc/core/sd_ops.h

Quoted 4 lines
Quoted 4 lines

drivers/mmc/core/sd_ops.h int mmc_app_send_scr(struct mmc_card

Quoted 4 lines

index ffc2305..3cfba59 100644

drivers/mmc/core/sd_ops.h +0 -0
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card

*card,

Quoted 3 lines
Quoted 3 lines

u32

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/mmc/core/sd_ops.h +0 -0
 *scr);

 int mmc_sd_switch(struct mmc_card *card, int mode, int

group,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

    u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr); +int mmc_start_voltage_switch(struct mmc_host *host);

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines

 #endif

(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct

Quoted 4 lines

index 8914a25..5487a0b 100644

drivers/mmc/host/sdhci.c +0 -0
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct

sdhci_host

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

*host)

Quoted 1 line
Quoted 1 line

    printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max

curr:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

0x%08x\n",
            sdhci_readw(host, SDHCI_COMMAND), sdhci_readl(host, SDHCI_MAX_CURRENT));
+   printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+           sdhci_readw(host, SDHCI_HOST_CONTROL2));

    if (host->flags & SDHCI_USE_ADMA) printk(KERN_DEBUG DRIVER_NAME ": ADMA Err:

0x%08x |

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ADMA

Quoted 6 lines

drivers/mmc/host/sdhci.c out: · line 1342

Quoted 6 lines

Ptr: 0x%08x\n",

drivers/mmc/host/sdhci.c +1 -0
@@ -1337,11 +1339,70 @@ out:
     spin_unlock_irqrestore(&host->lock, flags);
  }
 
+static int sdhci_start_signal_voltage_switch(struct

mmc_host

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

*mmc)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/sdhci.c +11 -0
+{
+   struct sdhci_host *host;
+   u8 pwr;
+   u16 clk, ctrl;
+   u32 present_state;
+
+   host = mmc_priv(mmc);
+
+   /* Stop SDCLK */
+   host = mmc_priv(mmc);
+   clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/sdhci.c out: · line 1361

Quoted 8 lines
drivers/mmc/host/sdhci.c +7 -0
+   clk &= ~SDHCI_CLOCK_CARD_EN;
+   sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+   /* Check whether DAT[3:0] is 0000 */
+   present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+   if (!((present_state & SDHCI_DATA_LVL_MASK) >>
 SDHCI_DATA_LVL_SHIFT)) {
+           /* Enable 1.8V Signal Enable in the Host

Control2

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

register

Quoted 11 lines

drivers/mmc/host/sdhci.c out: · line 1372

Quoted 11 lines
drivers/mmc/host/sdhci.c +10 -0
 */
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           ctrl |= SDHCI_CTRL_VDD_180;
+           sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+           /* Wait for 5ms */
+           usleep_range(5000, 5500);
+
+           ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+           if (ctrl & SDHCI_CTRL_VDD_180) {
+                   /* Provide SDCLK again and wait for

1ms*/

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/mmc/host/sdhci.c out: · line 1373

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+                   clk = sdhci_readw(host,

SDHCI_CLOCK_CONTROL);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/mmc/host/sdhci.c +2 -0
+                   clk |= SDHCI_CLOCK_CARD_EN;
+                   sdhci_writew(host, clk,
Quoted 8 lines
Quoted 8 lines

SDHCI_CLOCK_CONTROL);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c out: · line 1379

Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+                   usleep_range(1000, 1500);
+
+                   /*
+                    * If DAT[3:0] level is 1111b, then the

card

Quoted 2 lines
Quoted 2 lines

was

Quoted 1 line
Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+                    * successfully switched to 1.8V

signaling.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c out: · line 1384

Quoted 4 lines
drivers/mmc/host/sdhci.c +3 -0
+                    */
+                   present_state = sdhci_readl(host,
 SDHCI_PRESENT_STATE);
+                   if ((present_state &

SDHCI_DATA_LVL_MASK)

Quoted 9 lines
Quoted 9 lines

==

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+                        SDHCI_DATA_LVL_MASK) {
+                           return 0;
+                   }
+           }
+   }
+
+   /*
+    * If we are here, that means the switch to 1.8V

signaling

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

failed. Stop
+    * power to the card, and retry initialization sequence

by

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

setting S18R
+    * to 0.
+    */
+   pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+   pwr &= ~SDHCI_POWER_ON;
+   sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);

drivers/mmc/host/sdhci.c +4 -0
+
+   return -EAGAIN;
+}
+

 static const struct mmc_host_ops sdhci_ops = {
    .request        = sdhci_request,
    .set_ios        = sdhci_set_ios,
    .get_ro         = sdhci_get_ro,
    .enable_sdio_irq = sdhci_enable_sdio_irq,
+   .start_signal_voltage_switch    =
sdhci_start_signal_voltage_switch,

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

 };

/**********************************************************************

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*******\

drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
  int sdhci_add_host(struct sdhci_host *host)
  {
     struct mmc_host *mmc;
-   unsigned int caps, ocr_avail;
+   u32 caps[2];
+   u32 max_current_caps;
+   unsigned int ocr_avail;
     int ret;
 
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
     WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 1825

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
                     host->version);
     }
 
-   caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps
:

Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+   caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ?

host-

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

caps

Quoted 5 lines

:
            sdhci_readl(host, SDHCI_CAPABILITIES);

+   if (host->version >= SDHCI_SPEC_300)
+           caps[1] = sdhci_readl(host,

SDHCI_CAPABILITIES_1);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+
    if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
            host->flags |= SDHCI_USE_SDMA;
-   else if (!(caps & SDHCI_CAN_DO_SDMA))
+   else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
            DBG("Controller doesn't have SDMA

capability\n");

Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 3 lines

    else
            host->flags |= SDHCI_USE_SDMA;

drivers/mmc/host/sdhci.c +0 -0
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci.c +2 -1
             host->flags &= ~SDHCI_USE_SDMA;
     }
 
-   if ((host->version >= SDHCI_SPEC_200) && (caps &
 SDHCI_CAN_DO_ADMA2))
+   if ((host->version >= SDHCI_SPEC_200) &&
+           (caps[0] & SDHCI_CAN_DO_ADMA2))
             host->flags |= SDHCI_USE_ADMA;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 2 lines

    if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&

drivers/mmc/host/sdhci.c +0 -0
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
     }
 
     if (host->version >= SDHCI_SPEC_300)
-           host->max_clk = (caps &

SDHCI_CLOCK_V3_BASE_MASK)

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 1962

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+           host->max_clk = (caps[0] &

SDHCI_CLOCK_V3_BASE_MASK)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
                     >> SDHCI_CLOCK_BASE_SHIFT;

    else
-           host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+           host->max_clk = (caps[0] &

SDHCI_CLOCK_BASE_MASK)

Quoted 31 lines
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 4 lines

                    >> SDHCI_CLOCK_BASE_SHIFT;

    host->max_clk *= 1000000;

drivers/mmc/host/sdhci.c +0 -0
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
     }
 

    host->timeout_clk =
-           (caps & SDHCI_TIMEOUT_CLK_MASK) >>

Quoted 8 lines
Quoted 8 lines

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 7 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 7 lines

+           (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
    if (host->timeout_clk == 0) {
            if (host->ops->get_timeout_clock) { host->timeout_clk = host->ops-

Quoted 1 line

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +0 -0
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 9 lines
drivers/mmc/host/sdhci.c +1 -1
                     return -ENODEV;
             }
     }
-   if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+   if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
             host->timeout_clk *= 1000;
 
     /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mmc/host/sdhci.c +0 -0
     if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
             mmc->caps |= MMC_CAP_4_BIT_DATA;
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
drivers/mmc/host/sdhci.c +1 -1
-   if (caps & SDHCI_CAN_DO_HISPD)
+   if (caps[0] & SDHCI_CAN_DO_HISPD)

            mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 2 lines
Quoted 2 lines

    if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)

&&

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

        mmc_card_is_removable(mmc))
            mmc->caps |= MMC_CAP_NEEDS_POLL;

+   /* UHS-I mode(s) supported by the host controller. */
+   if (host->version >= SDHCI_SPEC_300)
+           mmc->caps |= MMC_CAP_UHS_SDR12 |

MMC_CAP_UHS_SDR25;

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+
+   /* SDR104 supports also implies SDR50 support */
+   if (caps[1] & SDHCI_SUPPORT_SDR104)
+           mmc->caps |= MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_SDR50;

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

+   else if (caps[1] & SDHCI_SUPPORT_SDR50)
+           mmc->caps |= MMC_CAP_UHS_SDR50;

drivers/mmc/host/sdhci.c +4 -0
+
+   if (caps[1] & SDHCI_SUPPORT_DDR50)
+           mmc->caps |= MMC_CAP_UHS_DDR50;
+

    ocr_avail = 0;
-   if (caps & SDHCI_CAN_VDD_330)
+   /*
+    * According to SD Host Controller spec v3.00, if the

Host

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

System

Quoted 1 line
Quoted 1 line

+    * can afford more than 150mA, Host Driver should set

XPC

Quoted 4 lines
Quoted 4 lines

to

Quoted 3 lines

1.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Also
+    * the value is meaningful only if Voltage Support in

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Capabilities
+    * register is set. The actual current value is 4 times

the

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

register
+    * value.
+    */
+   max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);

drivers/mmc/host/sdhci.c +4 -0
+
+   if (caps[0] & SDHCI_CAN_VDD_330) {
+           int max_current_330;
+

            ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-   if (caps & SDHCI_CAN_VDD_300)
+
+           max_current_330 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_330_MASK)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+                              SDHCI_MAX_CURRENT_330_SHIFT)

*

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

+                              SDHCI_MAX_CURRENT_MULTIPLIER;

drivers/mmc/host/sdhci.c +7 -0
+
+           if (max_current_330 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_330;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_300) {
+           int max_current_300;
+

            ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-   if (caps & SDHCI_CAN_VDD_180)
+
+           max_current_300 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_300_MASK)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+                              SDHCI_MAX_CURRENT_300_SHIFT)

*

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

+                              SDHCI_MAX_CURRENT_MULTIPLIER;

drivers/mmc/host/sdhci.c +7 -0
+
+           if (max_current_300 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_300;
+   }
+   if (caps[0] & SDHCI_CAN_VDD_180) {
+           int max_current_180;
+

            ocr_avail |= MMC_VDD_165_195;

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+           max_current_180 = ((max_current_caps &
+                              SDHCI_MAX_CURRENT_180_MASK)

+                              SDHCI_MAX_CURRENT_180_SHIFT)

*

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host

Quoted 10 lines

+                              SDHCI_MAX_CURRENT_MULTIPLIER;

drivers/mmc/host/sdhci.c +5 -0
+
+           if (max_current_180 > 150)
+                   mmc->caps |= MMC_CAP_SET_XPC_180;
+   }
+

    mmc->ocr_avail = ocr_avail;
    mmc->ocr_avail_sdio = ocr_avail;
    if (host->ocr_avail_sdio)

drivers/mmc/host/sdhci.c +0 -0
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host

*host)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 2027

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
     if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
             mmc->max_blk_size = 2;
     } else {
-           mmc->max_blk_size = (caps &

SDHCI_MAX_BLOCK_MASK)

Quoted 58 lines
Quoted 58 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host · line 2149

Quoted 2 lines
drivers/mmc/host/sdhci.c +1 -0
+           mmc->max_blk_size = (caps[0] &

SDHCI_MAX_BLOCK_MASK)

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -0
                             SDHCI_MAX_BLOCK_SHIFT;
             if (mmc->max_blk_size >= 3) {

                    printk(KERN_WARNING "%s: Invalid maximum

block

Quoted 3 lines

size,

Quoted 2 lines

Review

Quoted 2 lines

"

(quoted diff) +0 -0

b/drivers/mmc/host/sdhci.h

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

index 223762c..95d70e6 100644

drivers/mmc/host/sdhci.h +16 -2
@@ -69,6 +69,8 @@
  #define  SDHCI_DATA_AVAILABLE      0x00000800
  #define  SDHCI_CARD_PRESENT        0x00010000
  #define  SDHCI_WRITE_PROTECT       0x00080000
+#define  SDHCI_DATA_LVL_MASK       0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT     20
 
  #define SDHCI_HOST_CONTROL         0x28
  #define  SDHCI_CTRL_LED            0x01
@@ -147,7 +149,8 @@
 
  #define SDHCI_ACMD12_ERR   0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2                0x3E
+#define  SDHCI_CTRL_VDD_180                0x0008
 
  #define SDHCI_CAPABILITIES 0x40
  #define  SDHCI_TIMEOUT_CLK_MASK    0x0000003F
@@ -168,9 +171,20 @@
  #define  SDHCI_CAN_VDD_180 0x04000000
  #define  SDHCI_CAN_64BIT   0x10000000
 
+#define  SDHCI_SUPPORT_SDR50       0x00000001
+#define  SDHCI_SUPPORT_SDR104      0x00000002
+#define  SDHCI_SUPPORT_DDR50       0x00000004
+
  #define SDHCI_CAPABILITIES_1       0x44
 
-#define SDHCI_MAX_CURRENT  0x48
+#define SDHCI_MAX_CURRENT          0x48
+#define  SDHCI_MAX_CURRENT_330_MASK        0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT       0
+#define  SDHCI_MAX_CURRENT_300_MASK        0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT       8
+#define  SDHCI_MAX_CURRENT_180_MASK        0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT       16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER     4
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/mmc/host/sdhci.h +0 -0
  /* 4C-4F reserved for more max current */
 
(quoted diff) +0 -0

b/include/linux/mmc/host.h

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

index bcb793e..ad7daa3 100644

include/linux/mmc/host.h +0 -0
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
     /* optional callback for HC quirks */

    void    (*init_card)(struct mmc_host *host, struct

mmc_card

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

*card);

Quoted 2 lines
Quoted 2 lines

+
+   int     (*start_signal_voltage_switch)(struct mmc_host

*host);

Quoted 5 lines
Quoted 5 lines

include/linux/mmc/host.h struct mmc_host { · line 175

Quoted 5 lines

 };

 struct mmc_card;

include/linux/mmc/host.h +0 -0
@@ -173,6 +175,14 @@ struct mmc_host {
                                             /* DDR mode at

1.2V

Quoted 50 lines
Quoted 50 lines
Quoted 2 lines

*/

Quoted 1 line
Quoted 1 line
Quoted 1 line
include/linux/mmc/host.h +0 -0
  #define MMC_CAP_POWER_OFF_CARD     (1 << 13)       /* Can

power

Quoted 8 lines
Quoted 4 lines

off

Quoted 3 lines

after

Quoted 2 lines

boot */
 #define MMC_CAP_BUS_WIDTH_TEST     (1 << 14)       /*

CMD14/CMD19

Quoted 3 lines

bus

Quoted 2 lines
Quoted 2 lines

width ok */
+#define MMC_CAP_UHS_SDR12  (1 << 15)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR12

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR25  (1 << 16)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR25

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR50  (1 << 17)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_SDR104 (1 << 18)       /* Host supports

UHS

Quoted 3 lines
Quoted 3 lines

SDR104

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_UHS_DDR50  (1 << 19)       /* Host supports

UHS

Quoted 22 lines
Quoted 13 lines

DDR50

Quoted 2 lines
Quoted 2 lines

mode */
+#define MMC_CAP_SET_XPC_330        (1 << 20)       /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.3V */
+#define MMC_CAP_SET_XPC_300        (1 << 21)       /* Host

supports >150mA

Quoted 2 lines
Quoted 2 lines

current at 3.0V */
+#define MMC_CAP_SET_XPC_180        (1 << 22)       /* Host

supports >150mA

Quoted 3 lines
Quoted 3 lines

current at 1.8V */

    mmc_pm_flag_t           pm_caps;        /* supported pm

Quoted 8 lines

features */

Quoted 7 lines

include/linux/mmc/sd.h line 17

Quoted 7 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
  /* This is basically the same command as for MMC with some

quirks.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

*/

Quoted 1 line
include/linux/mmc/sd.h +0 -0
  #define SD_SEND_RELATIVE_ADDR     3   /* bcr

R6

Quoted 2 lines
Quoted 2 lines
include/linux/mmc/sd.h +0 -0
 */
  #define SD_SEND_IF_COND           8   /* bcr  [11:0] See

below

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

R7

Quoted 2 lines

include/linux/mmc/sd.h line 22

Quoted 2 lines
include/linux/mmc/sd.h +1 -0
 */
+#define SD_SWITCH_VOLTAGE         11  /* ac

R1

Quoted 4 lines
Quoted 4 lines
include/linux/mmc/sd.h +0 -0
 */

   /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See

below

Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines

R1

Quoted 6 lines
Quoted 6 lines

*/
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe

linux-

Quoted 8 lines
Quoted 4 lines

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-

info.html

Quoted 3 lines
Quoted 1 line
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-

mmc"

Quoted 3 lines

in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-

info.html

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

--
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

#24 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Zhangfei,

Quoted 243 lines

-----Original Message-----
From: zhangfei gao [mailto:[email protected]]
Sent: Wednesday, March 16, 2011 4:14 PM
To: Nath, Arindam
Cc: Subhash Jadavani; [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Quoted 8 lines · Arindam

Hi Zhangfei,

Quoted 5 lines

-----Original Message-----
From: zhangfei gao [mailto:[email protected]]
Sent: Wednesday, March 16, 2011 8:33 AM
To: Subhash Jadavani; Nath, Arindam
Cc: [email protected]; [email protected]; [email protected];

Su,

Quoted 2 lines
Quoted 2 lines

Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 31 lines
Quoted 31 lines

switch procedure

Quoted 9 lines · Subhash Jadavani
Quoted 9 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:59 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Hi Subhash,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 4:49 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

switch procedure

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Nath, Arindam
Sent: Tuesday, March 15, 2011 4:03 PM
To: Subhash Jadavani; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron;

[email protected]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

Subject: RE: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 5 lines
Quoted 5 lines

switch procedure

Hi Subhash,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Tuesday, March 15, 2011 3:48 PM
To: Nath, Arindam; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Su, Henry; Lu, Aaron;

[email protected]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Subject: RE: [PATCH v2 02/12] mmc: sd: add support for

signal

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

voltage

Quoted 4 lines
Quoted 4 lines

switch procedure

Arindam,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

During voltage switch, voltage level for CLK, DATA and CMD

pads/pins

Quoted 2 lines
Quoted 2 lines

should
be changed from 3.3v to 1.8v. for this SD controller has to

modify

Quoted 3 lines
Quoted 3 lines

few

Quoted 2 lines

bits
in their controller registers and also have to set the

voltage

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

level

Quoted 7 lines

of

Quoted 4 lines

a
regulator which is powering those pad/pins.

Now with you current patch, you are calling

start_signal_voltage_switch

Quoted 1 line

mmc_ops when you want to switch from 3.3v to 1.8v and each

controller

Quoted 2 lines
Quoted 2 lines

driver
would then perform above operation in their handler

(modifying

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

relevant

Quoted 1 line

controller register and setting the voltage level) along

with

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

SD3.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

spec
requirements.

Now let's say after all above initialization and some data

transfer

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

with
UHS-I card, card is removed from the slot. Now if I insert

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

SDHC/SDSC
card (with SDv2.0 support) then how will controller undone

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

above

Quoted 2 lines
Quoted 2 lines

voltage
switch operations (means changing pad/ping voltage level

back

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

from

Quoted 5 lines
Quoted 5 lines

1.8v

Quoted 4 lines

to
3.3v)?

To avoid above issue, we can have one new entry in mmc_ios

which

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specifies
the voltage level required for CLK, DATA, CMD pins (0 =

3.3v,

Quoted 3 lines
Quoted 3 lines

1 =

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1.8v).
This entry would be set once start_signal_voltage_switch

ops

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

returns

Quoted 1 line
Quoted 1 line

success. So now when card is removed and new card is

inserted,

Quoted 8 lines
Quoted 8 lines

at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

start
of initialization we should make sure that set_ios() gets

called

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

with

Quoted 2 lines
Quoted 2 lines

this
entry reset (0) which would make sure that CLK, DATA and

CMD

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

pads/pins

Quoted 1 line

voltage level back to 3.3v.

Rather than following the procedure mentioned above, can we

simply

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

not

Quoted 1 line

reset 1.8V signaling enable in the Host Control2 register

when a

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

card

Quoted 3 lines
Quoted 1 line

is removed? Will that serve the purpose?

How will the host controller driver comes to know that card is

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

removed

Quoted 1 line

(assuming that there is no hardware based card detection

available)?

Quoted 5 lines
Quoted 3 lines

Correct me if wrong, but I think bit 7 of Normal Interrupt Status Register can inform regarding the card removal event.

Sorry. But again I have to make this point clear. It's not

necessary

Quoted 4 lines
Quoted 4 lines

that

Quoted 1 line

all host controller implementation would be same as your host

controller

Quoted 1 line

implementation. In our host controller we don't have any such

status

Quoted 6 lines
Quoted 6 lines

bit for

Quoted 5 lines

card removal event.

Quoted 3 lines
Quoted 3 lines

And I
don't think host controller driver itself should take decision

to

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

revert
back from 1.8v to 3.3v until core layer tells it do so.

Regarding clearing the bit in Host Control2 register, it's

specific

Quoted 6 lines
Quoted 6 lines

to

Quoted 2 lines

your
controller. Not all controllers/platform will have same bits

As part of signal voltage switch procedure, we set 1.8V signaling enable in the Host Control2 register. So the same bit can be

reset

Quoted 10 lines
Quoted 10 lines

to

Quoted 9 lines
Quoted 1 line

set the signaling voltage back to 3.3V.

Same as my above comment.

Quoted 4 lines

and also

Quoted 2 lines

some
controller might have to do something extra than setting few

bits

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line
Quoted 1 line
Quoted 1 line

controller registers. In our case for switching from 3.3v to

1.8v,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

other
than setting one of the controller register bit, we also need

to

Quoted 8 lines
Quoted 8 lines

set

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the
voltage level of a regulator which is powering these interface

pins

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

CMD,
DATA, CLK.

In that case I will modify the code to add an entry into mmc_ios

as

Quoted 4 lines
Quoted 4 lines

per

Quoted 3 lines
Quoted 1 line

your suggestion.

What about removing start_signal_voltage_switch ops itself and

just

Quoted 2 lines
Quoted 2 lines

adding

Quoted 1 line

one entry in ios for voltage_switch? Whenever you want to switch

the

Quoted 4 lines
Quoted 4 lines

voltage

Quoted 1 line

level from 1.8v to 2.7v call set_ios() with this new entry set and

when you

Quoted 1 line

want to go back from 1.8v to 2.7v call set_ios() with this new

entry

Quoted 5 lines
Quoted 5 lines

reset.

Not sure set_ios is a good place to change voltage, which need some time to wait for voltage to be stable, no matter voltage provided by controller or external pmic, while set_ios is protected by

spin_lock.

Quoted 4 lines
Quoted 2 lines

Besides, find start_signal_voltage_switch is not protected by spin_lock when accessing register, it would be not safe.

I agree with you. Moreover, as Nicolas mentioned in one of the

Quoted 8 lines

discussions before, during signal voltage switching, there should not be any concurrent access, so we don't need locking anyways. That's why the current implementation has done away with locking. I am planning to implement using a variable inside mmc_ios and not part of set_ios(). This should be able to cater to the needs of all host controllers.

How about add spin_lock/unlock outside of sleep and protect the register accessing?

But if we cannot have concurrent access to start_signal_voltage_switch(), why do we need locking?

Thanks,
Arindam

Quoted 808 lines
Quoted 38 lines

Thanks,
Arindam

Quoted 34 lines
Quoted 25 lines
Quoted 25 lines

Thanks,
Arindam

Quoted 19 lines
Quoted 19 lines

Thanks,
Arindam

Quoted 12 lines

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-mmc- [email protected]] On Behalf Of Arindam Nath
Sent: Friday, March 04, 2011 5:03 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; Arindam Nath
Subject: [PATCH v2 02/12] mmc: sd: add support for signal

voltage

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

switch procedure

Host Controller v3.00 adds another Capabilities register.

Apart

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

from other things, this new register indicates whether

the

Quoted 5 lines
Quoted 5 lines

Host

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Controller supports SDR50, SDR104, and DDR50 UHS-I modes.

3 lines not shown · raw message

764 lines not shown · raw message

Part of this message is not shown here. View the raw message.

#25 lore raw

Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

In reply to Arindam Nath

Hi Arindam,

was getting kernel crash on SD card -- fix is below

Philip

Quoted 59 lines · Arindam Nath

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

---

drivers/mmc/core/sd.c     |   37 ++++++++++-
drivers/mmc/core/sd_ops.c |   32 ++++++++++
drivers/mmc/core/sd_ops.h |    1 +
drivers/mmc/host/sdhci.c  |  148 +++++++++++++++++++++++++++++++++++++++++----
drivers/mmc/host/sdhci.h  |   18 +++++-
include/linux/mmc/host.h  |   10 +++
include/linux/mmc/sd.h    |    1 +
7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +5 -1
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
       int err;
+       u32 rocr;
 
       /*
        * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
       if (!err)
               ocr |= 1 << 30;
 
-       err = mmc_send_app_op_cond(host, ocr, NULL);
+       /* If the host can supply more than 150mA, XPC should be set to 1. */
+       if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+           MMC_CAP_SET_XPC_180))
+               ocr |= 1 << 28;

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) · line 444

Quoted 10 lines
drivers/mmc/core/sd.c +7 -0
+
+       err = mmc_send_app_op_cond(host, ocr, &rocr);
       if (err)
               return err;
 
+       /*
+        * In case CCS and S18A in the response is set, start Signal Voltage
+        * Switch procedure. SPI mode doesn't support CMD11.
+        */
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {

getting kernel crash -- change code to

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) · line 445

Quoted 1 line
drivers/mmc/core/sd.c +1 -0
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000) == 0x41000000) {

need both bits set -- if one bit is set code is true.

Quoted 15 lines
drivers/mmc/core/sd.c +8 -0
+               err = mmc_start_voltage_switch(host);
+               if (err)
+                       return err;
+       }
+
       if (mmc_host_is_spi(host))
               err = mmc_send_cid(host, cid);
       else
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
       }
 
       /*
+        * If the host supports one of UHS-I modes, request the card
+        * to switch to 1.8V signaling level.
+        */

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 834

Quoted 10 lines
drivers/mmc/core/sd.c +5 -2
+       if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+           MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
+               host->ocr |= (1 << 24);
+
+       /*
        * Detect and init the card.
        */
       err = mmc_sd_init_card(host, host->ocr, NULL);
-       if (err)
-               goto err;

change

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 865

Quoted 9 lines
drivers/mmc/core/sd.c +9 -0
+       if (err == -EAGAIN) {
+               /*
+                * Retry initialization with S18R set to 0.
+                */
+               host->ocr &= ~(1 << 24);
+               err = mmc_sd_init_card(host, host->ocr, NULL);
+               if (err)
+                       goto err;
+       }

to

        if (err) {
                if (err == -EAGAIN) {
                        /*
                         * Retry initialization with S18R set to 0.
                         */
                        host->ocr &= ~(1 << 24);
                        err = mmc_sd_init_card(host, host->ocr, NULL);
                }
                if (err)
                        goto err;
        }

was getting kernel crash when init failed and host->card was NULL

Quoted 390 lines
drivers/mmc/core/sd.c +0 -0
       mmc_release_host(host);
       err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +32 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
       return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+       struct mmc_command cmd;
+       int err;
+
+       BUG_ON(!host);
+
+       /*
+        * If the host does not provide signal voltage switch procedure, we
+        * set S18R to 0, and then retry initialization sequence.
+        */
+       if (!host->ops->start_signal_voltage_switch)
+               return -EAGAIN;
+
+       memset(&cmd, 0, sizeof(struct mmc_command));
+
+       cmd.opcode = SD_SWITCH_VOLTAGE;
+       cmd.arg = 0;
+       cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+       err = mmc_wait_for_cmd(host, &cmd, 0);
+       if (err)
+               return err;
+
+       if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+               return -EIO;
+
+       err = host->ops->start_signal_voltage_switch(host);
+
+       return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
       struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +1 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
       u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
 
drivers/mmc/host/sdhci.c +135 -13
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
       printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr: 0x%08x\n",
               sdhci_readw(host, SDHCI_COMMAND),
               sdhci_readl(host, SDHCI_MAX_CURRENT));
+       printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+               sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
       if (host->flags & SDHCI_USE_ADMA)
               printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
@@ -1337,11 +1339,70 @@ out:
       spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+       struct sdhci_host *host;
+       u8 pwr;
+       u16 clk, ctrl;
+       u32 present_state;
+
+       host = mmc_priv(mmc);
+
+       /* Stop SDCLK */
+       host = mmc_priv(mmc);
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       clk &= ~SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       /* Check whether DAT[3:0] is 0000 */
+       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+       if (!((present_state & SDHCI_DATA_LVL_MASK) >> SDHCI_DATA_LVL_SHIFT)) {
+               /* Enable 1.8V Signal Enable in the Host Control2 register */
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               ctrl |= SDHCI_CTRL_VDD_180;
+               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+               /* Wait for 5ms */
+               usleep_range(5000, 5500);
+
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               if (ctrl & SDHCI_CTRL_VDD_180) {
+                       /* Provide SDCLK again and wait for 1ms*/
+                       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                       clk |= SDHCI_CLOCK_CARD_EN;
+                       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                       usleep_range(1000, 1500);
+
+                       /*
+                        * If DAT[3:0] level is 1111b, then the card was
+                        * successfully switched to 1.8V signaling.
+                        */
+                       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+                       if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                            SDHCI_DATA_LVL_MASK) {
+                               return 0;
+                       }
+               }
+       }
+
+       /*
+        * If we are here, that means the switch to 1.8V signaling failed. Stop
+        * power to the card, and retry initialization sequence by setting S18R
+        * to 0.
+        */
+       pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+       pwr &= ~SDHCI_POWER_ON;
+       sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
+
+       return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
       .request        = sdhci_request,
       .set_ios        = sdhci_set_ios,
       .get_ro         = sdhci_get_ro,
       .enable_sdio_irq = sdhci_enable_sdio_irq,
+       .start_signal_voltage_switch    = sdhci_start_signal_voltage_switch,
 };
 
 /*****************************************************************************\
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
       struct mmc_host *mmc;
-       unsigned int caps, ocr_avail;
+       u32 caps[2];
+       u32 max_current_caps;
+       unsigned int ocr_avail;
       int ret;
 
       WARN_ON(host == NULL);
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                       host->version);
       }
 
-       caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
+       caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
               sdhci_readl(host, SDHCI_CAPABILITIES);
 
+       if (host->version >= SDHCI_SPEC_300)
+               caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
       if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
               host->flags |= SDHCI_USE_SDMA;
-       else if (!(caps & SDHCI_CAN_DO_SDMA))
+       else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
               DBG("Controller doesn't have SDMA capability\n");
       else
               host->flags |= SDHCI_USE_SDMA;
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
               host->flags &= ~SDHCI_USE_SDMA;
       }
 
-       if ((host->version >= SDHCI_SPEC_200) && (caps & SDHCI_CAN_DO_ADMA2))
+       if ((host->version >= SDHCI_SPEC_200) &&
+               (caps[0] & SDHCI_CAN_DO_ADMA2))
               host->flags |= SDHCI_USE_ADMA;
 
       if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       if (host->version >= SDHCI_SPEC_300)
-               host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
 >> SDHCI_CLOCK_BASE_SHIFT;
       else
-               host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
 >> SDHCI_CLOCK_BASE_SHIFT;
 
       host->max_clk *= 1000000;
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       host->timeout_clk =
-               (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
+               (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
       if (host->timeout_clk == 0) {
               if (host->ops->get_timeout_clock) {
                       host->timeout_clk = host->ops->get_timeout_clock(host);
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                       return -ENODEV;
               }
       }
-       if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+       if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
               host->timeout_clk *= 1000;
 
       /*
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
       if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
               mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-       if (caps & SDHCI_CAN_DO_HISPD)
+       if (caps[0] & SDHCI_CAN_DO_HISPD)
               mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
 
       if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
           mmc_card_is_removable(mmc))
               mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+       /* UHS-I mode(s) supported by the host controller. */
+       if (host->version >= SDHCI_SPEC_300)
+               mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+       /* SDR104 supports also implies SDR50 support */
+       if (caps[1] & SDHCI_SUPPORT_SDR104)
+               mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
+       else if (caps[1] & SDHCI_SUPPORT_SDR50)
+               mmc->caps |= MMC_CAP_UHS_SDR50;
+
+       if (caps[1] & SDHCI_SUPPORT_DDR50)
+               mmc->caps |= MMC_CAP_UHS_DDR50;
+
       ocr_avail = 0;
-       if (caps & SDHCI_CAN_VDD_330)
+       /*
+        * According to SD Host Controller spec v3.00, if the Host System
+        * can afford more than 150mA, Host Driver should set XPC to 1. Also
+        * the value is meaningful only if Voltage Support in the Capabilities
+        * register is set. The actual current value is 4 times the register
+        * value.
+        */
+       max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+       if (caps[0] & SDHCI_CAN_VDD_330) {
+               int max_current_330;
+
               ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-       if (caps & SDHCI_CAN_VDD_300)
+
+               max_current_330 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_330_MASK) >>
+                                  SDHCI_MAX_CURRENT_330_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_330 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_330;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_300) {
+               int max_current_300;
+
               ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-       if (caps & SDHCI_CAN_VDD_180)
+
+               max_current_300 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_300_MASK) >>
+                                  SDHCI_MAX_CURRENT_300_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_300 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_300;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_180) {
+               int max_current_180;
+
               ocr_avail |= MMC_VDD_165_195;
 
+               max_current_180 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_180_MASK) >>
+                                  SDHCI_MAX_CURRENT_180_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_180 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_180;
+       }
+
       mmc->ocr_avail = ocr_avail;
       mmc->ocr_avail_sdio = ocr_avail;
       if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
       if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
               mmc->max_blk_size = 2;
       } else {
-               mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+               mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                               SDHCI_MAX_BLOCK_SHIFT;
               if (mmc->max_blk_size >= 3) {
                       printk(KERN_WARNING "%s: Invalid maximum block size, "
drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE  0x00000800
 #define  SDHCI_CARD_PRESENT    0x00010000
 #define  SDHCI_WRITE_PROTECT   0x00080000
+#define  SDHCI_DATA_LVL_MASK   0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT 20
 
 #define SDHCI_HOST_CONTROL     0x28
 #define  SDHCI_CTRL_LED                0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR       0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2            0x3E
+#define  SDHCI_CTRL_VDD_180            0x0008
 
 #define SDHCI_CAPABILITIES     0x40
 #define  SDHCI_TIMEOUT_CLK_MASK        0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180     0x04000000
 #define  SDHCI_CAN_64BIT       0x10000000
 
+#define  SDHCI_SUPPORT_SDR50   0x00000001
+#define  SDHCI_SUPPORT_SDR104  0x00000002
+#define  SDHCI_SUPPORT_DDR50   0x00000004
+
 #define SDHCI_CAPABILITIES_1   0x44
 
-#define SDHCI_MAX_CURRENT      0x48
+#define SDHCI_MAX_CURRENT              0x48
+#define  SDHCI_MAX_CURRENT_330_MASK    0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT   0
+#define  SDHCI_MAX_CURRENT_300_MASK    0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT   8
+#define  SDHCI_MAX_CURRENT_180_MASK    0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT   16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER 4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +10 -0
index bcb793e..ad7daa3 100644
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
       /* optional callback for HC quirks */
       void    (*init_card)(struct mmc_host *host, struct mmc_card *card);
+
+       int     (*start_signal_voltage_switch)(struct mmc_host *host);
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                               /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD (1 << 13)       /* Can power off after boot */
 #define MMC_CAP_BUS_WIDTH_TEST (1 << 14)       /* CMD14/CMD19 bus width ok */
+#define MMC_CAP_UHS_SDR12      (1 << 15)       /* Host supports UHS SDR12 mode */
+#define MMC_CAP_UHS_SDR25      (1 << 16)       /* Host supports UHS SDR25 mode */
+#define MMC_CAP_UHS_SDR50      (1 << 17)       /* Host supports UHS SDR50 mode */
+#define MMC_CAP_UHS_SDR104     (1 << 18)       /* Host supports UHS SDR104 mode */
+#define MMC_CAP_UHS_DDR50      (1 << 19)       /* Host supports UHS DDR50 mode */
+#define MMC_CAP_SET_XPC_330    (1 << 20)       /* Host supports >150mA current at 3.3V */
+#define MMC_CAP_SET_XPC_300    (1 << 21)       /* Host supports >150mA current at 3.0V */
+#define MMC_CAP_SET_XPC_180    (1 << 22)       /* Host supports >150mA current at 1.8V */
 
       mmc_pm_flag_t           pm_caps;        /* supported pm features */
 
include/linux/mmc/sd.h +1 -1
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks. */
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6  */
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7  */
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1  */
 
  /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below   R1  */
--

1.7.1

#26 lore raw

RE: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Philip,

Quoted 92 lines

-----Original Message-----
From: Philip Rakity [mailto:[email protected]]
Sent: Thursday, March 17, 2011 3:09 AM
To: Nath, Arindam
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Su, Henry; Lu, Aaron; [email protected]
Subject: Re: [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure

Hi Arindam,

was getting kernel crash on SD card -- fix is below

Philip

Quoted 27 lines · Arindam Nath

Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller support SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below.

Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller.

If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence.

Quoted 6 lines

---

drivers/mmc/core/sd.c     |   37 ++++++++++-
drivers/mmc/core/sd_ops.c |   32 ++++++++++
drivers/mmc/core/sd_ops.h |    1 +
drivers/mmc/host/sdhci.c  |  148

+++++++++++++++++++++++++++++++++++++++++----

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32

Quoted 18 lines
drivers/mmc/host/sdhci.h  |   18 +++++-
include/linux/mmc/host.h  |   10 +++
include/linux/mmc/sd.h    |    1 +
7 files changed, 229 insertions(+), 18 deletions(-)
drivers/mmc/core/sd.c +1 -0
index b3f8a3c..3e82599 100644
@@ -408,6 +408,7 @@ struct device_type sd_type = {
 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
 {
       int err;
+       u32 rocr;
 
       /*
        * Since we're changing the OCR value, we seem to
@@ -427,10 +428,25 @@ int mmc_sd_get_cid(struct mmc_host *host, u32

ocr, u32 *cid)

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 5 lines
drivers/mmc/core/sd.c +1 -1
       if (!err)
               ocr |= 1 << 30;
 
-       err = mmc_send_app_op_cond(host, ocr, NULL);
+       /* If the host can supply more than 150mA, XPC should be set

to 1. */

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)

Quoted 10 lines
drivers/mmc/core/sd.c +7 -0
+       if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
+           MMC_CAP_SET_XPC_180))
+               ocr |= 1 << 28;
+
+       err = mmc_send_app_op_cond(host, ocr, &rocr);
       if (err)
               return err;
 
+       /*
+        * In case CCS and S18A in the response is set, start Signal

Voltage

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) · line 444

Quoted 3 lines
drivers/mmc/core/sd.c +3 -0
+        * Switch procedure. SPI mode doesn't support CMD11.
+        */
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000)) {
Quoted 5 lines

getting kernel crash -- change code to

drivers/mmc/core/sd.c int mmc_sd_get_cid(struct mmc_host *host, u32 · line 445

Quoted 1 line
drivers/mmc/core/sd.c +1 -0
+       if (!mmc_host_is_spi(host) && (rocr & 0x41000000) ==

0x41000000) {

need both bits set -- if one bit is set code is true.

This was already pointed out by Zhangfei, and it will be fixed in V3.

Quoted 54 lines
Quoted 11 lines
drivers/mmc/core/sd.c +5 -0
+               err = mmc_start_voltage_switch(host);
+               if (err)
+                       return err;
+       }
+
       if (mmc_host_is_spi(host))
               err = mmc_send_cid(host, cid);
       else

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 850

Quoted 8 lines
drivers/mmc/core/sd.c +5 -0
@@ -827,11 +843,26 @@ int mmc_attach_sd(struct mmc_host *host)
       }
 
       /*
+        * If the host supports one of UHS-I modes, request the card
+        * to switch to 1.8V signaling level.
+        */
+       if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
+           MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |

MMC_CAP_UHS_DDR50))

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 834

Quoted 8 lines
drivers/mmc/core/sd.c +3 -2
+               host->ocr |= (1 << 24);
+
+       /*
        * Detect and init the card.
        */
       err = mmc_sd_init_card(host, host->ocr, NULL);
-       if (err)
-               goto err;

change

drivers/mmc/core/sd.c int mmc_attach_sd(struct mmc_host *host) · line 865

Quoted 9 lines
drivers/mmc/core/sd.c +9 -0
+       if (err == -EAGAIN) {
+               /*
+                * Retry initialization with S18R set to 0.
+                */
+               host->ocr &= ~(1 << 24);
+               err = mmc_sd_init_card(host, host->ocr, NULL);
+               if (err)
+                       goto err;
+       }

to

        if (err) {
                if (err == -EAGAIN) {
                        /*
                         * Retry initialization with S18R set to 0.
                         */
                        host->ocr &= ~(1 << 24);
                        err = mmc_sd_init_card(host, host->ocr, NULL);
                }
                if (err)
                        goto err;
        }
Quoted 1 line

was getting kernel crash when init failed and host->card was NULL

Zhangfei mentioned this one too. Will be fixed.

Thanks,
Arindam

Quoted 436 lines

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card,

Quoted 9 lines
drivers/mmc/core/sd.c +0 -0
       mmc_release_host(host);
       err = mmc_add_card(host->card);
drivers/mmc/core/sd_ops.c +0 -0
index 797cdb5..8a23e2e 100644
@@ -146,6 +146,38 @@ int mmc_app_set_bus_width(struct mmc_card *card,

int width)

drivers/mmc/core/sd_ops.c int mmc_app_set_bus_width(struct mmc_card *card, int width)

Quoted 12 lines
drivers/mmc/core/sd_ops.c +9 -0
       return 0;
 }
 
+int mmc_start_voltage_switch(struct mmc_host *host)
+{
+       struct mmc_command cmd;
+       int err;
+
+       BUG_ON(!host);
+
+       /*
+        * If the host does not provide signal voltage switch

procedure, we

drivers/mmc/core/sd_ops.h int mmc_app_send_scr(struct mmc_card *card, u32

Quoted 31 lines
drivers/mmc/core/sd_ops.c +23 -0
+        * set S18R to 0, and then retry initialization sequence.
+        */
+       if (!host->ops->start_signal_voltage_switch)
+               return -EAGAIN;
+
+       memset(&cmd, 0, sizeof(struct mmc_command));
+
+       cmd.opcode = SD_SWITCH_VOLTAGE;
+       cmd.arg = 0;
+       cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+       err = mmc_wait_for_cmd(host, &cmd, 0);
+       if (err)
+               return err;
+
+       if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
+               return -EIO;
+
+       err = host->ops->start_signal_voltage_switch(host);
+
+       return err;
+}
+
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
       struct mmc_command cmd;
drivers/mmc/core/sd_ops.h +0 -0
index ffc2305..3cfba59 100644
@@ -20,6 +20,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32

*scr);

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host *host) · line 85

Quoted 13 lines
drivers/mmc/core/sd_ops.h +1 -0
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
       u8 value, u8 *resp);
 int mmc_app_sd_status(struct mmc_card *card, void *ssr);
+int mmc_start_voltage_switch(struct mmc_host *host);
 
 #endif
 
drivers/mmc/host/sdhci.c +0 -0
index 8914a25..5487a0b 100644
@@ -85,6 +85,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
       printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr:

0x%08x\n",

drivers/mmc/host/sdhci.c static void sdhci_dumpregs(struct sdhci_host *host)

Quoted 7 lines
drivers/mmc/host/sdhci.c +2 -0
               sdhci_readw(host, SDHCI_COMMAND),
               sdhci_readl(host, SDHCI_MAX_CURRENT));
+       printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+               sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
       if (host->flags & SDHCI_USE_ADMA)
               printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x |

ADMA Ptr: 0x%08x\n",

Quoted 12 lines
drivers/mmc/host/sdhci.c +8 -0
@@ -1337,11 +1339,70 @@ out:
       spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc)
+{
+       struct sdhci_host *host;
+       u8 pwr;
+       u16 clk, ctrl;
+       u32 present_state;
+
+       host = mmc_priv(mmc);

drivers/mmc/host/sdhci.c out: · line 1359

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+       /* Stop SDCLK */
+       host = mmc_priv(mmc);
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       clk &= ~SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       /* Check whether DAT[3:0] is 0000 */
+       present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+       if (!((present_state & SDHCI_DATA_LVL_MASK) >>

SDHCI_DATA_LVL_SHIFT)) {

drivers/mmc/host/sdhci.c out: · line 1360

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+               /* Enable 1.8V Signal Enable in the Host Control2

register */

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               ctrl |= SDHCI_CTRL_VDD_180;
+               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+               /* Wait for 5ms */
+               usleep_range(5000, 5500);
+

drivers/mmc/host/sdhci.c out:

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+               if (ctrl & SDHCI_CTRL_VDD_180) {
+                       /* Provide SDCLK again and wait for 1ms*/
+                       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+                       clk |= SDHCI_CLOCK_CARD_EN;
+                       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+                       usleep_range(1000, 1500);
+
+                       /*
+                        * If DAT[3:0] level is 1111b, then the card

was

drivers/mmc/host/sdhci.c out:

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+                        * successfully switched to 1.8V signaling.
+                        */
+                       present_state = sdhci_readl(host,

SDHCI_PRESENT_STATE);

drivers/mmc/host/sdhci.c out:

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+                       if ((present_state & SDHCI_DATA_LVL_MASK) ==
+                            SDHCI_DATA_LVL_MASK) {
+                               return 0;
+                       }
+               }
+       }
+
+       /*
+        * If we are here, that means the switch to 1.8V signaling

failed. Stop

drivers/mmc/host/sdhci.c out: · line 1390

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * power to the card, and retry initialization sequence by

setting S18R

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+        * to 0.
+        */
+       pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
+       pwr &= ~SDHCI_POWER_ON;
+       sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);

drivers/mmc/host/sdhci.c out:

Quoted 10 lines
drivers/mmc/host/sdhci.c +5 -0
+
+       return -EAGAIN;
+}
+
 static const struct mmc_host_ops sdhci_ops = {
       .request        = sdhci_request,
       .set_ios        = sdhci_set_ios,
       .get_ro         = sdhci_get_ro,
       .enable_sdio_irq = sdhci_enable_sdio_irq,
+       .start_signal_voltage_switch    =

sdhci_start_signal_voltage_switch,

drivers/mmc/host/sdhci.c out: · line 1408

Quoted 3 lines
drivers/mmc/host/sdhci.c +0 -0
 };
 
 

/********************************************************************** *******\

Quoted 12 lines
drivers/mmc/host/sdhci.c +3 -1
@@ -1799,7 +1860,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
 int sdhci_add_host(struct sdhci_host *host)
 {
       struct mmc_host *mmc;
-       unsigned int caps, ocr_avail;
+       u32 caps[2];
+       u32 max_current_caps;
+       unsigned int ocr_avail;
       int ret;
 
       WARN_ON(host == NULL);

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1822,12 +1885,15 @@ int sdhci_add_host(struct sdhci_host *host)
                       host->version);
       }
 
-       caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps

:

Quoted 15 lines
drivers/mmc/host/sdhci.c +1 -0
+       caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host-

caps :

               sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/host/sdhci.c +4 -1
+       if (host->version >= SDHCI_SPEC_300)
+               caps[1] = sdhci_readl(host, SDHCI_CAPABILITIES_1);
+
       if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
               host->flags |= SDHCI_USE_SDMA;
-       else if (!(caps & SDHCI_CAN_DO_SDMA))
+       else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
               DBG("Controller doesn't have SDMA capability\n");
       else
               host->flags |= SDHCI_USE_SDMA;

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1838,7 +1904,8 @@ int sdhci_add_host(struct sdhci_host *host)
               host->flags &= ~SDHCI_USE_SDMA;
       }
 
-       if ((host->version >= SDHCI_SPEC_200) && (caps &

SDHCI_CAN_DO_ADMA2))

Quoted 19 lines
drivers/mmc/host/sdhci.c +4 -2
+       if ((host->version >= SDHCI_SPEC_200) &&
+               (caps[0] & SDHCI_CAN_DO_ADMA2))
               host->flags |= SDHCI_USE_ADMA;
 
       if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1892,10 +1959,10 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       if (host->version >= SDHCI_SPEC_300)
-               host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
 >> SDHCI_CLOCK_BASE_SHIFT;
       else
-               host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK)
+               host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
 >> SDHCI_CLOCK_BASE_SHIFT;
 
       host->max_clk *= 1000000;

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

Quoted 4 lines
drivers/mmc/host/sdhci.c +0 -1
@@ -1911,7 +1978,7 @@ int sdhci_add_host(struct sdhci_host *host)
       }
 
       host->timeout_clk =
-               (caps & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+               (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >>

SDHCI_TIMEOUT_CLK_SHIFT;

Quoted 14 lines
drivers/mmc/host/sdhci.c +0 -0
       if (host->timeout_clk == 0) {
               if (host->ops->get_timeout_clock) {
                       host->timeout_clk = host->ops-

get_timeout_clock(host);

drivers/mmc/host/sdhci.c +1 -1
@@ -1923,7 +1990,7 @@ int sdhci_add_host(struct sdhci_host *host)
                       return -ENODEV;
               }
       }
-       if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+       if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
               host->timeout_clk *= 1000;
 
       /*

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

Quoted 6 lines
drivers/mmc/host/sdhci.c +1 -1
@@ -1950,21 +2017,76 @@ int sdhci_add_host(struct sdhci_host *host)
       if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
               mmc->caps |= MMC_CAP_4_BIT_DATA;
 
-       if (caps & SDHCI_CAN_DO_HISPD)
+       if (caps[0] & SDHCI_CAN_DO_HISPD)
               mmc->caps |= MMC_CAP_SD_HIGHSPEED |

MMC_CAP_MMC_HIGHSPEED;

Quoted 12 lines
drivers/mmc/host/sdhci.c +7 -0
       if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
           mmc_card_is_removable(mmc))
               mmc->caps |= MMC_CAP_NEEDS_POLL;
 
+       /* UHS-I mode(s) supported by the host controller. */
+       if (host->version >= SDHCI_SPEC_300)
+               mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
+
+       /* SDR104 supports also implies SDR50 support */
+       if (caps[1] & SDHCI_SUPPORT_SDR104)
+               mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;

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

Quoted 10 lines
drivers/mmc/host/sdhci.c +8 -1
+       else if (caps[1] & SDHCI_SUPPORT_SDR50)
+               mmc->caps |= MMC_CAP_UHS_SDR50;
+
+       if (caps[1] & SDHCI_SUPPORT_DDR50)
+               mmc->caps |= MMC_CAP_UHS_DDR50;
+
       ocr_avail = 0;
-       if (caps & SDHCI_CAN_VDD_330)
+       /*
+        * According to SD Host Controller spec v3.00, if the Host

System

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * can afford more than 150mA, Host Driver should set XPC to

1. Also

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * the value is meaningful only if Voltage Support in the

Capabilities

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

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+        * register is set. The actual current value is 4 times the

register

Quoted 56 lines
drivers/mmc/host/sdhci.c +41 -3
+        * value.
+        */
+       max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
+
+       if (caps[0] & SDHCI_CAN_VDD_330) {
+               int max_current_330;
+
               ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
-       if (caps & SDHCI_CAN_VDD_300)
+
+               max_current_330 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_330_MASK) >>
+                                  SDHCI_MAX_CURRENT_330_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_330 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_330;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_300) {
+               int max_current_300;
+
               ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
-       if (caps & SDHCI_CAN_VDD_180)
+
+               max_current_300 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_300_MASK) >>
+                                  SDHCI_MAX_CURRENT_300_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_300 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_300;
+       }
+       if (caps[0] & SDHCI_CAN_VDD_180) {
+               int max_current_180;
+
               ocr_avail |= MMC_VDD_165_195;
 
+               max_current_180 = ((max_current_caps &
+                                  SDHCI_MAX_CURRENT_180_MASK) >>
+                                  SDHCI_MAX_CURRENT_180_SHIFT) *
+                                  SDHCI_MAX_CURRENT_MULTIPLIER;
+
+               if (max_current_180 > 150)
+                       mmc->caps |= MMC_CAP_SET_XPC_180;
+       }
+
       mmc->ocr_avail = ocr_avail;
       mmc->ocr_avail_sdio = ocr_avail;
       if (host->ocr_avail_sdio)
@@ -2024,7 +2146,7 @@ int sdhci_add_host(struct sdhci_host *host)
       if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
               mmc->max_blk_size = 2;
       } else {
-               mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+               mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK)
Quoted 1 line
Quoted 3 lines
                               SDHCI_MAX_BLOCK_SHIFT;
               if (mmc->max_blk_size >= 3) {
                       printk(KERN_WARNING "%s: Invalid maximum block

size, "

Quoted 50 lines
drivers/mmc/host/sdhci.h +16 -2
index 223762c..95d70e6 100644
@@ -69,6 +69,8 @@
 #define  SDHCI_DATA_AVAILABLE  0x00000800
 #define  SDHCI_CARD_PRESENT    0x00010000
 #define  SDHCI_WRITE_PROTECT   0x00080000
+#define  SDHCI_DATA_LVL_MASK   0x00F00000
+#define   SDHCI_DATA_LVL_SHIFT 20
 
 #define SDHCI_HOST_CONTROL     0x28
 #define  SDHCI_CTRL_LED                0x01
@@ -147,7 +149,8 @@
 
 #define SDHCI_ACMD12_ERR       0x3C
 
-/* 3E-3F reserved */
+#define SDHCI_HOST_CONTROL2            0x3E
+#define  SDHCI_CTRL_VDD_180            0x0008
 
 #define SDHCI_CAPABILITIES     0x40
 #define  SDHCI_TIMEOUT_CLK_MASK        0x0000003F
@@ -168,9 +171,20 @@
 #define  SDHCI_CAN_VDD_180     0x04000000
 #define  SDHCI_CAN_64BIT       0x10000000
 
+#define  SDHCI_SUPPORT_SDR50   0x00000001
+#define  SDHCI_SUPPORT_SDR104  0x00000002
+#define  SDHCI_SUPPORT_DDR50   0x00000004
+
 #define SDHCI_CAPABILITIES_1   0x44
 
-#define SDHCI_MAX_CURRENT      0x48
+#define SDHCI_MAX_CURRENT              0x48
+#define  SDHCI_MAX_CURRENT_330_MASK    0x0000FF
+#define  SDHCI_MAX_CURRENT_330_SHIFT   0
+#define  SDHCI_MAX_CURRENT_300_MASK    0x00FF00
+#define  SDHCI_MAX_CURRENT_300_SHIFT   8
+#define  SDHCI_MAX_CURRENT_180_MASK    0xFF0000
+#define  SDHCI_MAX_CURRENT_180_SHIFT   16
+#define   SDHCI_MAX_CURRENT_MULTIPLIER 4
 
 /* 4C-4F reserved for more max current */
 
include/linux/mmc/host.h +0 -0
index bcb793e..ad7daa3 100644

include/linux/mmc/host.h struct mmc_host_ops { · line 119

Quoted 3 lines
include/linux/mmc/host.h +0 -0
@@ -117,6 +117,8 @@ struct mmc_host_ops {
 
       /* optional callback for HC quirks */
       void    (*init_card)(struct mmc_host *host, struct mmc_card

*card);

include/linux/mmc/host.h struct mmc_host_ops { · line 121

Quoted 2 lines
include/linux/mmc/host.h +2 -0
+
+       int     (*start_signal_voltage_switch)(struct mmc_host

*host);

include/linux/mmc/host.h struct mmc_host { · line 176

Quoted 6 lines
include/linux/mmc/host.h +0 -0
 };
 
 struct mmc_card;
@@ -173,6 +175,14 @@ struct mmc_host {
                                               /* DDR mode at 1.2V */
 #define MMC_CAP_POWER_OFF_CARD (1 << 13)       /* Can power off after

boot */

include/linux/mmc/host.h struct mmc_host { · line 177

Quoted 1 line
include/linux/mmc/host.h +0 -0
 #define MMC_CAP_BUS_WIDTH_TEST (1 << 14)       /* CMD14/CMD19 bus

width ok */

include/linux/mmc/host.h struct mmc_host { · line 178

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR12      (1 << 15)       /* Host supports UHS

SDR12 mode */

include/linux/mmc/host.h struct mmc_host { · line 179

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR25      (1 << 16)       /* Host supports UHS

SDR25 mode */

include/linux/mmc/host.h struct mmc_host { · line 180

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR50      (1 << 17)       /* Host supports UHS

SDR50 mode */

include/linux/mmc/host.h struct mmc_host { · line 181

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_SDR104     (1 << 18)       /* Host supports UHS

SDR104 mode */

include/linux/mmc/host.h struct mmc_host { · line 182

Quoted 1 line
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_UHS_DDR50      (1 << 19)       /* Host supports UHS

DDR50 mode */

Quoted 8 lines
include/linux/mmc/host.h +1 -0
+#define MMC_CAP_SET_XPC_330    (1 << 20)       /* Host supports

150mA current at 3.3V */
+#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports
150mA current at 3.0V */
+#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports
150mA current at 1.8V */

mmc_pm_flag_t pm_caps; /* supported pm

features */

include/linux/mmc/sd.h line 18

Quoted 8 lines
include/linux/mmc/sd.h +0 -0
index 178363b..3ba5aa6 100644
@@ -17,6 +17,7 @@
 /* This is basically the same command as for MMC with some quirks. */
 #define SD_SEND_RELATIVE_ADDR     3   /* bcr                     R6

*/

include/linux/mmc/sd.h line 19

Quoted 1 line
include/linux/mmc/sd.h +0 -0
 #define SD_SEND_IF_COND           8   /* bcr  [11:0] See below   R7

*/

include/linux/mmc/sd.h line 20

Quoted 1 line
include/linux/mmc/sd.h +1 -0
+#define SD_SWITCH_VOLTAGE         11  /* ac                      R1

*/

include/linux/mmc/sd.h line 22

Quoted 3 lines
include/linux/mmc/sd.h +0 -0
  /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below   R1

*/

Quoted 3 lines
include/linux/mmc/sd.h +0 -1
--

1.7.1