Skip to contentSkip to conversation

added autodetect of sdram size and nr of banks for ixp

PATCH New Martijn de Gouw 3 participants 6 messages Sep 13, 2008 – Sep 15, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

Add autodetection of nr of banks and total sdram size tested on ixpdg425 and pdnb3 board.

---
 board/prodrive/pdnb3/pdnb3.c |   31 +++++++++++++-
 cpu/ixp/start.S              |   95
++++++++++++++++++++++++++++++++++++++++++
 include/configs/pdnb3.h      |    2 -
 3 files changed, 125 insertions(+), 3 deletions(-)
board/prodrive/pdnb3/pdnb3.c +1 -0
index 3445a3a..a049afe 100644
@@ -120,8 +120,37 @@ int checkboard(void)
 
 int dram_init(void)
 {
+	volatile unsigned long *sdr_config = (unsigned long

*)IXP425_SDR_CONFIG;
+
gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
- gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
+
+ switch ((*sdr_config & ~(0x18))) {
+ case 0x20:
+ gd->bd->bi_dram[0].size = (8 << 20);
+ break;
+ case 0x21:
+ case 0x22:
+ gd->bd->bi_dram[0].size = (16 << 20);
+ break;
+ case 0x23:
+ case 0x00:
+ gd->bd->bi_dram[0].size = (32 << 20);
+ break;
+ case 0x01:
+ case 0x02:
+ gd->bd->bi_dram[0].size = (64 << 20);
+ break;
+ case 0x03:
+ case 0x04:
+ gd->bd->bi_dram[0].size = (128 << 20);
+ break;
+ case 0x09:
+ gd->bd->bi_dram[0].size = (256 << 20);
+ break;
+ default:
+ gd->bd->bi_dram[0].size = 0;
+ break;
+ }

return (0);
}

cpu/ixp/start.S +95 -0

108 lines not on this page · raw message

include/configs/pdnb3.h +0 -2
index 889207a..ea15052 100644
@@ -186,7 +186,6 @@
  */
 #define CONFIG_NR_DRAM_BANKS    1          /* we have 1 bank of DRAM */
 #define PHYS_SDRAM_1            0x00000000 /* SDRAM Bank #1 */
-#define PHYS_SDRAM_1_SIZE       0x02000000 /* 32 MB */
 
 #define CFG_FLASH_BASE          0x50000000
 #define CFG_MONITOR_BASE	CFG_FLASH_BASE
@@ -209,7 +208,6 @@
 /*
  * SDRAM settings
  */
-#define CFG_SDR_CONFIG		0x18
 #define CFG_SDR_MODE_CONFIG	0x1
 #define CFG_SDRAM_REFRESH_CNT	0x81a
 
Signature · 7 lines
1.5.5

Disclaimer: The information contained in this email, including any attachments is 
confidential and is for the sole use of the intended recipient(s). Any unauthorized 
review, use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please notify the sender immediately by replying to this message and 
destroy all copies of this message and any attachments.
#1 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

Dear "Martijn de Gouw",

Quoted 16 lines · In message <[email protected]> you…

Add autodetection of nr of banks and total sdram size tested on ixpdg425 and pdnb3 board.

---
 board/prodrive/pdnb3/pdnb3.c |   31 +++++++++++++-
 cpu/ixp/start.S              |   95
++++++++++++++++++++++++++++++++++++++++++
 include/configs/pdnb3.h      |    2 -
 3 files changed, 125 insertions(+), 3 deletions(-)
board/prodrive/pdnb3/pdnb3.c +0 -0
index 3445a3a..a049afe 100644

board/prodrive/pdnb3/pdnb3.c int checkboard(void) · line 124

