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>
33 #include <asm/ar7/ar7.h>
47 /* I hate this. No. *I* *HATE* *THIS* */
48 static __initdata struct psp_chip_map psp_chip_map[] = {
52 "dummy", "cpufrequency", "memsize",
53 "flashsize", "modetty0", "modetty1", "prompt",
54 "bootcfg", "maca", "macb", "usb_rndis_mac",
55 "macap", "my_ipaddress", "server_ipaddress",
56 "bline_maca", "bline_macb", "bline_rndis",
57 "bline_atm", "usb_pid", "usb_vid",
58 "usb_eppolli", "gateway_ipaddress",
59 "subnet_mask", "usb_serial", "usb_board_mac",
60 "remote_user", "remote_pass", "remote_dir",
61 "sysfrequency", "link_timeout", "mac_port",
62 "path", "hostname", "tftpcfg", "buildops",
63 "tftp_fo_fname", "tftp_fo_ports",
64 "console_state", "mipsfrequency",
70 "dummy", "cpufrequency", "memsize",
71 "flashsize", "modetty0", "modetty1", "prompt",
72 "bootcfg", "maca", "macb", "usb_rndis_mac",
73 "macap", "my_ipaddress", "server_ipaddress",
74 "bline_maca", "bline_macb", "bline_rndis",
75 "bline_atm", "usb_pid", "usb_vid",
76 "usb_eppolli", "gateway_ipaddress",
77 "subnet_mask", "usb_serial", "usb_board_mac",
78 "remote_user", "remote_pass", "remote_dir",
79 "sysfrequency", "link_timeout", "mac_port",
80 "path", "hostname", "tftpcfg", "buildops",
81 "tftp_fo_fname", "tftp_fo_ports",
82 "console_state", "mipsfrequency",
88 "dummy", "cpufrequency", "memsize",
89 "flashsize", "modetty0", "modetty1", "prompt",
90 "bootcfg", "maca", "macb", "usb_rndis_mac",
91 "macap", "my_ipaddress", "server_ipaddress",
92 "bline_maca", "bline_macb", "bline_rndis",
93 "bline_atm", "usb_pid", "usb_vid",
94 "usb_eppolli", "gateway_ipaddress",
95 "subnet_mask", "usb_serial", "usb_board_mac",
96 "remote_user", "remote_pass", "remote_dir",
97 "sysfrequency", "link_timeout", "mac_port",
98 "path", "hostname", "tftpcfg", "buildops",
99 "tftp_fo_fname", "tftp_fo_ports",
100 "console_state", "mipsfrequency",
108 static struct env_var adam2_env[MAX_ENTRY] = { { 0, }, };
110 char * __init prom_getenv(char *name)
113 for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
114 if (!strcmp(name, adam2_env[i].name))
115 return adam2_env[i].value;
120 char * __init prom_getcmdline(void)
122 return &(arcs_cmdline[0]);
125 static void __init ar7_init_cmdline(int argc, char *argv[])
130 actr = 1; /* Always ignore argv[0] */
132 cp = &(arcs_cmdline[0]);
134 strcpy(cp, argv[actr]);
135 cp += strlen(argv[actr]);
139 if (cp != &(arcs_cmdline[0])) {
140 /* get rid of trailing space */
154 static __initdata char psp_env_version[] = "TIENV0.8";
161 unsigned char data[11];
164 static char psp_env_data[2048] = { 0, };
166 static void __init add_adam2_var(char *name, char *value)
169 for (i = 0; i < MAX_ENTRY; i++) {
170 if (!adam2_env[i].name) {
171 adam2_env[i].name = name;
172 adam2_env[i].value = value;
174 } else if (!strcmp(adam2_env[i].name, name)) {
175 adam2_env[i].value = value;
181 static int __init parse_psp_env(void *start)
185 struct psp_chip_map *map;
186 char *src, *dest, *name, *value;
187 struct psp_env_var *vars = start;
189 chip = get_chip_id();
190 for (map = psp_chip_map; map->chip; map++)
191 if (map->chip == chip)
200 while (vars[i].num < 0xff) {
203 strcpy(dest, map->names[vars[i].num]);
208 src += strlen(src) + 1;
210 dest += strlen(dest) + 1;
213 dest += strlen(dest) + 1;
214 add_adam2_var(name, value);
220 static void __init ar7_init_env(struct env_var *env)
223 struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
224 void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
226 if(strcmp(psp_env, psp_env_version) == 0) {
227 parse_psp_env(psp_env);
229 for (i = 0; i < MAX_ENTRY; i++, env++)
231 add_adam2_var(env->name, env->value);
235 void __init prom_init(void)
237 prom_printf("\nLINUX running...\n");
238 ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
239 ar7_init_env((struct env_var *)fw_arg2);
242 #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
243 static inline unsigned int serial_in(int offset)
245 return readb((void *)PORT(offset));
248 static inline void serial_out(int offset, int value)
250 writeb(value, (void *)PORT(offset));
253 char prom_getchar(void)
255 while (!(serial_in(UART_LSR) & UART_LSR_DR));
256 return serial_in(UART_RX);
259 int prom_putchar(char c)
261 while ((serial_in(UART_LSR) & UART_LSR_THRE) == 0);
262 serial_out(UART_TX, c);
266 EXPORT_SYMBOL(prom_getenv);