Move NAND driver from rb1xx to adm5120, rbmipsnand fixed by David Goodenough, thanks !
[openwrt/svn-archive/archive.git] / target / linux / rb1xx-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 #include <adm5120_info.h>
33
34 void setup_prom_printf(int);
35 void prom_printf(char *, ...);
36 void prom_meminit(void);
37
38 #define ADM5120_ENVC 1
39
40 char *adm5120_envp[2*ADM5120_ENVC] = {"memsize","0x001000000"};
41
42 #define READCSR(r) *(volatile unsigned long *)(0xB2600000+(r))
43 #define WRITECSR(r,v) *(volatile unsigned long *)(0xB2600000+(r)) = v
44
45 #define UART_DR_REG 0x00
46 #define UART_FR_REG 0x18
47 #define UART_TX_FIFO_FULL 0x20
48
49 int putPromChar(char c)
50 {
51 WRITECSR(UART_DR_REG, c);
52 while ( (READCSR(UART_FR_REG) & UART_TX_FIFO_FULL) );
53 return 0;
54 }
55
56 /*
57 * Ugly prom_printf used for debugging
58 */
59
60 void prom_printf(char *fmt, ...)
61 {
62 va_list args;
63 int l;
64 char *p, *buf_end;
65 char buf[1024];
66
67 va_start(args, fmt);
68 l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
69 va_end(args);
70
71 buf_end = buf + l;
72
73 for (p = buf; p < buf_end; p++) {
74 /* Crude cr/nl handling is better than none */
75 if (*p == '\n')
76 putPromChar('\r');
77 putPromChar(*p);
78 }
79 }
80
81 char *prom_getenv(char *envname)
82 {
83 int i, index=0;
84
85 i = strlen(envname);
86
87 printk(KERN_INFO "GETENV: envname is %s\n", envname);
88
89 while(index < (2*ADM5120_ENVC)) {
90 if(strncmp(envname, adm5120_envp[index], i) == 0) {
91 printk(KERN_INFO "GETENV: returning %s\n", adm5120_envp[index+1]);
92 return(adm5120_envp[index+1]);
93 }
94 index += 2;
95 }
96
97 printk(KERN_INFO "GETENV: not found.\n");
98 return(NULL);
99 }
100
101
102 /*
103 * initialize the prom module.
104 */
105 void __init prom_init(void)
106 {
107 /* you should these macros defined in include/asm/bootinfo.h */
108 mips_machgroup = MACH_GROUP_ADM_GW;
109 mips_machtype = MACH_ADM_GW_5120;
110
111 adm5120_info_init();
112
113 /* init command line, register a default kernel command line */
114 strcpy(&(arcs_cmdline[0]), "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
115
116 /* init memory map */
117 prom_meminit();
118 }