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>
30 #include <asm/bootinfo.h>
31 #include <asm/mips-boards/prom.h>
32 #include <asm/gdb-stub.h>
34 #include <asm/ar7/ar7.h>
48 /* I hate this. No. *I* *HATE* *THIS* */
49 static __initdata
struct psp_chip_map psp_chip_map
[] = {
51 .chip
= AR7_CHIP_7100
,
53 "dummy", "cpufrequency", "memsize",
54 "flashsize", "modetty0", "modetty1", "prompt",
55 "bootcfg", "maca", "macb", "usb_rndis_mac",
56 "macap", "my_ipaddress", "server_ipaddress",
57 "bline_maca", "bline_macb", "bline_rndis",
58 "bline_atm", "usb_pid", "usb_vid",
59 "usb_eppolli", "gateway_ipaddress",
60 "subnet_mask", "usb_serial", "usb_board_mac",
61 "remote_user", "remote_pass", "remote_dir",
62 "sysfrequency", "link_timeout", "mac_port",
63 "path", "hostname", "tftpcfg", "buildops",
64 "tftp_fo_fname", "tftp_fo_ports",
65 "console_state", "mipsfrequency",
69 .chip
= AR7_CHIP_7200
,
71 "dummy", "cpufrequency", "memsize",
72 "flashsize", "modetty0", "modetty1", "prompt",
73 "bootcfg", "maca", "macb", "usb_rndis_mac",
74 "macap", "my_ipaddress", "server_ipaddress",
75 "bline_maca", "bline_macb", "bline_rndis",
76 "bline_atm", "usb_pid", "usb_vid",
77 "usb_eppolli", "gateway_ipaddress",
78 "subnet_mask", "usb_serial", "usb_board_mac",
79 "remote_user", "remote_pass", "remote_dir",
80 "sysfrequency", "link_timeout", "mac_port",
81 "path", "hostname", "tftpcfg", "buildops",
82 "tftp_fo_fname", "tftp_fo_ports",
83 "console_state", "mipsfrequency",
87 .chip
= AR7_CHIP_7300
,
89 "dummy", "cpufrequency", "memsize",
90 "flashsize", "modetty0", "modetty1", "prompt",
91 "bootcfg", "maca", "macb", "usb_rndis_mac",
92 "macap", "my_ipaddress", "server_ipaddress",
93 "bline_maca", "bline_macb", "bline_rndis",
94 "bline_atm", "usb_pid", "usb_vid",
95 "usb_eppolli", "gateway_ipaddress",
96 "subnet_mask", "usb_serial", "usb_board_mac",
97 "remote_user", "remote_pass", "remote_dir",
98 "sysfrequency", "link_timeout", "mac_port",
99 "path", "hostname", "tftpcfg", "buildops",
100 "tftp_fo_fname", "tftp_fo_ports",
101 "console_state", "mipsfrequency",
109 static struct env_var adam2_env
[MAX_ENTRY
] = { { 0, }, };
111 char * prom_getenv(char *name
)
114 for (i
= 0; (i
< MAX_ENTRY
) && adam2_env
[i
].name
; i
++)
115 if (!strcmp(name
, adam2_env
[i
].name
))
116 return adam2_env
[i
].value
;
121 char * __init
prom_getcmdline(void)
123 return &(arcs_cmdline
[0]);
126 static void __init
ar7_init_cmdline(int argc
, char *argv
[])
131 actr
= 1; /* Always ignore argv[0] */
133 cp
= &(arcs_cmdline
[0]);
135 strcpy(cp
, argv
[actr
]);
136 cp
+= strlen(argv
[actr
]);
140 if (cp
!= &(arcs_cmdline
[0])) {
141 /* get rid of trailing space */
155 static __initdata
char psp_env_version
[] = "TIENV0.8";
162 unsigned char data
[11];
165 static char psp_env_data
[2048] = { 0, };
167 static void __init
add_adam2_var(char *name
, char *value
)
170 for (i
= 0; i
< MAX_ENTRY
; i
++) {
171 if (!adam2_env
[i
].name
) {
172 adam2_env
[i
].name
= name
;
173 adam2_env
[i
].value
= value
;
175 } else if (!strcmp(adam2_env
[i
].name
, name
)) {
176 adam2_env
[i
].value
= value
;
182 static int __init
parse_psp_env(void *start
)
186 struct psp_chip_map
*map
;
187 char *src
, *dest
, *name
, *value
;
188 struct psp_env_var
*vars
= start
;
190 chip
= ar7_chip_id();
191 for (map
= psp_chip_map
; map
->chip
; map
++)
192 if (map
->chip
== chip
)
201 while (vars
[i
].num
< 0xff) {
204 strcpy(dest
, map
->names
[vars
[i
].num
]);
209 src
+= strlen(src
) + 1;
211 dest
+= strlen(dest
) + 1;
214 dest
+= strlen(dest
) + 1;
215 add_adam2_var(name
, value
);
221 static void __init
ar7_init_env(struct env_var
*env
)
224 struct psbl_rec
*psbl
= (struct psbl_rec
*)(KSEG1ADDR(0x14000300));
225 void *psp_env
= (void *)KSEG1ADDR(psbl
->env_base
);
227 if(strcmp(psp_env
, psp_env_version
) == 0) {
228 parse_psp_env(psp_env
);
230 for (i
= 0; i
< MAX_ENTRY
; i
++, env
++)
232 add_adam2_var(env
->name
, env
->value
);
236 static void __init
console_config(void)
238 #ifdef CONFIG_SERIAL_8250_CONSOLE
239 char console_string
[40];
241 char parity
= '\0', bits
= '\0', flow
= '\0';
244 if (strstr(prom_getcmdline(), "console="))
248 strcat(prom_getcmdline(), " console=kgdb");
249 prom_printf("Please connect GDB to this port\n");
254 if ((s
= prom_getenv("modetty0"))) {
255 baud
= simple_strtoul(s
, &p
, 10);
258 if (*s
) parity
= *s
++;
262 if (*s
== 'h') flow
= 'r';
267 if (parity
!= 'n' && parity
!= 'o' && parity
!= 'e')
269 if (bits
!= '7' && bits
!= '8')
274 sprintf(console_string
, " console=ttyS0,%d%c%c%c", baud
,
276 strcat(prom_getcmdline(), console_string
);
280 void __init
prom_init(void)
282 prom_printf("\nLINUX running...\n");
283 ar7_init_cmdline(fw_arg0
, (char **)fw_arg1
);
284 ar7_init_env((struct env_var
*)fw_arg2
);
288 #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
289 static inline unsigned int serial_in(int offset
)
291 return readb((void *)PORT(offset
));
294 static inline void serial_out(int offset
, int value
)
296 writeb(value
, (void *)PORT(offset
));
299 char prom_getchar(void)
301 while (!(serial_in(UART_LSR
) & UART_LSR_DR
));
302 return serial_in(UART_RX
);
305 int prom_putchar(char c
)
307 while ((serial_in(UART_LSR
) & UART_LSR_TEMT
) == 0);
308 serial_out(UART_TX
, c
);
313 int putDebugChar(char c
)
315 return prom_putchar(c
);
318 char getDebugChar(void)
320 return prom_getchar();
324 EXPORT_SYMBOL(prom_getenv
);