fpga_manager.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2012 Altera Corporation <www.altera.com>
  3. * All rights reserved.
  4. *
  5. * This file contains only support functions used also by the SoCFPGA
  6. * platform code, the real meat is located in drivers/fpga/socfpga.c .
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. #include <common.h>
  11. #include <asm/io.h>
  12. #include <linux/errno.h>
  13. #include <asm/arch/fpga_manager.h>
  14. #include <asm/arch/reset_manager.h>
  15. #include <asm/arch/system_manager.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /* Timeout count */
  18. #define FPGA_TIMEOUT_CNT 0x1000000
  19. static struct socfpga_fpga_manager *fpgamgr_regs =
  20. (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS;
  21. /* Check whether FPGA Init_Done signal is high */
  22. static int is_fpgamgr_initdone_high(void)
  23. {
  24. unsigned long val;
  25. val = readl(&fpgamgr_regs->gpio_ext_porta);
  26. return val & FPGAMGRREGS_MON_GPIO_EXT_PORTA_ID_MASK;
  27. }
  28. /* Get the FPGA mode */
  29. int fpgamgr_get_mode(void)
  30. {
  31. unsigned long val;
  32. val = readl(&fpgamgr_regs->stat);
  33. return val & FPGAMGRREGS_STAT_MODE_MASK;
  34. }
  35. /* Check whether FPGA is ready to be accessed */
  36. int fpgamgr_test_fpga_ready(void)
  37. {
  38. /* Check for init done signal */
  39. if (!is_fpgamgr_initdone_high())
  40. return 0;
  41. /* Check again to avoid false glitches */
  42. if (!is_fpgamgr_initdone_high())
  43. return 0;
  44. if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_USERMODE)
  45. return 0;
  46. return 1;
  47. }
  48. /* Poll until FPGA is ready to be accessed or timeout occurred */
  49. int fpgamgr_poll_fpga_ready(void)
  50. {
  51. unsigned long i;
  52. /* If FPGA is blank, wait till WD invoke warm reset */
  53. for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  54. /* check for init done signal */
  55. if (!is_fpgamgr_initdone_high())
  56. continue;
  57. /* check again to avoid false glitches */
  58. if (!is_fpgamgr_initdone_high())
  59. continue;
  60. return 1;
  61. }
  62. return 0;
  63. }