blob: 0448bc93ffc442fd4983f5a4f1714e44c20f9545 [file] [log] [blame]
Dirk Behme91eee542008-12-14 09:47:15 +01001/*
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 * See file CREDITS for list of people who contributed to this
18 * project.
19 *
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.
24 *
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.
29 *
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,
33 * MA 02111-1307 USA
34 */
35#include <common.h>
36#include <asm/io.h>
37#include <asm/arch/sys_proto.h>
38#include <asm/arch/mem.h>
Kim, Heung Jun06e758e2009-06-20 11:02:17 +020039#include <asm/cache.h>
Aneesh V45bf0582011-06-16 23:30:53 +000040#include <asm/armv7.h>
Aneesh V080a46e2011-07-31 20:30:53 +000041#include <asm/arch/gpio.h>
Dirk Behme91eee542008-12-14 09:47:15 +010042
Aneesh V45bf0582011-06-16 23:30:53 +000043/* Declarations */
Dirk Behme91eee542008-12-14 09:47:15 +010044extern omap3_sysinfo sysinfo;
Aneesh V45bf0582011-06-16 23:30:53 +000045static void omap3_setup_aux_cr(void);
46static void omap3_invalidate_l2_cache_secure(void);
Dirk Behme91eee542008-12-14 09:47:15 +010047
Aneesh V25223a62011-07-21 09:29:29 -040048static 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 },
55};
56
57const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
58
Dirk Behme91eee542008-12-14 09:47:15 +010059/******************************************************************************
60 * Routine: delay
61 * Description: spinning delay to use before udelay works
62 *****************************************************************************/
63static inline void delay(unsigned long loops)
64{
65 __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
66 "bne 1b":"=r" (loops):"0"(loops));
67}
68
69/******************************************************************************
70 * Routine: secure_unlock
71 * Description: Setup security registers for access
72 * (GP Device only)
73 *****************************************************************************/
74void secure_unlock_mem(void)
75{
Dirk Behme97a099e2009-08-08 09:30:21 +020076 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;
Dirk Behme91eee542008-12-14 09:47:15 +010081
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);
87
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);
91
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);
96
97 /* IVA Changes */
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);
101
102 /* SDRC region 0 public */
103 writel(UNLOCK_1, &sms_base->rg_att0);
104}
105
106/******************************************************************************
107 * Routine: secureworld_exit()
108 * Description: If chip is EMU and boot type is external
109 * configure secure registers and exit secure world
110 * general use.
111 *****************************************************************************/
112void secureworld_exit()
113{
114 unsigned long i;
115
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));
120 /*
121 * allow allocation of locked TLBs and L2 lines in NS world
122 * allow use of PLE registers in NS world also
123 */
124 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
125 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
126
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));
131
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));
136}
137
138/******************************************************************************
Dirk Behme91eee542008-12-14 09:47:15 +0100139 * Routine: try_unlock_sram()
140 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
141 * general use.
142 *****************************************************************************/
143void try_unlock_memory()
144{
145 int mode;
146 int in_sdram = is_running_in_sdram();
147
148 /*
149 * if GP device unlock device SRAM for general use
150 * secure code breaks for Secure/Emulation device - HS/E/T
151 */
152 mode = get_device_type();
153 if (mode == GP_DEVICE)
154 secure_unlock_mem();
155
156 /*
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
160 *
161 * Assuming memories are unlocked by the demon who put us in SDRAM
162 */
163 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
164 && (!in_sdram)) {
165 secure_unlock_mem();
166 secureworld_exit();
167 }
168
169 return;
170}
171
172/******************************************************************************
173 * Routine: s_init
174 * Description: Does early system init of muxing and clocks.
175 * - Called path is with SRAM stack.
176 *****************************************************************************/
177void s_init(void)
178{
179 int in_sdram = is_running_in_sdram();
180
181 watchdog_init();
182
183 try_unlock_memory();
184
Aneesh V45bf0582011-06-16 23:30:53 +0000185 /* Errata workarounds */
186 omap3_setup_aux_cr();
Dirk Behme91eee542008-12-14 09:47:15 +0100187
Aneesh V45bf0582011-06-16 23:30:53 +0000188#ifndef CONFIG_SYS_L2CACHE_OFF
189 /* Invalidate L2-cache from secure mode */
190 omap3_invalidate_l2_cache_secure();
Dirk Behme91eee542008-12-14 09:47:15 +0100191#endif
Dirk Behme91eee542008-12-14 09:47:15 +0100192
193 set_muxconf_regs();
194 delay(100);
195
196 prcm_init();
197
198 per_clocks_enable();
199
200 if (!in_sdram)
Vaibhav Hiremathcae377b2010-06-07 15:20:34 -0400201 mem_init();
Dirk Behme91eee542008-12-14 09:47:15 +0100202}
203
204/******************************************************************************
205 * Routine: wait_for_command_complete
206 * Description: Wait for posting to finish on watchdog
207 *****************************************************************************/
Dirk Behme97a099e2009-08-08 09:30:21 +0200208void wait_for_command_complete(struct watchdog *wd_base)
Dirk Behme91eee542008-12-14 09:47:15 +0100209{
210 int pending = 1;
211 do {
212 pending = readl(&wd_base->wwps);
213 } while (pending);
214}
215
216/******************************************************************************
217 * Routine: watchdog_init
218 * Description: Shut down watch dogs
219 *****************************************************************************/
220void watchdog_init(void)
221{
Dirk Behme97a099e2009-08-08 09:30:21 +0200222 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
223 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
Dirk Behme91eee542008-12-14 09:47:15 +0100224
225 /*
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.
230 */
231
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);
235
236 writel(WD_UNLOCK1, &wd2_base->wspr);
237 wait_for_command_complete(wd2_base);
238 writel(WD_UNLOCK2, &wd2_base->wspr);
239}
240
241/******************************************************************************
Dirk Behme91eee542008-12-14 09:47:15 +0100242 * Dummy function to handle errors for EABI incompatibility
243 *****************************************************************************/
Dirk Behme91eee542008-12-14 09:47:15 +0100244void abort(void)
245{
246}
247
248#ifdef CONFIG_NAND_OMAP_GPMC
249/******************************************************************************
250 * OMAP3 specific command to switch between NAND HW and SW ecc
251 *****************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200252static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Dirk Behme91eee542008-12-14 09:47:15 +0100253{
254 if (argc != 2)
255 goto usage;
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);
260 else
261 goto usage;
262
263 return 0;
264
265usage:
Sanjeev Premi36003262009-04-03 14:00:07 +0530266 printf ("Usage: nandecc %s\n", cmdtp->usage);
Dirk Behme91eee542008-12-14 09:47:15 +0100267 return 1;
268}
269
270U_BOOT_CMD(
271 nandecc, 2, 1, do_switch_ecc,
Robert P. J. Daya93c92c2009-11-17 07:30:23 -0500272 "switch OMAP3 NAND ECC calculation algorithm",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200273 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
274);
Dirk Behme91eee542008-12-14 09:47:15 +0100275
276#endif /* CONFIG_NAND_OMAP_GPMC */
Sanjeev Premi6a6b62e2009-04-27 21:27:27 +0530277
278#ifdef CONFIG_DISPLAY_BOARDINFO
279/**
280 * Print board information
281 */
282int checkboard (void)
283{
284 char *mem_s ;
285
286 if (is_mem_sdr())
287 mem_s = "mSDR";
288 else
289 mem_s = "LPDDR";
290
291 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
292 sysinfo.nand_string);
293
294 return 0;
295}
296#endif /* CONFIG_DISPLAY_BOARDINFO */
Aneesh V45bf0582011-06-16 23:30:53 +0000297
298static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
299{
300 u32 i, num_params = *parameters;
301 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
302
303 /*
304 * copy the parameters to an un-cached area to avoid coherency
305 * issues
306 */
307 for (i = 0; i < num_params; i++) {
308 __raw_writel(*parameters, sram_scratch_space);
309 parameters++;
310 sram_scratch_space++;
311 }
312
313 /* Now make the PPA call */
314 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
315}
316
317static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
318{
319 u32 acr;
320
321 /* Read ACR */
322 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
323 acr &= ~clear_bits;
324 acr |= set_bits;
325
326 if (get_device_type() == GP_DEVICE) {
327 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
328 acr);
329 } else {
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);
335 }
336}
337
338static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
339{
340 u32 acr;
341
342 /* Read ACR */
343 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
344 acr &= ~clear_bits;
345 acr |= set_bits;
346
347 /* Write ACR - affects non-secure banked bits */
348 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
349}
350
351static void omap3_setup_aux_cr(void)
352{
353 /* Workaround for Cortex-A8 errata: #454179 #430973
354 * Set "IBE" bit
355 * Set "Disable Brach Size Mispredicts" bit
356 * Workaround for erratum #621766
357 * Enable L1NEON bit
358 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
359 */
360 omap3_update_aux_cr_secure(0xE0, 0);
361}
362
363#ifndef CONFIG_SYS_L2CACHE_OFF
364/* Invalidate the entire L2 cache from secure mode */
365static void omap3_invalidate_l2_cache_secure(void)
366{
367 if (get_device_type() == GP_DEVICE) {
368 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
369 0);
370 } else {
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);
376 }
377}
378
379void v7_outer_cache_enable(void)
380{
381 /* Set L2EN */
382 omap3_update_aux_cr_secure(0x2, 0);
383
384 /*
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
387 * by an erratum)
388 */
389 omap3_update_aux_cr(0x2, 0);
390}
391
392void v7_outer_cache_disable(void)
393{
394 /* Clear L2EN */
395 omap3_update_aux_cr_secure(0, 0x2);
396
397 /*
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
400 * by an erratum)
401 */
402 omap3_update_aux_cr(0, 0x2);
403}
404#endif
Aneesh V13d4f9b2011-08-11 04:35:43 +0000405
406#ifndef CONFIG_SYS_DCACHE_OFF
407void enable_caches(void)
408{
409 /* Enable D-cache. I-cache is already enabled in start.S */
410 dcache_enable();
411}
412#endif