blob: 1fee57436493e89a3bfc3ec8f980b64a0eb0c5cf [file] [log] [blame]
Dirk Behmee0e49fe2008-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 Jun3b5ac952009-06-20 11:02:17 +020039#include <asm/cache.h>
Aneesh Vd16dd012011-06-16 23:30:53 +000040#include <asm/armv7.h>
Aneesh V1843eca2011-07-31 20:30:53 +000041#include <asm/arch/gpio.h>
Simon Schwarz992dcf72011-09-14 15:29:26 -040042#include <asm/omap_common.h>
Tom Riniead66c12011-11-23 05:13:06 +000043#include <i2c.h>
Dirk Behmee0e49fe2008-12-14 09:47:15 +010044
Aneesh Vd16dd012011-06-16 23:30:53 +000045/* Declarations */
Dirk Behmee0e49fe2008-12-14 09:47:15 +010046extern omap3_sysinfo sysinfo;
Aneesh Vd16dd012011-06-16 23:30:53 +000047static void omap3_setup_aux_cr(void);
48static void omap3_invalidate_l2_cache_secure(void);
Dirk Behmee0e49fe2008-12-14 09:47:15 +010049
Aneesh V9a390882011-07-21 09:29:29 -040050static const struct gpio_bank gpio_bank_34xx[6] = {
51 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
52 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
53 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
54 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
55 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
56 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
57};
58
59const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
60
Simon Schwarz992dcf72011-09-14 15:29:26 -040061#ifdef CONFIG_SPL_BUILD
62/*
63* We use static variables because global data is not ready yet.
64* Initialized data is available in SPL right from the beginning.
65* We would not typically need to save these parameters in regular
66* U-Boot. This is needed only in SPL at the moment.
67*/
68u32 omap3_boot_device = BOOT_DEVICE_NAND;
69
70/* auto boot mode detection is not possible for OMAP3 - hard code */
71u32 omap_boot_mode(void)
72{
73 switch (omap_boot_device()) {
74 case BOOT_DEVICE_MMC2:
75 return MMCSD_MODE_RAW;
76 case BOOT_DEVICE_MMC1:
77 return MMCSD_MODE_FAT;
78 break;
79 case BOOT_DEVICE_NAND:
80 return NAND_MODE_HW_ECC;
81 break;
82 default:
83 puts("spl: ERROR: unknown device - can't select boot mode\n");
84 hang();
85 }
86}
87
88u32 omap_boot_device(void)
89{
90 return omap3_boot_device;
91}
92
Tom Riniead66c12011-11-23 05:13:06 +000093void spl_board_init(void)
94{
Stefano Babic44fa1882012-03-15 04:01:42 +000095#ifdef CONFIG_SPL_I2C_SUPPORT
Tom Riniead66c12011-11-23 05:13:06 +000096 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Stefano Babic44fa1882012-03-15 04:01:42 +000097#endif
Tom Riniead66c12011-11-23 05:13:06 +000098}
Simon Schwarz992dcf72011-09-14 15:29:26 -040099#endif /* CONFIG_SPL_BUILD */
100
101
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100102/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100103 * Routine: secure_unlock
104 * Description: Setup security registers for access
105 * (GP Device only)
106 *****************************************************************************/
107void secure_unlock_mem(void)
108{
Dirk Behmedc7af202009-08-08 09:30:21 +0200109 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
110 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
111 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
112 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
113 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100114
115 /* Protection Module Register Target APE (PM_RT) */
116 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
117 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
118 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
119 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
120
121 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
122 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
123 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
124
125 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
126 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
127 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
128 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
129
130 /* IVA Changes */
131 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
132 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
133 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
134
135 /* SDRC region 0 public */
136 writel(UNLOCK_1, &sms_base->rg_att0);
137}
138
139/******************************************************************************
140 * Routine: secureworld_exit()
141 * Description: If chip is EMU and boot type is external
142 * configure secure registers and exit secure world
143 * general use.
144 *****************************************************************************/
145void secureworld_exit()
146{
147 unsigned long i;
148
Peter Meerwald7ea4b7c2012-02-02 12:51:02 +0000149 /* configure non-secure access control register */
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100150 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
151 /* enabling co-processor CP10 and CP11 accesses in NS world */
152 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
153 /*
154 * allow allocation of locked TLBs and L2 lines in NS world
155 * allow use of PLE registers in NS world also
156 */
157 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
158 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
159
160 /* Enable ASA in ACR register */
161 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
162 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
163 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
164
165 /* Exiting secure world */
166 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
167 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
168 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
169}
170
171/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100172 * Routine: try_unlock_sram()
173 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
174 * general use.
175 *****************************************************************************/
176void try_unlock_memory()
177{
178 int mode;
179 int in_sdram = is_running_in_sdram();
180
181 /*
182 * if GP device unlock device SRAM for general use
183 * secure code breaks for Secure/Emulation device - HS/E/T
184 */
185 mode = get_device_type();
186 if (mode == GP_DEVICE)
187 secure_unlock_mem();
188
189 /*
190 * If device is EMU and boot is XIP external booting
191 * Unlock firewalls and disable L2 and put chip
192 * out of secure world
193 *
194 * Assuming memories are unlocked by the demon who put us in SDRAM
195 */
196 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
197 && (!in_sdram)) {
198 secure_unlock_mem();
199 secureworld_exit();
200 }
201
202 return;
203}
204
205/******************************************************************************
206 * Routine: s_init
207 * Description: Does early system init of muxing and clocks.
208 * - Called path is with SRAM stack.
209 *****************************************************************************/
210void s_init(void)
211{
212 int in_sdram = is_running_in_sdram();
213
214 watchdog_init();
215
216 try_unlock_memory();
217
Aneesh Vd16dd012011-06-16 23:30:53 +0000218 /* Errata workarounds */
219 omap3_setup_aux_cr();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100220
Aneesh Vd16dd012011-06-16 23:30:53 +0000221#ifndef CONFIG_SYS_L2CACHE_OFF
222 /* Invalidate L2-cache from secure mode */
223 omap3_invalidate_l2_cache_secure();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100224#endif
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100225
226 set_muxconf_regs();
Alexander Holler4e333f62010-12-18 13:24:20 +0100227 sdelay(100);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100228
229 prcm_init();
230
231 per_clocks_enable();
232
Govindraj.R3968a6a2012-02-06 03:55:35 +0000233#ifdef CONFIG_USB_EHCI_OMAP
234 ehci_clocks_enable();
235#endif
236
Simon Schwarz992dcf72011-09-14 15:29:26 -0400237#ifdef CONFIG_SPL_BUILD
238 preloader_console_init();
Andreas Müllerde3ffeb2012-01-04 15:26:23 +0000239
240 timer_init();
Simon Schwarz992dcf72011-09-14 15:29:26 -0400241#endif
242
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100243 if (!in_sdram)
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400244 mem_init();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100245}
246
247/******************************************************************************
248 * Routine: wait_for_command_complete
249 * Description: Wait for posting to finish on watchdog
250 *****************************************************************************/
Dirk Behmedc7af202009-08-08 09:30:21 +0200251void wait_for_command_complete(struct watchdog *wd_base)
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100252{
253 int pending = 1;
254 do {
255 pending = readl(&wd_base->wwps);
256 } while (pending);
257}
258
259/******************************************************************************
260 * Routine: watchdog_init
261 * Description: Shut down watch dogs
262 *****************************************************************************/
263void watchdog_init(void)
264{
Dirk Behmedc7af202009-08-08 09:30:21 +0200265 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
266 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100267
268 /*
269 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
270 * either taken care of by ROM (HS/EMU) or not accessible (GP).
271 * We need to take care of WD2-MPU or take a PRCM reset. WD3
272 * should not be running and does not generate a PRCM reset.
273 */
274
275 sr32(&prcm_base->fclken_wkup, 5, 1, 1);
276 sr32(&prcm_base->iclken_wkup, 5, 1, 1);
277 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
278
279 writel(WD_UNLOCK1, &wd2_base->wspr);
280 wait_for_command_complete(wd2_base);
281 writel(WD_UNLOCK2, &wd2_base->wspr);
282}
283
284/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100285 * Dummy function to handle errors for EABI incompatibility
286 *****************************************************************************/
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100287void abort(void)
288{
289}
290
Simon Schwarz992dcf72011-09-14 15:29:26 -0400291#if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100292/******************************************************************************
293 * OMAP3 specific command to switch between NAND HW and SW ecc
294 *****************************************************************************/
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200295static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100296{
297 if (argc != 2)
298 goto usage;
299 if (strncmp(argv[1], "hw", 2) == 0)
300 omap_nand_switch_ecc(1);
301 else if (strncmp(argv[1], "sw", 2) == 0)
302 omap_nand_switch_ecc(0);
303 else
304 goto usage;
305
306 return 0;
307
308usage:
Sanjeev Premi15af9982009-04-03 14:00:07 +0530309 printf ("Usage: nandecc %s\n", cmdtp->usage);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100310 return 1;
311}
312
313U_BOOT_CMD(
314 nandecc, 2, 1, do_switch_ecc,
Robert P. J. Day3ea16c32009-11-17 07:30:23 -0500315 "switch OMAP3 NAND ECC calculation algorithm",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200316 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
317);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100318
Simon Schwarz992dcf72011-09-14 15:29:26 -0400319#endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
Sanjeev Premie32ef2e2009-04-27 21:27:27 +0530320
321#ifdef CONFIG_DISPLAY_BOARDINFO
322/**
323 * Print board information
324 */
325int checkboard (void)
326{
327 char *mem_s ;
328
329 if (is_mem_sdr())
330 mem_s = "mSDR";
331 else
332 mem_s = "LPDDR";
333
334 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
335 sysinfo.nand_string);
336
337 return 0;
338}
339#endif /* CONFIG_DISPLAY_BOARDINFO */
Aneesh Vd16dd012011-06-16 23:30:53 +0000340
341static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
342{
343 u32 i, num_params = *parameters;
344 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
345
346 /*
347 * copy the parameters to an un-cached area to avoid coherency
348 * issues
349 */
350 for (i = 0; i < num_params; i++) {
351 __raw_writel(*parameters, sram_scratch_space);
352 parameters++;
353 sram_scratch_space++;
354 }
355
356 /* Now make the PPA call */
357 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
358}
359
360static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
361{
362 u32 acr;
363
364 /* Read ACR */
365 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
366 acr &= ~clear_bits;
367 acr |= set_bits;
368
369 if (get_device_type() == GP_DEVICE) {
370 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
371 acr);
372 } else {
373 struct emu_hal_params emu_romcode_params;
374 emu_romcode_params.num_params = 1;
375 emu_romcode_params.param1 = acr;
376 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
377 (u32 *)&emu_romcode_params);
378 }
379}
380
381static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
382{
383 u32 acr;
384
385 /* Read ACR */
386 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
387 acr &= ~clear_bits;
388 acr |= set_bits;
389
390 /* Write ACR - affects non-secure banked bits */
391 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
392}
393
394static void omap3_setup_aux_cr(void)
395{
396 /* Workaround for Cortex-A8 errata: #454179 #430973
397 * Set "IBE" bit
Peter Meerwald7ea4b7c2012-02-02 12:51:02 +0000398 * Set "Disable Branch Size Mispredicts" bit
Aneesh Vd16dd012011-06-16 23:30:53 +0000399 * Workaround for erratum #621766
400 * Enable L1NEON bit
401 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
402 */
403 omap3_update_aux_cr_secure(0xE0, 0);
404}
405
406#ifndef CONFIG_SYS_L2CACHE_OFF
407/* Invalidate the entire L2 cache from secure mode */
408static void omap3_invalidate_l2_cache_secure(void)
409{
410 if (get_device_type() == GP_DEVICE) {
411 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
412 0);
413 } else {
414 struct emu_hal_params emu_romcode_params;
415 emu_romcode_params.num_params = 1;
416 emu_romcode_params.param1 = 0;
417 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
418 (u32 *)&emu_romcode_params);
419 }
420}
421
422void v7_outer_cache_enable(void)
423{
424 /* Set L2EN */
425 omap3_update_aux_cr_secure(0x2, 0);
426
427 /*
428 * On some revisions L2EN bit is banked on some revisions it's not
429 * No harm in setting both banked bits(in fact this is required
430 * by an erratum)
431 */
432 omap3_update_aux_cr(0x2, 0);
433}
434
Aneesh Ve0db71d2012-02-16 03:40:15 +0000435void omap3_outer_cache_disable(void)
Aneesh Vd16dd012011-06-16 23:30:53 +0000436{
437 /* Clear L2EN */
438 omap3_update_aux_cr_secure(0, 0x2);
439
440 /*
441 * On some revisions L2EN bit is banked on some revisions it's not
442 * No harm in clearing both banked bits(in fact this is required
443 * by an erratum)
444 */
445 omap3_update_aux_cr(0, 0x2);
446}
447#endif
Aneesh V572134b2011-08-11 04:35:43 +0000448
449#ifndef CONFIG_SYS_DCACHE_OFF
450void enable_caches(void)
451{
452 /* Enable D-cache. I-cache is already enabled in start.S */
453 dcache_enable();
454}
455#endif