Skip to contentSkip to conversation

Add new Elpida memory configuration for ads5121

PATCH New Martha Marx 2 participants 2 messages Feb 19, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add new Elpida memory configuration for ads5121

Rev 3 and earlier stay with Micron memory settings. Rev 4 and later will default to Elpida settings. CONFIG_ELPIDA forces these setting and will run slightly more slowly. CONFIG_MICRON will force Micron settings. If Micron settings are used, if a memory test fails, it will revert to the slower Elpida settings

---
 board/ads5121/ads5121.c   |  154 ++++++++++++++++++++++++++++++++++++---------
 include/configs/ads5121.h |   41 +++++++-----
 2 files changed, 150 insertions(+), 45 deletions(-)
board/ads5121/ads5121.c +125 -29
index 6c40e94..deb4a74 100644
@@ -120,13 +120,53 @@ phys_size_t initdram (int board_type)
 	return msize;
 }
 
+int simple_mem_check()
+{
+	volatile u32 val;
+	volatile u32 *addr;
+	int i, j;
+	u32 save[32];
+
+	/*
+	 * Very very simple non-destructive check for operational RAM.
+	 */
+	j = 0;
+	for (i = CONFIG_SYS_DDR_SIZE / sizeof (long); i > 0; i >>= 1) {
+		addr = (volatile u32 *) CONFIG_SYS_DDR_BASE + i;
+		save[j++] = *addr;
+		*addr = ~i;
+	}
+
+	addr = (volatile u32 *) CONFIG_SYS_DDR_BASE;
+	save[j] = *addr;
+	*addr = 0xdeadbeef;
+	val = *addr;
+	*addr = save[j];
+
+	if (val != 0xdeadbeef)
+		return (0);
+
+	for (i = 1; i <= CONFIG_SYS_DDR_SIZE / sizeof (long); i <<= 1) {
+		addr = (volatile u32 *) CONFIG_SYS_DDR_BASE + i;
+		val = *addr;
+		*addr = save[--j];
+		if (val != ~i)
+			return (0);
+	}
+	return(1);
+}
+
 /*
  * fixed sdram init -- the board doesn't use memory modules that have serial presence
  * detect or similar mechanism for discovery of the DRAM settings
  */
+
 long int fixed_sdram (void)
 {
+	u32 try_elpida;
 	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
+
 	u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
 	u32 msize_log2 = __ilog2 (msize);
 	u32 i;
@@ -174,41 +214,97 @@ long int fixed_sdram (void)
 	im->mddrc.lut_table4_alternate_upper = CONFIG_SYS_MDDRCGRP_LUT4_AU;
 	im->mddrc.lut_table4_alternate_lower = CONFIG_SYS_MDDRCGRP_LUT4_AL;
 
+#ifdef CONFIG_MICRON
+/* forces Micron settings - on rev 4 boards will retry w/Elpida if necessary */
+	try_elpida = 0;
+#elif defined(CONFIG_ELPIDA)
+/* forces Elpida settings w/slower CAS - works w/ both Micron and Elpida rev4 */
+	try_elpida = 1;
+#else
+	if (brd_rev >= 0x0400)
+		try_elpida = 1;
+	else
+		try_elpida = 0;
+#endif
+retry:
+	debug("Use %s Memory settings\n\t", try_elpida ? "Elpida" : "Micron");
+
 	/* Initialize MDDRC */
-	im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG;
-	im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
-	im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1;
-	im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2;
+	if (try_elpida) {
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA;
+		im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
+		im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA;
+		im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA;
+	} else {
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_MICRON;
+		im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
+		im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_MICRON;
+		im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_MICRON;
+	}
 
 	/* Initialize DDR */
 	for (i = 0; i < 10; i++)
-		im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_PCHG_ALL;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_RFSH;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_RFSH;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_EM2;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_PCHG_ALL;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_EM2;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_EM3;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_EN_DLL;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_PCHG_ALL;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_RFSH;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_OCD_DEFAULT;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_PCHG_ALL;
-	im->mddrc.ddr_command = CONFIG_SYS_MICRON_NOP;
-
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_PCHG_ALL;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+
+	if (try_elpida) {
+	/* Elpida init sequence - works for Micron too but runs slower */
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EM2;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EM3;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EN_DLL;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RES_DLL;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_PCHG_ALL;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_ELPIDA_INIT_DEV_OP;
+		udelay(200);
+	} else {
+	/* Micron init sequence */
+		im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EM2;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_PCHG_ALL;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EM2;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EM3;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_EN_DLL;
+		im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_PCHG_ALL;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+		im->mddrc.ddr_command = CONFIG_SYS_MICRON_INIT_DEV_OP;
+		udelay(200);
+	}
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_OCD_DEFAULT;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_OCD_EXIT;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+	for (i = 0; i < 10; i++)
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
 	/* Start MDDRC */
 	im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0_RUN;
-	im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_RUN;
+
+	if (try_elpida)
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA_RUN;
+	else
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_MICRON_RUN;
+
+	if (try_elpida == 0) {
+		if (!simple_mem_check()) {
+			debug("Mem check failed\n\t");
+			try_elpida += 1;
+			im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_EN;
+			goto retry;
+		}
+	}
+	debug("Mem check %s\n\t", simple_mem_check()? "Passes":"Fails");
 
 	return msize;
 }
include/configs/ads5121.h +25 -16

54 lines not on this page · raw message

Signature · 1 line
1.5.2.4
#1 lore raw

PATCH 1/1 Add new Elpida memory configuration for ads5121

