[ramips] share memory size detection code
[openwrt.git] / target / linux / ramips / files / arch / mips / ralink / common / setup.c
1 /*
2  * Ralink SoC common setup
3  *
4  * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 as published
9  * by the Free Software Foundation.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
18
19 #include <asm/mach-ralink/common.h>
20 #include <ralink_soc.h>
21
22 static void __init detect_mem_size(void)
23 {
24         unsigned long size;
25
26         for (size = RALINK_SOC_MEM_SIZE_MIN; size < RALINK_SOC_MEM_SIZE_MAX;
27              size <<= 1 ) {
28                 if (!memcmp(detect_mem_size,
29                             detect_mem_size + size, 1024))
30                         break;
31         }
32
33         add_memory_region(RALINK_SOC_SDRAM_BASE, size, BOOT_MEM_RAM);
34 }
35
36 void __init plat_mem_setup(void)
37 {
38         set_io_port_base(KSEG1);
39
40         detect_mem_size();
41         ramips_soc_setup();
42 }