hwinit-common.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. *
  4. * Common functions for OMAP4/5 based boards
  5. *
  6. * (C) Copyright 2010
  7. * Texas Instruments, <www.ti.com>
  8. *
  9. * Author :
  10. * Aneesh V <aneesh@ti.com>
  11. * Steve Sakoman <steve@sakoman.com>
  12. */
  13. #include <common.h>
  14. #include <debug_uart.h>
  15. #include <fdtdec.h>
  16. #include <spl.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <linux/sizes.h>
  19. #include <asm/emif.h>
  20. #include <asm/omap_common.h>
  21. #include <linux/compiler.h>
  22. #include <asm/system.h>
  23. #include <dm/root.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  26. {
  27. int i;
  28. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  29. for (i = 0; i < size; i++, pad++)
  30. writew(pad->val, base + pad->offset);
  31. }
  32. static void set_mux_conf_regs(void)
  33. {
  34. switch (omap_hw_init_context()) {
  35. case OMAP_INIT_CONTEXT_SPL:
  36. set_muxconf_regs();
  37. break;
  38. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  39. break;
  40. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  41. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  42. set_muxconf_regs();
  43. break;
  44. }
  45. }
  46. u32 cortex_rev(void)
  47. {
  48. unsigned int rev;
  49. /* Read Main ID Register (MIDR) */
  50. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  51. return rev;
  52. }
  53. static void omap_rev_string(void)
  54. {
  55. u32 omap_rev = omap_revision();
  56. u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
  57. u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
  58. u32 major_rev = (omap_rev & 0x00000F00) >> 8;
  59. u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
  60. const char *sec_s, *package = NULL;
  61. switch (get_device_type()) {
  62. case TST_DEVICE:
  63. sec_s = "TST";
  64. break;
  65. case EMU_DEVICE:
  66. sec_s = "EMU";
  67. break;
  68. case HS_DEVICE:
  69. sec_s = "HS";
  70. break;
  71. case GP_DEVICE:
  72. sec_s = "GP";
  73. break;
  74. default:
  75. sec_s = "?";
  76. }
  77. #if defined(CONFIG_DRA7XX)
  78. if (is_dra76x()) {
  79. switch (omap_rev & 0xF) {
  80. case DRA762_ABZ_PACKAGE:
  81. package = "ABZ";
  82. break;
  83. case DRA762_ACD_PACKAGE:
  84. default:
  85. package = "ACD";
  86. break;
  87. }
  88. }
  89. #endif
  90. if (soc_variant)
  91. printf("OMAP");
  92. else
  93. printf("DRA");
  94. printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
  95. if (package)
  96. printf(" %s package\n", package);
  97. else
  98. puts("\n");
  99. }
  100. #ifdef CONFIG_SPL_BUILD
  101. void spl_display_print(void)
  102. {
  103. omap_rev_string();
  104. }
  105. #endif
  106. void __weak srcomp_enable(void)
  107. {
  108. }
  109. /**
  110. * do_board_detect() - Detect board description
  111. *
  112. * Function to detect board description. This is expected to be
  113. * overridden in the SoC family board file where desired.
  114. */
  115. void __weak do_board_detect(void)
  116. {
  117. }
  118. /**
  119. * vcores_init() - Assign omap_vcores based on board
  120. *
  121. * Function to pick the vcores based on board. This is expected to be
  122. * overridden in the SoC family board file where desired.
  123. */
  124. void __weak vcores_init(void)
  125. {
  126. }
  127. void s_init(void)
  128. {
  129. }
  130. /**
  131. * init_package_revision() - Initialize package revision
  132. *
  133. * Function to get the pacakage information. This is expected to be
  134. * overridden in the SoC family file where desired.
  135. */
  136. void __weak init_package_revision(void)
  137. {
  138. }
  139. /**
  140. * early_system_init - Does Early system initialization.
  141. *
  142. * Does early system init of watchdog, muxing, andclocks
  143. * Watchdog disable is done always. For the rest what gets done
  144. * depends on the boot mode in which this function is executed when
  145. * 1. SPL running from SRAM
  146. * 2. U-Boot running from FLASH
  147. * 3. U-Boot loaded to SDRAM by SPL
  148. * 4. U-Boot loaded to SDRAM by ROM code using the
  149. * Configuration Header feature
  150. * Please have a look at the respective functions to see what gets
  151. * done in each of these cases
  152. * This function is called with SRAM stack.
  153. */
  154. void early_system_init(void)
  155. {
  156. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
  157. int ret;
  158. int rescan;
  159. #endif
  160. init_omap_revision();
  161. hw_data_init();
  162. init_package_revision();
  163. #ifdef CONFIG_SPL_BUILD
  164. if (warm_reset())
  165. force_emif_self_refresh();
  166. #endif
  167. watchdog_init();
  168. set_mux_conf_regs();
  169. #ifdef CONFIG_SPL_BUILD
  170. srcomp_enable();
  171. do_io_settings();
  172. #endif
  173. setup_early_clocks();
  174. #ifdef CONFIG_SPL_BUILD
  175. /*
  176. * Save the boot parameters passed from romcode.
  177. * We cannot delay the saving further than this,
  178. * to prevent overwrites.
  179. */
  180. save_omap_boot_params();
  181. spl_early_init();
  182. #endif
  183. do_board_detect();
  184. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
  185. /*
  186. * Board detection has been done.
  187. * Let us see if another dtb wouldn't be a better match
  188. * for our board
  189. */
  190. ret = fdtdec_resetup(&rescan);
  191. if (!ret && rescan) {
  192. dm_uninit();
  193. dm_init_and_scan(true);
  194. }
  195. #endif
  196. vcores_init();
  197. #ifdef CONFIG_DEBUG_UART_OMAP
  198. debug_uart_init();
  199. #endif
  200. prcm_init();
  201. }
  202. #ifdef CONFIG_SPL_BUILD
  203. void board_init_f(ulong dummy)
  204. {
  205. early_system_init();
  206. #ifdef CONFIG_BOARD_EARLY_INIT_F
  207. board_early_init_f();
  208. #endif
  209. /* For regular u-boot sdram_init() is called from dram_init() */
  210. sdram_init();
  211. gd->ram_size = omap_sdram_size();
  212. }
  213. #endif
  214. int arch_cpu_init_dm(void)
  215. {
  216. early_system_init();
  217. return 0;
  218. }
  219. /*
  220. * Routine: wait_for_command_complete
  221. * Description: Wait for posting to finish on watchdog
  222. */
  223. void wait_for_command_complete(struct watchdog *wd_base)
  224. {
  225. int pending = 1;
  226. do {
  227. pending = readl(&wd_base->wwps);
  228. } while (pending);
  229. }
  230. /*
  231. * Routine: watchdog_init
  232. * Description: Shut down watch dogs
  233. */
  234. void watchdog_init(void)
  235. {
  236. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  237. writel(WD_UNLOCK1, &wd2_base->wspr);
  238. wait_for_command_complete(wd2_base);
  239. writel(WD_UNLOCK2, &wd2_base->wspr);
  240. }
  241. /*
  242. * This function finds the SDRAM size available in the system
  243. * based on DMM section configurations
  244. * This is needed because the size of memory installed may be
  245. * different on different versions of the board
  246. */
  247. u32 omap_sdram_size(void)
  248. {
  249. u32 section, i, valid;
  250. u64 sdram_start = 0, sdram_end = 0, addr,
  251. size, total_size = 0, trap_size = 0, trap_start = 0;
  252. for (i = 0; i < 4; i++) {
  253. section = __raw_readl(DMM_BASE + i*4);
  254. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  255. (EMIF_SDRC_ADDRSPC_SHIFT);
  256. addr = section & EMIF_SYS_ADDR_MASK;
  257. /* See if the address is valid */
  258. if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  259. (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
  260. size = ((section & EMIF_SYS_SIZE_MASK) >>
  261. EMIF_SYS_SIZE_SHIFT);
  262. size = 1 << size;
  263. size *= SZ_16M;
  264. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  265. if (!sdram_start || (addr < sdram_start))
  266. sdram_start = addr;
  267. if (!sdram_end || ((addr + size) > sdram_end))
  268. sdram_end = addr + size;
  269. } else {
  270. trap_size = size;
  271. trap_start = addr;
  272. }
  273. }
  274. }
  275. if ((trap_start >= sdram_start) && (trap_start < sdram_end))
  276. total_size = (sdram_end - sdram_start) - (trap_size);
  277. else
  278. total_size = sdram_end - sdram_start;
  279. return total_size;
  280. }
  281. /*
  282. * Routine: dram_init
  283. * Description: sets uboots idea of sdram size
  284. */
  285. int dram_init(void)
  286. {
  287. sdram_init();
  288. gd->ram_size = omap_sdram_size();
  289. return 0;
  290. }
  291. /*
  292. * Print board information
  293. */
  294. int checkboard(void)
  295. {
  296. puts(sysinfo.board_string);
  297. return 0;
  298. }
  299. #if defined(CONFIG_DISPLAY_CPUINFO)
  300. /*
  301. * Print CPU information
  302. */
  303. int print_cpuinfo(void)
  304. {
  305. puts("CPU : ");
  306. omap_rev_string();
  307. return 0;
  308. }
  309. #endif