fpga.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <spartan3.h>
  13. #include <command.h>
  14. #include <asm/io.h>
  15. #include "fpga.h"
  16. #include "mvsmr.h"
  17. xilinx_spartan3_slave_serial_fns fpga_fns = {
  18. fpga_pre_config_fn,
  19. fpga_pgm_fn,
  20. fpga_clk_fn,
  21. fpga_init_fn,
  22. fpga_done_fn,
  23. fpga_wr_fn,
  24. 0
  25. };
  26. xilinx_desc spartan3 = {
  27. xilinx_spartan2,
  28. slave_serial,
  29. XILINX_XC3S200_SIZE,
  30. (void *) &fpga_fns,
  31. 0,
  32. };
  33. DECLARE_GLOBAL_DATA_PTR;
  34. int mvsmr_init_fpga(void)
  35. {
  36. fpga_init();
  37. fpga_add(fpga_xilinx, &spartan3);
  38. return 1;
  39. }
  40. int fpga_init_fn(int cookie)
  41. {
  42. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  43. if (in_be32(&gpio->simple_ival) & FPGA_CONFIG)
  44. return 0;
  45. return 1;
  46. }
  47. int fpga_done_fn(int cookie)
  48. {
  49. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  50. int result = 0;
  51. udelay(10);
  52. if (in_be32(&gpio->simple_ival) & FPGA_DONE)
  53. result = 1;
  54. return result;
  55. }
  56. int fpga_pgm_fn(int assert, int flush, int cookie)
  57. {
  58. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  59. if (!assert)
  60. setbits_8(&gpio->sint_dvo, FPGA_STATUS);
  61. else
  62. clrbits_8(&gpio->sint_dvo, FPGA_STATUS);
  63. return assert;
  64. }
  65. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  66. {
  67. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  68. if (assert_clk)
  69. setbits_be32(&gpio->simple_dvo, FPGA_CCLK);
  70. else
  71. clrbits_be32(&gpio->simple_dvo, FPGA_CCLK);
  72. return assert_clk;
  73. }
  74. int fpga_wr_fn(int assert_write, int flush, int cookie)
  75. {
  76. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  77. if (assert_write)
  78. setbits_be32(&gpio->simple_dvo, FPGA_DIN);
  79. else
  80. clrbits_be32(&gpio->simple_dvo, FPGA_DIN);
  81. return assert_write;
  82. }
  83. int fpga_pre_config_fn(int cookie)
  84. {
  85. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  86. setbits_8(&gpio->sint_dvo, FPGA_STATUS);
  87. return 0;
  88. }