bsp.c 8.7 KB

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