board.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. *
  3. * Common functions for OMAP4 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/cpu.h>
  32. #include <asm/arch/sys_proto.h>
  33. #include <asm/sizes.h>
  34. #include "omap4_mux_data.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_muxconf_regs_essential(void)
  44. {
  45. do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
  46. sizeof(core_padconf_array_essential) /
  47. sizeof(struct pad_conf_entry));
  48. do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
  49. sizeof(wkup_padconf_array_essential) /
  50. sizeof(struct pad_conf_entry));
  51. }
  52. static void set_mux_conf_regs(void)
  53. {
  54. switch (omap4_hw_init_context()) {
  55. case OMAP_INIT_CONTEXT_SPL:
  56. set_muxconf_regs_essential();
  57. break;
  58. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  59. set_muxconf_regs_non_essential();
  60. break;
  61. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  62. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  63. set_muxconf_regs_essential();
  64. set_muxconf_regs_non_essential();
  65. break;
  66. }
  67. }
  68. /*
  69. * Routine: s_init
  70. * Description: Does early system init of watchdog, muxing, andclocks
  71. * Watchdog disable is done always. For the rest what gets done
  72. * depends on the boot mode in which this function is executed
  73. * 1. s_init of SPL running from SRAM
  74. * 2. s_init of U-Boot running from FLASH
  75. * 3. s_init of U-Boot loaded to SDRAM by SPL
  76. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  77. * Configuration Header feature
  78. * Please have a look at the respective functions to see what gets
  79. * done in each of these cases
  80. * This function is called with SRAM stack.
  81. */
  82. void s_init(void)
  83. {
  84. watchdog_init();
  85. set_mux_conf_regs();
  86. }
  87. /*
  88. * Routine: wait_for_command_complete
  89. * Description: Wait for posting to finish on watchdog
  90. */
  91. void wait_for_command_complete(struct watchdog *wd_base)
  92. {
  93. int pending = 1;
  94. do {
  95. pending = readl(&wd_base->wwps);
  96. } while (pending);
  97. }
  98. /*
  99. * Routine: watchdog_init
  100. * Description: Shut down watch dogs
  101. */
  102. void watchdog_init(void)
  103. {
  104. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  105. writel(WD_UNLOCK1, &wd2_base->wspr);
  106. wait_for_command_complete(wd2_base);
  107. writel(WD_UNLOCK2, &wd2_base->wspr);
  108. }
  109. /*
  110. * This function finds the SDRAM size available in the system
  111. * based on DMM section configurations
  112. * This is needed because the size of memory installed may be
  113. * different on different versions of the board
  114. */
  115. u32 sdram_size(void)
  116. {
  117. u32 section, i, total_size = 0, size, addr;
  118. for (i = 0; i < 4; i++) {
  119. section = __raw_readl(DMM_LISA_MAP_BASE + i*4);
  120. addr = section & DMM_LISA_MAP_SYS_ADDR_MASK;
  121. /* See if the address is valid */
  122. if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
  123. (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
  124. size = ((section & DMM_LISA_MAP_SYS_SIZE_MASK) >>
  125. DMM_LISA_MAP_SYS_SIZE_SHIFT);
  126. size = 1 << size;
  127. size *= SZ_16M;
  128. total_size += size;
  129. }
  130. }
  131. return total_size;
  132. }
  133. /*
  134. * Routine: dram_init
  135. * Description: sets uboots idea of sdram size
  136. */
  137. int dram_init(void)
  138. {
  139. gd->ram_size = sdram_size();
  140. return 0;
  141. }
  142. /*
  143. * Print board information
  144. */
  145. int checkboard(void)
  146. {
  147. puts(sysinfo.board_string);
  148. return 0;
  149. }
  150. /*
  151. * This function is called by start_armboot. You can reliably use static
  152. * data. Any boot-time function that require static data should be
  153. * called from here
  154. */
  155. int arch_cpu_init(void)
  156. {
  157. return 0;
  158. }
  159. #ifndef CONFIG_SYS_L2CACHE_OFF
  160. void v7_outer_cache_enable(void)
  161. {
  162. set_pl310_ctrl_reg(1);
  163. }
  164. void v7_outer_cache_disable(void)
  165. {
  166. set_pl310_ctrl_reg(0);
  167. }
  168. #endif