fpga.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "mvbc_p.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_EP2C8_SIZE,
  52. (void *) &altera_fns,
  53. NULL,
  54. 0
  55. };
  56. DECLARE_GLOBAL_DATA_PTR;
  57. int mvbc_p_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. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  74. u32 dvo = gpio->simple_dvo;
  75. fpga_debug("SET config : %s\n", assert ? "low" : "high");
  76. if (assert)
  77. dvo |= FPGA_CONFIG;
  78. else
  79. dvo &= ~FPGA_CONFIG;
  80. if (flush)
  81. gpio->simple_dvo = dvo;
  82. return assert;
  83. }
  84. int fpga_done_fn(int cookie)
  85. {
  86. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  87. int result = 0;
  88. udelay(10);
  89. fpga_debug("CONF_DONE check ... ");
  90. if (gpio->simple_ival & FPGA_CONF_DONE) {
  91. fpga_debug("high\n");
  92. result = 1;
  93. } else
  94. fpga_debug("low\n");
  95. return result;
  96. }
  97. int fpga_status_fn(int cookie)
  98. {
  99. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  100. int result = 0;
  101. fpga_debug("STATUS check ... ");
  102. if (gpio->sint_ival & FPGA_STATUS) {
  103. fpga_debug("high\n");
  104. result = 1;
  105. } else
  106. fpga_debug("low\n");
  107. return result;
  108. }
  109. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  110. {
  111. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  112. u32 dvo = gpio->simple_dvo;
  113. fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low");
  114. if (assert_clk)
  115. dvo |= FPGA_CCLK;
  116. else
  117. dvo &= ~FPGA_CCLK;
  118. if (flush)
  119. gpio->simple_dvo = dvo;
  120. return assert_clk;
  121. }
  122. static inline int _write_fpga(u8 val)
  123. {
  124. int i;
  125. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  126. u32 dvo = gpio->simple_dvo;
  127. for (i=0; i<8; i++) {
  128. dvo &= ~FPGA_CCLK;
  129. gpio->simple_dvo = dvo;
  130. dvo &= ~FPGA_DIN;
  131. if (val & 1)
  132. dvo |= FPGA_DIN;
  133. gpio->simple_dvo = dvo;
  134. dvo |= FPGA_CCLK;
  135. gpio->simple_dvo = dvo;
  136. val >>= 1;
  137. }
  138. return 0;
  139. }
  140. int fpga_wr_fn(void *buf, size_t len, int flush, int cookie)
  141. {
  142. unsigned char *data = (unsigned char *) buf;
  143. int i;
  144. fpga_debug("fpga_wr: buf %p / size %d\n", buf, len);
  145. for (i = 0; i < len; i++)
  146. _write_fpga(data[i]);
  147. fpga_debug("\n");
  148. return FPGA_SUCCESS;
  149. }