[U-Boot] [PATCH 1/1 v2] ppc4xx: Autocalibration can set RDCC to over aggressive value.

Adam Graham agraham at amcc.com
Tue Jan 13 23:54:21 CET 2009


The criteria of the AMCC SDRAM Controller DDR autocalibration
U-Boot code is to pick the largest passing write/read/compare
window that also has the smallest SDRAM_RDCC.[RDSS] Read Sample
Cycle Select value.

On some Kilauea boards the DDR autocalibration algorithm can
find a large passing write/read/compare window with a small
SDRAM_RDCC.[RDSS] aggressive value of Read Sample Cycle Select
value "T1 Sample".

This SDRAM_RDCC.[RDSS] Read Sample Cycle Select value of
"T1 Sample" proves to be to aggressive when later on U-Boot
relocates into DDR memory and executes.

The memory traces on the Kilauea board are short so on some
Kilauea boards the SDRAM_RDCC.[RDSS] Read Sample Cycle Select
value of "T1 Sample" shows up as a potentially valid value for
the DDR autocalibratiion algorithm.

The fix is to define a weak default function which provides
the minimum SDRAM_RDCC.[RDSS] Read Sample Cycle Select value
to accept for DDR autocalibration.  The default will be the
"T2 Sample" value.  A board developer who has a well defined
board and chooses to be more aggressive can always provide
their own board specific string function with the more
aggressive "T1 Sample" value or stick with the default
minimum SDRAM_RDCC.[RDSS] value of "T2".

Also put in a autocalibration loop fix for case where current
write/read/compare passing window size is the same as a prior
window size, then in this case choose the write/read/compare
result that has the associated smallest RDCC T-Sample value.

Signed-off-by: Adam Graham <agraham at amcc.com>
---
  v2:
   - Shortened the maximum patch comment line lengths
   - Correct coding indentions by using TABS
   - Correct coding style by removing deep nested if statements

 cpu/ppc4xx/4xx_ibm_ddr2_autocalib.c |  176 ++++++++++++++++++-----------------
 include/configs/kilauea.h           |    7 --
 2 files changed, 91 insertions(+), 92 deletions(-)

diff --git a/cpu/ppc4xx/4xx_ibm_ddr2_autocalib.c b/cpu/ppc4xx/4xx_ibm_ddr2_autocalib.c
index 1e3e20d..0c97d10 100644
--- a/cpu/ppc4xx/4xx_ibm_ddr2_autocalib.c
+++ b/cpu/ppc4xx/4xx_ibm_ddr2_autocalib.c
@@ -61,6 +61,12 @@
 #define NUMLOOPS		1	/* configure as you deem approporiate */
 #define NUMMEMWORDS		16
 
