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