purple.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 <netdev.h>
  26. #include <asm/inca-ip.h>
  27. #include <asm/regdef.h>
  28. #include <asm/mipsregs.h>
  29. #include <asm/io.h>
  30. #include <asm/addrspace.h>
  31. #include <asm/cacheops.h>
  32. #include <asm/reboot.h>
  33. #include "sconsole.h"
  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. typedef void (*FUNCPTR)(ulong *source, ulong *destination, ulong nlongs);
  45. extern void asc_serial_init (void);
  46. extern void asc_serial_putc (char);
  47. extern void asc_serial_puts (const char *);
  48. extern int asc_serial_getc (void);
  49. extern int asc_serial_tstc (void);
  50. extern void asc_serial_setbrg (void);
  51. void _machine_restart(void)
  52. {
  53. void (*f)(void) = (void *) 0xbfc00000;
  54. f();
  55. }
  56. static void sdram_timing_init (ulong size)
  57. {
  58. register uint pass;
  59. register uint done;
  60. register uint count;
  61. register uint p0, p1, p2, p3, p4;
  62. register uint addr;
  63. #define WRITE_MC_IOGP_1 *(uint *)0xbf800800 = (p1<<14)+(p2<<13)+(p4<<8)+(p0<<4)+p3;
  64. #define WRITE_MC_IOGP_2 *(uint *)0xbf800800 = (p1<<14)+(p2<<13)+((p4-16)<<8)+(p0<<4)+p3;
  65. done = 0;
  66. p0 = 2;
  67. while (p0 < 4 && done == 0) {
  68. p1 = 0;
  69. while (p1 < 2 && done == 0) {
  70. p2 = 0;
  71. while (p2 < 2 && done == 0) {
  72. p3 = 0;
  73. while (p3 < 16 && done == 0) {
  74. count = 0;
  75. p4 = 0;
  76. while (p4 < 32 && done == 0) {
  77. WRITE_MC_IOGP_1;
  78. for (addr = CKSEG1 + 0x4000;
  79. addr < CKSEG1ADDR (size);
  80. addr = addr + 4) {
  81. *(uint *) addr = 0xaa55aa55;
  82. }
  83. pass = 1;
  84. for (addr = CKSEG1 + 0x4000;
  85. addr < CKSEG1ADDR (size) && pass == 1;
  86. addr = addr + 4) {
  87. if (*(uint *) addr != 0xaa55aa55)
  88. pass = 0;
  89. }
  90. if (pass == 1) {
  91. count++;
  92. } else {
  93. count = 0;
  94. }
  95. if (count == 32) {
  96. WRITE_MC_IOGP_2;
  97. done = 1;
  98. }
  99. p4++;
  100. }
  101. p3++;
  102. }
  103. p2++;
  104. }
  105. p1++;
  106. }
  107. p0++;
  108. if (p0 == 1)
  109. p0++;
  110. }
  111. }
  112. phys_size_t initdram(int board_type)
  113. {
  114. /* The only supported number of SDRAM banks is 4.
  115. */
  116. #define CFG_NB 4
  117. ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0;
  118. ulong cfgdw = *INCA_IP_SDRAM_MC_CFGDW;
  119. int cols = cfgpb0 & 0xF;
  120. int rows = (cfgpb0 & 0xF0) >> 4;
  121. int dw = cfgdw & 0xF;
  122. ulong size = (1 << (rows + cols)) * (1 << (dw - 1)) * CFG_NB;
  123. void (* sdram_init) (ulong);
  124. sdram_init = (void (*)(ulong)) CKSEG0ADDR(&sdram_timing_init);
  125. sdram_init(0x10000);
  126. return size;
  127. }
  128. int checkboard (void)
  129. {
  130. unsigned long chipid = *(unsigned long *)0xB800C800;
  131. printf ("Board: Purple PLB 2800 chip version %ld, ", chipid & 0xF);
  132. printf("CPU Speed %d MHz\n", CPU_CLOCK_RATE/1000000);
  133. set_io_port_base(0);
  134. return 0;
  135. }
  136. int misc_init_r (void)
  137. {
  138. asc_serial_init ();
  139. sconsole_putc = asc_serial_putc;
  140. sconsole_puts = asc_serial_puts;
  141. sconsole_getc = asc_serial_getc;
  142. sconsole_tstc = asc_serial_tstc;
  143. sconsole_setbrg = asc_serial_setbrg;
  144. sconsole_flush ();
  145. return (0);
  146. }
  147. /*******************************************************************************
  148. *
  149. * copydwords - copy one buffer to another a long at a time
  150. *
  151. * This routine copies the first <nlongs> longs from <source> to <destination>.
  152. */
  153. static void copydwords (ulong *source, ulong *destination, ulong nlongs)
  154. {
  155. ulong temp,temp1;
  156. ulong *dstend = destination + nlongs;
  157. while (destination < dstend) {
  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 = CKSEG0;
  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 = CKSEG0;
  226. end = start + CFG_ICACHE_SIZE;
  227. while(start < end) {
  228. cache_unroll(start,Index_Invalidate_I);
  229. start += CFG_CACHELINE_SIZE;
  230. }
  231. }
  232. #ifdef CONFIG_PLB2800_ETHER
  233. int board_eth_init(bd_t *bis)
  234. {
  235. return plb2800_eth_initialize(bis);
  236. }
  237. #endif