add a workaround for a wds related crash
[openwrt/svn-archive/archive.git] / target / linux / rb532-2.6 / files / arch / mips / rb500 / prom.c.orig
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 unsigned int board_type = 500;
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 prom_free_prom_memory(void)
107 {
108 /* FIXME: STUB */
109 }
110
111 void __init prom_setup_cmdline(void){
112 char cmd_line[CL_SIZE];
113 char *cp;
114 int prom_argc;
115 char **prom_argv, **prom_envp;
116 int i;
117
118 prom_argc = fw_arg0;
119 prom_argv = (char **) fw_arg1;
120 prom_envp = (char **) fw_arg2;
121
122 cp=cmd_line;
123 /* Note: it is common that parameters start at argv[1] and not argv[0],
124 however, our elf loader starts at [0] */
125 for(i=0;i<prom_argc;i++){
126 if (strncmp(prom_argv[i], FREQ_TAG, sizeof(FREQ_TAG) - 1) == 0) {
127 idt_cpu_freq = simple_strtoul(prom_argv[i] + sizeof(FREQ_TAG) - 1, 0, 10);
128 continue;
129 }
130 #ifdef IGNORE_CMDLINE_MEM
131 /* parses out the "mem=xx" arg */
132 if (strncmp(prom_argv[i], MEM_TAG, sizeof(MEM_TAG) - 1) == 0) {
133 continue;
134 }
135 #endif
136 if (i>0) *(cp++) = ' ';
137 if (strncmp(prom_argv[i], BOARD_TAG, sizeof(BOARD_TAG) - 1) == 0) {
138 board_type = simple_strtoul(prom_argv[i] + sizeof(BOARD_TAG) - 1, 0, 10);
139 }
140 if (strncmp(prom_argv[i], GPIO_TAG, sizeof(GPIO_TAG) - 1) == 0) {
141 gpio_bootup_state = simple_strtoul(prom_argv[i] + sizeof(GPIO_TAG) - 1, 0, 10);
142 }
143 strcpy(cp,prom_argv[i]);
144 cp+=strlen(prom_argv[i]);
145 }
146
147 i=strlen(arcs_cmdline);
148 if (i>0){
149 *(cp++) = ' ';
150 strcpy(cp,arcs_cmdline);
151 cp+=strlen(arcs_cmdline);
152 }
153 if (gpio_bootup_state&0x02)
154 strcpy(cp,GPIO_INIT_NOBUTTON);
155 else
156 strcpy(cp,GPIO_INIT_BUTTON);
157 cmd_line[CL_SIZE-1] = '\0';
158
159 strcpy(arcs_cmdline,cmd_line);
160 }
161