purple.c 4.7 KB

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