w7o.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 "w7o.h"
  25. #include <asm/processor.h>
  26. #include "vpd.h"
  27. #include "errors.h"
  28. #include <watchdog.h>
  29. unsigned long get_dram_size(void);
  30. /*
  31. * Macros to transform values
  32. * into environment strings.
  33. */
  34. #define XMK_STR(x) #x
  35. #define MK_STR(x) XMK_STR(x)
  36. /* ------------------------------------------------------------------------- */
  37. int board_pre_init (void)
  38. {
  39. #if defined(CONFIG_W7OLMG)
  40. /*
  41. * Setup GPIO pins - reset devices.
  42. */
  43. out32(IBM405GP_GPIO0_ODR, 0x10000000); /* one open drain pin */
  44. out32(IBM405GP_GPIO0_OR, 0x3E000000); /* set output pins to default */
  45. out32(IBM405GP_GPIO0_TCR, 0x7f800000); /* setup for output */
  46. /*
  47. * IRQ 0-15 405GP internally generated; active high; level sensitive
  48. * IRQ 16 405GP internally generated; active low; level sensitive
  49. * IRQ 17-24 RESERVED
  50. * IRQ 25 (EXT IRQ 0) XILINX; active low; level sensitive
  51. * IRQ 26 (EXT IRQ 1) PCI INT A; active low; level sensitive
  52. * IRQ 27 (EXT IRQ 2) PCI INT B; active low; level sensitive
  53. * IRQ 28 (EXT IRQ 3) SAM 2; active low; level sensitive
  54. * IRQ 29 (EXT IRQ 4) Battery Bad; active low; level sensitive
  55. * IRQ 30 (EXT IRQ 5) Level One PHY; active low; level sensitive
  56. * IRQ 31 (EXT IRQ 6) SAM 1; active high; level sensitive
  57. */
  58. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  59. mtdcr(uicer, 0x00000000); /* disable all ints */
  60. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  61. mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
  62. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  63. mtdcr(uicvcr, 0x00000001); /* set vect base=0,
  64. INT0 highest priority*/
  65. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  66. #elif defined(CONFIG_W7OLMC)
  67. /*
  68. * Setup GPIO pins
  69. */
  70. out32(IBM405GP_GPIO0_ODR, 0x01800000); /* XCV Done Open Drain */
  71. out32(IBM405GP_GPIO0_OR, 0x03800000); /* set out pins to default */
  72. out32(IBM405GP_GPIO0_TCR, 0x66C00000); /* setup for output */
  73. /*
  74. * IRQ 0-15 405GP internally generated; active high; level sensitive
  75. * IRQ 16 405GP internally generated; active low; level sensitive
  76. * IRQ 17-24 RESERVED
  77. * IRQ 25 (EXT IRQ 0) DBE 0; active low; level sensitive
  78. * IRQ 26 (EXT IRQ 1) DBE 1; active low; level sensitive
  79. * IRQ 27 (EXT IRQ 2) DBE 2; active low; level sensitive
  80. * IRQ 28 (EXT IRQ 3) DBE Common; active low; level sensitive
  81. * IRQ 29 (EXT IRQ 4) PCI; active low; level sensitive
  82. * IRQ 30 (EXT IRQ 5) RCMM Reset; active low; level sensitive
  83. * IRQ 31 (EXT IRQ 6) PHY; active high; level sensitive
  84. */
  85. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  86. mtdcr(uicer, 0x00000000); /* disable all ints */
  87. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  88. mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
  89. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  90. mtdcr(uicvcr, 0x00000001); /* set vect base=0,
  91. INT0 highest priority*/
  92. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  93. #else /* Unknown */
  94. # error "Unknown W7O board configuration"
  95. #endif
  96. WATCHDOG_RESET(); /* Reset the watchdog */
  97. temp_uart_init(); /* init the uart for debug */
  98. WATCHDOG_RESET(); /* Reset the watchdog */
  99. test_led(); /* test the LEDs */
  100. test_sdram(get_dram_size()); /* test the dram */
  101. log_stat(ERR_POST1); /* log status,post1 complete */
  102. return 0;
  103. }
  104. /* ------------------------------------------------------------------------- */
  105. /*
  106. * Check Board Identity:
  107. */
  108. int checkboard (void)
  109. {
  110. VPD vpd;
  111. puts ("Board: ");
  112. /* VPD data present in I2C EEPROM */
  113. if (vpd_get_data(CFG_DEF_EEPROM_ADDR, &vpd) == 0) {
  114. /*
  115. * Known board type.
  116. */
  117. if (vpd.productId[0] &&
  118. ((strncmp(vpd.productId, "GMM", 3) == 0) ||
  119. (strncmp(vpd.productId, "CMM", 3) == 0))) {
  120. /* Output board information on startup */
  121. printf("\"%s\", revision '%c', serial# %ld, manufacturer %u\n",
  122. 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
  162. w7o_env_init(VPD *vpd)
  163. {
  164. /*
  165. * Read VPD
  166. */
  167. if (vpd_get_data(CFG_DEF_EEPROM_ADDR, vpd) != 0)
  168. return;
  169. /*
  170. * Known board type.
  171. */
  172. if (vpd->productId[0] &&
  173. ((strncmp(vpd->productId, "GMM", 3) == 0) ||
  174. (strncmp(vpd->productId, "CMM", 3) == 0))) {
  175. char buf[30];
  176. char *eth;
  177. unsigned char *serial = getenv("serial#");
  178. unsigned char *ethaddr = getenv("ethaddr");
  179. /* Set 'serial#' envvar if serial# isn't set */
  180. if (!serial) {
  181. sprintf(buf, "%s-%ld", vpd->productId, 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 && (strcmp(ethaddr, MK_STR(CONFIG_ETHADDR)) == 0)) {
  187. /* Now setup ethaddr */
  188. sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  189. eth[0], eth[1], eth[2], eth[3], eth[4], eth[5]);
  190. setenv("ethaddr", buf);
  191. }
  192. }
  193. } /* w7o_env_init() */
  194. int misc_init_r (void)
  195. {
  196. VPD vpd; /* VPD information */
  197. #if defined(CONFIG_W7OLMG)
  198. unsigned long greg; /* GPIO Register */
  199. greg = in32(IBM405GP_GPIO0_OR);
  200. /*
  201. * XXX - Unreset devices - this should be moved into VxWorks driver code
  202. */
  203. greg |= 0x41800000L; /* SAM, PHY, Galileo */
  204. out32(IBM405GP_GPIO0_OR, greg); /* set output pins to default */
  205. #endif /* CONFIG_W7OLMG */
  206. /*
  207. * Initialize W7O environment variables
  208. */
  209. w7o_env_init(&vpd);
  210. /*
  211. * Initialize the FPGA(s).
  212. */
  213. if (init_fpga() == 0)
  214. test_fpga((unsigned short *)CONFIG_FPGAS_BASE);
  215. /* More POST testing. */
  216. post2();
  217. /* Done with hardware initialization and POST. */
  218. log_stat(ERR_POSTOK);
  219. /* Call silly, fail safe boot init routine */
  220. init_fsboot();
  221. return (0);
  222. }