public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 17/20] M28: Add memory detection into SPL
Date: Wed,  9 Nov 2011 10:18:24 +0100	[thread overview]
Message-ID: <1320830307-4762-18-git-send-email-marek.vasut@gmail.com> (raw)
In-Reply-To: <1320830307-4762-1-git-send-email-marek.vasut@gmail.com>

This code allows the DDR DRAM size to be detected at runtime. The RAM size is
stored into two scratch registers, from which it is then fetched in U-Boot.

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Detlev Zundel <dzu@denx.de>

---
 board/denx/m28evk/Makefile   |    7 ++++++-
 board/denx/m28evk/m28evk.c   |   18 ++++++++++++++++--
 board/denx/m28evk/mem_init.c |   27 +++++++++++++++++++++++++++
 include/configs/m28evk.h     |    2 +-
 4 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/board/denx/m28evk/Makefile b/board/denx/m28evk/Makefile
index 47229e6..b6f002f 100644
--- a/board/denx/m28evk/Makefile
+++ b/board/denx/m28evk/Makefile
@@ -30,7 +30,7 @@ COBJS	:= m28evk.o
 endif
 
 ifdef	CONFIG_SPL_BUILD
-COBJS	:= mem_init.o mmc_boot.o power_init.o
+COBJS	:= mem_init.o mmc_boot.o power_init.o memsize.o
 endif
 
 SRCS	:= $(COBJS:.o=.c)
@@ -41,6 +41,11 @@ $(LIB):	$(obj).depend $(OBJS)
 
 all:	$(ALL)
 
+ifdef	CONFIG_SPL_BUILD
+memsize.c:
+	ln -sf $(TOPDIR)/common/memsize.c $@
+endif
+
 #########################################################################
 
 # defines $(obj).depend target
diff --git a/board/denx/m28evk/m28evk.c b/board/denx/m28evk/m28evk.c
index 118e222..168ceeb 100644
--- a/board/denx/m28evk/m28evk.c
+++ b/board/denx/m28evk/m28evk.c
@@ -63,10 +63,24 @@ int board_init(void)
 	return 0;
 }
 
+#define	HW_DIGCTRL_SCRATCH0	0x8001c280
+#define	HW_DIGCTRL_SCRATCH1	0x8001c290
 int dram_init(void)
 {
-	/* dram_init must store complete ramsize in gd->ram_size */
-	gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
+	uint32_t sz[2];
+
+	sz[0] = readl(HW_DIGCTRL_SCRATCH0);
+	sz[1] = readl(HW_DIGCTRL_SCRATCH1);
+
+	if (sz[0] != sz[1]) {
+		printf("MX28:\n"
+			"Error, the RAM size in HW_DIGCTRL_SCRATCH0 and\n"
+			"HW_DIGCTRL_SCRATCH1 is not the same. Please\n"
+			"verify these two registers contain valid RAM size!\n");
+		hang();
+	}
+
+	gd->ram_size = sz[0];
 	return 0;
 }
 
diff --git a/board/denx/m28evk/mem_init.c b/board/denx/m28evk/mem_init.c
index 066fe0d..17d1f9b 100644
--- a/board/denx/m28evk/mem_init.c
+++ b/board/denx/m28evk/mem_init.c
@@ -165,6 +165,31 @@ void mx28_mem_setup_vddd(void)
 		&power_regs->hw_power_vdddctrl);
 }
 
+#define	HW_DIGCTRL_SCRATCH0	0x8001c280
+#define	HW_DIGCTRL_SCRATCH1	0x8001c290
+void data_abort_memdetect_handler(void) __attribute__((naked));
+void data_abort_memdetect_handler(void)
+{
+	asm volatile("subs pc, r14, #4");
+}
+
+void mx28_mem_get_size(void)
+{
+	uint32_t sz, da;
+	uint32_t *vt = (uint32_t *)0x20;
+
+	/* Replace the DABT handler. */
+	da = vt[4];
+	vt[4] = (uint32_t)&data_abort_memdetect_handler;
+
+	sz = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
+	writel(sz, HW_DIGCTRL_SCRATCH0);
+	writel(sz, HW_DIGCTRL_SCRATCH1);
+
+	/* Restore the old DABT handler. */
+	vt[4] = da;
+}
+
 void mx28_mem_init(void)
 {
 	struct mx28_clkctrl_regs *clkctrl_regs =
@@ -210,4 +235,6 @@ void mx28_mem_init(void)
 	early_delay(10000);
 
 	mx28_mem_setup_cpu_and_hbus();
+
+	mx28_mem_get_size();
 }
