board.c 5.9 KB

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