board.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. * SPDX-License-Identifier: GPL-2.0+
  18. */
  19. #include <common.h>
  20. #include <dm.h>
  21. #include <spl.h>
  22. #include <asm/io.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/arch/mem.h>
  25. #include <asm/cache.h>
  26. #include <asm/armv7.h>
  27. #include <asm/gpio.h>
  28. #include <asm/omap_common.h>
  29. #include <linux/compiler.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* Declarations */
  32. extern omap3_sysinfo sysinfo;
  33. #ifndef CONFIG_SYS_L2CACHE_OFF
  34. static void omap3_invalidate_l2_cache_secure(void);
  35. #endif
  36. #ifdef CONFIG_DM_GPIO
  37. static const struct omap_gpio_platdata omap34xx_gpio[] = {
  38. { 0, OMAP34XX_GPIO1_BASE },
  39. { 1, OMAP34XX_GPIO2_BASE },
  40. { 2, OMAP34XX_GPIO3_BASE },
  41. { 3, OMAP34XX_GPIO4_BASE },
  42. { 4, OMAP34XX_GPIO5_BASE },
  43. { 5, OMAP34XX_GPIO6_BASE },
  44. };
  45. U_BOOT_DEVICES(am33xx_gpios) = {
  46. { "gpio_omap", &omap34xx_gpio[0] },
  47. { "gpio_omap", &omap34xx_gpio[1] },
  48. { "gpio_omap", &omap34xx_gpio[2] },
  49. { "gpio_omap", &omap34xx_gpio[3] },
  50. { "gpio_omap", &omap34xx_gpio[4] },
  51. { "gpio_omap", &omap34xx_gpio[5] },
  52. };
  53. #else
  54. static const struct gpio_bank gpio_bank_34xx[6] = {
  55. { (void *)OMAP34XX_GPIO1_BASE },
  56. { (void *)OMAP34XX_GPIO2_BASE },
  57. { (void *)OMAP34XX_GPIO3_BASE },
  58. { (void *)OMAP34XX_GPIO4_BASE },
  59. { (void *)OMAP34XX_GPIO5_BASE },
  60. { (void *)OMAP34XX_GPIO6_BASE },
  61. };
  62. const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
  63. #endif
  64. /******************************************************************************
  65. * Routine: secure_unlock
  66. * Description: Setup security registers for access
  67. * (GP Device only)
  68. *****************************************************************************/
  69. void secure_unlock_mem(void)
  70. {
  71. struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
  72. struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
  73. struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
  74. struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
  75. struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
  76. /* Protection Module Register Target APE (PM_RT) */
  77. writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
  78. writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
  79. writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
  80. writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
  81. writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
  82. writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
  83. writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
  84. writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
  85. writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
  86. writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
  87. writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
  88. /* IVA Changes */
  89. writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
  90. writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
  91. writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
  92. /* SDRC region 0 public */
  93. writel(UNLOCK_1, &sms_base->rg_att0);
  94. }
  95. /******************************************************************************
  96. * Routine: secureworld_exit()
  97. * Description: If chip is EMU and boot type is external
  98. * configure secure registers and exit secure world
  99. * general use.
  100. *****************************************************************************/
  101. void secureworld_exit(void)
  102. {
  103. unsigned long i;
  104. /* configure non-secure access control register */
  105. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
  106. /* enabling co-processor CP10 and CP11 accesses in NS world */
  107. __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
  108. /*
  109. * allow allocation of locked TLBs and L2 lines in NS world
  110. * allow use of PLE registers in NS world also
  111. */
  112. __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
  113. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
  114. /* Enable ASA in ACR register */
  115. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  116. __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
  117. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  118. /* Exiting secure world */
  119. __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
  120. __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
  121. __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
  122. }
  123. /******************************************************************************
  124. * Routine: try_unlock_sram()
  125. * Description: If chip is GP/EMU(special) type, unlock the SRAM for
  126. * general use.
  127. *****************************************************************************/
  128. void try_unlock_memory(void)
  129. {
  130. int mode;
  131. int in_sdram = is_running_in_sdram();
  132. /*
  133. * if GP device unlock device SRAM for general use
  134. * secure code breaks for Secure/Emulation device - HS/E/T
  135. */
  136. mode = get_device_type();
  137. if (mode == GP_DEVICE)
  138. secure_unlock_mem();
  139. /*
  140. * If device is EMU and boot is XIP external booting
  141. * Unlock firewalls and disable L2 and put chip
  142. * out of secure world
  143. *
  144. * Assuming memories are unlocked by the demon who put us in SDRAM
  145. */
  146. if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
  147. && (!in_sdram)) {
  148. secure_unlock_mem();
  149. secureworld_exit();
  150. }
  151. return;
  152. }
  153. /******************************************************************************
  154. * Routine: s_init
  155. * Description: Does early system init of muxing and clocks.
  156. * - Called path is with SRAM stack.
  157. *****************************************************************************/
  158. void s_init(void)
  159. {
  160. watchdog_init();
  161. try_unlock_memory();
  162. #ifndef CONFIG_SYS_L2CACHE_OFF
  163. /* Invalidate L2-cache from secure mode */
  164. omap3_invalidate_l2_cache_secure();
  165. #endif
  166. set_muxconf_regs();
  167. sdelay(100);
  168. prcm_init();
  169. per_clocks_enable();
  170. #ifdef CONFIG_USB_EHCI_OMAP
  171. ehci_clocks_enable();
  172. #endif
  173. }
  174. #ifdef CONFIG_SPL_BUILD
  175. void board_init_f(ulong dummy)
  176. {
  177. mem_init();
  178. }
  179. #endif
  180. /*
  181. * Routine: misc_init_r
  182. * Description: A basic misc_init_r that just displays the die ID
  183. */
  184. int __weak misc_init_r(void)
  185. {
  186. omap_die_id_display();
  187. return 0;
  188. }
  189. /******************************************************************************
  190. * Routine: wait_for_command_complete
  191. * Description: Wait for posting to finish on watchdog
  192. *****************************************************************************/
  193. static void wait_for_command_complete(struct watchdog *wd_base)
  194. {
  195. int pending = 1;
  196. do {
  197. pending = readl(&wd_base->wwps);
  198. } while (pending);
  199. }
  200. /******************************************************************************
  201. * Routine: watchdog_init
  202. * Description: Shut down watch dogs
  203. *****************************************************************************/
  204. void watchdog_init(void)
  205. {
  206. struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
  207. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  208. /*
  209. * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
  210. * either taken care of by ROM (HS/EMU) or not accessible (GP).
  211. * We need to take care of WD2-MPU or take a PRCM reset. WD3
  212. * should not be running and does not generate a PRCM reset.
  213. */
  214. setbits_le32(&prcm_base->fclken_wkup, 0x20);
  215. setbits_le32(&prcm_base->iclken_wkup, 0x20);
  216. wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
  217. writel(WD_UNLOCK1, &wd2_base->wspr);
  218. wait_for_command_complete(wd2_base);
  219. writel(WD_UNLOCK2, &wd2_base->wspr);
  220. }
  221. /******************************************************************************
  222. * Dummy function to handle errors for EABI incompatibility
  223. *****************************************************************************/
  224. void abort(void)
  225. {
  226. }
  227. #if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
  228. /******************************************************************************
  229. * OMAP3 specific command to switch between NAND HW and SW ecc
  230. *****************************************************************************/
  231. static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  232. {
  233. int hw, strength = 1;
  234. if (argc < 2 || argc > 3)
  235. goto usage;
  236. if (strncmp(argv[1], "hw", 2) == 0) {
  237. hw = 1;
  238. if (argc == 3) {
  239. if (strncmp(argv[2], "bch8", 4) == 0)
  240. strength = 8;
  241. else if (strncmp(argv[2], "bch16", 5) == 0)
  242. strength = 16;
  243. else if (strncmp(argv[2], "hamming", 7) != 0)
  244. goto usage;
  245. }
  246. } else if (strncmp(argv[1], "sw", 2) == 0) {
  247. hw = 0;
  248. if (argc == 3) {
  249. if (strncmp(argv[2], "bch8", 4) == 0)
  250. strength = 8;
  251. else if (strncmp(argv[2], "hamming", 7) != 0)
  252. goto usage;
  253. }
  254. } else {
  255. goto usage;
  256. }
  257. return -omap_nand_switch_ecc(hw, strength);
  258. usage:
  259. printf ("Usage: nandecc %s\n", cmdtp->usage);
  260. return 1;
  261. }
  262. U_BOOT_CMD(
  263. nandecc, 3, 1, do_switch_ecc,
  264. "switch OMAP3 NAND ECC calculation algorithm",
  265. "hw [hamming|bch8|bch16] - Switch between NAND hardware 1-bit hamming"
  266. " and 8-bit/16-bit BCH\n"
  267. " ecc calculation (second parameter may"
  268. " be omitted).\n"
  269. "nandecc sw - Switch to NAND software ecc algorithm."
  270. );
  271. #endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
  272. #ifdef CONFIG_DISPLAY_BOARDINFO
  273. /**
  274. * Print board information
  275. */
  276. int checkboard (void)
  277. {
  278. char *mem_s ;
  279. if (is_mem_sdr())
  280. mem_s = "mSDR";
  281. else
  282. mem_s = "LPDDR";
  283. printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
  284. sysinfo.nand_string);
  285. return 0;
  286. }
  287. #endif /* CONFIG_DISPLAY_BOARDINFO */
  288. static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
  289. {
  290. u32 i, num_params = *parameters;
  291. u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
  292. /*
  293. * copy the parameters to an un-cached area to avoid coherency
  294. * issues
  295. */
  296. for (i = 0; i < num_params; i++) {
  297. __raw_writel(*parameters, sram_scratch_space);
  298. parameters++;
  299. sram_scratch_space++;
  300. }
  301. /* Now make the PPA call */
  302. do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
  303. }
  304. void __weak omap3_set_aux_cr_secure(u32 acr)
  305. {
  306. struct emu_hal_params emu_romcode_params;
  307. emu_romcode_params.num_params = 1;
  308. emu_romcode_params.param1 = acr;
  309. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
  310. (u32 *)&emu_romcode_params);
  311. }
  312. void v7_arch_cp15_set_l2aux_ctrl(u32 l2auxctrl, u32 cpu_midr,
  313. u32 cpu_rev_comb, u32 cpu_variant,
  314. u32 cpu_rev)
  315. {
  316. if (get_device_type() == GP_DEVICE)
  317. omap_smc1(OMAP3_GP_ROMCODE_API_WRITE_L2ACR, l2auxctrl);
  318. /* L2 Cache Auxiliary Control Register is not banked */
  319. }
  320. void v7_arch_cp15_set_acr(u32 acr, u32 cpu_midr, u32 cpu_rev_comb,
  321. u32 cpu_variant, u32 cpu_rev)
  322. {
  323. /* Write ACR - affects secure banked bits */
  324. if (get_device_type() == GP_DEVICE)
  325. omap_smc1(OMAP3_GP_ROMCODE_API_WRITE_ACR, acr);
  326. else
  327. omap3_set_aux_cr_secure(acr);
  328. /* Write ACR - affects non-secure banked bits - some erratas need it */
  329. asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
  330. }
  331. #ifndef CONFIG_SYS_L2CACHE_OFF
  332. static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
  333. {
  334. u32 acr;
  335. /* Read ACR */
  336. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  337. acr &= ~clear_bits;
  338. acr |= set_bits;
  339. v7_arch_cp15_set_acr(acr, 0, 0, 0, 0);
  340. }
  341. /* Invalidate the entire L2 cache from secure mode */
  342. static void omap3_invalidate_l2_cache_secure(void)
  343. {
  344. if (get_device_type() == GP_DEVICE) {
  345. omap_smc1(OMAP3_GP_ROMCODE_API_L2_INVAL, 0);
  346. } else {
  347. struct emu_hal_params emu_romcode_params;
  348. emu_romcode_params.num_params = 1;
  349. emu_romcode_params.param1 = 0;
  350. omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
  351. (u32 *)&emu_romcode_params);
  352. }
  353. }
  354. void v7_outer_cache_enable(void)
  355. {
  356. /*
  357. * Set L2EN
  358. * On some revisions L2EN bit is banked on some revisions it's not
  359. * No harm in setting both banked bits(in fact this is required
  360. * by an erratum)
  361. */
  362. omap3_update_aux_cr(0x2, 0);
  363. }
  364. void omap3_outer_cache_disable(void)
  365. {
  366. /*
  367. * Clear L2EN
  368. * On some revisions L2EN bit is banked on some revisions it's not
  369. * No harm in clearing both banked bits(in fact this is required
  370. * by an erratum)
  371. */
  372. omap3_update_aux_cr(0, 0x2);
  373. }
  374. #endif /* !CONFIG_SYS_L2CACHE_OFF */