24373cdca1fc80c6c2e3e7ce5a21cea92e48ef9e
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / prom.c
1 /*
2 * Atheros AR71xx SoC specific prom routines
3 *
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
18 #include <asm/fw/myloader/myloader.h>
19
20 #include <asm/mach-ar71xx/ar71xx.h>
21
22 #include "devices.h"
23
24 struct board_rec {
25 char *name;
26 enum ar71xx_mach_type mach_type;
27 };
28
29 static int ar71xx_prom_argc __initdata;
30 static char **ar71xx_prom_argv __initdata;
31 static char **ar71xx_prom_envp __initdata;
32
33 static struct board_rec boards[] __initdata = {
34 {
35 .name = "411",
36 .mach_type = AR71XX_MACH_RB_411,
37 }, {
38 .name = "411U",
39 .mach_type = AR71XX_MACH_RB_411U,
40 }, {
41 .name = "433",
42 .mach_type = AR71XX_MACH_RB_433,
43 }, {
44 .name = "433U",
45 .mach_type = AR71XX_MACH_RB_433U,
46 }, {
47 .name = "450",
48 .mach_type = AR71XX_MACH_RB_450,
49 }, {
50 .name = "450G",
51 .mach_type = AR71XX_MACH_RB_450G,
52 }, {
53 .name = "493",
54 .mach_type = AR71XX_MACH_RB_493,
55 }, {
56 .name = "AP81",
57 .mach_type = AR71XX_MACH_AP81,
58 }, {
59 .name = "AP83",
60 .mach_type = AR71XX_MACH_AP83,
61 }, {
62 .name = "AW-NR580",
63 .mach_type = AR71XX_MACH_AW_NR580,
64 }, {
65 .name = "TEW-632BRP",
66 .mach_type = AR71XX_MACH_TEW_632BRP,
67 }, {
68 .name = "TL-WR741ND",
69 .mach_type = AR71XX_MACH_TL_WR741ND,
70 }, {
71 .name = "TL-WR941ND",
72 .mach_type = AR71XX_MACH_TL_WR941ND,
73 }, {
74 .name = "UBNT-RS",
75 .mach_type = AR71XX_MACH_UBNT_RS,
76 }, {
77 .name = "UBNT-RSPRO",
78 .mach_type = AR71XX_MACH_UBNT_RSPRO,
79 }, {
80 .name = "Ubiquiti AR71xx-based board",
81 .mach_type = AR71XX_MACH_UBNT_RS,
82 }, {
83 .name = "UBNT-LS-SR71",
84 .mach_type = AR71XX_MACH_UBNT_LSSR71,
85 }, {
86 .name = "UBNT-LSX",
87 .mach_type = AR71XX_MACH_UBNT_LSX,
88 }, {
89 .name = "WNR2000",
90 .mach_type = AR71XX_MACH_WNR2000,
91 }, {
92 .name = "WRT160NL",
93 .mach_type = AR71XX_MACH_WRT160NL,
94 }, {
95 .name = "WRT400N",
96 .mach_type = AR71XX_MACH_WRT400N,
97 }, {
98 .name = "PB42",
99 .mach_type = AR71XX_MACH_PB42,
100 }, {
101 .name = "PB44",
102 .mach_type = AR71XX_MACH_PB44,
103 }, {
104 .name = "MZK-W300NH",
105 .mach_type = AR71XX_MACH_MZK_W300NH,
106 }, {
107 .name = "MZK-W04NU",
108 .mach_type = AR71XX_MACH_MZK_W04NU,
109 }
110 };
111
112 static inline int is_valid_ram_addr(void *addr)
113 {
114 if (((u32) addr > KSEG0) &&
115 ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
116 return 1;
117
118 if (((u32) addr > KSEG1) &&
119 ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
120 return 1;
121
122 return 0;
123 }
124
125 static __init char *ar71xx_prom_getargv(const char *name)
126 {
127 int len = strlen(name);
128 int i;
129
130 if (!is_valid_ram_addr(ar71xx_prom_argv))
131 return NULL;
132
133 for (i = 0; i < ar71xx_prom_argc; i++) {
134 char *argv = ar71xx_prom_argv[i];
135
136 if (!is_valid_ram_addr(argv))
137 continue;
138
139 if (strncmp(name, argv, len) == 0 && (argv)[len] == '=')
140 return argv + len + 1;
141 }
142
143 return NULL;
144 }
145
146 static __init char *ar71xx_prom_getenv(const char *envname)
147 {
148 int len = strlen(envname);
149 char **env;
150
151 if (!is_valid_ram_addr(ar71xx_prom_envp))
152 return NULL;
153
154 for (env = ar71xx_prom_envp; is_valid_ram_addr(*env); env++) {
155 if (strncmp(envname, *env, len) == 0 && (*env)[len] == '=')
156 return *env + len + 1;
157
158 /* RedBoot env comes in pointer pairs - key, value */
159 if (strncmp(envname, *env, len) == 0 && (*env)[len] == 0)
160 if (is_valid_ram_addr(*(++env)))
161 return *env;
162 }
163
164 return NULL;
165 }
166
167 static __init unsigned long find_board_byname(char *name)
168 {
169 int i;
170
171 for (i = 0; i < ARRAY_SIZE(boards); i++)
172 if (strcmp(name, boards[i].name) == 0)
173 return boards[i].mach_type;
174
175 return AR71XX_MACH_GENERIC;
176 }
177
178 static int ar71xx_prom_init_myloader(void)
179 {
180 struct myloader_info *mylo;
181
182 mylo = myloader_get_info();
183 if (!mylo)
184 return 0;
185
186 switch (mylo->did) {
187 case DEVID_COMPEX_WP543:
188 ar71xx_mach = AR71XX_MACH_WP543;
189 break;
190 default:
191 printk(KERN_WARNING "prom: unknown device id: %x\n",
192 mylo->did);
193 }
194 ar71xx_set_mac_base(mylo->macs[0]);
195
196 return 1;
197 }
198
199 static void ar71xx_prom_init_generic(void)
200 {
201 char *p;
202
203 ar71xx_prom_argc = fw_arg0;
204 ar71xx_prom_argv = (char **)fw_arg1;
205 ar71xx_prom_envp = (char **)fw_arg2;
206
207 p = ar71xx_prom_getargv("board");
208 if (!p)
209 p = ar71xx_prom_getenv("board");
210 if (p)
211 ar71xx_mach = find_board_byname(p);
212
213 p = ar71xx_prom_getenv("ethaddr");
214 if (!p)
215 p = ar71xx_prom_getargv("kmac");
216 if (p)
217 ar71xx_parse_mac_addr(p);
218 }
219
220 void __init prom_init(void)
221 {
222 printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
223 "fw_arg2=%08x, fw_arg3=%08x\n",
224 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
225 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
226
227 ar71xx_mach = AR71XX_MACH_GENERIC;
228
229 if (ar71xx_prom_init_myloader())
230 return;
231
232 ar71xx_prom_init_generic();
233 }
234
235 void __init prom_free_prom_memory(void)
236 {
237 /* We do not have to prom memory to free */
238 }
This page took 0.051111 seconds and 3 git commands to generate.