fpga.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * (C) Copyright 2002
  3. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  4. * Keith Outwater, keith_outwater@mvis.com.
  5. *
  6. * (C) Copyright 2008
  7. * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. */
  28. #include <common.h>
  29. #include <ACEX1K.h>
  30. #include <command.h>
  31. #include "fpga.h"
  32. #include "mvblm7.h"
  33. #ifdef FPGA_DEBUG
  34. #define fpga_debug(fmt, args...) printf("%s: "fmt, __func__, ##args)
  35. #else
  36. #define fpga_debug(fmt, args...)
  37. #endif
  38. Altera_CYC2_Passive_Serial_fns altera_fns = {
  39. fpga_null_fn,
  40. fpga_config_fn,
  41. fpga_status_fn,
  42. fpga_done_fn,
  43. fpga_wr_fn,
  44. fpga_null_fn,
  45. fpga_null_fn,
  46. 0
  47. };
  48. Altera_desc cyclone2 = {
  49. Altera_CYC2,
  50. passive_serial,
  51. Altera_EP2C20_SIZE,
  52. (void *) &altera_fns,
  53. NULL,
  54. 0
  55. };
  56. DECLARE_GLOBAL_DATA_PTR;
  57. int mvblm7_init_fpga(void)
  58. {
  59. fpga_debug("Initialize FPGA interface (reloc 0x%.8lx)\n",
  60. gd->reloc_off);
  61. fpga_init(gd->reloc_off);
  62. fpga_add(fpga_altera, &cyclone2);
  63. fpga_config_fn(0, 1, 0);
  64. udelay(60);
  65. return 1;
  66. }
  67. int fpga_null_fn(int cookie)
  68. {
  69. return 0;
  70. }
  71. int fpga_config_fn(int assert, int flush, int cookie)
  72. {
  73. volatile immap_t *im = (volatile immap_t *)CFG_IMMR;
  74. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)&im->gpio[0];
  75. u32 dvo = gpio->dat;
  76. fpga_debug("SET config : %s\n", assert ? "low" : "high");
  77. if (assert)
  78. dvo |= FPGA_CONFIG;
  79. else
  80. dvo &= ~FPGA_CONFIG;
  81. if (flush)
  82. gpio->dat = dvo;
  83. return assert;
  84. }
  85. int fpga_done_fn(int cookie)
  86. {
  87. volatile immap_t *im = (volatile immap_t *)CFG_IMMR;
  88. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)&im->gpio[0];
  89. int result = 0;
  90. udelay(10);
  91. fpga_debug("CONF_DONE check ... ");
  92. if (gpio->dat & FPGA_CONF_DONE) {
  93. fpga_debug("high\n");
  94. result = 1;
  95. } else
  96. fpga_debug("low\n");
  97. return result;
  98. }
  99. int fpga_status_fn(int cookie)
  100. {
  101. volatile immap_t *im = (volatile immap_t *)CFG_IMMR;
  102. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)&im->gpio[0];
  103. int result = 0;
  104. fpga_debug("STATUS check ... ");
  105. if (gpio->dat & FPGA_STATUS) {
  106. fpga_debug("high\n");
  107. result = 1;
  108. } else
  109. fpga_debug("low\n");
  110. return result;
  111. }
  112. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  113. {
  114. volatile immap_t *im = (volatile immap_t *)CFG_IMMR;
  115. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)&im->gpio[0];
  116. u32 dvo = gpio->dat;
  117. fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low");
  118. if (assert_clk)
  119. dvo |= FPGA_CCLK;
  120. else
  121. dvo &= ~FPGA_CCLK;
  122. if (flush)
  123. gpio->dat = dvo;
  124. return assert_clk;
  125. }
  126. static inline int _write_fpga(u8 val, int dump)
  127. {
  128. volatile immap_t *im = (volatile immap_t *)CFG_IMMR;
  129. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)&im->gpio[0];
  130. int i;
  131. u32 dvo = gpio->dat;
  132. if (dump)
  133. fpga_debug(" %02x -> ", val);
  134. for (i = 0; i < 8; i++) {
  135. dvo &= ~FPGA_CCLK;
  136. gpio->dat = dvo;
  137. dvo &= ~FPGA_DIN;
  138. if (dump)
  139. fpga_debug("%d ", val&1);
  140. if (val & 1)
  141. dvo |= FPGA_DIN;
  142. gpio->dat = dvo;
  143. dvo |= FPGA_CCLK;
  144. gpio->dat = dvo;
  145. val >>= 1;
  146. }
  147. if (dump)
  148. fpga_debug("\n");
  149. return 0;
  150. }
  151. int fpga_wr_fn(void *buf, size_t len, int flush, int cookie)
  152. {
  153. unsigned char *data = (unsigned char *) buf;
  154. int i;
  155. fpga_debug("fpga_wr: buf %p / size %d\n", buf, len);
  156. for (i = 0; i < len; i++)
  157. _write_fpga(data[i], 0);
  158. fpga_debug("\n");
  159. return FPGA_SUCCESS;
  160. }