Do not register more than 2 ethernet porst for CFE based devices (i.e : Compex WP54G...
[openwrt-10.03/.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / prom.c
1 /*****************************************************************************
2  * Carsten Langgaard, carstenl@mips.com
3  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
4  * Copyright (C) 2003 ADMtek Incorporated.
5  *      daniell@admtek.com.tw
6  *
7  *  This program is free software; you can distribute it and/or modify it
8  *  under the terms of the GNU General Public License (Version 2) as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope it will be useful, but WITHOUT
12  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  *  for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
19  *
20  *****************************************************************************/
21
22 #include <linux/init.h>
23 #include <linux/autoconf.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/mm.h>
27 #include <linux/bootmem.h>
28
29 #include <asm/bootinfo.h>
30 #include <asm/addrspace.h>
31
32 /* boot loaders specific definitions */
33 #define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */
34 #define CFE 1
35 #define UBOOT 2
36 #define MYLOADER 3
37 #define UNKNOWN 0
38
39 void setup_prom_printf(int);
40 void prom_printf(char *, ...);
41 void prom_meminit(void);
42
43 /* we assume we don't know the boot loader by default */
44 int boot_loader_type = UNKNOWN;
45
46 #define ADM5120_ENVC           1
47
48 char *adm5120_envp[2*ADM5120_ENVC] = {"memsize","0x001000000"};
49
50 #define READCSR(r)      *(volatile unsigned long *)(0xB2600000+(r))
51 #define WRITECSR(r,v)   *(volatile unsigned long *)(0xB2600000+(r)) = v
52
53 #define UART_DR_REG         0x00
54 #define UART_FR_REG         0x18
55 #define UART_TX_FIFO_FULL   0x20
56
57 int putPromChar(char c)
58 {
59         WRITECSR(UART_DR_REG, c);
60         while ( (READCSR(UART_FR_REG) & UART_TX_FIFO_FULL) );
61         return 0;
62 }
63
64 /*
65  * Ugly prom_printf used for debugging
66  */
67
68 void prom_printf(char *fmt, ...)
69 {
70         va_list args;
71         int l;
72         char *p, *buf_end;
73         char buf[1024];
74
75         va_start(args, fmt);
76         l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
77         va_end(args);
78
79         buf_end = buf + l;
80
81         for (p = buf; p < buf_end; p++) {
82                 /* Crude cr/nl handling is better than none */
83                 if (*p == '\n')
84                         putPromChar('\r');
85                 putPromChar(*p);
86         }
87 }
88
89 char *prom_getenv(char *envname)
90 {
91         int i, index=0;
92
93         i = strlen(envname);
94
95         printk(KERN_INFO "GETENV: envname is %s\n", envname);
96
97         while(index < (2*ADM5120_ENVC)) {
98                 if(strncmp(envname, adm5120_envp[index], i) == 0) {
99                         printk(KERN_INFO "GETENV: returning %s\n", adm5120_envp[index+1]);
100                         return(adm5120_envp[index+1]);
101                 }
102                 index += 2;
103         }
104
105         printk(KERN_INFO "GETENV: not found.\n");
106         return(NULL);
107 }
108         
109 /*
110  * initialize the prom module.
111  */
112 void __init prom_init(void)
113 {
114         /* you should these macros defined in include/asm/bootinfo.h */
115         mips_machgroup = MACH_GROUP_ADM_GW;
116         mips_machtype = MACH_ADM_GW_5120;
117
118         /* init command line, register a default kernel command line */
119         strcpy(&(arcs_cmdline[0]), "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
120
121         /* check for CFE by finding the CFE magic number */
122         int *prom_vec = (int *) fw_arg3;
123         int argc = fw_arg0;
124         unsigned int cfe_eptseal;
125
126         if (argc < 0)
127                 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
128         else {
129                 if ((int32_t)(long)prom_vec < 0)
130                          /*
131                           * Old loaders all it gives us is the handle,
132                           * so assume the seal.
133                           */
134                         cfe_eptseal = CFE_EPTSEAL;
135                 else
136                         /*
137                          * Newer loaders bundle the handle/ept/eptseal
138                          */
139                         cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
140         }
141         if (cfe_eptseal == CFE_EPTSEAL) {
142                 boot_loader_type = CFE;
143                 printk("adm5120 : CFE boot loader\n");
144         }
145
146         /* init memory map */
147         prom_meminit();
148 }