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