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>
21 #include <asm/mach-ar71xx/platform.h>
25 unsigned long mach_type
;
28 static int ar71xx_prom_argc __initdata
;
29 static char **ar71xx_prom_argv __initdata
;
30 static char **ar71xx_prom_envp __initdata
;
32 static struct board_rec boards
[] __initdata
= {
35 .mach_type
= MACH_AR71XX_RB_411
,
38 .mach_type
= MACH_AR71XX_RB_433
,
41 .mach_type
= MACH_AR71XX_RB_450
,
45 static __init
void routerboot_printargs(void)
49 for (i
= 0; i
< ar71xx_prom_argc
; i
++)
50 printk(KERN_DEBUG
"prom: routerboot envp[%d]: %s\n",
51 i
, ar71xx_prom_argv
[i
]);
54 static __init
char *routerboot_getenv(const char *envname
)
56 int len
= strlen(envname
);
59 for (i
= 0; i
< ar71xx_prom_argc
; i
++) {
60 char *env
= ar71xx_prom_argv
[i
];
61 if (strncmp(envname
, env
, len
) == 0 && (env
)[len
] == '=')
68 static __init
char *redboot_getenv(const char *envname
)
70 int len
= strlen(envname
);
73 for (env
= ar71xx_prom_envp
; *env
!= NULL
; env
++)
74 if (strncmp(envname
, *env
, len
) == 0 && (*env
)[len
] == '=')
75 return *env
+ len
+ 1;
80 static __init
unsigned long find_board_byname(char *name
)
84 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
85 if (strcmp(name
, boards
[i
].name
) == 0)
86 return boards
[i
].mach_type
;
88 return MACH_AR71XX_GENERIC
;
91 void __init
prom_init(void)
96 printk(KERN_DEBUG
"prom: fw_arg0=%08x, fw_arg1=%08x, "
97 "fw_arg2=%08x, fw_arg3=%08x\n",
98 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
99 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
101 if ((fw_arg0
== 7) && (fw_arg2
== 0) && (fw_arg3
== 0)) {
102 /* assume RouterBOOT */
103 ar71xx_prom_argc
= fw_arg0
;
104 ar71xx_prom_argv
= (char **)fw_arg1
;
105 routerboot_printargs();
106 board
= routerboot_getenv("board");
107 mac
= routerboot_getenv("kmac");
110 ar71xx_prom_argc
= fw_arg0
;
111 ar71xx_prom_argv
= (char **)fw_arg1
;
112 ar71xx_prom_envp
= (char **)fw_arg2
;
113 mac
= redboot_getenv("ethaddr");
117 mips_machtype
= find_board_byname(board
);
119 mips_machtype
= MACH_AR71XX_GENERIC
;
122 ar71xx_set_mac_base(mac
);
124 ar71xx_print_cmdline();
127 void __init
prom_free_prom_memory(void)
129 /* We do not have to prom memory to free */
132 #define UART_READ(r) \
133 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
135 #define UART_WRITE(r, v) \
136 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
138 void prom_putchar(unsigned char ch
)
140 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);
141 UART_WRITE(UART_TX
, ch
);
142 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);