mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH RFC] arm/imx: provide command to add ram device with autodetected size
@ 2012-07-26  9:53 Uwe Kleine-König
  2012-07-26 10:17 ` Juergen Beisert
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2012-07-26  9:53 UTC (permalink / raw)
  To: barebox

The amount of available ram is determined by the ESDCTL register, so
better don't hardcode the value.

This commit provides a command that can be used instead of
arm_add_mem_device and convertes pcm043 (on which this patch was tested)
to it.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

maybe better move the new function into a new file
arch/arm/mach-imx/esdctl.c and the prototype into <mach/esdctl.h>?

Also imx_add_ram1() is still missing. I will implement that when we
agree the patch's idea is useful.

Best regards
Uwe

 arch/arm/boards/pcm043/pcm043.c          |    2 +-
 arch/arm/mach-imx/devices.c              |   34 ++++++++++++++++++++++++++++++
 arch/arm/mach-imx/include/mach/devices.h |    1 +
 arch/arm/mach-imx/include/mach/esdctl.h  |    1 +
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 152b47c..b1bf8ef 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -103,7 +103,7 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
 
 static int pcm043_mem_init(void)
 {
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SZ_128M);
+	imx_add_ram0();
 
 	return 0;
 }
diff --git a/arch/arm/mach-imx/devices.c b/arch/arm/mach-imx/devices.c
index 6cd50f3..ca98a80 100644
--- a/arch/arm/mach-imx/devices.c
+++ b/arch/arm/mach-imx/devices.c
@@ -1,6 +1,10 @@
 #include <common.h>
 #include <driver.h>
 #include <mach/devices.h>
+#include <mach/esdctl.h>
+#include <mach/imx-regs.h>
+#include <asm/io.h>
+#include <asm/memory.h>
 
 static inline struct device_d *imx_add_device(char *name, int id, void *base, int size, void *pdata)
 {
@@ -52,3 +56,33 @@ struct device_d *imx_add_esdhc(void *base, int id, struct esdhc_platform_data *p
 {
 	return imx_add_device("imx-esdhc", id, base, 0x1000, pdata);
 }
+
+static void imx_add_ram(const char* name, resource_size_t base,
+		void __iomem *esdctladdr)
+{
+	u32 esdctl = readl(esdctladdr);
+	/*
+	 * with the fields ROW, COL and DSIZ all zero we have 11 rows, 8 cols
+	 * and 2 bytes bus width on 4 banks.
+	 */
+	resource_size_t size = 4 << (11 + 8 + 1);
+
+	if (!(esdctl & ESDCTL0_SDE))
+		/* SDRAM controller disabled, so no RAM here */
+		return;
+
+	/* calculate memory size: 4 banks * 2^#rows * 2^#cols * bytes/word */
+	size <<= (esdctl & ESDCTL0_ROW_MASK) >> 24;
+	size <<= (esdctl & ESDCTL0_COL_MASK) >> 20;
+
+	if ((esdctl & ESDCTL0_DSIZ_MASK) == ESDCTL0_DSIZ_31_0)
+		/* 4 bytes bus width */
+		size <<= 1;
+
+	arm_add_mem_device(name, base, size);
+}
+
+void imx_add_ram0(void)
+{
+	imx_add_ram("ram0", (resource_size_t)IMX_SDRAM_CS0, (void __iomem *)ESDCTL0);
+}
diff --git a/arch/arm/mach-imx/include/mach/devices.h b/arch/arm/mach-imx/include/mach/devices.h
index f0f730a..317ad17 100644
--- a/arch/arm/mach-imx/include/mach/devices.h
+++ b/arch/arm/mach-imx/include/mach/devices.h
@@ -17,3 +17,4 @@ struct device_d *imx_add_ipufb(void *base, struct imx_ipu_fb_platform_data *pdat
 struct device_d *imx_add_mmc(void *base, int id, void *pdata);
 struct device_d *imx_add_esdhc(void *base, int id, struct esdhc_platform_data *pdata);
 
+void imx_add_ram0(void);
diff --git a/arch/arm/mach-imx/include/mach/esdctl.h b/arch/arm/mach-imx/include/mach/esdctl.h
index 10c8b9b..91d4141 100644
--- a/arch/arm/mach-imx/include/mach/esdctl.h
+++ b/arch/arm/mach-imx/include/mach/esdctl.h
@@ -26,6 +26,7 @@
 #define ESDCTL0_DSIZ_31_16			(0 << 16)
 #define ESDCTL0_DSIZ_15_0			(1 << 16)
 #define ESDCTL0_DSIZ_31_0			(2 << 16)
+#define ESDCTL0_DSIZ_MASK			(3 << 16)
 #define ESDCTL0_REF1				(1 << 13)
 #define ESDCTL0_REF2				(2 << 13)
 #define ESDCTL0_REF4				(3 << 13)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-03 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-26  9:53 [PATCH RFC] arm/imx: provide command to add ram device with autodetected size Uwe Kleine-König
2012-07-26 10:17 ` Juergen Beisert
2012-07-27  8:14 ` Sascha Hauer
2012-08-02 16:32 ` [PATCH v2] " Uwe Kleine-König
2012-08-03 13:26   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox