altera.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * (C) Copyright 2003
  3. * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
  4. *
  5. * (C) Copyright 2002
  6. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. *
  26. */
  27. /*
  28. * Altera FPGA support
  29. */
  30. #include <common.h>
  31. #include <ACEX1K.h>
  32. #include <stratixII.h>
  33. /* Define FPGA_DEBUG to get debug printf's */
  34. /* #define FPGA_DEBUG */
  35. #ifdef FPGA_DEBUG
  36. #define PRINTF(fmt,args...) printf (fmt ,##args)
  37. #else
  38. #define PRINTF(fmt,args...)
  39. #endif
  40. /* Local Static Functions */
  41. static int altera_validate (Altera_desc * desc, const char *fn);
  42. /* ------------------------------------------------------------------------- */
  43. int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
  44. {
  45. int ret_val = FPGA_FAIL; /* assume a failure */
  46. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  47. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  48. } else {
  49. switch (desc->family) {
  50. case Altera_ACEX1K:
  51. case Altera_CYC2:
  52. #if defined(CONFIG_FPGA_ACEX1K)
  53. PRINTF ("%s: Launching the ACEX1K Loader...\n",
  54. __FUNCTION__);
  55. ret_val = ACEX1K_load (desc, buf, bsize);
  56. #elif defined(CONFIG_FPGA_CYCLON2)
  57. PRINTF ("%s: Launching the CYCLONE II Loader...\n",
  58. __FUNCTION__);
  59. ret_val = CYC2_load (desc, buf, bsize);
  60. #else
  61. printf ("%s: No support for ACEX1K devices.\n",
  62. __FUNCTION__);
  63. #endif
  64. break;
  65. #if defined(CONFIG_FPGA_STRATIX_II)
  66. case Altera_StratixII:
  67. PRINTF ("%s: Launching the Stratix II Loader...\n",
  68. __FUNCTION__);
  69. ret_val = StratixII_load (desc, buf, bsize);
  70. break;
  71. #endif
  72. default:
  73. printf ("%s: Unsupported family type, %d\n",
  74. __FUNCTION__, desc->family);
  75. }
  76. }
  77. return ret_val;
  78. }
  79. int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
  80. {
  81. int ret_val = FPGA_FAIL; /* assume a failure */
  82. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  83. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  84. } else {
  85. switch (desc->family) {
  86. case Altera_ACEX1K:
  87. #if defined(CONFIG_FPGA_ACEX)
  88. PRINTF ("%s: Launching the ACEX1K Reader...\n",
  89. __FUNCTION__);
  90. ret_val = ACEX1K_dump (desc, buf, bsize);
  91. #else
  92. printf ("%s: No support for ACEX1K devices.\n",
  93. __FUNCTION__);
  94. #endif
  95. break;
  96. #if defined(CONFIG_FPGA_STRATIX_II)
  97. case Altera_StratixII:
  98. PRINTF ("%s: Launching the Stratix II Reader...\n",
  99. __FUNCTION__);
  100. ret_val = StratixII_dump (desc, buf, bsize);
  101. break;
  102. #endif
  103. default:
  104. printf ("%s: Unsupported family type, %d\n",
  105. __FUNCTION__, desc->family);
  106. }
  107. }
  108. return ret_val;
  109. }
  110. int altera_info( Altera_desc *desc )
  111. {
  112. int ret_val = FPGA_FAIL;
  113. if (altera_validate (desc, (char *)__FUNCTION__)) {
  114. printf ("Family: \t");
  115. switch (desc->family) {
  116. case Altera_ACEX1K:
  117. printf ("ACEX1K\n");
  118. break;
  119. case Altera_CYC2:
  120. printf ("CYCLON II\n");
  121. break;
  122. case Altera_StratixII:
  123. printf ("Stratix II\n");
  124. break;
  125. /* Add new family types here */
  126. default:
  127. printf ("Unknown family type, %d\n", desc->family);
  128. }
  129. printf ("Interface type:\t");
  130. switch (desc->iface) {
  131. case passive_serial:
  132. printf ("Passive Serial (PS)\n");
  133. break;
  134. case passive_parallel_synchronous:
  135. printf ("Passive Parallel Synchronous (PPS)\n");
  136. break;
  137. case passive_parallel_asynchronous:
  138. printf ("Passive Parallel Asynchronous (PPA)\n");
  139. break;
  140. case passive_serial_asynchronous:
  141. printf ("Passive Serial Asynchronous (PSA)\n");
  142. break;
  143. case altera_jtag_mode: /* Not used */
  144. printf ("JTAG Mode\n");
  145. break;
  146. case fast_passive_parallel:
  147. printf ("Fast Passive Parallel (FPP)\n");
  148. break;
  149. case fast_passive_parallel_security:
  150. printf
  151. ("Fast Passive Parallel with Security (FPPS) \n");
  152. break;
  153. /* Add new interface types here */
  154. default:
  155. printf ("Unsupported interface type, %d\n", desc->iface);
  156. }
  157. printf ("Device Size: \t%d bytes\n"
  158. "Cookie: \t0x%x (%d)\n",
  159. desc->size, desc->cookie, desc->cookie);
  160. if (desc->iface_fns) {
  161. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  162. switch (desc->family) {
  163. case Altera_ACEX1K:
  164. case Altera_CYC2:
  165. #if defined(CONFIG_FPGA_ACEX1K)
  166. ACEX1K_info (desc);
  167. #elif defined(CONFIG_FPGA_CYCLON2)
  168. CYC2_info (desc);
  169. #else
  170. /* just in case */
  171. printf ("%s: No support for ACEX1K devices.\n",
  172. __FUNCTION__);
  173. #endif
  174. break;
  175. #if defined(CONFIG_FPGA_STRATIX_II)
  176. case Altera_StratixII:
  177. StratixII_info (desc);
  178. break;
  179. #endif
  180. /* Add new family types here */
  181. default:
  182. /* we don't need a message here - we give one up above */
  183. break;
  184. }
  185. } else {
  186. printf ("No Device Function Table.\n");
  187. }
  188. ret_val = FPGA_SUCCESS;
  189. } else {
  190. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  191. }
  192. return ret_val;
  193. }
  194. /* ------------------------------------------------------------------------- */
  195. static int altera_validate (Altera_desc * desc, const char *fn)
  196. {
  197. int ret_val = false;
  198. if (desc) {
  199. if ((desc->family > min_altera_type) &&
  200. (desc->family < max_altera_type)) {
  201. if ((desc->iface > min_altera_iface_type) &&
  202. (desc->iface < max_altera_iface_type)) {
  203. if (desc->size) {
  204. ret_val = true;
  205. } else {
  206. printf ("%s: NULL part size\n", fn);
  207. }
  208. } else {
  209. printf ("%s: Invalid Interface type, %d\n",
  210. fn, desc->iface);
  211. }
  212. } else {
  213. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  214. }
  215. } else {
  216. printf ("%s: NULL descriptor!\n", fn);
  217. }
  218. return ret_val;
  219. }
  220. /* ------------------------------------------------------------------------- */