altera.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. /* Define FPGA_DEBUG to get debug printf's */
  33. /* #define FPGA_DEBUG */
  34. #ifdef FPGA_DEBUG
  35. #define PRINTF(fmt,args...) printf (fmt ,##args)
  36. #else
  37. #define PRINTF(fmt,args...)
  38. #endif
  39. #if (CONFIG_FPGA & CFG_FPGA_ALTERA)
  40. /* Local Static Functions */
  41. static int altera_validate (Altera_desc * desc, char *fn);
  42. /* ------------------------------------------------------------------------- */
  43. int altera_load( Altera_desc *desc, 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 (CONFIG_FPGA & CFG_ACEX1K)
  53. PRINTF ("%s: Launching the ACEX1K Loader...\n",
  54. __FUNCTION__);
  55. ret_val = ACEX1K_load (desc, buf, bsize);
  56. #elif (CONFIG_FPGA & CFG_CYCLON2)
  57. PRINTF ("%s: Launching the CYCLON 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. default:
  66. printf ("%s: Unsupported family type, %d\n",
  67. __FUNCTION__, desc->family);
  68. }
  69. }
  70. return ret_val;
  71. }
  72. int altera_dump( Altera_desc *desc, void *buf, size_t bsize )
  73. {
  74. int ret_val = FPGA_FAIL; /* assume a failure */
  75. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  76. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  77. } else {
  78. switch (desc->family) {
  79. case Altera_ACEX1K:
  80. #if (CONFIG_FPGA & CFG_ACEX)
  81. PRINTF ("%s: Launching the ACEX1K Reader...\n",
  82. __FUNCTION__);
  83. ret_val = ACEX1K_dump (desc, buf, bsize);
  84. #else
  85. printf ("%s: No support for ACEX1K devices.\n",
  86. __FUNCTION__);
  87. #endif
  88. break;
  89. default:
  90. printf ("%s: Unsupported family type, %d\n",
  91. __FUNCTION__, desc->family);
  92. }
  93. }
  94. return ret_val;
  95. }
  96. int altera_info( Altera_desc *desc )
  97. {
  98. int ret_val = FPGA_FAIL;
  99. if (altera_validate (desc, (char *)__FUNCTION__)) {
  100. printf ("Family: \t");
  101. switch (desc->family) {
  102. case Altera_ACEX1K:
  103. printf ("ACEX1K\n");
  104. break;
  105. /* Add new family types here */
  106. case Altera_CYC2:
  107. printf ("CYCLON II\n");
  108. break;
  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. /* Add new interface types here */
  130. default:
  131. printf ("Unsupported interface type, %d\n", desc->iface);
  132. }
  133. printf ("Device Size: \t%d bytes\n"
  134. "Cookie: \t0x%x (%d)\n",
  135. desc->size, desc->cookie, desc->cookie);
  136. if (desc->iface_fns) {
  137. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  138. switch (desc->family) {
  139. case Altera_ACEX1K:
  140. case Altera_CYC2:
  141. #if (CONFIG_FPGA & CFG_ACEX1K)
  142. ACEX1K_info (desc);
  143. #elif (CONFIG_FPGA & CFG_CYCLON2)
  144. CYC2_info (desc);
  145. #else
  146. /* just in case */
  147. printf ("%s: No support for ACEX1K devices.\n",
  148. __FUNCTION__);
  149. #endif
  150. break;
  151. /* Add new family types here */
  152. default:
  153. /* we don't need a message here - we give one up above */
  154. break;
  155. }
  156. } else {
  157. printf ("No Device Function Table.\n");
  158. }
  159. ret_val = FPGA_SUCCESS;
  160. } else {
  161. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  162. }
  163. return ret_val;
  164. }
  165. int altera_reloc( Altera_desc *desc, ulong reloc_offset)
  166. {
  167. int ret_val = FPGA_FAIL; /* assume a failure */
  168. if (!altera_validate (desc, (char *)__FUNCTION__)) {
  169. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  170. } else {
  171. switch (desc->family) {
  172. case Altera_ACEX1K:
  173. #if (CONFIG_FPGA & CFG_ACEX1K)
  174. ret_val = ACEX1K_reloc (desc, reloc_offset);
  175. #else
  176. printf ("%s: No support for ACEX devices.\n",
  177. __FUNCTION__);
  178. #endif
  179. break;
  180. case Altera_CYC2:
  181. #if (CONFIG_FPGA & CFG_CYCLON2)
  182. ret_val = CYC2_reloc (desc, reloc_offset);
  183. #else
  184. printf ("%s: No support for CYCLON II devices.\n",
  185. __FUNCTION__);
  186. #endif
  187. break;
  188. /* Add new family types here */
  189. default:
  190. printf ("%s: Unsupported family type, %d\n",
  191. __FUNCTION__, desc->family);
  192. }
  193. }
  194. return ret_val;
  195. }
  196. /* ------------------------------------------------------------------------- */
  197. static int altera_validate (Altera_desc * desc, char *fn)
  198. {
  199. int ret_val = FALSE;
  200. if (desc) {
  201. if ((desc->family > min_altera_type) &&
  202. (desc->family < max_altera_type)) {
  203. if ((desc->iface > min_altera_iface_type) &&
  204. (desc->iface < max_altera_iface_type)) {
  205. if (desc->size) {
  206. ret_val = TRUE;
  207. } else {
  208. printf ("%s: NULL part size\n", fn);
  209. }
  210. } else {
  211. printf ("%s: Invalid Interface type, %d\n",
  212. fn, desc->iface);
  213. }
  214. } else {
  215. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  216. }
  217. } else {
  218. printf ("%s: NULL descriptor!\n", fn);
  219. }
  220. return ret_val;
  221. }
  222. /* ------------------------------------------------------------------------- */
  223. #endif /* CONFIG_FPGA & CFG_FPGA_ALTERA */