[ar71xx] add MyLoader support
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / prom.c
1 /*
2 * Atheros AR71xx SoC specific prom routines
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
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.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15 #include <linux/serial_reg.h>
16
17 #include <asm/bootinfo.h>
18 #include <asm/addrspace.h>
19 #include <asm/fw/myloader/myloader.h>
20
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/platform.h>
23
24 struct board_rec {
25 char *name;
26 unsigned long mach_type;
27 };
28
29 static int ar71xx_prom_argc __initdata;
30 static char **ar71xx_prom_argv __initdata;
31 static char **ar71xx_prom_envp __initdata;
32
33 static struct board_rec boards[] __initdata = {
34 {
35 .name = "411",
36 .mach_type = MACH_AR71XX_RB_411,
37 }, {
38 .name = "433",
39 .mach_type = MACH_AR71XX_RB_433,
40 }, {
41 .name = "450",
42 .mach_type = MACH_AR71XX_RB_450,
43 }
44 };
45
46 static __init char *ar71xx_prom_getargv(const char *name)
47 {
48 int len = strlen(name);
49 int i;
50
51 if (!ar71xx_prom_argv)
52 return NULL;
53
54 for (i = 0; i < ar71xx_prom_argc; i++) {
55 char *argv = ar71xx_prom_argv[i];
56 if (strncmp(name, argv, len) == 0 && (argv)[len] == '=')
57 return argv + len + 1;
58 }
59
60 return NULL;
61 }
62
63 static __init char *ar71xx_prom_getenv(const char *envname)
64 {
65 int len = strlen(envname);
66 char **env;
67
68 if (!ar71xx_prom_envp)
69 return NULL;
70
71 for (env = ar71xx_prom_envp; *env != NULL; env++)
72 if (strncmp(envname, *env, len) == 0 && (*env)[len] == '=')
73 return *env + len + 1;
74
75 return NULL;
76 }
77
78 static __init unsigned long find_board_byname(char *name)
79 {
80 int i;
81
82 for (i = 0; i < ARRAY_SIZE(boards); i++)
83 if (strcmp(name, boards[i].name) == 0)
84 return boards[i].mach_type;
85
86 return MACH_AR71XX_GENERIC;
87 }
88
89 static int ar71xx_prom_init_myloader(void)
90 {
91 struct myloader_info *mylo;
92
93 mylo = myloader_get_info();
94 if (!mylo)
95 return 0;
96
97 switch (mylo->did) {
98 case DEVID_COMPEX_WP543:
99 mips_machtype = MACH_AR71XX_WP543;
100 break;
101 default:
102 printk(KERN_WARNING "prom: unknown device id: %x\n",
103 mylo->did);
104 }
105 ar71xx_set_mac_base(mylo->macs[0]);
106
107 return 1;
108 }
109
110 static void ar71xx_prom_init_generic(void)
111 {
112 char *p;
113
114 ar71xx_prom_argc = fw_arg0;
115 ar71xx_prom_argv = (char **)fw_arg1;
116 ar71xx_prom_envp = (char **)fw_arg2;
117
118 p = ar71xx_prom_getenv("board");
119 if (!p)
120 p = ar71xx_prom_getargv("board");
121 if (p)
122 mips_machtype = find_board_byname(p);
123
124 p = ar71xx_prom_getenv("ethaddr");
125 if (!p)
126 p = ar71xx_prom_getargv("kmac");
127 if (p)
128 ar71xx_parse_mac_addr(p);
129 }
130
131 void __init prom_init(void)
132 {
133 printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
134 "fw_arg2=%08x, fw_arg3=%08x\n",
135 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
136 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
137
138 mips_machtype = MACH_AR71XX_GENERIC;
139
140 if (ar71xx_prom_init_myloader())
141 return;
142
143 ar71xx_prom_init_generic();
144 }
145
146 void __init prom_free_prom_memory(void)
147 {
148 /* We do not have to prom memory to free */
149 }
150
151 #define UART_READ(r) \
152 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
153
154 #define UART_WRITE(r, v) \
155 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
156
157 void prom_putchar(unsigned char ch)
158 {
159 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
160 UART_WRITE(UART_TX, ch);
161 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
162 }