hwinit-common.c 6.5 KB

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