soc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. #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. /*
  94. * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
  95. * defines a 2-bit SPEED_GRADING
  96. */
  97. #define OCOTP_TESTER3_SPEED_SHIFT 8
  98. #define OCOTP_TESTER3_SPEED_800MHZ 0
  99. #define OCOTP_TESTER3_SPEED_500MHZ 1
  100. #define OCOTP_TESTER3_SPEED_1GHZ 2
  101. #define OCOTP_TESTER3_SPEED_1P2GHZ 3
  102. u32 get_cpu_speed_grade_hz(void)
  103. {
  104. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  105. struct fuse_bank *bank = &ocotp->bank[1];
  106. struct fuse_bank1_regs *fuse =
  107. (struct fuse_bank1_regs *)bank->fuse_regs;
  108. uint32_t val;
  109. val = readl(&fuse->tester3);
  110. val >>= OCOTP_TESTER3_SPEED_SHIFT;
  111. val &= 0x3;
  112. switch(val) {
  113. case OCOTP_TESTER3_SPEED_800MHZ:
  114. return 800000000;
  115. case OCOTP_TESTER3_SPEED_500MHZ:
  116. return 500000000;
  117. case OCOTP_TESTER3_SPEED_1GHZ:
  118. return 1000000000;
  119. case OCOTP_TESTER3_SPEED_1P2GHZ:
  120. return 1200000000;
  121. }
  122. return 0;
  123. }
  124. /*
  125. * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
  126. * defines a 2-bit SPEED_GRADING
  127. */
  128. #define OCOTP_TESTER3_TEMP_SHIFT 6
  129. u32 get_cpu_temp_grade(int *minc, int *maxc)
  130. {
  131. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  132. struct fuse_bank *bank = &ocotp->bank[1];
  133. struct fuse_bank1_regs *fuse =
  134. (struct fuse_bank1_regs *)bank->fuse_regs;
  135. uint32_t val;
  136. val = readl(&fuse->tester3);
  137. val >>= OCOTP_TESTER3_TEMP_SHIFT;
  138. val &= 0x3;
  139. if (minc && maxc) {
  140. if (val == TEMP_AUTOMOTIVE) {
  141. *minc = -40;
  142. *maxc = 125;
  143. } else if (val == TEMP_INDUSTRIAL) {
  144. *minc = -40;
  145. *maxc = 105;
  146. } else if (val == TEMP_EXTCOMMERCIAL) {
  147. *minc = -20;
  148. *maxc = 105;
  149. } else {
  150. *minc = 0;
  151. *maxc = 95;
  152. }
  153. }
  154. return val;
  155. }
  156. static bool is_mx7d(void)
  157. {
  158. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  159. struct fuse_bank *bank = &ocotp->bank[1];
  160. struct fuse_bank1_regs *fuse =
  161. (struct fuse_bank1_regs *)bank->fuse_regs;
  162. int val;
  163. val = readl(&fuse->tester4);
  164. if (val & 1)
  165. return false;
  166. else
  167. return true;
  168. }
  169. u32 get_cpu_rev(void)
  170. {
  171. struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
  172. ANATOP_BASE_ADDR;
  173. u32 reg = readl(&ccm_anatop->digprog);
  174. u32 type = (reg >> 16) & 0xff;
  175. if (!is_mx7d())
  176. type = MXC_CPU_MX7S;
  177. reg &= 0xff;
  178. return (type << 12) | reg;
  179. }
  180. #ifdef CONFIG_REVISION_TAG
  181. u32 __weak get_board_rev(void)
  182. {
  183. return get_cpu_rev();
  184. }
  185. #endif
  186. /* enable all periherial can be accessed in nosec mode */
  187. static void init_csu(void)
  188. {
  189. int i = 0;
  190. for (i = 0; i < CSU_NUM_REGS; i++)
  191. writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
  192. }
  193. static void imx_enet_mdio_fixup(void)
  194. {
  195. struct iomuxc_gpr_base_regs *gpr_regs =
  196. (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
  197. /*
  198. * The management data input/output (MDIO) requires open-drain,
  199. * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
  200. * this feature. So to TO1.1, need to enable open drain by setting
  201. * bits GPR0[8:7].
  202. */
  203. if (soc_rev() >= CHIP_REV_1_1) {
  204. setbits_le32(&gpr_regs->gpr[0],
  205. IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
  206. }
  207. }
  208. int arch_cpu_init(void)
  209. {
  210. init_aips();
  211. init_csu();
  212. /* Disable PDE bit of WMCR register */
  213. imx_set_wdog_powerdown(false);
  214. imx_enet_mdio_fixup();
  215. #ifdef CONFIG_APBH_DMA
  216. /* Start APBH DMA */
  217. mxs_dma_init();
  218. #endif
  219. #if CONFIG_IS_ENABLED(IMX_RDC)
  220. isolate_resource();
  221. #endif
  222. return 0;
  223. }
  224. #ifdef CONFIG_ARCH_MISC_INIT
  225. int arch_misc_init(void)
  226. {
  227. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  228. if (is_mx7d())
  229. env_set("soc", "imx7d");
  230. else
  231. env_set("soc", "imx7s");
  232. #endif
  233. return 0;
  234. }
  235. #endif
  236. #ifdef CONFIG_SERIAL_TAG
  237. void get_board_serial(struct tag_serialnr *serialnr)
  238. {
  239. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  240. struct fuse_bank *bank = &ocotp->bank[0];
  241. struct fuse_bank0_regs *fuse =
  242. (struct fuse_bank0_regs *)bank->fuse_regs;
  243. serialnr->low = fuse->tester0;
  244. serialnr->high = fuse->tester1;
  245. }
  246. #endif
  247. #if defined(CONFIG_FEC_MXC)
  248. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  249. {
  250. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  251. struct fuse_bank *bank = &ocotp->bank[9];
  252. struct fuse_bank9_regs *fuse =
  253. (struct fuse_bank9_regs *)bank->fuse_regs;
  254. if (0 == dev_id) {
  255. u32 value = readl(&fuse->mac_addr1);
  256. mac[0] = (value >> 8);
  257. mac[1] = value;
  258. value = readl(&fuse->mac_addr0);
  259. mac[2] = value >> 24;
  260. mac[3] = value >> 16;
  261. mac[4] = value >> 8;
  262. mac[5] = value;
  263. } else {
  264. u32 value = readl(&fuse->mac_addr2);
  265. mac[0] = value >> 24;
  266. mac[1] = value >> 16;
  267. mac[2] = value >> 8;
  268. mac[3] = value;
  269. value = readl(&fuse->mac_addr1);
  270. mac[4] = value >> 24;
  271. mac[5] = value >> 16;
  272. }
  273. }
  274. #endif
  275. #ifdef CONFIG_IMX_BOOTAUX
  276. int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
  277. {
  278. u32 stack, pc;
  279. struct src *src_reg = (struct src *)SRC_BASE_ADDR;
  280. if (!boot_private_data)
  281. return 1;
  282. stack = *(u32 *)boot_private_data;
  283. pc = *(u32 *)(boot_private_data + 4);
  284. /* Set the stack and pc to M4 bootROM */
  285. writel(stack, M4_BOOTROM_BASE_ADDR);
  286. writel(pc, M4_BOOTROM_BASE_ADDR + 4);
  287. /* Enable M4 */
  288. clrsetbits_le32(&src_reg->m4rcr, SRC_M4RCR_M4C_NON_SCLR_RST_MASK,
  289. SRC_M4RCR_ENABLE_M4_MASK);
  290. return 0;
  291. }
  292. int arch_auxiliary_core_check_up(u32 core_id)
  293. {
  294. uint32_t val;
  295. struct src *src_reg = (struct src *)SRC_BASE_ADDR;
  296. val = readl(&src_reg->m4rcr);
  297. if (val & 0x00000001)
  298. return 0; /* assert in reset */
  299. return 1;
  300. }
  301. #endif
  302. void set_wdog_reset(struct wdog_regs *wdog)
  303. {
  304. u32 reg = readw(&wdog->wcr);
  305. /*
  306. * Output WDOG_B signal to reset external pmic or POR_B decided by
  307. * the board desgin. Without external reset, the peripherals/DDR/
  308. * PMIC are not reset, that may cause system working abnormal.
  309. */
  310. reg = readw(&wdog->wcr);
  311. reg |= 1 << 3;
  312. /*
  313. * WDZST bit is write-once only bit. Align this bit in kernel,
  314. * otherwise kernel code will have no chance to set this bit.
  315. */
  316. reg |= 1 << 0;
  317. writew(reg, &wdog->wcr);
  318. }
  319. /*
  320. * cfg_val will be used for
  321. * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
  322. * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
  323. * to SBMR1, which will determine the boot device.
  324. */
  325. const struct boot_mode soc_boot_modes[] = {
  326. {"ecspi1:0", MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
  327. {"ecspi1:1", MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
  328. {"ecspi1:2", MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
  329. {"ecspi1:3", MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
  330. {"weim", MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
  331. {"qspi1", MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
  332. /* 4 bit bus width */
  333. {"usdhc1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
  334. {"usdhc2", MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
  335. {"usdhc3", MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
  336. {"mmc1", MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
  337. {"mmc2", MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
  338. {"mmc3", MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
  339. {NULL, 0},
  340. };
  341. enum boot_device get_boot_device(void)
  342. {
  343. struct bootrom_sw_info **p =
  344. (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
  345. enum boot_device boot_dev = SD1_BOOT;
  346. u8 boot_type = (*p)->boot_dev_type;
  347. u8 boot_instance = (*p)->boot_dev_instance;
  348. switch (boot_type) {
  349. case BOOT_TYPE_SD:
  350. boot_dev = boot_instance + SD1_BOOT;
  351. break;
  352. case BOOT_TYPE_MMC:
  353. boot_dev = boot_instance + MMC1_BOOT;
  354. break;
  355. case BOOT_TYPE_NAND:
  356. boot_dev = NAND_BOOT;
  357. break;
  358. case BOOT_TYPE_QSPI:
  359. boot_dev = QSPI_BOOT;
  360. break;
  361. case BOOT_TYPE_WEIM:
  362. boot_dev = WEIM_NOR_BOOT;
  363. break;
  364. case BOOT_TYPE_SPINOR:
  365. boot_dev = SPI_NOR_BOOT;
  366. break;
  367. default:
  368. break;
  369. }
  370. return boot_dev;
  371. }
  372. #ifdef CONFIG_ENV_IS_IN_MMC
  373. __weak int board_mmc_get_env_dev(int devno)
  374. {
  375. return CONFIG_SYS_MMC_ENV_DEV;
  376. }
  377. int mmc_get_env_dev(void)
  378. {
  379. struct bootrom_sw_info **p =
  380. (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
  381. int devno = (*p)->boot_dev_instance;
  382. u8 boot_type = (*p)->boot_dev_type;
  383. /* If not boot from sd/mmc, use default value */
  384. if ((boot_type != BOOT_TYPE_SD) && (boot_type != BOOT_TYPE_MMC))
  385. return CONFIG_SYS_MMC_ENV_DEV;
  386. return board_mmc_get_env_dev(devno);
  387. }
  388. #endif
  389. void s_init(void)
  390. {
  391. #if !defined CONFIG_SPL_BUILD
  392. /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
  393. asm volatile(
  394. "mrc p15, 0, r0, c1, c0, 1\n"
  395. "orr r0, r0, #1 << 6\n"
  396. "mcr p15, 0, r0, c1, c0, 1\n");
  397. #endif
  398. /* clock configuration. */
  399. clock_init();
  400. return;
  401. }
  402. void reset_misc(void)
  403. {
  404. #ifdef CONFIG_VIDEO_MXS
  405. lcdif_power_down();
  406. #endif
  407. }