RPXClassic.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * (C) Copyright 2001
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. * U-Boot port on RPXClassic LF (CLLF_BW31) board
  6. *
  7. * (C) Copyright 2000
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <i2c.h>
  30. #include <config.h>
  31. #include <mpc8xx.h>
  32. #include <net.h>
  33. /* ------------------------------------------------------------------------- */
  34. static long int dram_size (long int, long int *, long int);
  35. static unsigned char aschex_to_byte (unsigned char *cp);
  36. /* ------------------------------------------------------------------------- */
  37. #define _NOT_USED_ 0xFFFFCC25
  38. const uint sdram_table[] =
  39. {
  40. /*
  41. * Single Read. (Offset 00h in UPMA RAM)
  42. */
  43. 0xCFFFCC24, 0x0FFFCC04, 0X0CAFCC04, 0X03AFCC08,
  44. 0x3FBFCC27, /* last */
  45. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  46. /*
  47. * Burst Read. (Offset 08h in UPMA RAM)
  48. */
  49. 0xCFFFCC24, 0x0FFFCC04, 0x0CAFCC84, 0x03AFCC88,
  50. 0x3FBFCC27, /* last */
  51. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  52. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  53. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  54. /*
  55. * Single Write. (Offset 18h in UPMA RAM)
  56. */
  57. 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC04, 0x03FFCC00,
  58. 0x3FFFCC27, /* last */
  59. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  60. /*
  61. * Burst Write. (Offset 20h in UPMA RAM)
  62. */
  63. 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC80, 0x03FFCC8C,
  64. 0x0CFFCC00, 0x33FFCC27, /* last */
  65. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  66. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  67. _NOT_USED_, _NOT_USED_,
  68. /*
  69. * Refresh. (Offset 30h in UPMA RAM)
  70. */
  71. 0xC0FFCC24, 0x03FFCC24, 0x0FFFCC24, 0x0FFFCC24,
  72. 0x3FFFCC27, /* last */
  73. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  74. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  75. /*
  76. * Exception. (Offset 3Ch in UPMA RAM)
  77. */
  78. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_
  79. };
  80. /* ------------------------------------------------------------------------- */
  81. /*
  82. * Check Board Identity:
  83. */
  84. int checkboard (void)
  85. {
  86. puts ("Board: RPXClassic\n");
  87. return (0);
  88. }
  89. /*-----------------------------------------------------------------------------
  90. * board_get_enetaddr -- Read the MAC Address in the I2C EEPROM
  91. *-----------------------------------------------------------------------------
  92. */
  93. static void board_get_enetaddr(uchar *enet)
  94. {
  95. int i;
  96. char buff[256], *cp;
  97. /* Initialize I2C */
  98. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  99. /* Read 256 bytes in EEPROM */
  100. i2c_read (0x54, 0, 1, (uchar *)buff, 128);
  101. i2c_read (0x54, 128, 1, (uchar *)buff + 128, 128);
  102. /* Retrieve MAC address in buffer (key EA) */
  103. for (cp = buff;;) {
  104. if (cp[0] == 'E' && cp[1] == 'A') {
  105. cp += 3;
  106. /* Read MAC address */
  107. for (i = 0; i < 6; i++, cp += 2) {
  108. enet[i] = aschex_to_byte ((unsigned char *)cp);
  109. }
  110. }
  111. /* Scan to the end of the record */
  112. while ((*cp != '\n') && (*cp != (char)0xff)) {
  113. cp++;
  114. }
  115. /* If the next character is a \n, 0 or ff, we are done. */
  116. cp++;
  117. if ((*cp == '\n') || (*cp == 0) || (*cp == (char)0xff))
  118. break;
  119. }
  120. #ifdef CONFIG_FEC_ENET
  121. /* The MAC address is the same as normal ethernet except the 3rd byte */
  122. /* (See the E.P. Planet Core Overview manual */
  123. enet[3] |= 0x80;
  124. #endif
  125. printf("MAC address = %pM\n", enet);
  126. }
  127. int misc_init_r(void)
  128. {
  129. uchar enetaddr[6];
  130. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  131. board_get_enetaddr(enetaddr);
  132. eth_setenv_enetaddr("ethaddr", enetaddr);
  133. }
  134. return 0;
  135. }
  136. void rpxclassic_init (void)
  137. {
  138. /* Enable NVRAM */
  139. *((uchar *) BCSR0) |= BCSR0_ENNVRAM;
  140. #ifdef CONFIG_FEC_ENET
  141. /* Validate the fast ethernet tranceiver */
  142. *((volatile uchar *) BCSR2) &= ~BCSR2_MIICTL;
  143. *((volatile uchar *) BCSR2) &= ~BCSR2_MIIPWRDWN;
  144. *((volatile uchar *) BCSR2) |= BCSR2_MIIRST;
  145. *((volatile uchar *) BCSR2) |= BCSR2_MIIPWRDWN;
  146. #endif
  147. }
  148. /* ------------------------------------------------------------------------- */
  149. phys_size_t initdram (int board_type)
  150. {
  151. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  152. volatile memctl8xx_t *memctl = &immap->im_memctl;
  153. long int size10;
  154. upmconfig (UPMA, (uint *) sdram_table,
  155. sizeof (sdram_table) / sizeof (uint));
  156. /* Refresh clock prescalar */
  157. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  158. memctl->memc_mar = 0x00000000;
  159. /* Map controller banks 1 to the SDRAM bank */
  160. memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
  161. memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
  162. memctl->memc_mamr = CONFIG_SYS_MAMR_10COL & (~(MAMR_PTAE)); /* no refresh yet */
  163. udelay (200);
  164. /* perform SDRAM initializsation sequence */
  165. memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - refresh twice */
  166. udelay (1);
  167. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  168. udelay (1000);
  169. /* Check Bank 0 Memory Size
  170. * try 10 column mode
  171. */
  172. size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE_PRELIM,
  173. SDRAM_MAX_SIZE);
  174. return (size10);
  175. }
  176. /* ------------------------------------------------------------------------- */
  177. /*
  178. * Check memory range for valid RAM. A simple memory test determines
  179. * the actually available RAM size between addresses `base' and
  180. * `base + maxsize'. Some (not all) hardware errors are detected:
  181. * - short between address lines
  182. * - short between data lines
  183. */
  184. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  185. {
  186. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  187. volatile memctl8xx_t *memctl = &immap->im_memctl;
  188. memctl->memc_mamr = mamr_value;
  189. return (get_ram_size(base, maxsize));
  190. }
  191. /*-----------------------------------------------------------------------------
  192. * aschex_to_byte --
  193. *-----------------------------------------------------------------------------
  194. */
  195. static unsigned char aschex_to_byte (unsigned char *cp)
  196. {
  197. u_char byte, c;
  198. c = *cp++;
  199. if ((c >= 'A') && (c <= 'F')) {
  200. c -= 'A';
  201. c += 10;
  202. } else if ((c >= 'a') && (c <= 'f')) {
  203. c -= 'a';
  204. c += 10;
  205. } else {
  206. c -= '0';
  207. }
  208. byte = c * 16;
  209. c = *cp;
  210. if ((c >= 'A') && (c <= 'F')) {
  211. c -= 'A';
  212. c += 10;
  213. } else if ((c >= 'a') && (c <= 'f')) {
  214. c -= 'a';
  215. c += 10;
  216. } else {
  217. c -= '0';
  218. }
  219. byte += c;
  220. return (byte);
  221. }