2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * Putting things on the screen/serial line using YAMONs facilities.
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/serial_reg.h>
23 #include <linux/spinlock.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
27 #include <asm/bootinfo.h>
29 #include <asm/mach-ar7/ar7.h>
30 #include <asm/mach-ar7/prom.h>
39 static struct env_var adam2_env
[MAX_ENTRY
];
41 char *prom_getenv(const char *name
)
45 for (i
= 0; (i
< MAX_ENTRY
) && adam2_env
[i
].name
; i
++)
46 if (!strcmp(name
, adam2_env
[i
].name
))
47 return adam2_env
[i
].value
;
51 EXPORT_SYMBOL(prom_getenv
);
53 static void __init
ar7_init_cmdline(int argc
, char *argv
[])
57 for (i
= 1; i
< argc
; i
++) {
58 strlcat(arcs_cmdline
, argv
[i
], COMMAND_LINE_SIZE
);
60 strlcat(arcs_cmdline
, " ", COMMAND_LINE_SIZE
);
72 static const char psp_env_version
[] __initconst
= "TIENV0.8";
74 struct psp_env_chunk
{
82 struct psp_var_map_entry
{
87 static const struct psp_var_map_entry psp_var_map
[] = {
88 { 1, "cpufrequency" },
95 { 28, "sysfrequency" },
96 { 38, "mipsfrequency" },
101 Well-known variable (num is looked up in table above for matching variable name)
102 Example: cpufrequency=211968000
103 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
104 | 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
105 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
107 Name=Value pair in a single chunk
109 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
110 | 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
111 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
113 Name=Value pair in 2 chunks (len is the number of chunks)
114 Example: bootloaderVersion=1.3.7.15
115 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
116 | 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
117 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
118 | _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
119 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
121 Data is padded with 0xFF
125 #define PSP_ENV_SIZE 4096
127 static char psp_env_data
[PSP_ENV_SIZE
] = { 0, };
129 static char * __init
lookup_psp_var_map(u8 num
)
133 for (i
= 0; i
< ARRAY_SIZE(psp_var_map
); i
++)
134 if (psp_var_map
[i
].num
== num
)
135 return psp_var_map
[i
].value
;
140 static void __init
add_adam2_var(char *name
, char *value
)
144 for (i
= 0; i
< MAX_ENTRY
; i
++) {
145 if (!adam2_env
[i
].name
) {
146 adam2_env
[i
].name
= name
;
147 adam2_env
[i
].value
= value
;
149 } else if (!strcmp(adam2_env
[i
].name
, name
)) {
150 adam2_env
[i
].value
= value
;
156 static int __init
parse_psp_env(void *psp_env_base
)
160 struct psp_env_chunk
*chunks
= (struct psp_env_chunk
*)psp_env_data
;
162 memcpy_fromio(chunks
, psp_env_base
, PSP_ENV_SIZE
);
165 n
= PSP_ENV_SIZE
/ sizeof(struct psp_env_chunk
);
167 if ((chunks
[i
].num
== 0xff) || ((i
+ chunks
[i
].len
) > n
))
169 value
= chunks
[i
].data
;
171 name
= lookup_psp_var_map(chunks
[i
].num
);
174 value
+= strlen(name
) + 1;
177 add_adam2_var(name
, value
);
183 static void __init
ar7_init_env(struct env_var
*env
)
186 struct psbl_rec
*psbl
= (struct psbl_rec
*)(KSEG1ADDR(0x14000300));
187 void *psp_env
= (void *)KSEG1ADDR(psbl
->env_base
);
189 if (strcmp(psp_env
, psp_env_version
) == 0) {
190 parse_psp_env(psp_env
);
192 for (i
= 0; i
< MAX_ENTRY
; i
++, env
++)
194 add_adam2_var(env
->name
, env
->value
);
198 static void __init
console_config(void)
200 #ifdef CONFIG_SERIAL_8250_CONSOLE
201 char console_string
[40];
203 char parity
= '\0', bits
= '\0', flow
= '\0';
206 if (strstr(arcs_cmdline
, "console="))
209 s
= prom_getenv("modetty0");
211 baud
= simple_strtoul(s
, &p
, 10);
229 if (parity
!= 'n' && parity
!= 'o' && parity
!= 'e')
231 if (bits
!= '7' && bits
!= '8')
235 sprintf(console_string
, " console=ttyS0,%d%c%c%c", baud
,
238 sprintf(console_string
, " console=ttyS0,%d%c%c", baud
, parity
,
240 strlcat(arcs_cmdline
, console_string
, COMMAND_LINE_SIZE
);
244 void __init
prom_init(void)
246 ar7_init_cmdline(fw_arg0
, (char **)fw_arg1
);
247 ar7_init_env((struct env_var
*)fw_arg2
);
253 #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
254 static inline unsigned int serial_in(int offset
)
256 return readl((void *)PORT(offset
));
259 static inline void serial_out(int offset
, int value
)
261 writel(value
, (void *)PORT(offset
));
264 int prom_putchar(char c
)
266 while ((serial_in(UART_LSR
) & UART_LSR_TEMT
) == 0)
268 serial_out(UART_TX
, c
);