hwinit-common.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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();
  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;
  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 (soc_variant)
  76. printf("OMAP");
  77. else
  78. printf("DRA");
  79. printf("%x-%s ES%x.%x\n", omap_variant, sec_s, major_rev, minor_rev);
  80. }
  81. #ifdef CONFIG_SPL_BUILD
  82. void spl_display_print(void)
  83. {
  84. omap_rev_string();
  85. }
  86. #endif
  87. void __weak srcomp_enable(void)
  88. {
  89. }
  90. /**
  91. * do_board_detect() - Detect board description
  92. *
  93. * Function to detect board description. This is expected to be
  94. * overridden in the SoC family board file where desired.
  95. */
  96. void __weak do_board_detect(void)
  97. {
  98. }
  99. /**
  100. * vcores_init() - Assign omap_vcores based on board
  101. *
  102. * Function to pick the vcores based on board. This is expected to be
  103. * overridden in the SoC family board file where desired.
  104. */
  105. void __weak vcores_init(void)
  106. {
  107. }
  108. void s_init(void)
  109. {
  110. }
  111. /**
  112. * early_system_init - Does Early system initialization.
  113. *
  114. * Does early system init of watchdog, muxing, andclocks
  115. * Watchdog disable is done always. For the rest what gets done
  116. * depends on the boot mode in which this function is executed when
  117. * 1. SPL running from SRAM
  118. * 2. U-Boot running from FLASH
  119. * 3. U-Boot loaded to SDRAM by SPL
  120. * 4. U-Boot loaded to SDRAM by ROM code using the
  121. * Configuration Header feature
  122. * Please have a look at the respective functions to see what gets
  123. * done in each of these cases
  124. * This function is called with SRAM stack.
  125. */
  126. void early_system_init(void)
  127. {
  128. init_omap_revision();
  129. hw_data_init();
  130. #ifdef CONFIG_SPL_BUILD
  131. if (warm_reset())
  132. force_emif_self_refresh();
  133. #endif
  134. watchdog_init();
  135. set_mux_conf_regs();
  136. #ifdef CONFIG_SPL_BUILD
  137. srcomp_enable();
  138. do_io_settings();
  139. #endif
  140. setup_early_clocks();
  141. do_board_detect();
  142. vcores_init();
  143. prcm_init();
  144. }
  145. #ifdef CONFIG_SPL_BUILD
  146. void board_init_f(ulong dummy)
  147. {
  148. early_system_init();
  149. #ifdef CONFIG_BOARD_EARLY_INIT_F
  150. board_early_init_f();
  151. #endif
  152. /* For regular u-boot sdram_init() is called from dram_init() */
  153. sdram_init();
  154. }
  155. #endif
  156. int arch_cpu_init_dm(void)
  157. {
  158. early_system_init();
  159. return 0;
  160. }
  161. /*
  162. * Routine: wait_for_command_complete
  163. * Description: Wait for posting to finish on watchdog
  164. */
  165. void wait_for_command_complete(struct watchdog *wd_base)
  166. {
  167. int pending = 1;
  168. do {
  169. pending = readl(&wd_base->wwps);
  170. } while (pending);
  171. }
  172. /*
  173. * Routine: watchdog_init
  174. * Description: Shut down watch dogs
  175. */
  176. void watchdog_init(void)
  177. {
  178. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  179. writel(WD_UNLOCK1, &wd2_base->wspr);
  180. wait_for_command_complete(wd2_base);
  181. writel(WD_UNLOCK2, &wd2_base->wspr);
  182. }
  183. /*
  184. * This function finds the SDRAM size available in the system
  185. * based on DMM section configurations
  186. * This is needed because the size of memory installed may be
  187. * different on different versions of the board
  188. */
  189. u32 omap_sdram_size(void)
  190. {
  191. u32 section, i, valid;
  192. u64 sdram_start = 0, sdram_end = 0, addr,
  193. size, total_size = 0, trap_size = 0, trap_start = 0;
  194. for (i = 0; i < 4; i++) {
  195. section = __raw_readl(DMM_BASE + i*4);
  196. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  197. (EMIF_SDRC_ADDRSPC_SHIFT);
  198. addr = section & EMIF_SYS_ADDR_MASK;
  199. /* See if the address is valid */
  200. if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  201. (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
  202. size = ((section & EMIF_SYS_SIZE_MASK) >>
  203. EMIF_SYS_SIZE_SHIFT);
  204. size = 1 << size;
  205. size *= SZ_16M;
  206. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  207. if (!sdram_start || (addr < sdram_start))
  208. sdram_start = addr;
  209. if (!sdram_end || ((addr + size) > sdram_end))
  210. sdram_end = addr + size;
  211. } else {
  212. trap_size = size;
  213. trap_start = addr;
  214. }
  215. }
  216. }
  217. if ((trap_start >= sdram_start) && (trap_start < sdram_end))
  218. total_size = (sdram_end - sdram_start) - (trap_size);
  219. else
  220. total_size = sdram_end - sdram_start;
  221. return total_size;
  222. }
  223. /*
  224. * Routine: dram_init
  225. * Description: sets uboots idea of sdram size
  226. */
  227. int dram_init(void)
  228. {
  229. sdram_init();
  230. gd->ram_size = omap_sdram_size();
  231. return 0;
  232. }
  233. /*
  234. * Print board information
  235. */
  236. int checkboard(void)
  237. {
  238. puts(sysinfo.board_string);
  239. return 0;
  240. }
  241. /*
  242. * get_device_type(): tell if GP/HS/EMU/TST
  243. */
  244. u32 get_device_type(void)
  245. {
  246. return (readl((*ctrl)->control_status) &
  247. (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
  248. }
  249. #if defined(CONFIG_DISPLAY_CPUINFO)
  250. /*
  251. * Print CPU information
  252. */
  253. int print_cpuinfo(void)
  254. {
  255. puts("CPU : ");
  256. omap_rev_string();
  257. return 0;
  258. }
  259. #endif