system_manager.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2013 Altera Corporation <www.altera.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/system_manager.h>
  9. #include <asm/arch/fpga_manager.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. static struct socfpga_system_manager *sysmgr_regs =
  12. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  13. /*
  14. * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
  15. * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
  16. * CONFIG_SYSMGR_ISWGRP_HANDOFF.
  17. */
  18. static void populate_sysmgr_fpgaintf_module(void)
  19. {
  20. uint32_t handoff_val = 0;
  21. /* ISWGRP_HANDOFF_FPGAINTF */
  22. writel(0, &sysmgr_regs->iswgrp_handoff[2]);
  23. /* Enable the signal for those HPS peripherals that use FPGA. */
  24. if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA)
  25. handoff_val |= SYSMGR_FPGAINTF_NAND;
  26. if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  27. handoff_val |= SYSMGR_FPGAINTF_EMAC1;
  28. if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA)
  29. handoff_val |= SYSMGR_FPGAINTF_SDMMC;
  30. if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  31. handoff_val |= SYSMGR_FPGAINTF_EMAC0;
  32. if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  33. handoff_val |= SYSMGR_FPGAINTF_SPIM0;
  34. if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  35. handoff_val |= SYSMGR_FPGAINTF_SPIM1;
  36. /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
  37. based on pinmux setting */
  38. setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val);
  39. handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]);
  40. if (fpgamgr_test_fpga_ready()) {
  41. /* Enable the required signals only */
  42. writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module);
  43. }
  44. }
  45. /*
  46. * Configure all the pin muxes
  47. */
  48. void sysmgr_pinmux_init(void)
  49. {
  50. uint32_t regs = (uint32_t)&sysmgr_regs->emacio[0];
  51. const u8 *sys_mgr_init_table;
  52. unsigned int len;
  53. int i;
  54. sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);
  55. for (i = 0; i < len; i++) {
  56. writel(sys_mgr_init_table[i], regs);
  57. regs += sizeof(regs);
  58. }
  59. populate_sysmgr_fpgaintf_module();
  60. }
  61. /*
  62. * This bit allows the bootrom to configure the IOs after a warm reset.
  63. */
  64. void sysmgr_config_warmrstcfgio(int enable)
  65. {
  66. if (enable)
  67. setbits_le32(&sysmgr_regs->romcodegrp_ctrl,
  68. SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
  69. else
  70. clrbits_le32(&sysmgr_regs->romcodegrp_ctrl,
  71. SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
  72. }