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_411U
,
42 .mach_type
= AR71XX_MACH_RB_433
,
45 .mach_type
= AR71XX_MACH_RB_433U
,
48 .mach_type
= AR71XX_MACH_RB_450
,
51 .mach_type
= AR71XX_MACH_RB_450G
,
54 .mach_type
= AR71XX_MACH_RB_493
,
57 .mach_type
= AR71XX_MACH_AP81
,
60 .mach_type
= AR71XX_MACH_AP83
,
63 .mach_type
= AR71XX_MACH_AW_NR580
,
66 .mach_type
= AR71XX_MACH_TEW_632BRP
,
69 .mach_type
= AR71XX_MACH_TL_WR741ND
,
72 .mach_type
= AR71XX_MACH_TL_WR941ND
,
75 .mach_type
= AR71XX_MACH_UBNT_RS
,
78 .mach_type
= AR71XX_MACH_UBNT_RSPRO
,
80 .name
= "Ubiquiti AR71xx-based board",
81 .mach_type
= AR71XX_MACH_UBNT_RS
,
83 .name
= "UBNT-LS-SR71",
84 .mach_type
= AR71XX_MACH_UBNT_LSSR71
,
87 .mach_type
= AR71XX_MACH_UBNT_LSX
,
90 .mach_type
= AR71XX_MACH_WNR2000
,
93 .mach_type
= AR71XX_MACH_WRT160NL
,
96 .mach_type
= AR71XX_MACH_WRT400N
,
99 .mach_type
= AR71XX_MACH_PB42
,
102 .mach_type
= AR71XX_MACH_PB44
,
104 .name
= "MZK-W300NH",
105 .mach_type
= AR71XX_MACH_MZK_W300NH
,
108 .mach_type
= AR71XX_MACH_MZK_W04NU
,
112 static inline int is_valid_ram_addr(void *addr
)
114 if (((u32
) addr
> KSEG0
) &&
115 ((u32
) addr
< (KSEG0
+ AR71XX_MEM_SIZE_MAX
)))
118 if (((u32
) addr
> KSEG1
) &&
119 ((u32
) addr
< (KSEG1
+ AR71XX_MEM_SIZE_MAX
)))
125 static __init
char *ar71xx_prom_getargv(const char *name
)
127 int len
= strlen(name
);
130 if (!is_valid_ram_addr(ar71xx_prom_argv
))
133 for (i
= 0; i
< ar71xx_prom_argc
; i
++) {
134 char *argv
= ar71xx_prom_argv
[i
];
136 if (!is_valid_ram_addr(argv
))
139 if (strncmp(name
, argv
, len
) == 0 && (argv
)[len
] == '=')
140 return argv
+ len
+ 1;
146 static __init
char *ar71xx_prom_getenv(const char *envname
)
148 int len
= strlen(envname
);
151 if (!is_valid_ram_addr(ar71xx_prom_envp
))
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;
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
)))
167 static __init
unsigned long find_board_byname(char *name
)
171 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
172 if (strcmp(name
, boards
[i
].name
) == 0)
173 return boards
[i
].mach_type
;
175 return AR71XX_MACH_GENERIC
;
178 static int ar71xx_prom_init_myloader(void)
180 struct myloader_info
*mylo
;
182 mylo
= myloader_get_info();
187 case DEVID_COMPEX_WP543
:
188 ar71xx_mach
= AR71XX_MACH_WP543
;
191 printk(KERN_WARNING
"prom: unknown device id: %x\n",
194 ar71xx_set_mac_base(mylo
->macs
[0]);
199 static void ar71xx_prom_init_generic(void)
203 ar71xx_prom_argc
= fw_arg0
;
204 ar71xx_prom_argv
= (char **)fw_arg1
;
205 ar71xx_prom_envp
= (char **)fw_arg2
;
207 p
= ar71xx_prom_getargv("board");
209 p
= ar71xx_prom_getenv("board");
211 ar71xx_mach
= find_board_byname(p
);
213 p
= ar71xx_prom_getenv("ethaddr");
215 p
= ar71xx_prom_getargv("kmac");
217 ar71xx_parse_mac_addr(p
);
220 void __init
prom_init(void)
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
);
227 ar71xx_mach
= AR71XX_MACH_GENERIC
;
229 if (ar71xx_prom_init_myloader())
232 ar71xx_prom_init_generic();
235 void __init
prom_free_prom_memory(void)
237 /* We do not have to prom memory to free */