ar71xx: fix a compiler warning
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / prom.c
1 /*
2 * Atheros AR71xx SoC specific prom routines
3 *
4 * Copyright (C) 2008-2010 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 #include <linux/string.h>
16
17 #include <asm/bootinfo.h>
18 #include <asm/addrspace.h>
19 #include <asm/fw/myloader/myloader.h>
20
21 #include <asm/mach-ar71xx/ar71xx.h>
22
23 static inline int is_valid_ram_addr(void *addr)
24 {
25 if (((u32) addr > KSEG0) &&
26 ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
27 return 1;
28
29 if (((u32) addr > KSEG1) &&
30 ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
31 return 1;
32
33 return 0;
34 }
35
36 static char ar71xx_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
37 static void __init ar71xx_prom_append_cmdline(const char *name,
38 const char *value)
39 {
40 snprintf(ar71xx_cmdline_buf, sizeof(ar71xx_cmdline_buf),
41 " %s=%s", name, value);
42 strlcat(arcs_cmdline, ar71xx_cmdline_buf, sizeof(arcs_cmdline));
43 }
44
45 static const char * __init ar71xx_prom_find_env(char **envp, const char *name)
46 {
47 const char *ret = NULL;
48 int len;
49 char **p;
50
51 if (!is_valid_ram_addr(envp))
52 return NULL;
53
54 len = strlen(name);
55 for (p = envp; is_valid_ram_addr(*p); p++) {
56 if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') {
57 ret = *p + len + 1;
58 break;
59 }
60
61 /* RedBoot env comes in pointer pairs - key, value */
62 if (strncmp(name, *p, len) == 0 && (*p)[len] == 0)
63 if (is_valid_ram_addr(*(++p))) {
64 ret = *p;
65 break;
66 }
67 }
68
69 return ret;
70 }
71
72 static int __init ar71xx_prom_init_myloader(void)
73 {
74 struct myloader_info *mylo;
75 char mac_buf[32];
76 char *mac;
77
78 mylo = myloader_get_info();
79 if (!mylo)
80 return 0;
81
82 switch (mylo->did) {
83 case DEVID_COMPEX_WP543:
84 ar71xx_prom_append_cmdline("board", "WP543");
85 break;
86 default:
87 printk(KERN_WARNING "prom: unknown device id: %x\n",
88 mylo->did);
89 return 0;
90 }
91
92 mac = mylo->macs[0];
93 snprintf(mac_buf, sizeof(mac_buf), "%02x:%02x:%02x:%02x:%02x:%02x",
94 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
95
96 ar71xx_prom_append_cmdline("ethaddr", mac_buf);
97
98 return 1;
99 }
100
101 #ifdef CONFIG_IMAGE_CMDLINE_HACK
102 extern char __image_cmdline[];
103
104 static int __init ar71xx_use__image_cmdline(void)
105 {
106 char *p = __image_cmdline;
107 int replace = 0;
108
109 if (*p == '-') {
110 replace = 1;
111 p++;
112 }
113
114 if (*p == '\0')
115 return 0;
116
117 if (replace) {
118 strlcpy(arcs_cmdline, p, sizeof(arcs_cmdline));
119 } else {
120 strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
121 strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
122 }
123
124 return 1;
125 }
126 #else
127 static inline int ar71xx_use__image_cmdline(void) { return 0; }
128 #endif
129
130 static __init void ar71xx_prom_init_cmdline(int argc, char **argv)
131 {
132 int i;
133
134 if (ar71xx_use__image_cmdline())
135 return;
136
137 if (!is_valid_ram_addr(argv))
138 return;
139
140 for (i = 0; i < argc; i++)
141 if (is_valid_ram_addr(argv[i])) {
142 strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
143 strlcat(arcs_cmdline, argv[i], sizeof(arcs_cmdline));
144 }
145 }
146
147 void __init prom_init(void)
148 {
149 const char *env;
150 char **envp;
151
152 printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
153 "fw_arg2=%08x, fw_arg3=%08x\n",
154 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
155 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
156
157
158 if (ar71xx_prom_init_myloader())
159 return;
160
161 ar71xx_prom_init_cmdline(fw_arg0, (char **)fw_arg1);
162
163 envp = (char **)fw_arg2;
164 if (!strstr(arcs_cmdline, "ethaddr=")) {
165 env = ar71xx_prom_find_env(envp, "ethaddr");
166 if (env)
167 ar71xx_prom_append_cmdline("ethaddr", env);
168 }
169
170 if (!strstr(arcs_cmdline, "board=")) {
171 env = ar71xx_prom_find_env(envp, "board");
172 if (env) {
173 /* Workaround for buggy bootloaders */
174 if (strcmp(env, "RouterStation") == 0 ||
175 strcmp(env, "Ubiquiti AR71xx-based board") == 0)
176 env = "UBNT-RS";
177
178 if (strcmp(env, "RouterStation PRO") == 0)
179 env = "UBNT-RSPRO";
180
181 ar71xx_prom_append_cmdline("board", env);
182 }
183 }
184 }
185
186 void __init prom_free_prom_memory(void)
187 {
188 /* We do not have to prom memory to free */
189 }