[amazon] Read the size of the available memory from parameters passed to the kernel...
[openwrt-10.03/.git] / target / linux / amazon / files / arch / mips / amazon / prom.c
1 /*
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the Free Software
14  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15  *
16  *   Copyright 2007 John Crispin <blogic@openwrt.org> 
17  */
18
19 #include <linux/init.h>
20 #include <linux/string.h>
21 #include <linux/ctype.h>
22 #include <linux/kernel.h>
23 #include <linux/mm.h>
24 #include <linux/bootmem.h>
25 #include <linux/ioport.h>
26 #include <asm/bootinfo.h>
27 #include <asm/amazon/amazon.h>
28 #include <asm/amazon/irq.h>
29 #include <asm/amazon/model.h>
30 #include <asm/cpu.h>
31
32 void prom_putchar(char c)
33 {
34         /* Wait for FIFO to empty */
35         while ((amazon_readl(AMAZON_ASC_FSTAT) >> 8) != 0x00) ;
36         /* Crude cr/nl handling is better than none */
37         if(c == '\n')
38                 amazon_writel('\r', AMAZON_ASC_TBUF);
39         amazon_writel(c, AMAZON_ASC_TBUF);
40 }
41
42 void prom_printf(const char * fmt, ...)
43 {
44         va_list args;
45         int l;
46         char *p, *buf_end;
47         char buf[1024]; 
48
49         va_start(args, fmt);
50         /* FIXME - hopefully i < sizeof(buf) */
51         l = vsprintf(buf, fmt, args); 
52         va_end(args);
53         buf_end = buf + l;
54         
55         for (p = buf; p < buf_end; p++)
56                 prom_putchar(*p);
57 }
58
59
60 void __init prom_init(void)
61 {
62         char **envp = (char **) fw_arg2;
63
64         int memsize = 16; /* assume 16M as default */
65
66         mips_machgroup = MACH_GROUP_INFINEON;
67         mips_machtype = MACH_INFINEON_AMAZON;
68
69         envp = (char **)KSEG1ADDR((unsigned long)envp);
70         while (*envp) {
71                 char *e = (char *)KSEG1ADDR(*envp);
72
73                 if (!strncmp(e, "memsize=", 8)) {
74                         e += 8;
75                         memsize = simple_strtoul(e, NULL, 10);
76                 }
77                 envp++;
78         }
79         memsize *= 1024 * 1024;
80
81         strcpy(&(arcs_cmdline[0]), "console=ttyS0,115200 rootfstype=squashfs,jffs2");
82         
83         add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
84 }
85
86 void prom_free_prom_memory(void)
87 {
88 }
89
90 const char *get_system_type(void)
91 {
92         return BOARD_SYSTEM_TYPE;
93 }