hwinit-common.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <asm/arch/sys_proto.h>
  32. #include <asm/sizes.h>
  33. #include <asm/emif.h>
  34. #include <asm/omap_common.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /*
  37. * This is used to verify if the configuration header
  38. * was executed by rom code prior to control of transfer
  39. * to the bootloader. SPL is responsible for saving and
  40. * passing the boot_params pointer to the u-boot.
  41. */
  42. struct omap_boot_parameters boot_params __attribute__ ((section(".data")));
  43. #ifdef CONFIG_SPL_BUILD
  44. /*
  45. * We use static variables because global data is not ready yet.
  46. * Initialized data is available in SPL right from the beginning.
  47. * We would not typically need to save these parameters in regular
  48. * U-Boot. This is needed only in SPL at the moment.
  49. */
  50. u32 omap_bootmode = MMCSD_MODE_FAT;
  51. u32 omap_boot_device(void)
  52. {
  53. return (u32) (boot_params.omap_bootdevice);
  54. }
  55. u32 omap_boot_mode(void)
  56. {
  57. return omap_bootmode;
  58. }
  59. #endif
  60. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  61. {
  62. int i;
  63. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  64. for (i = 0; i < size; i++, pad++)
  65. writew(pad->val, base + pad->offset);
  66. }
  67. static void set_mux_conf_regs(void)
  68. {
  69. switch (omap_hw_init_context()) {
  70. case OMAP_INIT_CONTEXT_SPL:
  71. set_muxconf_regs_essential();
  72. break;
  73. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  74. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  75. set_muxconf_regs_non_essential();
  76. #endif
  77. break;
  78. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  79. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  80. set_muxconf_regs_essential();
  81. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  82. set_muxconf_regs_non_essential();
  83. #endif
  84. break;
  85. }
  86. }
  87. u32 cortex_rev(void)
  88. {
  89. unsigned int rev;
  90. /* Read Main ID Register (MIDR) */
  91. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  92. return rev;
  93. }
  94. void omap_rev_string(char *omap_rev_string)
  95. {
  96. u32 omap_rev = omap_revision();
  97. u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
  98. u32 major_rev = (omap_rev & 0x00000F00) >> 8;
  99. u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
  100. sprintf(omap_rev_string, "OMAP%x ES%x.%x", omap_variant, major_rev,
  101. minor_rev);
  102. }
  103. #ifdef CONFIG_SPL_BUILD
  104. static void init_boot_params(void)
  105. {
  106. boot_params_ptr = (u32 *) &boot_params;
  107. }
  108. #endif
  109. /*
  110. * Routine: s_init
  111. * Description: Does early system init of watchdog, muxing, andclocks
  112. * Watchdog disable is done always. For the rest what gets done
  113. * depends on the boot mode in which this function is executed
  114. * 1. s_init of SPL running from SRAM
  115. * 2. s_init of U-Boot running from FLASH
  116. * 3. s_init of U-Boot loaded to SDRAM by SPL
  117. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  118. * Configuration Header feature
  119. * Please have a look at the respective functions to see what gets
  120. * done in each of these cases
  121. * This function is called with SRAM stack.
  122. */
  123. void s_init(void)
  124. {
  125. init_omap_revision();
  126. watchdog_init();
  127. set_mux_conf_regs();
  128. #ifdef CONFIG_SPL_BUILD
  129. setup_clocks_for_console();
  130. preloader_console_init();
  131. do_io_settings();
  132. #endif
  133. prcm_init();
  134. #ifdef CONFIG_SPL_BUILD
  135. /* For regular u-boot sdram_init() is called from dram_init() */
  136. sdram_init();
  137. init_boot_params();
  138. #endif
  139. }
  140. /*
  141. * Routine: wait_for_command_complete
  142. * Description: Wait for posting to finish on watchdog
  143. */
  144. void wait_for_command_complete(struct watchdog *wd_base)
  145. {
  146. int pending = 1;
  147. do {
  148. pending = readl(&wd_base->wwps);
  149. } while (pending);
  150. }
  151. /*
  152. * Routine: watchdog_init
  153. * Description: Shut down watch dogs
  154. */
  155. void watchdog_init(void)
  156. {
  157. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  158. writel(WD_UNLOCK1, &wd2_base->wspr);
  159. wait_for_command_complete(wd2_base);
  160. writel(WD_UNLOCK2, &wd2_base->wspr);
  161. }
  162. /*
  163. * This function finds the SDRAM size available in the system
  164. * based on DMM section configurations
  165. * This is needed because the size of memory installed may be
  166. * different on different versions of the board
  167. */
  168. u32 omap_sdram_size(void)
  169. {
  170. u32 section, i, total_size = 0, size, addr;
  171. for (i = 0; i < 4; i++) {
  172. section = __raw_readl(DMM_BASE + i*4);
  173. addr = section & EMIF_SYS_ADDR_MASK;
  174. /* See if the address is valid */
  175. if ((addr >= DRAM_ADDR_SPACE_START) &&
  176. (addr < DRAM_ADDR_SPACE_END)) {
  177. size = ((section & EMIF_SYS_SIZE_MASK) >>
  178. EMIF_SYS_SIZE_SHIFT);
  179. size = 1 << size;
  180. size *= SZ_16M;
  181. total_size += size;
  182. }
  183. }
  184. return total_size;
  185. }
  186. /*
  187. * Routine: dram_init
  188. * Description: sets uboots idea of sdram size
  189. */
  190. int dram_init(void)
  191. {
  192. sdram_init();
  193. gd->ram_size = omap_sdram_size();
  194. return 0;
  195. }
  196. /*
  197. * Print board information
  198. */
  199. int checkboard(void)
  200. {
  201. puts(sysinfo.board_string);
  202. return 0;
  203. }
  204. /*
  205. * This function is called by start_armboot. You can reliably use static
  206. * data. Any boot-time function that require static data should be
  207. * called from here
  208. */
  209. int arch_cpu_init(void)
  210. {
  211. return 0;
  212. }
  213. /*
  214. * get_device_type(): tell if GP/HS/EMU/TST
  215. */
  216. u32 get_device_type(void)
  217. {
  218. return 0;
  219. }
  220. /*
  221. * Print CPU information
  222. */
  223. int print_cpuinfo(void)
  224. {
  225. char rev_string_buffer[50];
  226. omap_rev_string(rev_string_buffer);
  227. printf("CPU : %s\n", rev_string_buffer);
  228. return 0;
  229. }
  230. #ifndef CONFIG_SYS_DCACHE_OFF
  231. void enable_caches(void)
  232. {
  233. /* Enable D-cache. I-cache is already enabled in start.S */
  234. dcache_enable();
  235. }
  236. #endif