hwinit-common.c 6.6 KB

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