altera.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. break;
  144. }
  145. } else {
  146. printf ("No Device Function Table.\n");
  147. }
  148. ret_val = FPGA_SUCCESS;
  149. } else {
  150. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  151. }
  152. return ret_val;
  153. }
  154. int altera_reloc( Altera_desc *desc, ulong reloc_offset)
  155. {
  156. int ret_val = FPGA_FAIL; /* assume a failure */
  157. if (!altera_validate (desc, __FUNCTION__)) {
  158. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  159. } else {
  160. switch (desc->family) {
  161. case Altera_ACEX1K:
  162. #if (CONFIG_FPGA & CFG_ACEX1K)
  163. ret_val = ACEX1K_reloc (desc, reloc_offset);
  164. #else
  165. printf ("%s: No support for ACEX devices.\n",
  166. __FUNCTION__);
  167. #endif
  168. break;
  169. /* Add new family types here */
  170. default:
  171. printf ("%s: Unsupported family type, %d\n",
  172. __FUNCTION__, desc->family);
  173. }
  174. }
  175. return ret_val;
  176. }
  177. /* ------------------------------------------------------------------------- */
  178. static int altera_validate (Altera_desc * desc, 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. /* ------------------------------------------------------------------------- */
  204. #endif /* CONFIG_FPGA & CFG_FPGA_ALTERA */