add new switch configuration api
[openwrt/staging/wigyori.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 unsigned int gpio_bootup_state = 0;
46 EXPORT_SYMBOL(gpio_bootup_state);
47
48 char mips_mac_address[18] = "08:00:06:05:40:01";
49 EXPORT_SYMBOL(mips_mac_address);
50
51 /* what to append to cmdline when button is [not] pressed */
52 #define GPIO_INIT_NOBUTTON ""
53 #define GPIO_INIT_BUTTON " 2"
54
55 #ifdef CONFIG_MIKROTIK_RB500
56 unsigned soft_reboot = 0;
57 EXPORT_SYMBOL(soft_reboot);
58 #endif
59
60 #define SR_NMI 0x00180000 /* NMI */
61 #define SERIAL_SPEED_ENTRY 0x00000001
62
63 #ifdef CONFIG_REMOTE_DEBUG
64 extern int remote_debug;
65 #endif
66
67 #define FREQ_TAG "HZ="
68 #define GPIO_TAG "gpio="
69 #define KMAC_TAG "kmac="
70 #define MEM_TAG "mem="
71 #define BOARD_TAG "board="
72 #define IGNORE_CMDLINE_MEM 1
73 #define DEBUG_DDR
74
75 #define BOARD_RB532 "500"
76 #define BOARD_RB532A "500r5"
77
78 void parse_soft_settings(unsigned *ptr, unsigned size);
79 void parse_hard_settings(unsigned *ptr, unsigned size);
80
81 void __init prom_setup_cmdline(void);
82
83 void __init prom_init(void)
84 {
85 DDR_t ddr = (DDR_t) DDR_VirtualAddress; /* define the pointer to the DDR registers */
86 phys_t memsize = 0-ddr->ddrmask;
87
88 /* this should be the very first message, even before serial is properly initialized */
89 prom_setup_cmdline();
90 setup_serial_port();
91
92 mips_machgroup = MACH_GROUP_MIKROTIK;
93 soft_reboot = read_c0_status() & SR_NMI;
94 pm_power_off = NULL;
95
96 /*
97 * give all RAM to boot allocator,
98 * except for the first 0x400 and the last 0x200 bytes
99 */
100 add_memory_region(ddr->ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
101 }
102
103 void __init prom_free_prom_memory(void)
104 {
105 /* No prom memory to free */
106 }
107
108 static inline int match_tag(char *arg, const char *tag)
109 {
110 return (strncmp(arg, tag, strlen(tag)) == 0);
111 }
112
113 static inline unsigned long tag2ul(char *arg, const char *tag)
114 {
115 char *num = arg+strlen(tag);
116 return simple_strtoul(num, 0, 10);
117 }
118
119 extern char _image_cmdline;
120 void __init prom_setup_cmdline(void){
121 char cmd_line[CL_SIZE];
122 char *cp;
123 int prom_argc;
124 char **prom_argv, **prom_envp;
125 int i;
126
127 prom_argc = fw_arg0;
128 prom_argv = (char **) fw_arg1;
129 prom_envp = (char **) fw_arg2;
130
131 cp=cmd_line;
132 /* Note: it is common that parameters start at argv[1] and not argv[0],
133 however, our elf loader starts at [0] */
134 for(i=0;i<prom_argc;i++){
135 if (match_tag(prom_argv[i], FREQ_TAG)) {
136 idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
137 continue;
138 }
139 #ifdef IGNORE_CMDLINE_MEM
140 /* parses out the "mem=xx" arg */
141 if (match_tag(prom_argv[i], MEM_TAG)) {
142 continue;
143 }
144 #endif
145 if (i>0) *(cp++) = ' ';
146 if (match_tag(prom_argv[i], BOARD_TAG)) {
147 char *board = prom_argv[i] + strlen(BOARD_TAG);
148 if (match_tag(board, BOARD_RB532A))
149 mips_machtype = MACH_MIKROTIK_RB532A;
150 else
151 mips_machtype = MACH_MIKROTIK_RB532;
152 }
153
154 if (match_tag(prom_argv[i], GPIO_TAG)) {
155 gpio_bootup_state = tag2ul(prom_argv[i], GPIO_TAG);
156 }
157 strcpy(cp,prom_argv[i]);
158 cp+=strlen(prom_argv[i]);
159 }
160 *(cp++) = ' ';
161 strcpy(cp,(&_image_cmdline + 8));
162 cp += strlen(&_image_cmdline);
163
164 i=strlen(arcs_cmdline);
165 if (i>0){
166 *(cp++) = ' ';
167 strcpy(cp,arcs_cmdline);
168 cp+=strlen(arcs_cmdline);
169 }
170 if (gpio_bootup_state&0x02)
171 strcpy(cp,GPIO_INIT_NOBUTTON);
172 else
173 strcpy(cp,GPIO_INIT_BUTTON);
174 cmd_line[CL_SIZE-1] = '\0';
175
176 strcpy(arcs_cmdline,cmd_line);
177 }
178