fdt.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <linux/libfdt.h>
  7. #include <fdt_support.h>
  8. #include <asm/io.h>
  9. #include <asm/processor.h>
  10. #include <asm/arch/clock.h>
  11. #include <linux/ctype.h>
  12. #ifdef CONFIG_FSL_ESDHC
  13. #include <fsl_esdhc.h>
  14. #endif
  15. #include <tsec.h>
  16. #include <asm/arch/immap_ls102xa.h>
  17. #include <fsl_sec.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. void ft_fixup_enet_phy_connect_type(void *fdt)
  20. {
  21. struct eth_device *dev;
  22. struct tsec_private *priv;
  23. const char *enet_path, *phy_path;
  24. char enet[16];
  25. char phy[16];
  26. int phy_node;
  27. int i = 0;
  28. uint32_t ph;
  29. char *name[3] = { "eTSEC1", "eTSEC2", "eTSEC3" };
  30. for (; i < ARRAY_SIZE(name); i++) {
  31. dev = eth_get_dev_by_name(name[i]);
  32. if (dev) {
  33. sprintf(enet, "ethernet%d", i);
  34. sprintf(phy, "enet%d_rgmii_phy", i);
  35. } else {
  36. continue;
  37. }
  38. priv = dev->priv;
  39. if (priv->flags & TSEC_SGMII)
  40. continue;
  41. enet_path = fdt_get_alias(fdt, enet);
  42. if (!enet_path)
  43. continue;
  44. phy_path = fdt_get_alias(fdt, phy);
  45. if (!phy_path)
  46. continue;
  47. phy_node = fdt_path_offset(fdt, phy_path);
  48. if (phy_node < 0)
  49. continue;
  50. ph = fdt_create_phandle(fdt, phy_node);
  51. if (ph)
  52. do_fixup_by_path_u32(fdt, enet_path,
  53. "phy-handle", ph, 1);
  54. do_fixup_by_path(fdt, enet_path, "phy-connection-type",
  55. phy_string_for_interface(
  56. PHY_INTERFACE_MODE_RGMII_ID),
  57. sizeof(phy_string_for_interface(
  58. PHY_INTERFACE_MODE_RGMII_ID)),
  59. 1);
  60. }
  61. }
  62. void ft_cpu_setup(void *blob, bd_t *bd)
  63. {
  64. int off;
  65. int val;
  66. const char *sysclk_path;
  67. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  68. unsigned int svr;
  69. svr = in_be32(&gur->svr);
  70. unsigned long busclk = get_bus_freq(0);
  71. /* delete crypto node if not on an E-processor */
  72. if (!IS_E_PROCESSOR(svr))
  73. fdt_fixup_crypto_node(blob, 0);
  74. #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
  75. else {
  76. ccsr_sec_t __iomem *sec;
  77. sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  78. fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
  79. }
  80. #endif
  81. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  82. while (off != -FDT_ERR_NOTFOUND) {
  83. val = gd->cpu_clk;
  84. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  85. off = fdt_node_offset_by_prop_value(blob, off,
  86. "device_type", "cpu", 4);
  87. }
  88. do_fixup_by_prop_u32(blob, "device_type", "soc",
  89. 4, "bus-frequency", busclk, 1);
  90. ft_fixup_enet_phy_connect_type(blob);
  91. #ifdef CONFIG_SYS_NS16550
  92. do_fixup_by_compat_u32(blob, "fsl,16550-FIFO64",
  93. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  94. #endif
  95. sysclk_path = fdt_get_alias(blob, "sysclk");
  96. if (sysclk_path)
  97. do_fixup_by_path_u32(blob, sysclk_path, "clock-frequency",
  98. CONFIG_SYS_CLK_FREQ, 1);
  99. do_fixup_by_compat_u32(blob, "fsl,qoriq-sysclk-2.0",
  100. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  101. #if defined(CONFIG_DEEP_SLEEP) && defined(CONFIG_SD_BOOT)
  102. #define UBOOT_HEAD_LEN 0x1000
  103. /*
  104. * Reserved memory in SD boot deep sleep case.
  105. * Second stage uboot binary and malloc space should be reserved.
  106. * If the memory they occupied has not been reserved, then this
  107. * space would be used by kernel and overwritten in uboot when
  108. * deep sleep resume, which cause deep sleep failed.
  109. * Since second uboot binary has a head, that space need to be
  110. * reserved either(assuming its size is less than 0x1000).
  111. */
  112. off = fdt_add_mem_rsv(blob, CONFIG_SYS_TEXT_BASE - UBOOT_HEAD_LEN,
  113. CONFIG_SYS_MONITOR_LEN + CONFIG_SYS_SPL_MALLOC_SIZE +
  114. UBOOT_HEAD_LEN);
  115. if (off < 0)
  116. printf("Failed to reserve memory for SD boot deep sleep: %s\n",
  117. fdt_strerror(off));
  118. #endif
  119. #if defined(CONFIG_FSL_ESDHC)
  120. fdt_fixup_esdhc(blob, bd);
  121. #endif
  122. /*
  123. * platform bus clock = system bus clock/2
  124. * Here busclk = system bus clock
  125. * We are using the platform bus clock as 1588 Timer reference
  126. * clock source select
  127. */
  128. do_fixup_by_compat_u32(blob, "fsl, gianfar-ptp-timer",
  129. "timer-frequency", busclk / 2, 1);
  130. /*
  131. * clock-freq should change to clock-frequency and
  132. * flexcan-v1.0 should change to p1010-flexcan respectively
  133. * in the future.
  134. */
  135. do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
  136. "clock_freq", busclk / 2, 1);
  137. do_fixup_by_compat_u32(blob, "fsl, flexcan-v1.0",
  138. "clock-frequency", busclk / 2, 1);
  139. do_fixup_by_compat_u32(blob, "fsl, ls1021a-flexcan",
  140. "clock-frequency", busclk / 2, 1);
  141. #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI)
  142. off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT,
  143. CONFIG_SYS_IFC_ADDR);
  144. fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
  145. #else
  146. off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT,
  147. QSPI0_BASE_ADDR);
  148. fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
  149. off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT,
  150. DSPI1_BASE_ADDR);
  151. fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
  152. #endif
  153. }