fdt.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2009-2014 Freescale Semiconductor, Inc.
  4. * Copyright 2020 NXP
  5. *
  6. * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
  7. * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
  8. * cpu specific common code for 85xx/86xx processors.
  9. */
  10. #include <common.h>
  11. #include <cpu_func.h>
  12. #include <linux/libfdt.h>
  13. #include <fdt_support.h>
  14. #include <asm/mp.h>
  15. #include <asm/fsl_serdes.h>
  16. #include <phy.h>
  17. #include <hwconfig.h>
  18. #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
  19. #define CONFIG_USB_MAX_CONTROLLER_COUNT 1
  20. #endif
  21. #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
  22. static int ft_del_cpuhandle(void *blob, int cpuhandle)
  23. {
  24. int off, ret = -FDT_ERR_NOTFOUND;
  25. /* if we find a match, we'll delete at it which point the offsets are
  26. * invalid so we start over from the beginning
  27. */
  28. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  29. &cpuhandle, 4);
  30. while (off != -FDT_ERR_NOTFOUND) {
  31. fdt_delprop(blob, off, "cpu-handle");
  32. ret = 1;
  33. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  34. &cpuhandle, 4);
  35. }
  36. return ret;
  37. }
  38. void ft_fixup_num_cores(void *blob) {
  39. int off, num_cores, del_cores;
  40. del_cores = 0;
  41. num_cores = cpu_numcores();
  42. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  43. while (off != -FDT_ERR_NOTFOUND) {
  44. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  45. u32 phys_cpu_id = thread_to_core(*reg);
  46. if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
  47. int ph = fdt_get_phandle(blob, off);
  48. /* Delete the cpu node once there are no cpu handles */
  49. if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
  50. fdt_del_node(blob, off);
  51. del_cores++;
  52. }
  53. /* either we deleted some cpu handles or the cpu node
  54. * so we reset the offset back to the start since we
  55. * can't trust the offsets anymore
  56. */
  57. off = -1;
  58. }
  59. off = fdt_node_offset_by_prop_value(blob, off,
  60. "device_type", "cpu", 4);
  61. }
  62. debug ("%x core system found\n", num_cores);
  63. debug ("deleted %d extra core entry entries from device tree\n",
  64. del_cores);
  65. }
  66. #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
  67. int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
  68. {
  69. const char *conn;
  70. /* Do NOT apply fixup for backplane modes specified in DT */
  71. if (phyc == PHY_INTERFACE_MODE_XGMII) {
  72. conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
  73. if (is_backplane_mode(conn))
  74. return 0;
  75. }
  76. return fdt_setprop_string(blob, offset, "phy-connection-type",
  77. phy_string_for_interface(phyc));
  78. }
  79. #ifdef CONFIG_SYS_SRIO
  80. static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
  81. {
  82. int off = fdt_node_offset_by_prop_value(blob, srio_off,
  83. "cell-index", &port, 4);
  84. if (off >= 0) {
  85. off = fdt_setprop_string(blob, off, "status", "disabled");
  86. if (off > 0)
  87. printf("WARNING unable to set status for fsl,srio "
  88. "port %d: %s\n", port, fdt_strerror(off));
  89. }
  90. }
  91. static inline void ft_disable_rman(void *blob)
  92. {
  93. int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
  94. if (off >= 0) {
  95. off = fdt_setprop_string(blob, off, "status", "disabled");
  96. if (off > 0)
  97. printf("WARNING unable to set status for fsl,rman %s\n",
  98. fdt_strerror(off));
  99. }
  100. }
  101. static inline void ft_disable_rmu(void *blob)
  102. {
  103. int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
  104. if (off >= 0) {
  105. off = fdt_setprop_string(blob, off, "status", "disabled");
  106. if (off > 0)
  107. printf("WARNING unable to set status for "
  108. "fsl,srio-rmu %s\n", fdt_strerror(off));
  109. }
  110. }
  111. void ft_srio_setup(void *blob)
  112. {
  113. int srio1_used = 0, srio2_used = 0;
  114. int srio_off;
  115. /* search for srio node, if doesn't exist just return - nothing todo */
  116. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  117. if (srio_off < 0)
  118. return ;
  119. #ifdef CONFIG_SRIO1
  120. if (is_serdes_configured(SRIO1))
  121. srio1_used = 1;
  122. #endif
  123. #ifdef CONFIG_SRIO2
  124. if (is_serdes_configured(SRIO2))
  125. srio2_used = 1;
  126. #endif
  127. /* mark port1 disabled */
  128. if (!srio1_used)
  129. ft_disable_srio_port(blob, srio_off, 1);
  130. /* mark port2 disabled */
  131. if (!srio2_used)
  132. ft_disable_srio_port(blob, srio_off, 2);
  133. /* if both ports not used, disable controller, rmu and rman */
  134. if (!srio1_used && !srio2_used) {
  135. fdt_setprop_string(blob, srio_off, "status", "disabled");
  136. ft_disable_rman(blob);
  137. ft_disable_rmu(blob);
  138. }
  139. }
  140. #endif