Finally fix the rb500 boot (#2436)
[openwrt/svn-archive/archive.git] / target / linux / rb532 / files / arch / mips / rb500 / prom.c
1 /*
2 * prom.c
3 **********************************************************************
4 * P . Sadik Oct 10, 2003
5 *
6 * Started change log
7 * idt_cpu_freq is make a kernel configuration parameter
8 * idt_cpu_freq is exported so that other modules can use it.
9 * Code cleanup
10 **********************************************************************
11 * P. Sadik Oct 20, 2003
12 *
13 * Removed NVRAM code from here, since they are already available under
14 * nvram directory.
15 * Added serial port initialisation.
16 **********************************************************************
17 **********************************************************************
18 * P. Sadik Oct 30, 2003
19 *
20 * Added reset_cons_port
21 **********************************************************************
22
23 P.Christeas, 2005-2006
24 Port to 2.6, add 2.6 cmdline parsing
25
26 */
27
28 #include <linux/autoconf.h>
29 #include <linux/init.h>
30 #include <linux/mm.h>
31 #include <linux/module.h>
32 #include <linux/string.h>
33 #include <linux/console.h>
34 #include <asm/bootinfo.h>
35 #include <linux/bootmem.h>
36 #include <linux/ioport.h>
37 #include <linux/blkdev.h>
38 #include <asm/rc32434/ddr.h>
39
40 #define PROM_ENTRY(x) (0xbfc00000+((x)*8))
41 extern void __init setup_serial_port(void);
42
43 unsigned int idt_cpu_freq = 132000000;
44 EXPORT_SYMBOL(idt_cpu_freq);
45 char board_type[11];
46 EXPORT_SYMBOL(board_type);
47 unsigned int gpio_bootup_state = 0;
48 EXPORT_SYMBOL(gpio_bootup_state);
49
50
51 char mips_mac_address[18] = "08:00:06:05:40:01";
52 EXPORT_SYMBOL(mips_mac_address);
53
54 /* what to append to cmdline when button is [not] pressed */
55 #define GPIO_INIT_NOBUTTON ""
56 #define GPIO_INIT_BUTTON " 2"
57
58 #ifdef CONFIG_MIKROTIK_RB500
59 unsigned soft_reboot = 0;
60 EXPORT_SYMBOL(soft_reboot);
61 #endif
62
63 #define SR_NMI 0x00180000 /* NMI */
64 #define SERIAL_SPEED_ENTRY 0x00000001
65
66 #ifdef CONFIG_REMOTE_DEBUG
67 extern int remote_debug;
68 #endif
69
70 extern unsigned long mips_machgroup;
71 extern unsigned long mips_machtype;
72
73 #define FREQ_TAG "HZ="
74 #define GPIO_TAG "gpio="
75 #define KMAC_TAG "kmac="
76 #define MEM_TAG "mem="
77 #define BOARD_TAG "board="
78 #define IGNORE_CMDLINE_MEM 1
79 #define DEBUG_DDR
80
81 void parse_soft_settings(unsigned *ptr, unsigned size);
82 void parse_hard_settings(unsigned *ptr, unsigned size);
83
84 void __init prom_setup_cmdline(void);
85
86 void __init prom_init(void)
87 {
88 DDR_t ddr = (DDR_t) DDR_VirtualAddress; /* define the pointer to the DDR registers */
89 phys_t memsize = 0-ddr->ddrmask;
90
91 /* this should be the very first message, even before serial is properly initialized */
92 prom_setup_cmdline();
93 setup_serial_port();
94
95 mips_machgroup = MACH_GROUP_MIKROTIK;
96 soft_reboot = read_c0_status() & SR_NMI;
97 pm_power_off = NULL;
98
99 /*
100 * give all RAM to boot allocator,
101 * except for the first 0x400 and the last 0x200 bytes
102 */
103 add_memory_region(ddr->ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
104 }
105
106 void __init prom_free_prom_memory(void)
107 {
108 /* No prom memory to free */
109 }
110
111 extern char _image_cmdline;
112 void __init prom_setup_cmdline(void){
113 char cmd_line[CL_SIZE];
114 char *cp;
115 int prom_argc;
116 char **prom_argv, **prom_envp;
117 int i;
118
119 prom_argc = fw_arg0;
120 prom_argv = (char **) fw_arg1;
121 prom_envp = (char **) fw_arg2;
122
123 cp=cmd_line;
124 /* Note: it is common that parameters start at argv[1] and not argv[0],
125 however, our elf loader starts at [0] */
126 for(i=0;i<prom_argc;i++){
127 if (strncmp(prom_argv[i], FREQ_TAG, sizeof(FREQ_TAG) - 1) == 0) {
128 idt_cpu_freq = simple_strtoul(prom_argv[i] + sizeof(FREQ_TAG) - 1, 0, 10);
129 continue;
130 }
131 #ifdef IGNORE_CMDLINE_MEM
132 /* parses out the "mem=xx" arg */
133 if (strncmp(prom_argv[i], MEM_TAG, sizeof(MEM_TAG) - 1) == 0) {
134 continue;
135 }
136 #endif
137 if (i>0) *(cp++) = ' ';
138
139 if (strncmp(prom_argv[i], BOARD_TAG, sizeof(BOARD_TAG) - 1) == 0) {
140 strcpy(board_type, prom_argv[i] + sizeof(BOARD_TAG) -1);
141 }
142 if (strncmp(prom_argv[i], GPIO_TAG, sizeof(GPIO_TAG) - 1) == 0) {
143 gpio_bootup_state = simple_strtoul(prom_argv[i] + sizeof(GPIO_TAG) - 1, 0, 10);
144 }
145 strcpy(cp,prom_argv[i]);
146 cp+=strlen(prom_argv[i]);
147 }
148 *(cp++) = ' ';
149 strcpy(cp,(&_image_cmdline + 8));
150 cp += strlen(&_image_cmdline);
151
152 i=strlen(arcs_cmdline);
153 if (i>0){
154 *(cp++) = ' ';
155 strcpy(cp,arcs_cmdline);
156 cp+=strlen(arcs_cmdline);
157 }
158 if (gpio_bootup_state&0x02)
159 strcpy(cp,GPIO_INIT_NOBUTTON);
160 else
161 strcpy(cp,GPIO_INIT_BUTTON);
162 cmd_line[CL_SIZE-1] = '\0';
163
164 strcpy(arcs_cmdline,cmd_line);
165 }
166