Quoted 5 lines
board/prodrive/pdnb3/pdnb3.c +1 -0
@@ -120,8 +120,37 @@ int checkboard(void)
 
 int dram_init(void)
 {
+	volatile unsigned long *sdr_config = (unsigned long
 *)IXP425_SDR_CONFIG;

^^^^^^^^^^^^^^^^^^^^^^

Your patch has been corrupted by your mailer which wrapped long lines. Please fix your mailer setup and resubmit.

Quoted 6 lines
cpu/ixp/start.S +0 -0
index d4c8e33..f1123de 100644
@@ -165,7 +165,16 @@ reset:
 	orr     r1, r1, #0x80000000

cpu/ixp/start.S reset: · line 175

Quoted 10 lines
cpu/ixp/start.S +7 -0
 	str     r1, [r2]
 #endif
+
+#ifdef CFG_SDR_CONFIG
 	mov	r1, #CFG_SDR_CONFIG
+	mov	r9, #0xff
+#else
+	mov	r1, #0x1d /* 256 MB, two banks of 128 MB */
+	mov	r9, #0
+#endif

I don't want such $ifdef's in global code. Why do you thinkthat 2 x 128 MB would be a default configuration for all IXP based boards?

Quoted 84 lines
cpu/ixp/start.S +77 -0
+sdr_init:
 	ldr     r2, =IXP425_SDR_CONFIG
 	str     r1, [r2]
 
@@ -208,6 +217,92 @@ reset:
 	str	r1, [r4]
 	DELAY_FOR 0x4000, r0
 
+	cmp	r9, #0xff
+	beq	sdr_init_done
+
+sdr_test_cs1:
+	/* test if there are chips connected to bank 1 */
+	mov	r9, #0x18 /* holds new SDR_CONFIG value */
+	mov	r1, #(256 << 20)
+	orr	r1, r1, #(128 << 20)
+	orr	r1, r1, #(1 << 20)
+	mov	r2, #0
+	str	r2, [r1]
+	ldr	r3, [r1]
+	cmp	r2, r3
+	bne	sdr_test_cs0
+	orr	r9, r9, #(0x01)
+
+sdr_test_cs0:
+	/* test chip size on bank 0 */
+	/* r1: holds test address */
+	/* r3: holds test value */
+	/* r5: holds mirror address */
+
+	/* clear @ 1MB */
+	mov	r1, #(1 << 20)
+	orr	r1, r1, #(256 << 20)
+	mov	r2, #0
+	str	r2, [r1]
+
+	/* test value and test offset */
+	mov	r3, #0xbe
+	orr	r3, r3, #(0xba << 8)
+	orr	r3, r3, #(0xfe << 16)
+	orr	r3, r3, #(0xca << 24)
+
+	mov	r4, #(1 << 20)
+	orr	r4, r4, #(256 << 20)
+	b	sdr_try_32Mbit
+
+sdr_try_32Mbit:
+	orr	r5, r4, #(4 << 20)
+	str	r3, [r5]
+	ldr	r6, [r1]
+	cmp	r6, r3
+	bne	sdr_try_64Mbit
+	add	r9, r9, #0x00
+	orr	r9, r9, #(1 << 5)
+	b	sdr_reinit
+
+sdr_try_64Mbit:
+	orr	r5, r4, #(4 << 20)
+	str	r3, [r5]
+	ldr	r6, [r1]
+	cmp	r6, r3
+	bne	sdr_try_128Mbit
+	add	r9, r9, #0x02
+	orr	r9, r9, #(1 << 5)
+	b	sdr_reinit
+
+sdr_try_128Mbit:
+	orr	r5, r4, #(8 << 20)
+	str	r3, [r5]
+	ldr	r6, [r1]
+	cmp	r6, r3
+	bne	sdr_try_256Mbit
+	add	r9, r9, #0x00
+	b	sdr_reinit
+
+sdr_try_256Mbit:
+	orr	r5, r4, #(16 << 20)
+	str	r3, [r5]
+	ldr	r6, [r1]
+	cmp	r6, r3
+	bne	sdr_try_512Mbit
+	add	r9, r9, #0x02
+	b	sdr_reinit
+

cpu/ixp/start.S reset: · line 305

Quoted 10 lines
cpu/ixp/start.S +10 -0
+sdr_try_512Mbit:
+	add	r9, r9, #0x04
+	b	sdr_reinit
+
+sdr_reinit:
+	mov	r1, r9
+	mov	r9, #0xff
+	b	sdr_init
+
+sdr_init_done:

This whole test makes not much sense to me. I think the code should be changed to use the standard get_ram_size() funciton instead (see common/memsize.c).

Best regards,

Wolfgang Denk

Signature · 4 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
"Tell the truth and run."                          - Yugoslav proverb
#2 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

Hi Wolfgang

Quoted 11 lines

cpu/ixp/start.S reset: · line 175

Quoted 8 lines
cpu/ixp/start.S +7 -0
+
+#ifdef CFG_SDR_CONFIG
 	mov	r1, #CFG_SDR_CONFIG
+	mov	r9, #0xff
+#else
+	mov	r1, #0x1d /* 256 MB, two banks of 128 MB */
+	mov	r9, #0
+#endif

I don't want such $ifdef's in global code. Why do you thinkthat 2 x 128 MB would be a default configuration for all IXP based boards?

When CFG_SDR_CONFIG is defined, it holds the memory size, which is set in the config.h
When this value is not set, autodetection is assumed. Setting up the board as 2 x 128Mb is used for the autodetection.

Quoted 2 lines
Quoted 2 lines

+sdr_init:

/* snip */

Quoted 5 lines
Quoted 1 line

+sdr_init_done:

This whole test makes not much sense to me. I think the code should be changed to use the standard get_ram_size() funciton instead (see common/memsize.c).

get_ram_size will nog set the memory controller to the correct size. The ixp can not run C code when memory is not initialized.

Maybe it could be used as a replacement for the code in pdnb.c yes.

Regards, Martijn

Disclaimer: The information contained in this email, including any attachments is confidential and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments.

#3 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

Dear "Martijn de Gouw",

Quoted 13 lines · In message <[email protected]> you…
Quoted 12 lines

cpu/ixp/start.S reset: · line 175

Quoted 9 lines
cpu/ixp/start.S +7 -0
+
+#ifdef CFG_SDR_CONFIG
 	mov	r1, #CFG_SDR_CONFIG
+	mov	r9, #0xff
+#else
+	mov	r1, #0x1d /* 256 MB, two banks of 128 MB */
+	mov	r9, #0
+#endif

I don't want such $ifdef's in global code. Why do you thinkthat 2 x 128 MB would be a default configuration for all IXP based boards?

Quoted 4 lines

When CFG_SDR_CONFIG is defined, it holds the memory size, which is set in the config.h
When this value is not set, autodetection is assumed. Setting up the board as 2 x 128Mb is used for the autodetection.

You could set CFG_SDR_CONFIG to that value in your board config file and avoid the #ifdef ?

Quoted 1 line

get_ram_size will nog set the memory controller to the correct size.

No, it does not set the size, it auto-detects the size that can be seen for a specific configuration of the memory controller.

Quoted 1 line

The ixp can not run C code when memory is not initialized.

Has it not enough on-chip memory or caches for that like other processors?

Best regards,

Wolfgang Denk

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-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Anarchy may not be the best form of government, but it's better  than
no government at all.
#4 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

In reply to Martijn de Gouw

Hi Martijn,

Quoted 11 lines · Martijn de Gouw
Quoted 10 lines

cpu/ixp/start.S reset: · line 175

Quoted 7 lines
cpu/ixp/start.S +6 -0
+#ifdef CFG_SDR_CONFIG
 	mov	r1, #CFG_SDR_CONFIG
+	mov	r9, #0xff
+#else
+	mov	r1, #0x1d /* 256 MB, two banks of 128 MB */
+	mov	r9, #0
+#endif

I don't want such $ifdef's in global code. Why do you thinkthat 2 x 128 MB would be a default configuration for all IXP based boards?

Quoted 4 lines

When CFG_SDR_CONFIG is defined, it holds the memory size, which is set in the config.h
When this value is not set, autodetection is assumed. Setting up the board as 2 x 128Mb is used for the autodetection.

Understood. Nevertheless the resulting code is quite complex hard to read.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

+sdr_init:

/* snip */

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+sdr_init_done:

This whole test makes not much sense to me. I think the code should be changed to use the standard get_ram_size() funciton instead (see common/memsize.c).

get_ram_size will nog set the memory controller to the correct size. The ixp can not run C code when memory is not initialized.

Because of the missing C environment (stack etc)? We could probably use a part of the QueueManager SRAM for a temorary initial stack, so that we could run C code very early. And do the SDRAM initialization and autodetection in C instead of assembler (as done for PPC).

If we could run this SDRAM setup code in C, you could implement a weak default init function that could be overwritten by a board specific version (in your case). This way we wouldn't add more custom stuff into the common/generic source files.

What do you think?

Quoted 1 line

Maybe it could be used as a replacement for the code in pdnb.c yes.

Yes. This should be replaced.

Best regards,
Stefan

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

#5 lore raw

PATCH 1/1 added autodetect of sdram size and nr of banks for ixp

Hi

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

cpu/ixp/start.S reset: · line 175

Quoted 7 lines
cpu/ixp/start.S +6 -0
+#ifdef CFG_SDR_CONFIG
 	mov	r1, #CFG_SDR_CONFIG
+	mov	r9, #0xff
+#else
+	mov	r1, #0x1d /* 256 MB, two banks of 128 MB */
+	mov	r9, #0
+#endif

I don't want such $ifdef's in global code. Why do you

thinkthat 2 x

Quoted 2 lines
Quoted 1 line

128 MB would be a default configuration for all IXP based boards?

Quoted 8 lines
Quoted 1 line

When CFG_SDR_CONFIG is defined, it holds the memory size,

which is set

Quoted 3 lines

in the config.h
When this value is not set, autodetection is assumed. Setting up the board as 2 x 128Mb is used for the autodetection.

Understood. Nevertheless the resulting code is quite complex hard to read.

Not complex, just hard to read because of assembly :)

