blob: 4401aa21d5f834cc31640fdde4a3089fc2b00620 [file] [log] [blame]
wdenk60fbe252003-04-08 23:25:21 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <asm/inca-ip.h>
27#include <asm/regdef.h>
28#include <asm/mipsregs.h>
Jean-Christophe PLAGNIOL-VILLARD5c150102007-11-13 09:11:05 +010029#include <asm/io.h>
wdenk60fbe252003-04-08 23:25:21 +000030#include <asm/addrspace.h>
31#include <asm/cacheops.h>
Shinya Kuribayashib0c66af2008-03-25 21:30:07 +090032#include <asm/reboot.h>
wdenk60fbe252003-04-08 23:25:21 +000033
34#include "sconsole.h"
35
Wolfgang Denk53677ef2008-05-20 16:00:29 +020036#define cache_unroll(base,op) \
37 __asm__ __volatile__(" \
38 .set noreorder; \
39 .set mips3; \
40 cache %1, (%0); \
41 .set mips0; \
42 .set reorder" \
43 : \
44 : "r" (base), \
wdenk60fbe252003-04-08 23:25:21 +000045 "i" (op));
46
47typedef void (*FUNCPTR)(ulong *source, ulong *destination, ulong nlongs);
48
49extern void asc_serial_init (void);
Wolfgang Denk53677ef2008-05-20 16:00:29 +020050extern void asc_serial_putc (char);
51extern void asc_serial_puts (const char *);
52extern int asc_serial_getc (void);
53extern int asc_serial_tstc (void);
54extern void asc_serial_setbrg (void);
wdenk60fbe252003-04-08 23:25:21 +000055
Shinya Kuribayashib0c66af2008-03-25 21:30:07 +090056void _machine_restart(void)
57{
58 void (*f)(void) = (void *) 0xbfc00000;
59
60 f();
61}
62
wdenk86d82762003-05-20 10:39:44 +000063static void sdram_timing_init (ulong size)
64{
65 register uint pass;
66 register uint done;
67 register uint count;
68 register uint p0, p1, p2, p3, p4;
69 register uint addr;
70
71#define WRITE_MC_IOGP_1 *(uint *)0xbf800800 = (p1<<14)+(p2<<13)+(p4<<8)+(p0<<4)+p3;
72#define WRITE_MC_IOGP_2 *(uint *)0xbf800800 = (p1<<14)+(p2<<13)+((p4-16)<<8)+(p0<<4)+p3;
73
74 done = 0;
75 p0 = 2;
76 while (p0 < 4 && done == 0) {
77 p1 = 0;
78 while (p1 < 2 && done == 0) {
79 p2 = 0;
80 while (p2 < 2 && done == 0) {
81 p3 = 0;
82 while (p3 < 16 && done == 0) {
83 count = 0;
84 p4 = 0;
85 while (p4 < 32 && done == 0) {
86 WRITE_MC_IOGP_1;
87
88 for (addr = KSEG1 + 0x4000;
89 addr < KSEG1ADDR (size);
90 addr = addr + 4) {
91 *(uint *) addr = 0xaa55aa55;
92 }
93
94 pass = 1;
95
96 for (addr = KSEG1 + 0x4000;
97 addr < KSEG1ADDR (size) && pass == 1;
98 addr = addr + 4) {
99 if (*(uint *) addr != 0xaa55aa55)
100 pass = 0;
101 }
102
103 if (pass == 1) {
104 count++;
105 } else {
106 count = 0;
107 }
108
109 if (count == 32) {
110 WRITE_MC_IOGP_2;
111 done = 1;
112 }
113 p4++;
114 }
115 p3++;
116 }
117 p2++;
118 }
119 p1++;
120 }
121 p0++;
122 if (p0 == 1)
123 p0++;
124 }
125}
wdenk60fbe252003-04-08 23:25:21 +0000126
127long int initdram(int board_type)
128{
129 /* The only supported number of SDRAM banks is 4.
130 */
131#define CFG_NB 4
132
133 ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0;
134 ulong cfgdw = *INCA_IP_SDRAM_MC_CFGDW;
135 int cols = cfgpb0 & 0xF;
136 int rows = (cfgpb0 & 0xF0) >> 4;
137 int dw = cfgdw & 0xF;
138 ulong size = (1 << (rows + cols)) * (1 << (dw - 1)) * CFG_NB;
wdenk86d82762003-05-20 10:39:44 +0000139 void (* sdram_init) (ulong);
140
141 sdram_init = (void (*)(ulong)) KSEG0ADDR(&sdram_timing_init);
142
143 sdram_init(0x10000);
wdenk60fbe252003-04-08 23:25:21 +0000144
145 return size;
146}
147
148int checkboard (void)
149{
150
151 unsigned long chipid = *(unsigned long *)0xB800C800;
152
153 printf ("Board: Purple PLB 2800 chip version %ld, ", chipid & 0xF);
154
155 printf("CPU Speed %d MHz\n", CPU_CLOCK_RATE/1000000);
156
Jean-Christophe PLAGNIOL-VILLARD5c150102007-11-13 09:11:05 +0100157 set_io_port_base(0);
158
wdenk60fbe252003-04-08 23:25:21 +0000159 return 0;
160}
161
162int misc_init_r (void)
163{
164 asc_serial_init ();
165
166 sconsole_putc = asc_serial_putc;
167 sconsole_puts = asc_serial_puts;
168 sconsole_getc = asc_serial_getc;
169 sconsole_tstc = asc_serial_tstc;
170 sconsole_setbrg = asc_serial_setbrg;
171
172 sconsole_flush ();
173 return (0);
174}
175
176/*******************************************************************************
177*
178* copydwords - copy one buffer to another a long at a time
179*
180* This routine copies the first <nlongs> longs from <source> to <destination>.
181*/
182static void copydwords (ulong *source, ulong *destination, ulong nlongs)
183{
184 ulong temp,temp1;
185 ulong *dstend = destination + nlongs;
186
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200187 while (destination < dstend) {
wdenk60fbe252003-04-08 23:25:21 +0000188 temp = *source++;
189 /* dummy read from sdram */
190 temp1 = *(ulong *)0xa0000000;
191 /* avoid optimization from compliler */
192 *(ulong *)0xbf0081f8 = temp1 + temp;
193 *destination++ = temp;
194
wdenk8bde7f72003-06-27 21:31:46 +0000195 }
wdenk60fbe252003-04-08 23:25:21 +0000196}
197
198/*******************************************************************************
199*
200* copyLongs - copy one buffer to another a long at a time
201*
202* This routine copies the first <nlongs> longs from <source> to <destination>.
203*/
204static void copyLongs (ulong *source, ulong *destination, ulong nlongs)
205{
206 FUNCPTR absEntry;
207
208 absEntry = (FUNCPTR)(0xbf008000+((ulong)copydwords & 0x7));
209 absEntry(source, destination, nlongs);
210}
211
212/*******************************************************************************
213*
214* programLoad - load program into ram
215*
216* This routine load copydwords into ram
217*
218*/
219static void programLoad(void)
220{
221 FUNCPTR absEntry;
222 ulong *src,*dst;
223
224 src = (ulong *)(TEXT_BASE + 0x428);
225 dst = (ulong *)0xbf0081d0;
226
wdenk8bde7f72003-06-27 21:31:46 +0000227 absEntry = (FUNCPTR)(TEXT_BASE + 0x400);
228 absEntry(src,dst,0x6);
wdenk60fbe252003-04-08 23:25:21 +0000229
230 src = (ulong *)((ulong)copydwords & 0xfffffff8);
231 dst = (ulong *)0xbf008000;
232
233 absEntry(src,dst,0x38);
234}
235
236/*******************************************************************************
237*
238* copy_code - copy u-boot image from flash to RAM
239*
240* This routine is needed to solve flash problems on this board
241*
242*/
243void copy_code (ulong dest_addr)
244{
wdenk3b57fe02003-05-30 12:48:29 +0000245 extern long uboot_end_data;
wdenk60fbe252003-04-08 23:25:21 +0000246 unsigned long start;
247 unsigned long end;
248
249 /* load copydwords into ram
250 */
251 programLoad();
252
253 /* copy u-boot code
254 */
255 copyLongs((ulong *)CFG_MONITOR_BASE,
256 (ulong *)dest_addr,
wdenk3b57fe02003-05-30 12:48:29 +0000257 ((ulong)&uboot_end_data - CFG_MONITOR_BASE + 3) / 4);
wdenk60fbe252003-04-08 23:25:21 +0000258
259
260 /* flush caches
261 */
262
263 start = KSEG0;
264 end = start + CFG_DCACHE_SIZE;
265 while(start < end) {
266 cache_unroll(start,Index_Writeback_Inv_D);
267 start += CFG_CACHELINE_SIZE;
268 }
269
270 start = KSEG0;
271 end = start + CFG_ICACHE_SIZE;
272 while(start < end) {
273 cache_unroll(start,Index_Invalidate_I);
274 start += CFG_CACHELINE_SIZE;
275 }
276}