Updated support for Zynos/adm5120eb boards, thanks Gabor
[openwrt.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / memory.c
1 /*****************************************************************************
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 * Copyright (C) 2003 ADMtek Incorporated.
5 * daniell@admtek.com.tw
6 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
7 *
8 * ########################################################################
9 *
10 * This program is free software; you can distribute it and/or modify it
11 * under the terms of the GNU General Public License (Version 2) as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * ########################################################################
24 *
25 *****************************************************************************/
26
27 #include <linux/autoconf.h>
28 #include <linux/init.h>
29 #include <linux/mm.h>
30 #include <linux/bootmem.h>
31 #include <linux/pfn.h>
32 #include <linux/string.h>
33
34 #include <asm/bootinfo.h>
35 #include <asm/page.h>
36 #include <asm/sections.h>
37
38 #include <asm-mips/mips-boards/prom.h>
39
40 extern char *prom_getenv(char *envname);
41
42 #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
43
44 #define ADM5120_MEMCTRL 0x1200001c
45 #define ADM5120_MEMCTRL_SDRAM_MASK 0x7
46
47 static const unsigned long adm_sdramsize[] __initdata = {
48 0x0, /* Reserved */
49 0x0400000, /* 4Mb */
50 0x0800000, /* 8Mb */
51 0x1000000, /* 16Mb */
52 0x4000000, /* 64Mb */
53 0x8000000, /* 128Mb */
54 };
55
56 /* determined physical memory size, not overridden by command line args */
57 unsigned long physical_memsize = 0L;
58
59 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
60
61 struct prom_pmemblock * __init prom_getmdesc(void)
62 {
63 char *memsize_str;
64 unsigned int memsize;
65 char cmdline[CL_SIZE], *ptr;
66
67 memsize_str = prom_getenv("memsize");
68
69 if (!memsize_str)
70 {
71 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
72 physical_memsize = 0x00800000;
73 }
74 else
75 #ifdef DEBUG
76 prom_printf("prom_memsize = %s\n", memsize_str);
77 #endif
78 physical_memsize = simple_strtol(memsize_str, NULL, 0);
79
80 /* Check the command line for a memsize directive that overrides
81 * the physical/default amount */
82 strcpy(cmdline, arcs_cmdline);
83 ptr = strstr(cmdline, "memsize=");
84 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
85 ptr = strstr(ptr, " memsize=");
86
87 if (ptr)
88 memsize = memparse(ptr + 8, &ptr);
89 else
90 memsize = physical_memsize;
91
92 memset(mdesc, 0, sizeof(mdesc));
93
94 mdesc[0].type = BOOT_MEM_RAM;
95 mdesc[0].base = CPHYSADDR(PFN_ALIGN(&_end));
96 mdesc[0].size = memsize - mdesc[0].base;
97
98 return &mdesc[0];
99 }
100
101 void __init prom_meminit(void)
102 {
103 struct prom_pmemblock *p;
104
105 p = prom_getmdesc();
106
107 while (p->size)
108 {
109 long type;
110 unsigned long base, size;
111 base = p->base;
112 type = p->type,
113 size = p->size;
114 add_memory_region(base, size, type);
115 p++;
116 }
117 }
118
119 #if 0
120 void __init prom_meminit(void)
121 {
122 unsigned long base = CPHYSADDR(PFN_ALIGN(&_end));
123 unsigned long size;
124
125 u32 memctrl = *(u32*)KSEG1ADDR(ADM5120_MEMCTRL);
126 size = adm_sdramsize[memctrl & ADM5120_MEMCTRL_SDRAM_MASK];
127 add_memory_region(base, size-base, BOOT_MEM_RAM);
128 }
129 #endif
130
131 unsigned long __init prom_free_prom_memory(void)
132 {
133 /* We do not have to prom memory to free */
134 return 0;
135 }
This page took 0.063187 seconds and 5 git commands to generate.