fpga.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. };
  47. Altera_desc cyclone2 = {
  48. Altera_CYC2,
  49. passive_serial,
  50. Altera_EP2C8_SIZE,
  51. (void *) &altera_fns,
  52. NULL,
  53. };
  54. DECLARE_GLOBAL_DATA_PTR;
  55. int mvbc_p_init_fpga(void)
  56. {
  57. fpga_debug("Initialize FPGA interface\n");
  58. fpga_init();
  59. fpga_add(fpga_altera, &cyclone2);
  60. fpga_config_fn(0, 1, 0);
  61. udelay(60);
  62. return 1;
  63. }
  64. int fpga_null_fn(int cookie)
  65. {
  66. return 0;
  67. }
  68. int fpga_config_fn(int assert, int flush, int cookie)
  69. {
  70. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  71. u32 dvo = gpio->simple_dvo;
  72. fpga_debug("SET config : %s\n", assert ? "low" : "high");
  73. if (assert)
  74. dvo |= FPGA_CONFIG;
  75. else
  76. dvo &= ~FPGA_CONFIG;
  77. if (flush)
  78. gpio->simple_dvo = dvo;
  79. return assert;
  80. }
  81. int fpga_done_fn(int cookie)
  82. {
  83. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  84. int result = 0;
  85. udelay(10);
  86. fpga_debug("CONF_DONE check ... ");
  87. if (gpio->simple_ival & FPGA_CONF_DONE) {
  88. fpga_debug("high\n");
  89. result = 1;
  90. } else
  91. fpga_debug("low\n");
  92. return result;
  93. }
  94. int fpga_status_fn(int cookie)
  95. {
  96. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  97. int result = 0;
  98. fpga_debug("STATUS check ... ");
  99. if (gpio->sint_ival & FPGA_STATUS) {
  100. fpga_debug("high\n");
  101. result = 1;
  102. } else
  103. fpga_debug("low\n");
  104. return result;
  105. }
  106. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  107. {
  108. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  109. u32 dvo = gpio->simple_dvo;
  110. fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low");
  111. if (assert_clk)
  112. dvo |= FPGA_CCLK;
  113. else
  114. dvo &= ~FPGA_CCLK;
  115. if (flush)
  116. gpio->simple_dvo = dvo;
  117. return assert_clk;
  118. }
  119. static inline int _write_fpga(u8 val)
  120. {
  121. int i;
  122. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  123. u32 dvo = gpio->simple_dvo;
  124. for (i=0; i<8; i++) {
  125. dvo &= ~FPGA_CCLK;
  126. gpio->simple_dvo = dvo;
  127. dvo &= ~FPGA_DIN;
  128. if (val & 1)
  129. dvo |= FPGA_DIN;
  130. gpio->simple_dvo = dvo;
  131. dvo |= FPGA_CCLK;
  132. gpio->simple_dvo = dvo;
  133. val >>= 1;
  134. }
  135. return 0;
  136. }
  137. int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie)
  138. {
  139. unsigned char *data = (unsigned char *) buf;
  140. int i;
  141. fpga_debug("fpga_wr: buf %p / size %d\n", buf, len);
  142. for (i = 0; i < len; i++)
  143. _write_fpga(data[i]);
  144. fpga_debug("\n");
  145. return FPGA_SUCCESS;
  146. }