2 * Atheros AR71xx SoC specific prom routines
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
15 #include <linux/string.h>
17 #include <asm/bootinfo.h>
18 #include <asm/addrspace.h>
19 #include <asm/fw/myloader/myloader.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
27 enum ar71xx_mach_type mach_type
;
30 static struct board_rec boards
[] __initdata
= {
33 .mach_type
= AR71XX_MACH_RB_411
,
36 .mach_type
= AR71XX_MACH_RB_411U
,
39 .mach_type
= AR71XX_MACH_RB_433
,
42 .mach_type
= AR71XX_MACH_RB_433U
,
45 .mach_type
= AR71XX_MACH_RB_450
,
48 .mach_type
= AR71XX_MACH_RB_450G
,
51 .mach_type
= AR71XX_MACH_RB_493
,
54 .mach_type
= AR71XX_MACH_AP81
,
57 .mach_type
= AR71XX_MACH_AP83
,
60 .mach_type
= AR71XX_MACH_AW_NR580
,
63 .mach_type
= AR71XX_MACH_DIR_825_B1
,
66 .mach_type
= AR71XX_MACH_TEW_632BRP
,
69 .mach_type
= AR71XX_MACH_DIR_615_C1
,
72 .mach_type
= AR71XX_MACH_TL_WR741ND
,
75 .mach_type
= AR71XX_MACH_TL_WR941ND
,
77 .name
= "TL-WR1043ND",
78 .mach_type
= AR71XX_MACH_TL_WR1043ND
,
81 .mach_type
= AR71XX_MACH_UBNT_RS
,
84 .mach_type
= AR71XX_MACH_UBNT_RSPRO
,
86 .name
= "Ubiquiti AR71xx-based board",
87 .mach_type
= AR71XX_MACH_UBNT_RS
,
89 .name
= "UBNT-LS-SR71",
90 .mach_type
= AR71XX_MACH_UBNT_LSSR71
,
93 .mach_type
= AR71XX_MACH_UBNT_LSX
,
96 .mach_type
= AR71XX_MACH_UBNT_BULLET_M
,
99 .mach_type
= AR71XX_MACH_UBNT_ROCKET_M
,
102 .mach_type
= AR71XX_MACH_UBNT_NANO_M
,
105 .mach_type
= AR71XX_MACH_WNDR3700
,
108 .mach_type
= AR71XX_MACH_WNR2000
,
111 .mach_type
= AR71XX_MACH_WRT160NL
,
114 .mach_type
= AR71XX_MACH_WP543
,
117 .mach_type
= AR71XX_MACH_WRT400N
,
120 .mach_type
= AR71XX_MACH_PB42
,
123 .mach_type
= AR71XX_MACH_PB44
,
125 .name
= "MZK-W300NH",
126 .mach_type
= AR71XX_MACH_MZK_W300NH
,
129 .mach_type
= AR71XX_MACH_MZK_W04NU
,
133 static int __init
ar71xx_board_setup(char *name
)
137 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
138 if (strcmp(name
, boards
[i
].name
) == 0) {
139 ar71xx_mach
= boards
[i
].mach_type
;
145 __setup("board=", ar71xx_board_setup
);
147 static int __init
ar71xx_ethaddr_setup(char *str
)
149 ar71xx_parse_mac_addr(str
);
152 __setup("ethaddr=", ar71xx_ethaddr_setup
);
154 static int __init
ar71xx_kmac_setup(char *str
)
156 ar71xx_parse_mac_addr(str
);
159 __setup("kmac=", ar71xx_kmac_setup
);
161 static inline int is_valid_ram_addr(void *addr
)
163 if (((u32
) addr
> KSEG0
) &&
164 ((u32
) addr
< (KSEG0
+ AR71XX_MEM_SIZE_MAX
)))
167 if (((u32
) addr
> KSEG1
) &&
168 ((u32
) addr
< (KSEG1
+ AR71XX_MEM_SIZE_MAX
)))
174 static void __init
ar71xx_prom_append_cmdline(const char *name
,
179 snprintf(buf
, sizeof(buf
), " %s=%s", name
, value
);
180 strlcat(arcs_cmdline
, buf
, sizeof(arcs_cmdline
));
183 static void __init
ar71xx_prom_find_env(char **envp
, const char *name
)
185 int len
= strlen(name
);
188 if (!is_valid_ram_addr(envp
))
191 for (p
= envp
; is_valid_ram_addr(*p
); p
++) {
192 if (strncmp(name
, *p
, len
) == 0 && (*p
)[len
] == '=') {
193 ar71xx_prom_append_cmdline(name
, *p
+ len
+ 1);
197 /* RedBoot env comes in pointer pairs - key, value */
198 if (strncmp(name
, *p
, len
) == 0 && (*p
)[len
] == 0)
199 if (is_valid_ram_addr(*(++p
))) {
200 ar71xx_prom_append_cmdline(name
, *p
);
206 static int __init
ar71xx_prom_init_myloader(void)
208 struct myloader_info
*mylo
;
212 mylo
= myloader_get_info();
217 case DEVID_COMPEX_WP543
:
218 ar71xx_prom_append_cmdline("board", "WP543");
221 printk(KERN_WARNING
"prom: unknown device id: %x\n",
227 snprintf(mac_buf
, sizeof(mac_buf
), "%02x:%02x:%02x:%02x:%02x:%02x",
228 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5]);
230 ar71xx_prom_append_cmdline("ethaddr", mac_buf
);
235 #ifdef CONFIG_IMAGE_CMDLINE_HACK
236 extern char __image_cmdline
[];
238 static int __init
ar71xx_use__image_cmdline(void)
240 char *p
= __image_cmdline
;
252 strlcpy(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
254 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
255 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
261 static int inline ar71xx_use__image_cmdline(void) { return 0; }
264 static __init
void ar71xx_prom_init_cmdline(int argc
, char **argv
)
268 if (ar71xx_use__image_cmdline())
271 if (!is_valid_ram_addr(argv
))
274 for (i
= 0; i
< argc
; i
++)
275 if (is_valid_ram_addr(argv
[i
])) {
276 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
277 strlcat(arcs_cmdline
, argv
[i
], sizeof(arcs_cmdline
));
281 void __init
prom_init(void)
285 printk(KERN_DEBUG
"prom: fw_arg0=%08x, fw_arg1=%08x, "
286 "fw_arg2=%08x, fw_arg3=%08x\n",
287 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
288 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
291 ar71xx_mach
= AR71XX_MACH_GENERIC
;
293 if (ar71xx_prom_init_myloader())
296 ar71xx_prom_init_cmdline(fw_arg0
, (char **)fw_arg1
);
298 envp
= (char **)fw_arg2
;
299 ar71xx_prom_find_env(envp
, "board");
300 ar71xx_prom_find_env(envp
, "ethaddr");
303 void __init
prom_free_prom_memory(void)
305 /* We do not have to prom memory to free */