3 * Common board functions for OMAP3 based boards.
5 * (C) Copyright 2004-2008
6 * Texas Instruments, <www.ti.com>
9 * Sunil Kumar <sunilsaini05@gmail.com>
10 * Shashi Ranjan <shashiranjanmca05@gmail.com>
12 * Derived from Beagle Board and 3430 SDP code by
13 * Richard Woodruff <r-woodruff2@ti.com>
14 * Syed Mohammed Khasim <khasim@ti.com>
17 * SPDX-License-Identifier: GPL-2.0+
23 #include <asm/arch/sys_proto.h>
24 #include <asm/arch/mem.h>
25 #include <asm/cache.h>
26 #include <asm/armv7.h>
28 #include <asm/omap_common.h>
29 #include <asm/arch/mmc_host_def.h>
31 #include <linux/compiler.h>
33 DECLARE_GLOBAL_DATA_PTR;
36 extern omap3_sysinfo sysinfo;
37 static void omap3_setup_aux_cr(void);
38 #ifndef CONFIG_SYS_L2CACHE_OFF
39 static void omap3_invalidate_l2_cache_secure(void);
43 static const struct omap_gpio_platdata omap34xx_gpio[] = {
44 { 0, OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
45 { 1, OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
46 { 2, OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
47 { 3, OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
48 { 4, OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
49 { 5, OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
52 U_BOOT_DEVICES(am33xx_gpios) = {
53 { "gpio_omap", &omap34xx_gpio[0] },
54 { "gpio_omap", &omap34xx_gpio[1] },
55 { "gpio_omap", &omap34xx_gpio[2] },
56 { "gpio_omap", &omap34xx_gpio[3] },
57 { "gpio_omap", &omap34xx_gpio[4] },
58 { "gpio_omap", &omap34xx_gpio[5] },
63 static const struct gpio_bank gpio_bank_34xx[6] = {
64 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
65 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
66 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
67 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
68 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
69 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
72 const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
76 #ifdef CONFIG_SPL_BUILD
78 * We use static variables because global data is not ready yet.
79 * Initialized data is available in SPL right from the beginning.
80 * We would not typically need to save these parameters in regular
81 * U-Boot. This is needed only in SPL at the moment.
83 u32 omap3_boot_device = BOOT_DEVICE_NAND;
85 /* auto boot mode detection is not possible for OMAP3 - hard code */
86 u32 spl_boot_mode(void)
88 switch (spl_boot_device()) {
89 case BOOT_DEVICE_MMC2:
90 return MMCSD_MODE_RAW;
91 case BOOT_DEVICE_MMC1:
92 return MMCSD_MODE_FAT;
95 puts("spl: ERROR: unknown device - can't select boot mode\n");
100 u32 spl_boot_device(void)
102 return omap3_boot_device;
105 int board_mmc_init(bd_t *bis)
107 switch (spl_boot_device()) {
108 case BOOT_DEVICE_MMC1:
109 omap_mmc_init(0, 0, 0, -1, -1);
111 case BOOT_DEVICE_MMC2:
112 case BOOT_DEVICE_MMC2_2:
113 omap_mmc_init(1, 0, 0, -1, -1);
119 void spl_board_init(void)
121 #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
124 #ifdef CONFIG_SPL_I2C_SUPPORT
125 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
128 #endif /* CONFIG_SPL_BUILD */
131 /******************************************************************************
132 * Routine: secure_unlock
133 * Description: Setup security registers for access
135 *****************************************************************************/
136 void secure_unlock_mem(void)
138 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
139 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
140 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
141 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
142 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
144 /* Protection Module Register Target APE (PM_RT) */
145 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
146 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
147 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
148 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
150 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
151 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
152 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
154 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
155 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
156 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
157 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
160 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
161 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
162 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
164 /* SDRC region 0 public */
165 writel(UNLOCK_1, &sms_base->rg_att0);
168 /******************************************************************************
169 * Routine: secureworld_exit()
170 * Description: If chip is EMU and boot type is external
171 * configure secure registers and exit secure world
173 *****************************************************************************/
174 void secureworld_exit(void)
178 /* configure non-secure access control register */
179 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
180 /* enabling co-processor CP10 and CP11 accesses in NS world */
181 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
183 * allow allocation of locked TLBs and L2 lines in NS world
184 * allow use of PLE registers in NS world also
186 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
187 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
189 /* Enable ASA in ACR register */
190 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
191 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
192 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
194 /* Exiting secure world */
195 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
196 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
197 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
200 /******************************************************************************
201 * Routine: try_unlock_sram()
202 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
204 *****************************************************************************/
205 void try_unlock_memory(void)
208 int in_sdram = is_running_in_sdram();
211 * if GP device unlock device SRAM for general use
212 * secure code breaks for Secure/Emulation device - HS/E/T
214 mode = get_device_type();
215 if (mode == GP_DEVICE)
219 * If device is EMU and boot is XIP external booting
220 * Unlock firewalls and disable L2 and put chip
221 * out of secure world
223 * Assuming memories are unlocked by the demon who put us in SDRAM
225 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
234 /******************************************************************************
236 * Description: Does early system init of muxing and clocks.
237 * - Called path is with SRAM stack.
238 *****************************************************************************/
241 int in_sdram = is_running_in_sdram();
247 /* Errata workarounds */
248 omap3_setup_aux_cr();
250 #ifndef CONFIG_SYS_L2CACHE_OFF
251 /* Invalidate L2-cache from secure mode */
252 omap3_invalidate_l2_cache_secure();
262 #ifdef CONFIG_USB_EHCI_OMAP
263 ehci_clocks_enable();
266 #ifdef CONFIG_SPL_BUILD
269 preloader_console_init();
279 * Routine: misc_init_r
280 * Description: A basic misc_init_r that just displays the die ID
282 int __weak misc_init_r(void)
289 /******************************************************************************
290 * Routine: wait_for_command_complete
291 * Description: Wait for posting to finish on watchdog
292 *****************************************************************************/
293 void wait_for_command_complete(struct watchdog *wd_base)
297 pending = readl(&wd_base->wwps);
301 /******************************************************************************
302 * Routine: watchdog_init
303 * Description: Shut down watch dogs
304 *****************************************************************************/
305 void watchdog_init(void)
307 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
308 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
311 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
312 * either taken care of by ROM (HS/EMU) or not accessible (GP).
313 * We need to take care of WD2-MPU or take a PRCM reset. WD3
314 * should not be running and does not generate a PRCM reset.
317 setbits_le32(&prcm_base->fclken_wkup, 0x20);
318 setbits_le32(&prcm_base->iclken_wkup, 0x20);
319 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
321 writel(WD_UNLOCK1, &wd2_base->wspr);
322 wait_for_command_complete(wd2_base);
323 writel(WD_UNLOCK2, &wd2_base->wspr);
326 /******************************************************************************
327 * Dummy function to handle errors for EABI incompatibility
328 *****************************************************************************/
333 #if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
334 /******************************************************************************
335 * OMAP3 specific command to switch between NAND HW and SW ecc
336 *****************************************************************************/
337 static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
339 if (argc < 2 || argc > 3)
342 if (strncmp(argv[1], "hw", 2) == 0) {
344 omap_nand_switch_ecc(1, 1);
346 if (strncmp(argv[2], "hamming", 7) == 0)
347 omap_nand_switch_ecc(1, 1);
348 else if (strncmp(argv[2], "bch8", 4) == 0)
349 omap_nand_switch_ecc(1, 8);
353 } else if (strncmp(argv[1], "sw", 2) == 0) {
354 omap_nand_switch_ecc(0, 0);
362 printf ("Usage: nandecc %s\n", cmdtp->usage);
367 nandecc, 3, 1, do_switch_ecc,
368 "switch OMAP3 NAND ECC calculation algorithm",
369 "hw [hamming|bch8] - Switch between NAND hardware 1-bit hamming and"
371 " ecc calculation (second parameter may"
373 "nandecc sw - Switch to NAND software ecc algorithm."
376 #endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
378 #ifdef CONFIG_DISPLAY_BOARDINFO
380 * Print board information
382 int checkboard (void)
391 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
392 sysinfo.nand_string);
396 #endif /* CONFIG_DISPLAY_BOARDINFO */
398 static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
400 u32 i, num_params = *parameters;
401 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
404 * copy the parameters to an un-cached area to avoid coherency
407 for (i = 0; i < num_params; i++) {
408 __raw_writel(*parameters, sram_scratch_space);
410 sram_scratch_space++;
413 /* Now make the PPA call */
414 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
417 static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
422 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
426 if (get_device_type() == GP_DEVICE) {
427 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
430 struct emu_hal_params emu_romcode_params;
431 emu_romcode_params.num_params = 1;
432 emu_romcode_params.param1 = acr;
433 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
434 (u32 *)&emu_romcode_params);
438 static void omap3_setup_aux_cr(void)
440 /* Workaround for Cortex-A8 errata: #454179 #430973
442 * Set "Disable Branch Size Mispredicts" bit
443 * Workaround for erratum #621766
445 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
447 omap3_update_aux_cr_secure(0xE0, 0);
450 #ifndef CONFIG_SYS_L2CACHE_OFF
451 static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
456 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
460 /* Write ACR - affects non-secure banked bits */
461 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
464 /* Invalidate the entire L2 cache from secure mode */
465 static void omap3_invalidate_l2_cache_secure(void)
467 if (get_device_type() == GP_DEVICE) {
468 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
471 struct emu_hal_params emu_romcode_params;
472 emu_romcode_params.num_params = 1;
473 emu_romcode_params.param1 = 0;
474 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
475 (u32 *)&emu_romcode_params);
479 void v7_outer_cache_enable(void)
482 omap3_update_aux_cr_secure(0x2, 0);
485 * On some revisions L2EN bit is banked on some revisions it's not
486 * No harm in setting both banked bits(in fact this is required
489 omap3_update_aux_cr(0x2, 0);
492 void omap3_outer_cache_disable(void)
495 omap3_update_aux_cr_secure(0, 0x2);
498 * On some revisions L2EN bit is banked on some revisions it's not
499 * No harm in clearing both banked bits(in fact this is required
502 omap3_update_aux_cr(0, 0x2);
504 #endif /* !CONFIG_SYS_L2CACHE_OFF */