ip860.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * (C) Copyright 2000
  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 <commproc.h>
  25. #include <mpc8xx.h>
  26. /* ------------------------------------------------------------------------- */
  27. static long int dram_size (long int, long int *, long int);
  28. /* ------------------------------------------------------------------------- */
  29. #define _NOT_USED_ 0xFFFFFFFF
  30. const uint sdram_table[] = {
  31. /*
  32. * Single Read. (Offset 0 in UPMA RAM)
  33. */
  34. 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
  35. 0x1ff77c47, /* last */
  36. /*
  37. * SDRAM Initialization (offset 5 in UPMA RAM)
  38. *
  39. * This is no UPM entry point. The following definition uses
  40. * the remaining space to establish an initialization
  41. * sequence, which is executed by a RUN command.
  42. *
  43. */
  44. 0x1ff77c34, 0xefeabc34, 0x1fb57c35, /* last */
  45. /*
  46. * Burst Read. (Offset 8 in UPMA RAM)
  47. */
  48. 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
  49. 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, /* last */
  50. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  51. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  52. /*
  53. * Single Write. (Offset 18 in UPMA RAM)
  54. */
  55. 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, /* last */
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. /*
  58. * Burst Write. (Offset 20 in UPMA RAM)
  59. */
  60. 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  61. 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, /* last */
  62. _NOT_USED_,
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  65. /*
  66. * Refresh (Offset 30 in UPMA RAM)
  67. */
  68. 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  69. 0xfffffc84, 0xfffffc07, /* last */
  70. _NOT_USED_, _NOT_USED_,
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. /*
  73. * Exception. (Offset 3c in UPMA RAM)
  74. */
  75. 0x7ffffc07, /* last */
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. };
  78. /* ------------------------------------------------------------------------- */
  79. /*
  80. * Check Board Identity:
  81. *
  82. * Test ID string (IP860...)
  83. */
  84. int checkboard (void)
  85. {
  86. unsigned char *s, *e;
  87. unsigned char buf[64];
  88. int i;
  89. puts ("Board: ");
  90. i = getenv_r ("serial#", buf, sizeof (buf));
  91. s = (i > 0) ? buf : NULL;
  92. if (!s || strncmp (s, "IP860", 5)) {
  93. puts ("### No HW ID - assuming IP860");
  94. } else {
  95. for (e = s; *e; ++e) {
  96. if (*e == ' ')
  97. break;
  98. }
  99. for (; s < e; ++s) {
  100. putc (*s);
  101. }
  102. }
  103. putc ('\n');
  104. return (0);
  105. }
  106. /* ------------------------------------------------------------------------- */
  107. long int initdram (int board_type)
  108. {
  109. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  110. volatile memctl8xx_t *memctl = &immap->im_memctl;
  111. long int size;
  112. upmconfig (UPMA, (uint *) sdram_table,
  113. sizeof (sdram_table) / sizeof (uint));
  114. /*
  115. * Preliminary prescaler for refresh
  116. */
  117. memctl->memc_mptpr = 0x0400;
  118. memctl->memc_mar = 0x00000088;
  119. /*
  120. * Map controller banks 2 to the SDRAM address
  121. */
  122. memctl->memc_or2 = CFG_OR2;
  123. memctl->memc_br2 = CFG_BR2;
  124. /* IP860 boards have only one bank SDRAM */
  125. udelay (200);
  126. /* perform SDRAM initializsation sequence */
  127. memctl->memc_mamr = 0xC3804114;
  128. memctl->memc_mcr = 0x80004105; /* run precharge pattern from loc 5 */
  129. udelay (1);
  130. memctl->memc_mamr = 0xC3804118;
  131. memctl->memc_mcr = 0x80004130; /* run refresh pattern 8 times */
  132. udelay (1000);
  133. /*
  134. * Check SDRAM Memory Size
  135. */
  136. size = dram_size (CFG_MAMR, (ulong *) SDRAM_BASE, SDRAM_MAX_SIZE);
  137. udelay (1000);
  138. memctl->memc_or2 = ((-size) & 0xFFFF0000) | SDRAM_TIMING;
  139. memctl->memc_br2 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  140. udelay (10000);
  141. /*
  142. * Also, map other memory to correct position
  143. */
  144. #if (defined(CFG_OR1) && defined(CFG_BR1_PRELIM))
  145. memctl->memc_or1 = CFG_OR1;
  146. memctl->memc_br1 = CFG_BR1;
  147. #endif
  148. #if defined(CFG_OR3) && defined(CFG_BR3)
  149. memctl->memc_or3 = CFG_OR3;
  150. memctl->memc_br3 = CFG_BR3;
  151. #endif
  152. #if defined(CFG_OR4) && defined(CFG_BR4)
  153. memctl->memc_or4 = CFG_OR4;
  154. memctl->memc_br4 = CFG_BR4;
  155. #endif
  156. #if defined(CFG_OR5) && defined(CFG_BR5)
  157. memctl->memc_or5 = CFG_OR5;
  158. memctl->memc_br5 = CFG_BR5;
  159. #endif
  160. #if defined(CFG_OR6) && defined(CFG_BR6)
  161. memctl->memc_or6 = CFG_OR6;
  162. memctl->memc_br6 = CFG_BR6;
  163. #endif
  164. #if defined(CFG_OR7) && defined(CFG_BR7)
  165. memctl->memc_or7 = CFG_OR7;
  166. memctl->memc_br7 = CFG_BR7;
  167. #endif
  168. return (size);
  169. }
  170. /* ------------------------------------------------------------------------- */
  171. /*
  172. * Check memory range for valid RAM. A simple memory test determines
  173. * the actually available RAM size between addresses `base' and
  174. * `base + maxsize'. Some (not all) hardware errors are detected:
  175. * - short between address lines
  176. * - short between data lines
  177. */
  178. static long int dram_size (long int mamr_value, long int *base,
  179. long int maxsize)
  180. {
  181. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  182. volatile memctl8xx_t *memctl = &immap->im_memctl;
  183. volatile long int *addr;
  184. ulong cnt, val;
  185. ulong save[32]; /* to make test non-destructive */
  186. unsigned char i = 0;
  187. memctl->memc_mamr = mamr_value;
  188. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  189. addr = base + cnt; /* pointer arith! */
  190. save[i++] = *addr;
  191. *addr = ~cnt;
  192. }
  193. /* write 0 to base address */
  194. addr = base;
  195. save[i] = *addr;
  196. *addr = 0;
  197. /* check at base address */
  198. if ((val = *addr) != 0) {
  199. *addr = save[i];
  200. return (0);
  201. }
  202. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  203. addr = base + cnt; /* pointer arith! */
  204. val = *addr;
  205. *addr = save[--i];
  206. if (val != (~cnt)) {
  207. return (cnt * sizeof (long));
  208. }
  209. }
  210. return (maxsize);
  211. }
  212. /* ------------------------------------------------------------------------- */
  213. void reset_phy (void)
  214. {
  215. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  216. ulong mask = PB_ENET_RESET | PB_ENET_JABD;
  217. ulong reg;
  218. /* Make sure PHY is not in low-power mode */
  219. immr->im_cpm.cp_pbpar &= ~(mask); /* GPIO */
  220. immr->im_cpm.cp_pbodr &= ~(mask); /* active output */
  221. /* Set JABD low (no JABber Disable),
  222. * and RESET high (Reset PHY)
  223. */
  224. reg = immr->im_cpm.cp_pbdat;
  225. reg = (reg & ~PB_ENET_JABD) | PB_ENET_RESET;
  226. immr->im_cpm.cp_pbdat = reg;
  227. /* now drive outputs */
  228. immr->im_cpm.cp_pbdir |= mask; /* output */
  229. udelay (1000);
  230. /*
  231. * Release RESET signal
  232. */
  233. immr->im_cpm.cp_pbdat &= ~(PB_ENET_RESET);
  234. udelay (1000);
  235. }
  236. /* ------------------------------------------------------------------------- */