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>
43 extern omap3_sysinfo sysinfo
;
44 static void omap3_setup_aux_cr(void);
45 static void omap3_invalidate_l2_cache_secure(void);
47 /******************************************************************************
49 * Description: spinning delay to use before udelay works
50 *****************************************************************************/
51 static inline void delay(unsigned long loops
)
53 __asm__
volatile ("1:\n" "subs %0, %1, #1\n"
54 "bne 1b":"=r" (loops
):"0"(loops
));
57 /******************************************************************************
58 * Routine: secure_unlock
59 * Description: Setup security registers for access
61 *****************************************************************************/
62 void secure_unlock_mem(void)
64 struct pm
*pm_rt_ape_base
= (struct pm
*)PM_RT_APE_BASE_ADDR_ARM
;
65 struct pm
*pm_gpmc_base
= (struct pm
*)PM_GPMC_BASE_ADDR_ARM
;
66 struct pm
*pm_ocm_ram_base
= (struct pm
*)PM_OCM_RAM_BASE_ADDR_ARM
;
67 struct pm
*pm_iva2_base
= (struct pm
*)PM_IVA2_BASE_ADDR_ARM
;
68 struct sms
*sms_base
= (struct sms
*)OMAP34XX_SMS_BASE
;
70 /* Protection Module Register Target APE (PM_RT) */
71 writel(UNLOCK_1
, &pm_rt_ape_base
->req_info_permission_1
);
72 writel(UNLOCK_1
, &pm_rt_ape_base
->read_permission_0
);
73 writel(UNLOCK_1
, &pm_rt_ape_base
->wirte_permission_0
);
74 writel(UNLOCK_2
, &pm_rt_ape_base
->addr_match_1
);
76 writel(UNLOCK_3
, &pm_gpmc_base
->req_info_permission_0
);
77 writel(UNLOCK_3
, &pm_gpmc_base
->read_permission_0
);
78 writel(UNLOCK_3
, &pm_gpmc_base
->wirte_permission_0
);
80 writel(UNLOCK_3
, &pm_ocm_ram_base
->req_info_permission_0
);
81 writel(UNLOCK_3
, &pm_ocm_ram_base
->read_permission_0
);
82 writel(UNLOCK_3
, &pm_ocm_ram_base
->wirte_permission_0
);
83 writel(UNLOCK_2
, &pm_ocm_ram_base
->addr_match_2
);
86 writel(UNLOCK_3
, &pm_iva2_base
->req_info_permission_0
);
87 writel(UNLOCK_3
, &pm_iva2_base
->read_permission_0
);
88 writel(UNLOCK_3
, &pm_iva2_base
->wirte_permission_0
);
90 /* SDRC region 0 public */
91 writel(UNLOCK_1
, &sms_base
->rg_att0
);
94 /******************************************************************************
95 * Routine: secureworld_exit()
96 * Description: If chip is EMU and boot type is external
97 * configure secure registers and exit secure world
99 *****************************************************************************/
100 void secureworld_exit()
104 /* configrue 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
));
109 * allow allocation of locked TLBs and L2 lines in NS world
110 * allow use of PLE registers in NS world also
112 __asm__
__volatile__("orr %0, %0, #0x70000":"=r"(i
));
113 __asm__
__volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i
));
115 /* Enable ASA in ACR register */
116 __asm__
__volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i
));
117 __asm__
__volatile__("orr %0, %0, #0x10":"=r"(i
));
118 __asm__
__volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i
));
120 /* Exiting secure world */
121 __asm__
__volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i
));
122 __asm__
__volatile__("orr %0, %0, #0x31":"=r"(i
));
123 __asm__
__volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i
));
126 /******************************************************************************
127 * Routine: try_unlock_sram()
128 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
130 *****************************************************************************/
131 void try_unlock_memory()
134 int in_sdram
= is_running_in_sdram();
137 * if GP device unlock device SRAM for general use
138 * secure code breaks for Secure/Emulation device - HS/E/T
140 mode
= get_device_type();
141 if (mode
== GP_DEVICE
)
145 * If device is EMU and boot is XIP external booting
146 * Unlock firewalls and disable L2 and put chip
147 * out of secure world
149 * Assuming memories are unlocked by the demon who put us in SDRAM
151 if ((mode
<= EMU_DEVICE
) && (get_boot_type() == 0x1F)
160 /******************************************************************************
162 * Description: Does early system init of muxing and clocks.
163 * - Called path is with SRAM stack.
164 *****************************************************************************/
167 int in_sdram
= is_running_in_sdram();
173 /* Errata workarounds */
174 omap3_setup_aux_cr();
176 #ifndef CONFIG_SYS_L2CACHE_OFF
177 /* Invalidate L2-cache from secure mode */
178 omap3_invalidate_l2_cache_secure();
192 /******************************************************************************
193 * Routine: wait_for_command_complete
194 * Description: Wait for posting to finish on watchdog
195 *****************************************************************************/
196 void wait_for_command_complete(struct watchdog
*wd_base
)
200 pending
= readl(&wd_base
->wwps
);
204 /******************************************************************************
205 * Routine: watchdog_init
206 * Description: Shut down watch dogs
207 *****************************************************************************/
208 void watchdog_init(void)
210 struct watchdog
*wd2_base
= (struct watchdog
*)WD2_BASE
;
211 struct prcm
*prcm_base
= (struct prcm
*)PRCM_BASE
;
214 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
215 * either taken care of by ROM (HS/EMU) or not accessible (GP).
216 * We need to take care of WD2-MPU or take a PRCM reset. WD3
217 * should not be running and does not generate a PRCM reset.
220 sr32(&prcm_base
->fclken_wkup
, 5, 1, 1);
221 sr32(&prcm_base
->iclken_wkup
, 5, 1, 1);
222 wait_on_value(ST_WDT2
, 0x20, &prcm_base
->idlest_wkup
, 5);
224 writel(WD_UNLOCK1
, &wd2_base
->wspr
);
225 wait_for_command_complete(wd2_base
);
226 writel(WD_UNLOCK2
, &wd2_base
->wspr
);
229 /******************************************************************************
230 * Dummy function to handle errors for EABI incompatibility
231 *****************************************************************************/
236 #ifdef CONFIG_NAND_OMAP_GPMC
237 /******************************************************************************
238 * OMAP3 specific command to switch between NAND HW and SW ecc
239 *****************************************************************************/
240 static int do_switch_ecc(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
244 if (strncmp(argv
[1], "hw", 2) == 0)
245 omap_nand_switch_ecc(1);
246 else if (strncmp(argv
[1], "sw", 2) == 0)
247 omap_nand_switch_ecc(0);
254 printf ("Usage: nandecc %s\n", cmdtp
->usage
);
259 nandecc
, 2, 1, do_switch_ecc
,
260 "switch OMAP3 NAND ECC calculation algorithm",
261 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
264 #endif /* CONFIG_NAND_OMAP_GPMC */
266 #ifdef CONFIG_DISPLAY_BOARDINFO
268 * Print board information
270 int checkboard (void)
279 printf("%s + %s/%s\n", sysinfo
.board_string
, mem_s
,
280 sysinfo
.nand_string
);
284 #endif /* CONFIG_DISPLAY_BOARDINFO */
286 static void omap3_emu_romcode_call(u32 service_id
, u32
*parameters
)
288 u32 i
, num_params
= *parameters
;
289 u32
*sram_scratch_space
= (u32
*)OMAP3_PUBLIC_SRAM_SCRATCH_AREA
;
292 * copy the parameters to an un-cached area to avoid coherency
295 for (i
= 0; i
< num_params
; i
++) {
296 __raw_writel(*parameters
, sram_scratch_space
);
298 sram_scratch_space
++;
301 /* Now make the PPA call */
302 do_omap3_emu_romcode_call(service_id
, OMAP3_PUBLIC_SRAM_SCRATCH_AREA
);
305 static void omap3_update_aux_cr_secure(u32 set_bits
, u32 clear_bits
)
310 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr
));
314 if (get_device_type() == GP_DEVICE
) {
315 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR
,
318 struct emu_hal_params emu_romcode_params
;
319 emu_romcode_params
.num_params
= 1;
320 emu_romcode_params
.param1
= acr
;
321 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR
,
322 (u32
*)&emu_romcode_params
);
326 static void omap3_update_aux_cr(u32 set_bits
, u32 clear_bits
)
331 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr
));
335 /* Write ACR - affects non-secure banked bits */
336 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr
));
339 static void omap3_setup_aux_cr(void)
341 /* Workaround for Cortex-A8 errata: #454179 #430973
343 * Set "Disable Brach Size Mispredicts" bit
344 * Workaround for erratum #621766
346 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
348 omap3_update_aux_cr_secure(0xE0, 0);
351 #ifndef CONFIG_SYS_L2CACHE_OFF
352 /* Invalidate the entire L2 cache from secure mode */
353 static void omap3_invalidate_l2_cache_secure(void)
355 if (get_device_type() == GP_DEVICE
) {
356 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL
,
359 struct emu_hal_params emu_romcode_params
;
360 emu_romcode_params
.num_params
= 1;
361 emu_romcode_params
.param1
= 0;
362 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL
,
363 (u32
*)&emu_romcode_params
);
367 void v7_outer_cache_enable(void)
370 omap3_update_aux_cr_secure(0x2, 0);
373 * On some revisions L2EN bit is banked on some revisions it's not
374 * No harm in setting both banked bits(in fact this is required
377 omap3_update_aux_cr(0x2, 0);
380 void v7_outer_cache_disable(void)
383 omap3_update_aux_cr_secure(0, 0x2);
386 * On some revisions L2EN bit is banked on some revisions it's not
387 * No harm in clearing both banked bits(in fact this is required
390 omap3_update_aux_cr(0, 0x2);