board.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. /*
  67. * Some tuning of IOs for optimal power and performance
  68. */
  69. static void do_io_settings(void)
  70. {
  71. u32 lpddr2io;
  72. struct control_lpddr2io_regs *lpddr2io_regs =
  73. (struct control_lpddr2io_regs *)LPDDR2_IO_REGS_BASE;
  74. struct omap4_sys_ctrl_regs *const ctrl =
  75. (struct omap4_sys_ctrl_regs *)SYSCTRL_GENERAL_CORE_BASE;
  76. u32 omap4_rev = omap_revision();
  77. if (omap4_rev == OMAP4430_ES1_0)
  78. lpddr2io = CONTROL_LPDDR2IO_SLEW_125PS_DRV8_PULL_DOWN;
  79. else if (omap4_rev == OMAP4430_ES2_0)
  80. lpddr2io = CONTROL_LPDDR2IO_SLEW_325PS_DRV8_GATE_KEEPER;
  81. else
  82. lpddr2io = CONTROL_LPDDR2IO_SLEW_315PS_DRV12_PULL_DOWN;
  83. /* EMIF1 */
  84. writel(lpddr2io, &lpddr2io_regs->control_lpddr2io1_0);
  85. writel(lpddr2io, &lpddr2io_regs->control_lpddr2io1_1);
  86. /* No pull for GR10 as per hw team's recommendation */
  87. writel(lpddr2io & ~LPDDR2IO_GR10_WD_MASK,
  88. &lpddr2io_regs->control_lpddr2io1_2);
  89. writel(CONTROL_LPDDR2IO_3_VAL, &lpddr2io_regs->control_lpddr2io1_3);
  90. /* EMIF2 */
  91. writel(lpddr2io, &lpddr2io_regs->control_lpddr2io2_0);
  92. writel(lpddr2io, &lpddr2io_regs->control_lpddr2io2_1);
  93. /* No pull for GR10 as per hw team's recommendation */
  94. writel(lpddr2io & ~LPDDR2IO_GR10_WD_MASK,
  95. &lpddr2io_regs->control_lpddr2io2_2);
  96. writel(CONTROL_LPDDR2IO_3_VAL, &lpddr2io_regs->control_lpddr2io2_3);
  97. /*
  98. * Some of these settings (TRIM values) come from eFuse and are
  99. * in turn programmed in the eFuse at manufacturing time after
  100. * calibration of the device. Do the software over-ride only if
  101. * the device is not correctly trimmed
  102. */
  103. if (!(readl(&ctrl->control_std_fuse_opp_bgap) & 0xFFFF)) {
  104. writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
  105. &ctrl->control_ldosram_iva_voltage_ctrl);
  106. writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
  107. &ctrl->control_ldosram_mpu_voltage_ctrl);
  108. writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
  109. &ctrl->control_ldosram_core_voltage_ctrl);
  110. }
  111. if (!readl(&ctrl->control_efuse_1))
  112. writel(CONTROL_EFUSE_1_OVERRIDE, &ctrl->control_efuse_1);
  113. if (!readl(&ctrl->control_efuse_2))
  114. writel(CONTROL_EFUSE_2_OVERRIDE, &ctrl->control_efuse_2);
  115. }
  116. #endif
  117. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  118. {
  119. int i;
  120. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  121. for (i = 0; i < size; i++, pad++)
  122. writew(pad->val, base + pad->offset);
  123. }
  124. static void set_muxconf_regs_essential(void)
  125. {
  126. do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
  127. sizeof(core_padconf_array_essential) /
  128. sizeof(struct pad_conf_entry));
  129. do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
  130. sizeof(wkup_padconf_array_essential) /
  131. sizeof(struct pad_conf_entry));
  132. if (omap_revision() >= OMAP4460_ES1_0)
  133. do_set_mux(CONTROL_PADCONF_WKUP,
  134. wkup_padconf_array_essential_4460,
  135. sizeof(wkup_padconf_array_essential_4460) /
  136. sizeof(struct pad_conf_entry));
  137. }
  138. static void set_mux_conf_regs(void)
  139. {
  140. switch (omap4_hw_init_context()) {
  141. case OMAP_INIT_CONTEXT_SPL:
  142. set_muxconf_regs_essential();
  143. break;
  144. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  145. set_muxconf_regs_non_essential();
  146. break;
  147. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  148. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  149. set_muxconf_regs_essential();
  150. set_muxconf_regs_non_essential();
  151. break;
  152. }
  153. }
  154. static u32 cortex_a9_rev(void)
  155. {
  156. unsigned int rev;
  157. /* Read Main ID Register (MIDR) */
  158. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  159. return rev;
  160. }
  161. static void init_omap4_revision(void)
  162. {
  163. /*
  164. * For some of the ES2/ES1 boards ID_CODE is not reliable:
  165. * Also, ES1 and ES2 have different ARM revisions
  166. * So use ARM revision for identification
  167. */
  168. unsigned int arm_rev = cortex_a9_rev();
  169. switch (arm_rev) {
  170. case MIDR_CORTEX_A9_R0P1:
  171. *omap4_revision = OMAP4430_ES1_0;
  172. break;
  173. case MIDR_CORTEX_A9_R1P2:
  174. switch (readl(CONTROL_ID_CODE)) {
  175. case OMAP4430_CONTROL_ID_CODE_ES2_0:
  176. *omap4_revision = OMAP4430_ES2_0;
  177. break;
  178. case OMAP4430_CONTROL_ID_CODE_ES2_1:
  179. *omap4_revision = OMAP4430_ES2_1;
  180. break;
  181. case OMAP4430_CONTROL_ID_CODE_ES2_2:
  182. *omap4_revision = OMAP4430_ES2_2;
  183. break;
  184. default:
  185. *omap4_revision = OMAP4430_ES2_0;
  186. break;
  187. }
  188. break;
  189. case MIDR_CORTEX_A9_R1P3:
  190. *omap4_revision = OMAP4430_ES2_3;
  191. break;
  192. case MIDR_CORTEX_A9_R2P10:
  193. switch (readl(CONTROL_ID_CODE)) {
  194. case OMAP4460_CONTROL_ID_CODE_ES1_0:
  195. *omap4_revision = OMAP4460_ES1_0;
  196. break;
  197. case OMAP4460_CONTROL_ID_CODE_ES1_1:
  198. *omap4_revision = OMAP4460_ES1_1;
  199. break;
  200. default:
  201. *omap4_revision = OMAP4460_ES1_0;
  202. break;
  203. }
  204. break;
  205. default:
  206. *omap4_revision = OMAP4430_SILICON_ID_INVALID;
  207. break;
  208. }
  209. }
  210. void omap_rev_string(char *omap4_rev_string)
  211. {
  212. u32 omap4_rev = omap_revision();
  213. u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
  214. u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
  215. u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
  216. sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
  217. minor_rev);
  218. }
  219. /*
  220. * Routine: s_init
  221. * Description: Does early system init of watchdog, muxing, andclocks
  222. * Watchdog disable is done always. For the rest what gets done
  223. * depends on the boot mode in which this function is executed
  224. * 1. s_init of SPL running from SRAM
  225. * 2. s_init of U-Boot running from FLASH
  226. * 3. s_init of U-Boot loaded to SDRAM by SPL
  227. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  228. * Configuration Header feature
  229. * Please have a look at the respective functions to see what gets
  230. * done in each of these cases
  231. * This function is called with SRAM stack.
  232. */
  233. void s_init(void)
  234. {
  235. init_omap4_revision();
  236. watchdog_init();
  237. set_mux_conf_regs();
  238. #ifdef CONFIG_SPL_BUILD
  239. setup_clocks_for_console();
  240. preloader_console_init();
  241. do_io_settings();
  242. #endif
  243. prcm_init();
  244. #ifdef CONFIG_SPL_BUILD
  245. /* For regular u-boot sdram_init() is called from dram_init() */
  246. sdram_init();
  247. #endif
  248. }
  249. /*
  250. * Routine: wait_for_command_complete
  251. * Description: Wait for posting to finish on watchdog
  252. */
  253. void wait_for_command_complete(struct watchdog *wd_base)
  254. {
  255. int pending = 1;
  256. do {
  257. pending = readl(&wd_base->wwps);
  258. } while (pending);
  259. }
  260. /*
  261. * Routine: watchdog_init
  262. * Description: Shut down watch dogs
  263. */
  264. void watchdog_init(void)
  265. {
  266. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  267. writel(WD_UNLOCK1, &wd2_base->wspr);
  268. wait_for_command_complete(wd2_base);
  269. writel(WD_UNLOCK2, &wd2_base->wspr);
  270. }
  271. /*
  272. * This function finds the SDRAM size available in the system
  273. * based on DMM section configurations
  274. * This is needed because the size of memory installed may be
  275. * different on different versions of the board
  276. */
  277. u32 omap4_sdram_size(void)
  278. {
  279. u32 section, i, total_size = 0, size, addr;
  280. for (i = 0; i < 4; i++) {
  281. section = __raw_readl(OMAP44XX_DMM_LISA_MAP_BASE + i*4);
  282. addr = section & OMAP44XX_SYS_ADDR_MASK;
  283. /* See if the address is valid */
  284. if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
  285. (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
  286. size = ((section & OMAP44XX_SYS_SIZE_MASK) >>
  287. OMAP44XX_SYS_SIZE_SHIFT);
  288. size = 1 << size;
  289. size *= SZ_16M;
  290. total_size += size;
  291. }
  292. }
  293. return total_size;
  294. }
  295. /*
  296. * Routine: dram_init
  297. * Description: sets uboots idea of sdram size
  298. */
  299. int dram_init(void)
  300. {
  301. sdram_init();
  302. gd->ram_size = omap4_sdram_size();
  303. return 0;
  304. }
  305. /*
  306. * Print board information
  307. */
  308. int checkboard(void)
  309. {
  310. puts(sysinfo.board_string);
  311. return 0;
  312. }
  313. /*
  314. * This function is called by start_armboot. You can reliably use static
  315. * data. Any boot-time function that require static data should be
  316. * called from here
  317. */
  318. int arch_cpu_init(void)
  319. {
  320. return 0;
  321. }
  322. #ifndef CONFIG_SYS_L2CACHE_OFF
  323. void v7_outer_cache_enable(void)
  324. {
  325. set_pl310_ctrl_reg(1);
  326. }
  327. void v7_outer_cache_disable(void)
  328. {
  329. set_pl310_ctrl_reg(0);
  330. }
  331. #endif
  332. #ifndef CONFIG_SYS_DCACHE_OFF
  333. void enable_caches(void)
  334. {
  335. /* Enable D-cache. I-cache is already enabled in start.S */
  336. dcache_enable();
  337. }
  338. #endif