soc.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. #define IOMUXC_GPR1 0x4
  20. #define BM_IOMUXC_GPR1_IRQ 0x1000
  21. #define GPC_LPCR_A7_BSC 0x0
  22. #define GPC_LPCR_M4 0x8
  23. #define GPC_SLPCR 0x14
  24. #define GPC_PGC_ACK_SEL_A7 0x24
  25. #define GPC_IMR1_CORE0 0x30
  26. #define GPC_IMR1_CORE1 0x40
  27. #define GPC_IMR1_M4 0x50
  28. #define GPC_PGC_CPU_MAPPING 0xec
  29. #define GPC_PGC_C0_PUPSCR 0x804
  30. #define GPC_PGC_SCU_TIMING 0x890
  31. #define GPC_PGC_C1_PUPSCR 0x844
  32. #define BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP 0x70000000
  33. #define BM_LPCR_A7_BSC_CPU_CLK_ON_LPM 0x4000
  34. #define BM_LPCR_M4_MASK_DSM_TRIGGER 0x80000000
  35. #define BM_SLPCR_EN_DSM 0x80000000
  36. #define BM_SLPCR_RBC_EN 0x40000000
  37. #define BM_SLPCR_REG_BYPASS_COUNT 0x3f000000
  38. #define BM_SLPCR_VSTBY 0x4
  39. #define BM_SLPCR_SBYOS 0x2
  40. #define BM_SLPCR_BYPASS_PMIC_READY 0x1
  41. #define BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE 0x10000
  42. #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK 0x80000000
  43. #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK 0x8000
  44. #define BM_GPC_PGC_CORE_PUPSCR 0x7fff80
  45. #if defined(CONFIG_IMX_THERMAL)
  46. static const struct imx_thermal_plat imx7_thermal_plat = {
  47. .regs = (void *)ANATOP_BASE_ADDR,
  48. .fuse_bank = 3,
  49. .fuse_word = 3,
  50. };
  51. U_BOOT_DEVICE(imx7_thermal) = {
  52. .name = "imx_thermal",
  53. .platdata = &imx7_thermal_plat,
  54. };
  55. #endif
  56. #if CONFIG_IS_ENABLED(IMX_RDC)
  57. /*
  58. * In current design, if any peripheral was assigned to both A7 and M4,
  59. * it will receive ipg_stop or ipg_wait when any of the 2 platforms enter
  60. * low power mode. So M4 sleep will cause some peripherals fail to work
  61. * at A7 core side. At default, all resources are in domain 0 - 3.
  62. *
  63. * There are 26 peripherals impacted by this IC issue:
  64. * SIM2(sim2/emvsim2)
  65. * SIM1(sim1/emvsim1)
  66. * UART1/UART2/UART3/UART4/UART5/UART6/UART7
  67. * SAI1/SAI2/SAI3
  68. * WDOG1/WDOG2/WDOG3/WDOG4
  69. * GPT1/GPT2/GPT3/GPT4
  70. * PWM1/PWM2/PWM3/PWM4
  71. * ENET1/ENET2
  72. * Software Workaround:
  73. * Here we setup some resources to domain 0 where M4 codes will move
  74. * the M4 out of this domain. Then M4 is not able to access them any longer.
  75. * This is a workaround for ic issue. So the peripherals are not shared
  76. * by them. This way requires the uboot implemented the RDC driver and
  77. * set the 26 IPs above to domain 0 only. M4 code will assign resource
  78. * to its own domain, if it want to use the resource.
  79. */
  80. static rdc_peri_cfg_t const resources[] = {
  81. (RDC_PER_SIM1 | RDC_DOMAIN(0)),
  82. (RDC_PER_SIM2 | RDC_DOMAIN(0)),
  83. (RDC_PER_UART1 | RDC_DOMAIN(0)),
  84. (RDC_PER_UART2 | RDC_DOMAIN(0)),
  85. (RDC_PER_UART3 | RDC_DOMAIN(0)),
  86. (RDC_PER_UART4 | RDC_DOMAIN(0)),
  87. (RDC_PER_UART5 | RDC_DOMAIN(0)),
  88. (RDC_PER_UART6 | RDC_DOMAIN(0)),
  89. (RDC_PER_UART7 | RDC_DOMAIN(0)),
  90. (RDC_PER_SAI1 | RDC_DOMAIN(0)),
  91. (RDC_PER_SAI2 | RDC_DOMAIN(0)),
  92. (RDC_PER_SAI3 | RDC_DOMAIN(0)),
  93. (RDC_PER_WDOG1 | RDC_DOMAIN(0)),
  94. (RDC_PER_WDOG2 | RDC_DOMAIN(0)),
  95. (RDC_PER_WDOG3 | RDC_DOMAIN(0)),
  96. (RDC_PER_WDOG4 | RDC_DOMAIN(0)),
  97. (RDC_PER_GPT1 | RDC_DOMAIN(0)),
  98. (RDC_PER_GPT2 | RDC_DOMAIN(0)),
  99. (RDC_PER_GPT3 | RDC_DOMAIN(0)),
  100. (RDC_PER_GPT4 | RDC_DOMAIN(0)),
  101. (RDC_PER_PWM1 | RDC_DOMAIN(0)),
  102. (RDC_PER_PWM2 | RDC_DOMAIN(0)),
  103. (RDC_PER_PWM3 | RDC_DOMAIN(0)),
  104. (RDC_PER_PWM4 | RDC_DOMAIN(0)),
  105. (RDC_PER_ENET1 | RDC_DOMAIN(0)),
  106. (RDC_PER_ENET2 | RDC_DOMAIN(0)),
  107. };
  108. static void isolate_resource(void)
  109. {
  110. imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources));
  111. }
  112. #endif
  113. #if defined(CONFIG_SECURE_BOOT)
  114. struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
  115. .bank = 1,
  116. .word = 3,
  117. };
  118. #endif
  119. static bool is_mx7d(void)
  120. {
  121. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  122. struct fuse_bank *bank = &ocotp->bank[1];
  123. struct fuse_bank1_regs *fuse =
  124. (struct fuse_bank1_regs *)bank->fuse_regs;
  125. int val;
  126. val = readl(&fuse->tester4);
  127. if (val & 1)
  128. return false;
  129. else
  130. return true;
  131. }
  132. u32 get_cpu_rev(void)
  133. {
  134. struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
  135. ANATOP_BASE_ADDR;
  136. u32 reg = readl(&ccm_anatop->digprog);
  137. u32 type = (reg >> 16) & 0xff;
  138. if (!is_mx7d())
  139. type = MXC_CPU_MX7S;
  140. reg &= 0xff;
  141. return (type << 12) | reg;
  142. }
  143. #ifdef CONFIG_REVISION_TAG
  144. u32 __weak get_board_rev(void)
  145. {
  146. return get_cpu_rev();
  147. }
  148. #endif
  149. /* enable all periherial can be accessed in nosec mode */
  150. static void init_csu(void)
  151. {
  152. int i = 0;
  153. for (i = 0; i < CSU_NUM_REGS; i++)
  154. writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
  155. }
  156. static void imx_enet_mdio_fixup(void)
  157. {
  158. struct iomuxc_gpr_base_regs *gpr_regs =
  159. (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
  160. /*
  161. * The management data input/output (MDIO) requires open-drain,
  162. * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
  163. * this feature. So to TO1.1, need to enable open drain by setting
  164. * bits GPR0[8:7].
  165. */
  166. if (soc_rev() >= CHIP_REV_1_1) {
  167. setbits_le32(&gpr_regs->gpr[0],
  168. IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
  169. }
  170. }
  171. static void imx_gpcv2_init(void)
  172. {
  173. u32 val, i;
  174. /*
  175. * Force IOMUXC irq pending, so that the interrupt to GPC can be
  176. * used to deassert dsm_request signal when the signal gets
  177. * asserted unexpectedly.
  178. */
  179. val = readl(IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1);
  180. val |= BM_IOMUXC_GPR1_IRQ;
  181. writel(val, IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1);
  182. /* Initially mask all interrupts */
  183. for (i = 0; i < 4; i++) {
  184. writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE0 + i * 4);
  185. writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE1 + i * 4);
  186. writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_M4 + i * 4);
  187. }
  188. /* set SCU timing */
  189. writel((0x59 << 10) | 0x5B | (0x2 << 20),
  190. GPC_IPS_BASE_ADDR + GPC_PGC_SCU_TIMING);
  191. /* only external IRQs to wake up LPM and core 0/1 */
  192. val = readl(GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC);
  193. val |= BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP;
  194. writel(val, GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC);
  195. /* set C0 power up timming per design requirement */
  196. val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR);
  197. val &= ~BM_GPC_PGC_CORE_PUPSCR;
  198. val |= (0x1A << 7);
  199. writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR);
  200. /* set C1 power up timming per design requirement */
  201. val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR);
  202. val &= ~BM_GPC_PGC_CORE_PUPSCR;
  203. val |= (0x1A << 7);
  204. writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR);
  205. /* dummy ack for time slot by default */
  206. writel(BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK |
  207. BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK,
  208. GPC_IPS_BASE_ADDR + GPC_PGC_ACK_SEL_A7);
  209. /* mask M4 DSM trigger */
  210. writel(readl(GPC_IPS_BASE_ADDR + GPC_LPCR_M4) |
  211. BM_LPCR_M4_MASK_DSM_TRIGGER,
  212. GPC_IPS_BASE_ADDR + GPC_LPCR_M4);
  213. /* set mega/fast mix in A7 domain */
  214. writel(0x1, GPC_IPS_BASE_ADDR + GPC_PGC_CPU_MAPPING);
  215. /* DSM related settings */
  216. val = readl(GPC_IPS_BASE_ADDR + GPC_SLPCR);
  217. val &= ~(BM_SLPCR_EN_DSM | BM_SLPCR_VSTBY | BM_SLPCR_RBC_EN |
  218. BM_SLPCR_SBYOS | BM_SLPCR_BYPASS_PMIC_READY |
  219. BM_SLPCR_REG_BYPASS_COUNT);
  220. val |= BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE;
  221. writel(val, GPC_IPS_BASE_ADDR + GPC_SLPCR);
  222. /*
  223. * disabling RBC need to delay at least 2 cycles of CKIL(32K)
  224. * due to hardware design requirement, which is
  225. * ~61us, here we use 65us for safe
  226. */
  227. udelay(65);
  228. }
  229. int arch_cpu_init(void)
  230. {
  231. init_aips();
  232. init_csu();
  233. /* Disable PDE bit of WMCR register */
  234. imx_wdog_disable_powerdown();
  235. imx_enet_mdio_fixup();
  236. #ifdef CONFIG_APBH_DMA
  237. /* Start APBH DMA */
  238. mxs_dma_init();
  239. #endif
  240. #if CONFIG_IS_ENABLED(IMX_RDC)
  241. isolate_resource();
  242. #endif
  243. init_snvs();
  244. imx_gpcv2_init();
  245. return 0;
  246. }
  247. #ifdef CONFIG_ARCH_MISC_INIT
  248. int arch_misc_init(void)
  249. {
  250. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  251. if (is_mx7d())
  252. env_set("soc", "imx7d");
  253. else
  254. env_set("soc", "imx7s");
  255. #endif
  256. #ifdef CONFIG_FSL_CAAM
  257. sec_init();
  258. #endif
  259. return 0;
  260. }
  261. #endif
  262. #ifdef CONFIG_SERIAL_TAG
  263. /*
  264. * OCOTP_TESTER
  265. * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1, 08/2016
  266. * OCOTP_TESTER describes a unique ID based on silicon wafer
  267. * and die X/Y position
  268. *
  269. * OCOTOP_TESTER offset 0x410
  270. * 31:0 fuse 0
  271. * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
  272. *
  273. * OCOTP_TESTER1 offset 0x420
  274. * 31:24 fuse 1
  275. * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
  276. * 23:16 fuse 1
  277. * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
  278. * 15:11 fuse 1
  279. * The wafer number of the wafer on which the device was fabricated/SJC
  280. * CHALLENGE/ Unique ID
  281. * 10:0 fuse 1
  282. * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
  283. */
  284. void get_board_serial(struct tag_serialnr *serialnr)
  285. {
  286. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  287. struct fuse_bank *bank = &ocotp->bank[0];
  288. struct fuse_bank0_regs *fuse =
  289. (struct fuse_bank0_regs *)bank->fuse_regs;
  290. serialnr->low = fuse->tester0;
  291. serialnr->high = fuse->tester1;
  292. }
  293. #endif
  294. void set_wdog_reset(struct wdog_regs *wdog)
  295. {
  296. u32 reg = readw(&wdog->wcr);
  297. /*
  298. * Output WDOG_B signal to reset external pmic or POR_B decided by
  299. * the board desgin. Without external reset, the peripherals/DDR/
  300. * PMIC are not reset, that may cause system working abnormal.
  301. */
  302. reg = readw(&wdog->wcr);
  303. reg |= 1 << 3;
  304. /*
  305. * WDZST bit is write-once only bit. Align this bit in kernel,
  306. * otherwise kernel code will have no chance to set this bit.
  307. */
  308. reg |= 1 << 0;
  309. writew(reg, &wdog->wcr);
  310. }
  311. void s_init(void)
  312. {
  313. /* clock configuration. */
  314. clock_init();
  315. return;
  316. }
  317. void reset_misc(void)
  318. {
  319. #ifdef CONFIG_VIDEO_MXS
  320. lcdif_power_down();
  321. #endif
  322. }