blob: 45976f90e9c98d9d070e1c8b5894043a4bb71215 [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>
Tom Rini29d69dc2012-08-14 08:50:58 -070042#include <asm/spl.h>
Simon Schwarz992dcf72011-09-14 15:29:26 -040043#include <asm/omap_common.h>
Tom Riniead66c12011-11-23 05:13:06 +000044#include <i2c.h>
Tom Rini05df8912012-04-13 12:20:03 +000045#include <linux/compiler.h>
Dirk Behmee0e49fe2008-12-14 09:47:15 +010046
Aneesh Vd16dd012011-06-16 23:30:53 +000047/* Declarations */
Dirk Behmee0e49fe2008-12-14 09:47:15 +010048extern omap3_sysinfo sysinfo;
Aneesh Vd16dd012011-06-16 23:30:53 +000049static void omap3_setup_aux_cr(void);
50static void omap3_invalidate_l2_cache_secure(void);
Dirk Behmee0e49fe2008-12-14 09:47:15 +010051
Aneesh V9a390882011-07-21 09:29:29 -040052static const struct gpio_bank gpio_bank_34xx[6] = {
53 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
54 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
55 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
56 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
57 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
58 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
59};
60
61const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
62
Simon Schwarz992dcf72011-09-14 15:29:26 -040063#ifdef CONFIG_SPL_BUILD
64/*
65* We use static variables because global data is not ready yet.
66* Initialized data is available in SPL right from the beginning.
67* We would not typically need to save these parameters in regular
68* U-Boot. This is needed only in SPL at the moment.
69*/
70u32 omap3_boot_device = BOOT_DEVICE_NAND;
71
72/* auto boot mode detection is not possible for OMAP3 - hard code */
Tom Rinia76ff952012-08-14 09:19:44 -070073u32 spl_boot_mode(void)
Simon Schwarz992dcf72011-09-14 15:29:26 -040074{
Tom Rini0be93ff2012-08-13 12:53:23 -070075 switch (spl_boot_device()) {
Simon Schwarz992dcf72011-09-14 15:29:26 -040076 case BOOT_DEVICE_MMC2:
77 return MMCSD_MODE_RAW;
78 case BOOT_DEVICE_MMC1:
79 return MMCSD_MODE_FAT;
80 break;
Simon Schwarz992dcf72011-09-14 15:29:26 -040081 default:
82 puts("spl: ERROR: unknown device - can't select boot mode\n");
83 hang();
84 }
85}
86
Tom Rini0be93ff2012-08-13 12:53:23 -070087u32 spl_boot_device(void)
Simon Schwarz992dcf72011-09-14 15:29:26 -040088{
89 return omap3_boot_device;
90}
91
Tom Riniead66c12011-11-23 05:13:06 +000092void spl_board_init(void)
93{
Stefano Babic44fa1882012-03-15 04:01:42 +000094#ifdef CONFIG_SPL_I2C_SUPPORT
Tom Riniead66c12011-11-23 05:13:06 +000095 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Stefano Babic44fa1882012-03-15 04:01:42 +000096#endif
Tom Riniead66c12011-11-23 05:13:06 +000097}
Simon Schwarz992dcf72011-09-14 15:29:26 -040098#endif /* CONFIG_SPL_BUILD */
99
100
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100101/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100102 * Routine: secure_unlock
103 * Description: Setup security registers for access
104 * (GP Device only)
105 *****************************************************************************/
106void secure_unlock_mem(void)
107{
Dirk Behmedc7af202009-08-08 09:30:21 +0200108 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
109 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
110 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
111 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
112 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100113
114 /* Protection Module Register Target APE (PM_RT) */
115 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
116 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
117 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
118 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
119
120 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
121 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
122 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
123
124 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
125 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
126 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
127 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
128
129 /* IVA Changes */
130 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
131 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
132 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
133
134 /* SDRC region 0 public */
135 writel(UNLOCK_1, &sms_base->rg_att0);
136}
137
138/******************************************************************************
139 * Routine: secureworld_exit()
140 * Description: If chip is EMU and boot type is external
141 * configure secure registers and exit secure world
142 * general use.
143 *****************************************************************************/
144void secureworld_exit()
145{
146 unsigned long i;
147
Peter Meerwald7ea4b7c2012-02-02 12:51:02 +0000148 /* configure non-secure access control register */
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100149 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
150 /* enabling co-processor CP10 and CP11 accesses in NS world */
151 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
152 /*
153 * allow allocation of locked TLBs and L2 lines in NS world
154 * allow use of PLE registers in NS world also
155 */
156 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
157 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
158
159 /* Enable ASA in ACR register */
160 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
161 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
162 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
163
164 /* Exiting secure world */
165 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
166 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
167 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
168}
169
170/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100171 * Routine: try_unlock_sram()
172 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
173 * general use.
174 *****************************************************************************/
175void try_unlock_memory()
176{
177 int mode;
178 int in_sdram = is_running_in_sdram();
179
180 /*
181 * if GP device unlock device SRAM for general use
182 * secure code breaks for Secure/Emulation device - HS/E/T
183 */
184 mode = get_device_type();
185 if (mode == GP_DEVICE)
186 secure_unlock_mem();
187
188 /*
189 * If device is EMU and boot is XIP external booting
190 * Unlock firewalls and disable L2 and put chip
191 * out of secure world
192 *
193 * Assuming memories are unlocked by the demon who put us in SDRAM
194 */
195 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
196 && (!in_sdram)) {
197 secure_unlock_mem();
198 secureworld_exit();
199 }
200
201 return;
202}
203
204/******************************************************************************
205 * Routine: s_init
206 * Description: Does early system init of muxing and clocks.
207 * - Called path is with SRAM stack.
208 *****************************************************************************/
209void s_init(void)
210{
211 int in_sdram = is_running_in_sdram();
212
213 watchdog_init();
214
215 try_unlock_memory();
216
Aneesh Vd16dd012011-06-16 23:30:53 +0000217 /* Errata workarounds */
218 omap3_setup_aux_cr();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100219
Aneesh Vd16dd012011-06-16 23:30:53 +0000220#ifndef CONFIG_SYS_L2CACHE_OFF
221 /* Invalidate L2-cache from secure mode */
222 omap3_invalidate_l2_cache_secure();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100223#endif
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100224
225 set_muxconf_regs();
Alexander Holler4e333f62010-12-18 13:24:20 +0100226 sdelay(100);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100227
228 prcm_init();
229
230 per_clocks_enable();
231
Govindraj.R3968a6a2012-02-06 03:55:35 +0000232#ifdef CONFIG_USB_EHCI_OMAP
233 ehci_clocks_enable();
234#endif
235
Simon Schwarz992dcf72011-09-14 15:29:26 -0400236#ifdef CONFIG_SPL_BUILD
237 preloader_console_init();
Andreas Müllerde3ffeb2012-01-04 15:26:23 +0000238
239 timer_init();
Simon Schwarz992dcf72011-09-14 15:29:26 -0400240#endif
241
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100242 if (!in_sdram)
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400243 mem_init();
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100244}
245
Tom Rini05df8912012-04-13 12:20:03 +0000246/*
247 * Routine: misc_init_r
248 * Description: A basic misc_init_r that just displays the die ID
249 */
250int __weak misc_init_r(void)
251{
252 dieid_num_r();
253
254 return 0;
255}
256
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100257/******************************************************************************
258 * Routine: wait_for_command_complete
259 * Description: Wait for posting to finish on watchdog
260 *****************************************************************************/
Dirk Behmedc7af202009-08-08 09:30:21 +0200261void wait_for_command_complete(struct watchdog *wd_base)
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100262{
263 int pending = 1;
264 do {
265 pending = readl(&wd_base->wwps);
266 } while (pending);
267}
268
269/******************************************************************************
270 * Routine: watchdog_init
271 * Description: Shut down watch dogs
272 *****************************************************************************/
273void watchdog_init(void)
274{
Dirk Behmedc7af202009-08-08 09:30:21 +0200275 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
276 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100277
278 /*
279 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
280 * either taken care of by ROM (HS/EMU) or not accessible (GP).
281 * We need to take care of WD2-MPU or take a PRCM reset. WD3
282 * should not be running and does not generate a PRCM reset.
283 */
284
285 sr32(&prcm_base->fclken_wkup, 5, 1, 1);
286 sr32(&prcm_base->iclken_wkup, 5, 1, 1);
287 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
288
289 writel(WD_UNLOCK1, &wd2_base->wspr);
290 wait_for_command_complete(wd2_base);
291 writel(WD_UNLOCK2, &wd2_base->wspr);
292}
293
294/******************************************************************************
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100295 * Dummy function to handle errors for EABI incompatibility
296 *****************************************************************************/
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100297void abort(void)
298{
299}
300
Simon Schwarz992dcf72011-09-14 15:29:26 -0400301#if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100302/******************************************************************************
303 * OMAP3 specific command to switch between NAND HW and SW ecc
304 *****************************************************************************/
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200305static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100306{
307 if (argc != 2)
308 goto usage;
309 if (strncmp(argv[1], "hw", 2) == 0)
310 omap_nand_switch_ecc(1);
311 else if (strncmp(argv[1], "sw", 2) == 0)
312 omap_nand_switch_ecc(0);
313 else
314 goto usage;
315
316 return 0;
317
318usage:
Sanjeev Premi15af9982009-04-03 14:00:07 +0530319 printf ("Usage: nandecc %s\n", cmdtp->usage);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100320 return 1;
321}
322
323U_BOOT_CMD(
324 nandecc, 2, 1, do_switch_ecc,
Robert P. J. Day3ea16c32009-11-17 07:30:23 -0500325 "switch OMAP3 NAND ECC calculation algorithm",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200326 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
327);
Dirk Behmee0e49fe2008-12-14 09:47:15 +0100328
Simon Schwarz992dcf72011-09-14 15:29:26 -0400329#endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
Sanjeev Premie32ef2e2009-04-27 21:27:27 +0530330
331#ifdef CONFIG_DISPLAY_BOARDINFO
332/**
333 * Print board information
334 */
335int checkboard (void)
336{
337 char *mem_s ;
338
339 if (is_mem_sdr())
340 mem_s = "mSDR";
341 else
342 mem_s = "LPDDR";
343
344 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
345 sysinfo.nand_string);
346
347 return 0;
348}
349#endif /* CONFIG_DISPLAY_BOARDINFO */
Aneesh Vd16dd012011-06-16 23:30:53 +0000350
351static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
352{
353 u32 i, num_params = *parameters;
354 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
355
356 /*
357 * copy the parameters to an un-cached area to avoid coherency
358 * issues
359 */
360 for (i = 0; i < num_params; i++) {
361 __raw_writel(*parameters, sram_scratch_space);
362 parameters++;
363 sram_scratch_space++;
364 }
365
366 /* Now make the PPA call */
367 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
368}
369
370static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
371{
372 u32 acr;
373
374 /* Read ACR */
375 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
376 acr &= ~clear_bits;
377 acr |= set_bits;
378
379 if (get_device_type() == GP_DEVICE) {
380 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
381 acr);
382 } else {
383 struct emu_hal_params emu_romcode_params;
384 emu_romcode_params.num_params = 1;
385 emu_romcode_params.param1 = acr;
386 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
387 (u32 *)&emu_romcode_params);
388 }
389}
390
391static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
392{
393 u32 acr;
394
395 /* Read ACR */
396 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
397 acr &= ~clear_bits;
398 acr |= set_bits;
399
400 /* Write ACR - affects non-secure banked bits */
401 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
402}
403
404static void omap3_setup_aux_cr(void)
405{
406 /* Workaround for Cortex-A8 errata: #454179 #430973
407 * Set "IBE" bit
Peter Meerwald7ea4b7c2012-02-02 12:51:02 +0000408 * Set "Disable Branch Size Mispredicts" bit
Aneesh Vd16dd012011-06-16 23:30:53 +0000409 * Workaround for erratum #621766
410 * Enable L1NEON bit
411 * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
412 */
413 omap3_update_aux_cr_secure(0xE0, 0);
414}
415
416#ifndef CONFIG_SYS_L2CACHE_OFF
417/* Invalidate the entire L2 cache from secure mode */
418static void omap3_invalidate_l2_cache_secure(void)
419{
420 if (get_device_type() == GP_DEVICE) {
421 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
422 0);
423 } else {
424 struct emu_hal_params emu_romcode_params;
425 emu_romcode_params.num_params = 1;
426 emu_romcode_params.param1 = 0;
427 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
428 (u32 *)&emu_romcode_params);
429 }
430}
431
432void v7_outer_cache_enable(void)
433{
434 /* Set L2EN */
435 omap3_update_aux_cr_secure(0x2, 0);
436
437 /*
438 * On some revisions L2EN bit is banked on some revisions it's not
439 * No harm in setting both banked bits(in fact this is required
440 * by an erratum)
441 */
442 omap3_update_aux_cr(0x2, 0);
443}
444
Aneesh Ve0db71d2012-02-16 03:40:15 +0000445void omap3_outer_cache_disable(void)
Aneesh Vd16dd012011-06-16 23:30:53 +0000446{
447 /* Clear L2EN */
448 omap3_update_aux_cr_secure(0, 0x2);
449
450 /*
451 * On some revisions L2EN bit is banked on some revisions it's not
452 * No harm in clearing both banked bits(in fact this is required
453 * by an erratum)
454 */
455 omap3_update_aux_cr(0, 0x2);
456}
457#endif
Aneesh V572134b2011-08-11 04:35:43 +0000458
459#ifndef CONFIG_SYS_DCACHE_OFF
460void enable_caches(void)
461{
462 /* Enable D-cache. I-cache is already enabled in start.S */
463 dcache_enable();
464}
465#endif