]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/purple/purple.c
293cc560e1904bf8ef7f5734ec4af7cd99c1995d
[karo-tx-uboot.git] / board / purple / purple.c
1 /*
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>
29 #include <asm/addrspace.h>
30 #include <asm/cacheops.h>
31
32 #include "sconsole.h"
33
34 #define cache_unroll(base,op)                   \
35         __asm__ __volatile__("                  \
36                 .set noreorder;                 \
37                 .set mips3;                     \
38                 cache %1, (%0);                 \
39                 .set mips0;                     \
40                 .set reorder"                   \
41                 :                               \
42                 : "r" (base),                   \
43                   "i" (op));
44
45 typedef void (*FUNCPTR)(ulong *source, ulong *destination, ulong nlongs);
46
47 extern void     asc_serial_init         (void);
48 extern void     asc_serial_putc         (char);
49 extern void     asc_serial_puts         (const char *);
50 extern int      asc_serial_getc         (void);
51 extern int      asc_serial_tstc         (void);
52 extern void     asc_serial_setbrg       (void);
53
54
55 long int initdram(int board_type)
56 {
57         /* The only supported number of SDRAM banks is 4.
58          */
59 #define CFG_NB  4
60
61         ulong   cfgpb0  = *INCA_IP_SDRAM_MC_CFGPB0;
62         ulong   cfgdw   = *INCA_IP_SDRAM_MC_CFGDW;
63         int     cols    = cfgpb0 & 0xF;
64         int     rows    = (cfgpb0 & 0xF0) >> 4;
65         int     dw      = cfgdw & 0xF;
66         ulong   size    = (1 << (rows + cols)) * (1 << (dw - 1)) * CFG_NB;
67
68         return size;
69 }
70
71 int checkboard (void)
72 {
73
74         unsigned long chipid = *(unsigned long *)0xB800C800;
75
76         printf ("Board: Purple PLB 2800 chip version %ld, ", chipid & 0xF);
77
78         printf("CPU Speed %d MHz\n", CPU_CLOCK_RATE/1000000);
79
80         return 0;
81 }
82
83 int misc_init_r (void)
84 {
85         asc_serial_init ();
86
87         sconsole_putc   = asc_serial_putc;
88         sconsole_puts   = asc_serial_puts;
89         sconsole_getc   = asc_serial_getc;
90         sconsole_tstc   = asc_serial_tstc;
91         sconsole_setbrg = asc_serial_setbrg;
92
93         sconsole_flush ();
94         return (0);
95 }
96
97 /*******************************************************************************
98 *
99 * copydwords - copy one buffer to another a long at a time
100 *
101 * This routine copies the first <nlongs> longs from <source> to <destination>.
102 */
103 static void copydwords (ulong *source, ulong *destination, ulong nlongs)
104 {
105         ulong temp,temp1;
106         ulong *dstend = destination + nlongs;
107
108         while (destination < dstend)
109         {
110                 temp = *source++;
111                 /* dummy read from sdram */
112                 temp1 = *(ulong *)0xa0000000;
113                 /* avoid optimization from compliler */
114                 *(ulong *)0xbf0081f8 = temp1 + temp;
115                 *destination++ = temp;
116
117         } 
118 }
119
120 /*******************************************************************************
121 *
122 * copyLongs - copy one buffer to another a long at a time
123 *
124 * This routine copies the first <nlongs> longs from <source> to <destination>.
125 */
126 static void copyLongs (ulong *source, ulong *destination, ulong nlongs)
127 {
128         FUNCPTR absEntry;
129
130         absEntry = (FUNCPTR)(0xbf008000+((ulong)copydwords & 0x7));
131         absEntry(source, destination, nlongs);
132 }
133
134 /*******************************************************************************
135 *
136 * programLoad - load program into ram
137 *
138 * This routine load copydwords into ram
139 *
140 */
141 static void programLoad(void)
142 {
143         FUNCPTR absEntry;
144         ulong *src,*dst;
145
146         src = (ulong *)(TEXT_BASE + 0x428);
147         dst = (ulong *)0xbf0081d0;
148
149         absEntry = (FUNCPTR)(TEXT_BASE + 0x400);   
150         absEntry(src,dst,0x6);          
151
152         src = (ulong *)((ulong)copydwords & 0xfffffff8);
153         dst = (ulong *)0xbf008000;
154
155         absEntry(src,dst,0x38);
156 }
157
158 /*******************************************************************************
159 *
160 * copy_code - copy u-boot image from flash to RAM
161 *
162 * This routine is needed to solve flash problems on this board
163 *
164 */
165 void copy_code (ulong dest_addr)
166 {
167         unsigned long start;
168         unsigned long end;
169
170         /* load copydwords into ram
171          */
172         programLoad();
173
174         /* copy u-boot code
175          */
176         copyLongs((ulong *)CFG_MONITOR_BASE,
177                   (ulong *)dest_addr,
178                   (CFG_MONITOR_LEN + 3) / 4);
179
180
181         /* flush caches
182          */
183
184         start = KSEG0;
185         end = start + CFG_DCACHE_SIZE;
186         while(start < end) {
187                 cache_unroll(start,Index_Writeback_Inv_D);
188                 start += CFG_CACHELINE_SIZE;
189         }
190
191         start = KSEG0;
192         end = start + CFG_ICACHE_SIZE;
193         while(start < end) {
194                 cache_unroll(start,Index_Invalidate_I);
195                 start += CFG_CACHELINE_SIZE;
196         }
197 }