hwinit-common.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 <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_essential();
  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_essential();
  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. if (soc_variant)
  59. printf("OMAP");
  60. else
  61. printf("DRA");
  62. printf("%x ES%x.%x\n", omap_variant, major_rev,
  63. minor_rev);
  64. }
  65. #ifdef CONFIG_SPL_BUILD
  66. void spl_display_print(void)
  67. {
  68. omap_rev_string();
  69. }
  70. #endif
  71. void __weak srcomp_enable(void)
  72. {
  73. }
  74. #ifdef CONFIG_ARCH_CPU_INIT
  75. /*
  76. * SOC specific cpu init
  77. */
  78. int arch_cpu_init(void)
  79. {
  80. save_omap_boot_params();
  81. return 0;
  82. }
  83. #endif /* CONFIG_ARCH_CPU_INIT */
  84. /*
  85. * Routine: s_init
  86. * Description: Does early system init of watchdog, muxing, andclocks
  87. * Watchdog disable is done always. For the rest what gets done
  88. * depends on the boot mode in which this function is executed
  89. * 1. s_init of SPL running from SRAM
  90. * 2. s_init of U-Boot running from FLASH
  91. * 3. s_init of U-Boot loaded to SDRAM by SPL
  92. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  93. * Configuration Header feature
  94. * Please have a look at the respective functions to see what gets
  95. * done in each of these cases
  96. * This function is called with SRAM stack.
  97. */
  98. void s_init(void)
  99. {
  100. /*
  101. * Save the boot parameters passed from romcode.
  102. * We cannot delay the saving further than this,
  103. * to prevent overwrites.
  104. */
  105. #ifdef CONFIG_SPL_BUILD
  106. save_omap_boot_params();
  107. #endif
  108. init_omap_revision();
  109. hw_data_init();
  110. #ifdef CONFIG_SPL_BUILD
  111. if (warm_reset() &&
  112. (is_omap44xx() || (omap_revision() == OMAP5430_ES1_0)))
  113. force_emif_self_refresh();
  114. #endif
  115. watchdog_init();
  116. set_mux_conf_regs();
  117. #ifdef CONFIG_SPL_BUILD
  118. srcomp_enable();
  119. setup_clocks_for_console();
  120. gd = &gdata;
  121. preloader_console_init();
  122. do_io_settings();
  123. #endif
  124. prcm_init();
  125. #ifdef CONFIG_SPL_BUILD
  126. #ifdef CONFIG_BOARD_EARLY_INIT_F
  127. board_early_init_f();
  128. #endif
  129. /* For regular u-boot sdram_init() is called from dram_init() */
  130. sdram_init();
  131. #endif
  132. }
  133. /*
  134. * Routine: wait_for_command_complete
  135. * Description: Wait for posting to finish on watchdog
  136. */
  137. void wait_for_command_complete(struct watchdog *wd_base)
  138. {
  139. int pending = 1;
  140. do {
  141. pending = readl(&wd_base->wwps);
  142. } while (pending);
  143. }
  144. /*
  145. * Routine: watchdog_init
  146. * Description: Shut down watch dogs
  147. */
  148. void watchdog_init(void)
  149. {
  150. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  151. writel(WD_UNLOCK1, &wd2_base->wspr);
  152. wait_for_command_complete(wd2_base);
  153. writel(WD_UNLOCK2, &wd2_base->wspr);
  154. }
  155. /*
  156. * This function finds the SDRAM size available in the system
  157. * based on DMM section configurations
  158. * This is needed because the size of memory installed may be
  159. * different on different versions of the board
  160. */
  161. u32 omap_sdram_size(void)
  162. {
  163. u32 section, i, valid;
  164. u64 sdram_start = 0, sdram_end = 0, addr,
  165. size, total_size = 0, trap_size = 0, trap_start = 0;
  166. for (i = 0; i < 4; i++) {
  167. section = __raw_readl(DMM_BASE + i*4);
  168. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  169. (EMIF_SDRC_ADDRSPC_SHIFT);
  170. addr = section & EMIF_SYS_ADDR_MASK;
  171. /* See if the address is valid */
  172. if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  173. (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
  174. size = ((section & EMIF_SYS_SIZE_MASK) >>
  175. EMIF_SYS_SIZE_SHIFT);
  176. size = 1 << size;
  177. size *= SZ_16M;
  178. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  179. if (!sdram_start || (addr < sdram_start))
  180. sdram_start = addr;
  181. if (!sdram_end || ((addr + size) > sdram_end))
  182. sdram_end = addr + size;
  183. } else {
  184. trap_size = size;
  185. trap_start = addr;
  186. }
  187. }
  188. }
  189. if ((trap_start >= sdram_start) && (trap_start < sdram_end))
  190. total_size = (sdram_end - sdram_start) - (trap_size);
  191. else
  192. total_size = sdram_end - sdram_start;
  193. return total_size;
  194. }
  195. /*
  196. * Routine: dram_init
  197. * Description: sets uboots idea of sdram size
  198. */
  199. int dram_init(void)
  200. {
  201. sdram_init();
  202. gd->ram_size = omap_sdram_size();
  203. return 0;
  204. }
  205. /*
  206. * Print board information
  207. */
  208. int checkboard(void)
  209. {
  210. puts(sysinfo.board_string);
  211. return 0;
  212. }
  213. /*
  214. * get_device_type(): tell if GP/HS/EMU/TST
  215. */
  216. u32 get_device_type(void)
  217. {
  218. return (readl((*ctrl)->control_status) &
  219. (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
  220. }
  221. #if defined(CONFIG_DISPLAY_CPUINFO)
  222. /*
  223. * Print CPU information
  224. */
  225. int print_cpuinfo(void)
  226. {
  227. puts("CPU : ");
  228. omap_rev_string();
  229. return 0;
  230. }
  231. #endif