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