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