kernel: update linux 3.8 to 3.8.6
[openwrt/staging/chunkeey.git] / target / linux / ramips / patches-3.8 / 0207-owrt-MIPS-ralink-add-support-for-runtime-memory-dete.patch
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
5 detection
6
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
9 detected ar runtime.
10
11 Signed-off-by: John Crispin <blogic@openwrt.org>
12 ---
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
19
20 --- a/arch/mips/include/asm/prom.h
21 +++ b/arch/mips/include/asm/prom.h
22 @@ -20,6 +20,9 @@
23 extern int early_init_dt_scan_memory_arch(unsigned long node,
24 const char *uname, int depth, void *data);
25
26 +extern int early_init_dt_detect_memory(unsigned long node,
27 + const char *uname, int depth, void *data);
28 +
29 extern void device_tree_init(void);
30
31 static inline unsigned long pci_address_to_pio(phys_addr_t address)
32 --- a/arch/mips/kernel/prom.c
33 +++ b/arch/mips/kernel/prom.c
34 @@ -88,6 +88,9 @@ void __init early_init_devtree(void *par
35 of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
36
37 /* try to load the mips machine name */
38 + of_scan_flat_dt(early_init_dt_detect_memory, NULL);
39 +
40 + /* try to load the mips machine name */
41 of_scan_flat_dt(early_init_dt_scan_model, NULL);
42 }
43
44 --- a/arch/mips/ralink/Makefile
45 +++ b/arch/mips/ralink/Makefile
46 @@ -6,7 +6,7 @@
47 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
48 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
49
50 -obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
51 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o memory.o
52
53 obj-$(CONFIG_SOC_RT288X) += rt288x.o
54 obj-$(CONFIG_SOC_RT305X) += rt305x.o rt305x-usb.o
55 --- /dev/null
56 +++ b/arch/mips/ralink/memory.c
57 @@ -0,0 +1,119 @@
58 +/*
59 + * This program is free software; you can redistribute it and/or modify it
60 + * under the terms of the GNU General Public License version 2 as published
61 + * by the Free Software Foundation.
62 + *
63 + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
64 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
65 + */
66 +
67 +#include <linux/string.h>
68 +#include <linux/of_fdt.h>
69 +#include <linux/of_platform.h>
70 +
71 +#include <asm/bootinfo.h>
72 +#include <asm/addrspace.h>
73 +
74 +#include "common.h"
75 +
76 +#define MB (1024 * 1024)
77 +
78 +unsigned long ramips_mem_base;
79 +unsigned long ramips_mem_size_min;
80 +unsigned long ramips_mem_size_max;
81 +
82 +#ifdef CONFIG_SOC_RT305X
83 +
84 +#include <asm/mach-ralink/rt305x.h>
85 +
86 +static unsigned long rt5350_get_mem_size(void)
87 +{
88 + void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
89 + unsigned long ret;
90 + u32 t;
91 +
92 + t = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG);
93 + t = (t >> RT5350_SYSCFG0_DRAM_SIZE_SHIFT) &
94 + RT5350_SYSCFG0_DRAM_SIZE_MASK;
95 +
96 + switch (t) {
97 + case RT5350_SYSCFG0_DRAM_SIZE_2M:
98 + ret = 2 * 1024 * 1024;
99 + break;
100 + case RT5350_SYSCFG0_DRAM_SIZE_8M:
101 + ret = 8 * 1024 * 1024;
102 + break;
103 + case RT5350_SYSCFG0_DRAM_SIZE_16M:
104 + ret = 16 * 1024 * 1024;
105 + break;
106 + case RT5350_SYSCFG0_DRAM_SIZE_32M:
107 + ret = 32 * 1024 * 1024;
108 + break;
109 + case RT5350_SYSCFG0_DRAM_SIZE_64M:
110 + ret = 64 * 1024 * 1024;
111 + break;
112 + default:
113 + panic("rt5350: invalid DRAM size: %u", t);
114 + break;
115 + }
116 +
117 + return ret;
118 +}
119 +
120 +#endif
121 +
122 +static void __init detect_mem_size(void)
123 +{
124 + unsigned long size;
125 +
126 +#ifdef CONFIG_SOC_RT305X
127 + if (soc_is_rt5350()) {
128 + size = rt5350_get_mem_size();
129 + } else
130 +#endif
131 + {
132 + void *base;
133 +
134 + base = (void *) KSEG1ADDR(detect_mem_size);
135 + for (size = ramips_mem_size_min; size < ramips_mem_size_max;
136 + size <<= 1 ) {
137 + if (!memcmp(base, base + size, 1024))
138 + break;
139 + }
140 + }
141 +
142 + pr_info("memory detected: %uMB\n", (unsigned int) size / MB);
143 +
144 + add_memory_region(ramips_mem_base, size, BOOT_MEM_RAM);
145 +}
146 +
147 +int __init early_init_dt_detect_memory(unsigned long node, const char *uname,
148 + int depth, void *data)
149 +{
150 + unsigned long l;
151 + __be32 *mem;
152 +
153 + /* We are scanning "memorydetect" nodes only */
154 + if (depth != 1 || strcmp(uname, "memorydetect") != 0)
155 + return 0;
156 +
157 + mem = of_get_flat_dt_prop(node, "ralink,memory", &l);
158 + if (mem == NULL)
159 + return 0;
160 +
161 + if ((l / sizeof(__be32)) != 3)
162 + panic("invalid memorydetect node\n");
163 +
164 + ramips_mem_base = dt_mem_next_cell(dt_root_addr_cells, &mem);
165 + ramips_mem_size_min = dt_mem_next_cell(dt_root_size_cells, &mem);
166 + ramips_mem_size_max = dt_mem_next_cell(dt_root_size_cells, &mem);
167 +
168 + pr_info("memory window: 0x%llx, min: %uMB, max: %uMB\n",
169 + (unsigned long long) ramips_mem_base,
170 + (unsigned int) ramips_mem_size_min / MB,
171 + (unsigned int) ramips_mem_size_max / MB);
172 +
173 + detect_mem_size();
174 +
175 + return 0;
176 +}