stratixII.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
  27. int isSerial, int isSecure);
  28. int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
  29. /****************************************************************/
  30. /* Stratix II Generic Implementation */
  31. int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
  32. {
  33. int ret_val = FPGA_FAIL;
  34. switch (desc->iface) {
  35. case passive_serial:
  36. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
  37. break;
  38. case fast_passive_parallel:
  39. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
  40. break;
  41. case fast_passive_parallel_security:
  42. ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
  43. break;
  44. /* Add new interface types here */
  45. default:
  46. printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
  47. desc->iface);
  48. }
  49. return ret_val;
  50. }
  51. int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
  52. {
  53. int ret_val = FPGA_FAIL;
  54. switch (desc->iface) {
  55. case passive_serial:
  56. case fast_passive_parallel:
  57. case fast_passive_parallel_security:
  58. ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
  59. break;
  60. /* Add new interface types here */
  61. default:
  62. printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
  63. desc->iface);
  64. }
  65. return ret_val;
  66. }
  67. int StratixII_info (Altera_desc * desc)
  68. {
  69. return FPGA_SUCCESS;
  70. }
  71. int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
  72. {
  73. printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
  74. return FPGA_FAIL;
  75. }
  76. int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
  77. int isSerial, int isSecure)
  78. {
  79. altera_board_specific_func *fns;
  80. int cookie;
  81. int ret_val = FPGA_FAIL;
  82. int bytecount;
  83. char *buff = buf;
  84. int i;
  85. if (!desc) {
  86. printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
  87. return FPGA_FAIL;
  88. }
  89. if (!buff) {
  90. printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
  91. return FPGA_FAIL;
  92. }
  93. if (!bsize) {
  94. printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
  95. return FPGA_FAIL;
  96. }
  97. if (!desc->iface_fns) {
  98. printf
  99. ("%s(%d) Altera_desc function interface table is missing\n",
  100. __FUNCTION__, __LINE__);
  101. return FPGA_FAIL;
  102. }
  103. fns = (altera_board_specific_func *) (desc->iface_fns);
  104. cookie = desc->cookie;
  105. if (!
  106. (fns->config && fns->status && fns->done && fns->data
  107. && fns->abort)) {
  108. printf
  109. ("%s(%d) Missing some function in the function interface table\n",
  110. __FUNCTION__, __LINE__);
  111. return FPGA_FAIL;
  112. }
  113. /* 1. give board specific a chance to do anything before we start */
  114. if (fns->pre) {
  115. if ((ret_val = fns->pre (cookie)) < 0) {
  116. return ret_val;
  117. }
  118. }
  119. /* from this point on we must fail gracfully by calling lower layer abort */
  120. /* 2. Strat burn cycle by deasserting config for t_CFG and waiting t_CF2CK after reaserted */
  121. fns->config (0, 1, cookie);
  122. udelay (5); /* nCONFIG low pulse width 2usec */
  123. fns->config (1, 1, cookie);
  124. udelay (100); /* nCONFIG high to first rising edge on DCLK */
  125. /* 3. Start the Data cycle with clk deasserted */
  126. bytecount = 0;
  127. fns->clk (0, 1, cookie);
  128. printf ("loading to fpga ");
  129. while (bytecount < bsize) {
  130. /* 3.1 check stratix has not signaled us an error */
  131. if (fns->status (cookie) != 1) {
  132. printf
  133. ("\n%s(%d) Stratix failed (byte transfered till failure 0x%x)\n",
  134. __FUNCTION__, __LINE__, bytecount);
  135. fns->abort (cookie);
  136. return FPGA_FAIL;
  137. }
  138. if (isSerial) {
  139. int i;
  140. uint8_t data = buff[bytecount++];
  141. for (i = 0; i < 8; i++) {
  142. /* 3.2(ps) put data on the bus */
  143. fns->data ((data >> i) & 1, 1, cookie);
  144. /* 3.3(ps) clock once */
  145. fns->clk (1, 1, cookie);
  146. fns->clk (0, 1, cookie);
  147. }
  148. } else {
  149. /* 3.2(fpp) put data on the bus */
  150. fns->data (buff[bytecount++], 1, cookie);
  151. /* 3.3(fpp) clock once */
  152. fns->clk (1, 1, cookie);
  153. fns->clk (0, 1, cookie);
  154. /* 3.4(fpp) for secure cycle push 3 more clocks */
  155. for (i = 0; isSecure && i < 3; i++) {
  156. fns->clk (1, 1, cookie);
  157. fns->clk (0, 1, cookie);
  158. }
  159. }
  160. /* 3.5 while clk is deasserted it is safe to print some progress indication */
  161. if ((bytecount % (bsize / 100)) == 0) {
  162. printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
  163. }
  164. }
  165. /* 4. Set one last clock and check conf done signal */
  166. fns->clk (1, 1, cookie);
  167. udelay (100);
  168. if (!fns->done (cookie)) {
  169. printf (" error!.\n");
  170. fns->abort (cookie);
  171. return FPGA_FAIL;
  172. } else {
  173. printf ("\b\b\b done.\n");
  174. }
  175. /* 5. call lower layer post configuration */
  176. if (fns->post) {
  177. if ((ret_val = fns->post (cookie)) < 0) {
  178. fns->abort (cookie);
  179. return ret_val;
  180. }
  181. }
  182. return FPGA_SUCCESS;
  183. }