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>
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
18 #include <asm/fw/myloader/myloader.h>
20 #include <asm/mach-ar71xx/ar71xx.h>
26 enum ar71xx_mach_type mach_type
;
29 static int ar71xx_prom_argc __initdata
;
30 static char **ar71xx_prom_argv __initdata
;
31 static char **ar71xx_prom_envp __initdata
;
33 static struct board_rec boards
[] __initdata
= {
36 .mach_type
= AR71XX_MACH_RB_411
,
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_TEW_632BRP
,
66 .mach_type
= AR71XX_MACH_TL_WR741ND
,
69 .mach_type
= AR71XX_MACH_TL_WR941ND
,
72 .mach_type
= AR71XX_MACH_UBNT_RS
,
75 .mach_type
= AR71XX_MACH_UBNT_RSPRO
,
77 .name
= "Ubiquiti AR71xx-based board",
78 .mach_type
= AR71XX_MACH_UBNT_RS
,
80 .name
= "UBNT-LS-SR71",
81 .mach_type
= AR71XX_MACH_UBNT_LSSR71
,
84 .mach_type
= AR71XX_MACH_UBNT_LSX
,
87 .mach_type
= AR71XX_MACH_WNR2000
,
90 .mach_type
= AR71XX_MACH_WRT160NL
,
93 .mach_type
= AR71XX_MACH_WRT400N
,
96 .mach_type
= AR71XX_MACH_PB42
,
99 .mach_type
= AR71XX_MACH_PB44
,
101 .name
= "MZK-W300NH",
102 .mach_type
= AR71XX_MACH_MZK_W300NH
,
105 .mach_type
= AR71XX_MACH_MZK_W04NU
,
109 static inline int is_valid_ram_addr(void *addr
)
111 if (((u32
) addr
> KSEG0
) &&
112 ((u32
) addr
< (KSEG0
+ AR71XX_MEM_SIZE_MAX
)))
115 if (((u32
) addr
> KSEG1
) &&
116 ((u32
) addr
< (KSEG1
+ AR71XX_MEM_SIZE_MAX
)))
122 static __init
char *ar71xx_prom_getargv(const char *name
)
124 int len
= strlen(name
);
127 if (!is_valid_ram_addr(ar71xx_prom_argv
))
130 for (i
= 0; i
< ar71xx_prom_argc
; i
++) {
131 char *argv
= ar71xx_prom_argv
[i
];
133 if (!is_valid_ram_addr(argv
))
136 if (strncmp(name
, argv
, len
) == 0 && (argv
)[len
] == '=')
137 return argv
+ len
+ 1;
143 static __init
char *ar71xx_prom_getenv(const char *envname
)
145 int len
= strlen(envname
);
148 if (!is_valid_ram_addr(ar71xx_prom_envp
))
151 for (env
= ar71xx_prom_envp
; is_valid_ram_addr(*env
); env
++) {
152 if (strncmp(envname
, *env
, len
) == 0 && (*env
)[len
] == '=')
153 return *env
+ len
+ 1;
155 /* RedBoot env comes in pointer pairs - key, value */
156 if (strncmp(envname
, *env
, len
) == 0 && (*env
)[len
] == 0)
157 if (is_valid_ram_addr(*(++env
)))
164 static __init
unsigned long find_board_byname(char *name
)
168 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
169 if (strcmp(name
, boards
[i
].name
) == 0)
170 return boards
[i
].mach_type
;
172 return AR71XX_MACH_GENERIC
;
175 static int ar71xx_prom_init_myloader(void)
177 struct myloader_info
*mylo
;
179 mylo
= myloader_get_info();
184 case DEVID_COMPEX_WP543
:
185 ar71xx_mach
= AR71XX_MACH_WP543
;
188 printk(KERN_WARNING
"prom: unknown device id: %x\n",
191 ar71xx_set_mac_base(mylo
->macs
[0]);
196 static void ar71xx_prom_init_generic(void)
200 ar71xx_prom_argc
= fw_arg0
;
201 ar71xx_prom_argv
= (char **)fw_arg1
;
202 ar71xx_prom_envp
= (char **)fw_arg2
;
204 p
= ar71xx_prom_getargv("board");
206 p
= ar71xx_prom_getenv("board");
208 ar71xx_mach
= find_board_byname(p
);
210 p
= ar71xx_prom_getenv("ethaddr");
212 p
= ar71xx_prom_getargv("kmac");
214 ar71xx_parse_mac_addr(p
);
217 void __init
prom_init(void)
219 printk(KERN_DEBUG
"prom: fw_arg0=%08x, fw_arg1=%08x, "
220 "fw_arg2=%08x, fw_arg3=%08x\n",
221 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
222 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
224 ar71xx_mach
= AR71XX_MACH_GENERIC
;
226 if (ar71xx_prom_init_myloader())
229 ar71xx_prom_init_generic();
232 void __init
prom_free_prom_memory(void)
234 /* We do not have to prom memory to free */