board.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. extern omap3_sysinfo sysinfo;
  41. /******************************************************************************
  42. * Routine: delay
  43. * Description: spinning delay to use before udelay works
  44. *****************************************************************************/
  45. static inline void delay(unsigned long loops)
  46. {
  47. __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
  48. "bne 1b":"=r" (loops):"0"(loops));
  49. }
  50. /******************************************************************************
  51. * Routine: secure_unlock
  52. * Description: Setup security registers for access
  53. * (GP Device only)
  54. *****************************************************************************/
  55. void secure_unlock_mem(void)
  56. {
  57. struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
  58. struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
  59. struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
  60. struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
  61. struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
  62. /* Protection Module Register Target APE (PM_RT) */
  63. writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
  64. writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
  65. writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
  66. writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
  67. writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
  68. writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
  69. writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
  70. writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
  71. writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
  72. writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
  73. writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
  74. /* IVA Changes */
  75. writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
  76. writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
  77. writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
  78. /* SDRC region 0 public */
  79. writel(UNLOCK_1, &sms_base->rg_att0);
  80. }
  81. /******************************************************************************
  82. * Routine: secureworld_exit()
  83. * Description: If chip is EMU and boot type is external
  84. * configure secure registers and exit secure world
  85. * general use.
  86. *****************************************************************************/
  87. void secureworld_exit()
  88. {
  89. unsigned long i;
  90. /* configrue non-secure access control register */
  91. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
  92. /* enabling co-processor CP10 and CP11 accesses in NS world */
  93. __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
  94. /*
  95. * allow allocation of locked TLBs and L2 lines in NS world
  96. * allow use of PLE registers in NS world also
  97. */
  98. __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
  99. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
  100. /* Enable ASA in ACR register */
  101. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  102. __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
  103. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  104. /* Exiting secure world */
  105. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
  106. __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
  107. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
  108. }
  109. /******************************************************************************
  110. * Routine: try_unlock_sram()
  111. * Description: If chip is GP/EMU(special) type, unlock the SRAM for
  112. * general use.
  113. *****************************************************************************/
  114. void try_unlock_memory()
  115. {
  116. int mode;
  117. int in_sdram = is_running_in_sdram();
  118. /*
  119. * if GP device unlock device SRAM for general use
  120. * secure code breaks for Secure/Emulation device - HS/E/T
  121. */
  122. mode = get_device_type();
  123. if (mode == GP_DEVICE)
  124. secure_unlock_mem();
  125. /*
  126. * If device is EMU and boot is XIP external booting
  127. * Unlock firewalls and disable L2 and put chip
  128. * out of secure world
  129. *
  130. * Assuming memories are unlocked by the demon who put us in SDRAM
  131. */
  132. if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
  133. && (!in_sdram)) {
  134. secure_unlock_mem();
  135. secureworld_exit();
  136. }
  137. return;
  138. }
  139. /******************************************************************************
  140. * Routine: s_init
  141. * Description: Does early system init of muxing and clocks.
  142. * - Called path is with SRAM stack.
  143. *****************************************************************************/
  144. void s_init(void)
  145. {
  146. int in_sdram = is_running_in_sdram();
  147. watchdog_init();
  148. try_unlock_memory();
  149. /*
  150. * Right now flushing at low MPU speed.
  151. * Need to move after clock init
  152. */
  153. invalidate_dcache(get_device_type());
  154. #ifndef CONFIG_ICACHE_OFF
  155. icache_enable();
  156. #endif
  157. #ifdef CONFIG_L2_OFF
  158. l2_cache_disable();
  159. #else
  160. l2_cache_enable();
  161. #endif
  162. /*
  163. * Writing to AuxCR in U-boot using SMI for GP DEV
  164. * Currently SMI in Kernel on ES2 devices seems to have an issue
  165. * Once that is resolved, we can postpone this config to kernel
  166. */
  167. if (get_device_type() == GP_DEVICE)
  168. setup_auxcr();
  169. set_muxconf_regs();
  170. delay(100);
  171. prcm_init();
  172. per_clocks_enable();
  173. if (!in_sdram)
  174. mem_init();
  175. }
  176. /******************************************************************************
  177. * Routine: wait_for_command_complete
  178. * Description: Wait for posting to finish on watchdog
  179. *****************************************************************************/
  180. void wait_for_command_complete(struct watchdog *wd_base)
  181. {
  182. int pending = 1;
  183. do {
  184. pending = readl(&wd_base->wwps);
  185. } while (pending);
  186. }
  187. /******************************************************************************
  188. * Routine: watchdog_init
  189. * Description: Shut down watch dogs
  190. *****************************************************************************/
  191. void watchdog_init(void)
  192. {
  193. struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
  194. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  195. /*
  196. * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
  197. * either taken care of by ROM (HS/EMU) or not accessible (GP).
  198. * We need to take care of WD2-MPU or take a PRCM reset. WD3
  199. * should not be running and does not generate a PRCM reset.
  200. */
  201. sr32(&prcm_base->fclken_wkup, 5, 1, 1);
  202. sr32(&prcm_base->iclken_wkup, 5, 1, 1);
  203. wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
  204. writel(WD_UNLOCK1, &wd2_base->wspr);
  205. wait_for_command_complete(wd2_base);
  206. writel(WD_UNLOCK2, &wd2_base->wspr);
  207. }
  208. /******************************************************************************
  209. * Dummy function to handle errors for EABI incompatibility
  210. *****************************************************************************/
  211. void abort(void)
  212. {
  213. }
  214. #ifdef CONFIG_NAND_OMAP_GPMC
  215. /******************************************************************************
  216. * OMAP3 specific command to switch between NAND HW and SW ecc
  217. *****************************************************************************/
  218. static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  219. {
  220. if (argc != 2)
  221. goto usage;
  222. if (strncmp(argv[1], "hw", 2) == 0)
  223. omap_nand_switch_ecc(1);
  224. else if (strncmp(argv[1], "sw", 2) == 0)
  225. omap_nand_switch_ecc(0);
  226. else
  227. goto usage;
  228. return 0;
  229. usage:
  230. printf ("Usage: nandecc %s\n", cmdtp->usage);
  231. return 1;
  232. }
  233. U_BOOT_CMD(
  234. nandecc, 2, 1, do_switch_ecc,
  235. "switch OMAP3 NAND ECC calculation algorithm",
  236. "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
  237. );
  238. #endif /* CONFIG_NAND_OMAP_GPMC */
  239. #ifdef CONFIG_DISPLAY_BOARDINFO
  240. /**
  241. * Print board information
  242. */
  243. int checkboard (void)
  244. {
  245. char *mem_s ;
  246. if (is_mem_sdr())
  247. mem_s = "mSDR";
  248. else
  249. mem_s = "LPDDR";
  250. printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
  251. sysinfo.nand_string);
  252. return 0;
  253. }
  254. #endif /* CONFIG_DISPLAY_BOARDINFO */