fdt.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Copyright 2009-2011 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. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <libfdt.h>
  27. #include <fdt_support.h>
  28. #include <asm/mp.h>
  29. #include <asm/fsl_enet.h>
  30. #include <asm/fsl_serdes.h>
  31. #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
  32. static int ft_del_cpuhandle(void *blob, int cpuhandle)
  33. {
  34. int off, ret = -FDT_ERR_NOTFOUND;
  35. /* if we find a match, we'll delete at it which point the offsets are
  36. * invalid so we start over from the beginning
  37. */
  38. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  39. &cpuhandle, 4);
  40. while (off != -FDT_ERR_NOTFOUND) {
  41. fdt_delprop(blob, off, "cpu-handle");
  42. ret = 1;
  43. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  44. &cpuhandle, 4);
  45. }
  46. return ret;
  47. }
  48. void ft_fixup_num_cores(void *blob) {
  49. int off, num_cores, del_cores;
  50. del_cores = 0;
  51. num_cores = cpu_numcores();
  52. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  53. while (off != -FDT_ERR_NOTFOUND) {
  54. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  55. if ((*reg > num_cores-1) || (is_core_disabled(*reg))) {
  56. int ph = fdt_get_phandle(blob, off);
  57. /* Delete the cpu node once there are no cpu handles */
  58. if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
  59. fdt_del_node(blob, off);
  60. del_cores++;
  61. }
  62. /* either we deleted some cpu handles or the cpu node
  63. * so we reset the offset back to the start since we
  64. * can't trust the offsets anymore
  65. */
  66. off = -1;
  67. }
  68. off = fdt_node_offset_by_prop_value(blob, off,
  69. "device_type", "cpu", 4);
  70. }
  71. debug ("%x core system found\n", num_cores);
  72. debug ("deleted %d extra core entry entries from device tree\n",
  73. del_cores);
  74. }
  75. #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
  76. #ifdef CONFIG_HAS_FSL_DR_USB
  77. void fdt_fixup_dr_usb(void *blob, bd_t *bd)
  78. {
  79. char *mode;
  80. char *type;
  81. const char *compat = "fsl-usb2-dr";
  82. const char *prop_mode = "dr_mode";
  83. const char *prop_type = "phy_type";
  84. int node_offset;
  85. int err;
  86. mode = getenv("usb_dr_mode");
  87. type = getenv("usb_phy_type");
  88. if (!mode && !type)
  89. return;
  90. node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
  91. if (node_offset < 0) {
  92. printf("WARNING: could not find compatible node %s: %s.\n",
  93. compat, fdt_strerror(node_offset));
  94. return;
  95. }
  96. if (mode) {
  97. err = fdt_setprop(blob, node_offset, prop_mode, mode,
  98. strlen(mode) + 1);
  99. if (err < 0)
  100. printf("WARNING: could not set %s for %s: %s.\n",
  101. prop_mode, compat, fdt_strerror(err));
  102. }
  103. if (type) {
  104. err = fdt_setprop(blob, node_offset, prop_type, type,
  105. strlen(type) + 1);
  106. if (err < 0)
  107. printf("WARNING: could not set %s for %s: %s.\n",
  108. prop_type, compat, fdt_strerror(err));
  109. }
  110. }
  111. #endif /* CONFIG_HAS_FSL_DR_USB */
  112. /*
  113. * update crypto node properties to a specified revision of the SEC
  114. * called with sec_rev == 0 if not on an E processor
  115. */
  116. #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
  117. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  118. {
  119. const struct sec_rev_prop {
  120. u32 sec_rev;
  121. u32 num_channels;
  122. u32 channel_fifo_len;
  123. u32 exec_units_mask;
  124. u32 descriptor_types_mask;
  125. } sec_rev_prop_list [] = {
  126. { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
  127. { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
  128. { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
  129. { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
  130. { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
  131. { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
  132. { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
  133. };
  134. char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
  135. sizeof("fsl,secX.Y")];
  136. int crypto_node, sec_idx, err;
  137. char *p;
  138. u32 val;
  139. /* locate crypto node based on lowest common compatible */
  140. crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
  141. if (crypto_node == -FDT_ERR_NOTFOUND)
  142. return;
  143. /* delete it if not on an E-processor */
  144. if (crypto_node > 0 && !sec_rev) {
  145. fdt_del_node(blob, crypto_node);
  146. return;
  147. }
  148. /* else we got called for possible uprev */
  149. for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
  150. if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
  151. break;
  152. if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
  153. puts("warning: unknown SEC revision number\n");
  154. return;
  155. }
  156. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
  157. err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
  158. if (err < 0)
  159. printf("WARNING: could not set crypto property: %s\n",
  160. fdt_strerror(err));
  161. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
  162. err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
  163. if (err < 0)
  164. printf("WARNING: could not set crypto property: %s\n",
  165. fdt_strerror(err));
  166. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
  167. err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
  168. if (err < 0)
  169. printf("WARNING: could not set crypto property: %s\n",
  170. fdt_strerror(err));
  171. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
  172. err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
  173. if (err < 0)
  174. printf("WARNING: could not set crypto property: %s\n",
  175. fdt_strerror(err));
  176. val = 0;
  177. while (sec_idx >= 0) {
  178. p = compat_strlist + val;
  179. val += sprintf(p, "fsl,sec%d.%d",
  180. (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
  181. sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
  182. sec_idx--;
  183. }
  184. err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
  185. if (err < 0)
  186. printf("WARNING: could not set crypto property: %s\n",
  187. fdt_strerror(err));
  188. }
  189. #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
  190. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  191. {
  192. if (!sec_rev)
  193. fdt_del_node_and_alias(blob, "crypto");
  194. }
  195. #endif
  196. int fdt_fixup_phy_connection(void *blob, int offset, enum fsl_phy_enet_if phyc)
  197. {
  198. static const char *fsl_phy_enet_if_str[] = {
  199. [MII] = "mii",
  200. [RMII] = "rmii",
  201. [GMII] = "gmii",
  202. [RGMII] = "rgmii",
  203. [RGMII_ID] = "rgmii-id",
  204. [RGMII_RXID] = "rgmii-rxid",
  205. [SGMII] = "sgmii",
  206. [TBI] = "tbi",
  207. [RTBI] = "rtbi",
  208. [XAUI] = "xgmii",
  209. [FSL_ETH_IF_NONE] = "",
  210. };
  211. if (phyc > ARRAY_SIZE(fsl_phy_enet_if_str))
  212. return fdt_setprop_string(blob, offset, "phy-connection-type", "");
  213. return fdt_setprop_string(blob, offset, "phy-connection-type",
  214. fsl_phy_enet_if_str[phyc]);
  215. }
  216. #ifdef CONFIG_SYS_SRIO
  217. void ft_srio_setup(void *blob)
  218. {
  219. #ifdef CONFIG_SRIO1
  220. if (!is_serdes_configured(SRIO1)) {
  221. fdt_del_node_and_alias(blob, "rio0");
  222. }
  223. #else
  224. fdt_del_node_and_alias(blob, "rio0");
  225. #endif
  226. #ifdef CONFIG_SRIO2
  227. if (!is_serdes_configured(SRIO2)) {
  228. fdt_del_node_and_alias(blob, "rio1");
  229. }
  230. #else
  231. fdt_del_node_and_alias(blob, "rio1");
  232. #endif
  233. }
  234. #endif