summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mxs
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-08-13 15:02:52 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-14 08:54:40 +0200
commit7158c5987e6999f1fd89b7170c685a7b29bc8322 (patch)
tree8d40a826970a118e427aab268cdd2b83e59aaddf /arch/arm/mach-mxs
parent1c1f94ecc2cf658b751847306a913acc209af64d (diff)
downloadbarebox-7158c5987e6999f1fd89b7170c685a7b29bc8322.tar.gz
barebox-7158c5987e6999f1fd89b7170c685a7b29bc8322.tar.xz
ARM: i.MX23: Add memory size detection
No need for the boards to manually add memory, we can do this automatically by reading back the memory size from the SDRAM controller. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Roland Hieber <r.hieber@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-mxs')
-rw-r--r--arch/arm/mach-mxs/include/mach/imx23.h29
-rw-r--r--arch/arm/mach-mxs/soc-imx23.c4
2 files changed, 33 insertions, 0 deletions
diff --git a/arch/arm/mach-mxs/include/mach/imx23.h b/arch/arm/mach-mxs/include/mach/imx23.h
new file mode 100644
index 0000000000..56e76d5f50
--- /dev/null
+++ b/arch/arm/mach-mxs/include/mach/imx23.h
@@ -0,0 +1,29 @@
+#ifndef __MACH_IMX23_H
+#define __MACH_IMX23_H
+
+#include <linux/bitfield.h>
+#include <io.h>
+
+#define DRAM_CTL14_CS0_EN BIT(0)
+#define DRAM_CTL14_CS1_EN BIT(1)
+#define DRAM_CTL11_COLUMNS_DIFF GENMASK(10, 8)
+#define DRAM_CTL10_ROWS_DIFF GENMASK(18, 16)
+
+#define DRAM_CTL(n) (IMX_SDRAMC_BASE + 4 * (n))
+
+static inline u32 imx23_get_memsize(void)
+{
+ u32 ctl10 = readl(DRAM_CTL(10));
+ u32 ctl11 = readl(DRAM_CTL(11));
+ u32 ctl14 = readl(DRAM_CTL(14));
+ int rows, columns, banks = 4, cs0, cs1;
+
+ columns = 12 - FIELD_GET(DRAM_CTL11_COLUMNS_DIFF, ctl11);
+ rows = 13 - FIELD_GET(DRAM_CTL10_ROWS_DIFF, ctl10);
+ cs0 = FIELD_GET(DRAM_CTL14_CS0_EN, ctl14);
+ cs1 = FIELD_GET(DRAM_CTL14_CS1_EN, ctl14);
+
+ return (1 << columns) * (1 << rows) * banks * (cs0 + cs1);
+}
+
+#endif /* __MACH_IMX23_H */ \ No newline at end of file
diff --git a/arch/arm/mach-mxs/soc-imx23.c b/arch/arm/mach-mxs/soc-imx23.c
index d471c8eb5c..f25fff18c3 100644
--- a/arch/arm/mach-mxs/soc-imx23.c
+++ b/arch/arm/mach-mxs/soc-imx23.c
@@ -19,6 +19,8 @@
#include <restart.h>
#include <mach/imx23-regs.h>
#include <io.h>
+#include <asm/memory.h>
+#include <mach/imx23.h>
#define HW_CLKCTRL_RESET 0x120
# define HW_CLKCTRL_RESET_CHIP (1 << 1)
@@ -37,6 +39,8 @@ static void __noreturn imx23_restart_soc(struct restart_handler *rst)
static int imx23_devices_init(void)
{
+ arm_add_mem_device("ram0", IMX_MEMORY_BASE, imx23_get_memsize());
+
if (of_get_root_node())
return 0;