soc.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include <asm/arch/imx-regs.h>
  8. #include <asm/arch/clock.h>
  9. #include <asm/arch/sys_proto.h>
  10. #include <asm/mach-imx/dma.h>
  11. #include <asm/mach-imx/hab.h>
  12. #include <asm/mach-imx/rdc-sema.h>
  13. #include <asm/arch/imx-rdc.h>
  14. #include <asm/arch/crm_regs.h>
  15. #include <dm.h>
  16. #include <imx_thermal.h>
  17. #include <fsl_sec.h>
  18. #include <asm/setup.h>
  19. #if defined(CONFIG_IMX_THERMAL)
  20. static const struct imx_thermal_plat imx7_thermal_plat = {
  21. .regs = (void *)ANATOP_BASE_ADDR,
  22. .fuse_bank = 3,
  23. .fuse_word = 3,
  24. };
  25. U_BOOT_DEVICE(imx7_thermal) = {
  26. .name = "imx_thermal",
  27. .platdata = &imx7_thermal_plat,
  28. };
  29. #endif
  30. #if CONFIG_IS_ENABLED(IMX_RDC)
  31. /*
  32. * In current design, if any peripheral was assigned to both A7 and M4,
  33. * it will receive ipg_stop or ipg_wait when any of the 2 platforms enter
  34. * low power mode. So M4 sleep will cause some peripherals fail to work
  35. * at A7 core side. At default, all resources are in domain 0 - 3.
  36. *
  37. * There are 26 peripherals impacted by this IC issue:
  38. * SIM2(sim2/emvsim2)
  39. * SIM1(sim1/emvsim1)
  40. * UART1/UART2/UART3/UART4/UART5/UART6/UART7
  41. * SAI1/SAI2/SAI3
  42. * WDOG1/WDOG2/WDOG3/WDOG4
  43. * GPT1/GPT2/GPT3/GPT4
  44. * PWM1/PWM2/PWM3/PWM4
  45. * ENET1/ENET2
  46. * Software Workaround:
  47. * Here we setup some resources to domain 0 where M4 codes will move
  48. * the M4 out of this domain. Then M4 is not able to access them any longer.
  49. * This is a workaround for ic issue. So the peripherals are not shared
  50. * by them. This way requires the uboot implemented the RDC driver and
  51. * set the 26 IPs above to domain 0 only. M4 code will assign resource
  52. * to its own domain, if it want to use the resource.
  53. */
  54. static rdc_peri_cfg_t const resources[] = {
  55. (RDC_PER_SIM1 | RDC_DOMAIN(0)),
  56. (RDC_PER_SIM2 | RDC_DOMAIN(0)),
  57. (RDC_PER_UART1 | RDC_DOMAIN(0)),
  58. (RDC_PER_UART2 | RDC_DOMAIN(0)),
  59. (RDC_PER_UART3 | RDC_DOMAIN(0)),
  60. (RDC_PER_UART4 | RDC_DOMAIN(0)),
  61. (RDC_PER_UART5 | RDC_DOMAIN(0)),
  62. (RDC_PER_UART6 | RDC_DOMAIN(0)),
  63. (RDC_PER_UART7 | RDC_DOMAIN(0)),
  64. (RDC_PER_SAI1 | RDC_DOMAIN(0)),
  65. (RDC_PER_SAI2 | RDC_DOMAIN(0)),
  66. (RDC_PER_SAI3 | RDC_DOMAIN(0)),
  67. (RDC_PER_WDOG1 | RDC_DOMAIN(0)),
  68. (RDC_PER_WDOG2 | RDC_DOMAIN(0)),
  69. (RDC_PER_WDOG3 | RDC_DOMAIN(0)),
  70. (RDC_PER_WDOG4 | RDC_DOMAIN(0)),
  71. (RDC_PER_GPT1 | RDC_DOMAIN(0)),
  72. (RDC_PER_GPT2 | RDC_DOMAIN(0)),
  73. (RDC_PER_GPT3 | RDC_DOMAIN(0)),
  74. (RDC_PER_GPT4 | RDC_DOMAIN(0)),
  75. (RDC_PER_PWM1 | RDC_DOMAIN(0)),
  76. (RDC_PER_PWM2 | RDC_DOMAIN(0)),
  77. (RDC_PER_PWM3 | RDC_DOMAIN(0)),
  78. (RDC_PER_PWM4 | RDC_DOMAIN(0)),
  79. (RDC_PER_ENET1 | RDC_DOMAIN(0)),
  80. (RDC_PER_ENET2 | RDC_DOMAIN(0)),
  81. };
  82. static void isolate_resource(void)
  83. {
  84. imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources));
  85. }
  86. #endif
  87. #if defined(CONFIG_SECURE_BOOT)
  88. struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
  89. .bank = 1,
  90. .word = 3,
  91. };
  92. #endif
  93. static bool is_mx7d(void)
  94. {
  95. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  96. struct fuse_bank *bank = &ocotp->bank[1];
  97. struct fuse_bank1_regs *fuse =
  98. (struct fuse_bank1_regs *)bank->fuse_regs;
  99. int val;
  100. val = readl(&fuse->tester4);
  101. if (val & 1)
  102. return false;
  103. else
  104. return true;
  105. }
  106. u32 get_cpu_rev(void)
  107. {
  108. struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
  109. ANATOP_BASE_ADDR;
  110. u32 reg = readl(&ccm_anatop->digprog);
  111. u32 type = (reg >> 16) & 0xff;
  112. if (!is_mx7d())
  113. type = MXC_CPU_MX7S;
  114. reg &= 0xff;
  115. return (type << 12) | reg;
  116. }
  117. #ifdef CONFIG_REVISION_TAG
  118. u32 __weak get_board_rev(void)
  119. {
  120. return get_cpu_rev();
  121. }
  122. #endif
  123. /* enable all periherial can be accessed in nosec mode */
  124. static void init_csu(void)
  125. {
  126. int i = 0;
  127. for (i = 0; i < CSU_NUM_REGS; i++)
  128. writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
  129. }
  130. static void imx_enet_mdio_fixup(void)
  131. {
  132. struct iomuxc_gpr_base_regs *gpr_regs =
  133. (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
  134. /*
  135. * The management data input/output (MDIO) requires open-drain,
  136. * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
  137. * this feature. So to TO1.1, need to enable open drain by setting
  138. * bits GPR0[8:7].
  139. */
  140. if (soc_rev() >= CHIP_REV_1_1) {
  141. setbits_le32(&gpr_regs->gpr[0],
  142. IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
  143. }
  144. }
  145. int arch_cpu_init(void)
  146. {
  147. init_aips();
  148. init_csu();
  149. /* Disable PDE bit of WMCR register */
  150. imx_wdog_disable_powerdown();
  151. imx_enet_mdio_fixup();
  152. #ifdef CONFIG_APBH_DMA
  153. /* Start APBH DMA */
  154. mxs_dma_init();
  155. #endif
  156. #if CONFIG_IS_ENABLED(IMX_RDC)
  157. isolate_resource();
  158. #endif
  159. init_snvs();
  160. return 0;
  161. }
  162. #ifdef CONFIG_ARCH_MISC_INIT
  163. int arch_misc_init(void)
  164. {
  165. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  166. if (is_mx7d())
  167. env_set("soc", "imx7d");
  168. else
  169. env_set("soc", "imx7s");
  170. #endif
  171. #ifdef CONFIG_FSL_CAAM
  172. sec_init();
  173. #endif
  174. return 0;
  175. }
  176. #endif
  177. #ifdef CONFIG_SERIAL_TAG
  178. /*
  179. * OCOTP_TESTER
  180. * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1, 08/2016
  181. * OCOTP_TESTER describes a unique ID based on silicon wafer
  182. * and die X/Y position
  183. *
  184. * OCOTOP_TESTER offset 0x410
  185. * 31:0 fuse 0
  186. * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
  187. *
  188. * OCOTP_TESTER1 offset 0x420
  189. * 31:24 fuse 1
  190. * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
  191. * 23:16 fuse 1
  192. * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
  193. * 15:11 fuse 1
  194. * The wafer number of the wafer on which the device was fabricated/SJC
  195. * CHALLENGE/ Unique ID
  196. * 10:0 fuse 1
  197. * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
  198. */
  199. void get_board_serial(struct tag_serialnr *serialnr)
  200. {
  201. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  202. struct fuse_bank *bank = &ocotp->bank[0];
  203. struct fuse_bank0_regs *fuse =
  204. (struct fuse_bank0_regs *)bank->fuse_regs;
  205. serialnr->low = fuse->tester0;
  206. serialnr->high = fuse->tester1;
  207. }
  208. #endif
  209. void set_wdog_reset(struct wdog_regs *wdog)
  210. {
  211. u32 reg = readw(&wdog->wcr);
  212. /*
  213. * Output WDOG_B signal to reset external pmic or POR_B decided by
  214. * the board desgin. Without external reset, the peripherals/DDR/
  215. * PMIC are not reset, that may cause system working abnormal.
  216. */
  217. reg = readw(&wdog->wcr);
  218. reg |= 1 << 3;
  219. /*
  220. * WDZST bit is write-once only bit. Align this bit in kernel,
  221. * otherwise kernel code will have no chance to set this bit.
  222. */
  223. reg |= 1 << 0;
  224. writew(reg, &wdog->wcr);
  225. }
  226. void s_init(void)
  227. {
  228. /* clock configuration. */
  229. clock_init();
  230. return;
  231. }
  232. void reset_misc(void)
  233. {
  234. #ifdef CONFIG_VIDEO_MXS
  235. lcdif_power_down();
  236. #endif
  237. }