j721e_init.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * J721E: SoC specific initialization
  4. *
  5. * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
  6. * Lokesh Vutla <lokeshvutla@ti.com>
  7. */
  8. #include <common.h>
  9. #include <init.h>
  10. #include <spl.h>
  11. #include <asm/io.h>
  12. #include <asm/armv7_mpu.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/sysfw-loader.h>
  15. #include "common.h"
  16. #include <asm/arch/sys_proto.h>
  17. #include <linux/soc/ti/ti_sci_protocol.h>
  18. #include <dm.h>
  19. #include <dm/uclass-internal.h>
  20. #include <dm/pinctrl.h>
  21. #include <mmc.h>
  22. #include <remoteproc.h>
  23. #ifdef CONFIG_SPL_BUILD
  24. #ifdef CONFIG_K3_LOAD_SYSFW
  25. #ifdef CONFIG_TI_SECURE_DEVICE
  26. struct fwl_data cbass_hc_cfg0_fwls[] = {
  27. { "PCIE0_CFG", 2560, 8 },
  28. { "PCIE1_CFG", 2561, 8 },
  29. { "USB3SS0_CORE", 2568, 4 },
  30. { "USB3SS1_CORE", 2570, 4 },
  31. { "EMMC8SS0_CFG", 2576, 4 },
  32. { "UFS_HCI0_CFG", 2580, 4 },
  33. { "SERDES0", 2584, 1 },
  34. { "SERDES1", 2585, 1 },
  35. }, cbass_hc0_fwls[] = {
  36. { "PCIE0_HP", 2528, 24 },
  37. { "PCIE0_LP", 2529, 24 },
  38. { "PCIE1_HP", 2530, 24 },
  39. { "PCIE1_LP", 2531, 24 },
  40. }, cbass_rc_cfg0_fwls[] = {
  41. { "EMMCSD4SS0_CFG", 2380, 4 },
  42. }, cbass_rc0_fwls[] = {
  43. { "GPMC0", 2310, 8 },
  44. }, infra_cbass0_fwls[] = {
  45. { "PLL_MMR0", 8, 26 },
  46. { "CTRL_MMR0", 9, 16 },
  47. }, mcu_cbass0_fwls[] = {
  48. { "MCU_R5FSS0_CORE0", 1024, 4 },
  49. { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
  50. { "MCU_R5FSS0_CORE1", 1028, 4 },
  51. { "MCU_FSS0_CFG", 1032, 12 },
  52. { "MCU_FSS0_S1", 1033, 8 },
  53. { "MCU_FSS0_S0", 1036, 8 },
  54. { "MCU_PSROM49152X32", 1048, 1 },
  55. { "MCU_MSRAM128KX64", 1050, 8 },
  56. { "MCU_CTRL_MMR0", 1200, 8 },
  57. { "MCU_PLL_MMR0", 1201, 3 },
  58. { "MCU_CPSW0", 1220, 2 },
  59. }, wkup_cbass0_fwls[] = {
  60. { "WKUP_CTRL_MMR0", 131, 16 },
  61. };
  62. #endif
  63. #endif
  64. static void ctrl_mmr_unlock(void)
  65. {
  66. /* Unlock all WKUP_CTRL_MMR0 module registers */
  67. mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
  68. mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
  69. mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
  70. mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
  71. mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
  72. mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
  73. mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
  74. /* Unlock all MCU_CTRL_MMR0 module registers */
  75. mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
  76. mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
  77. mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
  78. mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
  79. mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
  80. /* Unlock all CTRL_MMR0 module registers */
  81. mmr_unlock(CTRL_MMR0_BASE, 0);
  82. mmr_unlock(CTRL_MMR0_BASE, 1);
  83. mmr_unlock(CTRL_MMR0_BASE, 2);
  84. mmr_unlock(CTRL_MMR0_BASE, 3);
  85. mmr_unlock(CTRL_MMR0_BASE, 5);
  86. if (soc_is_j721e())
  87. mmr_unlock(CTRL_MMR0_BASE, 6);
  88. mmr_unlock(CTRL_MMR0_BASE, 7);
  89. }
  90. #if defined(CONFIG_K3_LOAD_SYSFW)
  91. void k3_mmc_stop_clock(void)
  92. {
  93. if (spl_boot_device() == BOOT_DEVICE_MMC1) {
  94. struct mmc *mmc = find_mmc_device(0);
  95. if (!mmc)
  96. return;
  97. mmc->saved_clock = mmc->clock;
  98. mmc_set_clock(mmc, 0, true);
  99. }
  100. }
  101. void k3_mmc_restart_clock(void)
  102. {
  103. if (spl_boot_device() == BOOT_DEVICE_MMC1) {
  104. struct mmc *mmc = find_mmc_device(0);
  105. if (!mmc)
  106. return;
  107. mmc_set_clock(mmc, mmc->saved_clock, false);
  108. }
  109. }
  110. #endif
  111. /*
  112. * This uninitialized global variable would normal end up in the .bss section,
  113. * but the .bss is cleared between writing and reading this variable, so move
  114. * it to the .data section.
  115. */
  116. u32 bootindex __section(".data");
  117. static struct rom_extended_boot_data bootdata __section(".data");
  118. static void store_boot_info_from_rom(void)
  119. {
  120. bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
  121. memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
  122. sizeof(struct rom_extended_boot_data));
  123. }
  124. void board_init_f(ulong dummy)
  125. {
  126. #if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
  127. struct udevice *dev;
  128. int ret;
  129. #endif
  130. /*
  131. * Cannot delay this further as there is a chance that
  132. * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
  133. */
  134. store_boot_info_from_rom();
  135. /* Make all control module registers accessible */
  136. ctrl_mmr_unlock();
  137. #ifdef CONFIG_CPU_V7R
  138. disable_linefill_optimization();
  139. setup_k3_mpu_regions();
  140. #endif
  141. /* Init DM early */
  142. spl_early_init();
  143. #ifdef CONFIG_K3_LOAD_SYSFW
  144. /*
  145. * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
  146. * regardless of the result of pinctrl. Do this without probing the
  147. * device, but instead by searching the device that would request the
  148. * given sequence number if probed. The UART will be used by the system
  149. * firmware (SYSFW) image for various purposes and SYSFW depends on us
  150. * to initialize its pin settings.
  151. */
  152. ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
  153. if (!ret)
  154. pinctrl_select_state(dev, "default");
  155. /*
  156. * Load, start up, and configure system controller firmware. Provide
  157. * the U-Boot console init function to the SYSFW post-PM configuration
  158. * callback hook, effectively switching on (or over) the console
  159. * output.
  160. */
  161. k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
  162. k3_mmc_stop_clock, k3_mmc_restart_clock);
  163. /*
  164. * Force probe of clk_k3 driver here to ensure basic default clock
  165. * configuration is always done.
  166. */
  167. if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
  168. ret = uclass_get_device_by_driver(UCLASS_CLK,
  169. DM_DRIVER_GET(ti_clk),
  170. &dev);
  171. if (ret)
  172. panic("Failed to initialize clk-k3!\n");
  173. }
  174. /* Prepare console output */
  175. preloader_console_init();
  176. /* Disable ROM configured firewalls right after loading sysfw */
  177. #ifdef CONFIG_TI_SECURE_DEVICE
  178. remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
  179. remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
  180. remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
  181. remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
  182. remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
  183. remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
  184. remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
  185. #endif
  186. #else
  187. /* Prepare console output */
  188. preloader_console_init();
  189. #endif
  190. /* Output System Firmware version info */
  191. k3_sysfw_print_ver();
  192. /* Perform EEPROM-based board detection */
  193. if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
  194. do_board_detect();
  195. #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
  196. ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
  197. &dev);
  198. if (ret)
  199. printf("AVS init failed: %d\n", ret);
  200. #endif
  201. #if defined(CONFIG_K3_J721E_DDRSS)
  202. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  203. if (ret)
  204. panic("DRAM init failed: %d\n", ret);
  205. #endif
  206. spl_enable_dcache();
  207. }
  208. u32 spl_mmc_boot_mode(const u32 boot_device)
  209. {
  210. switch (boot_device) {
  211. case BOOT_DEVICE_MMC1:
  212. return MMCSD_MODE_EMMCBOOT;
  213. case BOOT_DEVICE_MMC2:
  214. return MMCSD_MODE_FS;
  215. default:
  216. return MMCSD_MODE_RAW;
  217. }
  218. }
  219. static u32 __get_backup_bootmedia(u32 main_devstat)
  220. {
  221. u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
  222. MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
  223. switch (bkup_boot) {
  224. case BACKUP_BOOT_DEVICE_USB:
  225. return BOOT_DEVICE_DFU;
  226. case BACKUP_BOOT_DEVICE_UART:
  227. return BOOT_DEVICE_UART;
  228. case BACKUP_BOOT_DEVICE_ETHERNET:
  229. return BOOT_DEVICE_ETHERNET;
  230. case BACKUP_BOOT_DEVICE_MMC2:
  231. {
  232. u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
  233. MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
  234. if (port == 0x0)
  235. return BOOT_DEVICE_MMC1;
  236. return BOOT_DEVICE_MMC2;
  237. }
  238. case BACKUP_BOOT_DEVICE_SPI:
  239. return BOOT_DEVICE_SPI;
  240. case BACKUP_BOOT_DEVICE_I2C:
  241. return BOOT_DEVICE_I2C;
  242. }
  243. return BOOT_DEVICE_RAM;
  244. }
  245. static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
  246. {
  247. u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
  248. WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
  249. bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
  250. BOOT_MODE_B_SHIFT;
  251. if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
  252. bootmode = BOOT_DEVICE_SPI;
  253. if (bootmode == BOOT_DEVICE_MMC2) {
  254. u32 port = (main_devstat &
  255. MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
  256. MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
  257. if (port == 0x0)
  258. bootmode = BOOT_DEVICE_MMC1;
  259. }
  260. return bootmode;
  261. }
  262. u32 spl_boot_device(void)
  263. {
  264. u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
  265. u32 main_devstat;
  266. if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
  267. printf("ERROR: MCU only boot is not yet supported\n");
  268. return BOOT_DEVICE_RAM;
  269. }
  270. /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
  271. main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
  272. if (bootindex == K3_PRIMARY_BOOTMODE)
  273. return __get_primary_bootmedia(main_devstat, wkup_devstat);
  274. else
  275. return __get_backup_bootmedia(main_devstat);
  276. }
  277. #endif
  278. #ifdef CONFIG_SYS_K3_SPL_ATF
  279. #define J721E_DEV_MCU_RTI0 262
  280. #define J721E_DEV_MCU_RTI1 263
  281. #define J721E_DEV_MCU_ARMSS0_CPU0 250
  282. #define J721E_DEV_MCU_ARMSS0_CPU1 251
  283. void release_resources_for_core_shutdown(void)
  284. {
  285. struct ti_sci_handle *ti_sci;
  286. struct ti_sci_dev_ops *dev_ops;
  287. struct ti_sci_proc_ops *proc_ops;
  288. int ret;
  289. u32 i;
  290. const u32 put_device_ids[] = {
  291. J721E_DEV_MCU_RTI0,
  292. J721E_DEV_MCU_RTI1,
  293. };
  294. ti_sci = get_ti_sci_handle();
  295. dev_ops = &ti_sci->ops.dev_ops;
  296. proc_ops = &ti_sci->ops.proc_ops;
  297. /* Iterate through list of devices to put (shutdown) */
  298. for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
  299. u32 id = put_device_ids[i];
  300. ret = dev_ops->put_device(ti_sci, id);
  301. if (ret)
  302. panic("Failed to put device %u (%d)\n", id, ret);
  303. }
  304. const u32 put_core_ids[] = {
  305. J721E_DEV_MCU_ARMSS0_CPU1,
  306. J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
  307. };
  308. /* Iterate through list of cores to put (shutdown) */
  309. for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
  310. u32 id = put_core_ids[i];
  311. /*
  312. * Queue up the core shutdown request. Note that this call
  313. * needs to be followed up by an actual invocation of an WFE
  314. * or WFI CPU instruction.
  315. */
  316. ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
  317. if (ret)
  318. panic("Failed sending core %u shutdown message (%d)\n",
  319. id, ret);
  320. }
  321. }
  322. #endif