2007-03-19 19:34:37 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Carsten Langgaard, carstenl@mips.com
|
|
|
|
* Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2003 ADMtek Incorporated.
|
|
|
|
* daniell@admtek.com.tw
|
2007-04-16 12:55:30 +03:00
|
|
|
* Copyright (C) 2007 OpenWrt.org
|
2007-03-19 19:34:37 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can distribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License (Version 2) as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/autoconf.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
|
|
|
|
#include <asm/bootinfo.h>
|
|
|
|
#include <asm/addrspace.h>
|
|
|
|
|
2007-04-16 12:55:30 +03:00
|
|
|
#include <asm/mach-adm5120/adm5120_info.h>
|
2007-03-23 00:43:11 +02:00
|
|
|
|
2007-06-26 22:41:00 +03:00
|
|
|
static char **prom_envp = NULL;
|
2007-06-25 14:12:51 +03:00
|
|
|
|
2007-03-19 19:34:37 +02:00
|
|
|
void setup_prom_printf(int);
|
|
|
|
void prom_printf(char *, ...);
|
|
|
|
void prom_meminit(void);
|
|
|
|
|
|
|
|
|
|
|
|
#define READCSR(r) *(volatile unsigned long *)(0xB2600000+(r))
|
|
|
|
#define WRITECSR(r,v) *(volatile unsigned long *)(0xB2600000+(r)) = v
|
|
|
|
|
|
|
|
#define UART_DR_REG 0x00
|
|
|
|
#define UART_FR_REG 0x18
|
|
|
|
#define UART_TX_FIFO_FULL 0x20
|
|
|
|
|
|
|
|
int putPromChar(char c)
|
|
|
|
{
|
|
|
|
WRITECSR(UART_DR_REG, c);
|
|
|
|
while ( (READCSR(UART_FR_REG) & UART_TX_FIFO_FULL) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ugly prom_printf used for debugging
|
|
|
|
*/
|
|
|
|
|
|
|
|
void prom_printf(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int l;
|
|
|
|
char *p, *buf_end;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
buf_end = buf + l;
|
|
|
|
|
|
|
|
for (p = buf; p < buf_end; p++) {
|
|
|
|
/* Crude cr/nl handling is better than none */
|
|
|
|
if (*p == '\n')
|
|
|
|
putPromChar('\r');
|
|
|
|
putPromChar(*p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *prom_getenv(char *envname)
|
|
|
|
{
|
2007-06-25 14:12:51 +03:00
|
|
|
char **env;
|
|
|
|
char *ret;
|
2007-03-19 19:34:37 +02:00
|
|
|
|
2007-06-25 14:12:51 +03:00
|
|
|
ret = NULL;
|
2007-03-19 19:34:37 +02:00
|
|
|
|
2007-06-25 14:12:51 +03:00
|
|
|
if (prom_envp== NULL)
|
|
|
|
return NULL;
|
2007-03-19 19:34:37 +02:00
|
|
|
|
2007-06-25 14:12:51 +03:00
|
|
|
for (env = prom_envp; *env != NULL; env++) {
|
|
|
|
if (strcmp(envname, *env++) == 0) {
|
|
|
|
ret = *env;
|
|
|
|
break;
|
2007-03-19 19:34:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-25 14:12:51 +03:00
|
|
|
return ret;
|
2007-03-19 19:34:37 +02:00
|
|
|
}
|
2007-03-26 10:37:31 +03:00
|
|
|
|
2007-05-30 13:32:32 +03:00
|
|
|
extern char _image_cmdline;
|
2007-03-19 19:34:37 +02:00
|
|
|
/*
|
|
|
|
* initialize the prom module.
|
|
|
|
*/
|
|
|
|
void __init prom_init(void)
|
|
|
|
{
|
2007-05-30 13:32:32 +03:00
|
|
|
char *cmd;
|
|
|
|
|
2007-06-26 22:41:00 +03:00
|
|
|
if ((fw_arg2 & 3) == 0) {
|
|
|
|
prom_envp = (char **)fw_arg2;
|
|
|
|
}
|
2007-06-25 14:12:51 +03:00
|
|
|
|
2007-03-26 10:37:31 +03:00
|
|
|
adm5120_info_init();
|
2007-03-19 19:34:37 +02:00
|
|
|
|
2007-04-16 12:55:30 +03:00
|
|
|
/* you should these macros defined in include/asm/bootinfo.h */
|
|
|
|
mips_machgroup = MACH_GROUP_ADM5120;
|
|
|
|
mips_machtype = adm5120_board.mach_type;
|
|
|
|
|
2007-03-19 19:34:37 +02:00
|
|
|
/* init command line, register a default kernel command line */
|
2007-05-30 13:32:32 +03:00
|
|
|
cmd = &_image_cmdline + 8;
|
|
|
|
if( strlen(cmd) > 0) strcpy( &(arcs_cmdline[0]), cmd);
|
|
|
|
else strcpy(&(arcs_cmdline[0]), CONFIG_CMDLINE);
|
2007-03-19 19:34:37 +02:00
|
|
|
|
|
|
|
/* init memory map */
|
|
|
|
prom_meminit();
|
|
|
|
}
|