fpga.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * (C) Copyright 2002
  3. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  4. * Keith Outwater, keith_outwater@mvis.com.
  5. *
  6. * (C) Copyright 2010
  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 <spartan3.h>
  30. #include <command.h>
  31. #include <asm/io.h>
  32. #include "fpga.h"
  33. #include "mvsmr.h"
  34. Xilinx_Spartan3_Slave_Serial_fns fpga_fns = {
  35. fpga_pre_config_fn,
  36. fpga_pgm_fn,
  37. fpga_clk_fn,
  38. fpga_init_fn,
  39. fpga_done_fn,
  40. fpga_wr_fn,
  41. 0
  42. };
  43. Xilinx_desc spartan3 = {
  44. Xilinx_Spartan2,
  45. slave_serial,
  46. XILINX_XC3S200_SIZE,
  47. (void *) &fpga_fns,
  48. 0,
  49. };
  50. DECLARE_GLOBAL_DATA_PTR;
  51. int mvsmr_init_fpga(void)
  52. {
  53. fpga_init();
  54. fpga_add(fpga_xilinx, &spartan3);
  55. return 1;
  56. }
  57. int fpga_init_fn(int cookie)
  58. {
  59. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  60. if (in_be32(&gpio->simple_ival) & FPGA_CONFIG)
  61. return 0;
  62. return 1;
  63. }
  64. int fpga_done_fn(int cookie)
  65. {
  66. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  67. int result = 0;
  68. udelay(10);
  69. if (in_be32(&gpio->simple_ival) & FPGA_DONE)
  70. result = 1;
  71. return result;
  72. }
  73. int fpga_pgm_fn(int assert, int flush, int cookie)
  74. {
  75. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  76. if (!assert)
  77. setbits_8(&gpio->sint_dvo, FPGA_STATUS);
  78. else
  79. clrbits_8(&gpio->sint_dvo, FPGA_STATUS);
  80. return assert;
  81. }
  82. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  83. {
  84. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  85. if (assert_clk)
  86. setbits_be32(&gpio->simple_dvo, FPGA_CCLK);
  87. else
  88. clrbits_be32(&gpio->simple_dvo, FPGA_CCLK);
  89. return assert_clk;
  90. }
  91. int fpga_wr_fn(int assert_write, int flush, int cookie)
  92. {
  93. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  94. if (assert_write)
  95. setbits_be32(&gpio->simple_dvo, FPGA_DIN);
  96. else
  97. clrbits_be32(&gpio->simple_dvo, FPGA_DIN);
  98. return assert_write;
  99. }
  100. int fpga_pre_config_fn(int cookie)
  101. {
  102. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  103. setbits_8(&gpio->sint_dvo, FPGA_STATUS);
  104. return 0;
  105. }