soc.c 7.5 KB

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