fdt.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Copyright 2009-2012 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_serdes.h>
  30. #include <phy.h>
  31. #include <hwconfig.h>
  32. #define FSL_MAX_NUM_USB_CTRLS 2
  33. #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
  34. static int ft_del_cpuhandle(void *blob, int cpuhandle)
  35. {
  36. int off, ret = -FDT_ERR_NOTFOUND;
  37. /* if we find a match, we'll delete at it which point the offsets are
  38. * invalid so we start over from the beginning
  39. */
  40. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  41. &cpuhandle, 4);
  42. while (off != -FDT_ERR_NOTFOUND) {
  43. fdt_delprop(blob, off, "cpu-handle");
  44. ret = 1;
  45. off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
  46. &cpuhandle, 4);
  47. }
  48. return ret;
  49. }
  50. void ft_fixup_num_cores(void *blob) {
  51. int off, num_cores, del_cores;
  52. del_cores = 0;
  53. num_cores = cpu_numcores();
  54. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  55. while (off != -FDT_ERR_NOTFOUND) {
  56. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  57. u32 phys_cpu_id = thread_to_core(*reg);
  58. if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
  59. int ph = fdt_get_phandle(blob, off);
  60. /* Delete the cpu node once there are no cpu handles */
  61. if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
  62. fdt_del_node(blob, off);
  63. del_cores++;
  64. }
  65. /* either we deleted some cpu handles or the cpu node
  66. * so we reset the offset back to the start since we
  67. * can't trust the offsets anymore
  68. */
  69. off = -1;
  70. }
  71. off = fdt_node_offset_by_prop_value(blob, off,
  72. "device_type", "cpu", 4);
  73. }
  74. debug ("%x core system found\n", num_cores);
  75. debug ("deleted %d extra core entry entries from device tree\n",
  76. del_cores);
  77. }
  78. #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
  79. #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
  80. static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
  81. const char *phy_type, int start_offset)
  82. {
  83. const char *compat_dr = "fsl-usb2-dr";
  84. const char *compat_mph = "fsl-usb2-mph";
  85. const char *prop_mode = "dr_mode";
  86. const char *prop_type = "phy_type";
  87. const char *node_type = NULL;
  88. int node_offset;
  89. int err;
  90. node_offset = fdt_node_offset_by_compatible(blob,
  91. start_offset, compat_mph);
  92. if (node_offset < 0) {
  93. node_offset = fdt_node_offset_by_compatible(blob,
  94. start_offset, compat_dr);
  95. if (node_offset < 0) {
  96. printf("WARNING: could not find compatible"
  97. " node %s or %s: %s.\n", compat_mph,
  98. compat_dr, fdt_strerror(node_offset));
  99. return -1;
  100. } else
  101. node_type = compat_dr;
  102. } else
  103. node_type = compat_mph;
  104. if (mode) {
  105. err = fdt_setprop(blob, node_offset, prop_mode, mode,
  106. strlen(mode) + 1);
  107. if (err < 0)
  108. printf("WARNING: could not set %s for %s: %s.\n",
  109. prop_mode, node_type, fdt_strerror(err));
  110. }
  111. if (phy_type) {
  112. err = fdt_setprop(blob, node_offset, prop_type, phy_type,
  113. strlen(phy_type) + 1);
  114. if (err < 0)
  115. printf("WARNING: could not set %s for %s: %s.\n",
  116. prop_type, node_type, fdt_strerror(err));
  117. }
  118. return node_offset;
  119. }
  120. void fdt_fixup_dr_usb(void *blob, bd_t *bd)
  121. {
  122. const char *modes[] = { "host", "peripheral", "otg" };
  123. const char *phys[] = { "ulpi", "utmi" };
  124. const char *mode = NULL;
  125. const char *phy_type = NULL;
  126. const char *dr_mode_type = NULL;
  127. const char *dr_phy_type = NULL;
  128. char usb1_defined = 0;
  129. int usb_mode_off = -1;
  130. int usb_phy_off = -1;
  131. char str[5];
  132. int i, j;
  133. for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
  134. int mode_idx = -1, phy_idx = -1;
  135. snprintf(str, 5, "%s%d", "usb", i);
  136. if (hwconfig(str)) {
  137. for (j = 0; j < ARRAY_SIZE(modes); j++) {
  138. if (hwconfig_subarg_cmp(str, "dr_mode",
  139. modes[j])) {
  140. mode_idx = j;
  141. break;
  142. }
  143. }
  144. for (j = 0; j < ARRAY_SIZE(phys); j++) {
  145. if (hwconfig_subarg_cmp(str, "phy_type",
  146. phys[j])) {
  147. phy_idx = j;
  148. break;
  149. }
  150. }
  151. if (mode_idx < 0 || phy_idx < 0) {
  152. puts("ERROR: wrong usb mode/phy defined!!\n");
  153. return;
  154. }
  155. dr_mode_type = modes[mode_idx];
  156. dr_phy_type = phys[phy_idx];
  157. /* use usb_dr_mode and usb_phy_type if
  158. usb1_defined = 0; these variables are to
  159. be deprecated */
  160. if (!strcmp(str, "usb1"))
  161. usb1_defined = 1;
  162. if (mode_idx < 0 && phy_idx < 0) {
  163. printf("WARNING: invalid phy or mode\n");
  164. return;
  165. }
  166. }
  167. usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
  168. dr_mode_type, NULL, usb_mode_off);
  169. if (usb_mode_off < 0)
  170. return;
  171. usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
  172. NULL, dr_phy_type, usb_phy_off);
  173. if (usb_phy_off < 0)
  174. return;
  175. }
  176. if (!usb1_defined) {
  177. int usb_off = -1;
  178. mode = getenv("usb_dr_mode");
  179. phy_type = getenv("usb_phy_type");
  180. if (mode || phy_type) {
  181. printf("WARNING: usb_dr_mode and usb_phy_type "
  182. "are to be deprecated soon. Use "
  183. "hwconfig to set these values instead!!\n");
  184. fdt_fixup_usb_mode_phy_type(blob, mode,
  185. phy_type, usb_off);
  186. }
  187. }
  188. }
  189. #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */
  190. /*
  191. * update crypto node properties to a specified revision of the SEC
  192. * called with sec_rev == 0 if not on an E processor
  193. */
  194. #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
  195. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  196. {
  197. static const struct sec_rev_prop {
  198. u32 sec_rev;
  199. u32 num_channels;
  200. u32 channel_fifo_len;
  201. u32 exec_units_mask;
  202. u32 descriptor_types_mask;
  203. } sec_rev_prop_list [] = {
  204. { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
  205. { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
  206. { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
  207. { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
  208. { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
  209. { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
  210. { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
  211. };
  212. static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
  213. sizeof("fsl,secX.Y")];
  214. int crypto_node, sec_idx, err;
  215. char *p;
  216. u32 val;
  217. /* locate crypto node based on lowest common compatible */
  218. crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
  219. if (crypto_node == -FDT_ERR_NOTFOUND)
  220. return;
  221. /* delete it if not on an E-processor */
  222. if (crypto_node > 0 && !sec_rev) {
  223. fdt_del_node(blob, crypto_node);
  224. return;
  225. }
  226. /* else we got called for possible uprev */
  227. for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
  228. if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
  229. break;
  230. if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
  231. puts("warning: unknown SEC revision number\n");
  232. return;
  233. }
  234. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
  235. err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
  236. if (err < 0)
  237. printf("WARNING: could not set crypto property: %s\n",
  238. fdt_strerror(err));
  239. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
  240. err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
  241. if (err < 0)
  242. printf("WARNING: could not set crypto property: %s\n",
  243. fdt_strerror(err));
  244. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
  245. err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
  246. if (err < 0)
  247. printf("WARNING: could not set crypto property: %s\n",
  248. fdt_strerror(err));
  249. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
  250. err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
  251. if (err < 0)
  252. printf("WARNING: could not set crypto property: %s\n",
  253. fdt_strerror(err));
  254. val = 0;
  255. while (sec_idx >= 0) {
  256. p = compat_strlist + val;
  257. val += sprintf(p, "fsl,sec%d.%d",
  258. (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
  259. sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
  260. sec_idx--;
  261. }
  262. err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
  263. if (err < 0)
  264. printf("WARNING: could not set crypto property: %s\n",
  265. fdt_strerror(err));
  266. }
  267. #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
  268. static u8 caam_get_era(void)
  269. {
  270. static const struct {
  271. u16 ip_id;
  272. u8 maj_rev;
  273. u8 era;
  274. } caam_eras[] = {
  275. {0x0A10, 1, 1},
  276. {0x0A10, 2, 2},
  277. {0x0A12, 1, 3},
  278. {0x0A14, 1, 3},
  279. {0x0A14, 2, 4},
  280. {0x0A16, 1, 4},
  281. {0x0A10, 3, 4},
  282. {0x0A11, 1, 4},
  283. {0x0A18, 1, 4},
  284. {0x0A11, 2, 5},
  285. {0x0A12, 2, 5},
  286. {0x0A13, 1, 5},
  287. {0x0A1C, 1, 5}
  288. };
  289. ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  290. u32 secvid_ms = in_be32(&sec->secvid_ms);
  291. u32 ccbvid = in_be32(&sec->ccbvid);
  292. u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >>
  293. SEC_SECVID_MS_IPID_SHIFT;
  294. u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >>
  295. SEC_SECVID_MS_MAJ_REV_SHIFT;
  296. u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT;
  297. int i;
  298. if (era) /* This is '0' prior to CAAM ERA-6 */
  299. return era;
  300. for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
  301. if (caam_eras[i].ip_id == ip_id &&
  302. caam_eras[i].maj_rev == maj_rev)
  303. return caam_eras[i].era;
  304. return 0;
  305. }
  306. static void fdt_fixup_crypto_era(void *blob, u32 era)
  307. {
  308. int err;
  309. int crypto_node;
  310. crypto_node = fdt_path_offset(blob, "crypto");
  311. if (crypto_node < 0) {
  312. printf("WARNING: Missing crypto node\n");
  313. return;
  314. }
  315. err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era,
  316. sizeof(era));
  317. if (err < 0) {
  318. printf("ERROR: could not set fsl,sec-era property: %s\n",
  319. fdt_strerror(err));
  320. }
  321. }
  322. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  323. {
  324. u8 era;
  325. if (!sec_rev) {
  326. fdt_del_node_and_alias(blob, "crypto");
  327. return;
  328. }
  329. /* Add SEC ERA information in compatible */
  330. era = caam_get_era();
  331. if (era) {
  332. fdt_fixup_crypto_era(blob, era);
  333. } else {
  334. printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
  335. sec_rev);
  336. }
  337. }
  338. #endif
  339. int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
  340. {
  341. return fdt_setprop_string(blob, offset, "phy-connection-type",
  342. phy_string_for_interface(phyc));
  343. }
  344. #ifdef CONFIG_SYS_SRIO
  345. static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
  346. {
  347. int off = fdt_node_offset_by_prop_value(blob, srio_off,
  348. "cell-index", &port, 4);
  349. if (off >= 0) {
  350. off = fdt_setprop_string(blob, off, "status", "disabled");
  351. if (off > 0)
  352. printf("WARNING unable to set status for fsl,srio "
  353. "port %d: %s\n", port, fdt_strerror(off));
  354. }
  355. }
  356. static inline void ft_disable_rman(void *blob)
  357. {
  358. int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
  359. if (off >= 0) {
  360. off = fdt_setprop_string(blob, off, "status", "disabled");
  361. if (off > 0)
  362. printf("WARNING unable to set status for fsl,rman %s\n",
  363. fdt_strerror(off));
  364. }
  365. }
  366. static inline void ft_disable_rmu(void *blob)
  367. {
  368. int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
  369. if (off >= 0) {
  370. off = fdt_setprop_string(blob, off, "status", "disabled");
  371. if (off > 0)
  372. printf("WARNING unable to set status for "
  373. "fsl,srio-rmu %s\n", fdt_strerror(off));
  374. }
  375. }
  376. void ft_srio_setup(void *blob)
  377. {
  378. int srio1_used = 0, srio2_used = 0;
  379. int srio_off;
  380. /* search for srio node, if doesn't exist just return - nothing todo */
  381. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  382. if (srio_off < 0)
  383. return ;
  384. #ifdef CONFIG_SRIO1
  385. if (is_serdes_configured(SRIO1))
  386. srio1_used = 1;
  387. #endif
  388. #ifdef CONFIG_SRIO2
  389. if (is_serdes_configured(SRIO2))
  390. srio2_used = 1;
  391. #endif
  392. /* mark port1 disabled */
  393. if (!srio1_used)
  394. ft_disable_srio_port(blob, srio_off, 1);
  395. /* mark port2 disabled */
  396. if (!srio2_used)
  397. ft_disable_srio_port(blob, srio_off, 2);
  398. /* if both ports not used, disable controller, rmu and rman */
  399. if (!srio1_used && !srio2_used) {
  400. fdt_setprop_string(blob, srio_off, "status", "disabled");
  401. ft_disable_rman(blob);
  402. ft_disable_rmu(blob);
  403. }
  404. }
  405. #endif