board.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. /* Declarations */
  42. extern omap3_sysinfo sysinfo;
  43. static void omap3_setup_aux_cr(void);
  44. static void omap3_invalidate_l2_cache_secure(void);
  45. /******************************************************************************
  46. * Routine: delay
  47. * Description: spinning delay to use before udelay works
  48. *****************************************************************************/
  49. static inline void delay(unsigned long loops)
  50. {
  51. __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
  52. "bne 1b":"=r" (loops):"0"(loops));
  53. }
  54. /******************************************************************************
  55. * Routine: secure_unlock
  56. * Description: Setup security registers for access
  57. * (GP Device only)
  58. *****************************************************************************/
  59. void secure_unlock_mem(void)
  60. {
  61. struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
  62. struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
  63. struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
  64. struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
  65. struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
  66. /* Protection Module Register Target APE (PM_RT) */
  67. writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
  68. writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
  69. writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
  70. writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
  71. writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
  72. writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
  73. writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
  74. writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
  75. writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
  76. writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
  77. writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
  78. /* IVA Changes */
  79. writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
  80. writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
  81. writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
  82. /* SDRC region 0 public */
  83. writel(UNLOCK_1, &sms_base->rg_att0);
  84. }
  85. /******************************************************************************
  86. * Routine: secureworld_exit()
  87. * Description: If chip is EMU and boot type is external
  88. * configure secure registers and exit secure world
  89. * general use.
  90. *****************************************************************************/
  91. void secureworld_exit()
  92. {
  93. unsigned long i;
  94. /* configrue non-secure access control register */
  95. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
  96. /* enabling co-processor CP10 and CP11 accesses in NS world */
  97. __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
  98. /*
  99. * allow allocation of locked TLBs and L2 lines in NS world
  100. * allow use of PLE registers in NS world also
  101. */
  102. __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
  103. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
  104. /* Enable ASA in ACR register */
  105. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  106. __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
  107. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  108. /* Exiting secure world */
  109. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
  110. __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
  111. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
  112. }
  113. /******************************************************************************
  114. * Routine: try_unlock_sram()
  115. * Description: If chip is GP/EMU(special) type, unlock the SRAM for
  116. * general use.
  117. *****************************************************************************/
  118. void try_unlock_memory()
  119. {
  120. int mode;
  121. int in_sdram = is_running_in_sdram();
  122. /*
  123. * if GP device unlock device SRAM for general use
  124. * secure code breaks for Secure/Emulation device - HS/E/T
  125. */
  126. mode = get_device_type();
  127. if (mode == GP_DEVICE)
  128. secure_unlock_mem();
  129. /*
  130. * If device is EMU and boot is XIP external booting
  131. * Unlock firewalls and disable L2 and put chip
  132. * out of secure world
  133. *
  134. * Assuming memories are unlocked by the demon who put us in SDRAM
  135. */
  136. if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
  137. && (!in_sdram)) {
  138. secure_unlock_mem();
  139. secureworld_exit();
  140. }
  141. return;
  142. }
  143. /******************************************************************************
  144. * Routine: s_init
  145. * Description: Does early system init of muxing and clocks.
  146. * - Called path is with SRAM stack.
  147. *****************************************************************************/
  148. void s_init(void)
  149. {
  150. int in_sdram = is_running_in_sdram();
  151. watchdog_init();
  152. try_unlock_memory();
  153. /* Errata workarounds */
  154. omap3_setup_aux_cr();
  155. #ifndef CONFIG_SYS_L2CACHE_OFF
  156. /* Invalidate L2-cache from secure mode */
  157. omap3_invalidate_l2_cache_secure();
  158. #endif
  159. set_muxconf_regs();
  160. delay(100);
  161. prcm_init();
  162. per_clocks_enable();
  163. if (!in_sdram)
  164. mem_init();
  165. }
  166. /******************************************************************************
  167. * Routine: wait_for_command_complete
  168. * Description: Wait for posting to finish on watchdog
  169. *****************************************************************************/
  170. void wait_for_command_complete(struct watchdog *wd_base)
  171. {
  172. int pending = 1;
  173. do {
  174. pending = readl(&wd_base->wwps);
  175. } while (pending);
  176. }
  177. /******************************************************************************
  178. * Routine: watchdog_init
  179. * Description: Shut down watch dogs
  180. *****************************************************************************/
  181. void watchdog_init(void)
  182. {
  183. struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
  184. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  185. /*
  186. * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
  187. * either taken care of by ROM (HS/EMU) or not accessible (GP).
  188. * We need to take care of WD2-MPU or take a PRCM reset. WD3
  189. * should not be running and does not generate a PRCM reset.
  190. */
  191. sr32(&prcm_base->fclken_wkup, 5, 1, 1);
  192. sr32(&prcm_base->iclken_wkup, 5, 1, 1);
  193. wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
  194. writel(WD_UNLOCK1, &wd2_base->wspr);
  195. wait_for_command_complete(wd2_base);
  196. writel(WD_UNLOCK2, &wd2_base->wspr);
  197. }
  198. /******************************************************************************
  199. * Dummy function to handle errors for EABI incompatibility
  200. *****************************************************************************/
  201. void abort(void)
  202. {
  203. }
  204. #ifdef CONFIG_NAND_OMAP_GPMC
  205. /******************************************************************************
  206. * OMAP3 specific command to switch between NAND HW and SW ecc
  207. *****************************************************************************/
  208. static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  209. {
  210. if (argc != 2)
  211. goto usage;
  212. if (strncmp(argv[1], "hw", 2) == 0)
  213. omap_nand_switch_ecc(1);
  214. else if (strncmp(argv[1], "sw", 2) == 0)
  215. omap_nand_switch_ecc(0);
  216. else
  217. goto usage;
  218. return 0;
  219. usage:
  220. printf ("Usage: nandecc %s\n", cmdtp->usage);
  221. return 1;
  222. }
  223. U_BOOT_CMD(
  224. nandecc, 2, 1, do_switch_ecc,
  225. "switch OMAP3 NAND ECC calculation algorithm",
  226. "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
  227. );
  228. #endif /* CONFIG_NAND_OMAP_GPMC */
  229. #ifdef CONFIG_DISPLAY_BOARDINFO
  230. /**
  231. * Print board information
  232. */
  233. int checkboard (void)
  234. {
  235. char *mem_s ;
  236. if (is_mem_sdr())
  237. mem_s = "mSDR";
  238. else
  239. mem_s = "LPDDR";
  240. printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
  241. sysinfo.nand_string);
  242. return 0;
  243. }
  244. #endif /* CONFIG_DISPLAY_BOARDINFO */
  245. static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
  246. {
  247. u32 i, num_params = *parameters;
  248. u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
  249. /*
  250. * copy the parameters to an un-cached area to avoid coherency
  251. * issues
  252. */
  253. for (i = 0; i < num_params; i++) {
  254. __raw_writel(*parameters, sram_scratch_space);
  255. parameters++;
  256. sram_scratch_space++;
  257. }
  258. /* Now make the PPA call */
  259. do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
  260. }
  261. static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
  262. {
  263. u32 acr;
  264. /* Read ACR */
  265. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  266. acr &= ~clear_bits;
  267. acr |= set_bits;
  268. if (get_device_type() == GP_DEVICE) {
  269. omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
  270. acr);
  271. } else {
  272. struct emu_hal_params emu_romcode_params;
  273. emu_romcode_params.num_params = 1;
  274. emu_romcode_params.param1 = acr;
  275. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
  276. (u32 *)&emu_romcode_params);
  277. }
  278. }
  279. static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
  280. {
  281. u32 acr;
  282. /* Read ACR */
  283. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  284. acr &= ~clear_bits;
  285. acr |= set_bits;
  286. /* Write ACR - affects non-secure banked bits */
  287. asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
  288. }
  289. static void omap3_setup_aux_cr(void)
  290. {
  291. /* Workaround for Cortex-A8 errata: #454179 #430973
  292. * Set "IBE" bit
  293. * Set "Disable Brach Size Mispredicts" bit
  294. * Workaround for erratum #621766
  295. * Enable L1NEON bit
  296. * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
  297. */
  298. omap3_update_aux_cr_secure(0xE0, 0);
  299. }
  300. #ifndef CONFIG_SYS_L2CACHE_OFF
  301. /* Invalidate the entire L2 cache from secure mode */
  302. static void omap3_invalidate_l2_cache_secure(void)
  303. {
  304. if (get_device_type() == GP_DEVICE) {
  305. omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
  306. 0);
  307. } else {
  308. struct emu_hal_params emu_romcode_params;
  309. emu_romcode_params.num_params = 1;
  310. emu_romcode_params.param1 = 0;
  311. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
  312. (u32 *)&emu_romcode_params);
  313. }
  314. }
  315. void v7_outer_cache_enable(void)
  316. {
  317. /* Set L2EN */
  318. omap3_update_aux_cr_secure(0x2, 0);
  319. /*
  320. * On some revisions L2EN bit is banked on some revisions it's not
  321. * No harm in setting both banked bits(in fact this is required
  322. * by an erratum)
  323. */
  324. omap3_update_aux_cr(0x2, 0);
  325. }
  326. void v7_outer_cache_disable(void)
  327. {
  328. /* Clear L2EN */
  329. omap3_update_aux_cr_secure(0, 0x2);
  330. /*
  331. * On some revisions L2EN bit is banked on some revisions it's not
  332. * No harm in clearing both banked bits(in fact this is required
  333. * by an erratum)
  334. */
  335. omap3_update_aux_cr(0, 0x2);
  336. }
  337. #endif