stratixII.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * (C) Copyright 2007
  3. * Eran Liberty, Extricom , eran.liberty@gmail.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. #include <common.h> /* core U-Boot definitions */
  25. #include <altera.h>
  26. #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ALTERA) && defined(CONFIG_FPGA_STRATIX_II)
  27. int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
  28. int isSerial, int isSecure);
  29. int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
  30. /****************************************************************/
  31. /* Stratix II Generic Implementation */
  32. int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
  33. {
  34. int ret_val = FPGA_FAIL;
  35. switch (desc->iface) {
  36. case passive_serial:
  37. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
  38. break;
  39. case fast_passive_parallel:
  40. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
  41. break;
  42. case fast_passive_parallel_security:
  43. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
  44. break;
  45. /* Add new interface types here */
  46. default:
  47. printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
  48. desc->iface);
  49. }
  50. return ret_val;
  51. }
  52. int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
  53. {
  54. int ret_val = FPGA_FAIL;
  55. switch (desc->iface) {
  56. case passive_serial:
  57. case fast_passive_parallel:
  58. case fast_passive_parallel_security:
  59. ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
  60. break;
  61. /* Add new interface types here */
  62. default:
  63. printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
  64. desc->iface);
  65. }
  66. return ret_val;
  67. }
  68. int StratixII_info (Altera_desc * desc)
  69. {
  70. return FPGA_SUCCESS;
  71. }
  72. int StratixII_reloc (Altera_desc * desc, ulong reloc_offset)
  73. {
  74. int i;
  75. uint32_t dest = (uint32_t) desc & 0xff000000;
  76. /* we assume a relocated code and non relocated code has different upper 8 bits */
  77. if (dest != ((uint32_t) desc->iface_fns & 0xff000000)) {
  78. desc->iface_fns =
  79. (void *)((uint32_t) (desc->iface_fns) + reloc_offset);
  80. }
  81. for (i = 0; i < sizeof (altera_board_specific_func) / sizeof (void *);
  82. i++) {
  83. if (dest !=
  84. ((uint32_t) (((void **)(desc->iface_fns))[i]) & 0xff000000))
  85. {
  86. ((void **)(desc->iface_fns))[i] =
  87. (void
  88. *)(((uint32_t) (((void **)(desc->iface_fns))[i])) +
  89. reloc_offset);
  90. }
  91. }
  92. return FPGA_SUCCESS;
  93. }
  94. int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
  95. {
  96. printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
  97. return FPGA_FAIL;
  98. }
  99. int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
  100. int isSerial, int isSecure)
  101. {
  102. altera_board_specific_func *fns;
  103. int cookie;
  104. int ret_val = FPGA_FAIL;
  105. int bytecount;
  106. char *buff = buf;
  107. int i;
  108. if (!desc) {
  109. printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
  110. return FPGA_FAIL;
  111. }
  112. if (!buff) {
  113. printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
  114. return FPGA_FAIL;
  115. }
  116. if (!bsize) {
  117. printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
  118. return FPGA_FAIL;
  119. }
  120. if (!desc->iface_fns) {
  121. printf
  122. ("%s(%d) Altera_desc function interface table is missing\n",
  123. __FUNCTION__, __LINE__);
  124. return FPGA_FAIL;
  125. }
  126. fns = (altera_board_specific_func *) (desc->iface_fns);
  127. cookie = desc->cookie;
  128. if (!
  129. (fns->config && fns->status && fns->done && fns->data
  130. && fns->abort)) {
  131. printf
  132. ("%s(%d) Missing some function in the function interface table\n",
  133. __FUNCTION__, __LINE__);
  134. return FPGA_FAIL;
  135. }
  136. /* 1. give board specific a chance to do anything before we start */
  137. if (fns->pre) {
  138. if ((ret_val = fns->pre (cookie)) < 0) {
  139. return ret_val;
  140. }
  141. }
  142. /* from this point on we must fail gracfully by calling lower layer abort */
  143. /* 2. Strat burn cycle by deasserting config for t_CFG and waiting t_CF2CK after reaserted */
  144. fns->config (0, 1, cookie);
  145. udelay (5); /* nCONFIG low pulse width 2usec */
  146. fns->config (1, 1, cookie);
  147. udelay (100); /* nCONFIG high to first rising edge on DCLK */
  148. /* 3. Start the Data cycle with clk deasserted */
  149. bytecount = 0;
  150. fns->clk (0, 1, cookie);
  151. printf ("loading to fpga ");
  152. while (bytecount < bsize) {
  153. /* 3.1 check stratix has not signaled us an error */
  154. if (fns->status (cookie) != 1) {
  155. printf
  156. ("\n%s(%d) Stratix failed (byte transfered till failure 0x%x)\n",
  157. __FUNCTION__, __LINE__, bytecount);
  158. fns->abort (cookie);
  159. return FPGA_FAIL;
  160. }
  161. if (isSerial) {
  162. int i;
  163. uint8_t data = buff[bytecount++];
  164. for (i = 0; i < 8; i++) {
  165. /* 3.2(ps) put data on the bus */
  166. fns->data ((data >> i) & 1, 1, cookie);
  167. /* 3.3(ps) clock once */
  168. fns->clk (1, 1, cookie);
  169. fns->clk (0, 1, cookie);
  170. }
  171. } else {
  172. /* 3.2(fpp) put data on the bus */
  173. fns->data (buff[bytecount++], 1, cookie);
  174. /* 3.3(fpp) clock once */
  175. fns->clk (1, 1, cookie);
  176. fns->clk (0, 1, cookie);
  177. /* 3.4(fpp) for secure cycle push 3 more clocks */
  178. for (i = 0; isSecure && i < 3; i++) {
  179. fns->clk (1, 1, cookie);
  180. fns->clk (0, 1, cookie);
  181. }
  182. }
  183. /* 3.5 while clk is deasserted it is safe to print some progress indication */
  184. if ((bytecount % (bsize / 100)) == 0) {
  185. printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
  186. }
  187. }
  188. /* 4. Set one last clock and check conf done signal */
  189. fns->clk (1, 1, cookie);
  190. udelay (100);
  191. if (!fns->done (cookie)) {
  192. printf (" error!.\n");
  193. fns->abort (cookie);
  194. return FPGA_FAIL;
  195. } else {
  196. printf ("\b\b\b done.\n");
  197. }
  198. /* 5. call lower layer post configuration */
  199. if (fns->post) {
  200. if ((ret_val = fns->post (cookie)) < 0) {
  201. fns->abort (cookie);
  202. return ret_val;
  203. }
  204. }
  205. return FPGA_SUCCESS;
  206. }
  207. #endif /* defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ALTERA) && defined(CONFIG_FPGA_STRATIX_II) */