board.c 11 KB

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