1 From bcd97dbdcb7bc0300397db481872252e8849307b Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 25 Mar 2013 10:50:53 +0100
4 Subject: [PATCH 207/208] owrt: MIPS: ralink: add support for runtime memory
7 This allows us to add a device_node called "memorydetect" to the DT with
8 information about the memory windoe of the SoC. Based on this the memory is
11 Signed-off-by: John Crispin <blogic@openwrt.org>
13 arch/mips/include/asm/prom.h | 3 ++
14 arch/mips/kernel/prom.c | 3 ++
15 arch/mips/ralink/Makefile | 2 +-
16 arch/mips/ralink/memory.c | 119 ++++++++++++++++++++++++++++++++++++++++++
17 4 files changed, 126 insertions(+), 1 deletion(-)
18 create mode 100644 arch/mips/ralink/memory.c
20 diff --git a/arch/mips/include/asm/prom.h b/arch/mips/include/asm/prom.h
21 index a4ad354..91e83e3 100644
22 --- a/arch/mips/include/asm/prom.h
23 +++ b/arch/mips/include/asm/prom.h
25 extern int early_init_dt_scan_memory_arch(unsigned long node,
26 const char *uname, int depth, void *data);
28 +extern int early_init_dt_detect_memory(unsigned long node,
29 + const char *uname, int depth, void *data);
31 extern void device_tree_init(void);
33 static inline unsigned long pci_address_to_pio(phys_addr_t address)
34 diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
35 index 1aa68a2..feac917 100644
36 --- a/arch/mips/kernel/prom.c
37 +++ b/arch/mips/kernel/prom.c
38 @@ -88,6 +88,9 @@ void __init early_init_devtree(void *params)
39 of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
41 /* try to load the mips machine name */
42 + of_scan_flat_dt(early_init_dt_detect_memory, NULL);
44 + /* try to load the mips machine name */
45 of_scan_flat_dt(early_init_dt_scan_model, NULL);
48 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
49 index 9e58aa1..800f98b 100644
50 --- a/arch/mips/ralink/Makefile
51 +++ b/arch/mips/ralink/Makefile
53 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
54 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
56 -obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
57 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o memory.o
59 obj-$(CONFIG_SOC_RT288X) += rt288x.o
60 obj-$(CONFIG_SOC_RT305X) += rt305x.o rt305x-usb.o
61 diff --git a/arch/mips/ralink/memory.c b/arch/mips/ralink/memory.c
63 index 0000000..54da31d
65 +++ b/arch/mips/ralink/memory.c
68 + * This program is free software; you can redistribute it and/or modify it
69 + * under the terms of the GNU General Public License version 2 as published
70 + * by the Free Software Foundation.
72 + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
73 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
76 +#include <linux/string.h>
77 +#include <linux/of_fdt.h>
78 +#include <linux/of_platform.h>
80 +#include <asm/bootinfo.h>
81 +#include <asm/addrspace.h>
85 +#define MB (1024 * 1024)
87 +unsigned long ramips_mem_base;
88 +unsigned long ramips_mem_size_min;
89 +unsigned long ramips_mem_size_max;
91 +#ifdef CONFIG_SOC_RT305X
93 +#include <asm/mach-ralink/rt305x.h>
95 +static unsigned long rt5350_get_mem_size(void)
97 + void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
101 + t = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG);
102 + t = (t >> RT5350_SYSCFG0_DRAM_SIZE_SHIFT) &
103 + RT5350_SYSCFG0_DRAM_SIZE_MASK;
106 + case RT5350_SYSCFG0_DRAM_SIZE_2M:
107 + ret = 2 * 1024 * 1024;
109 + case RT5350_SYSCFG0_DRAM_SIZE_8M:
110 + ret = 8 * 1024 * 1024;
112 + case RT5350_SYSCFG0_DRAM_SIZE_16M:
113 + ret = 16 * 1024 * 1024;
115 + case RT5350_SYSCFG0_DRAM_SIZE_32M:
116 + ret = 32 * 1024 * 1024;
118 + case RT5350_SYSCFG0_DRAM_SIZE_64M:
119 + ret = 64 * 1024 * 1024;
122 + panic("rt5350: invalid DRAM size: %u", t);
131 +static void __init detect_mem_size(void)
133 + unsigned long size;
135 +#ifdef CONFIG_SOC_RT305X
136 + if (soc_is_rt5350()) {
137 + size = rt5350_get_mem_size();
143 + base = (void *) KSEG1ADDR(detect_mem_size);
144 + for (size = ramips_mem_size_min; size < ramips_mem_size_max;
146 + if (!memcmp(base, base + size, 1024))
151 + pr_info("memory detected: %uMB\n", (unsigned int) size / MB);
153 + add_memory_region(ramips_mem_base, size, BOOT_MEM_RAM);
156 +int __init early_init_dt_detect_memory(unsigned long node, const char *uname,
157 + int depth, void *data)
162 + /* We are scanning "memorydetect" nodes only */
163 + if (depth != 1 || strcmp(uname, "memorydetect") != 0)
166 + mem = of_get_flat_dt_prop(node, "ralink,memory", &l);
170 + if ((l / sizeof(__be32)) != 3)
171 + panic("invalid memorydetect node\n");
173 + ramips_mem_base = dt_mem_next_cell(dt_root_addr_cells, &mem);
174 + ramips_mem_size_min = dt_mem_next_cell(dt_root_size_cells, &mem);
175 + ramips_mem_size_max = dt_mem_next_cell(dt_root_size_cells, &mem);
177 + pr_info("memory window: 0x%llx, min: %uMB, max: %uMB\n",
178 + (unsigned long long) ramips_mem_base,
179 + (unsigned int) ramips_mem_size_min / MB,
180 + (unsigned int) ramips_mem_size_max / MB);