xilinx.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 0
  33. #define FPGA_DEBUG
  34. #endif
  35. /* Define FPGA_DEBUG to get debug printf's */
  36. #ifdef FPGA_DEBUG
  37. #define PRINTF(fmt,args...) printf (fmt ,##args)
  38. #else
  39. #define PRINTF(fmt,args...)
  40. #endif
  41. /* Local Static Functions */
  42. static int xilinx_validate (Xilinx_desc * desc, char *fn);
  43. /* ------------------------------------------------------------------------- */
  44. int xilinx_load(Xilinx_desc *desc, const void *buf, size_t bsize)
  45. {
  46. int ret_val = FPGA_FAIL; /* assume a failure */
  47. if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
  48. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  49. } else
  50. switch (desc->family) {
  51. case Xilinx_Spartan2:
  52. #if defined(CONFIG_FPGA_SPARTAN2)
  53. PRINTF ("%s: Launching the Spartan-II Loader...\n",
  54. __FUNCTION__);
  55. ret_val = Spartan2_load (desc, buf, bsize);
  56. #else
  57. printf ("%s: No support for Spartan-II devices.\n",
  58. __FUNCTION__);
  59. #endif
  60. break;
  61. case Xilinx_Spartan3:
  62. #if defined(CONFIG_FPGA_SPARTAN3)
  63. PRINTF ("%s: Launching the Spartan-III Loader...\n",
  64. __FUNCTION__);
  65. ret_val = Spartan3_load (desc, buf, bsize);
  66. #else
  67. printf ("%s: No support for Spartan-III devices.\n",
  68. __FUNCTION__);
  69. #endif
  70. break;
  71. case Xilinx_Virtex2:
  72. #if defined(CONFIG_FPGA_VIRTEX2)
  73. PRINTF ("%s: Launching the Virtex-II Loader...\n",
  74. __FUNCTION__);
  75. ret_val = Virtex2_load (desc, buf, bsize);
  76. #else
  77. printf ("%s: No support for Virtex-II devices.\n",
  78. __FUNCTION__);
  79. #endif
  80. break;
  81. default:
  82. printf ("%s: Unsupported family type, %d\n",
  83. __FUNCTION__, desc->family);
  84. }
  85. return ret_val;
  86. }
  87. int xilinx_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
  88. {
  89. int ret_val = FPGA_FAIL; /* assume a failure */
  90. if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
  91. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  92. } else
  93. switch (desc->family) {
  94. case Xilinx_Spartan2:
  95. #if defined(CONFIG_FPGA_SPARTAN2)
  96. PRINTF ("%s: Launching the Spartan-II Reader...\n",
  97. __FUNCTION__);
  98. ret_val = Spartan2_dump (desc, buf, bsize);
  99. #else
  100. printf ("%s: No support for Spartan-II devices.\n",
  101. __FUNCTION__);
  102. #endif
  103. break;
  104. case Xilinx_Spartan3:
  105. #if defined(CONFIG_FPGA_SPARTAN3)
  106. PRINTF ("%s: Launching the Spartan-III Reader...\n",
  107. __FUNCTION__);
  108. ret_val = Spartan3_dump (desc, buf, bsize);
  109. #else
  110. printf ("%s: No support for Spartan-III devices.\n",
  111. __FUNCTION__);
  112. #endif
  113. break;
  114. case Xilinx_Virtex2:
  115. #if defined( CONFIG_FPGA_VIRTEX2)
  116. PRINTF ("%s: Launching the Virtex-II Reader...\n",
  117. __FUNCTION__);
  118. ret_val = Virtex2_dump (desc, buf, bsize);
  119. #else
  120. printf ("%s: No support for Virtex-II devices.\n",
  121. __FUNCTION__);
  122. #endif
  123. break;
  124. default:
  125. printf ("%s: Unsupported family type, %d\n",
  126. __FUNCTION__, desc->family);
  127. }
  128. return ret_val;
  129. }
  130. int xilinx_info (Xilinx_desc * desc)
  131. {
  132. int ret_val = FPGA_FAIL;
  133. if (xilinx_validate (desc, (char *)__FUNCTION__)) {
  134. printf ("Family: \t");
  135. switch (desc->family) {
  136. case Xilinx_Spartan2:
  137. printf ("Spartan-II\n");
  138. break;
  139. case Xilinx_Spartan3:
  140. printf ("Spartan-III\n");
  141. break;
  142. case Xilinx_Virtex2:
  143. printf ("Virtex-II\n");
  144. break;
  145. /* Add new family types here */
  146. default:
  147. printf ("Unknown family type, %d\n", desc->family);
  148. }
  149. printf ("Interface type:\t");
  150. switch (desc->iface) {
  151. case slave_serial:
  152. printf ("Slave Serial\n");
  153. break;
  154. case master_serial: /* Not used */
  155. printf ("Master Serial\n");
  156. break;
  157. case slave_parallel:
  158. printf ("Slave Parallel\n");
  159. break;
  160. case jtag_mode: /* Not used */
  161. printf ("JTAG Mode\n");
  162. break;
  163. case slave_selectmap:
  164. printf ("Slave SelectMap Mode\n");
  165. break;
  166. case master_selectmap:
  167. printf ("Master SelectMap Mode\n");
  168. break;
  169. /* Add new interface types here */
  170. default:
  171. printf ("Unsupported interface type, %d\n", desc->iface);
  172. }
  173. printf ("Device Size: \t%d bytes\n"
  174. "Cookie: \t0x%x (%d)\n",
  175. desc->size, desc->cookie, desc->cookie);
  176. if (desc->iface_fns) {
  177. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  178. switch (desc->family) {
  179. case Xilinx_Spartan2:
  180. #if defined(CONFIG_FPGA_SPARTAN2)
  181. Spartan2_info (desc);
  182. #else
  183. /* just in case */
  184. printf ("%s: No support for Spartan-II devices.\n",
  185. __FUNCTION__);
  186. #endif
  187. break;
  188. case Xilinx_Spartan3:
  189. #if defined(CONFIG_FPGA_SPARTAN3)
  190. Spartan3_info (desc);
  191. #else
  192. /* just in case */
  193. printf ("%s: No support for Spartan-III devices.\n",
  194. __FUNCTION__);
  195. #endif
  196. break;
  197. case Xilinx_Virtex2:
  198. #if defined(CONFIG_FPGA_VIRTEX2)
  199. Virtex2_info (desc);
  200. #else
  201. /* just in case */
  202. printf ("%s: No support for Virtex-II devices.\n",
  203. __FUNCTION__);
  204. #endif
  205. break;
  206. /* Add new family types here */
  207. default:
  208. /* we don't need a message here - we give one up above */
  209. ;
  210. }
  211. } else
  212. printf ("No Device Function Table.\n");
  213. ret_val = FPGA_SUCCESS;
  214. } else {
  215. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  216. }
  217. return ret_val;
  218. }
  219. /* ------------------------------------------------------------------------- */
  220. static int xilinx_validate (Xilinx_desc * desc, char *fn)
  221. {
  222. int ret_val = false;
  223. if (desc) {
  224. if ((desc->family > min_xilinx_type) &&
  225. (desc->family < max_xilinx_type)) {
  226. if ((desc->iface > min_xilinx_iface_type) &&
  227. (desc->iface < max_xilinx_iface_type)) {
  228. if (desc->size) {
  229. ret_val = true;
  230. } else
  231. printf ("%s: NULL part size\n", fn);
  232. } else
  233. printf ("%s: Invalid Interface type, %d\n",
  234. fn, desc->iface);
  235. } else
  236. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  237. } else
  238. printf ("%s: NULL descriptor!\n", fn);
  239. return ret_val;
  240. }