purple.c 6.0 KB

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