soc.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  4. */
  5. #include <asm/io.h>
  6. #include <asm/arch/clock.h>
  7. #include <asm/arch/imx-regs.h>
  8. #include <asm/arch/sys_proto.h>
  9. #include <asm/mach-imx/hab.h>
  10. static char *get_reset_cause(char *);
  11. #if defined(CONFIG_SECURE_BOOT)
  12. struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
  13. .bank = 29,
  14. .word = 6,
  15. };
  16. #endif
  17. u32 get_cpu_rev(void)
  18. {
  19. /* Temporally hard code the CPU rev to 0x73, rev 1.0. Fix it later */
  20. return (MXC_CPU_MX7ULP << 12) | (1 << 4);
  21. }
  22. #ifdef CONFIG_REVISION_TAG
  23. u32 __weak get_board_rev(void)
  24. {
  25. return get_cpu_rev();
  26. }
  27. #endif
  28. enum bt_mode get_boot_mode(void)
  29. {
  30. u32 bt0_cfg = 0;
  31. bt0_cfg = readl(CMC0_RBASE + 0x40);
  32. bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
  33. if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
  34. /* No low power boot */
  35. if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
  36. return DUAL_BOOT;
  37. else
  38. return SINGLE_BOOT;
  39. }
  40. return LOW_POWER_BOOT;
  41. }
  42. int arch_cpu_init(void)
  43. {
  44. return 0;
  45. }
  46. #ifdef CONFIG_BOARD_POSTCLK_INIT
  47. int board_postclk_init(void)
  48. {
  49. return 0;
  50. }
  51. #endif
  52. #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
  53. #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
  54. #define REFRESH_WORD0 0xA602 /* 1st refresh word */
  55. #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
  56. static void disable_wdog(u32 wdog_base)
  57. {
  58. writel(UNLOCK_WORD0, (wdog_base + 0x04));
  59. writel(UNLOCK_WORD1, (wdog_base + 0x04));
  60. writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
  61. writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
  62. writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
  63. writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
  64. writel(REFRESH_WORD1, (wdog_base + 0x04));
  65. }
  66. void init_wdog(void)
  67. {
  68. /*
  69. * ROM will configure WDOG1, disable it or enable it
  70. * depending on FUSE. The update bit is set for reconfigurable.
  71. * We have to use unlock sequence to reconfigure it.
  72. * WDOG2 is not touched by ROM, so it will have default value
  73. * which is enabled. We can directly configure it.
  74. * To simplify the codes, we still use same reconfigure
  75. * process as WDOG1. Because the update bit is not set for
  76. * WDOG2, the unlock sequence won't take effect really.
  77. * It actually directly configure the wdog.
  78. * In this function, we will disable both WDOG1 and WDOG2,
  79. * and set update bit for both. So that kernel can reconfigure them.
  80. */
  81. disable_wdog(WDG1_RBASE);
  82. disable_wdog(WDG2_RBASE);
  83. }
  84. void s_init(void)
  85. {
  86. /* Disable wdog */
  87. init_wdog();
  88. /* clock configuration. */
  89. clock_init();
  90. return;
  91. }
  92. #ifndef CONFIG_ULP_WATCHDOG
  93. void reset_cpu(ulong addr)
  94. {
  95. setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
  96. while (1)
  97. ;
  98. }
  99. #endif
  100. #if defined(CONFIG_DISPLAY_CPUINFO)
  101. const char *get_imx_type(u32 imxtype)
  102. {
  103. return "7ULP";
  104. }
  105. int print_cpuinfo(void)
  106. {
  107. u32 cpurev;
  108. char cause[18];
  109. cpurev = get_cpu_rev();
  110. printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
  111. get_imx_type((cpurev & 0xFF000) >> 12),
  112. (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
  113. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  114. printf("Reset cause: %s\n", get_reset_cause(cause));
  115. printf("Boot mode: ");
  116. switch (get_boot_mode()) {
  117. case LOW_POWER_BOOT:
  118. printf("Low power boot\n");
  119. break;
  120. case DUAL_BOOT:
  121. printf("Dual boot\n");
  122. break;
  123. case SINGLE_BOOT:
  124. default:
  125. printf("Single boot\n");
  126. break;
  127. }
  128. return 0;
  129. }
  130. #endif
  131. #define CMC_SRS_TAMPER (1 << 31)
  132. #define CMC_SRS_SECURITY (1 << 30)
  133. #define CMC_SRS_TZWDG (1 << 29)
  134. #define CMC_SRS_JTAG_RST (1 << 28)
  135. #define CMC_SRS_CORE1 (1 << 16)
  136. #define CMC_SRS_LOCKUP (1 << 15)
  137. #define CMC_SRS_SW (1 << 14)
  138. #define CMC_SRS_WDG (1 << 13)
  139. #define CMC_SRS_PIN_RESET (1 << 8)
  140. #define CMC_SRS_WARM (1 << 4)
  141. #define CMC_SRS_HVD (1 << 3)
  142. #define CMC_SRS_LVD (1 << 2)
  143. #define CMC_SRS_POR (1 << 1)
  144. #define CMC_SRS_WUP (1 << 0)
  145. static u32 reset_cause = -1;
  146. static char *get_reset_cause(char *ret)
  147. {
  148. u32 cause1, cause = 0, srs = 0;
  149. u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
  150. u32 *reg_srs = (u32 *)(SRC_BASE_ADDR + 0x20);
  151. if (!ret)
  152. return "null";
  153. srs = readl(reg_srs);
  154. cause1 = readl(reg_ssrs);
  155. writel(cause1, reg_ssrs);
  156. reset_cause = cause1;
  157. cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
  158. switch (cause) {
  159. case CMC_SRS_POR:
  160. sprintf(ret, "%s", "POR");
  161. break;
  162. case CMC_SRS_WUP:
  163. sprintf(ret, "%s", "WUP");
  164. break;
  165. case CMC_SRS_WARM:
  166. cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
  167. CMC_SRS_JTAG_RST);
  168. switch (cause) {
  169. case CMC_SRS_WDG:
  170. sprintf(ret, "%s", "WARM-WDG");
  171. break;
  172. case CMC_SRS_SW:
  173. sprintf(ret, "%s", "WARM-SW");
  174. break;
  175. case CMC_SRS_JTAG_RST:
  176. sprintf(ret, "%s", "WARM-JTAG");
  177. break;
  178. default:
  179. sprintf(ret, "%s", "WARM-UNKN");
  180. break;
  181. }
  182. break;
  183. default:
  184. sprintf(ret, "%s-%X", "UNKN", cause1);
  185. break;
  186. }
  187. debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
  188. return ret;
  189. }
  190. #ifdef CONFIG_ENV_IS_IN_MMC
  191. __weak int board_mmc_get_env_dev(int devno)
  192. {
  193. return CONFIG_SYS_MMC_ENV_DEV;
  194. }
  195. int mmc_get_env_dev(void)
  196. {
  197. int devno = 0;
  198. u32 bt1_cfg = 0;
  199. /* If not boot from sd/mmc, use default value */
  200. if (get_boot_mode() == LOW_POWER_BOOT)
  201. return CONFIG_SYS_MMC_ENV_DEV;
  202. bt1_cfg = readl(CMC1_RBASE + 0x40);
  203. devno = (bt1_cfg >> 9) & 0x7;
  204. return board_mmc_get_env_dev(devno);
  205. }
  206. #endif