hwinit-common.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. init_omap_revision();
  101. hw_data_init();
  102. #ifdef CONFIG_SPL_BUILD
  103. if (warm_reset() &&
  104. (is_omap44xx() || (omap_revision() == OMAP5430_ES1_0)))
  105. force_emif_self_refresh();
  106. #endif
  107. watchdog_init();
  108. set_mux_conf_regs();
  109. #ifdef CONFIG_SPL_BUILD
  110. srcomp_enable();
  111. setup_clocks_for_console();
  112. do_io_settings();
  113. #endif
  114. prcm_init();
  115. #ifdef CONFIG_SPL_BUILD
  116. #ifdef CONFIG_BOARD_EARLY_INIT_F
  117. board_early_init_f();
  118. #endif
  119. /* For regular u-boot sdram_init() is called from dram_init() */
  120. sdram_init();
  121. #endif
  122. }
  123. /*
  124. * Routine: wait_for_command_complete
  125. * Description: Wait for posting to finish on watchdog
  126. */
  127. void wait_for_command_complete(struct watchdog *wd_base)
  128. {
  129. int pending = 1;
  130. do {
  131. pending = readl(&wd_base->wwps);
  132. } while (pending);
  133. }
  134. /*
  135. * Routine: watchdog_init
  136. * Description: Shut down watch dogs
  137. */
  138. void watchdog_init(void)
  139. {
  140. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  141. writel(WD_UNLOCK1, &wd2_base->wspr);
  142. wait_for_command_complete(wd2_base);
  143. writel(WD_UNLOCK2, &wd2_base->wspr);
  144. }
  145. /*
  146. * This function finds the SDRAM size available in the system
  147. * based on DMM section configurations
  148. * This is needed because the size of memory installed may be
  149. * different on different versions of the board
  150. */
  151. u32 omap_sdram_size(void)
  152. {
  153. u32 section, i, valid;
  154. u64 sdram_start = 0, sdram_end = 0, addr,
  155. size, total_size = 0, trap_size = 0, trap_start = 0;
  156. for (i = 0; i < 4; i++) {
  157. section = __raw_readl(DMM_BASE + i*4);
  158. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  159. (EMIF_SDRC_ADDRSPC_SHIFT);
  160. addr = section & EMIF_SYS_ADDR_MASK;
  161. /* See if the address is valid */
  162. if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  163. (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
  164. size = ((section & EMIF_SYS_SIZE_MASK) >>
  165. EMIF_SYS_SIZE_SHIFT);
  166. size = 1 << size;
  167. size *= SZ_16M;
  168. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  169. if (!sdram_start || (addr < sdram_start))
  170. sdram_start = addr;
  171. if (!sdram_end || ((addr + size) > sdram_end))
  172. sdram_end = addr + size;
  173. } else {
  174. trap_size = size;
  175. trap_start = addr;
  176. }
  177. }
  178. }
  179. if ((trap_start >= sdram_start) && (trap_start < sdram_end))
  180. total_size = (sdram_end - sdram_start) - (trap_size);
  181. else
  182. total_size = sdram_end - sdram_start;
  183. return total_size;
  184. }
  185. /*
  186. * Routine: dram_init
  187. * Description: sets uboots idea of sdram size
  188. */
  189. int dram_init(void)
  190. {
  191. sdram_init();
  192. gd->ram_size = omap_sdram_size();
  193. return 0;
  194. }
  195. /*
  196. * Print board information
  197. */
  198. int checkboard(void)
  199. {
  200. puts(sysinfo.board_string);
  201. return 0;
  202. }
  203. /*
  204. * get_device_type(): tell if GP/HS/EMU/TST
  205. */
  206. u32 get_device_type(void)
  207. {
  208. return (readl((*ctrl)->control_status) &
  209. (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
  210. }
  211. #if defined(CONFIG_DISPLAY_CPUINFO)
  212. /*
  213. * Print CPU information
  214. */
  215. int print_cpuinfo(void)
  216. {
  217. puts("CPU : ");
  218. omap_rev_string();
  219. return 0;
  220. }
  221. #endif