xilinx.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * (C) Copyright 2002
  3. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  4. * Keith Outwater, keith_outwater@mvis.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. */
  25. /*
  26. * Xilinx FPGA support
  27. */
  28. #include <common.h>
  29. #include <virtex2.h>
  30. #include <spartan2.h>
  31. #include <spartan3.h>
  32. #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
  33. #if 0
  34. #define FPGA_DEBUG
  35. #endif
  36. /* Define FPGA_DEBUG to get debug printf's */
  37. #ifdef FPGA_DEBUG
  38. #define PRINTF(fmt,args...) printf (fmt ,##args)
  39. #else
  40. #define PRINTF(fmt,args...)
  41. #endif
  42. /* Local Static Functions */
  43. static int xilinx_validate (Xilinx_desc * desc, char *fn);
  44. /* ------------------------------------------------------------------------- */
  45. int xilinx_load (Xilinx_desc * desc, void *buf, size_t bsize)
  46. {
  47. int ret_val = FPGA_FAIL; /* assume a failure */
  48. if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
  49. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  50. } else
  51. switch (desc->family) {
  52. case Xilinx_Spartan2:
  53. #if defined(CONFIG_FPGA_SPARTAN2)
  54. PRINTF ("%s: Launching the Spartan-II Loader...\n",
  55. __FUNCTION__);
  56. ret_val = Spartan2_load (desc, buf, bsize);
  57. #else
  58. printf ("%s: No support for Spartan-II devices.\n",
  59. __FUNCTION__);
  60. #endif
  61. break;
  62. case Xilinx_Spartan3:
  63. #if defined(CONFIG_FPGA_SPARTAN3)
  64. PRINTF ("%s: Launching the Spartan-III Loader...\n",
  65. __FUNCTION__);
  66. ret_val = Spartan3_load (desc, buf, bsize);
  67. #else
  68. printf ("%s: No support for Spartan-III devices.\n",
  69. __FUNCTION__);
  70. #endif
  71. break;
  72. case Xilinx_Virtex2:
  73. #if defined(CONFIG_FPGA_VIRTEX2)
  74. PRINTF ("%s: Launching the Virtex-II Loader...\n",
  75. __FUNCTION__);
  76. ret_val = Virtex2_load (desc, buf, bsize);
  77. #else
  78. printf ("%s: No support for Virtex-II devices.\n",
  79. __FUNCTION__);
  80. #endif
  81. break;
  82. default:
  83. printf ("%s: Unsupported family type, %d\n",
  84. __FUNCTION__, desc->family);
  85. }
  86. return ret_val;
  87. }
  88. int xilinx_dump (Xilinx_desc * desc, void *buf, size_t bsize)
  89. {
  90. int ret_val = FPGA_FAIL; /* assume a failure */
  91. if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
  92. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  93. } else
  94. switch (desc->family) {
  95. case Xilinx_Spartan2:
  96. #if defined(CONFIG_FPGA_SPARTAN2)
  97. PRINTF ("%s: Launching the Spartan-II Reader...\n",
  98. __FUNCTION__);
  99. ret_val = Spartan2_dump (desc, buf, bsize);
  100. #else
  101. printf ("%s: No support for Spartan-II devices.\n",
  102. __FUNCTION__);
  103. #endif
  104. break;
  105. case Xilinx_Spartan3:
  106. #if defined(CONFIG_FPGA_SPARTAN3)
  107. PRINTF ("%s: Launching the Spartan-III Reader...\n",
  108. __FUNCTION__);
  109. ret_val = Spartan3_dump (desc, buf, bsize);
  110. #else
  111. printf ("%s: No support for Spartan-III devices.\n",
  112. __FUNCTION__);
  113. #endif
  114. break;
  115. case Xilinx_Virtex2:
  116. #if defined( CONFIG_FPGA_VIRTEX2)
  117. PRINTF ("%s: Launching the Virtex-II Reader...\n",
  118. __FUNCTION__);
  119. ret_val = Virtex2_dump (desc, buf, bsize);
  120. #else
  121. printf ("%s: No support for Virtex-II devices.\n",
  122. __FUNCTION__);
  123. #endif
  124. break;
  125. default:
  126. printf ("%s: Unsupported family type, %d\n",
  127. __FUNCTION__, desc->family);
  128. }
  129. return ret_val;
  130. }
  131. int xilinx_info (Xilinx_desc * desc)
  132. {
  133. int ret_val = FPGA_FAIL;
  134. if (xilinx_validate (desc, (char *)__FUNCTION__)) {
  135. printf ("Family: \t");
  136. switch (desc->family) {
  137. case Xilinx_Spartan2:
  138. printf ("Spartan-II\n");
  139. break;
  140. case Xilinx_Spartan3:
  141. printf ("Spartan-III\n");
  142. break;
  143. case Xilinx_Virtex2:
  144. printf ("Virtex-II\n");
  145. break;
  146. /* Add new family types here */
  147. default:
  148. printf ("Unknown family type, %d\n", desc->family);
  149. }
  150. printf ("Interface type:\t");
  151. switch (desc->iface) {
  152. case slave_serial:
  153. printf ("Slave Serial\n");
  154. break;
  155. case master_serial: /* Not used */
  156. printf ("Master Serial\n");
  157. break;
  158. case slave_parallel:
  159. printf ("Slave Parallel\n");
  160. break;
  161. case jtag_mode: /* Not used */
  162. printf ("JTAG Mode\n");
  163. break;
  164. case slave_selectmap:
  165. printf ("Slave SelectMap Mode\n");
  166. break;
  167. case master_selectmap:
  168. printf ("Master SelectMap Mode\n");
  169. break;
  170. /* Add new interface types here */
  171. default:
  172. printf ("Unsupported interface type, %d\n", desc->iface);
  173. }
  174. printf ("Device Size: \t%d bytes\n"
  175. "Cookie: \t0x%x (%d)\n",
  176. desc->size, desc->cookie, desc->cookie);
  177. if (desc->iface_fns) {
  178. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  179. switch (desc->family) {
  180. case Xilinx_Spartan2:
  181. #if defined(CONFIG_FPGA_SPARTAN2)
  182. Spartan2_info (desc);
  183. #else
  184. /* just in case */
  185. printf ("%s: No support for Spartan-II devices.\n",
  186. __FUNCTION__);
  187. #endif
  188. break;
  189. case Xilinx_Spartan3:
  190. #if defined(CONFIG_FPGA_SPARTAN3)
  191. Spartan3_info (desc);
  192. #else
  193. /* just in case */
  194. printf ("%s: No support for Spartan-III devices.\n",
  195. __FUNCTION__);
  196. #endif
  197. break;
  198. case Xilinx_Virtex2:
  199. #if defined(CONFIG_FPGA_VIRTEX2)
  200. Virtex2_info (desc);
  201. #else
  202. /* just in case */
  203. printf ("%s: No support for Virtex-II devices.\n",
  204. __FUNCTION__);
  205. #endif
  206. break;
  207. /* Add new family types here */
  208. default:
  209. /* we don't need a message here - we give one up above */
  210. ;
  211. }
  212. } else
  213. printf ("No Device Function Table.\n");
  214. ret_val = FPGA_SUCCESS;
  215. } else {
  216. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  217. }
  218. return ret_val;
  219. }
  220. int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset)
  221. {
  222. int ret_val = FPGA_FAIL; /* assume a failure */
  223. if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
  224. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  225. } else
  226. switch (desc->family) {
  227. case Xilinx_Spartan2:
  228. #if defined(CONFIG_FPGA_SPARTAN2)
  229. ret_val = Spartan2_reloc (desc, reloc_offset);
  230. #else
  231. printf ("%s: No support for Spartan-II devices.\n",
  232. __FUNCTION__);
  233. #endif
  234. break;
  235. case Xilinx_Spartan3:
  236. #if defined(CONFIG_FPGA_SPARTAN3)
  237. ret_val = Spartan3_reloc (desc, reloc_offset);
  238. #else
  239. printf ("%s: No support for Spartan-III devices.\n",
  240. __FUNCTION__);
  241. #endif
  242. break;
  243. case Xilinx_Virtex2:
  244. #if defined(CONFIG_FPGA_VIRTEX2)
  245. ret_val = Virtex2_reloc (desc, reloc_offset);
  246. #else
  247. printf ("%s: No support for Virtex-II devices.\n",
  248. __FUNCTION__);
  249. #endif
  250. break;
  251. /* Add new family types here */
  252. default:
  253. printf ("%s: Unsupported family type, %d\n",
  254. __FUNCTION__, desc->family);
  255. }
  256. return ret_val;
  257. }
  258. /* ------------------------------------------------------------------------- */
  259. static int xilinx_validate (Xilinx_desc * desc, char *fn)
  260. {
  261. int ret_val = FALSE;
  262. if (desc) {
  263. if ((desc->family > min_xilinx_type) &&
  264. (desc->family < max_xilinx_type)) {
  265. if ((desc->iface > min_xilinx_iface_type) &&
  266. (desc->iface < max_xilinx_iface_type)) {
  267. if (desc->size) {
  268. ret_val = TRUE;
  269. } else
  270. printf ("%s: NULL part size\n", fn);
  271. } else
  272. printf ("%s: Invalid Interface type, %d\n",
  273. fn, desc->iface);
  274. } else
  275. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  276. } else
  277. printf ("%s: NULL descriptor!\n", fn);
  278. return ret_val;
  279. }
  280. #endif /* CONFIG_FPGA && CONFIG_FPGA_XILINX */