blob: 0c44ea53e12ed34df596abb5ed0f285f273b0b2b [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020017 * SPDX-License-Identifier: GPL-2.0+
Dirk Behme91eee542008-12-14 09:47:15 +010018 */
19#include <common.h>
Simon Glassb3f4ca12014-10-22 21:37:15 -060020#include <dm.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070021#include <spl.h>
Dirk Behme91eee542008-12-14 09:47:15 +010022#include <asm/io.h>
23#include <asm/arch/sys_proto.h>
24#include <asm/arch/mem.h>
Kim, Heung Jun06e758e2009-06-20 11:02:17 +020025#include <asm/cache.h>
Aneesh V45bf0582011-06-16 23:30:53 +000026#include <asm/armv7.h>
Simon Glassb3f4ca12014-10-22 21:37:15 -060027#include <asm/gpio.h>
Simon Schwarzbb085b82011-09-14 15:29:26 -040028#include <asm/omap_common.h>
Tom Rini8a87a3d2012-04-13 12:20:03 +000029#include <linux/compiler.h>
Dirk Behme91eee542008-12-14 09:47:15 +010030
Tom Rini6507f132012-08-22 15:31:05 -070031DECLARE_GLOBAL_DATA_PTR;
32
Aneesh V45bf0582011-06-16 23:30:53 +000033/* Declarations */
Dirk Behme91eee542008-12-14 09:47:15 +010034extern omap3_sysinfo sysinfo;
Tom Rini57f588b2012-10-30 22:23:28 -070035#ifndef CONFIG_SYS_L2CACHE_OFF
Aneesh V45bf0582011-06-16 23:30:53 +000036static void omap3_invalidate_l2_cache_secure(void);
Tom Rini57f588b2012-10-30 22:23:28 -070037#endif
Dirk Behme91eee542008-12-14 09:47:15 +010038
Simon Glassb3f4ca12014-10-22 21:37:15 -060039#ifdef CONFIG_DM_GPIO
40static const struct omap_gpio_platdata omap34xx_gpio[] = {
Tom Rini0a9e3402015-07-31 19:55:09 -040041 { 0, OMAP34XX_GPIO1_BASE },
42 { 1, OMAP34XX_GPIO2_BASE },
43 { 2, OMAP34XX_GPIO3_BASE },
44 { 3, OMAP34XX_GPIO4_BASE },
45 { 4, OMAP34XX_GPIO5_BASE },
46 { 5, OMAP34XX_GPIO6_BASE },
Simon Glassb3f4ca12014-10-22 21:37:15 -060047};
48
49U_BOOT_DEVICES(am33xx_gpios) = {
50 { "gpio_omap", &omap34xx_gpio[0] },
51 { "gpio_omap", &omap34xx_gpio[1] },
52 { "gpio_omap", &omap34xx_gpio[2] },
53 { "gpio_omap", &omap34xx_gpio[3] },
54 { "gpio_omap", &omap34xx_gpio[4] },
55 { "gpio_omap", &omap34xx_gpio[5] },
56};
57
58#else
59
Aneesh V25223a62011-07-21 09:29:29 -040060static const struct gpio_bank gpio_bank_34xx[6] = {
Tom Rini0a9e3402015-07-31 19:55:09 -040061 { (void *)OMAP34XX_GPIO1_BASE },
62 { (void *)OMAP34XX_GPIO2_BASE },
63 { (void *)OMAP34XX_GPIO3_BASE },
64 { (void *)OMAP34XX_GPIO4_BASE },
65 { (void *)OMAP34XX_GPIO5_BASE },
66 { (void *)OMAP34XX_GPIO6_BASE },
Aneesh V25223a62011-07-21 09:29:29 -040067};
68
69const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
70
Simon Glassb3f4ca12014-10-22 21:37:15 -060071#endif
72
Dirk Behme91eee542008-12-14 09:47:15 +010073/******************************************************************************
Dirk Behme91eee542008-12-14 09:47:15 +010074 * Routine: secure_unlock
75 * Description: Setup security registers for access
76 * (GP Device only)
77 *****************************************************************************/
78void secure_unlock_mem(void)
79{
Dirk Behme97a099e2009-08-08 09:30:21 +020080 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
81 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
82 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
83 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
84 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
Dirk Behme91eee542008-12-14 09:47:15 +010085
86 /* Protection Module Register Target APE (PM_RT) */
87 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
88 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
89 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
90 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
91
92 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
93 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
94 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
95
96 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
97 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
98 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
99 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
100
101 /* IVA Changes */
102 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
103 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
104 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
105
106 /* SDRC region 0 public */
107 writel(UNLOCK_1, &sms_base->rg_att0);
108}
109
110/******************************************************************************
111 * Routine: secureworld_exit()
112 * Description: If chip is EMU and boot type is external
113 * configure secure registers and exit secure world
114 * general use.
115 *****************************************************************************/
Jeroen Hofsteefd3f4012014-06-16 23:22:23 +0200116void secureworld_exit(void)
Dirk Behme91eee542008-12-14 09:47:15 +0100117{
118 unsigned long i;
119
Peter Meerwalda4958312012-02-02 12:51:02 +0000120 /* configure non-secure access control register */
Dirk Behme91eee542008-12-14 09:47:15 +0100121 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
122 /* enabling co-processor CP10 and CP11 accesses in NS world */
123 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
124 /*
125 * allow allocation of locked TLBs and L2 lines in NS world
126 * allow use of PLE registers in NS world also
127 */
128 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
129 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
130
131 /* Enable ASA in ACR register */
132 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
133 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
134 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
135
136 /* Exiting secure world */
137 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
138 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
139 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
140}
141
142/******************************************************************************
Dirk Behme91eee542008-12-14 09:47:15 +0100143 * Routine: try_unlock_sram()
144 * Description: If chip is GP/EMU(special) type, unlock the SRAM for
145 * general use.
146 *****************************************************************************/
Jeroen Hofsteefd3f4012014-06-16 23:22:23 +0200147void try_unlock_memory(void)
Dirk Behme91eee542008-12-14 09:47:15 +0100148{
149 int mode;
150 int in_sdram = is_running_in_sdram();
151
152 /*
153 * if GP device unlock device SRAM for general use
154 * secure code breaks for Secure/Emulation device - HS/E/T
155 */
156 mode = get_device_type();
157 if (mode == GP_DEVICE)
158 secure_unlock_mem();
159
160 /*
161 * If device is EMU and boot is XIP external booting
162 * Unlock firewalls and disable L2 and put chip
163 * out of secure world
164 *
165 * Assuming memories are unlocked by the demon who put us in SDRAM
166 */
167 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
168 && (!in_sdram)) {
169 secure_unlock_mem();
170 secureworld_exit();
171 }
172
173 return;
174}
175
176/******************************************************************************
177 * Routine: s_init
178 * Description: Does early system init of muxing and clocks.
179 * - Called path is with SRAM stack.
180 *****************************************************************************/
181void s_init(void)
182{
Dirk Behme91eee542008-12-14 09:47:15 +0100183 watchdog_init();
184
185 try_unlock_memory();
186
Aneesh V45bf0582011-06-16 23:30:53 +0000187#ifndef CONFIG_SYS_L2CACHE_OFF
188 /* Invalidate L2-cache from secure mode */
189 omap3_invalidate_l2_cache_secure();
Dirk Behme91eee542008-12-14 09:47:15 +0100190#endif
Dirk Behme91eee542008-12-14 09:47:15 +0100191
192 set_muxconf_regs();
Alexander Holler86623ad2010-12-18 13:24:20 +0100193 sdelay(100);
Dirk Behme91eee542008-12-14 09:47:15 +0100194
195 prcm_init();
196
197 per_clocks_enable();
198
Govindraj.R95f87912012-02-06 03:55:35 +0000199#ifdef CONFIG_USB_EHCI_OMAP
200 ehci_clocks_enable();
201#endif
Dirk Behme91eee542008-12-14 09:47:15 +0100202}
203
Simon Glass7ae83502015-03-03 08:03:02 -0700204#ifdef CONFIG_SPL_BUILD
205void board_init_f(ulong dummy)
206{
207 mem_init();
208}
209#endif
210
Tom Rini8a87a3d2012-04-13 12:20:03 +0000211/*
212 * Routine: misc_init_r
213 * Description: A basic misc_init_r that just displays the die ID
214 */
215int __weak misc_init_r(void)
216{
Paul Kocialkowski679f82c2015-08-27 19:37:13 +0200217 omap_die_id_display();
Tom Rini8a87a3d2012-04-13 12:20:03 +0000218
219 return 0;
220}
221
Dirk Behme91eee542008-12-14 09:47:15 +0100222/******************************************************************************
223 * Routine: wait_for_command_complete
224 * Description: Wait for posting to finish on watchdog
225 *****************************************************************************/
Jeroen Hofstee98431d52014-10-08 22:57:41 +0200226static void wait_for_command_complete(struct watchdog *wd_base)
Dirk Behme91eee542008-12-14 09:47:15 +0100227{
228 int pending = 1;
229 do {
230 pending = readl(&wd_base->wwps);
231 } while (pending);
232}
233
234/******************************************************************************
235 * Routine: watchdog_init
236 * Description: Shut down watch dogs
237 *****************************************************************************/
238void watchdog_init(void)
239{
Dirk Behme97a099e2009-08-08 09:30:21 +0200240 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
241 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
Dirk Behme91eee542008-12-14 09:47:15 +0100242
243 /*
244 * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
245 * either taken care of by ROM (HS/EMU) or not accessible (GP).
246 * We need to take care of WD2-MPU or take a PRCM reset. WD3
247 * should not be running and does not generate a PRCM reset.
248 */
249
Wolfgang Denke7300f42014-03-25 14:49:48 +0100250 setbits_le32(&prcm_base->fclken_wkup, 0x20);
251 setbits_le32(&prcm_base->iclken_wkup, 0x20);
Dirk Behme91eee542008-12-14 09:47:15 +0100252 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
253
254 writel(WD_UNLOCK1, &wd2_base->wspr);
255 wait_for_command_complete(wd2_base);
256 writel(WD_UNLOCK2, &wd2_base->wspr);
257}
258
259/******************************************************************************
Dirk Behme91eee542008-12-14 09:47:15 +0100260 * Dummy function to handle errors for EABI incompatibility
261 *****************************************************************************/
Dirk Behme91eee542008-12-14 09:47:15 +0100262void abort(void)
263{
264}
265
Simon Schwarzbb085b82011-09-14 15:29:26 -0400266#if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
Dirk Behme91eee542008-12-14 09:47:15 +0100267/******************************************************************************
268 * OMAP3 specific command to switch between NAND HW and SW ecc
269 *****************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200270static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Dirk Behme91eee542008-12-14 09:47:15 +0100271{
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000272 if (argc < 2 || argc > 3)
Dirk Behme91eee542008-12-14 09:47:15 +0100273 goto usage;
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000274
275 if (strncmp(argv[1], "hw", 2) == 0) {
276 if (argc == 2) {
277 omap_nand_switch_ecc(1, 1);
278 } else {
279 if (strncmp(argv[2], "hamming", 7) == 0)
280 omap_nand_switch_ecc(1, 1);
281 else if (strncmp(argv[2], "bch8", 4) == 0)
282 omap_nand_switch_ecc(1, 8);
283 else
284 goto usage;
285 }
286 } else if (strncmp(argv[1], "sw", 2) == 0) {
Ash Charlesb0508982015-02-18 11:25:11 -0800287 if (argc == 2) {
288 omap_nand_switch_ecc(0, 1);
289 } else {
290 if (strncmp(argv[2], "hamming", 7) == 0)
291 omap_nand_switch_ecc(0, 1);
292 else if (strncmp(argv[2], "bch8", 4) == 0)
293 omap_nand_switch_ecc(0, 8);
294 else
295 goto usage;
296 }
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000297 } else {
Dirk Behme91eee542008-12-14 09:47:15 +0100298 goto usage;
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000299 }
Dirk Behme91eee542008-12-14 09:47:15 +0100300
301 return 0;
302
303usage:
Sanjeev Premi36003262009-04-03 14:00:07 +0530304 printf ("Usage: nandecc %s\n", cmdtp->usage);
Dirk Behme91eee542008-12-14 09:47:15 +0100305 return 1;
306}
307
308U_BOOT_CMD(
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000309 nandecc, 3, 1, do_switch_ecc,
Robert P. J. Daya93c92c2009-11-17 07:30:23 -0500310 "switch OMAP3 NAND ECC calculation algorithm",
Andreas Bießmannda634ae2013-04-04 23:52:50 +0000311 "hw [hamming|bch8] - Switch between NAND hardware 1-bit hamming and"
312 " 8-bit BCH\n"
313 " ecc calculation (second parameter may"
314 " be omitted).\n"
315 "nandecc sw - Switch to NAND software ecc algorithm."
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200316);
Dirk Behme91eee542008-12-14 09:47:15 +0100317
Simon Schwarzbb085b82011-09-14 15:29:26 -0400318#endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
Sanjeev Premi6a6b62e2009-04-27 21:27:27 +0530319
320#ifdef CONFIG_DISPLAY_BOARDINFO
321/**
322 * Print board information
323 */
324int checkboard (void)
325{
326 char *mem_s ;
327
328 if (is_mem_sdr())
329 mem_s = "mSDR";
330 else
331 mem_s = "LPDDR";
332
333 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
334 sysinfo.nand_string);
335
336 return 0;
337}
338#endif /* CONFIG_DISPLAY_BOARDINFO */
Aneesh V45bf0582011-06-16 23:30:53 +0000339
340static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
341{
342 u32 i, num_params = *parameters;
343 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
344
345 /*
346 * copy the parameters to an un-cached area to avoid coherency
347 * issues
348 */
349 for (i = 0; i < num_params; i++) {
350 __raw_writel(*parameters, sram_scratch_space);
351 parameters++;
352 sram_scratch_space++;
353 }
354
355 /* Now make the PPA call */
356 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
357}
358
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500359void __weak omap3_set_aux_cr_secure(u32 acr)
360{
361 struct emu_hal_params emu_romcode_params;
362
363 emu_romcode_params.num_params = 1;
364 emu_romcode_params.param1 = acr;
365 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
366 (u32 *)&emu_romcode_params);
367}
368
Nishanth Menonc6f90e12015-03-09 17:12:08 -0500369void v7_arch_cp15_set_acr(u32 acr, u32 cpu_midr, u32 cpu_rev_comb,
370 u32 cpu_variant, u32 cpu_rev)
Aneesh V45bf0582011-06-16 23:30:53 +0000371{
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500372 /* Write ACR - affects secure banked bits */
373 if (get_device_type() == GP_DEVICE)
Nishanth Menon49ec9492015-03-09 17:12:05 -0500374 omap_smc1(OMAP3_GP_ROMCODE_API_WRITE_ACR, acr);
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500375 else
376 omap3_set_aux_cr_secure(acr);
377
378 /* Write ACR - affects non-secure banked bits - some erratas need it */
379 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
Aneesh V45bf0582011-06-16 23:30:53 +0000380}
381
Aneesh V45bf0582011-06-16 23:30:53 +0000382
383#ifndef CONFIG_SYS_L2CACHE_OFF
Tom Rini57f588b2012-10-30 22:23:28 -0700384static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
385{
386 u32 acr;
387
388 /* Read ACR */
389 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
390 acr &= ~clear_bits;
391 acr |= set_bits;
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500392 v7_arch_cp15_set_acr(acr, 0, 0, 0, 0);
Tom Rini57f588b2012-10-30 22:23:28 -0700393
Tom Rini57f588b2012-10-30 22:23:28 -0700394}
395
Aneesh V45bf0582011-06-16 23:30:53 +0000396/* Invalidate the entire L2 cache from secure mode */
397static void omap3_invalidate_l2_cache_secure(void)
398{
399 if (get_device_type() == GP_DEVICE) {
Nishanth Menon49ec9492015-03-09 17:12:05 -0500400 omap_smc1(OMAP3_GP_ROMCODE_API_L2_INVAL, 0);
Aneesh V45bf0582011-06-16 23:30:53 +0000401 } else {
402 struct emu_hal_params emu_romcode_params;
403 emu_romcode_params.num_params = 1;
404 emu_romcode_params.param1 = 0;
405 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
406 (u32 *)&emu_romcode_params);
407 }
408}
409
410void v7_outer_cache_enable(void)
411{
Aneesh V45bf0582011-06-16 23:30:53 +0000412
413 /*
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500414 * Set L2EN
Aneesh V45bf0582011-06-16 23:30:53 +0000415 * 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
Aneesh Vf1f2c3c2012-02-16 03:40:15 +0000422void omap3_outer_cache_disable(void)
Aneesh V45bf0582011-06-16 23:30:53 +0000423{
Aneesh V45bf0582011-06-16 23:30:53 +0000424 /*
Nishanth Menoncdef0b32015-03-09 17:12:09 -0500425 * Clear L2EN
Aneesh V45bf0582011-06-16 23:30:53 +0000426 * On some revisions L2EN bit is banked on some revisions it's not
427 * No harm in clearing both banked bits(in fact this is required
428 * by an erratum)
429 */
430 omap3_update_aux_cr(0, 0x2);
431}
Robert P. J. Daye3fe6252012-11-13 07:57:54 +0000432#endif /* !CONFIG_SYS_L2CACHE_OFF */