Dear Martha,

Quoted 45 lines · In message <[email protected]> you wrote:

Rev 3 and earlier stay with Micron memory settings. Rev 4 and later will default to Elpida settings. CONFIG_ELPIDA forces these setting and will run slightly more slowly. CONFIG_MICRON will force Micron settings. If Micron settings are used, if a memory test fails, it will revert to the slower Elpida settings

---
 board/ads5121/ads5121.c   |  154 ++++++++++++++++++++++++++++++++++++---------
 include/configs/ads5121.h |   41 +++++++-----
 2 files changed, 150 insertions(+), 45 deletions(-)
board/ads5121/ads5121.c +25 -0
index 6c40e94..deb4a74 100644
@@ -120,13 +120,53 @@ phys_size_t initdram (int board_type)
 	return msize;
 }
 
+int simple_mem_check()
+{
+	volatile u32 val;
+	volatile u32 *addr;
+	int i, j;
+	u32 save[32];
+
+	/*
+	 * Very very simple non-destructive check for operational RAM.
+	 */
+	j = 0;
+	for (i = CONFIG_SYS_DDR_SIZE / sizeof (long); i > 0; i >>= 1) {
+		addr = (volatile u32 *) CONFIG_SYS_DDR_BASE + i;
+		save[j++] = *addr;
+		*addr = ~i;
+	}
+
+	addr = (volatile u32 *) CONFIG_SYS_DDR_BASE;
+	save[j] = *addr;
+	*addr = 0xdeadbeef;
+	val = *addr;
+	*addr = save[j];
+
+	if (val != 0xdeadbeef)
+		return (0);

board/ads5121/ads5121.c phys_size_t initdram (int board_type) · line 157

Quoted 10 lines
board/ads5121/ads5121.c +10 -0
+
+	for (i = 1; i <= CONFIG_SYS_DDR_SIZE / sizeof (long); i <<= 1) {
+		addr = (volatile u32 *) CONFIG_SYS_DDR_BASE + i;
+		val = *addr;
+		*addr = save[--j];
+		if (val != ~i)
+			return (0);
+	}
+	return(1);
+}

We already have that code, just a bit more general and non-destructive, as function get_ram_size() in "common/memsize.c".

Please do not reinvent the wheel - use the existing code instead (ideally this should also be used to auto-adjust the RAM size on the boards).

board/ads5121/ads5121.c phys_size_t initdram (int board_type) · line 163

Quoted 5 lines
board/ads5121/ads5121.c +1 -0
 /*
  * fixed sdram init -- the board doesn't use memory modules that have serial presence
  * detect or similar mechanism for discovery of the DRAM settings
  */
+

Please do not add random white space changes.

Quoted 16 lines
board/ads5121/ads5121.c +6 -0
 long int fixed_sdram (void)
 {
+	u32 try_elpida;
 	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
+
 	u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
 	u32 msize_log2 = __ilog2 (msize);
 	u32 i;
@@ -174,41 +214,97 @@ long int fixed_sdram (void)
 	im->mddrc.lut_table4_alternate_upper = CONFIG_SYS_MDDRCGRP_LUT4_AU;
 	im->mddrc.lut_table4_alternate_lower = CONFIG_SYS_MDDRCGRP_LUT4_AL;
 
+#ifdef CONFIG_MICRON
+/* forces Micron settings - on rev 4 boards will retry w/Elpida if necessary */
+	try_elpida = 0;

board/ads5121/ads5121.c long int fixed_sdram (void) · line 229

Quoted 10 lines
board/ads5121/ads5121.c +10 -0
+#elif defined(CONFIG_ELPIDA)
+/* forces Elpida settings w/slower CAS - works w/ both Micron and Elpida rev4 */
+	try_elpida = 1;
+#else
+	if (brd_rev >= 0x0400)
+		try_elpida = 1;
+	else
+		try_elpida = 0;
+#endif
+retry:

Please keep the code simple. As discussed by PM before, please drop the config stuff and support for old boards that long have reached EOL.

Old boards can be used with the existing U-Boot; here in mainline we should support board rev. 4.x and higher only.

Quoted 8 lines
board/ads5121/ads5121.c +3 -4
+	debug("Use %s Memory settings\n\t", try_elpida ? "Elpida" : "Micron");
+
 	/* Initialize MDDRC */
-	im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG;
-	im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
-	im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1;
-	im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2;
+	if (try_elpida) {

board/ads5121/ads5121.c long int fixed_sdram (void) · line 243

Quoted 10 lines
board/ads5121/ads5121.c +10 -0
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA;
+		im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
+		im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA;
+		im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA;
+	} else {
+		im->mddrc.ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_MICRON;
+		im->mddrc.ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0;
+		im->mddrc.ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_MICRON;
+		im->mddrc.ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_MICRON;
+	}

Drop this. ALways use the (more relaxed?) Elpida settings.

board/ads5121/ads5121.c long int fixed_sdram (void) · line 254

Quoted 8 lines
board/ads5121/ads5121.c +8 -0
+		im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_PCHG_ALL;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_RFSH;
+	im->mddrc.ddr_command = CONFIG_SYS_DDR_NOP;

As mentioned a couple times before, we should start with an initial patch that performas a global rename to get rid of the (inappropiate) CONFIG_SYS_ names here.

Thanks.

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
As usual, this being a 1.3.x release, I haven't  even  compiled  this
kernel yet. So if it works, you should be doubly impressed.
      - Linus Torvalds in <[email protected]>