1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
4 //=============================================================================
6 // hal_platform_setup.h
8 // Platform specific support for HAL (assembly code)
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //===========================================================================
45 #include <pkgconf/system.h> // System-wide configuration info
46 #include CYGBLD_HAL_VARIANT_H // Variant specific configuration
47 #include CYGBLD_HAL_PLATFORM_H // Platform specific configuration
48 #include <cyg/hal/hal_soc.h> // Variant specific hardware definitions
49 #include <cyg/hal/hal_mmu.h> // MMU definitions
50 #include <cyg/hal/fsl_board.h> // Platform specific hardware definitions
52 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
53 #define PLATFORM_SETUP1 _platform_setup1
54 #define CYGHWR_HAL_ARM_HAS_MMU
56 #ifdef CYG_HAL_STARTUP_ROMRAM
57 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
60 //#define NFC_2K_BI_SWAP
61 #define SDRAM_FULL_PAGE_BIT 0x100
62 #define SDRAM_FULL_PAGE_MODE 0x37
63 #define SDRAM_BURST_MODE 0x33
65 #define CYGHWR_HAL_ROM_VADDR 0x0
68 #define UNALIGNED_ACCESS_ENABLE
69 #define SET_T_BIT_DISABLE
70 #define BRANCH_PREDICTION_ENABLE
73 #define DCDGEN(i,type, addr, data) \
79 #define PLATFORM_PREAMBLE flash_header
80 //flash header & DCD @ 0x400
84 app_code_jump_v: .long reset_vector
85 app_code_barker: .long 0xB1
87 dcd_ptr_ptr: .long dcd_ptr
88 super_root_key: .long 0
89 dcd_ptr: .long dcd_data
90 app_dest_ptr: .long 0xAFF00000
92 dcd_data: .long 0xB17219E9 // Fixed. can't change.
93 dcd_len: .long (56*12)
96 //DDR2 IOMUX configuration
97 DCDGEN(1, 4, IOMUXC_BASE_ADDR + 0x8a0, 0x200)
98 DCDGEN(2, 4, IOMUXC_BASE_ADDR + 0x50c, 0x20c5)
99 DCDGEN(3, 4, IOMUXC_BASE_ADDR + 0x510, 0x20c5)
100 DCDGEN(4, 4, IOMUXC_BASE_ADDR + 0x83c, 0x2)
101 DCDGEN(5, 4, IOMUXC_BASE_ADDR + 0x848, 0x2)
102 DCDGEN(6, 4, IOMUXC_BASE_ADDR + 0x4b8, 0xe7)
103 DCDGEN(7, 4, IOMUXC_BASE_ADDR + 0x4bc, 0x45)
104 DCDGEN(8, 4, IOMUXC_BASE_ADDR + 0x4c0, 0x45)
105 DCDGEN(9, 4, IOMUXC_BASE_ADDR + 0x4c4, 0x45)
106 DCDGEN(10, 4, IOMUXC_BASE_ADDR + 0x4c8, 0x45)
107 DCDGEN(11, 4, IOMUXC_BASE_ADDR + 0x820, 0x0)
108 DCDGEN(12, 4, IOMUXC_BASE_ADDR + 0x4a4, 0x3)
109 DCDGEN(13, 4, IOMUXC_BASE_ADDR + 0x4a8, 0x3)
110 DCDGEN(14, 4, IOMUXC_BASE_ADDR + 0x4ac, 0xe3)
111 DCDGEN(15, 4, IOMUXC_BASE_ADDR + 0x4b0, 0xe3)
112 DCDGEN(16, 4, IOMUXC_BASE_ADDR + 0x4b4, 0xe3)
113 DCDGEN(17, 4, IOMUXC_BASE_ADDR + 0x4cc, 0xe3)
114 DCDGEN(18, 4, IOMUXC_BASE_ADDR + 0x4d0, 0xe2)
115 //Set drive strength to HIGH
116 DCDGEN(19, 4, IOMUXC_BASE_ADDR + 0x82c, 0x4)
117 DCDGEN(20, 4, IOMUXC_BASE_ADDR + 0x8a4, 0x4)
118 DCDGEN(21, 4, IOMUXC_BASE_ADDR + 0x8ac, 0x4)
119 DCDGEN(22, 4, IOMUXC_BASE_ADDR + 0x8b8, 0x4)
120 //13 ROW, 10 COL, 32Bit, SREF=4 Micron Model
122 DCDGEN(23, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0x82a20000)
123 DCDGEN(24, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL1, 0x82a20000)
124 DCDGEN(25, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDMISC, 0x000ad0d0)
125 DCDGEN(26, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCFG0, 0x3F3584AB)
126 DCDGEN(27, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCFG1, 0x3F3584AB)
128 DCDGEN(28, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x04008008)
129 DCDGEN(29, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801a)
130 DCDGEN(30, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801b)
131 DCDGEN(31, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00448019)
132 DCDGEN(32, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x07328018)
133 DCDGEN(33, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x04008008)
134 DCDGEN(34, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
135 DCDGEN(35, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
136 DCDGEN(36, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x06328018)
137 DCDGEN(37, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x03808019)
138 DCDGEN(38, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00408019)
139 DCDGEN(39, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008000)
142 DCDGEN(40, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0400800c)
143 DCDGEN(41, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801e)
144 DCDGEN(42, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801f)
145 DCDGEN(43, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801d)
146 DCDGEN(44, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0732801c)
147 DCDGEN(45, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0400800c)
148 DCDGEN(46, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008014)
149 DCDGEN(47, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008014)
150 DCDGEN(48, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0632801c)
151 DCDGEN(49, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0380801d)
152 DCDGEN(50, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0040801d)
153 DCDGEN(51, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008004)
155 DCDGEN(52, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0xb2a20000)
156 DCDGEN(53, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL1, 0xb2a20000)
157 DCDGEN(54, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDMISC, 0x000ad6d0)
158 DCDGEN(55, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCDLYGD, 0x90000000)
159 DCDGEN(56, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00000000)
161 image_len: .long 256*1024
165 //#define ENABLE_IMPRECISE_ABORT
167 // This macro represents the initial startup code for the platform
168 .macro _platform_setup1
169 FSL_BOARD_SETUP_START:
170 // mrc p15, 0, r0, c1, c1, 0 // Read Secure Configuration Register data. Why doesn't work???
171 // mcr p15, 0, <Rd>, c1, c1, 0 ; Write Secure Configuration Register data
173 ldr r0, GPIO1_BASE_ADDR_W
175 orr r1, r1, #(1 << 23)
178 orr r1, r1, #(1 << 23)
181 #ifdef ENABLE_IMPRECISE_ABORT
182 mrs r1, spsr // save old spsr
183 mrs r0, cpsr // read out the cpsr
184 bic r0, r0, #0x100 // clear the A bit
185 msr spsr, r0 // update spsr
186 add lr, pc, #0x8 // update lr
187 movs pc, lr // update cpsr
192 msr spsr, r1 // restore old spsr
194 // explicitly disable L2 cache
195 mrc 15, 0, r0, c1, c0, 1
197 mcr 15, 0, r0, c1, c0, 1
199 // reconfigure L2 cache aux control reg
200 mov r0, #0xC0 // tag RAM
201 add r0, r0, #0x4 // data RAM
202 orr r0, r0, #(1 << 24) // disable write allocate delay
203 orr r0, r0, #(1 << 23) // disable write allocate combine
204 orr r0, r0, #(1 << 22) // disable write allocate
206 ldr r1, =ROM_BASE_ADDRESS
207 ldr r3, [r1, #ROM_SI_REV_OFFSET]
209 orrls r0, r0, #(1 << 25) // disable write combine for TO 2 and lower revs
211 mcr 15, 1, r0, c9, c0, 2
217 #ifdef CYG_HAL_STARTUP_ROMRAM /* enable running from RAM */
218 /* Check if need to copy image to Redboot ROM space */
221 ldr r1, MXC_REDBOOT_ROM_START
223 beq HWInitialise_skip_SDRAM_copy
225 add r2, r0, #REDBOOT_IMAGE_SIZE
227 1: ldmia r0!, {r3-r10}
233 and r0, pc, r1 /* offset of pc */
234 ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
240 #endif /* CYG_HAL_STARTUP_ROMRAM */
242 HWInitialise_skip_SDRAM_copy:
243 /* Skip clock setup if already booted up */
244 ldr r0, =IRAM_BASE_ADDR
246 ldr r1, =FROM_SPI_NOR_FLASH
248 beq Normal_Boot_Continue
249 ldr r1, =FROM_MMC_FLASH
251 beq Normal_Boot_Continue
256 Normal_Boot_Continue:
260 * IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
263 // Set up a stack [for calling C code]
264 ldr r1, =__startup_stack
265 ldr r2, =RAM_BANK0_BASE
271 /* Workaround for arm errata #709718 */
272 //Setup PRRR so device is always mapped to non-shared
273 mrc MMU_CP, 0, r1, c10, c2, 0 // Read Primary Region Remap Register
275 mcr MMU_CP, 0, r1, c10, c2, 0 // Write Primary Region Remap Register
279 mrc MMU_CP, 0, r1, MMU_Control, c0
280 orr r1, r1, #7 // enable MMU bit
281 orr r1, r1, #0x800 // enable z bit
282 orr r1, r1, #(1 << 28) // Enable TEX remap
283 mcr MMU_CP, 0, r1, MMU_Control, c0
285 /* Workaround for arm errata #621766 */
286 mrc MMU_CP, 0, r1, MMU_Control, c0, 1
287 orr r1, r1, #(1 << 5) // enable L1NEON bit
288 mcr MMU_CP, 0, r1, MMU_Control, c0, 1
290 mov pc,r2 /* Change address spaces */
296 // Save shadow copy of BCR, also hardware configuration
300 str r9, [r1] // Saved far above...
302 .endm // _platform_setup1
304 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
305 #define PLATFORM_SETUP1
308 /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
311 * Set all MPROTx to be non-bufferable, trusted for R/W,
312 * not forced to user-mode.
314 ldr r0, AIPS1_CTRL_BASE_ADDR_W
315 ldr r1, AIPS1_PARAM_W
318 ldr r0, AIPS2_CTRL_BASE_ADDR_W
322 .endm /* init_aips */
325 ldr r0, CCM_BASE_ADDR_W
327 /* Gate of clocks to the peripherals first */
329 str r1, [r0, #CLKCTL_CCGR0]
331 str r1, [r0, #CLKCTL_CCGR1]
332 str r1, [r0, #CLKCTL_CCGR2]
333 str r1, [r0, #CLKCTL_CCGR3]
336 str r1, [r0, #CLKCTL_CCGR4]
338 str r1, [r0, #CLKCTL_CCGR5]
340 str r1, [r0, #CLKCTL_CCGR6]
342 /* Disable IPU and HSC dividers */
344 str r1, [r0, #CLKCTL_CCDR]
346 /* Make sure to switch the DDR away from PLL 1 */
347 ldr r1, CCM_VAL_0x19239145
348 str r1, [r0, #CLKCTL_CBCDR]
349 /* make sure divider effective */
350 1: ldr r1, [r0, #CLKCTL_CDHIPR]
354 /* Switch ARM to step clock */
356 str r1, [r0, #CLKCTL_CCSR]
360 /* Switch peripheral to PLL 3 */
361 ldr r0, CCM_BASE_ADDR_W
362 ldr r1, CCM_VAL_0x000010C0
363 str r1, [r0, #CLKCTL_CBCMR]
364 ldr r1, CCM_VAL_0x13239145
365 str r1, [r0, #CLKCTL_CBCDR]
367 /* Switch peripheral to PLL 2 */
368 ldr r0, CCM_BASE_ADDR_W
369 ldr r1, CCM_VAL_0x19239145
370 str r1, [r0, #CLKCTL_CBCDR]
371 ldr r1, CCM_VAL_0x000020C0
372 str r1, [r0, #CLKCTL_CBCMR]
376 /* Set the platform clock dividers */
377 ldr r0, PLATFORM_BASE_ADDR_W
378 ldr r1, PLATFORM_CLOCK_DIV_W
379 str r1, [r0, #PLATFORM_ICGC]
381 ldr r0, CCM_BASE_ADDR_W
382 /* Run TO 3.0 at Full speed, for other TO's wait till we increase VDDGP */
383 ldr r1, =ROM_BASE_ADDRESS
384 ldr r3, [r1, #ROM_SI_REV_OFFSET]
388 str r1, [r0, #CLKCTL_CACRR]
390 /* Switch ARM back to PLL 1. */
392 str r1, [r0, #CLKCTL_CCSR]
395 /* Use lp_apm (24MHz) source for perclk */
396 ldr r1, CCM_VAL_0x000020C2
397 str r1, [r0, #CLKCTL_CBCMR]
398 // ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz
399 ldr r1, CCM_VAL_0x59239100
400 str r1, [r0, #CLKCTL_CBCDR]
402 /* Restore the default values in the Gate registers */
404 str r1, [r0, #CLKCTL_CCGR0]
405 str r1, [r0, #CLKCTL_CCGR1]
406 str r1, [r0, #CLKCTL_CCGR2]
407 str r1, [r0, #CLKCTL_CCGR3]
408 str r1, [r0, #CLKCTL_CCGR4]
409 str r1, [r0, #CLKCTL_CCGR5]
410 str r1, [r0, #CLKCTL_CCGR6]
412 /* Use PLL 2 for UART's, get 66.5MHz from it */
413 ldr r1, CCM_VAL_0xA5A2A020
414 str r1, [r0, #CLKCTL_CSCMR1]
415 ldr r1, CCM_VAL_0x00C30321
416 str r1, [r0, #CLKCTL_CSCDR1]
418 /* make sure divider effective */
419 1: ldr r1, [r0, #CLKCTL_CDHIPR]
424 str r1, [r0, #CLKCTL_CCDR]
426 // for cko - for ARM div by 8
428 add r1, r1, #0x00000F0
429 str r1, [r0, #CLKCTL_CCOSR]
430 .endm /* init_clock */
432 .macro setup_pll pll_nr, mhz
433 ldr r0, BASE_ADDR_W_\pll_nr
434 ldr r1, PLL_VAL_0x1232
435 str r1, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit); BRMO=1 */
437 str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
440 str r1, [r0, #PLL_DP_OP]
441 str r1, [r0, #PLL_DP_HFS_OP]
443 ldr r1, W_DP_MFD_\mhz
444 str r1, [r0, #PLL_DP_MFD]
445 str r1, [r0, #PLL_DP_HFS_MFD]
447 ldr r1, W_DP_MFN_\mhz
448 str r1, [r0, #PLL_DP_MFN]
449 str r1, [r0, #PLL_DP_HFS_MFN]
451 /* Now restart PLL */
452 ldr r1, PLL_VAL_0x1232
453 str r1, [r0, #PLL_DP_CTL]
454 wait_pll_lock\pll_nr\mhz:
455 ldr r1, [r0, #PLL_DP_CTL]
457 beq wait_pll_lock\pll_nr\mhz
463 ldr r0, M4IF_0x00000203
464 str r0, [r1, #M4IF_FBPM0]
467 str r0, [r1, #M4IF_FBPM1]
469 ldr r0, M4IF_0x00120125
470 str r0, [r1, #M4IF_FPWC]
472 ldr r0, M4IF_0x001901A3
473 str r0, [r1, #M4IF_MIF4]
474 .endm /* init_m4if */
476 #define PLATFORM_VECTORS _platform_vectors
477 .macro _platform_vectors
478 .globl _board_BCR, _board_CFG
479 _board_BCR: .long 0 // Board Control register shadow
480 _board_CFG: .long 0 // Board Configuration (read at RESET)
483 AIPS1_CTRL_BASE_ADDR_W: .word AIPS1_CTRL_BASE_ADDR
484 AIPS2_CTRL_BASE_ADDR_W: .word AIPS2_CTRL_BASE_ADDR
485 AIPS1_PARAM_W: .word 0x77777777
486 M4IF_BASE_W: .word M4IF_BASE_ADDR
487 M4IF_0x00120125: .word 0x00120125
488 M4IF_0x001901A3: .word 0x001901A3
489 M4IF_0x00000203: .word 0x00000203
490 MXC_REDBOOT_ROM_START: .word SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
491 GPIO1_BASE_ADDR_W: .word GPIO1_BASE_ADDR
492 CCM_BASE_ADDR_W: .word CCM_BASE_ADDR
493 CCM_VAL_0x000020C2: .word 0x000020C2
494 CCM_VAL_0x59239100: .word 0x59239100
495 CCM_VAL_0x19239145: .word 0x19239145
496 CCM_VAL_0xA5A2A020: .word 0xA5A2A020
497 CCM_VAL_0x00C30321: .word 0x00C30321
498 CCM_VAL_0x000010C0: .word 0x000010C0
499 CCM_VAL_0x13239145: .word 0x13239145
500 CCM_VAL_0x000020C0: .word 0x000020C0
501 PLL_VAL_0x222: .word 0x222
502 PLL_VAL_0x232: .word 0x232
503 BASE_ADDR_W_PLL1: .word PLL1_BASE_ADDR
504 BASE_ADDR_W_PLL2: .word PLL2_BASE_ADDR
505 BASE_ADDR_W_PLL3: .word PLL3_BASE_ADDR
506 PLL_VAL_0x1232: .word 0x1232
507 W_DP_OP_800: .word DP_OP_800
508 W_DP_MFD_800: .word DP_MFD_800
509 W_DP_MFN_800: .word DP_MFN_800
510 W_DP_OP_665: .word DP_OP_665
511 W_DP_MFD_665: .word DP_MFD_665
512 W_DP_MFN_665: .word DP_MFN_665
513 W_DP_OP_216: .word DP_OP_216
514 W_DP_MFD_216: .word DP_MFD_216
515 W_DP_MFN_216: .word DP_MFN_216
516 PLATFORM_BASE_ADDR_W: .word PLATFORM_BASE_ADDR
517 PLATFORM_CLOCK_DIV_W: .word 0x00000124
519 /*---------------------------------------------------------------------------*/
520 /* end of hal_platform_setup.h */
521 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */