misc_s10.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
  4. *
  5. */
  6. #include <altera.h>
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <fdtdec.h>
  10. #include <miiphy.h>
  11. #include <netdev.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/reset_manager.h>
  14. #include <asm/arch/system_manager.h>
  15. #include <asm/arch/misc.h>
  16. #include <asm/pl310.h>
  17. #include <linux/libfdt.h>
  18. #include <dt-bindings/reset/altr,rst-mgr-s10.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. static struct socfpga_system_manager *sysmgr_regs =
  21. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  22. /*
  23. * DesignWare Ethernet initialization
  24. */
  25. #ifdef CONFIG_ETH_DESIGNWARE
  26. static u32 socfpga_phymode_setup(u32 gmac_index, const char *phymode)
  27. {
  28. u32 modereg;
  29. if (!phymode)
  30. return -EINVAL;
  31. if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii"))
  32. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
  33. else if (!strcmp(phymode, "rgmii"))
  34. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
  35. else if (!strcmp(phymode, "rmii"))
  36. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
  37. else
  38. return -EINVAL;
  39. clrsetbits_le32(&sysmgr_regs->emac0 + gmac_index,
  40. SYSMGR_EMACGRP_CTRL_PHYSEL_MASK,
  41. modereg);
  42. return 0;
  43. }
  44. static int socfpga_set_phymode(void)
  45. {
  46. const void *fdt = gd->fdt_blob;
  47. struct fdtdec_phandle_args args;
  48. const char *phy_mode;
  49. u32 gmac_index;
  50. int nodes[2]; /* Max. 3 GMACs */
  51. int ret, count;
  52. int i, node;
  53. count = fdtdec_find_aliases_for_id(fdt, "ethernet",
  54. COMPAT_ALTERA_SOCFPGA_DWMAC,
  55. nodes, ARRAY_SIZE(nodes));
  56. for (i = 0; i < count; i++) {
  57. node = nodes[i];
  58. if (node <= 0)
  59. continue;
  60. ret = fdtdec_parse_phandle_with_args(fdt, node, "resets",
  61. "#reset-cells", 1, 0,
  62. &args);
  63. if (ret || args.args_count != 1) {
  64. debug("GMAC%i: Failed to parse DT 'resets'!\n", i);
  65. continue;
  66. }
  67. gmac_index = args.args[0] - EMAC0_RESET;
  68. phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL);
  69. ret = socfpga_phymode_setup(gmac_index, phy_mode);
  70. if (ret) {
  71. debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i);
  72. continue;
  73. }
  74. }
  75. return 0;
  76. }
  77. #else
  78. static int socfpga_set_phymode(void)
  79. {
  80. return 0;
  81. };
  82. #endif
  83. /*
  84. * Print CPU information
  85. */
  86. #if defined(CONFIG_DISPLAY_CPUINFO)
  87. int print_cpuinfo(void)
  88. {
  89. puts("CPU: Intel FPGA SoCFPGA Platform (ARMv8 64bit Cortex-A53)\n");
  90. return 0;
  91. }
  92. #endif
  93. #ifdef CONFIG_ARCH_MISC_INIT
  94. int arch_misc_init(void)
  95. {
  96. char qspi_string[13];
  97. sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz());
  98. env_set("qspi_clock", qspi_string);
  99. socfpga_set_phymode();
  100. return 0;
  101. }
  102. #endif
  103. int arch_early_init_r(void)
  104. {
  105. return 0;
  106. }
  107. void do_bridge_reset(int enable)
  108. {
  109. socfpga_bridges_reset(enable);
  110. }