board.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. *
  3. * Common board functions for OMAP3 based boards.
  4. *
  5. * (C) Copyright 2004-2008
  6. * Texas Instruments, <www.ti.com>
  7. *
  8. * Author :
  9. * Sunil Kumar <sunilsaini05@gmail.com>
  10. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  11. *
  12. * Derived from Beagle Board and 3430 SDP code by
  13. * Richard Woodruff <r-woodruff2@ti.com>
  14. * Syed Mohammed Khasim <khasim@ti.com>
  15. *
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <common.h>
  36. #include <asm/io.h>
  37. #include <asm/arch/sys_proto.h>
  38. #include <asm/arch/mem.h>
  39. #include <asm/cache.h>
  40. #include <asm/armv7.h>
  41. #include <asm/arch/gpio.h>
  42. #include <asm/spl.h>
  43. #include <asm/omap_common.h>
  44. #include <i2c.h>
  45. #include <linux/compiler.h>
  46. /* Declarations */
  47. extern omap3_sysinfo sysinfo;
  48. static void omap3_setup_aux_cr(void);
  49. static void omap3_invalidate_l2_cache_secure(void);
  50. static const struct gpio_bank gpio_bank_34xx[6] = {
  51. { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
  52. { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
  53. { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
  54. { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
  55. { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
  56. { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
  57. };
  58. const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
  59. #ifdef CONFIG_SPL_BUILD
  60. /*
  61. * We use static variables because global data is not ready yet.
  62. * Initialized data is available in SPL right from the beginning.
  63. * We would not typically need to save these parameters in regular
  64. * U-Boot. This is needed only in SPL at the moment.
  65. */
  66. u32 omap3_boot_device = BOOT_DEVICE_NAND;
  67. /* auto boot mode detection is not possible for OMAP3 - hard code */
  68. u32 spl_boot_mode(void)
  69. {
  70. switch (spl_boot_device()) {
  71. case BOOT_DEVICE_MMC2:
  72. return MMCSD_MODE_RAW;
  73. case BOOT_DEVICE_MMC1:
  74. return MMCSD_MODE_FAT;
  75. break;
  76. default:
  77. puts("spl: ERROR: unknown device - can't select boot mode\n");
  78. hang();
  79. }
  80. }
  81. u32 spl_boot_device(void)
  82. {
  83. return omap3_boot_device;
  84. }
  85. void spl_board_init(void)
  86. {
  87. #ifdef CONFIG_SPL_I2C_SUPPORT
  88. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  89. #endif
  90. }
  91. #endif /* CONFIG_SPL_BUILD */
  92. /******************************************************************************
  93. * Routine: secure_unlock
  94. * Description: Setup security registers for access
  95. * (GP Device only)
  96. *****************************************************************************/
  97. void secure_unlock_mem(void)
  98. {
  99. struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
  100. struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
  101. struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
  102. struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
  103. struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
  104. /* Protection Module Register Target APE (PM_RT) */
  105. writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
  106. writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
  107. writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
  108. writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
  109. writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
  110. writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
  111. writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
  112. writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
  113. writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
  114. writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
  115. writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
  116. /* IVA Changes */
  117. writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
  118. writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
  119. writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
  120. /* SDRC region 0 public */
  121. writel(UNLOCK_1, &sms_base->rg_att0);
  122. }
  123. /******************************************************************************
  124. * Routine: secureworld_exit()
  125. * Description: If chip is EMU and boot type is external
  126. * configure secure registers and exit secure world
  127. * general use.
  128. *****************************************************************************/
  129. void secureworld_exit()
  130. {
  131. unsigned long i;
  132. /* configure non-secure access control register */
  133. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
  134. /* enabling co-processor CP10 and CP11 accesses in NS world */
  135. __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
  136. /*
  137. * allow allocation of locked TLBs and L2 lines in NS world
  138. * allow use of PLE registers in NS world also
  139. */
  140. __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
  141. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
  142. /* Enable ASA in ACR register */
  143. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  144. __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
  145. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  146. /* Exiting secure world */
  147. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
  148. __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
  149. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
  150. }
  151. /******************************************************************************
  152. * Routine: try_unlock_sram()
  153. * Description: If chip is GP/EMU(special) type, unlock the SRAM for
  154. * general use.
  155. *****************************************************************************/
  156. void try_unlock_memory()
  157. {
  158. int mode;
  159. int in_sdram = is_running_in_sdram();
  160. /*
  161. * if GP device unlock device SRAM for general use
  162. * secure code breaks for Secure/Emulation device - HS/E/T
  163. */
  164. mode = get_device_type();
  165. if (mode == GP_DEVICE)
  166. secure_unlock_mem();
  167. /*
  168. * If device is EMU and boot is XIP external booting
  169. * Unlock firewalls and disable L2 and put chip
  170. * out of secure world
  171. *
  172. * Assuming memories are unlocked by the demon who put us in SDRAM
  173. */
  174. if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
  175. && (!in_sdram)) {
  176. secure_unlock_mem();
  177. secureworld_exit();
  178. }
  179. return;
  180. }
  181. /******************************************************************************
  182. * Routine: s_init
  183. * Description: Does early system init of muxing and clocks.
  184. * - Called path is with SRAM stack.
  185. *****************************************************************************/
  186. void s_init(void)
  187. {
  188. int in_sdram = is_running_in_sdram();
  189. watchdog_init();
  190. try_unlock_memory();
  191. /* Errata workarounds */
  192. omap3_setup_aux_cr();
  193. #ifndef CONFIG_SYS_L2CACHE_OFF
  194. /* Invalidate L2-cache from secure mode */
  195. omap3_invalidate_l2_cache_secure();
  196. #endif
  197. set_muxconf_regs();
  198. sdelay(100);
  199. prcm_init();
  200. per_clocks_enable();
  201. #ifdef CONFIG_USB_EHCI_OMAP
  202. ehci_clocks_enable();
  203. #endif
  204. #ifdef CONFIG_SPL_BUILD
  205. preloader_console_init();
  206. timer_init();
  207. #endif
  208. if (!in_sdram)
  209. mem_init();
  210. }
  211. /*
  212. * Routine: misc_init_r
  213. * Description: A basic misc_init_r that just displays the die ID
  214. */
  215. int __weak misc_init_r(void)
  216. {
  217. dieid_num_r();
  218. return 0;
  219. }
  220. /******************************************************************************
  221. * Routine: wait_for_command_complete
  222. * Description: Wait for posting to finish on watchdog
  223. *****************************************************************************/
  224. void wait_for_command_complete(struct watchdog *wd_base)
  225. {
  226. int pending = 1;
  227. do {
  228. pending = readl(&wd_base->wwps);
  229. } while (pending);
  230. }
  231. /******************************************************************************
  232. * Routine: watchdog_init
  233. * Description: Shut down watch dogs
  234. *****************************************************************************/
  235. void watchdog_init(void)
  236. {
  237. struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
  238. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  239. /*
  240. * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
  241. * either taken care of by ROM (HS/EMU) or not accessible (GP).
  242. * We need to take care of WD2-MPU or take a PRCM reset. WD3
  243. * should not be running and does not generate a PRCM reset.
  244. */
  245. sr32(&prcm_base->fclken_wkup, 5, 1, 1);
  246. sr32(&prcm_base->iclken_wkup, 5, 1, 1);
  247. wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
  248. writel(WD_UNLOCK1, &wd2_base->wspr);
  249. wait_for_command_complete(wd2_base);
  250. writel(WD_UNLOCK2, &wd2_base->wspr);
  251. }
  252. /******************************************************************************
  253. * Dummy function to handle errors for EABI incompatibility
  254. *****************************************************************************/
  255. void abort(void)
  256. {
  257. }
  258. #if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
  259. /******************************************************************************
  260. * OMAP3 specific command to switch between NAND HW and SW ecc
  261. *****************************************************************************/
  262. static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  263. {
  264. if (argc != 2)
  265. goto usage;
  266. if (strncmp(argv[1], "hw", 2) == 0)
  267. omap_nand_switch_ecc(1);
  268. else if (strncmp(argv[1], "sw", 2) == 0)
  269. omap_nand_switch_ecc(0);
  270. else
  271. goto usage;
  272. return 0;
  273. usage:
  274. printf ("Usage: nandecc %s\n", cmdtp->usage);
  275. return 1;
  276. }
  277. U_BOOT_CMD(
  278. nandecc, 2, 1, do_switch_ecc,
  279. "switch OMAP3 NAND ECC calculation algorithm",
  280. "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
  281. );
  282. #endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
  283. #ifdef CONFIG_DISPLAY_BOARDINFO
  284. /**
  285. * Print board information
  286. */
  287. int checkboard (void)
  288. {
  289. char *mem_s ;
  290. if (is_mem_sdr())
  291. mem_s = "mSDR";
  292. else
  293. mem_s = "LPDDR";
  294. printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
  295. sysinfo.nand_string);
  296. return 0;
  297. }
  298. #endif /* CONFIG_DISPLAY_BOARDINFO */
  299. static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
  300. {
  301. u32 i, num_params = *parameters;
  302. u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
  303. /*
  304. * copy the parameters to an un-cached area to avoid coherency
  305. * issues
  306. */
  307. for (i = 0; i < num_params; i++) {
  308. __raw_writel(*parameters, sram_scratch_space);
  309. parameters++;
  310. sram_scratch_space++;
  311. }
  312. /* Now make the PPA call */
  313. do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
  314. }
  315. static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
  316. {
  317. u32 acr;
  318. /* Read ACR */
  319. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  320. acr &= ~clear_bits;
  321. acr |= set_bits;
  322. if (get_device_type() == GP_DEVICE) {
  323. omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
  324. acr);
  325. } else {
  326. struct emu_hal_params emu_romcode_params;
  327. emu_romcode_params.num_params = 1;
  328. emu_romcode_params.param1 = acr;
  329. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
  330. (u32 *)&emu_romcode_params);
  331. }
  332. }
  333. static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
  334. {
  335. u32 acr;
  336. /* Read ACR */
  337. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  338. acr &= ~clear_bits;
  339. acr |= set_bits;
  340. /* Write ACR - affects non-secure banked bits */
  341. asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
  342. }
  343. static void omap3_setup_aux_cr(void)
  344. {
  345. /* Workaround for Cortex-A8 errata: #454179 #430973
  346. * Set "IBE" bit
  347. * Set "Disable Branch Size Mispredicts" bit
  348. * Workaround for erratum #621766
  349. * Enable L1NEON bit
  350. * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
  351. */
  352. omap3_update_aux_cr_secure(0xE0, 0);
  353. }
  354. #ifndef CONFIG_SYS_L2CACHE_OFF
  355. /* Invalidate the entire L2 cache from secure mode */
  356. static void omap3_invalidate_l2_cache_secure(void)
  357. {
  358. if (get_device_type() == GP_DEVICE) {
  359. omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
  360. 0);
  361. } else {
  362. struct emu_hal_params emu_romcode_params;
  363. emu_romcode_params.num_params = 1;
  364. emu_romcode_params.param1 = 0;
  365. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
  366. (u32 *)&emu_romcode_params);
  367. }
  368. }
  369. void v7_outer_cache_enable(void)
  370. {
  371. /* Set L2EN */
  372. omap3_update_aux_cr_secure(0x2, 0);
  373. /*
  374. * On some revisions L2EN bit is banked on some revisions it's not
  375. * No harm in setting both banked bits(in fact this is required
  376. * by an erratum)
  377. */
  378. omap3_update_aux_cr(0x2, 0);
  379. }
  380. void omap3_outer_cache_disable(void)
  381. {
  382. /* Clear L2EN */
  383. omap3_update_aux_cr_secure(0, 0x2);
  384. /*
  385. * On some revisions L2EN bit is banked on some revisions it's not
  386. * No harm in clearing both banked bits(in fact this is required
  387. * by an erratum)
  388. */
  389. omap3_update_aux_cr(0, 0x2);
  390. }
  391. #endif
  392. #ifndef CONFIG_SYS_DCACHE_OFF
  393. void enable_caches(void)
  394. {
  395. /* Enable D-cache. I-cache is already enabled in start.S */
  396. dcache_enable();
  397. }
  398. #endif