2 * RouterBoard 500 specific prom routines
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>
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.
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.
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.
27 #include <linux/init.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>
36 #include <asm/bootinfo.h>
37 #include <asm/mach-rc32434/ddr.h>
38 #include <asm/mach-rc32434/prom.h>
40 extern void __init setup_serial_port(void);
42 unsigned int idt_cpu_freq = 132000000;
43 EXPORT_SYMBOL(idt_cpu_freq);
44 unsigned int gpio_bootup_state;
45 EXPORT_SYMBOL(gpio_bootup_state);
47 static struct resource ddr_reg[] = {
50 .start = DDR0_PHYS_ADDR,
51 .end = DDR0_PHYS_ADDR + sizeof(struct ddr_ram),
52 .flags = IORESOURCE_MEM,
56 void __init prom_free_prom_memory(void)
58 /* No prom memory to free */
61 static inline int match_tag(char *arg, const char *tag)
63 return strncmp(arg, tag, strlen(tag)) == 0;
66 static inline unsigned long tag2ul(char *arg, const char *tag)
70 num = arg + strlen(tag);
71 return simple_strtoul(num, 0, 10);
74 void __init prom_setup_cmdline(void)
76 char cmd_line[CL_SIZE];
79 char **prom_argv, **prom_envp;
83 prom_argv = (char **) fw_arg1;
84 prom_envp = (char **) fw_arg2;
87 /* Note: it is common that parameters start
88 * at argv[1] and not argv[0],
89 * however, our elf loader starts at [0] */
90 for (i = 0; i < prom_argc; i++) {
91 if (match_tag(prom_argv[i], FREQ_TAG)) {
92 idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
95 #ifdef IGNORE_CMDLINE_MEM
96 /* parses out the "mem=xx" arg */
97 if (match_tag(prom_argv[i], MEM_TAG))
102 if (match_tag(prom_argv[i], BOARD_TAG)) {
103 board = prom_argv[i] + strlen(BOARD_TAG);
105 if (match_tag(board, BOARD_RB532A))
106 mips_machtype = MACH_MIKROTIK_RB532A;
108 mips_machtype = MACH_MIKROTIK_RB532;
111 if (match_tag(prom_argv[i], GPIO_TAG))
112 gpio_bootup_state = tag2ul(prom_argv[i], GPIO_TAG);
114 strcpy(cp, prom_argv[i]);
115 cp += strlen(prom_argv[i]);
119 i = strlen(arcs_cmdline);
122 strcpy(cp, arcs_cmdline);
123 cp += strlen(arcs_cmdline);
125 if (gpio_bootup_state & 0x02)
126 strcpy(cp, GPIO_INIT_NOBUTTON);
128 strcpy(cp, GPIO_INIT_BUTTON);
130 cmd_line[CL_SIZE-1] = '\0';
132 strcpy(arcs_cmdline, cmd_line);
135 void __init prom_init(void)
137 struct ddr_ram __iomem *ddr;
141 ddr = ioremap_nocache(ddr_reg[0].start,
142 ddr_reg[0].end - ddr_reg[0].start);
145 printk(KERN_ERR "Unable to remap DDR register\n");
149 ddrbase = (phys_t)&ddr->ddrbase;
150 memsize = (phys_t)&ddr->ddrmask;
151 memsize = 0 - memsize;
153 prom_setup_cmdline();
155 /* give all RAM to boot allocator,
156 * except for the first 0x400 and the last 0x200 bytes */
157 add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);