4 * Copyright (C) 2006, 2007 OpenWrt.org
6 * Carsten Langgaard, carstenl@mips.com
7 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
9 * This program is free software; you can distribute it and/or modify it
10 * under the terms of the GNU General Public License (Version 2) as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 * Putting things on the screen/serial line using YAMONs facilities.
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/serial_reg.h>
27 #include <linux/spinlock.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
31 #include <asm/bootinfo.h>
32 #include <asm/mips-boards/prom.h>
33 #include <asm/gdb-stub.h>
35 #include <asm/ar7/ar7.h>
49 /* I hate this. No. *I* *HATE* *THIS* */
50 static __initdata
struct psp_chip_map psp_chip_map
[] = {
52 .chip
= AR7_CHIP_7100
,
54 "dummy", "cpufrequency", "memsize",
55 "flashsize", "modetty0", "modetty1", "prompt",
56 "bootcfg", "maca", "macb", "usb_rndis_mac",
57 "macap", "my_ipaddress", "server_ipaddress",
58 "bline_maca", "bline_macb", "bline_rndis",
59 "bline_atm", "usb_pid", "usb_vid",
60 "usb_eppolli", "gateway_ipaddress",
61 "subnet_mask", "usb_serial", "usb_board_mac",
62 "remote_user", "remote_pass", "remote_dir",
63 "sysfrequency", "link_timeout", "mac_port",
64 "path", "hostname", "tftpcfg", "buildops",
65 "tftp_fo_fname", "tftp_fo_ports",
66 "console_state", "mipsfrequency",
70 .chip
= AR7_CHIP_7200
,
72 "dummy", "cpufrequency", "memsize",
73 "flashsize", "modetty0", "modetty1", "prompt",
74 "bootcfg", "maca", "macb", "usb_rndis_mac",
75 "macap", "my_ipaddress", "server_ipaddress",
76 "bline_maca", "bline_macb", "bline_rndis",
77 "bline_atm", "usb_pid", "usb_vid",
78 "usb_eppolli", "gateway_ipaddress",
79 "subnet_mask", "usb_serial", "usb_board_mac",
80 "remote_user", "remote_pass", "remote_dir",
81 "sysfrequency", "link_timeout", "mac_port",
82 "path", "hostname", "tftpcfg", "buildops",
83 "tftp_fo_fname", "tftp_fo_ports",
84 "console_state", "mipsfrequency",
88 .chip
= AR7_CHIP_7300
,
90 "dummy", "cpufrequency", "memsize",
91 "flashsize", "modetty0", "modetty1", "prompt",
92 "bootcfg", "maca", "macb", "usb_rndis_mac",
93 "macap", "my_ipaddress", "server_ipaddress",
94 "bline_maca", "bline_macb", "bline_rndis",
95 "bline_atm", "usb_pid", "usb_vid",
96 "usb_eppolli", "gateway_ipaddress",
97 "subnet_mask", "usb_serial", "usb_board_mac",
98 "remote_user", "remote_pass", "remote_dir",
99 "sysfrequency", "link_timeout", "mac_port",
100 "path", "hostname", "tftpcfg", "buildops",
101 "tftp_fo_fname", "tftp_fo_ports",
102 "console_state", "mipsfrequency",
110 static struct env_var adam2_env
[MAX_ENTRY
] = { { 0, }, };
112 char * prom_getenv(char *name
)
115 for (i
= 0; (i
< MAX_ENTRY
) && adam2_env
[i
].name
; i
++)
116 if (!strcmp(name
, adam2_env
[i
].name
))
117 return adam2_env
[i
].value
;
122 char * __init
prom_getcmdline(void)
124 return &(arcs_cmdline
[0]);
127 static void __init
ar7_init_cmdline(int argc
, char *argv
[])
132 actr
= 1; /* Always ignore argv[0] */
134 cp
= &(arcs_cmdline
[0]);
136 strcpy(cp
, argv
[actr
]);
137 cp
+= strlen(argv
[actr
]);
141 if (cp
!= &(arcs_cmdline
[0])) {
142 /* get rid of trailing space */
156 static __initdata
char psp_env_version
[] = "TIENV0.8";
163 unsigned char data
[11];
166 static char psp_env_data
[2048] = { 0, };
168 static void __init
add_adam2_var(char *name
, char *value
)
171 for (i
= 0; i
< MAX_ENTRY
; i
++) {
172 if (!adam2_env
[i
].name
) {
173 adam2_env
[i
].name
= name
;
174 adam2_env
[i
].value
= value
;
176 } else if (!strcmp(adam2_env
[i
].name
, name
)) {
177 adam2_env
[i
].value
= value
;
183 static int __init
parse_psp_env(void *start
)
187 struct psp_chip_map
*map
;
188 char *src
, *dest
, *name
, *value
;
189 struct psp_env_var
*vars
= start
;
191 chip
= ar7_chip_id();
192 for (map
= psp_chip_map
; map
->chip
; map
++)
193 if (map
->chip
== chip
)
202 while (vars
[i
].num
< 0xff) {
205 strcpy(dest
, map
->names
[vars
[i
].num
]);
210 src
+= strlen(src
) + 1;
212 dest
+= strlen(dest
) + 1;
215 dest
+= strlen(dest
) + 1;
216 add_adam2_var(name
, value
);
222 static void __init
ar7_init_env(struct env_var
*env
)
225 struct psbl_rec
*psbl
= (struct psbl_rec
*)(KSEG1ADDR(0x14000300));
226 void *psp_env
= (void *)KSEG1ADDR(psbl
->env_base
);
228 if(strcmp(psp_env
, psp_env_version
) == 0) {
229 parse_psp_env(psp_env
);
231 for (i
= 0; i
< MAX_ENTRY
; i
++, env
++)
233 add_adam2_var(env
->name
, env
->value
);
237 static void __init
console_config(void)
239 #ifdef CONFIG_SERIAL_8250_CONSOLE
240 char console_string
[40];
242 char parity
= '\0', bits
= '\0', flow
= '\0';
245 if (strstr(prom_getcmdline(), "console="))
249 if (!strstr(prom_getcmdline(), "nokgdb"))
251 strcat(prom_getcmdline(), " console=kgdb");
257 if ((s
= prom_getenv("modetty0"))) {
258 baud
= simple_strtoul(s
, &p
, 10);
261 if (*s
) parity
= *s
++;
265 if (*s
== 'h') flow
= 'r';
270 if (parity
!= 'n' && parity
!= 'o' && parity
!= 'e')
272 if (bits
!= '7' && bits
!= '8')
277 sprintf(console_string
, " console=ttyS0,%d%c%c%c", baud
,
279 strcat(prom_getcmdline(), console_string
);
283 void __init
prom_init(void)
285 ar7_init_cmdline(fw_arg0
, (char **)fw_arg1
);
286 ar7_init_env((struct env_var
*)fw_arg2
);
290 #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
291 static inline unsigned int serial_in(int offset
)
293 return readb((void *)PORT(offset
));
296 static inline void serial_out(int offset
, int value
)
298 writeb(value
, (void *)PORT(offset
));
301 char prom_getchar(void)
303 while (!(serial_in(UART_LSR
) & UART_LSR_DR
));
304 return serial_in(UART_RX
);
307 int prom_putchar(char c
)
309 while ((serial_in(UART_LSR
) & UART_LSR_TEMT
) == 0);
310 serial_out(UART_TX
, c
);
314 // from adm5120/prom.c
315 void prom_printf(char *fmt
, ...)
323 l
= vsprintf(buf
, fmt
, args
); /* hopefully i < sizeof(buf) */
328 for (p
= buf
; p
< buf_end
; p
++) {
329 /* Crude cr/nl handling is better than none */
337 int putDebugChar(char c
)
339 return prom_putchar(c
);
342 char getDebugChar(void)
344 return prom_getchar();
348 EXPORT_SYMBOL(prom_getenv
);