board.c 13 KB

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