bsp.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. * hacked for Hymod FPGA support by Murray.Jensen@csiro.au, 29-Jan-01
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <net.h>
  28. #include <asm/iopin_8260.h>
  29. /*-----------------------------------------------------------------------
  30. * Board Special Commands: FPGA load/store, EEPROM erase
  31. */
  32. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  33. #define LOAD_SUCCESS 0
  34. #define LOAD_FAIL_NOCONF 1
  35. #define LOAD_FAIL_NOINIT 2
  36. #define LOAD_FAIL_NODONE 3
  37. #define STORE_SUCCESS 0
  38. /*
  39. * Programming the Hymod FPGAs
  40. *
  41. * The 8260 io port config table is set up so that the INIT pin is
  42. * held Low (Open Drain output 0) - this will delay the automatic
  43. * Power-On config until INIT is released (by making it an input).
  44. *
  45. * If the FPGA has been programmed before, then the assertion of PROGRAM
  46. * will initiate configuration (i.e. it begins clearing the RAM).
  47. *
  48. * When the FPGA is ready to receive configuration data (either after
  49. * releasing INIT after Power-On, or after asserting PROGRAM), it will
  50. * pull INIT high.
  51. *
  52. * Notes from Paul Dunn:
  53. *
  54. * 1. program pin should be forced low for >= 300ns
  55. * (about 20 bus clock cycles minimum).
  56. *
  57. * 2. then wait for init to go high, which signals
  58. * that the FPGA has cleared its internal memory
  59. * and is ready to load
  60. *
  61. * 3. perform load writes of entire config file
  62. *
  63. * 4. wait for done to go high, which should be
  64. * within a few bus clock cycles. If done has not
  65. * gone high after reasonable period, then load
  66. * has not worked (wait several ms?)
  67. */
  68. int
  69. fpga_load (int mezz, uchar *addr, ulong size)
  70. {
  71. DECLARE_GLOBAL_DATA_PTR;
  72. hymod_conf_t *cp = &gd->bd->bi_hymod_conf;
  73. xlx_info_t *fp;
  74. xlx_iopins_t *fpgaio;
  75. volatile uchar *fpgabase;
  76. volatile uint cnt;
  77. uchar *eaddr = addr + size;
  78. int result;
  79. if (mezz)
  80. fp = &cp->mezz.xlx[0];
  81. else
  82. fp = &cp->main.xlx[0];
  83. if (!fp->mmap.prog.exists)
  84. return (LOAD_FAIL_NOCONF);
  85. fpgabase = (uchar *)fp->mmap.prog.base;
  86. fpgaio = &fp->iopins;
  87. /* set enable HIGH if required */
  88. if (fpgaio->enable_pin.flag)
  89. iopin_set_high (&fpgaio->enable_pin);
  90. /* ensure INIT is released (set it to be an input) */
  91. iopin_set_in (&fpgaio->init_pin);
  92. /* toggle PROG Low then High (will already be Low after Power-On) */
  93. iopin_set_low (&fpgaio->prog_pin);
  94. udelay (1); /* minimum 300ns - 1usec should do it */
  95. iopin_set_high (&fpgaio->prog_pin);
  96. /* wait for INIT High */
  97. cnt = 0;
  98. while (!iopin_is_high (&fpgaio->init_pin))
  99. if (++cnt == 10000000) {
  100. result = LOAD_FAIL_NOINIT;
  101. goto done;
  102. }
  103. /* write configuration data */
  104. while (addr < eaddr)
  105. *fpgabase = *addr++;
  106. /* wait for DONE High */
  107. cnt = 0;
  108. while (!iopin_is_high (&fpgaio->done_pin))
  109. if (++cnt == 100000000) {
  110. result = LOAD_FAIL_NODONE;
  111. goto done;
  112. }
  113. /* success */
  114. result = LOAD_SUCCESS;
  115. done:
  116. if (fpgaio->enable_pin.flag)
  117. iopin_set_low (&fpgaio->enable_pin);
  118. return (result);
  119. }
  120. /* ------------------------------------------------------------------------- */
  121. int
  122. do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  123. {
  124. uchar *addr, *save_addr;
  125. ulong size;
  126. int mezz, arg, result;
  127. switch (argc) {
  128. case 0:
  129. case 1:
  130. break;
  131. case 2:
  132. if (strcmp (argv[1], "info") == 0) {
  133. printf ("\nHymod FPGA Info...\n");
  134. printf ("\t\t\t\tAddress\t\tSize\n");
  135. printf ("\tMain Configuration:\t0x%08x\t%d\n",
  136. FPGA_MAIN_CFG_BASE, FPGA_MAIN_CFG_SIZE);
  137. printf ("\tMain Register:\t\t0x%08x\t%d\n",
  138. FPGA_MAIN_REG_BASE, FPGA_MAIN_REG_SIZE);
  139. printf ("\tMain Port:\t\t0x%08x\t%d\n",
  140. FPGA_MAIN_PORT_BASE, FPGA_MAIN_PORT_SIZE);
  141. printf ("\tMezz Configuration:\t0x%08x\t%d\n",
  142. FPGA_MEZZ_CFG_BASE, FPGA_MEZZ_CFG_SIZE);
  143. return 0;
  144. }
  145. break;
  146. case 3:
  147. if (strcmp (argv[1], "store") == 0) {
  148. addr = (uchar *) simple_strtoul (argv[2], NULL, 16);
  149. save_addr = addr;
  150. #if 0
  151. /* fpga readback unimplemented */
  152. while (more readback data)
  153. *addr++ = *fpga;
  154. result = error ? STORE_FAIL_XXX : STORE_SUCCESS;
  155. #else
  156. result = STORE_SUCCESS;
  157. #endif
  158. if (result == STORE_SUCCESS) {
  159. printf ("SUCCEEDED (%d bytes)\n",
  160. addr - save_addr);
  161. return 0;
  162. } else
  163. printf ("FAILED (%d bytes)\n",
  164. addr - save_addr);
  165. return 1;
  166. }
  167. break;
  168. case 4:
  169. if (strcmp (argv[1], "tftp") == 0) {
  170. copy_filename (BootFile, argv[2], sizeof (BootFile));
  171. load_addr = simple_strtoul (argv[3], NULL, 16);
  172. NetBootFileXferSize = 0;
  173. if (NetLoop (TFTP) <= 0) {
  174. printf ("tftp transfer failed - aborting "
  175. "fgpa load\n");
  176. return 1;
  177. }
  178. if (NetBootFileXferSize == 0) {
  179. printf ("can't determine file size - "
  180. "aborting fpga load\n");
  181. return 1;
  182. }
  183. printf ("File transfer succeeded - "
  184. "beginning fpga load...");
  185. result = fpga_load (0, (uchar *) load_addr,
  186. NetBootFileXferSize);
  187. if (result == LOAD_SUCCESS) {
  188. printf ("SUCCEEDED\n");
  189. return 0;
  190. } else if (result == LOAD_FAIL_NOCONF)
  191. printf ("FAILED (no CONF)\n");
  192. else if (result == LOAD_FAIL_NOINIT)
  193. printf ("FAILED (no INIT)\n");
  194. else
  195. printf ("FAILED (no DONE)\n");
  196. return 1;
  197. }
  198. /* fall through ... */
  199. case 5:
  200. if (strcmp (argv[1], "load") == 0) {
  201. if (argc == 5) {
  202. if (strcmp (argv[2], "main") == 0)
  203. mezz = 0;
  204. else if (strcmp (argv[2], "mezz") == 0)
  205. mezz = 1;
  206. else {
  207. printf ("FPGA type must be either "
  208. "`main' or `mezz'\n");
  209. return 1;
  210. }
  211. arg = 3;
  212. } else {
  213. mezz = 0;
  214. arg = 2;
  215. }
  216. addr = (uchar *) simple_strtoul (argv[arg++], NULL, 16);
  217. size = (ulong) simple_strtoul (argv[arg], NULL, 16);
  218. result = fpga_load (mezz, addr, size);
  219. if (result == LOAD_SUCCESS) {
  220. printf ("SUCCEEDED\n");
  221. return 0;
  222. } else if (result == LOAD_FAIL_NOCONF)
  223. printf ("FAILED (no CONF)\n");
  224. else if (result == LOAD_FAIL_NOINIT)
  225. printf ("FAILED (no INIT)\n");
  226. else
  227. printf ("FAILED (no DONE)\n");
  228. return 1;
  229. }
  230. break;
  231. default:
  232. break;
  233. }
  234. printf ("Usage:\n%s\n", cmdtp->usage);
  235. return 1;
  236. }
  237. cmd_tbl_t U_BOOT_CMD(fpga) = MK_CMD_ENTRY(
  238. "fpga", 6, 1, do_fpga,
  239. "fpga - FPGA sub-system\n",
  240. "load [type] addr size\n"
  241. " - write the configuration data at memory address `addr',\n"
  242. " size `size' bytes, into the FPGA of type `type' (either\n"
  243. " `main' or `mezz', default `main'). e.g.\n"
  244. " `fpga load 100000 7d8f'\n"
  245. " loads the main FPGA with config data at address 100000\n"
  246. " HEX, size 7d8f HEX (32143 DEC) bytes\n"
  247. "fpga tftp file addr\n"
  248. " - transfers `file' from the tftp server into memory at\n"
  249. " address `addr', then writes the entire file contents\n"
  250. " into the main FPGA\n"
  251. "fpga store addr\n"
  252. " - read configuration data from the main FPGA (the mezz\n"
  253. " FPGA is write-only), into address `addr'. There must be\n"
  254. " enough memory available at `addr' to hold all the config\n"
  255. " data - the size of which is determined by VC:???\n"
  256. "fpga info\n"
  257. " - print information about the Hymod FPGA, namely the\n"
  258. " memory addresses at which the four FPGA local bus\n"
  259. " address spaces appear in the physical address space\n"
  260. );
  261. /* ------------------------------------------------------------------------- */
  262. int
  263. do_eecl (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  264. {
  265. uchar data[HYMOD_EEPROM_SIZE];
  266. uint addr = CFG_I2C_EEPROM_ADDR;
  267. switch (argc) {
  268. case 1:
  269. addr |= HYMOD_EEOFF_MAIN;
  270. break;
  271. case 2:
  272. if (strcmp (argv[1], "main") == 0) {
  273. addr |= HYMOD_EEOFF_MAIN;
  274. break;
  275. }
  276. if (strcmp (argv[1], "mezz") == 0) {
  277. addr |= HYMOD_EEOFF_MEZZ;
  278. break;
  279. }
  280. /* fall through ... */
  281. default:
  282. printf ("Usage:\n%s\n", cmdtp->usage);
  283. return 1;
  284. }
  285. memset (data, 0, HYMOD_EEPROM_SIZE);
  286. eeprom_write (addr, 0, data, HYMOD_EEPROM_SIZE);
  287. return 0;
  288. }
  289. cmd_tbl_t U_BOOT_CMD(eec) = MK_CMD_ENTRY(
  290. "eeclear", 1, 0, do_eecl,
  291. "eeclear - Clear the eeprom on a Hymod board \n",
  292. "[type]\n"
  293. " - write zeroes into the EEPROM on the board of type `type'\n"
  294. " (`type' is either `main' or `mezz' - default `main')\n"
  295. " Note: the EEPROM write enable jumper must be installed\n"
  296. );
  297. /* ------------------------------------------------------------------------- */
  298. int
  299. do_htest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  300. {
  301. #if 0
  302. int rc;
  303. #endif
  304. #ifdef CONFIG_ETHER_LOOPBACK_TEST
  305. extern void eth_loopback_test (void);
  306. #endif /* CONFIG_ETHER_LOOPBACK_TEST */
  307. printf ("HYMOD tests - ensure loopbacks etc. are connected\n\n");
  308. #if 0
  309. /* Load FPGA with test program */
  310. printf ("Loading test FPGA program ...");
  311. rc = fpga_load (0, test_bitfile, sizeof (test_bitfile));
  312. switch (rc) {
  313. case LOAD_SUCCESS:
  314. printf (" SUCCEEDED\n");
  315. break;
  316. case LOAD_FAIL_NOCONF:
  317. printf (" FAILED (no configuration space defined)\n");
  318. return 1;
  319. case LOAD_FAIL_NOINIT:
  320. printf (" FAILED (timeout - no INIT signal seen)\n");
  321. return 1;
  322. case LOAD_FAIL_NODONE:
  323. printf (" FAILED (timeout - no DONE signal seen)\n");
  324. return 1;
  325. default:
  326. printf (" FAILED (unknown return code from fpga_load\n");
  327. return 1;
  328. }
  329. /* run Local Bus <=> Xilinx tests */
  330. /* tell Xilinx to run ZBT Ram, High Speed serial and Mezzanine tests */
  331. /* run SDRAM test */
  332. #endif
  333. #ifdef CONFIG_ETHER_LOOPBACK_TEST
  334. /* run Ethernet test */
  335. eth_loopback_test ();
  336. #endif /* CONFIG_ETHER_LOOPBACK_TEST */
  337. return 0;
  338. }
  339. #endif /* CFG_CMD_BSP */
  340. /* ------------------------------------------------------------------------- */