+#define DDR_VERBOSE_PRT(dbg, lvl, fmt, args...) \
+	do { \
+	if (lvl > dbg) \
+		printf(fmt, ##args); \
+	} while (0)
+
 /* Private Structure Definitions */
 
 struct autocal_regs {
@@ -147,6 +153,12 @@ ulong __ddr_scan_option(ulong default_val)
 }
 ulong ddr_scan_option(ulong) __attribute__((weak, alias("__ddr_scan_option")));
 
+u32 __ddr_rdss_opt(u32 default_val)
+{
+	return default_val;
+}
+u32 ddr_rdss_opt(ulong) __attribute__((weak, alias("__ddr_rdss_opt")));
+
 static u32 *get_membase(int bxcr_num)
 {
 	ulong bxcf;
@@ -341,6 +353,7 @@ static int short_mem_test(u32 *base_address)
 			ppcDcbf((ulong)&(base_address[j]));
 		}
 		sync();
+		iobarrier_rw();
 		for (l = 0; l < NUMLOOPS; l++) {
 			for (j = 0; j < NUMMEMWORDS; j++) {
 				if (base_address[j] != test[i][j]) {
@@ -355,6 +368,7 @@ static int short_mem_test(u32 *base_address)
 				ppcDcbf((u32)&(base_address[j]));
 			} /* for (j = 0; j < NUMMEMWORDS; j++) */
 			sync();
+			iobarrier_rw();
 		} /* for (l=0; l<NUMLOOPS; l++) */
 	}
 
@@ -447,7 +461,8 @@ static u32 DQS_calibration_methodA(struct ddrautocal *cal)
 	 * Program RDCC register
 	 * Read sample cycle auto-update enable
 	 */
-	mtsdram(SDRAM_RDCC, SDRAM_RDCC_RDSS_T1 | SDRAM_RDCC_RSAE_ENABLE);
+	mtsdram(SDRAM_RDCC,
+		ddr_rdss_opt(SDRAM_RDCC_RDSS_T2) | SDRAM_RDCC_RSAE_ENABLE);
 
 #ifdef DEBUG
 	mfsdram(SDRAM_RDCC, temp);
@@ -633,7 +648,8 @@ static u32 program_DQS_calibration_methodB(struct ddrautocal *ddrcal)
 	 * Program RDCC register
 	 * Read sample cycle auto-update enable
 	 */
-	mtsdram(SDRAM_RDCC, SDRAM_RDCC_RDSS_T2 | SDRAM_RDCC_RSAE_ENABLE);
+	mtsdram(SDRAM_RDCC,
+		ddr_rdss_opt(SDRAM_RDCC_RDSS_T2) | SDRAM_RDCC_RSAE_ENABLE);
 
 #ifdef DEBUG
 	mfsdram(SDRAM_RDCC, temp);
@@ -1013,10 +1029,10 @@ u32 DQS_autocalibration(void)
 #endif
 
 		debug("\n");
-		if (verbose_lvl > 2) {
-			printf("*** SDRAM_WRDTR (wdtr) set to %d\n", wdtr);
-			printf("*** SDRAM_CLKTR (clkp) set to %d\n", clkp);
-		}
+		DDR_VERBOSE_PRT(2, verbose_lvl,
+			"*** SDRAM_WRDTR (wdtr) set to %d\n", wdtr);
+		DDR_VERBOSE_PRT(2, verbose_lvl,
+			"*** SDRAM_CLKTR (clkp) set to %d\n", clkp);
 
 		memset(&ddrcal, 0, sizeof(ddrcal));
 
@@ -1091,91 +1107,81 @@ u32 DQS_autocalibration(void)
 		 * if no passing window was found, or is the
 		 * size of the RFFD passing window.
 		 */
-		if (result != 0) {
-			tcal.autocal.flags = 1;
-			debug("*** (%d)(%d) result passed window size: 0x%08x, "
-			      "rqfd = 0x%08x, rffd = 0x%08x, rdcc = 0x%08x\n",
-				wdtr, clkp, result, ddrcal.rqfd,
-				ddrcal.rffd, ddrcal.rdcc);
-			/*
-			 * Save the SDRAM_WRDTR and SDRAM_CLKTR
-			 * settings for the largest returned
-			 * RFFD passing window size.
-			 */
-			if (result > best_result) {
+		/*
+		 * want the lowest Read Sample Cycle Select
+		 */
+		val = (val & SDRAM_RDCC_RDSS_MASK) >> 30;
+		debug("*** (%d) (%d) current_rdcc, best_rdcc\n",
+					val, best_rdcc);
+		if ((result != 0) &&
+		    (val >= (ddr_rdss_opt(SDRAM_RDCC_RDSS_T2) >> 30))) {
+			if (((result == best_result) && (val < best_rdcc)) ||
+			    ((result > best_result) && (val <= best_rdcc))) {
+				tcal.autocal.flags = 1;
+				debug("*** (%d)(%d) result passed window "
+					"size: 0x%08x, rqfd = 0x%08x, "
+					"rffd = 0x%08x, rdcc = 0x%08x\n",
+					wdtr, clkp, result, ddrcal.rqfd,
+					ddrcal.rffd, ddrcal.rdcc);
 				/*
-				 * want the lowest Read Sample Cycle Select
+				 * Save the SDRAM_WRDTR and SDRAM_CLKTR
+				 * settings for the largest returned
+				 * RFFD passing window size.
 				 */
-				val = (val & SDRAM_RDCC_RDSS_MASK) >> 30;
-				debug("*** (%d) (%d) current_rdcc, best_rdcc\n",
-							val, best_rdcc);
-				if (val <= best_rdcc) {
-					best_rdcc = val;
-					tcal.clocks.wrdtr = wdtr;
-					tcal.clocks.clktr = clkp;
-					tcal.clocks.rdcc = (val << 30);
-					tcal.autocal.rqfd = ddrcal.rqfd;
-					tcal.autocal.rffd = ddrcal.rffd;
-					best_result = result;
-
-					if (verbose_lvl > 2) {
-						printf("** (%d)(%d)  "
-						       "best result: 0x%04x\n",
-							wdtr, clkp,
-							best_result);
-						printf("** (%d)(%d)  "
-						       "best WRDTR: 0x%04x\n",
-							wdtr, clkp,
-							tcal.clocks.wrdtr);
-						printf("** (%d)(%d)  "
-						       "best CLKTR: 0x%04x\n",
-							wdtr, clkp,
-							tcal.clocks.clktr);
-						printf("** (%d)(%d)  "
-						       "best RQDC: 0x%04x\n",
-							wdtr, clkp,
-							tcal.autocal.rqfd);
-						printf("** (%d)(%d)  "
-						       "best RFDC: 0x%04x\n",
-							wdtr, clkp,
-							tcal.autocal.rffd);
-						printf("** (%d)(%d)  "
-						       "best RDCC: 0x%08x\n",
-							wdtr, clkp,
-							(u32)tcal.clocks.rdcc);
-						mfsdram(SDRAM_RTSR, val);
-						printf("** (%d)(%d)  best "
-						       "loop RTSR: 0x%08x\n",
-							wdtr, clkp, val);
-						mfsdram(SDRAM_FCSR, val);
-						printf("** (%d)(%d)  best "
-						       "loop FCSR: 0x%08x\n",
-							wdtr, clkp, val);
-					}
-				} /* if (val <= best_rdcc) */
-			} /* if (result >= best_result) */
-		} /* if (result != 0) */
+				best_rdcc = val;
+				tcal.clocks.wrdtr = wdtr;
+				tcal.clocks.clktr = clkp;
+				tcal.clocks.rdcc = (val << 30);
+				tcal.autocal.rqfd = ddrcal.rqfd;
+				tcal.autocal.rffd = ddrcal.rffd;
+				best_result = result;
+
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best result: 0x%04x\n",
+					wdtr, clkp, best_result);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best WRDTR: 0x%04x\n",
+					wdtr, clkp, tcal.clocks.wrdtr);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best CLKTR: 0x%04x\n",
+					wdtr, clkp, tcal.clocks.clktr);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best RQDC: 0x%04x\n",
+					wdtr, clkp, tcal.autocal.rqfd);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best RFDC: 0x%04x\n",
+					wdtr, clkp, tcal.autocal.rffd);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best RDCC: 0x%08x\n",
+					wdtr, clkp, tcal.clocks.rdcc);
+				mfsdram(SDRAM_RTSR, val);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best loop RTSR: 0x%08x\n",
+					wdtr, clkp, val);
+				mfsdram(SDRAM_FCSR, val);
+				DDR_VERBOSE_PRT(2, verbose_lvl,
+					"** (%d)(%d)  best loop FCSR: 0x%08x\n",
+					wdtr, clkp, val);
+			}
+		} /* if ((result != 0) && (val >= (ddr_rdss_opt()))) */
 		scan_list++;
 	} /* while ((scan_list->wrdtr != -1) && (scan_list->clktr != -1)) */
 
 	if (tcal.autocal.flags == 1) {
-		if (verbose_lvl > 0) {
-			printf("*** --------------\n");
-			printf("*** best_result window size: %d\n",
-							best_result);
-			printf("*** best_result WRDTR: 0x%04x\n",
-							tcal.clocks.wrdtr);
-			printf("*** best_result CLKTR: 0x%04x\n",
-							tcal.clocks.clktr);
-			printf("*** best_result RQFD: 0x%04x\n",
-							tcal.autocal.rqfd);
-			printf("*** best_result RFFD: 0x%04x\n",
-							tcal.autocal.rffd);
-			printf("*** best_result RDCC: 0x%04x\n",
-							tcal.clocks.rdcc);
-			printf("*** --------------\n");
-			printf("\n");
-		}
+		DDR_VERBOSE_PRT(0, verbose_lvl, "*** --------------\n");
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result window size: %d\n", best_result);
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result WRDTR: 0x%04x\n", tcal.clocks.wrdtr);
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result CLKTR: 0x%04x\n", tcal.clocks.clktr);
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result RQFD: 0x%04x\n", tcal.autocal.rqfd);
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result RFFD: 0x%04x\n", tcal.autocal.rffd);
+		DDR_VERBOSE_PRT(0, verbose_lvl,
+			"*** best_result RDCC: 0x%04x\n", tcal.clocks.rdcc);
+		DDR_VERBOSE_PRT(0, verbose_lvl, "*** --------------\n\n");
 
 		/*
 		 * if got best passing result window, then lock in the
diff --git a/include/configs/kilauea.h b/include/configs/kilauea.h
index b943f31..237a9c5 100644
--- a/include/configs/kilauea.h
+++ b/include/configs/kilauea.h
@@ -235,16 +235,9 @@
  *
  * DDR Autocalibration Method_B is the default.
  */
-#if 0
-/*
- * Needs FIX!!!
- * Disable autocalibration for now, because of the unresolved problem
- * with kilauea board using 200MHz PLB/DDR2 frequency
- */
 #define	CONFIG_PPC4xx_DDR_AUTOCALIBRATION	/* IBM DDR autocalibration */
 #define	DEBUG_PPC4xx_DDR_AUTOCALIBRATION	/* dynamic DDR autocal debug */
 #undef	CONFIG_PPC4xx_DDR_METHOD_A
-#endif
 
 #define	CONFIG_SYS_SDRAM0_MB0CF_BASE	((  0 << 20) + CONFIG_SYS_SDRAM_BASE)
 
-- 
1.5.5



More information about the U-Boot mailing list