board.c 7.3 KB

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