hwinit-common.c 6.0 KB

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