]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/rb532/prom.c
MIPS: RB532: Remove gpio bootup state
[linux-2.6-omap-h63xx.git] / arch / mips / rb532 / prom.c
1 /*
2  *  RouterBoard 500 specific prom routines
3  *
4  *  Copyright (C) 2003, Peter Sadik <peter.sadik@idt.com>
5  *  Copyright (C) 2005-2006, P.Christeas <p_christ@hol.gr>
6  *  Copyright (C) 2007, Gabor Juhos <juhosg@openwrt.org>
7  *                      Felix Fietkau <nbd@openwrt.org>
8  *                      Florian Fainelli <florian@openwrt.org>
9  *
10  *  This program is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU General Public License
12  *  as published by the Free Software Foundation; either version 2
13  *  of the License, or (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the
22  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  *  Boston, MA  02110-1301, USA.
24  *
25  */
26
27 #include <linux/init.h>
28 #include <linux/mm.h>
29 #include <linux/module.h>
30 #include <linux/string.h>
31 #include <linux/console.h>
32 #include <linux/bootmem.h>
33 #include <linux/ioport.h>
34 #include <linux/blkdev.h>
35
36 #include <asm/bootinfo.h>
37 #include <asm/mach-rc32434/ddr.h>
38 #include <asm/mach-rc32434/prom.h>
39
40 extern void __init setup_serial_port(void);
41
42 unsigned int idt_cpu_freq = 132000000;
43 EXPORT_SYMBOL(idt_cpu_freq);
44
45 static struct resource ddr_reg[] = {
46         {
47                 .name = "ddr-reg",
48                 .start = DDR0_PHYS_ADDR,
49                 .end = DDR0_PHYS_ADDR + sizeof(struct ddr_ram),
50                 .flags = IORESOURCE_MEM,
51         }
52 };
53
54 void __init prom_free_prom_memory(void)
55 {
56         /* No prom memory to free */
57 }
58
59 static inline int match_tag(char *arg, const char *tag)
60 {
61         return strncmp(arg, tag, strlen(tag)) == 0;
62 }
63
64 static inline unsigned long tag2ul(char *arg, const char *tag)
65 {
66         char *num;
67
68         num = arg + strlen(tag);
69         return simple_strtoul(num, 0, 10);
70 }
71
72 void __init prom_setup_cmdline(void)
73 {
74         char cmd_line[CL_SIZE];
75         char *cp, *board;
76         int prom_argc;
77         char **prom_argv, **prom_envp;
78         int i;
79
80         prom_argc = fw_arg0;
81         prom_argv = (char **) fw_arg1;
82         prom_envp = (char **) fw_arg2;
83
84         cp = cmd_line;
85                 /* Note: it is common that parameters start
86                  * at argv[1] and not argv[0],
87                  * however, our elf loader starts at [0] */
88         for (i = 0; i < prom_argc; i++) {
89                 if (match_tag(prom_argv[i], FREQ_TAG)) {
90                         idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
91                         continue;
92                 }
93 #ifdef IGNORE_CMDLINE_MEM
94                 /* parses out the "mem=xx" arg */
95                 if (match_tag(prom_argv[i], MEM_TAG))
96                         continue;
97 #endif
98                 if (i > 0)
99                         *(cp++) = ' ';
100                 if (match_tag(prom_argv[i], BOARD_TAG)) {
101                         board = prom_argv[i] + strlen(BOARD_TAG);
102
103                         if (match_tag(board, BOARD_RB532A))
104                                 mips_machtype = MACH_MIKROTIK_RB532A;
105                         else
106                                 mips_machtype = MACH_MIKROTIK_RB532;
107                 }
108
109                 strcpy(cp, prom_argv[i]);
110                 cp += strlen(prom_argv[i]);
111         }
112         *(cp++) = ' ';
113
114         i = strlen(arcs_cmdline);
115         if (i > 0) {
116                 *(cp++) = ' ';
117                 strcpy(cp, arcs_cmdline);
118                 cp += strlen(arcs_cmdline);
119         }
120         cmd_line[CL_SIZE-1] = '\0';
121
122         strcpy(arcs_cmdline, cmd_line);
123 }
124
125 void __init prom_init(void)
126 {
127         struct ddr_ram __iomem *ddr;
128         phys_t memsize;
129         phys_t ddrbase;
130
131         ddr = ioremap_nocache(ddr_reg[0].start,
132                         ddr_reg[0].end - ddr_reg[0].start);
133
134         if (!ddr) {
135                 printk(KERN_ERR "Unable to remap DDR register\n");
136                 return;
137         }
138
139         ddrbase = (phys_t)&ddr->ddrbase;
140         memsize = (phys_t)&ddr->ddrmask;
141         memsize = 0 - memsize;
142
143         prom_setup_cmdline();
144
145         /* give all RAM to boot allocator,
146          * except for the first 0x400 and the last 0x200 bytes */
147         add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
148 }