altera.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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, __FUNCTION__)) {
  47. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  48. } else {
  49. switch (desc->family) {
  50. case Altera_ACEX1K:
  51. #if (CONFIG_FPGA & CFG_ACEX1K)
  52. PRINTF ("%s: Launching the ACEX1K Loader...\n",
  53. __FUNCTION__);
  54. ret_val = ACEX1K_load (desc, buf, bsize);
  55. #else
  56. printf ("%s: No support for ACEX1K devices.\n",
  57. __FUNCTION__);
  58. #endif
  59. break;
  60. default:
  61. printf ("%s: Unsupported family type, %d\n",
  62. __FUNCTION__, desc->family);
  63. }
  64. }
  65. return ret_val;
  66. }
  67. int altera_dump( Altera_desc *desc, void *buf, size_t bsize )
  68. {
  69. int ret_val = FPGA_FAIL; /* assume a failure */
  70. if (!altera_validate (desc, __FUNCTION__)) {
  71. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  72. } else {
  73. switch (desc->family) {
  74. case Altera_ACEX1K:
  75. #if (CONFIG_FPGA & CFG_ACEX)
  76. PRINTF ("%s: Launching the ACEX1K Reader...\n",
  77. __FUNCTION__);
  78. ret_val = ACEX1K_dump (desc, buf, bsize);
  79. #else
  80. printf ("%s: No support for ACEX1K devices.\n",
  81. __FUNCTION__);
  82. #endif
  83. break;
  84. default:
  85. printf ("%s: Unsupported family type, %d\n",
  86. __FUNCTION__, desc->family);
  87. }
  88. }
  89. return ret_val;
  90. }
  91. int altera_info( Altera_desc *desc )
  92. {
  93. int ret_val = FPGA_FAIL;
  94. if (altera_validate (desc, __FUNCTION__)) {
  95. printf ("Family: \t");
  96. switch (desc->family) {
  97. case Altera_ACEX1K:
  98. printf ("ACEX1K\n");
  99. break;
  100. /* Add new family types here */
  101. default:
  102. printf ("Unknown family type, %d\n", desc->family);
  103. }
  104. printf ("Interface type:\t");
  105. switch (desc->iface) {
  106. case passive_serial:
  107. printf ("Passive Serial (PS)\n");
  108. break;
  109. case passive_parallel_synchronous:
  110. printf ("Passive Parallel Synchronous (PPS)\n");
  111. break;
  112. case passive_parallel_asynchronous:
  113. printf ("Passive Parallel Asynchronous (PPA)\n");
  114. break;
  115. case passive_serial_asynchronous:
  116. printf ("Passive Serial Asynchronous (PSA)\n");
  117. break;
  118. case altera_jtag_mode: /* Not used */
  119. printf ("JTAG Mode\n");
  120. break;
  121. /* Add new interface types here */
  122. default:
  123. printf ("Unsupported interface type, %d\n", desc->iface);
  124. }
  125. printf ("Device Size: \t%d bytes\n"
  126. "Cookie: \t0x%x (%d)\n",
  127. desc->size, desc->cookie, desc->cookie);
  128. if (desc->iface_fns) {
  129. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  130. switch (desc->family) {
  131. case Altera_ACEX1K:
  132. #if (CONFIG_FPGA & CFG_ACEX1K)
  133. ACEX1K_info (desc);
  134. #else
  135. /* just in case */
  136. printf ("%s: No support for ACEX1K devices.\n",
  137. __FUNCTION__);
  138. #endif
  139. break;
  140. /* Add new family types here */
  141. default:
  142. /* we don't need a message here - we give one up above */
  143. }
  144. } else {
  145. printf ("No Device Function Table.\n");
  146. }
  147. ret_val = FPGA_SUCCESS;
  148. } else {
  149. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  150. }
  151. return ret_val;
  152. }
  153. int altera_reloc( Altera_desc *desc, ulong reloc_offset)
  154. {
  155. int ret_val = FPGA_FAIL; /* assume a failure */
  156. if (!altera_validate (desc, __FUNCTION__)) {
  157. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  158. } else {
  159. switch (desc->family) {
  160. case Altera_ACEX1K:
  161. #if (CONFIG_FPGA & CFG_ACEX1K)
  162. ret_val = ACEX1K_reloc (desc, reloc_offset);
  163. #else
  164. printf ("%s: No support for ACEX devices.\n",
  165. __FUNCTION__);
  166. #endif
  167. break;
  168. /* Add new family types here */
  169. default:
  170. printf ("%s: Unsupported family type, %d\n",
  171. __FUNCTION__, desc->family);
  172. }
  173. }
  174. return ret_val;
  175. }
  176. /* ------------------------------------------------------------------------- */
  177. static int altera_validate (Altera_desc * desc, char *fn)
  178. {
  179. int ret_val = FALSE;
  180. if (desc) {
  181. if ((desc->family > min_altera_type) &&
  182. (desc->family < max_altera_type)) {
  183. if ((desc->iface > min_altera_iface_type) &&
  184. (desc->iface < max_altera_iface_type)) {
  185. if (desc->size) {
  186. ret_val = TRUE;
  187. } else {
  188. printf ("%s: NULL part size\n", fn);
  189. }
  190. } else {
  191. printf ("%s: Invalid Interface type, %d\n",
  192. fn, desc->iface);
  193. }
  194. } else {
  195. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  196. }
  197. } else {
  198. printf ("%s: NULL descriptor!\n", fn);
  199. }
  200. return ret_val;
  201. }
  202. /* ------------------------------------------------------------------------- */
  203. #endif /* CONFIG_FPGA & CFG_FPGA_ALTERA */