hwinit-common.c 6.5 KB

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