2 * Atheros AR71xx SoC specific prom routines
4 * Copyright (C) 2008 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>
20 #include <asm/mach-ar71xx/ar71xx.h>
24 unsigned long mach_type
;
27 static int prom_argc __initdata
;
28 static char **prom_argv __initdata
;
29 static char **prom_envp __initdata
;
31 static struct board_rec boards
[] __initdata
= {
34 .mach_type
= MACH_AR71XX_RB_411
,
37 .mach_type
= MACH_AR71XX_RB_433
,
40 .mach_type
= MACH_AR71XX_RB_450
,
44 char *(*prom_getenv
)(const char *envname
) __initdata
;
46 static __init
char *dummy_getenv(const char *envname
)
51 static void __init
routerboot_printargs(void)
55 for (i
= 0; i
< prom_argc
; i
++)
56 printk(KERN_DEBUG
"prom: routerboot envp[%d]: %s\n",
60 static __init
char *routerboot_getenv(const char *envname
)
63 int i
= strlen(envname
);
65 for (env
= prom_envp
; *env
!= NULL
; env
++)
66 if (strncmp(envname
, *env
, i
) == 0 && (*env
)[i
] == '=')
72 static __init
unsigned long find_board_byname(char *name
)
76 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
77 if (strcmp(name
, boards
[i
].name
) == 0)
78 return boards
[i
].mach_type
;
80 return MACH_AR71XX_GENERIC
;
83 void __init
prom_init(void)
87 printk(KERN_DEBUG
"prom: fw_arg0=%08x, fw_arg1=%08x, "
88 "fw_arg2=%08x, fw_arg3=%08x\n",
89 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
90 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
92 prom_getenv
= dummy_getenv
;
94 if ((fw_arg0
== 7) && (fw_arg2
== 0)) {
96 prom_envp
= (char **)fw_arg1
;
97 prom_getenv
= routerboot_getenv
;
98 routerboot_printargs();
101 board
= prom_getenv("board");
103 mips_machtype
= find_board_byname(board
);
105 mips_machtype
= MACH_AR71XX_GENERIC
;
107 ar71xx_print_cmdline();
110 void __init
prom_free_prom_memory(void)
112 /* We do not have to prom memory to free */
115 #define UART_READ(r) \
116 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
118 #define UART_WRITE(r, v) \
119 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
121 void prom_putchar(unsigned char ch
)
123 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);
124 UART_WRITE(UART_TX
, ch
);
125 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);