fdt.c 4.0 KB

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