hwinit-common.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  37. {
  38. int i;
  39. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  40. for (i = 0; i < size; i++, pad++)
  41. writew(pad->val, base + pad->offset);
  42. }
  43. static void set_mux_conf_regs(void)
  44. {
  45. switch (omap_hw_init_context()) {
  46. case OMAP_INIT_CONTEXT_SPL:
  47. set_muxconf_regs_essential();
  48. break;
  49. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  50. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  51. set_muxconf_regs_non_essential();
  52. #endif
  53. break;
  54. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  55. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  56. set_muxconf_regs_essential();
  57. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  58. set_muxconf_regs_non_essential();
  59. #endif
  60. break;
  61. }
  62. }
  63. u32 cortex_rev(void)
  64. {
  65. unsigned int rev;
  66. /* Read Main ID Register (MIDR) */
  67. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  68. return rev;
  69. }
  70. void omap_rev_string(char *omap_rev_string)
  71. {
  72. u32 omap_rev = omap_revision();
  73. u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
  74. u32 major_rev = (omap_rev & 0x00000F00) >> 8;
  75. u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
  76. sprintf(omap_rev_string, "OMAP%x ES%x.%x", omap_variant, major_rev,
  77. minor_rev);
  78. }
  79. #ifdef CONFIG_SPL_BUILD
  80. static void init_boot_params(void)
  81. {
  82. boot_params_ptr = (u32 *) &boot_params;
  83. }
  84. #endif
  85. /*
  86. * Routine: s_init
  87. * Description: Does early system init of watchdog, muxing, andclocks
  88. * Watchdog disable is done always. For the rest what gets done
  89. * depends on the boot mode in which this function is executed
  90. * 1. s_init of SPL running from SRAM
  91. * 2. s_init of U-Boot running from FLASH
  92. * 3. s_init of U-Boot loaded to SDRAM by SPL
  93. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  94. * Configuration Header feature
  95. * Please have a look at the respective functions to see what gets
  96. * done in each of these cases
  97. * This function is called with SRAM stack.
  98. */
  99. void s_init(void)
  100. {
  101. init_omap_revision();
  102. watchdog_init();
  103. set_mux_conf_regs();
  104. #ifdef CONFIG_SPL_BUILD
  105. setup_clocks_for_console();
  106. preloader_console_init();
  107. do_io_settings();
  108. #endif
  109. prcm_init();
  110. #ifdef CONFIG_SPL_BUILD
  111. /* For regular u-boot sdram_init() is called from dram_init() */
  112. sdram_init();
  113. init_boot_params();
  114. #endif
  115. }
  116. /*
  117. * Routine: wait_for_command_complete
  118. * Description: Wait for posting to finish on watchdog
  119. */
  120. void wait_for_command_complete(struct watchdog *wd_base)
  121. {
  122. int pending = 1;
  123. do {
  124. pending = readl(&wd_base->wwps);
  125. } while (pending);
  126. }
  127. /*
  128. * Routine: watchdog_init
  129. * Description: Shut down watch dogs
  130. */
  131. void watchdog_init(void)
  132. {
  133. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  134. writel(WD_UNLOCK1, &wd2_base->wspr);
  135. wait_for_command_complete(wd2_base);
  136. writel(WD_UNLOCK2, &wd2_base->wspr);
  137. }
  138. /*
  139. * This function finds the SDRAM size available in the system
  140. * based on DMM section configurations
  141. * This is needed because the size of memory installed may be
  142. * different on different versions of the board
  143. */
  144. u32 omap_sdram_size(void)
  145. {
  146. u32 section, i, total_size = 0, size, addr;
  147. for (i = 0; i < 4; i++) {
  148. section = __raw_readl(DMM_BASE + i*4);
  149. addr = section & EMIF_SYS_ADDR_MASK;
  150. /* See if the address is valid */
  151. if ((addr >= DRAM_ADDR_SPACE_START) &&
  152. (addr < DRAM_ADDR_SPACE_END)) {
  153. size = ((section & EMIF_SYS_SIZE_MASK) >>
  154. EMIF_SYS_SIZE_SHIFT);
  155. size = 1 << size;
  156. size *= SZ_16M;
  157. total_size += size;
  158. }
  159. }
  160. return total_size;
  161. }
  162. /*
  163. * Routine: dram_init
  164. * Description: sets uboots idea of sdram size
  165. */
  166. int dram_init(void)
  167. {
  168. sdram_init();
  169. gd->ram_size = omap_sdram_size();
  170. return 0;
  171. }
  172. /*
  173. * Print board information
  174. */
  175. int checkboard(void)
  176. {
  177. puts(sysinfo.board_string);
  178. return 0;
  179. }
  180. /*
  181. * This function is called by start_armboot. You can reliably use static
  182. * data. Any boot-time function that require static data should be
  183. * called from here
  184. */
  185. int arch_cpu_init(void)
  186. {
  187. return 0;
  188. }
  189. /*
  190. * get_device_type(): tell if GP/HS/EMU/TST
  191. */
  192. u32 get_device_type(void)
  193. {
  194. return 0;
  195. }
  196. /*
  197. * Print CPU information
  198. */
  199. int print_cpuinfo(void)
  200. {
  201. char rev_string_buffer[50];
  202. omap_rev_string(rev_string_buffer);
  203. printf("CPU : %s\n", rev_string_buffer);
  204. return 0;
  205. }
  206. #ifndef CONFIG_SYS_DCACHE_OFF
  207. void enable_caches(void)
  208. {
  209. /* Enable D-cache. I-cache is already enabled in start.S */
  210. dcache_enable();
  211. }
  212. #endif