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>
19 #include <asm/fw/myloader/myloader.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/platform.h>
26 unsigned long 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_450
,
45 .mach_type
= AR71XX_MACH_RB_493
,
48 .mach_type
= AR71XX_MACH_AW_NR580
,
51 .mach_type
= AR71XX_MACH_AP83
,
55 static __init
char *ar71xx_prom_getargv(const char *name
)
57 int len
= strlen(name
);
60 if (!ar71xx_prom_argv
)
63 for (i
= 0; i
< ar71xx_prom_argc
; i
++) {
64 char *argv
= ar71xx_prom_argv
[i
];
69 if (strncmp(name
, argv
, len
) == 0 && (argv
)[len
] == '=')
70 return argv
+ len
+ 1;
76 static __init
char *ar71xx_prom_getenv(const char *envname
)
78 int len
= strlen(envname
);
81 if (!ar71xx_prom_envp
)
84 for (env
= ar71xx_prom_envp
; *env
!= NULL
; env
++)
85 if (strncmp(envname
, *env
, len
) == 0 && (*env
)[len
] == '=')
86 return *env
+ len
+ 1;
91 static __init
unsigned long find_board_byname(char *name
)
95 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
96 if (strcmp(name
, boards
[i
].name
) == 0)
97 return boards
[i
].mach_type
;
99 return AR71XX_MACH_GENERIC
;
102 static int ar71xx_prom_init_myloader(void)
104 struct myloader_info
*mylo
;
106 mylo
= myloader_get_info();
111 case DEVID_COMPEX_WP543
:
112 ar71xx_mach_type
= AR71XX_MACH_WP543
;
115 printk(KERN_WARNING
"prom: unknown device id: %x\n",
118 ar71xx_set_mac_base(mylo
->macs
[0]);
123 static void ar71xx_prom_init_generic(void)
127 ar71xx_prom_argc
= fw_arg0
;
128 ar71xx_prom_argv
= (char **)fw_arg1
;
129 ar71xx_prom_envp
= (char **)fw_arg2
;
131 p
= ar71xx_prom_getenv("board");
133 p
= ar71xx_prom_getargv("board");
135 ar71xx_mach_type
= find_board_byname(p
);
137 p
= ar71xx_prom_getenv("ethaddr");
139 p
= ar71xx_prom_getargv("kmac");
141 ar71xx_parse_mac_addr(p
);
144 void __init
prom_init(void)
146 printk(KERN_DEBUG
"prom: fw_arg0=%08x, fw_arg1=%08x, "
147 "fw_arg2=%08x, fw_arg3=%08x\n",
148 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
149 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
151 ar71xx_mach_type
= AR71XX_MACH_GENERIC
;
153 if (ar71xx_prom_init_myloader())
156 ar71xx_prom_init_generic();
159 void __init
prom_free_prom_memory(void)
161 /* We do not have to prom memory to free */
164 #define UART_READ(r) \
165 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
167 #define UART_WRITE(r, v) \
168 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
170 void prom_putchar(unsigned char ch
)
172 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);
173 UART_WRITE(UART_TX
, ch
);
174 while (((UART_READ(UART_LSR
)) & UART_LSR_THRE
) == 0);