Skip to contentSkip to conversation

fsl_esdhc: Always stop clock before changing frequency

PATCH New Kumar Gala 2 participants 8 messages Mar 19, 2010 – Mar 21, 2010 MMC, SD and SDIO

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/3 fsl_esdhc: Always stop clock before changing frequency

We need to stop the clocks on 83xx/85xx as well as imx. No need to make this code conditional to just imx.

---
 drivers/mmc/fsl_esdhc.c |   11 +++--------
 include/fsl_esdhc.h     |    3 +--
 2 files changed, 4 insertions(+), 10 deletions(-)
drivers/mmc/fsl_esdhc.c +3 -8
index e665b5e..85354e8 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007, Freescale Semiconductor, Inc
+ * Copyright 2007,2010 Freescale Semiconductor, Inc
  * Andy Fleming
  *
  * Based vaguely on the pxa mmc code:
@@ -265,18 +265,13 @@ void set_sysctl(struct mmc *mmc, uint clock)
 
 	clk = (pre_div << 8) | (div << 4);
 
-	/* On imx the clock must be stopped before changing frequency */
-	if (cfg->clk_enable)
-		esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
+	esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
 
 	esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
 
 	udelay(10000);
 
-	clk = SYSCTL_PEREN;
-	/* On imx systems the clock must be explicitely enabled */
-	if (cfg->clk_enable)
-		clk |= SYSCTL_CKEN;
+	clk = SYSCTL_PEREN | SYSCTL_CKEN;
 
 	esdhc_setbits32(&regs->sysctl, clk);
 }
include/fsl_esdhc.h +1 -2
index 01b7dec..57a08cd 100644
@@ -2,7 +2,7 @@
  * FSL SD/MMC Defines
  *-------------------------------------------------------------------
  *
- * Copyright 2007-2008, Freescale Semiconductor, Inc
+ * Copyright 2007-2008,2010 Freescale Semiconductor, Inc
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -148,7 +148,6 @@
 struct fsl_esdhc_cfg {
 	u32	esdhc_base;
 	u32	no_snoop;
-	u32	clk_enable;
 };
 
 /* Select the correct accessors depending on endianess */
Signature · 1 line
1.6.0.6
author
#1 lore raw

PATCH 2/3 fsl_esdhc: Add function to reset the eSDHC controller

From: Jerry Huang <[email protected]>

To support multiple block read command we must set abort or use auto CMD12. If we booted from eSDHC controller neither of these are used and thus we need to reset the controller to allow multiple block read to function.

---
 drivers/mmc/fsl_esdhc.c |   17 +++++++++++++++++
 include/fsl_esdhc.h     |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/mmc/fsl_esdhc.c +17 -0
index 85354e8..999b581 100644
@@ -344,6 +344,20 @@ static int esdhc_init(struct mmc *mmc)
 	return ret;
 }
 
+static void esdhc_reset(struct fsl_esdhc *regs)
+{
+	unsigned long timeout = 100; /* wait max 100 ms */
+
+	/* reset the controller */
+	esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
+
+	/* hardware clears the bit when it is done */
+	while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
+		udelay(1000);
+	if (!timeout)
+		printf("MMC/SD: Reset never completed.\n");
+}
+
 int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 {
 	struct fsl_esdhc *regs;
@@ -358,6 +372,9 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 	sprintf(mmc->name, "FSL_ESDHC");
 	regs = (struct fsl_esdhc *)cfg->esdhc_base;
 
+	/* First reset the eSDHC controller */
+	esdhc_reset(regs);
+
 	mmc->priv = cfg;
 	mmc->send_cmd = esdhc_send_cmd;
 	mmc->set_ios = esdhc_set_ios;
include/fsl_esdhc.h +1 -0
index 57a08cd..5f02018 100644
@@ -39,6 +39,7 @@
 #define SYSCTL_PEREN		0x00000004
 #define SYSCTL_HCKEN		0x00000002
 #define SYSCTL_IPGEN		0x00000001
+#define SYSCTL_RSTA		0x01000000
 
 #define IRQSTAT			0x0002e030
 #define IRQSTAT_DMAE		(0x10000000)
Signature · 1 line
1.6.0.6
author
#2 lore raw

PATCH 3/3 fsl_esdhc: Only modify WML[WR] field

From: Roy Zang <[email protected]>

Maintain the value of the reset of wml register rather than hard coding it

---
 drivers/mmc/fsl_esdhc.c |    7 ++++---
 include/fsl_esdhc.h     |    2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/mmc/fsl_esdhc.c +4 -3
index 999b581..b3d99dc 100644
@@ -110,8 +110,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 		if (wml_value > 0x10)
 			wml_value = 0x10;
 
-		wml_value = 0x100000 | wml_value;
-
+		wml_value |= in_be32(&regs->wml) & ~WML_RD_WML_MASK;
 		esdhc_write32(&regs->dsaddr, (u32)data->dest);
 	} else {
 		if (wml_value > 0x80)
@@ -120,7 +119,9 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 			printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
 			return TIMEOUT;
 		}
