5c52ea27e2c3c5265aecd1ab0909d45e01c98b46
[oweals/openwrt.git] / target / linux / adm5120 / files-3.8 / 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
17 #include <asm/bootinfo.h>
18 #include <asm/mips_machine.h>
19
20 #include <asm/mach-adm5120/adm5120_info.h>
21
22 #include <prom/cfe.h>
23 #include <prom/generic.h>
24 #include <prom/routerboot.h>
25 #include <prom/myloader.h>
26 #include <prom/zynos.h>
27
28 unsigned int adm5120_prom_type  = ADM5120_PROM_GENERIC;
29
30 struct board_desc {
31         unsigned long   mach_type;
32         char            *name;
33 };
34
35 #define DEFBOARD(n, mt) { .mach_type = (mt), .name = (n)}
36 static struct board_desc common_boards[] __initdata = {
37         /* Cellvision/SparkLAN boards */
38         DEFBOARD("CAS-630",     MACH_ADM5120_CAS630),
39         DEFBOARD("CAS-670",     MACH_ADM5120_CAS670),
40         DEFBOARD("CAS-700",     MACH_ADM5120_CAS700),
41         DEFBOARD("CAS-771",     MACH_ADM5120_CAS771),
42         DEFBOARD("CAS-790",     MACH_ADM5120_CAS790),
43         DEFBOARD("CAS-861",     MACH_ADM5120_CAS861),
44         DEFBOARD("NFS-101U",    MACH_ADM5120_NFS101U),
45         /* Compex boards */
46         DEFBOARD("WP54G-WRT",   MACH_ADM5120_WP54G_WRT),
47         /* Edimax boards */
48         DEFBOARD("BR-6104K",    MACH_ADM5120_BR6104K),
49         DEFBOARD("BR-6104KP",   MACH_ADM5120_BR6104KP),
50         DEFBOARD("BR-6104WG",   MACH_ADM5120_BR61X4WG),
51         DEFBOARD("BR-6114WG",   MACH_ADM5120_BR61X4WG),
52         /* Infineon boards */
53         DEFBOARD("EASY 5120P-ATA",      MACH_ADM5120_EASY5120PATA),
54         DEFBOARD("EASY 5120-RT",        MACH_ADM5120_EASY5120RT),
55         DEFBOARD("EASY 5120-WVoIP",     MACH_ADM5120_EASY5120WVOIP),
56         DEFBOARD("EASY 83000",          MACH_ADM5120_EASY83000),
57         /* Mikrotik RouterBOARDs */
58         DEFBOARD("111",         MACH_ADM5120_RB_11X),
59         DEFBOARD("112",         MACH_ADM5120_RB_11X),
60         DEFBOARD("133",         MACH_ADM5120_RB_133),
61         DEFBOARD("133C",        MACH_ADM5120_RB_133C),
62         DEFBOARD("133C3",       MACH_ADM5120_RB_133C),
63         DEFBOARD("150",         MACH_ADM5120_RB_153), /* it's intentional */
64         DEFBOARD("153",         MACH_ADM5120_RB_153),
65         DEFBOARD("192",         MACH_ADM5120_RB_192),
66         DEFBOARD("miniROUTER",  MACH_ADM5120_RB_150),
67         /* OSBRiDGE boards */
68         DEFBOARD("OSBRiDGE 5GXi",       MACH_ADM5120_5GXI),
69         /* Motorola boards */
70         DEFBOARD("Powerline MU Gateway", MACH_ADM5120_PMUGW),
71         /* Generic EB-214A */
72         DEFBOARD("ADM5120",     MACH_ADM5120_EB_214A),
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_P334U,  MACH_ADM5120_P334U),
135         ZYXEL_BOARD(ZYNOS_BOARD_P334W,  MACH_ADM5120_P334W),
136         ZYXEL_BOARD(ZYNOS_BOARD_P334WH, MACH_ADM5120_P334WH),
137         ZYXEL_BOARD(ZYNOS_BOARD_P334WHD, MACH_ADM5120_P334WHD),
138         ZYXEL_BOARD(ZYNOS_BOARD_P334WT, MACH_ADM5120_P334WT),
139         ZYXEL_BOARD(ZYNOS_BOARD_P334WT_ALT,     MACH_ADM5120_P334WT),
140         ZYXEL_BOARD(ZYNOS_BOARD_P335,   MACH_ADM5120_P335),
141         ZYXEL_BOARD(ZYNOS_BOARD_P335PLUS, MACH_ADM5120_P335PLUS),
142         ZYXEL_BOARD(ZYNOS_BOARD_P335U,  MACH_ADM5120_P335U)
143 };
144
145 static unsigned long __init detect_machtype_bootbase(void)
146 {
147         int i;
148
149         for (i = 0; i < ARRAY_SIZE(zynos_boards); i++) {
150                 if (zynos_boards[i].vendor_id == bootbase_info.vendor_id &&
151                         zynos_boards[i].board_id == bootbase_info.board_id) {
152                         return zynos_boards[i].mach_type;
153                         break;
154                 }
155         }
156
157         printk(KERN_WARNING "Unknown ZyXEL model (%u)\n",
158                                 bootbase_info.board_id);
159         return MACH_ADM5120_GENERIC;
160 }
161
162 static struct {
163         unsigned long   mach_type;
164         u16     vid;
165         u16     did;
166         u16     svid;
167         u16     sdid;
168 } mylo_boards[]  __initdata = {
169 #define MYLO_BOARD(v, d, sv, sd, mt) \
170         {.vid = (v), .did = (d), .svid = (sv), .sdid = (sd), .mach_type = (mt)}
171 #define COMPEX_BOARD(d, mt) \
172         MYLO_BOARD(VENID_COMPEX, (d), VENID_COMPEX, (d), (mt))
173
174         COMPEX_BOARD(DEVID_COMPEX_NP27G, MACH_ADM5120_NP27G),
175         COMPEX_BOARD(DEVID_COMPEX_NP28G, MACH_ADM5120_NP28G),
176         COMPEX_BOARD(DEVID_COMPEX_NP28GHS, MACH_ADM5120_NP28GHS),
177         COMPEX_BOARD(DEVID_COMPEX_WP54G, MACH_ADM5120_WP54),
178         COMPEX_BOARD(DEVID_COMPEX_WP54Gv1C, MACH_ADM5120_WP54Gv1C),
179         COMPEX_BOARD(DEVID_COMPEX_WP54AG, MACH_ADM5120_WP54),
180         COMPEX_BOARD(DEVID_COMPEX_WPP54G, MACH_ADM5120_WP54),
181         COMPEX_BOARD(DEVID_COMPEX_WPP54AG, MACH_ADM5120_WP54),
182 };
183
184 static unsigned long __init detect_machtype_myloader(void)
185 {
186         unsigned long ret;
187         int i;
188
189         ret = MACH_ADM5120_GENERIC;
190         for (i = 0; i < ARRAY_SIZE(mylo_boards); i++) {
191                 if (mylo_boards[i].vid == myloader_info.vid &&
192                         mylo_boards[i].did == myloader_info.did &&
193                         mylo_boards[i].svid == myloader_info.svid &&
194                         mylo_boards[i].sdid == myloader_info.sdid) {
195                         ret = mylo_boards[i].mach_type;
196                         break;
197                 }
198         }
199
200         return ret;
201 }
202
203 static void __init prom_detect_machtype(void)
204 {
205         if (bootbase_present()) {
206                 adm5120_prom_type = ADM5120_PROM_BOOTBASE;
207                 mips_machtype = detect_machtype_bootbase();
208                 return;
209         }
210
211         if (cfe_present()) {
212                 adm5120_prom_type = ADM5120_PROM_CFE;
213                 mips_machtype = detect_machtype_cfe();
214                 return;
215         }
216
217         if (myloader_present()) {
218                 adm5120_prom_type = ADM5120_PROM_MYLOADER;
219                 mips_machtype = detect_machtype_myloader();
220                 return;
221         }
222
223         if (routerboot_present()) {
224                 adm5120_prom_type = ADM5120_PROM_ROUTERBOOT;
225                 mips_machtype = detect_machtype_routerboot();
226                 return;
227         }
228
229         if (generic_prom_present()) {
230                 adm5120_prom_type = ADM5120_PROM_GENERIC;
231                 mips_machtype = detect_machtype_generic();
232                 return;
233         }
234
235         mips_machtype = MACH_ADM5120_GENERIC;
236 }
237
238 #ifdef CONFIG_IMAGE_CMDLINE_HACK
239 extern char __image_cmdline[];
240
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;
247         if (strlen(cmd) > 0)
248                 strlcpy(arcs_cmdline, cmd, sizeof(arcs_cmdline));
249
250 }
251 #else
252 static inline void prom_init_cmdline(void) {}
253 #endif /* CONFIG_IMAGE_CMDLINE_HACK */
254
255 void __init prom_init(void)
256 {
257         prom_detect_machtype();
258         prom_init_cmdline();
259 }
260
261 void __init prom_free_prom_memory(void)
262 {
263         /* We do not have to prom memory to free */
264 }