altera.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. /*
  11. * Altera FPGA support
  12. */
  13. #include <common.h>
  14. #include <ACEX1K.h>
  15. #include <stratixII.h>
  16. /* Define FPGA_DEBUG to get debug printf's */
  17. /* #define FPGA_DEBUG */
  18. #ifdef FPGA_DEBUG
  19. #define PRINTF(fmt,args...) printf (fmt ,##args)
  20. #else
  21. #define PRINTF(fmt,args...)
  22. #endif
  23. /* Local Static Functions */
  24. static int altera_validate (Altera_desc * desc, const char *fn);
  25. /* ------------------------------------------------------------------------- */
  26. int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
  27. {
  28. int ret_val = FPGA_FAIL; /* assume a failure */
  29. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  30. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  31. } else {
  32. switch (desc->family) {
  33. case Altera_ACEX1K:
  34. case Altera_CYC2:
  35. #if defined(CONFIG_FPGA_ACEX1K)
  36. PRINTF ("%s: Launching the ACEX1K Loader...\n",
  37. __FUNCTION__);
  38. ret_val = ACEX1K_load (desc, buf, bsize);
  39. #elif defined(CONFIG_FPGA_CYCLON2)
  40. PRINTF ("%s: Launching the CYCLONE II Loader...\n",
  41. __FUNCTION__);
  42. ret_val = CYC2_load (desc, buf, bsize);
  43. #else
  44. printf ("%s: No support for ACEX1K devices.\n",
  45. __FUNCTION__);
  46. #endif
  47. break;
  48. #if defined(CONFIG_FPGA_STRATIX_II)
  49. case Altera_StratixII:
  50. PRINTF ("%s: Launching the Stratix II Loader...\n",
  51. __FUNCTION__);
  52. ret_val = StratixII_load (desc, buf, bsize);
  53. break;
  54. #endif
  55. default:
  56. printf ("%s: Unsupported family type, %d\n",
  57. __FUNCTION__, desc->family);
  58. }
  59. }
  60. return ret_val;
  61. }
  62. int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
  63. {
  64. int ret_val = FPGA_FAIL; /* assume a failure */
  65. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  66. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  67. } else {
  68. switch (desc->family) {
  69. case Altera_ACEX1K:
  70. #if defined(CONFIG_FPGA_ACEX)
  71. PRINTF ("%s: Launching the ACEX1K Reader...\n",
  72. __FUNCTION__);
  73. ret_val = ACEX1K_dump (desc, buf, bsize);
  74. #else
  75. printf ("%s: No support for ACEX1K devices.\n",
  76. __FUNCTION__);
  77. #endif
  78. break;
  79. #if defined(CONFIG_FPGA_STRATIX_II)
  80. case Altera_StratixII:
  81. PRINTF ("%s: Launching the Stratix II Reader...\n",
  82. __FUNCTION__);
  83. ret_val = StratixII_dump (desc, buf, bsize);
  84. break;
  85. #endif
  86. default:
  87. printf ("%s: Unsupported family type, %d\n",
  88. __FUNCTION__, desc->family);
  89. }
  90. }
  91. return ret_val;
  92. }
  93. int altera_info( Altera_desc *desc )
  94. {
  95. int ret_val = FPGA_FAIL;
  96. if (altera_validate (desc, (char *)__FUNCTION__)) {
  97. printf ("Family: \t");
  98. switch (desc->family) {
  99. case Altera_ACEX1K:
  100. printf ("ACEX1K\n");
  101. break;
  102. case Altera_CYC2:
  103. printf ("CYCLON II\n");
  104. break;
  105. case Altera_StratixII:
  106. printf ("Stratix II\n");
  107. break;
  108. /* Add new family types here */
  109. default:
  110. printf ("Unknown family type, %d\n", desc->family);
  111. }
  112. printf ("Interface type:\t");
  113. switch (desc->iface) {
  114. case passive_serial:
  115. printf ("Passive Serial (PS)\n");
  116. break;
  117. case passive_parallel_synchronous:
  118. printf ("Passive Parallel Synchronous (PPS)\n");
  119. break;
  120. case passive_parallel_asynchronous:
  121. printf ("Passive Parallel Asynchronous (PPA)\n");
  122. break;
  123. case passive_serial_asynchronous:
  124. printf ("Passive Serial Asynchronous (PSA)\n");
  125. break;
  126. case altera_jtag_mode: /* Not used */
  127. printf ("JTAG Mode\n");
  128. break;
  129. case fast_passive_parallel:
  130. printf ("Fast Passive Parallel (FPP)\n");
  131. break;
  132. case fast_passive_parallel_security:
  133. printf
  134. ("Fast Passive Parallel with Security (FPPS) \n");
  135. break;
  136. /* Add new interface types here */
  137. default:
  138. printf ("Unsupported interface type, %d\n", desc->iface);
  139. }
  140. printf("Device Size: \t%zd bytes\n"
  141. "Cookie: \t0x%x (%d)\n",
  142. desc->size, desc->cookie, desc->cookie);
  143. if (desc->iface_fns) {
  144. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  145. switch (desc->family) {
  146. case Altera_ACEX1K:
  147. case Altera_CYC2:
  148. #if defined(CONFIG_FPGA_ACEX1K)
  149. ACEX1K_info (desc);
  150. #elif defined(CONFIG_FPGA_CYCLON2)
  151. CYC2_info (desc);
  152. #else
  153. /* just in case */
  154. printf ("%s: No support for ACEX1K devices.\n",
  155. __FUNCTION__);
  156. #endif
  157. break;
  158. #if defined(CONFIG_FPGA_STRATIX_II)
  159. case Altera_StratixII:
  160. StratixII_info (desc);
  161. break;
  162. #endif
  163. /* Add new family types here */
  164. default:
  165. /* we don't need a message here - we give one up above */
  166. break;
  167. }
  168. } else {
  169. printf ("No Device Function Table.\n");
  170. }
  171. ret_val = FPGA_SUCCESS;
  172. } else {
  173. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  174. }
  175. return ret_val;
  176. }
  177. /* ------------------------------------------------------------------------- */
  178. static int altera_validate (Altera_desc * desc, const char *fn)
  179. {
  180. int ret_val = false;
  181. if (desc) {
  182. if ((desc->family > min_altera_type) &&
  183. (desc->family < max_altera_type)) {
  184. if ((desc->iface > min_altera_iface_type) &&
  185. (desc->iface < max_altera_iface_type)) {
  186. if (desc->size) {
  187. ret_val = true;
  188. } else {
  189. printf ("%s: NULL part size\n", fn);
  190. }
  191. } else {
  192. printf ("%s: Invalid Interface type, %d\n",
  193. fn, desc->iface);
  194. }
  195. } else {
  196. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  197. }
  198. } else {
  199. printf ("%s: NULL descriptor!\n", fn);
  200. }
  201. return ret_val;
  202. }
  203. /* ------------------------------------------------------------------------- */