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 * See file CREDITS for list of people who contributed to this
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.
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.
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,
37 #include <asm/arch/sys_proto.h>
38 #include <asm/arch/mem.h>
39 #include <asm/cache.h>
40 #include <asm/armv7.h>
41 #include <asm/arch/gpio.h>
44 extern omap3_sysinfo sysinfo;
45 static void omap3_setup_aux_cr(void);
46 static void omap3_invalidate_l2_cache_secure(void);
48 static const struct gpio_bank gpio_bank_34xx[6] = {
49 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
50 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
51 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
52 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
53 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
54 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
57 const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
59 /******************************************************************************
61 * Description: spinning delay to use before udelay works
62 *****************************************************************************/
63 static inline void delay(unsigned long loops)
65 __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
66 "bne 1b":"=r" (loops):"0"(loops));
69 /******************************************************************************
70 * Routine: secure_unlock
71 * Description: Setup security registers for access
73 *****************************************************************************/
74 void secure_unlock_mem(void)
76 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
77 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
78 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
79 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
80 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
82 /* Protection Module Register Target APE (PM_RT) */
83 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
84 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
85 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
86 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
88 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
89 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
90 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
92 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
93 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
94 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
95 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
98 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
99 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
100 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
102 /* SDRC region 0 public */
103 writel(UNLOCK_1, &sms_base->rg_att0);
106 /******************************************************************************
107 * Routine: secureworld_exit()
108 * Description: If chip is EMU and boot type is external
109 * configure secure registers and exit secure world
111 *****************************************************************************/
112 void secureworld_exit()
116 /* configrue non-secure access control register */
117 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
118 /* enabling co-processor CP10 and CP11 accesses in NS world */
119 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
121 * allow allocation of locked TLBs and L2 lines in NS world
122 * allow use of PLE registers in NS world also
124 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
125 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
127 /* Enable ASA in ACR register */
128 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
129 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
130 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
132 /* Exiting secure world */
133 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
134 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
135 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
138 /******************************************************************************
139 * Routine: try_unlock_sram()
140 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
142 *****************************************************************************/
143 void try_unlock_memory()
146 int in_sdram = is_running_in_sdram();
149 * if GP device unlock device SRAM for general use
150 * secure code breaks for Secure/Emulation device - HS/E/T
152 mode = get_device_type();
153 if (mode == GP_DEVICE)
157 * If device is EMU and boot is XIP external booting
158 * Unlock firewalls and disable L2 and put chip
159 * out of secure world
161 * Assuming memories are unlocked by the demon who put us in SDRAM
163 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
172 /******************************************************************************
174 * Description: Does early system init of muxing and clocks.
175 * - Called path is with SRAM stack.
176 *****************************************************************************/
179 int in_sdram = is_running_in_sdram();
185 /* Errata workarounds */
186 omap3_setup_aux_cr();
188 #ifndef CONFIG_SYS_L2CACHE_OFF
189 /* Invalidate L2-cache from secure mode */
190 omap3_invalidate_l2_cache_secure();
204 /******************************************************************************
205 * Routine: wait_for_command_complete
206 * Description: Wait for posting to finish on watchdog
207 *****************************************************************************/
208 void wait_for_command_complete(struct watchdog *wd_base)
212 pending = readl(&wd_base->wwps);
216 /******************************************************************************
217 * Routine: watchdog_init
218 * Description: Shut down watch dogs
219 *****************************************************************************/
220 void watchdog_init(void)
222 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
223 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
226 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
227 * either taken care of by ROM (HS/EMU) or not accessible (GP).
228 * We need to take care of WD2-MPU or take a PRCM reset. WD3
229 * should not be running and does not generate a PRCM reset.
232 sr32(&prcm_base->fclken_wkup, 5, 1, 1);
233 sr32(&prcm_base->iclken_wkup, 5, 1, 1);
234 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
236 writel(WD_UNLOCK1, &wd2_base->wspr);
237 wait_for_command_complete(wd2_base);
238 writel(WD_UNLOCK2, &wd2_base->wspr);
241 /******************************************************************************
242 * Dummy function to handle errors for EABI incompatibility
243 *****************************************************************************/
248 #ifdef CONFIG_NAND_OMAP_GPMC
249 /******************************************************************************
250 * OMAP3 specific command to switch between NAND HW and SW ecc
251 *****************************************************************************/
252 static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
256 if (strncmp(argv[1], "hw", 2) == 0)
257 omap_nand_switch_ecc(1);
258 else if (strncmp(argv[1], "sw", 2) == 0)
259 omap_nand_switch_ecc(0);
266 printf ("Usage: nandecc %s\n", cmdtp->usage);
271 nandecc, 2, 1, do_switch_ecc,
272 "switch OMAP3 NAND ECC calculation algorithm",
273 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
276 #endif /* CONFIG_NAND_OMAP_GPMC */
278 #ifdef CONFIG_DISPLAY_BOARDINFO
280 * Print board information
282 int checkboard (void)
291 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
292 sysinfo.nand_string);
296 #endif /* CONFIG_DISPLAY_BOARDINFO */
298 static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
300 u32 i, num_params = *parameters;
301 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
304 * copy the parameters to an un-cached area to avoid coherency
307 for (i = 0; i < num_params; i++) {
308 __raw_writel(*parameters, sram_scratch_space);
310 sram_scratch_space++;
313 /* Now make the PPA call */
314 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
317 static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
322 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
326 if (get_device_type() == GP_DEVICE) {
327 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
330 struct emu_hal_params emu_romcode_params;
331 emu_romcode_params.num_params = 1;
332 emu_romcode_params.param1 = acr;
333 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
334 (u32 *)&emu_romcode_params);
338 static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
343 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
347 /* Write ACR - affects non-secure banked bits */
348 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
351 static void omap3_setup_aux_cr(void)
353 /* Workaround for Cortex-A8 errata: #454179 #430973
355 * Set "Disable Brach Size Mispredicts" bit
356 * Workaround for erratum #621766
358 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
360 omap3_update_aux_cr_secure(0xE0, 0);
363 #ifndef CONFIG_SYS_L2CACHE_OFF
364 /* Invalidate the entire L2 cache from secure mode */
365 static void omap3_invalidate_l2_cache_secure(void)
367 if (get_device_type() == GP_DEVICE) {
368 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
371 struct emu_hal_params emu_romcode_params;
372 emu_romcode_params.num_params = 1;
373 emu_romcode_params.param1 = 0;
374 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
375 (u32 *)&emu_romcode_params);
379 void v7_outer_cache_enable(void)
382 omap3_update_aux_cr_secure(0x2, 0);
385 * On some revisions L2EN bit is banked on some revisions it's not
386 * No harm in setting both banked bits(in fact this is required
389 omap3_update_aux_cr(0x2, 0);
392 void v7_outer_cache_disable(void)
395 omap3_update_aux_cr_secure(0, 0x2);
398 * On some revisions L2EN bit is banked on some revisions it's not
399 * No harm in clearing both banked bits(in fact this is required
402 omap3_update_aux_cr(0, 0x2);
406 #ifndef CONFIG_SYS_DCACHE_OFF
407 void enable_caches(void)
409 /* Enable D-cache. I-cache is already enabled in start.S */