fdt.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright 2009-2010 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. #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
  31. static int ft_del_cpuhandle(void *blob, int cpuhandle)
  32. {
  33. int off, ret = -FDT_ERR_NOTFOUND;
  34. /* if we find a match, we'll delete at it which point the offsets are
  35. * invalid so we start over from the beginning
  36. */
  37. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  38. &cpuhandle, 4);
  39. while (off != -FDT_ERR_NOTFOUND) {
  40. fdt_delprop(blob, off, "cpu-handle");
  41. ret = 1;
  42. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  43. &cpuhandle, 4);
  44. }
  45. return ret;
  46. }
  47. void ft_fixup_num_cores(void *blob) {
  48. int off, num_cores, del_cores;
  49. del_cores = 0;
  50. num_cores = cpu_numcores();
  51. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  52. while (off != -FDT_ERR_NOTFOUND) {
  53. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  54. if ((*reg > num_cores-1) || (is_core_disabled(*reg))) {
  55. int ph = fdt_get_phandle(blob, off);
  56. /* Delete the cpu node once there are no cpu handles */
  57. if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
  58. fdt_del_node(blob, off);
  59. del_cores++;
  60. }
  61. /* either we deleted some cpu handles or the cpu node
  62. * so we reset the offset back to the start since we
  63. * can't trust the offsets anymore
  64. */
  65. off = -1;
  66. }
  67. off = fdt_node_offset_by_prop_value(blob, off,
  68. "device_type", "cpu", 4);
  69. }
  70. debug ("%x core system found\n", num_cores);
  71. debug ("deleted %d extra core entry entries from device tree\n",
  72. del_cores);
  73. }
  74. #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
  75. #ifdef CONFIG_HAS_FSL_DR_USB
  76. void fdt_fixup_dr_usb(void *blob, bd_t *bd)
  77. {
  78. char *mode;
  79. char *type;
  80. const char *compat = "fsl-usb2-dr";
  81. const char *prop_mode = "dr_mode";
  82. const char *prop_type = "phy_type";
  83. int node_offset;
  84. int err;
  85. mode = getenv("usb_dr_mode");
  86. type = getenv("usb_phy_type");
  87. if (!mode && !type)
  88. return;
  89. node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
  90. if (node_offset < 0) {
  91. printf("WARNING: could not find compatible node %s: %s.\n",
  92. compat, fdt_strerror(node_offset));
  93. return;
  94. }
  95. if (mode) {
  96. err = fdt_setprop(blob, node_offset, prop_mode, mode,
  97. strlen(mode) + 1);
  98. if (err < 0)
  99. printf("WARNING: could not set %s for %s: %s.\n",
  100. prop_mode, compat, fdt_strerror(err));
  101. }
  102. if (type) {
  103. err = fdt_setprop(blob, node_offset, prop_type, type,
  104. strlen(type) + 1);
  105. if (err < 0)
  106. printf("WARNING: could not set %s for %s: %s.\n",
  107. prop_type, compat, fdt_strerror(err));
  108. }
  109. }
  110. #endif /* CONFIG_HAS_FSL_DR_USB */
  111. /*
  112. * update crypto node properties to a specified revision of the SEC
  113. * called with sec_rev == 0 if not on an E processor
  114. */
  115. #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
  116. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  117. {
  118. const struct sec_rev_prop {
  119. u32 sec_rev;
  120. u32 num_channels;
  121. u32 channel_fifo_len;
  122. u32 exec_units_mask;
  123. u32 descriptor_types_mask;
  124. } sec_rev_prop_list [] = {
  125. { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
  126. { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
  127. { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
  128. { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
  129. { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
  130. { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
  131. { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
  132. };
  133. char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
  134. sizeof("fsl,secX.Y")];
  135. int crypto_node, sec_idx, err;
  136. char *p;
  137. u32 val;
  138. /* locate crypto node based on lowest common compatible */
  139. crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
  140. if (crypto_node == -FDT_ERR_NOTFOUND)
  141. return;
  142. /* delete it if not on an E-processor */
  143. if (crypto_node > 0 && !sec_rev) {
  144. fdt_del_node(blob, crypto_node);
  145. return;
  146. }
  147. /* else we got called for possible uprev */
  148. for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
  149. if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
  150. break;
  151. if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
  152. puts("warning: unknown SEC revision number\n");
  153. return;
  154. }
  155. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
  156. err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
  157. if (err < 0)
  158. printf("WARNING: could not set crypto property: %s\n",
  159. fdt_strerror(err));
  160. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
  161. err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
  162. if (err < 0)
  163. printf("WARNING: could not set crypto property: %s\n",
  164. fdt_strerror(err));
  165. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
  166. err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
  167. if (err < 0)
  168. printf("WARNING: could not set crypto property: %s\n",
  169. fdt_strerror(err));
  170. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
  171. err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
  172. if (err < 0)
  173. printf("WARNING: could not set crypto property: %s\n",
  174. fdt_strerror(err));
  175. val = 0;
  176. while (sec_idx >= 0) {
  177. p = compat_strlist + val;
  178. val += sprintf(p, "fsl,sec%d.%d",
  179. (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
  180. sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
  181. sec_idx--;
  182. }
  183. err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
  184. if (err < 0)
  185. printf("WARNING: could not set crypto property: %s\n",
  186. fdt_strerror(err));
  187. }
  188. #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
  189. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  190. {
  191. if (!sec_rev)
  192. fdt_del_node_and_alias(blob, "crypto");
  193. }
  194. #endif
  195. int fdt_fixup_phy_connection(void *blob, int offset, enum fsl_phy_enet_if phyc)
  196. {
  197. static const char *fsl_phy_enet_if_str[] = {
  198. [MII] = "mii",
  199. [RMII] = "rmii",
  200. [GMII] = "gmii",
  201. [RGMII] = "rgmii",
  202. [RGMII_ID] = "rgmii-id",
  203. [RGMII_RXID] = "rgmii-rxid",
  204. [SGMII] = "sgmii",
  205. [TBI] = "tbi",
  206. [RTBI] = "rtbi",
  207. [XAUI] = "xgmii",
  208. [FSL_ETH_IF_NONE] = "",
  209. };
  210. if (phyc > ARRAY_SIZE(fsl_phy_enet_if_str))
  211. return fdt_setprop_string(blob, offset, "phy-connection-type", "");
  212. return fdt_setprop_string(blob, offset, "phy-connection-type",
  213. fsl_phy_enet_if_str[phyc]);
  214. }