hwinit-common.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. gd->ram_size = omap_sdram_size();
  155. }
  156. #endif
  157. int arch_cpu_init_dm(void)
  158. {
  159. early_system_init();
  160. return 0;
  161. }
  162. /*
  163. * Routine: wait_for_command_complete
  164. * Description: Wait for posting to finish on watchdog
  165. */
  166. void wait_for_command_complete(struct watchdog *wd_base)
  167. {
  168. int pending = 1;
  169. do {
  170. pending = readl(&wd_base->wwps);
  171. } while (pending);
  172. }
  173. /*
  174. * Routine: watchdog_init
  175. * Description: Shut down watch dogs
  176. */
  177. void watchdog_init(void)
  178. {
  179. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  180. writel(WD_UNLOCK1, &wd2_base->wspr);
  181. wait_for_command_complete(wd2_base);
  182. writel(WD_UNLOCK2, &wd2_base->wspr);
  183. }
  184. /*
  185. * This function finds the SDRAM size available in the system
  186. * based on DMM section configurations
  187. * This is needed because the size of memory installed may be
  188. * different on different versions of the board
  189. */
  190. u32 omap_sdram_size(void)
  191. {
  192. u32 section, i, valid;
  193. u64 sdram_start = 0, sdram_end = 0, addr,
  194. size, total_size = 0, trap_size = 0, trap_start = 0;
  195. for (i = 0; i < 4; i++) {
  196. section = __raw_readl(DMM_BASE + i*4);
  197. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  198. (EMIF_SDRC_ADDRSPC_SHIFT);
  199. addr = section & EMIF_SYS_ADDR_MASK;
  200. /* See if the address is valid */
  201. if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  202. (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
  203. size = ((section & EMIF_SYS_SIZE_MASK) >>
  204. EMIF_SYS_SIZE_SHIFT);
  205. size = 1 << size;
  206. size *= SZ_16M;
  207. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  208. if (!sdram_start || (addr < sdram_start))
  209. sdram_start = addr;
  210. if (!sdram_end || ((addr + size) > sdram_end))
  211. sdram_end = addr + size;
  212. } else {
  213. trap_size = size;
  214. trap_start = addr;
  215. }
  216. }
  217. }
  218. if ((trap_start >= sdram_start) && (trap_start < sdram_end))
  219. total_size = (sdram_end - sdram_start) - (trap_size);
  220. else
  221. total_size = sdram_end - sdram_start;
  222. return total_size;
  223. }
  224. /*
  225. * Routine: dram_init
  226. * Description: sets uboots idea of sdram size
  227. */
  228. int dram_init(void)
  229. {
  230. sdram_init();
  231. gd->ram_size = omap_sdram_size();
  232. return 0;
  233. }
  234. /*
  235. * Print board information
  236. */
  237. int checkboard(void)
  238. {
  239. puts(sysinfo.board_string);
  240. return 0;
  241. }
  242. /*
  243. * get_device_type(): tell if GP/HS/EMU/TST
  244. */
  245. u32 get_device_type(void)
  246. {
  247. return (readl((*ctrl)->control_status) &
  248. (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
  249. }
  250. #if defined(CONFIG_DISPLAY_CPUINFO)
  251. /*
  252. * Print CPU information
  253. */
  254. int print_cpuinfo(void)
  255. {
  256. puts("CPU : ");
  257. omap_rev_string();
  258. return 0;
  259. }
  260. #endif