-		wml_value = wml_value << 16 | 0x10;
+
+		esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK, wml_value << 16);
+
 		esdhc_write32(&regs->dsaddr, (u32)data->src);
 	}
 
include/fsl_esdhc.h +2 -0
index 5f02018..f9ae15a 100644
@@ -133,6 +133,8 @@
 
 #define WML		0x2e044
 #define WML_WRITE	0x00010000
+#define WML_RD_WML_MASK	0xff
+#define WML_WR_WML_MASK	0xff0000
 
 #define BLKATTR		0x2e004
 #define BLKATTR_CNT(x)	((x & 0xffff) << 16)
Signature · 1 line
1.6.0.6
author
#3 lore raw

PATCH 3/3 fsl_esdhc: Only modify WML[WR] field

Quoted 15 lines · Kumar Gala

From: Roy Zang <[email protected]>

Maintain the value of the reset of wml register rather than hard coding it

---

drivers/mmc/fsl_esdhc.c |    7 ++++---
include/fsl_esdhc.h     |    2 ++
2 files changed, 6 insertions(+), 3 deletions(-)
drivers/mmc/fsl_esdhc.c +0 -0
index 999b581..b3d99dc 100644

drivers/mmc/fsl_esdhc.c static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) · line 113

Quoted 6 lines
drivers/mmc/fsl_esdhc.c +1 -2
@@ -110,8 +110,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 		if (wml_value > 0x10)
 			wml_value = 0x10;
 
-		wml_value = 0x100000 | wml_value;
-
+		wml_value |= in_be32(&regs->wml) & ~WML_RD_WML_MASK;

oops, should be esdhc_read32() instead of in_be32().

Quoted 34 lines
drivers/mmc/fsl_esdhc.c +3 -1
 		esdhc_write32(&regs->dsaddr, (u32)data->dest);
 	} else {
 		if (wml_value > 0x80)
@@ -120,7 +119,9 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 			printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
 			return TIMEOUT;
 		}
-		wml_value = wml_value << 16 | 0x10;
+
+		esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK, wml_value << 16);
+
 		esdhc_write32(&regs->dsaddr, (u32)data->src);
 	}
 
include/fsl_esdhc.h +2 -0
index 5f02018..f9ae15a 100644
@@ -133,6 +133,8 @@
 
 #define WML		0x2e044
 #define WML_WRITE	0x00010000
+#define WML_RD_WML_MASK	0xff
+#define WML_WR_WML_MASK	0xff0000
 
 #define BLKATTR		0x2e004
 #define BLKATTR_CNT(x)	((x & 0xffff) << 16)
Signature · 6 lines
1.6.0.6

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
#4 lore raw

PATCH 2/3 fsl_esdhc: Add function to reset the eSDHC controller

In reply to Kumar Gala
Quoted 9 lines · Kumar Gala

From: Jerry Huang <[email protected]>

To support multiple block read command we must set abort or use auto CMD12. If we booted from eSDHC controller neither of these are used and thus we need to reset the controller to allow multiple block read to function.

Tested successfully on mx51evk.

Regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
author Applied
#5 lore raw

PATCH 2/3 fsl_esdhc: Add function to reset the eSDHC controller

Quoted 8 lines · Stefano Babic
Quoted 7 lines · Kumar Gala

From: Jerry Huang <[email protected]>

To support multiple block read command we must set abort or use auto CMD12. If we booted from eSDHC controller neither of these are used and thus we need to reset the controller to allow multiple block read to function.

Quoted 6 lines
Quoted 2 lines

Tested successfully on mx51evk.

applied to 85xx-next.

- k

#6 lore raw

PATCH 1/3 fsl_esdhc: Always stop clock before changing frequency

In reply to Kumar Gala
Quoted 9 lines · Kumar Gala

We need to stop the clocks on 83xx/85xx as well as imx. No need to make this code conditional to just imx.

---
 drivers/mmc/fsl_esdhc.c |   11 +++--------
 include/fsl_esdhc.h     |    3 +--
 2 files changed, 4 insertions(+), 10 deletions(-)

Agree, but please remove clk_enable from the mx51evk.c, too.

Tested successfully on mx51evk.

Regards,
Stefano

Signature · 9 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mx51evk_warnings
Url: http://lists.denx.de/pipermail/u-boot/attachments/20100320/4f93d8bf/attachment.txt 
author Applied
#7 lore raw

PATCH 1/3 fsl_esdhc: Always stop clock before changing frequency

Quoted 11 lines · Stefano Babic
Quoted 9 lines · Kumar Gala

We need to stop the clocks on 83xx/85xx as well as imx. No need to make this code conditional to just imx.

---
drivers/mmc/fsl_esdhc.c | 11 +++--------
include/fsl_esdhc.h | 3 +--

2 files changed, 4 insertions(+), 10 deletions(-)
Quoted 5 lines

Agree, but please remove clk_enable from the mx51evk.c, too.

Tested successfully on mx51evk.

applied to 85xx-next.

- k