c14c1722995179c470377dc0cb99bd24a892568e
[openwrt/svn-archive/archive.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / prom.c
1 /*
2 * $Id$
3 *
4 * ADM5120 specific prom routines
5 *
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 *
24 */
25
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/string.h>
29 #include <linux/mm.h>
30
31 #include <asm/bootinfo.h>
32 #include <asm/addrspace.h>
33
34 #include <asm/mach-adm5120/adm5120_info.h>
35 #include <asm/mach-adm5120/adm5120_defs.h>
36 #include <asm/mach-adm5120/adm5120_uart.h>
37
38 #include <prom/cfe.h>
39 #include <prom/generic.h>
40 #include <prom/routerboot.h>
41 #include <prom/myloader.h>
42 #include <prom/zynos.h>
43
44 unsigned int adm5120_prom_type = ADM5120_PROM_GENERIC;
45
46 struct board_desc {
47 unsigned long mach_type;
48 char *name;
49 };
50
51 #define DEFBOARD(n, mt) { .mach_type = (mt), .name = (n)}
52 static struct board_desc common_boards[] __initdata = {
53 /* Cellvision/SparkLAN boards */
54 DEFBOARD("CAS-630", MACH_ADM5120_CAS630),
55 DEFBOARD("CAS-670", MACH_ADM5120_CAS670),
56 DEFBOARD("CAS-771", MACH_ADM5120_CAS771),
57 DEFBOARD("CAS-790", MACH_ADM5120_CAS790),
58 DEFBOARD("CAS-861", MACH_ADM5120_CAS861),
59 /* Compex boards */
60 DEFBOARD("WP54G-WRT", MACH_ADM5120_WP54G_WRT),
61 /* Edimax boards */
62 DEFBOARD("BR-6104K", MACH_ADM5120_BR6104K),
63 DEFBOARD("BR-6104KP", MACH_ADM5120_BR6104K),
64 /* Infineon boards */
65 DEFBOARD("EASY 5120P-ATA", MACH_ADM5120_EASY5120PATA),
66 DEFBOARD("EASY 5120-RT", MACH_ADM5120_EASY5120RT),
67 DEFBOARD("EASY 5120-WVoIP", MACH_ADM5120_EASY5120WVOIP),
68 DEFBOARD("EASY 83000", MACH_ADM5120_EASY83000),
69 /* Mikrotik RouterBOARDs */
70 DEFBOARD("111", MACH_ADM5120_RB_111),
71 DEFBOARD("112", MACH_ADM5120_RB_112),
72 DEFBOARD("133", MACH_ADM5120_RB_133),
73 DEFBOARD("133C", MACH_ADM5120_RB_133C),
74 DEFBOARD("miniROUTER", MACH_ADM5120_RB_150),
75 DEFBOARD("153", MACH_ADM5120_RB_153),
76 };
77
78 static unsigned long __init find_machtype_byname(char *name)
79 {
80 unsigned long ret;
81 int i;
82
83 ret = MACH_ADM5120_GENERIC;
84 if (name == NULL)
85 goto out;
86
87 if (*name == '\0')
88 goto out;
89
90 for (i=0; i<ARRAY_SIZE(common_boards); i++) {
91 if (strcmp(common_boards[i].name, name) == 0) {
92 ret = common_boards[i].mach_type;
93 break;
94 }
95 }
96
97 out:
98 return ret;
99 }
100
101 static unsigned long __init detect_machtype_routerboot(void)
102 {
103 char *name;
104
105 name = routerboot_get_boardname();
106 return find_machtype_byname(name);
107 }
108
109 static unsigned long __init detect_machtype_generic(void)
110 {
111 char *name;
112
113 name = generic_prom_getenv("board_name");
114 return find_machtype_byname(name);
115 }
116
117 unsigned long __init detect_machtype_cfe(void)
118 {
119 char *name;
120
121 name = cfe_getenv("BOARD_NAME");
122 return find_machtype_byname(name);
123 }
124
125 static struct {
126 unsigned long mach_type;
127 u16 vendor_id;
128 u16 board_id;
129 } zynos_boards[] __initdata = {
130 #define ZYNOS_BOARD(vi, bi, mt) { .vendor_id = (vi), .board_id = (bi), \
131 .mach_type = (mt) }
132
133 #define ZYXEL_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_ZYXEL, bi, mt)
134 #define DLINK_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_DLINK, bi, mt)
135 #define LUCENT_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_LUCENT, bi, mt)
136 ZYXEL_BOARD(ZYNOS_BOARD_HS100, MACH_ADM5120_HS100),
137 ZYXEL_BOARD(ZYNOS_BOARD_P334, MACH_ADM5120_P334),
138 ZYXEL_BOARD(ZYNOS_BOARD_P334U, MACH_ADM5120_P334U),
139 ZYXEL_BOARD(ZYNOS_BOARD_P334W, MACH_ADM5120_P334W),
140 ZYXEL_BOARD(ZYNOS_BOARD_P334WH, MACH_ADM5120_P334WH),
141 ZYXEL_BOARD(ZYNOS_BOARD_P334WHD, MACH_ADM5120_P334WHD),
142 ZYXEL_BOARD(ZYNOS_BOARD_P334WT, MACH_ADM5120_P334WT),
143 ZYXEL_BOARD(ZYNOS_BOARD_P335, MACH_ADM5120_P335),
144 ZYXEL_BOARD(ZYNOS_BOARD_P335PLUS, MACH_ADM5120_P335PLUS),
145 ZYXEL_BOARD(ZYNOS_BOARD_P335U, MACH_ADM5120_P335U)
146 };
147
148 static unsigned long __init detect_machtype_bootbase(void)
149 {
150 unsigned long ret;
151 int i;
152
153 ret = MACH_ADM5120_GENERIC;
154 for (i=0; i<ARRAY_SIZE(zynos_boards); i++) {
155 if (zynos_boards[i].vendor_id == bootbase_info.vendor_id &&
156 zynos_boards[i].board_id == bootbase_info.board_id) {
157 ret = zynos_boards[i].mach_type;
158 break;
159 }
160 }
161
162 return ret;
163 }
164
165 static struct {
166 unsigned long mach_type;
167 u16 vid;
168 u16 did;
169 u16 svid;
170 u16 sdid;
171 } mylo_boards[] __initdata = {
172 #define MYLO_BOARD(v,d,sv,sd,mt) { .vid = (v), .did = (d), .svid = (sv), \
173 .sdid = (sd), .mach_type = (mt) }
174 #define COMPEX_BOARD(d,mt) MYLO_BOARD(VENID_COMPEX,(d),VENID_COMPEX,(d),(mt))
175
176 COMPEX_BOARD(DEVID_COMPEX_NP27G, MACH_ADM5120_NP27G),
177 COMPEX_BOARD(DEVID_COMPEX_NP28G, MACH_ADM5120_NP28G),
178 COMPEX_BOARD(DEVID_COMPEX_NP28GHS, MACH_ADM5120_NP28GHS),
179 COMPEX_BOARD(DEVID_COMPEX_WP54G, MACH_ADM5120_WP54G),
180 COMPEX_BOARD(DEVID_COMPEX_WP54Gv1C, MACH_ADM5120_WP54Gv1C),
181 COMPEX_BOARD(DEVID_COMPEX_WP54AG, MACH_ADM5120_WP54AG),
182 COMPEX_BOARD(DEVID_COMPEX_WPP54G, MACH_ADM5120_WPP54G),
183 COMPEX_BOARD(DEVID_COMPEX_WPP54AG, MACH_ADM5120_WPP54AG),
184 };
185
186 static unsigned long __init detect_machtype_myloader(void)
187 {
188 unsigned long ret;
189 int i;
190
191 ret = MACH_ADM5120_GENERIC;
192 for (i=0; i<ARRAY_SIZE(mylo_boards); i++) {
193 if (mylo_boards[i].vid == myloader_info.vid &&
194 mylo_boards[i].did == myloader_info.did &&
195 mylo_boards[i].svid == myloader_info.svid &&
196 mylo_boards[i].sdid == myloader_info.sdid) {
197 ret = mylo_boards[i].mach_type;
198 break;
199 }
200 }
201
202 return ret;
203 }
204
205 static void __init prom_detect_machtype(void)
206 {
207 if (bootbase_present()) {
208 adm5120_prom_type = ADM5120_PROM_BOOTBASE;
209 mips_machtype = detect_machtype_bootbase();
210 return;
211 }
212
213 if (cfe_present()) {
214 adm5120_prom_type = ADM5120_PROM_CFE;
215 mips_machtype = detect_machtype_cfe();
216 return;
217 }
218
219 if (myloader_present()) {
220 adm5120_prom_type = ADM5120_PROM_MYLOADER;
221 mips_machtype = detect_machtype_myloader();
222 return;
223 }
224
225 if (routerboot_present()) {
226 adm5120_prom_type = ADM5120_PROM_ROUTERBOOT;
227 mips_machtype = detect_machtype_routerboot();
228 return;
229 }
230
231 if (generic_prom_present()) {
232 adm5120_prom_type = ADM5120_PROM_GENERIC;
233 mips_machtype = detect_machtype_generic();
234 return;
235 }
236
237 mips_machtype = MACH_ADM5120_GENERIC;
238 }
239
240 /* TODO: this is an ugly hack for RouterBOARDS */
241 extern char _image_cmdline;
242 static void __init prom_init_cmdline(void)
243 {
244 char *cmd;
245
246 /* init command line, register a default kernel command line */
247 cmd = &_image_cmdline + 8;
248 if( strlen(cmd) > 0) strcpy( &(arcs_cmdline[0]), cmd);
249 else strcpy(&(arcs_cmdline[0]), CONFIG_CMDLINE);
250
251 }
252
253 #define UART_READ(r) *(volatile u32 *)(KSEG1ADDR(ADM5120_UART0_BASE)+(r))
254 #define UART_WRITE(r,v) *(volatile u32 *)(KSEG1ADDR(ADM5120_UART0_BASE)+(r))=(v)
255
256 void __init prom_putchar(char ch)
257 {
258 while ((UART_READ(UART_REG_FLAG) & UART_FLAG_TXFE) == 0);
259 UART_WRITE(UART_REG_DATA, ch);
260 while ((UART_READ(UART_REG_FLAG) & UART_FLAG_TXFE) == 0);
261 }
262
263 void __init prom_init(void)
264 {
265 mips_machgroup = MACH_GROUP_ADM5120;
266 prom_detect_machtype();
267
268 prom_init_cmdline();
269 }
270
271 void __init prom_free_prom_memory(void)
272 {
273 /* We do not have to prom memory to free */
274 }