bsp.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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@cmst.csiro.au, 29-Jan-01
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <net.h>
  28. #include <i2c.h>
  29. #include <asm/iopin_8260.h>
  30. #include <cmd_bsp.h>
  31. /*-----------------------------------------------------------------------
  32. * Board Special Commands: FPGA load/store, EEPROM erase
  33. */
  34. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  35. #define LOAD_SUCCESS 0
  36. #define LOAD_FAIL_NOCONF 1
  37. #define LOAD_FAIL_NOINIT 2
  38. #define LOAD_FAIL_NODONE 3
  39. #define STORE_SUCCESS 0
  40. /*
  41. * Programming the Hymod FPGAs
  42. *
  43. * The 8260 io port config table is set up so that the INIT pin is
  44. * held Low (Open Drain output 0) - this will delay the automatic
  45. * Power-On config until INIT is released (by making it an input).
  46. *
  47. * If the FPGA has been programmed before, then the assertion of PROGRAM
  48. * will initiate configuration (i.e. it begins clearing the RAM).
  49. *
  50. * When the FPGA is ready to receive configuration data (either after
  51. * releasing INIT after Power-On, or after asserting PROGRAM), it will
  52. * pull INIT high.
  53. *
  54. * Notes from Paul Dunn:
  55. *
  56. * 1. program pin should be forced low for >= 300ns
  57. * (about 20 bus clock cycles minimum).
  58. *
  59. * 2. then wait for init to go high, which signals
  60. * that the FPGA has cleared its internal memory
  61. * and is ready to load
  62. *
  63. * 3. perform load writes of entire config file
  64. *
  65. * 4. wait for done to go high, which should be
  66. * within a few bus clock cycles. If done has not
  67. * gone high after reasonable period, then load
  68. * has not worked (wait several ms?)
  69. */
  70. int 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_iopins_t *fpgaio;
  75. volatile uchar *fpgabase;
  76. volatile uint cnt;
  77. uchar *eaddr = addr + size;
  78. int result;
  79. if (mezz) {
  80. if (!cp->mezz.mmap[0].prog.exists)
  81. return (LOAD_FAIL_NOCONF);
  82. fpgabase = (uchar *) cp->mezz.mmap[0].prog.base;
  83. fpgaio = &cp->mezz.iopins[0];
  84. } else {
  85. if (!cp->main.mmap[0].prog.exists)
  86. return (LOAD_FAIL_NOCONF);
  87. fpgabase = (uchar *) cp->main.mmap[0].prog.base;
  88. fpgaio = &cp->main.iopins[0];
  89. }
  90. /* set enable HIGH if required */
  91. if (fpgaio->enable_pin.flag)
  92. iopin_set_high (&fpgaio->enable_pin);
  93. /* ensure INIT is released (set it to be an input) */
  94. iopin_set_in (&fpgaio->init_pin);
  95. /* toggle PROG Low then High (will already be Low after Power-On) */
  96. iopin_set_low (&fpgaio->prog_pin);
  97. udelay (1); /* minimum 300ns - 1usec should do it */
  98. iopin_set_high (&fpgaio->prog_pin);
  99. /* wait for INIT High */
  100. cnt = 0;
  101. while (!iopin_is_high (&fpgaio->init_pin))
  102. if (++cnt == 10000000) {
  103. result = LOAD_FAIL_NOINIT;
  104. goto done;
  105. }
  106. /* write configuration data */
  107. while (addr < eaddr)
  108. *fpgabase = *addr++;
  109. /* wait for DONE High */
  110. cnt = 0;
  111. while (!iopin_is_high (&fpgaio->done_pin))
  112. if (++cnt == 100000000) {
  113. result = LOAD_FAIL_NODONE;
  114. goto done;
  115. }
  116. /* success */
  117. result = LOAD_SUCCESS;
  118. done:
  119. if (fpgaio->enable_pin.flag)
  120. iopin_set_low (&fpgaio->enable_pin);
  121. return (result);
  122. }
  123. /* ------------------------------------------------------------------------- */
  124. int
  125. do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  126. {
  127. uchar *addr, *save_addr;
  128. ulong size;
  129. int mezz, arg, result;
  130. switch (argc) {
  131. case 0:
  132. case 1:
  133. break;
  134. case 2:
  135. if (strcmp (argv[1], "info") == 0) {
  136. printf ("\nHymod FPGA Info...\n");
  137. printf (" Address Size\n");
  138. printf (" Main Configuration: 0x%08x %d\n",
  139. FPGA_MAIN_CFG_BASE, FPGA_MAIN_CFG_SIZE);
  140. printf (" Main Register: 0x%08x %d\n",
  141. FPGA_MAIN_REG_BASE, FPGA_MAIN_REG_SIZE);
  142. printf (" Main Port: 0x%08x %d\n",
  143. FPGA_MAIN_PORT_BASE, FPGA_MAIN_PORT_SIZE);
  144. printf (" Mezz Configuration: 0x%08x %d\n",
  145. FPGA_MEZZ_CFG_BASE, FPGA_MEZZ_CFG_SIZE);
  146. return 0;
  147. }
  148. break;
  149. case 3:
  150. if (strcmp (argv[1], "store") == 0) {
  151. addr = (uchar *) simple_strtoul (argv[2], NULL, 16);
  152. save_addr = addr;
  153. #if 0
  154. /* reading config data unimplemented */
  155. while VM
  156. :more config data * addr++ = *fpga;
  157. result = VM:? ? ?
  158. #else
  159. result = 0;
  160. #endif
  161. if (result == STORE_SUCCESS) {
  162. printf ("SUCCEEDED (%d bytes)\n", addr - save_addr);
  163. return 0;
  164. } else
  165. printf ("FAILED (%d bytes)\n", 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. if (NetLoop (TFTP) == 0) {
  174. printf ("tftp transfer failed - aborting fgpa load\n");
  175. return 1;
  176. }
  177. if (NetBootFileXferSize == 0) {
  178. printf ("can't determine file size - aborting fpga load\n");
  179. return 1;
  180. }
  181. printf ("File transfer succeeded - beginning fpga load...");
  182. result = fpga_load (0, (uchar *) load_addr,
  183. NetBootFileXferSize);
  184. if (result == LOAD_SUCCESS) {
  185. printf ("SUCCEEDED\n");
  186. return 0;
  187. } else if (result == LOAD_FAIL_NOINIT)
  188. printf ("FAILED (no INIT)\n");
  189. else
  190. printf ("FAILED (no DONE)\n");
  191. return 1;
  192. }
  193. /* fall through ... */
  194. case 5:
  195. if (strcmp (argv[1], "load") == 0) {
  196. if (argc == 5) {
  197. if (strcmp (argv[2], "main") == 0)
  198. mezz = 0;
  199. else if (strcmp (argv[2], "mezz") == 0)
  200. mezz = 1;
  201. else {
  202. printf ("FPGA type must be either `main' or `mezz'\n");
  203. return 1;
  204. }
  205. arg = 3;
  206. } else {
  207. mezz = 0;
  208. arg = 2;
  209. }
  210. addr = (uchar *) simple_strtoul (argv[arg++], NULL, 16);
  211. size = (ulong) simple_strtoul (argv[arg], NULL, 16);
  212. result = fpga_load (mezz, addr, size);
  213. if (result == LOAD_SUCCESS) {
  214. printf ("SUCCEEDED\n");
  215. return 0;
  216. } else if (result == LOAD_FAIL_NOINIT)
  217. printf ("FAILED (no INIT)\n");
  218. else
  219. printf ("FAILED (no DONE)\n");
  220. return 1;
  221. }
  222. break;
  223. default:
  224. break;
  225. }
  226. printf ("Usage:\n%s\n", cmdtp->usage);
  227. return 1;
  228. }
  229. /* ------------------------------------------------------------------------- */
  230. int
  231. do_eecl (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  232. {
  233. uchar data[HYMOD_EEPROM_SIZE];
  234. uint offset;
  235. int rcode = 0;
  236. switch (argc) {
  237. case 1:
  238. offset = HYMOD_EEOFF_MAIN;
  239. break;
  240. case 2:
  241. if (strcmp (argv[1], "main") == 0) {
  242. offset = HYMOD_EEOFF_MAIN;
  243. break;
  244. }
  245. if (strcmp (argv[1], "mezz") == 0) {
  246. offset = HYMOD_EEOFF_MEZZ;
  247. break;
  248. }
  249. /* fall through ... */
  250. default:
  251. printf ("Usage:\n%s\n", cmdtp->usage);
  252. return 1;
  253. }
  254. memset (data, 0, HYMOD_EEPROM_SIZE);
  255. if (i2c_write
  256. (CFG_I2C_EEPROM_ADDR | offset, 0, CFG_I2C_EEPROM_ADDR_LEN, data,
  257. HYMOD_EEPROM_SIZE)) {
  258. rcode = 1;
  259. }
  260. return rcode;
  261. }
  262. #endif /* CFG_CMD_BSP */
  263. /* ------------------------------------------------------------------------- */