socfpga.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <linux/errno.h>
  10. #include <asm/arch/fpga_manager.h>
  11. #include <asm/arch/reset_manager.h>
  12. #include <asm/arch/system_manager.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /* Timeout count */
  15. #define FPGA_TIMEOUT_CNT 0x1000000
  16. static struct socfpga_fpga_manager *fpgamgr_regs =
  17. (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS;
  18. int fpgamgr_dclkcnt_set(unsigned long cnt)
  19. {
  20. unsigned long i;
  21. /* Clear any existing done status */
  22. if (readl(&fpgamgr_regs->dclkstat))
  23. writel(0x1, &fpgamgr_regs->dclkstat);
  24. /* Write the dclkcnt */
  25. writel(cnt, &fpgamgr_regs->dclkcnt);
  26. /* Wait till the dclkcnt done */
  27. for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  28. if (!readl(&fpgamgr_regs->dclkstat))
  29. continue;
  30. writel(0x1, &fpgamgr_regs->dclkstat);
  31. return 0;
  32. }
  33. return -ETIMEDOUT;
  34. }
  35. /* Write the RBF data to FPGA Manager */
  36. void fpgamgr_program_write(const void *rbf_data, size_t rbf_size)
  37. {
  38. uint32_t src = (uint32_t)rbf_data;
  39. uint32_t dst = SOCFPGA_FPGAMGRDATA_ADDRESS;
  40. /* Number of loops for 32-byte long copying. */
  41. uint32_t loops32 = rbf_size / 32;
  42. /* Number of loops for 4-byte long copying + trailing bytes */
  43. uint32_t loops4 = DIV_ROUND_UP(rbf_size % 32, 4);
  44. asm volatile(
  45. " cmp %2, #0\n"
  46. " beq 2f\n"
  47. "1: ldmia %0!, {r0-r7}\n"
  48. " stmia %1!, {r0-r7}\n"
  49. " sub %1, #32\n"
  50. " subs %2, #1\n"
  51. " bne 1b\n"
  52. "2: cmp %3, #0\n"
  53. " beq 4f\n"
  54. "3: ldr %2, [%0], #4\n"
  55. " str %2, [%1]\n"
  56. " subs %3, #1\n"
  57. " bne 3b\n"
  58. "4: nop\n"
  59. : "+r"(src), "+r"(dst), "+r"(loops32), "+r"(loops4) :
  60. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "cc");
  61. }