w7o.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * (C) Copyright 2001
  3. * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
  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 "w7o.h"
  26. #include <asm/processor.h>
  27. #include "vpd.h"
  28. #include "errors.h"
  29. #include <watchdog.h>
  30. unsigned long get_dram_size (void);
  31. /*
  32. * Macros to transform values
  33. * into environment strings.
  34. */
  35. #define XMK_STR(x) #x
  36. #define MK_STR(x) XMK_STR(x)
  37. /* ------------------------------------------------------------------------- */
  38. int board_early_init_f (void)
  39. {
  40. #if defined(CONFIG_W7OLMG)
  41. /*
  42. * Setup GPIO pins - reset devices.
  43. */
  44. out32 (PPC405GP_GPIO0_ODR, 0x10000000); /* one open drain pin */
  45. out32 (PPC405GP_GPIO0_OR, 0x3E000000); /* set output pins to default */
  46. out32 (PPC405GP_GPIO0_TCR, 0x7f800000); /* setup for output */
  47. /*
  48. * IRQ 0-15 405GP internally generated; active high; level sensitive
  49. * IRQ 16 405GP internally generated; active low; level sensitive
  50. * IRQ 17-24 RESERVED
  51. * IRQ 25 (EXT IRQ 0) XILINX; active low; level sensitive
  52. * IRQ 26 (EXT IRQ 1) PCI INT A; active low; level sensitive
  53. * IRQ 27 (EXT IRQ 2) PCI INT B; active low; level sensitive
  54. * IRQ 28 (EXT IRQ 3) SAM 2; active low; level sensitive
  55. * IRQ 29 (EXT IRQ 4) Battery Bad; active low; level sensitive
  56. * IRQ 30 (EXT IRQ 5) Level One PHY; active low; level sensitive
  57. * IRQ 31 (EXT IRQ 6) SAM 1; active high; level sensitive
  58. */
  59. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  60. mtdcr (uicer, 0x00000000); /* disable all ints */
  61. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  62. mtdcr (uicpr, 0xFFFFFF80); /* set int polarities */
  63. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  64. mtdcr (uicvcr, 0x00000001); /* set vect base=0,
  65. INT0 highest priority */
  66. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  67. #elif defined(CONFIG_W7OLMC)
  68. /*
  69. * Setup GPIO pins
  70. */
  71. out32 (PPC405GP_GPIO0_ODR, 0x01800000); /* XCV Done Open Drain */
  72. out32 (PPC405GP_GPIO0_OR, 0x03800000); /* set out pins to default */
  73. out32 (PPC405GP_GPIO0_TCR, 0x66C00000); /* setup for output */
  74. /*
  75. * IRQ 0-15 405GP internally generated; active high; level sensitive
  76. * IRQ 16 405GP internally generated; active low; level sensitive
  77. * IRQ 17-24 RESERVED
  78. * IRQ 25 (EXT IRQ 0) DBE 0; active low; level sensitive
  79. * IRQ 26 (EXT IRQ 1) DBE 1; active low; level sensitive
  80. * IRQ 27 (EXT IRQ 2) DBE 2; active low; level sensitive
  81. * IRQ 28 (EXT IRQ 3) DBE Common; active low; level sensitive
  82. * IRQ 29 (EXT IRQ 4) PCI; active low; level sensitive
  83. * IRQ 30 (EXT IRQ 5) RCMM Reset; active low; level sensitive
  84. * IRQ 31 (EXT IRQ 6) PHY; active high; level sensitive
  85. */
  86. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  87. mtdcr (uicer, 0x00000000); /* disable all ints */
  88. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  89. mtdcr (uicpr, 0xFFFFFF80); /* set int polarities */
  90. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  91. mtdcr (uicvcr, 0x00000001); /* set vect base=0,
  92. INT0 highest priority */
  93. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  94. #else /* Unknown */
  95. # error "Unknown W7O board configuration"
  96. #endif
  97. WATCHDOG_RESET (); /* Reset the watchdog */
  98. temp_uart_init (); /* init the uart for debug */
  99. WATCHDOG_RESET (); /* Reset the watchdog */
  100. test_led (); /* test the LEDs */
  101. test_sdram (get_dram_size ()); /* test the dram */
  102. log_stat (ERR_POST1); /* log status,post1 complete */
  103. return 0;
  104. }
  105. /* ------------------------------------------------------------------------- */
  106. /*
  107. * Check Board Identity:
  108. */
  109. int checkboard (void)
  110. {
  111. VPD vpd;
  112. puts ("Board: ");
  113. /* VPD data present in I2C EEPROM */
  114. if (vpd_get_data (CFG_DEF_EEPROM_ADDR, &vpd) == 0) {
  115. /*
  116. * Known board type.
  117. */
  118. if (vpd.productId[0] &&
  119. ((strncmp (vpd.productId, "GMM", 3) == 0) ||
  120. (strncmp (vpd.productId, "CMM", 3) == 0))) {
  121. /* Output board information on startup */
  122. printf ("\"%s\", revision '%c', serial# %ld, manufacturer %u\n", vpd.productId, vpd.revisionId, vpd.serialNum, vpd.manuID);
  123. return (0);
  124. }
  125. }
  126. puts ("### Unknown HW ID - assuming NOTHING\n");
  127. return (0);
  128. }
  129. /* ------------------------------------------------------------------------- */
  130. long int initdram (int board_type)
  131. {
  132. return get_dram_size ();
  133. }
  134. unsigned long get_dram_size (void)
  135. {
  136. int tmp, i, regs[4];
  137. int size = 0;
  138. /* Get bank Size registers */
  139. mtdcr (memcfga, mem_mb0cf); /* get bank 0 config reg */
  140. regs[0] = mfdcr (memcfgd);
  141. mtdcr (memcfga, mem_mb1cf); /* get bank 1 config reg */
  142. regs[1] = mfdcr (memcfgd);
  143. mtdcr (memcfga, mem_mb2cf); /* get bank 2 config reg */
  144. regs[2] = mfdcr (memcfgd);
  145. mtdcr (memcfga, mem_mb3cf); /* get bank 3 config reg */
  146. regs[3] = mfdcr (memcfgd);
  147. /* compute the size, add each bank if enabled */
  148. for (i = 0; i < 4; i++) {
  149. if (regs[i] & 0x0001) { /* if enabled, */
  150. tmp = ((regs[i] >> (31 - 14)) & 0x7); /* get size bits */
  151. tmp = 0x400000 << tmp; /* Size bits X 4MB = size */
  152. size += tmp;
  153. }
  154. }
  155. return size;
  156. }
  157. int misc_init_f (void)
  158. {
  159. return 0;
  160. }
  161. static void w7o_env_init (VPD * vpd)
  162. {
  163. /*
  164. * Read VPD
  165. */
  166. if (vpd_get_data (CFG_DEF_EEPROM_ADDR, vpd) != 0)
  167. return;
  168. /*
  169. * Known board type.
  170. */
  171. if (vpd->productId[0] &&
  172. ((strncmp (vpd->productId, "GMM", 3) == 0) ||
  173. (strncmp (vpd->productId, "CMM", 3) == 0))) {
  174. char buf[30];
  175. char *eth;
  176. unsigned char *serial = getenv ("serial#");
  177. unsigned char *ethaddr = getenv ("ethaddr");
  178. /* Set 'serial#' envvar if serial# isn't set */
  179. if (!serial) {
  180. sprintf (buf, "%s-%ld", vpd->productId,
  181. vpd->serialNum);
  182. setenv ("serial#", buf);
  183. }
  184. /* Set 'ethaddr' envvar if 'ethaddr' envvar is the default */
  185. eth = vpd->ethAddrs[0];
  186. if (ethaddr
  187. && (strcmp (ethaddr, MK_STR (CONFIG_ETHADDR)) == 0)) {
  188. /* Now setup ethaddr */
  189. sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  190. eth[0], eth[1], eth[2], eth[3], eth[4],
  191. eth[5]);
  192. setenv ("ethaddr", buf);
  193. }
  194. }
  195. } /* w7o_env_init() */
  196. int misc_init_r (void)
  197. {
  198. VPD vpd; /* VPD information */
  199. #if defined(CONFIG_W7OLMG)
  200. unsigned long greg; /* GPIO Register */
  201. greg = in32 (PPC405GP_GPIO0_OR);
  202. /*
  203. * XXX - Unreset devices - this should be moved into VxWorks driver code
  204. */
  205. greg |= 0x41800000L; /* SAM, PHY, Galileo */
  206. out32 (PPC405GP_GPIO0_OR, greg); /* set output pins to default */
  207. #endif /* CONFIG_W7OLMG */
  208. /*
  209. * Initialize W7O environment variables
  210. */
  211. w7o_env_init (&vpd);
  212. /*
  213. * Initialize the FPGA(s).
  214. */
  215. if (init_fpga () == 0)
  216. test_fpga ((unsigned short *) CONFIG_FPGAS_BASE);
  217. /* More POST testing. */
  218. post2 ();
  219. /* Done with hardware initialization and POST. */
  220. log_stat (ERR_POSTOK);
  221. /* Call silly, fail safe boot init routine */
  222. init_fsboot ();
  223. return (0);
  224. }