make selection of ASC for prom working
[openwrt/staging/wigyori.git] / target / linux / ifxmips / files / arch / mips / ifxmips / prom.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) 2005 Wu Qi Ming infineon
17 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
18 */
19
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/bootmem.h>
23 #include <asm/bootinfo.h>
24 #include <asm/ifxmips/ifxmips.h>
25
26 static char buf[1024]; /* for prom_printf() */
27
28 /* for voice cpu (MIPS24K) */
29 unsigned int *prom_cp1_base;
30 unsigned int prom_cp1_size;
31
32 /* for Multithreading (APRP) on MIPS34K */
33 unsigned long physical_memsize;
34
35 #ifdef CONFIG_IFXMIPS_PROM_ASC0
36 #define IFXMIPS_ASC_DIFF 0
37 #else
38 #define IFXMIPS_ASC_DIFF IFXMIPS_ASC_BASE_DIFF
39 #endif
40
41 static inline u32 asc_r32(unsigned long r)
42 {
43 return ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
44 }
45
46 static inline void asc_w32(u32 v, unsigned long r)
47 {
48 ifxmips_w32(v, (u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
49 }
50
51 void prom_free_prom_memory(void)
52 {
53 }
54
55 void prom_putchar(char c)
56 {
57 unsigned long flags;
58
59 local_irq_save(flags);
60 while ((asc_r32(IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF)
61 ;
62
63 if (c == '\n')
64 asc_w32('\r', IFXMIPS_ASC_TBUF);
65 asc_w32(c, IFXMIPS_ASC_TBUF);
66 local_irq_restore(flags);
67 }
68
69 void prom_printf(const char *fmt, ...)
70 {
71 va_list args;
72 int l;
73 char *p, *buf_end;
74
75 va_start(args, fmt);
76 l = vsprintf(buf, fmt, args);
77 va_end(args);
78 buf_end = buf + l;
79
80 for (p = buf; p < buf_end; p++)
81 prom_putchar(*p);
82 }
83
84 unsigned int *prom_get_cp1_base(void)
85 {
86 return prom_cp1_base;
87 }
88 EXPORT_SYMBOL(prom_get_cp1_base);
89
90 unsigned int prom_get_cp1_size(void)
91 {
92 /* return size im MB */
93 return prom_cp1_size>>20;
94 }
95 EXPORT_SYMBOL(prom_get_cp1_size);
96
97 void __init prom_init(void)
98 {
99 int argc = fw_arg0;
100 char **argv = (char **) fw_arg1;
101 char **envp = (char **) fw_arg2;
102
103 int memsize = 16; /* assume 16M as default */
104 int i;
105
106 mips_machtype = MACH_INFINEON_IFXMIPS;
107
108 if (argc) {
109 argv = (char **)KSEG1ADDR((unsigned long)argv);
110 arcs_cmdline[0] = '\0';
111 for (i = 1; i < argc; i++) {
112 char *a = (char *)KSEG1ADDR(argv[i]);
113 if (!argv[i])
114 continue;
115 /* for voice cpu on Twinpass/Danube */
116 if (cpu_data[0].cputype == CPU_24K)
117 if (!strncmp(a, "cp1_size=", 9)) {
118 prom_cp1_size = memparse(a + 9, &a);
119 continue;
120 }
121 if (strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline)) {
122 prom_printf("cmdline overflow, skipping: %s\n", a);
123 break;
124 }
125 strcat(arcs_cmdline, a);
126 strcat(arcs_cmdline, " ");
127 }
128 if (!*arcs_cmdline)
129 strcpy(&(arcs_cmdline[0]),
130 "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
131 }
132 envp = (char **)KSEG1ADDR((unsigned long)envp);
133 while (*envp) {
134 char *e = (char *)KSEG1ADDR(*envp);
135
136 if (!strncmp(e, "memsize=", 8)) {
137 e += 8;
138 memsize = simple_strtoul(e, NULL, 10);
139 }
140 envp++;
141 }
142 memsize *= 1024 * 1024;
143
144 /* only on Twinpass/Danube a second CPU is used for Voice */
145 if ((cpu_data[0].cputype == CPU_24K) && (prom_cp1_size)) {
146 memsize -= prom_cp1_size;
147 prom_cp1_base = (unsigned int *)KSEG1ADDR(memsize);
148
149 prom_printf("Using %dMB Ram and reserving %dMB for cp1\n",
150 memsize>>20, prom_cp1_size>>20);
151 }
152
153 add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
154 }