u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mmc: test mmc bus width on startup
@ 2011-10-03  9:03 Lei Wen
  2011-10-03 10:41 ` Marek Vasut
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Lei Wen @ 2011-10-03  9:03 UTC (permalink / raw)
  To: u-boot

For we don't know mmc bus width from reading registers, the only way
to check is to test.

Change-Id: Ia50df480bd14349e36ac8217d8d290cf732db089
Signed-off-by: Lei Wen <leiwen@marvell.com>
---
 drivers/mmc/mmc.c |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 391bc2b..e384399 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -631,8 +631,6 @@ int mmc_change_freq(struct mmc *mmc)
 	if (mmc->version < MMC_VERSION_4)
 		return 0;
 
-	mmc->card_caps |= MMC_MODE_4BIT;
-
 	err = mmc_send_ext_csd(mmc, ext_csd);
 
 	if (err)
@@ -856,11 +854,11 @@ void mmc_set_bus_width(struct mmc *mmc, uint width)
 
 int mmc_startup(struct mmc *mmc)
 {
-	int err;
+	int err, width;
 	uint mult, freq;
 	u64 cmult, csize, capacity;
 	struct mmc_cmd cmd;
-	char ext_csd[512];
+	char ext_csd[512], test_csd[512];
 	int timeout = 1000;
 
 #ifdef CONFIG_MMC_SPI_CRC_ON
@@ -1077,26 +1075,29 @@ int mmc_startup(struct mmc *mmc)
 		else
 			mmc_set_clock(mmc, 25000000);
 	} else {
-		if (mmc->card_caps & MMC_MODE_4BIT) {
+		for (width = EXT_CSD_BUS_WIDTH_8; width >= 0; width--) {
 			/* Set the card to use 4 bit*/
 			err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
-					EXT_CSD_BUS_WIDTH,
-					EXT_CSD_BUS_WIDTH_4);
-
-			if (err)
-				return err;
-
-			mmc_set_bus_width(mmc, 4);
-		} else if (mmc->card_caps & MMC_MODE_8BIT) {
-			/* Set the card to use 8 bit*/
-			err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
-					EXT_CSD_BUS_WIDTH,
-					EXT_CSD_BUS_WIDTH_8);
+					EXT_CSD_BUS_WIDTH, width);
 
 			if (err)
-				return err;
+				continue;
 
-			mmc_set_bus_width(mmc, 8);
+			if (!width) {
+				mmc_set_bus_width(mmc, 1);
+				break;
+			} else
+				mmc_set_bus_width(mmc, 4 * width);
+
+			err = mmc_send_ext_csd(mmc, test_csd);
+			if (!err && ext_csd[160] == test_csd[160]
+			    && ext_csd[175] == test_csd[175]
+			    && ext_csd[192] == test_csd[192]
+			    && ext_csd[224] == test_csd[224]
+			    && memcmp(&ext_csd[212], &test_csd[212], 4) == 0) {
+				mmc->card_caps |= width;
+				break;
+			}
 		}
 
 		if (mmc->card_caps & MMC_MODE_HS) {
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2011-10-15 16:05 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-03  9:03 [U-Boot] [PATCH] mmc: test mmc bus width on startup Lei Wen
2011-10-03 10:41 ` Marek Vasut
2011-10-03 11:45   ` Lei Wen
2011-10-04  6:35 ` [U-Boot] [PATCH V2 0/2] test mmc bus " Lei Wen
2011-10-04  6:35 ` [U-Boot] [PATCH V2 1/2] mmc: change magic number to macro define Lei Wen
2011-10-04 12:07   ` Marek Vasut
2011-10-06 15:10     ` Lei Wen
2011-10-06 16:10       ` Marek Vasut
2011-10-06 17:39       ` Wolfgang Denk
2011-10-10 14:44         ` Lei Wen
2011-10-10 17:33           ` Wolfgang Denk
2011-10-11  0:48             ` Lei Wen
2011-10-11  1:09               ` Graeme Russ
2011-10-11 13:52                 ` Lei Wen
2011-10-13 20:09                 ` Wolfgang Denk
2011-10-14  3:18                   ` Lei Wen
2011-10-14 20:36                     ` Wolfgang Denk
2011-10-15 14:43                       ` Lei Wen
2011-10-15 16:05                         ` Wolfgang Denk
2011-10-07  8:36       ` Prafulla Wadaskar
2011-10-08 13:45         ` Lei Wen
2011-10-11  1:12         ` Graeme Russ
2011-10-11 16:37           ` Andy Fleming
2011-10-04  6:35 ` [U-Boot] [PATCH V2 2/2] mmc: test mmc bus width on startup Lei Wen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).