summaryrefslogtreecommitdiffstats
path: root/target/linux/ramips/patches-3.8/0207-owrt-MIPS-ralink-add-support-for-runtime-memory-dete.patch
blob: 08656ff886e22455753befa0ccd67a40e7672b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From bcd97dbdcb7bc0300397db481872252e8849307b Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Mon, 25 Mar 2013 10:50:53 +0100
Subject: [PATCH 207/208] owrt: MIPS: ralink: add support for runtime memory
 detection

This allows us to add a device_node called "memorydetect" to the DT with
information about the memory windoe of the SoC. Based on this the memory is
detected ar runtime.

Signed-off-by: John Crispin <blogic@openwrt.org>
---
 arch/mips/include/asm/prom.h |    3 ++
 arch/mips/kernel/prom.c      |    3 ++
 arch/mips/ralink/Makefile    |    2 +-
 arch/mips/ralink/memory.c    |  119 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/ralink/memory.c

diff --git a/arch/mips/include/asm/prom.h b/arch/mips/include/asm/prom.h
index a4ad354..91e83e3 100644
--- a/arch/mips/include/asm/prom.h
+++ b/arch/mips/include/asm/prom.h
@@ -20,6 +20,9 @@
 extern int early_init_dt_scan_memory_arch(unsigned long node,
 	const char *uname, int depth, void *data);
 
+extern int early_init_dt_detect_memory(unsigned long node,
+	const char *uname, int depth, void *data);
+
 extern void device_tree_init(void);
 
 static inline unsigned long pci_address_to_pio(phys_addr_t address)
diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index 1aa68a2..feac917 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -88,6 +88,9 @@ void __init early_init_devtree(void *params)
 	of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
 
 	/* try to load the mips machine name */
+	of_scan_flat_dt(early_init_dt_detect_memory, NULL);
+
+	/* try to load the mips machine name */
 	of_scan_flat_dt(early_init_dt_scan_model, NULL);
 }
 
diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
index 9e58aa1..800f98b 100644
--- a/arch/mips/ralink/Makefile
+++ b/arch/mips/ralink/Makefile
@@ -6,7 +6,7 @@
 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
 
-obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
+obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o memory.o
 
 obj-$(CONFIG_SOC_RT288X) += rt288x.o
 obj-$(CONFIG_SOC_RT305X) += rt305x.o rt305x-usb.o
diff --git a/arch/mips/ralink/memory.c b/arch/mips/ralink/memory.c
new file mode 100644
index 0000000..54da31d
--- /dev/null
+++ b/arch/mips/ralink/memory.c
@@ -0,0 +1,119 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ *
+ *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ *  Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ */
+
+#include <linux/string.h>
+#include <linux/of_fdt.h>
+#include <linux/of_platform.h>
+
+#include <asm/bootinfo.h>
+#include <asm/addrspace.h>
+
+#include "common.h"
+
+#define MB	(1024 * 1024)
+
+unsigned long ramips_mem_base;
+unsigned long ramips_mem_size_min;
+unsigned long ramips_mem_size_max;
+
+#ifdef CONFIG_SOC_RT305X
+
+#include <asm/mach-ralink/rt305x.h>
+
+static unsigned long rt5350_get_mem_size(void)
+{
+	void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
+	unsigned long ret;
+	u32 t;
+
+	t = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG);
+	t = (t >> RT5350_SYSCFG0_DRAM_SIZE_SHIFT) &
+	RT5350_SYSCFG0_DRAM_SIZE_MASK;
+
+	switch (t) {
+	case RT5350_SYSCFG0_DRAM_SIZE_2M:
+		ret = 2 * 1024 * 1024;
+		break;
+	case RT5350_SYSCFG0_DRAM_SIZE_8M:
+		ret = 8 * 1024 * 1024;
+		break;
+	case RT5350_SYSCFG0_DRAM_SIZE_16M:
+		ret = 16 * 1024 * 1024;
+		break;
+	case RT5350_SYSCFG0_DRAM_SIZE_32M:
+		ret = 32 * 1024 * 1024;
+		break;
+	case RT5350_SYSCFG0_DRAM_SIZE_64M:
+		ret = 64 * 1024 * 1024;
+		break;
+	default:
+		panic("rt5350: invalid DRAM size: %u", t);
+		break;
+	}
+
+	return ret;
+}
+
+#endif
+
+static void __init detect_mem_size(void)
+{
+	unsigned long size;
+
+#ifdef CONFIG_SOC_RT305X
+	if (soc_is_rt5350()) {
+		size = rt5350_get_mem_size();
+	} else
+#endif
+	{
+		void *base;
+
+		base = (void *) KSEG1ADDR(detect_mem_size);
+		for (size = ramips_mem_size_min; size < ramips_mem_size_max;
+		     size <<= 1 ) {
+			if (!memcmp(base, base + size, 1024))
+				break;
+		}
+	}
+
+	pr_info("memory detected: %uMB\n", (unsigned int) size / MB);
+
+	add_memory_region(ramips_mem_base, size, BOOT_MEM_RAM);
+}
+
+int __init early_init_dt_detect_memory(unsigned long node, const char *uname,
+				     int depth, void *data)
+{
+	unsigned long l;
+	__be32 *mem;
+
+	/* We are scanning "memorydetect" nodes only */
+	if (depth != 1 || strcmp(uname, "memorydetect") != 0)
+		return 0;
+
+	mem = of_get_flat_dt_prop(node, "ralink,memory", &l);
+	if (mem == NULL)
+		return 0;
+
+	if ((l / sizeof(__be32)) != 3)
+		panic("invalid memorydetect node\n");
+
+	ramips_mem_base = dt_mem_next_cell(dt_root_addr_cells, &mem);
+	ramips_mem_size_min = dt_mem_next_cell(dt_root_size_cells, &mem);
+	ramips_mem_size_max = dt_mem_next_cell(dt_root_size_cells, &mem);
+
+	pr_info("memory window: 0x%llx, min: %uMB, max: %uMB\n",
+		(unsigned long long) ramips_mem_base,
+		(unsigned int) ramips_mem_size_min / MB,
+		(unsigned int) ramips_mem_size_max / MB);
+
+	detect_mem_size();
+
+	return 0;
+}
-- 
1.7.10.4