diff --git a/include/configs/m28evk.h b/include/configs/m28evk.h
index 381b01e..c8b0cf5 100644
--- a/include/configs/m28evk.h
+++ b/include/configs/m28evk.h
@@ -81,7 +81,7 @@
  */
 #define	CONFIG_NR_DRAM_BANKS		1		/* 2 banks of DRAM */
 #define	PHYS_SDRAM_1			0x40000000	/* Base address */
-#define	PHYS_SDRAM_1_SIZE		0x08000000	/* 128 MB */
+#define	PHYS_SDRAM_1_SIZE		0x40000000	/* Max 1 GB RAM */
 #define	CONFIG_STACKSIZE		0x00010000	/* 128 KB stack */
 #define	CONFIG_SYS_MALLOC_LEN		0x00400000	/* 4 MB for malloc */
 #define	CONFIG_SYS_GBL_DATA_SIZE	128		/* Initial data */
-- 
1.7.7.1

  parent reply	other threads:[~2011-11-09  9:18 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09  9:18 [U-Boot] [PATCH 00/20 FINAL] Support for the DENX M28 SoM Marek Vasut
2011-11-09  9:18 ` [U-Boot] [PATCH 01/20] iMX28: Initial support for iMX28 CPU Marek Vasut
2011-11-09  9:18 ` [U-Boot] [PATCH 02/20] iMX28: Add SSP MMC driver Marek Vasut
2011-11-10 13:08   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 03/20] FEC: Add support for iMX28 quirks Marek Vasut
2011-11-10 13:09   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 04/20] iMX28: Add PINMUX control Marek Vasut
2011-11-10 13:09   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 05/20] iMX28: Add I2C bus driver Marek Vasut
2011-11-09  9:38   ` Heiko Schocher
2011-11-09 10:46     ` Marek Vasut
2011-11-10 13:10   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 06/20] iMX28: Add GPIO control Marek Vasut
2011-11-10 13:11   ` Stefano Babic
2011-11-10 16:23   ` Mike Frysinger
2011-11-10 16:58     ` Marek Vasut
2011-11-10 17:10       ` Mike Frysinger
2011-11-10 17:44         ` Marek Vasut
2011-11-09  9:18 ` [U-Boot] [PATCH 07/20] iMX28: Add SPI driver Marek Vasut
2011-11-10 13:11   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 08/20] iMX28: Add APBH DMA driver Marek Vasut
2011-11-10 13:12   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 09/20] iMX28: Add GPMI NAND driver Marek Vasut
2011-11-10 13:12   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 10/20] iMX28: Add driver for internal RTC Marek Vasut
2011-11-10 13:12   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 11/20] iMX28: Add image header generator tool Marek Vasut
2011-11-10 13:12   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 12/20] iMX28: Add u-boot.sb target to Makefile Marek Vasut
2011-11-10 13:13   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 13/20] iMX28: Add support for DENX M28EVK board Marek Vasut
2011-11-10 13:13   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 14/20] M28: Add MMC SPL Marek Vasut
2011-11-10 13:13   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 15/20] M28: Add doc/README.m28 documentation Marek Vasut
2011-11-10 13:14   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 16/20] iMX28: Fix ARM vector handling Marek Vasut
2011-11-10 13:14   ` Stefano Babic
2011-11-09  9:18 ` Marek Vasut [this message]
2011-11-10 13:14   ` [U-Boot] [PATCH 17/20] M28: Add memory detection into SPL Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 18/20] iMX28: Add USB and USB PHY register definitions Marek Vasut
2011-11-10 13:15   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 19/20] iMX28: Add USB HOST driver Marek Vasut
2011-11-10 13:15   ` Stefano Babic
2011-11-09  9:18 ` [U-Boot] [PATCH 20/20] M28EVK: Enable USB HOST support Marek Vasut
2011-11-10 13:16   ` Stefano Babic
2011-11-11 14:07   ` Veli-Pekka Peltola
2011-11-11 17:49     ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1320830307-4762-18-git-send-email-marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox