misc_s10.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. !strcmp(phymode, "sgmii"))
  33. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
  34. else if (!strcmp(phymode, "rgmii"))
  35. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
  36. else if (!strcmp(phymode, "rmii"))
  37. modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
  38. else
  39. return -EINVAL;
  40. clrsetbits_le32(&sysmgr_regs->emac0 + gmac_index,
  41. SYSMGR_EMACGRP_CTRL_PHYSEL_MASK,
  42. modereg);
  43. return 0;
  44. }
  45. static int socfpga_set_phymode(void)
  46. {
  47. const void *fdt = gd->fdt_blob;
  48. struct fdtdec_phandle_args args;
  49. const char *phy_mode;
  50. u32 gmac_index;
  51. int nodes[3]; /* Max. 3 GMACs */
  52. int ret, count;
  53. int i, node;
  54. count = fdtdec_find_aliases_for_id(fdt, "ethernet",
  55. COMPAT_ALTERA_SOCFPGA_DWMAC,
  56. nodes, ARRAY_SIZE(nodes));
  57. for (i = 0; i < count; i++) {
  58. node = nodes[i];
  59. if (node <= 0)
  60. continue;
  61. ret = fdtdec_parse_phandle_with_args(fdt, node, "resets",
  62. "#reset-cells", 1, 0,
  63. &args);
  64. if (ret || args.args_count != 1) {
  65. debug("GMAC%i: Failed to parse DT 'resets'!\n", i);
  66. continue;
  67. }
  68. gmac_index = args.args[0] - EMAC0_RESET;
  69. phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL);
  70. ret = socfpga_phymode_setup(gmac_index, phy_mode);
  71. if (ret) {
  72. debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i);
  73. continue;
  74. }
  75. }
  76. return 0;
  77. }
  78. #else
  79. static int socfpga_set_phymode(void)
  80. {
  81. return 0;
  82. };
  83. #endif
  84. /*
  85. * Print CPU information
  86. */
  87. #if defined(CONFIG_DISPLAY_CPUINFO)
  88. int print_cpuinfo(void)
  89. {
  90. puts("CPU: Intel FPGA SoCFPGA Platform (ARMv8 64bit Cortex-A53)\n");
  91. return 0;
  92. }
  93. #endif
  94. #ifdef CONFIG_ARCH_MISC_INIT
  95. int arch_misc_init(void)
  96. {
  97. char qspi_string[13];
  98. sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz());
  99. env_set("qspi_clock", qspi_string);
  100. socfpga_set_phymode();
  101. return 0;
  102. }
  103. #endif
  104. int arch_early_init_r(void)
  105. {
  106. return 0;
  107. }
  108. void do_bridge_reset(int enable)
  109. {
  110. socfpga_bridges_reset(enable);
  111. }