soc.c 5.5 KB

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