board.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/armv7.h>
  32. #include <asm/arch/cpu.h>
  33. #include <asm/arch/sys_proto.h>
  34. #include <asm/sizes.h>
  35. #include <asm/arch/emif.h>
  36. #include "omap4_mux_data.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
  39. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  40. {
  41. int i;
  42. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  43. for (i = 0; i < size; i++, pad++)
  44. writew(pad->val, base + pad->offset);
  45. }
  46. static void set_muxconf_regs_essential(void)
  47. {
  48. do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
  49. sizeof(core_padconf_array_essential) /
  50. sizeof(struct pad_conf_entry));
  51. do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
  52. sizeof(wkup_padconf_array_essential) /
  53. sizeof(struct pad_conf_entry));
  54. }
  55. static void set_mux_conf_regs(void)
  56. {
  57. switch (omap4_hw_init_context()) {
  58. case OMAP_INIT_CONTEXT_SPL:
  59. set_muxconf_regs_essential();
  60. break;
  61. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  62. set_muxconf_regs_non_essential();
  63. break;
  64. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  65. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  66. set_muxconf_regs_essential();
  67. set_muxconf_regs_non_essential();
  68. break;
  69. }
  70. }
  71. static u32 cortex_a9_rev(void)
  72. {
  73. unsigned int rev;
  74. /* Read Main ID Register (MIDR) */
  75. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  76. return rev;
  77. }
  78. static void init_omap4_revision(void)
  79. {
  80. /*
  81. * For some of the ES2/ES1 boards ID_CODE is not reliable:
  82. * Also, ES1 and ES2 have different ARM revisions
  83. * So use ARM revision for identification
  84. */
  85. unsigned int arm_rev = cortex_a9_rev();
  86. switch (arm_rev) {
  87. case MIDR_CORTEX_A9_R0P1:
  88. *omap4_revision = OMAP4430_ES1_0;
  89. break;
  90. case MIDR_CORTEX_A9_R1P2:
  91. switch (readl(CONTROL_ID_CODE)) {
  92. case OMAP4_CONTROL_ID_CODE_ES2_0:
  93. *omap4_revision = OMAP4430_ES2_0;
  94. break;
  95. case OMAP4_CONTROL_ID_CODE_ES2_1:
  96. *omap4_revision = OMAP4430_ES2_1;
  97. break;
  98. case OMAP4_CONTROL_ID_CODE_ES2_2:
  99. *omap4_revision = OMAP4430_ES2_2;
  100. break;
  101. default:
  102. *omap4_revision = OMAP4430_ES2_0;
  103. break;
  104. }
  105. break;
  106. case MIDR_CORTEX_A9_R1P3:
  107. *omap4_revision = OMAP4430_ES2_3;
  108. break;
  109. default:
  110. *omap4_revision = OMAP4430_SILICON_ID_INVALID;
  111. break;
  112. }
  113. }
  114. void omap_rev_string(char *omap4_rev_string)
  115. {
  116. u32 omap4_rev = omap_revision();
  117. u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
  118. u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
  119. u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
  120. sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
  121. minor_rev);
  122. }
  123. /*
  124. * Routine: s_init
  125. * Description: Does early system init of watchdog, muxing, andclocks
  126. * Watchdog disable is done always. For the rest what gets done
  127. * depends on the boot mode in which this function is executed
  128. * 1. s_init of SPL running from SRAM
  129. * 2. s_init of U-Boot running from FLASH
  130. * 3. s_init of U-Boot loaded to SDRAM by SPL
  131. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  132. * Configuration Header feature
  133. * Please have a look at the respective functions to see what gets
  134. * done in each of these cases
  135. * This function is called with SRAM stack.
  136. */
  137. void s_init(void)
  138. {
  139. init_omap4_revision();
  140. watchdog_init();
  141. set_mux_conf_regs();
  142. prcm_init();
  143. }
  144. /*
  145. * Routine: wait_for_command_complete
  146. * Description: Wait for posting to finish on watchdog
  147. */
  148. void wait_for_command_complete(struct watchdog *wd_base)
  149. {
  150. int pending = 1;
  151. do {
  152. pending = readl(&wd_base->wwps);
  153. } while (pending);
  154. }
  155. /*
  156. * Routine: watchdog_init
  157. * Description: Shut down watch dogs
  158. */
  159. void watchdog_init(void)
  160. {
  161. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  162. writel(WD_UNLOCK1, &wd2_base->wspr);
  163. wait_for_command_complete(wd2_base);
  164. writel(WD_UNLOCK2, &wd2_base->wspr);
  165. }
  166. /*
  167. * This function finds the SDRAM size available in the system
  168. * based on DMM section configurations
  169. * This is needed because the size of memory installed may be
  170. * different on different versions of the board
  171. */
  172. u32 omap4_sdram_size(void)
  173. {
  174. u32 section, i, total_size = 0, size, addr;
  175. for (i = 0; i < 4; i++) {
  176. section = __raw_readl(OMAP44XX_DMM_LISA_MAP_BASE + i*4);
  177. addr = section & OMAP44XX_SYS_ADDR_MASK;
  178. /* See if the address is valid */
  179. if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
  180. (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
  181. size = ((section & OMAP44XX_SYS_SIZE_MASK) >>
  182. OMAP44XX_SYS_SIZE_SHIFT);
  183. size = 1 << size;
  184. size *= SZ_16M;
  185. total_size += size;
  186. }
  187. }
  188. return total_size;
  189. }
  190. /*
  191. * Routine: dram_init
  192. * Description: sets uboots idea of sdram size
  193. */
  194. int dram_init(void)
  195. {
  196. sdram_init();
  197. gd->ram_size = omap4_sdram_size();
  198. return 0;
  199. }
  200. /*
  201. * Print board information
  202. */
  203. int checkboard(void)
  204. {
  205. puts(sysinfo.board_string);
  206. return 0;
  207. }
  208. /*
  209. * This function is called by start_armboot. You can reliably use static
  210. * data. Any boot-time function that require static data should be
  211. * called from here
  212. */
  213. int arch_cpu_init(void)
  214. {
  215. return 0;
  216. }
  217. #ifndef CONFIG_SYS_L2CACHE_OFF
  218. void v7_outer_cache_enable(void)
  219. {
  220. set_pl310_ctrl_reg(1);
  221. }
  222. void v7_outer_cache_disable(void)
  223. {
  224. set_pl310_ctrl_reg(0);
  225. }
  226. #endif