Skip to contentSkip to conversation

at91rm9200: add autodetect sdram size

PATCH New Jean-Christophe PLAGNIOL-VILLARD 1 participant 2 messages Jan 27, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/2 at91rm9200: add autodetect sdram size

In reply to a message not in the archive
---
 arch/arm/mach-at91/at91rm9200_devices.c         |    3 +++
 arch/arm/mach-at91/include/mach/at91rm9200_mc.h |   30 +++++++++++++++++++++++
 2 files changed, 33 insertions(+)
arch/arm/mach-at91/at91rm9200_devices.c +3 -0
index 84d4c15..0f2ec1f 100644
@@ -25,6 +25,9 @@
 
 void at91_add_device_sdram(u32 size)
 {
+	if (!size)
+		size = at91rm9200_get_sdram_size();
+
 	arm_add_mem_device("ram0", AT91_CHIPSELECT_1, size);
 	add_mem_device("sram0", AT91RM9200_SRAM_BASE, AT91RM9200_SRAM_SIZE,
 			IORESOURCE_MEM_WRITEABLE);
arch/arm/mach-at91/include/mach/at91rm9200_mc.h +30 -0
index d34e4ed..fc44a61 100644
@@ -157,4 +157,34 @@
 #define		AT91_BFC_MUXEN		(1   << 18)		/* Multiplexed Bus Enable */
 #define		AT91_BFC_RDYEN		(1   << 19)		/* Ready Enable Mode */
 
+#ifndef __ASSEMBLY__
+#include <mach/io.h>
+static inline u32 at91rm9200_get_sdram_size(void)
+{
+	u32 cr, mr;
+	u32 size;
+
+	cr = at91_sys_read(AT91_SDRAMC_CR);
+	mr = at91_sys_read(AT91_SDRAMC_MR);
+
+	/* Formula:
+	 * size = bank << (col + row + 1);
+	 * if (bandwidth == 32 bits)
+	 *	size <<= 1;
+	 */
+	size = 1;
+	/* COL */
+	size += (cr & AT91_SDRAMC_NC) + 8;
+	/* ROW */
+	size += ((cr & AT91_SDRAMC_NR) >> 2) + 11;
+	/* BANK */
+	size = ((cr & AT91_SDRAMC_NB) ? 4 : 2) << size;
+	/* bandwidth */
+	if (!(mr & AT91_SDRAMC_DBW))
+		size <<= 1;
+
+	return size;
+}
+#endif
+
 #endif
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/2 at91rm9200ek: auto detect sdram size

---
 arch/arm/boards/at91rm9200ek/init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boards/at91rm9200ek/init.c +1 -1
index 0a360ae..66ea6b7 100644
@@ -39,7 +39,7 @@ static struct at91_ether_platform_data ether_pdata = {
 
 static int at91rm9200ek_mem_init(void)
 {
-	at91_add_device_sdram(32 * 1024 * 1024);
+	at91_add_device_sdram(0);
 
 	return 0;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox