purple.c 6.1 KB

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