Quoted 15 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

+sdr_init:

/* snip */

Quoted 3 lines
Quoted 1 line

+sdr_init_done:

This whole test makes not much sense to me. I think the

code should be

Quoted 5 lines
Quoted 2 lines

changed to use the standard get_ram_size() funciton instead (see common/memsize.c).

get_ram_size will nog set the memory controller to the correct size. The ixp can not run C code when memory is not initialized.

Quoted 7 lines

Because of the missing C environment (stack etc)? We could probably use a part
of the QueueManager SRAM for a temorary initial stack, so that we could run C
code very early. And do the SDRAM initialization and autodetection in C
instead of assembler (as done for PPC).

This would involve a large change in the code, compared to this patch. Even the relocation code is in assembler right now (because of this reason)

Quoted 4 lines

If we could run this SDRAM setup code in C, you could implement a weak default
init function that could be overwritten by a board specific version (in your

Yes, ofcource, in C life is much simpler.

Quoted 5 lines

case). This way we wouldn't add more custom stuff into the common/generic
source files.

What do you think?

I think that this code could be used as generic code, it is not board specific code.
I could change de ifdef structure to enable/disable the autodetection part, instead of using the CFG_SDR_CONFIG define, but a ifdef would remain.

Quoted 4 lines
Quoted 2 lines

Maybe it could be used as a replacement for the code in pdnb.c yes.

Yes. This should be replaced.

Ok, makes sense.

Regards, Martijn de Gouw

Disclaimer: The information contained in this email, including any attachments is confidential and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments.