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/serial_reg.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 unsigned long mach_type;
30 static int ar71xx_prom_argc __initdata;
31 static char **ar71xx_prom_argv __initdata;
32 static char **ar71xx_prom_envp __initdata;
34 static struct board_rec boards[] __initdata = {
37 .mach_type = AR71XX_MACH_RB_411,
40 .mach_type = AR71XX_MACH_RB_433,
43 .mach_type = AR71XX_MACH_RB_450,
46 .mach_type = AR71XX_MACH_RB_493,
49 .mach_type = AR71XX_MACH_AP81,
52 .mach_type = AR71XX_MACH_AP83,
55 .mach_type = AR71XX_MACH_AW_NR580,
58 .mach_type = AR71XX_MACH_TEW_632BRP,
61 .mach_type = AR71XX_MACH_TL_WR941ND,
64 .mach_type = AR71XX_MACH_UBNT_RS,
67 .mach_type = AR71XX_MACH_UBNT_RSPRO,
69 .name = "Ubiquiti AR71xx-based board",
70 .mach_type = AR71XX_MACH_UBNT_RS,
72 .name = "UBNT-LS-SR71",
73 .mach_type = AR71XX_MACH_UBNT_LSSR71,
76 .mach_type = AR71XX_MACH_UBNT_LSX,
79 .mach_type = AR71XX_MACH_WNR2000,
82 .mach_type = AR71XX_MACH_WRT400N,
85 .mach_type = AR71XX_MACH_PB42,
88 .mach_type = AR71XX_MACH_MZK_W300NH,
91 .mach_type = AR71XX_MACH_MZK_W04NU,
95 static inline int is_valid_ram_addr(void *addr)
97 if (((u32) addr > KSEG0) &&
98 ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
101 if (((u32) addr > KSEG1) &&
102 ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
108 static __init char *ar71xx_prom_getargv(const char *name)
110 int len = strlen(name);
113 if (!is_valid_ram_addr(ar71xx_prom_argv))
116 for (i = 0; i < ar71xx_prom_argc; i++) {
117 char *argv = ar71xx_prom_argv[i];
119 if (!is_valid_ram_addr(argv))
122 if (strncmp(name, argv, len) == 0 && (argv)[len] == '=')
123 return argv + len + 1;
129 static __init char *ar71xx_prom_getenv(const char *envname)
131 int len = strlen(envname);
134 if (!is_valid_ram_addr(ar71xx_prom_envp))
137 for (env = ar71xx_prom_envp; is_valid_ram_addr(*env); env++) {
138 if (strncmp(envname, *env, len) == 0 && (*env)[len] == '=')
139 return *env + len + 1;
141 /* RedBoot env comes in pointer pairs - key, value */
142 if (strncmp(envname, *env, len) == 0 && (*env)[len] == 0)
143 if (is_valid_ram_addr(*(++env)))
150 static __init unsigned long find_board_byname(char *name)
154 for (i = 0; i < ARRAY_SIZE(boards); i++)
155 if (strcmp(name, boards[i].name) == 0)
156 return boards[i].mach_type;
158 return AR71XX_MACH_GENERIC;
161 static int ar71xx_prom_init_myloader(void)
163 struct myloader_info *mylo;
165 mylo = myloader_get_info();
170 case DEVID_COMPEX_WP543:
171 ar71xx_mach_type = AR71XX_MACH_WP543;
174 printk(KERN_WARNING "prom: unknown device id: %x\n",
177 ar71xx_set_mac_base(mylo->macs[0]);
182 static void ar71xx_prom_init_generic(void)
186 ar71xx_prom_argc = fw_arg0;
187 ar71xx_prom_argv = (char **)fw_arg1;
188 ar71xx_prom_envp = (char **)fw_arg2;
190 p = ar71xx_prom_getargv("board");
192 p = ar71xx_prom_getenv("board");
194 ar71xx_mach_type = find_board_byname(p);
196 p = ar71xx_prom_getenv("ethaddr");
198 p = ar71xx_prom_getargv("kmac");
200 ar71xx_parse_mac_addr(p);
203 void __init prom_init(void)
205 printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
206 "fw_arg2=%08x, fw_arg3=%08x\n",
207 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
208 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
210 ar71xx_mach_type = AR71XX_MACH_GENERIC;
212 if (ar71xx_prom_init_myloader())
215 ar71xx_prom_init_generic();
218 void __init prom_free_prom_memory(void)
220 /* We do not have to prom memory to free */
223 #define UART_READ(r) \
224 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
226 #define UART_WRITE(r, v) \
227 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
229 void prom_putchar(unsigned char ch)
231 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
232 UART_WRITE(UART_TX, ch);
233 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);