soc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 NXP
  4. *
  5. * Peng Fan <peng.fan@nxp.com>
  6. */
  7. #include <common.h>
  8. #include <asm/arch/imx-regs.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/mach-imx/hab.h>
  13. #include <asm/mach-imx/boot_mode.h>
  14. #include <asm/mach-imx/syscounter.h>
  15. #include <asm/armv8/mmu.h>
  16. #include <errno.h>
  17. #include <fdt_support.h>
  18. #include <fsl_wdog.h>
  19. #include <imx_sip.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #if defined(CONFIG_SECURE_BOOT)
  22. struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
  23. .bank = 1,
  24. .word = 3,
  25. };
  26. #endif
  27. int timer_init(void)
  28. {
  29. #ifdef CONFIG_SPL_BUILD
  30. struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
  31. unsigned long freq = readl(&sctr->cntfid0);
  32. /* Update with accurate clock frequency */
  33. asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
  34. clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
  35. SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
  36. #endif
  37. gd->arch.tbl = 0;
  38. gd->arch.tbu = 0;
  39. return 0;
  40. }
  41. void enable_tzc380(void)
  42. {
  43. struct iomuxc_gpr_base_regs *gpr =
  44. (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
  45. /* Enable TZASC and lock setting */
  46. setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
  47. setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
  48. }
  49. void set_wdog_reset(struct wdog_regs *wdog)
  50. {
  51. /*
  52. * Output WDOG_B signal to reset external pmic or POR_B decided by
  53. * the board design. Without external reset, the peripherals/DDR/
  54. * PMIC are not reset, that may cause system working abnormal.
  55. * WDZST bit is write-once only bit. Align this bit in kernel,
  56. * otherwise kernel code will have no chance to set this bit.
  57. */
  58. setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
  59. }
  60. static struct mm_region imx8m_mem_map[] = {
  61. {
  62. /* ROM */
  63. .virt = 0x0UL,
  64. .phys = 0x0UL,
  65. .size = 0x100000UL,
  66. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  67. PTE_BLOCK_OUTER_SHARE
  68. }, {
  69. /* OCRAM */
  70. .virt = 0x900000UL,
  71. .phys = 0x900000UL,
  72. .size = 0x200000UL,
  73. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  74. PTE_BLOCK_OUTER_SHARE
  75. }, {
  76. /* AIPS */
  77. .virt = 0xB00000UL,
  78. .phys = 0xB00000UL,
  79. .size = 0x3f500000UL,
  80. .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
  81. PTE_BLOCK_NON_SHARE |
  82. PTE_BLOCK_PXN | PTE_BLOCK_UXN
  83. }, {
  84. /* DRAM1 */
  85. .virt = 0x40000000UL,
  86. .phys = 0x40000000UL,
  87. .size = 0xC0000000UL,
  88. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  89. PTE_BLOCK_OUTER_SHARE
  90. }, {
  91. /* DRAM2 */
  92. .virt = 0x100000000UL,
  93. .phys = 0x100000000UL,
  94. .size = 0x040000000UL,
  95. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  96. PTE_BLOCK_OUTER_SHARE
  97. }, {
  98. /* List terminator */
  99. 0,
  100. }
  101. };
  102. struct mm_region *mem_map = imx8m_mem_map;
  103. u32 get_cpu_rev(void)
  104. {
  105. struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
  106. u32 reg = readl(&ana_pll->digprog);
  107. u32 type = (reg >> 16) & 0xff;
  108. u32 rom_version;
  109. reg &= 0xff;
  110. if (reg == CHIP_REV_1_0) {
  111. /*
  112. * For B0 chip, the DIGPROG is not updated, still TO1.0.
  113. * we have to check ROM version further
  114. */
  115. rom_version = readl((void __iomem *)ROM_VERSION_A0);
  116. if (rom_version != CHIP_REV_1_0) {
  117. rom_version = readl((void __iomem *)ROM_VERSION_B0);
  118. if (rom_version >= CHIP_REV_2_0)
  119. reg = CHIP_REV_2_0;
  120. }
  121. }
  122. return (type << 12) | reg;
  123. }
  124. static void imx_set_wdog_powerdown(bool enable)
  125. {
  126. struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
  127. struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
  128. struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
  129. /* Write to the PDE (Power Down Enable) bit */
  130. writew(enable, &wdog1->wmcr);
  131. writew(enable, &wdog2->wmcr);
  132. writew(enable, &wdog3->wmcr);
  133. }
  134. int arch_cpu_init(void)
  135. {
  136. /*
  137. * Init timer at very early state, because sscg pll setting
  138. * will use it
  139. */
  140. timer_init();
  141. if (IS_ENABLED(CONFIG_SPL_BUILD)) {
  142. clock_init();
  143. imx_set_wdog_powerdown(false);
  144. }
  145. return 0;
  146. }
  147. bool is_usb_boot(void)
  148. {
  149. return get_boot_device() == USB_BOOT;
  150. }
  151. #ifdef CONFIG_OF_SYSTEM_SETUP
  152. int ft_system_setup(void *blob, bd_t *bd)
  153. {
  154. int i = 0;
  155. int rc;
  156. int nodeoff;
  157. /* Disable the CPU idle for A0 chip since the HW does not support it */
  158. if (is_soc_rev(CHIP_REV_1_0)) {
  159. static const char * const nodes_path[] = {
  160. "/cpus/cpu@0",
  161. "/cpus/cpu@1",
  162. "/cpus/cpu@2",
  163. "/cpus/cpu@3",
  164. };
  165. for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
  166. nodeoff = fdt_path_offset(blob, nodes_path[i]);
  167. if (nodeoff < 0)
  168. continue; /* Not found, skip it */
  169. printf("Found %s node\n", nodes_path[i]);
  170. rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
  171. if (rc) {
  172. printf("Unable to update property %s:%s, err=%s\n",
  173. nodes_path[i], "status", fdt_strerror(rc));
  174. return rc;
  175. }
  176. printf("Remove %s:%s\n", nodes_path[i],
  177. "cpu-idle-states");
  178. }
  179. }
  180. return 0;
  181. }
  182. #endif
  183. void reset_cpu(ulong addr)
  184. {
  185. struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
  186. /* Clear WDA to trigger WDOG_B immediately */
  187. writew((WCR_WDE | WCR_SRS), &wdog->wcr);
  188. while (1) {
  189. /*
  190. * spin for .5 seconds before reset
  191. */
  192. }
  193. }