1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <common.h>
20#include <spl.h>
21#include <asm/io.h>
22#include <asm/arch/sys_proto.h>
23#include <asm/arch/mem.h>
24#include <asm/cache.h>
25#include <asm/armv7.h>
26#include <asm/arch/gpio.h>
27#include <asm/omap_common.h>
28#include <asm/arch/mmc_host_def.h>
29#include <i2c.h>
30#include <linux/compiler.h>
31
32DECLARE_GLOBAL_DATA_PTR;
33
34
35extern omap3_sysinfo sysinfo;
36static void omap3_setup_aux_cr(void);
37#ifndef CONFIG_SYS_L2CACHE_OFF
38static void omap3_invalidate_l2_cache_secure(void);
39#endif
40
41static const struct gpio_bank gpio_bank_34xx[6] = {
42 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
43 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
44 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
45 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
46 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
47 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
48};
49
50const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
51
52#ifdef CONFIG_SPL_BUILD
53
54
55
56
57
58
59u32 omap3_boot_device = BOOT_DEVICE_NAND;
60
61
62u32 spl_boot_mode(void)
63{
64 switch (spl_boot_device()) {
65 case BOOT_DEVICE_MMC2:
66 return MMCSD_MODE_RAW;
67 case BOOT_DEVICE_MMC1:
68 return MMCSD_MODE_FAT;
69 break;
70 default:
71 puts("spl: ERROR: unknown device - can't select boot mode\n");
72 hang();
73 }
74}
75
76u32 spl_boot_device(void)
77{
78 return omap3_boot_device;
79}
80
81int board_mmc_init(bd_t *bis)
82{
83 switch (spl_boot_device()) {
84 case BOOT_DEVICE_MMC1:
85 omap_mmc_init(0, 0, 0, -1, -1);
86 break;
87 case BOOT_DEVICE_MMC2:
88 case BOOT_DEVICE_MMC2_2:
89 omap_mmc_init(1, 0, 0, -1, -1);
90 break;
91 }
92 return 0;
93}
94
95void spl_board_init(void)
96{
97#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
98 gpmc_init();
99#endif
100#ifdef CONFIG_SPL_I2C_SUPPORT
101 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
102#endif
103}
104#endif
105
106
107
108
109
110
111
112void secure_unlock_mem(void)
113{
114 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
115 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
116 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
117 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
118 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
119
120
121 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
122 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
123 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
124 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
125
126 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
127 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
128 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
129
130 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
131 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
132 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
133 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
134
135
136 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
137 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
138 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
139
140
141 writel(UNLOCK_1, &sms_base->rg_att0);
142}
143
144
145
146
147
148
149
150void secureworld_exit()
151{
152 unsigned long i;
153
154
155 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
156
157 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
158
159
160
161
162 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
163 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
164
165
166 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
167 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
168 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
169
170
171 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
172 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
173 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
174}
175
176
177
178
179
180
181void try_unlock_memory()
182{
183 int mode;
184 int in_sdram = is_running_in_sdram();
185
186
187
188
189
190 mode = get_device_type();
191 if (mode == GP_DEVICE)
192 secure_unlock_mem();
193
194
195
196
197
198
199
200
201 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
202 && (!in_sdram)) {
203 secure_unlock_mem();
204 secureworld_exit();
205 }
206
207 return;
208}
209
210
211
212
213
214
215void s_init(void)
216{
217 int in_sdram = is_running_in_sdram();
218
219 watchdog_init();
220
221 try_unlock_memory();
222
223
224 omap3_setup_aux_cr();
225
226#ifndef CONFIG_SYS_L2CACHE_OFF
227
228 omap3_invalidate_l2_cache_secure();
229#endif
230
231 set_muxconf_regs();
232 sdelay(100);
233
234 prcm_init();
235
236 per_clocks_enable();
237
238#ifdef CONFIG_USB_EHCI_OMAP
239 ehci_clocks_enable();
240#endif
241
242#ifdef CONFIG_SPL_BUILD
243 gd = &gdata;
244
245 preloader_console_init();
246
247 timer_init();
248#endif
249
250 if (!in_sdram)
251 mem_init();
252}
253
254
255
256
257
258int __weak misc_init_r(void)
259{
260 dieid_num_r();
261
262 return 0;
263}
264
265
266
267
268
269void wait_for_command_complete(struct watchdog *wd_base)
270{
271 int pending = 1;
272 do {
273 pending = readl(&wd_base->wwps);
274 } while (pending);
275}
276
277
278
279
280
281void watchdog_init(void)
282{
283 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
284 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
285
286
287
288
289
290
291
292
293 sr32(&prcm_base->fclken_wkup, 5, 1, 1);
294 sr32(&prcm_base->iclken_wkup, 5, 1, 1);
295 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
296
297 writel(WD_UNLOCK1, &wd2_base->wspr);
298 wait_for_command_complete(wd2_base);
299 writel(WD_UNLOCK2, &wd2_base->wspr);
300}
301
302
303
304
305void abort(void)
306{
307}
308
309#if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
310
311
312
313static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
314{
315 if (argc < 2 || argc > 3)
316 goto usage;
317
318 if (strncmp(argv[1], "hw", 2) == 0) {
319 if (argc == 2) {
320 omap_nand_switch_ecc(1, 1);
321 } else {
322 if (strncmp(argv[2], "hamming", 7) == 0)
323 omap_nand_switch_ecc(1, 1);
324 else if (strncmp(argv[2], "bch8", 4) == 0)
325 omap_nand_switch_ecc(1, 8);
326 else
327 goto usage;
328 }
329 } else if (strncmp(argv[1], "sw", 2) == 0) {
330 omap_nand_switch_ecc(0, 0);
331 } else {
332 goto usage;
333 }
334
335 return 0;
336
337usage:
338 printf ("Usage: nandecc %s\n", cmdtp->usage);
339 return 1;
340}
341
342U_BOOT_CMD(
343 nandecc, 3, 1, do_switch_ecc,
344 "switch OMAP3 NAND ECC calculation algorithm",
345 "hw [hamming|bch8] - Switch between NAND hardware 1-bit hamming and"
346 " 8-bit BCH\n"
347 " ecc calculation (second parameter may"
348 " be omitted).\n"
349 "nandecc sw - Switch to NAND software ecc algorithm."
350);
351
352#endif
353
354#ifdef CONFIG_DISPLAY_BOARDINFO
355
356
357
358int checkboard (void)
359{
360 char *mem_s ;
361
362 if (is_mem_sdr())
363 mem_s = "mSDR";
364 else
365 mem_s = "LPDDR";
366
367 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
368 sysinfo.nand_string);
369
370 return 0;
371}
372#endif
373
374static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
375{
376 u32 i, num_params = *parameters;
377 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
378
379
380
381
382
383 for (i = 0; i < num_params; i++) {
384 __raw_writel(*parameters, sram_scratch_space);
385 parameters++;
386 sram_scratch_space++;
387 }
388
389
390 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
391}
392
393static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
394{
395 u32 acr;
396
397
398 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
399 acr &= ~clear_bits;
400 acr |= set_bits;
401
402 if (get_device_type() == GP_DEVICE) {
403 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
404 acr);
405 } else {
406 struct emu_hal_params emu_romcode_params;
407 emu_romcode_params.num_params = 1;
408 emu_romcode_params.param1 = acr;
409 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
410 (u32 *)&emu_romcode_params);
411 }
412}
413
414static void omap3_setup_aux_cr(void)
415{
416
417
418
419
420
421
422
423 omap3_update_aux_cr_secure(0xE0, 0);
424}
425
426#ifndef CONFIG_SYS_L2CACHE_OFF
427static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
428{
429 u32 acr;
430
431
432 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
433 acr &= ~clear_bits;
434 acr |= set_bits;
435
436
437 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
438}
439
440
441static void omap3_invalidate_l2_cache_secure(void)
442{
443 if (get_device_type() == GP_DEVICE) {
444 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
445 0);
446 } else {
447 struct emu_hal_params emu_romcode_params;
448 emu_romcode_params.num_params = 1;
449 emu_romcode_params.param1 = 0;
450 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
451 (u32 *)&emu_romcode_params);
452 }
453}
454
455void v7_outer_cache_enable(void)
456{
457
458 omap3_update_aux_cr_secure(0x2, 0);
459
460
461
462
463
464
465 omap3_update_aux_cr(0x2, 0);
466}
467
468void omap3_outer_cache_disable(void)
469{
470
471 omap3_update_aux_cr_secure(0, 0x2);
472
473
474
475
476
477
478 omap3_update_aux_cr(0, 0x2);
479}
480#endif
481
482#ifndef CONFIG_SYS_DCACHE_OFF
483void enable_caches(void)
484{
485
486 dcache_enable();
487}
488#endif
489