]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx51/3stack/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx51 / 3stack / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3
4 //=============================================================================
5 //
6 //      hal_platform_setup.h
7 //
8 //      Platform specific support for HAL (assembly code)
9 //
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.
15 //
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.
19 //
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
23 // for more details.
24 //
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.
28 //
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.
35 //
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.
38 //
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 //===========================================================================
44
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
51
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
55
56 #ifdef CYG_HAL_STARTUP_ROMRAM
57 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
58 #endif
59
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
64
65 #define CYGHWR_HAL_ROM_VADDR    0x0
66
67 #if 0
68 #define UNALIGNED_ACCESS_ENABLE
69 #define SET_T_BIT_DISABLE
70 #define BRANCH_PREDICTION_ENABLE
71 #endif
72
73 #define DCDGEN(i,type, addr, data) \
74 dcd_##i:                         ;\
75     .long type                   ;\
76     .long addr                   ;\
77     .long data
78
79 #define PLATFORM_PREAMBLE flash_header
80 //flash header & DCD @ 0x400
81 .macro flash_header
82     b reset_vector
83     .org 0x400
84 app_code_jump_v:    .long reset_vector
85 app_code_barker:    .long 0xB1
86 app_code_csf:       .long 0
87 dcd_ptr_ptr:        .long dcd_ptr
88 super_root_key:     .long 0
89 dcd_ptr:            .long dcd_data
90 app_dest_ptr:       .long 0x97f00000
91
92 dcd_data:           .long 0xB17219E9   // Fixed. can't change.
93 #ifdef IMX51_TO_2
94 dcd_len:            .long (56*12)
95
96 //DCD
97 //DDR2 IOMUX configuration
98 DCDGEN(1, 4, IOMUXC_BASE_ADDR + 0x8a0, 0x200)
99 DCDGEN(2, 4, IOMUXC_BASE_ADDR + 0x50c, 0x20c5)
100 DCDGEN(3, 4, IOMUXC_BASE_ADDR + 0x510, 0x20c5)
101 DCDGEN(4, 4, IOMUXC_BASE_ADDR + 0x83c, 0x2)
102 DCDGEN(5, 4, IOMUXC_BASE_ADDR + 0x848, 0x2)
103 DCDGEN(6, 4, IOMUXC_BASE_ADDR + 0x4b8, 0xe7)
104 DCDGEN(7, 4, IOMUXC_BASE_ADDR + 0x4bc, 0x45)
105 DCDGEN(8, 4, IOMUXC_BASE_ADDR + 0x4c0, 0x45)
106 DCDGEN(9, 4, IOMUXC_BASE_ADDR + 0x4c4, 0x45)
107 DCDGEN(10, 4, IOMUXC_BASE_ADDR + 0x4c8, 0x45)
108 DCDGEN(11, 4, IOMUXC_BASE_ADDR + 0x820, 0x0)
109 DCDGEN(12, 4, IOMUXC_BASE_ADDR + 0x4a4, 0x3)
110 DCDGEN(13, 4, IOMUXC_BASE_ADDR + 0x4a8, 0x3)
111 DCDGEN(14, 4, IOMUXC_BASE_ADDR + 0x4ac, 0xe3)
112 DCDGEN(15, 4, IOMUXC_BASE_ADDR + 0x4b0, 0xe3)
113 DCDGEN(16, 4, IOMUXC_BASE_ADDR + 0x4b4, 0xe3)
114 DCDGEN(17, 4, IOMUXC_BASE_ADDR + 0x4cc, 0xe3)
115 DCDGEN(18, 4, IOMUXC_BASE_ADDR + 0x4d0, 0xe2)
116 //Set drive strength to MAX
117 DCDGEN(19, 4, IOMUXC_BASE_ADDR + 0x82c, 0x6)
118 DCDGEN(20, 4, IOMUXC_BASE_ADDR + 0x8a4, 0x6)
119 DCDGEN(21, 4, IOMUXC_BASE_ADDR + 0x8ac, 0x6)
120 DCDGEN(22, 4, IOMUXC_BASE_ADDR + 0x8b8, 0x6)
121 //13 ROW, 10 COL, 32Bit, SREF=4 Micron Model
122 //CAS=3,  BL=4
123 DCDGEN(23, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0x82a20000)
124 DCDGEN(24, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL1, 0x82a20000)
125 DCDGEN(25, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDMISC, 0x000ad0d0)
126 DCDGEN(26, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCFG0, 0x333574aa)
127 DCDGEN(27, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCFG1, 0x333574aa)
128 // Init DRAM on CS0
129 DCDGEN(28, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x04008008)
130 DCDGEN(29, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801a)
131 DCDGEN(30, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801b)
132 DCDGEN(31, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00448019)
133 DCDGEN(32, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x07328018)
134 DCDGEN(33, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x04008008)
135 DCDGEN(34, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
136 DCDGEN(35, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
137 DCDGEN(36, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x06328018)
138 DCDGEN(37, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x03808019)
139 DCDGEN(38, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00408019)
140 DCDGEN(39, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008000)
141
142 // Init DRAM on CS1
143 DCDGEN(40, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0400800c)
144 DCDGEN(41, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801e)
145 DCDGEN(42, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801f)
146 DCDGEN(43, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0000801d)
147 DCDGEN(44, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0732801c)
148 DCDGEN(45, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0400800c)
149 DCDGEN(46, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008014)
150 DCDGEN(47, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008014)
151 DCDGEN(48, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0632801c)
152 DCDGEN(49, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0380801d)
153 DCDGEN(50, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0040801d)
154 DCDGEN(51, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008004)
155
156 DCDGEN(52, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0xb2a20000)
157 DCDGEN(53, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL1, 0xb2a20000)
158 DCDGEN(54, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDMISC, 0x000ad6d0)
159 DCDGEN(55, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCDLYGD, 0x90000000)
160 DCDGEN(56, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00000000)
161
162 #else
163 dcd_len:            .long (9*12)
164
165 //DCD
166     //    ldr r0, ESDCTL_BASE_W
167     //    /* Set CSD0 */
168     //    ldr r1, =0x80000000
169     //    str r1, [r0, #ESDCTL_ESDCTL0]
170 DCDGEN(1, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0x80000000)
171     //    /* Precharge command */
172     //    ldr r1, SDRAM_0x04008008
173     //    str r1, [r0, #ESDCTL_ESDSCR]
174 DCDGEN(2, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x04008008)
175     //    /* 2 refresh commands */
176     //    ldr r1, SDRAM_0x00008010
177     //    str r1, [r0, #ESDCTL_ESDSCR]
178 DCDGEN(3, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
179     //    str r1, [r0, #ESDCTL_ESDSCR]
180 DCDGEN(4, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00008010)
181     //    /* LMR with CAS=3 and BL=3 */
182     //    ldr r1, SDRAM_0x00338018
183     //    str r1, [r0, #ESDCTL_ESDSCR]
184 DCDGEN(5, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x00338018)
185     //    /* 13 ROW, 10 COL, 32Bit, SREF=4 Micron Model */
186     //    ldr r1, SDRAM_0xB2220000
187     //    str r1, [r0, #ESDCTL_ESDCTL0]
188 DCDGEN(6, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCTL0, 0xB2220000)
189     //    /* Timing parameters */
190     //    ldr r1, SDRAM_0xB02567A9
191     //    str r1, [r0, #ESDCTL_ESDCFG0]
192 DCDGEN(7, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDCFG0, 0xB02567A9)
193     //    /* MDDR enable, RLAT=2 */
194     //    ldr r1, SDRAM_0x000A0104
195     //    str r1, [r0, #ESDCTL_ESDMISC]
196 DCDGEN(8, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDMISC, 0x000A0104)
197     //    /* Normal mode */
198     //    ldr r1, =0x00000000
199     //    str r1, [r0, #ESDCTL_ESDSCR]
200 DCDGEN(9, 4, ESDCTL_BASE_ADDR + ESDCTL_ESDSCR, 0x0)
201 #endif
202 image_len:           .long 256*1024
203
204 .endm
205
206 //#define ENABLE_IMPRECISE_ABORT
207
208 // This macro represents the initial startup code for the platform
209     .macro  _platform_setup1
210 FSL_BOARD_SETUP_START:
211     // mrc p15, 0, r0, c1, c1, 0 // Read Secure Configuration Register data. Why doesn't work???
212     // mcr p15, 0, <Rd>, c1, c1, 0 ; Write Secure Configuration Register data
213 #ifdef ENABLE_IMPRECISE_ABORT
214         mrs r1, spsr            // save old spsr
215         mrs r0, cpsr            // read out the cpsr
216         bic r0, r0, #0x100      // clear the A bit
217         msr spsr, r0            // update spsr
218         add lr, pc, #0x8        // update lr
219         movs pc, lr             // update cpsr
220         nop
221         nop
222         nop
223         nop
224         msr spsr, r1            // restore old spsr
225 #endif
226
227     // explicitly disable L2 cache
228     mrc 15, 0, r0, c1, c0, 1
229     bic r0, r0, #0x2
230     mcr 15, 0, r0, c1, c0, 1
231
232     // reconfigure L2 cache aux control reg
233     mov r0, #0xC0               // tag RAM
234     add r0, r0, #0x4    // data RAM
235     orr r0, r0, #(1 << 25)    // disable write combine
236     orr r0, r0, #(1 << 24)    // disable write allocate delay
237     orr r0, r0, #(1 << 23)    // disable write allocate combine
238     orr r0, r0, #(1 << 22)    // disable write allocate
239
240     mcr 15, 1, r0, c9, c0, 2
241
242     /* Reload data from spare area to 0x400 of main area if booting from NAND */
243     ldr r0, NFC_BASE_W
244     cmp pc, r0
245     blo 1f
246     cmp pc, r1
247     bhi 1f
248 1:
249     /* Store the boot type, from NAND or SDRAM */
250     mov r11, #SDRAM_NON_FLASH_BOOT
251
252 init_spba_start:
253     init_spba
254 init_aips_start:
255     init_aips
256 init_max_start:
257     init_max
258 init_m4if_start:
259     init_m4if
260 init_iomux_start:
261 //    init_iomux
262
263     // disable wdog
264     ldr r0, =0x30
265     ldr r1, WDOG1_BASE_W
266     strh r0, [r1]
267
268     /* If SDRAM has been setup, bypass clock/WEIM setup */
269     cmp pc, #SDRAM_BASE_ADDR
270     blo external_boot_cont
271     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
272     blo internal_boot_cont
273
274 external_boot_cont:
275
276 init_sdram_start:
277     setup_sdram
278
279
280 internal_boot_cont:
281 init_clock_start:
282     init_clock
283
284 HWInitialise_skip_SDRAM_setup:
285     ldr r0, NFC_BASE_W
286     add r2, r0, #0x1000      // 4K window
287     cmp pc, r0
288     blo Normal_Boot_Continue
289     cmp pc, r2
290     bhi Normal_Boot_Continue
291
292 NAND_Boot_Start:
293     /* Copy image from flash to SDRAM first */
294     ldr r1, MXC_REDBOOT_ROM_START
295 1:  ldmia r0!, {r3-r10}
296     stmia r1!, {r3-r10}
297     cmp r0, r2
298     blo 1b
299
300     /* Jump to SDRAM */
301     ldr r1, CONST_0x0FFF
302     and r0, pc, r1     /* offset of pc */
303     ldr r1, MXC_REDBOOT_ROM_START
304     add r1, r1, #0x10
305     add pc, r0, r1
306     nop
307     nop
308     nop
309     nop
310     nop
311     nop
312
313 NAND_Copy_Main:
314     ldr r11, NFC_IP_BASE_W  //r11: NFC IP register base. Doesn't change
315     ldr r0, [r11, #0x24]
316     and r0, r0, #3
317     cmp r0, #1
318     mov r0, #4096
319     moveq r0, #2048
320     movlt r0, #512
321     ldr r1, =_nand_pg_sz // r1 -> _nand_pg_sz
322     str r0, [r1]    // store the page size into the global variable _nand_pg_sz
323
324     ldr r0, NFC_BASE_W   //r0: nfc base. Reloaded after each page copying
325     ldr r1, _nand_pg_sz //r1: starting flash addr to be copied. Updated constantly
326     add r2, r0, #0x800   //r2: end of 3rd RAM buf. Doesn't change ?? dynamic
327     cmp r1, #2048
328     addgt r2, r2, #2048 // for 4K page, copy 4K instead of 2K
329
330     add r12, r0, #0x1E00  //r12: NFC AXI register base. Doesn't change
331     ldr r14, MXC_REDBOOT_ROM_START
332     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
333     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
334
335     //unlock internal buffer
336     mov r3, #0xFF000000
337     add r3, r3, #0x00FF0000
338     str r3, [r11, #0x4]
339     str r3, [r11, #0x8]
340     str r3, [r11, #0xC]
341     str r3, [r11, #0x10]
342     str r3, [r11, #0x14]
343     str r3, [r11, #0x18]
344     str r3, [r11, #0x1C]
345     str r3, [r11, #0x20]
346     mov r4, #0x7
347     mov r3, #0x84
348 1:  add r5, r3, r4, lsr #3
349     str r5, [r11, #0x0]
350     subs r4, r4, #0x1
351     bne 1b
352
353     mov r3, #0
354     str r3, [r11, #0x2C]
355
356 Nfc_Read_Page:
357     //start_nfc_addr_ops1(pg_no, pg_off);
358     ldr r3, _nand_pg_sz
359     cmp r3, #2048
360     // TODO: need to deal with 512B page
361     movgt r3, r1, lsr #12  // get the page number for 4K page nand
362     moveq r3, r1, lsr #11  // get the page number for 2K page nand
363     mov r3, r3, lsl #16
364     str r3, [r12, #0x4] // set the addr
365
366     // writel((FLASH_Read_Mode1_LG << 8) | FLASH_Read_Mode1, NAND_CMD_REG);
367     mov r3, #0x3000
368     str r3, [r12, #0x0]
369
370     // writel(0x00000000, NAND_CONFIGURATION1_REG);
371     mov r3, #0x0
372     str r3, [r12, #0x34]
373
374     // start auto-read
375     //writel(NAND_LAUNCH_AUTO_READ, NAND_LAUNCH_REG);
376     mov r3, #NAND_LAUNCH_AUTO_READ
377     str r3, [r12, #0x40]
378
379     do_wait_op_done
380
381 Copy_Good_Blk:
382     //copying page
383 1:  ldmia r0!, {r3-r10}
384     stmia r14!, {r3-r10}
385     cmp r0, r2
386     blo 1b
387     cmp r14, r13
388     bge NAND_Copy_Main_done
389     ldr r3, _nand_pg_sz
390     add r1, r1, r3
391     ldr r0, NFC_BASE_W
392     b Nfc_Read_Page
393
394 NAND_Copy_Main_done:
395
396 Normal_Boot_Continue:
397
398 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
399     /* Copy image from flash to SDRAM first */
400     ldr r0, =0xFFFFF000
401     and r0, r0, pc
402     ldr r1, MXC_REDBOOT_ROM_START
403     cmp r0, r1
404     beq HWInitialise_skip_SDRAM_copy
405
406     add r2, r0, #REDBOOT_IMAGE_SIZE
407
408 1:  ldmia r0!, {r3-r10}
409     stmia r1!, {r3-r10}
410     cmp r0, r2
411     ble 1b
412     /* Jump to SDRAM */
413     ldr r1, =0xFFFF
414     and r0, pc, r1         /* offset of pc */
415     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
416     add pc, r0, r1
417     nop
418     nop
419     nop
420     nop
421 #endif /* CYG_HAL_STARTUP_ROMRAM */
422
423 HWInitialise_skip_SDRAM_copy:
424
425 init_cs1_start:
426 //    init_cs1 -- moved to plf_hardware_init()
427
428 /*
429  * Note:
430  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
431  */
432 STACK_Setup:
433     // Set up a stack [for calling C code]
434     ldr r1, =__startup_stack
435     ldr r2, =RAM_BANK0_BASE
436     orr sp, r1, r2
437
438     // Create MMU tables
439     bl hal_mmu_init
440
441     // Enable MMU
442     ldr r2, =10f
443     ldr r0, =ROM_BASE_ADDRESS
444     ldr r3, [r0, #ROM_SI_REV_OFFSET]
445     cmp r3, #0x1
446     bne skip_L1_workaround
447     // Workaround for L1 cache issue
448     mrc MMU_CP, 0, r1, c10, c2, 1  // Read normal memory remap register
449     bic r1, r1, #(3 << 14)       // Remap inner attribute for TEX[0],C,B = b111 as noncacheable
450     bic r1, r1, #(3 << 6)       // Remap inner attribute for TEX[0],C,B = b011 as noncacheable
451     bic r1, r1, #(3 << 4)       // Remap inner attribute for TEX[0],C,B = b010 as noncacheable
452     mcr MMU_CP, 0, r1, c10, c2, 1  // Write normal memory remap register
453 skip_L1_workaround:
454     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
455     orr r1, r1, #7                          // enable MMU bit
456     orr r1, r1, #0x800                      // enable z bit
457     orrne r1, r1, #(1 << 28)            // Enable TEX remap, workaround for L1 cache issue
458     mcr MMU_CP, 0, r1, MMU_Control, c0
459     mov pc,r2    /* Change address spaces */
460     nop
461     nop
462     nop
463 10:
464
465     // Save shadow copy of BCR, also hardware configuration
466     ldr r1, =_board_BCR
467     str r2, [r1]
468     ldr r1, =_board_CFG
469     str r9, [r1]                // Saved far above...
470
471     .endm                       // _platform_setup1
472
473 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
474 #define PLATFORM_SETUP1
475 #endif
476
477     /* Do nothing */
478     .macro  init_spba
479     .endm  /* init_spba */
480
481     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
482     .macro init_aips
483         /*
484          * Set all MPROTx to be non-bufferable, trusted for R/W,
485          * not forced to user-mode.
486          */
487         ldr r0, AIPS1_CTRL_BASE_ADDR_W
488         ldr r1, AIPS1_PARAM_W
489         str r1, [r0, #0x00]
490         str r1, [r0, #0x04]
491         ldr r0, AIPS2_CTRL_BASE_ADDR_W
492         str r1, [r0, #0x00]
493         str r1, [r0, #0x04]
494
495     .endm /* init_aips */
496
497     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
498     .macro init_max
499     .endm /* init_max */
500
501     .macro    init_clock
502         ldr r0, CCM_BASE_ADDR_W
503         /* Disable IPU and HSC dividers */
504         mov r1, #0x60000
505         str r1, [r0, #CLKCTL_CCDR]
506
507 #ifdef IMX51_TO_2
508         /* Make sure to switch the DDR away from PLL 1 */
509         ldr r1, CCM_VAL_0x19239100
510         str r1, [r0, #CLKCTL_CBCDR]
511         /* make sure divider effective */
512     1:  ldr r1, [r0, #CLKCTL_CDHIPR]
513         cmp r1, #0x0
514         bne 1b
515 #endif
516         /* Switch ARM to step clock */
517         mov r1, #0x4
518         str r1, [r0, #CLKCTL_CCSR]
519         setup_pll PLL1, 800
520
521         setup_pll PLL3, 665
522         /* Switch peripheral to PLL 3 */
523         ldr r0, CCM_BASE_ADDR_W
524         ldr r1, CCM_VAL_0x0000D3C0
525         str r1, [r0, #CLKCTL_CBCMR]
526         ldr r1, CCM_VAL_0x033B9145
527         str r1, [r0, #CLKCTL_CBCDR]
528         setup_pll PLL2, 665
529         /* Switch peripheral to PLL 2 */
530         ldr r0, CCM_BASE_ADDR_W
531         ldr r1, CCM_VAL_0x013B9145
532         str r1, [r0, #CLKCTL_CBCDR]
533         ldr r1, CCM_VAL_0x0000E3C0
534         str r1, [r0, #CLKCTL_CBCMR]
535
536         setup_pll PLL3, 216
537
538         /* Set the platform clock dividers */
539         ldr r0, PLATFORM_BASE_ADDR_W
540         ldr r1, PLATFORM_CLOCK_DIV_W
541         str r1, [r0, #PLATFORM_ICGC]
542
543         /* Switch ARM back to PLL 1. */
544         ldr r0, CCM_BASE_ADDR_W
545         mov r1, #0x0
546         str r1, [r0, #CLKCTL_CCSR]
547
548         /* setup the rest */
549         mov r1, #0
550         str r1, [r0, #CLKCTL_CACRR]
551
552         /* Use lp_apm (24MHz) source for perclk */
553 #ifdef IMX51_TO_2
554         ldr r1, CCM_VAL_0x000020C2
555         str r1, [r0, #CLKCTL_CBCMR]
556         // ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz
557         ldr r1, CCM_VAL_0x59239100
558         str r1, [r0, #CLKCTL_CBCDR]
559 #else
560         ldr r1, CCM_VAL_0x0000E3C2
561         str r1, [r0, #CLKCTL_CBCMR]
562         // emi=ahb, all perclk dividers are 1 since using 24MHz
563         ldr r1, CCM_VAL_0x013B9100
564         str r1, [r0, #CLKCTL_CBCDR]
565 #endif
566         /* Use PLL 2 for UART's, get 66.5MHz from it */
567         ldr r1, CCM_VAL_0xA5A2A020
568         str r1, [r0, #CLKCTL_CSCMR1]
569         ldr r1, CCM_VAL_0x00C30321
570         str r1, [r0, #CLKCTL_CSCDR1]
571
572         /* make sure divider effective */
573     1:  ldr r1, [r0, #CLKCTL_CDHIPR]
574         cmp r1, #0x0
575         bne 1b
576
577         mov r1, #0x00000
578         str r1, [r0, #CLKCTL_CCDR]
579
580         // for cko - for ARM div by 8
581         mov r1, #0x000A0000
582         add r1, r1, #0x00000F0
583         str r1, [r0, #CLKCTL_CCOSR]
584     .endm /* init_clock */
585
586     .macro setup_pll pll_nr, mhz
587         ldr r0, BASE_ADDR_W_\pll_nr
588         ldr r1, PLL_VAL_0x1232
589         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
590         ldr r1, =0x2
591         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
592
593         ldr r1, W_DP_OP_\mhz
594         str r1, [r0, #PLL_DP_OP]
595         str r1, [r0, #PLL_DP_HFS_OP]
596
597         ldr r1, W_DP_MFD_\mhz
598         str r1, [r0, #PLL_DP_MFD]
599         str r1, [r0, #PLL_DP_HFS_MFD]
600
601         ldr r1, W_DP_MFN_\mhz
602         str r1, [r0, #PLL_DP_MFN]
603         str r1, [r0, #PLL_DP_HFS_MFN]
604
605         /* Now restart PLL */
606         ldr r1, PLL_VAL_0x1232
607         str r1, [r0, #PLL_DP_CTL]
608 wait_pll_lock\pll_nr\mhz:
609         ldr r1, [r0, #PLL_DP_CTL]
610         ands r1, r1, #0x1
611         beq wait_pll_lock\pll_nr\mhz
612     .endm
613
614     /* M3IF setup */
615     .macro init_m4if
616         ldr r1, M4IF_BASE_W
617 #ifdef IMX51_TO_2
618         ldr r0, M4IF_0x00240180
619         str r0, [r1, #M4IF_MIF4]
620 #else
621         /* IPU accesses with ID=0x1 given highest priority (=0xA) */
622         ldr r0, M4IF_0x00000a01
623         str r0, [r1, #M4IF_FIDBP]
624 #endif
625         /* Configure M4IF registers, VPU and IPU given higher priority (=0x4) */
626         ldr r0, M4IF_0x00000404
627         str r0, [r1, #M4IF_FBPM0]
628     .endm /* init_m4if */
629
630     .macro setup_sdram
631         ldr r0, ESDCTL_BASE_W
632         /* Set CSD0 */
633         ldr r1, =0x80000000
634         str r1, [r0, #ESDCTL_ESDCTL0]
635         /* Precharge command */
636         ldr r1, SDRAM_0x04008008
637         str r1, [r0, #ESDCTL_ESDSCR]
638         /* 2 refresh commands */
639         ldr r1, SDRAM_0x00008010
640         str r1, [r0, #ESDCTL_ESDSCR]
641         str r1, [r0, #ESDCTL_ESDSCR]
642         /* LMR with CAS=3 and BL=3 */
643         ldr r1, SDRAM_0x00338018
644         str r1, [r0, #ESDCTL_ESDSCR]
645         /* 13 ROW, 10 COL, 32Bit, SREF=4 Micron Model */
646         ldr r1, SDRAM_0xB2220000
647         str r1, [r0, #ESDCTL_ESDCTL0]
648         /* Timing parameters */
649 //        ldr r1, SDRAM_0x899F6BBA
650         ldr r1, SDRAM_0xB02567A9
651         str r1, [r0, #ESDCTL_ESDCFG0]
652         /* MDDR enable, RLAT=2 */
653         ldr r1, SDRAM_0x000A0104
654         str r1, [r0, #ESDCTL_ESDMISC]
655         /* Normal mode */
656         ldr r1, =0x00000000
657         str r1, [r0, #ESDCTL_ESDSCR]
658     .endm
659
660     .macro do_wait_op_done
661     1:
662         ldr r3, [r11, #0x2C]
663         ands r3, r3, #NFC_IPC_INT
664         beq 1b
665         mov r3, #0x0
666         str r3, [r11, #0x2C]
667     .endm   // do_wait_op_done
668
669     .macro  init_iomux
670         // do nothing
671     .endm /* init_iomux */
672
673 #define PLATFORM_VECTORS         _platform_vectors
674     .macro  _platform_vectors
675         .globl  _board_BCR, _board_CFG
676 _board_BCR:     .long   0       // Board Control register shadow
677 _board_CFG:     .long   0       // Board Configuration (read at RESET)
678     .endm
679
680 WDOG1_BASE_W:           .word   WDOG1_BASE_ADDR
681 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
682 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
683 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
684 AIPS1_PARAM_W:          .word   0x77777777
685 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
686 MAX_PARAM1:             .word   0x00302154
687 ESDCTL_BASE_W:          .word   ESDCTL_BASE_ADDR
688 M4IF_BASE_W:            .word   M4IF_BASE_ADDR
689 M4IF_0x00000a01:       .word   0x00000a01
690 M4IF_0x00240180:       .word   0x00240180
691 M4IF_0x00000404:       .word   0x00000404
692 NFC_BASE_W:             .word   NFC_BASE_ADDR_AXI
693 NFC_IP_BASE_W:          .word   NFC_IP_BASE
694 SDRAM_0x04008008:       .word   0x04008008
695 SDRAM_0x00008010:       .word   0x00008010
696 SDRAM_0x00338018:       .word   0x00338018
697 SDRAM_0xB2220000:       .word   0xB2220000
698 SDRAM_0x899F6BBA:       .word   0x899F6BBA
699 SDRAM_0xB02567A9:       .word   0xB02567A9
700 SDRAM_0x000A0104:       .word   0x000A0104
701 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
702 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
703 CONST_0x0FFF:           .word   0x0FFF
704 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
705 CCM_VAL_0x0000E3C2:     .word   0x0000E3C2
706 CCM_VAL_0x000020C2:     .word   0x000020C2
707 CCM_VAL_0x013B9100:     .word   0x013B9100
708 CCM_VAL_0x59239100:     .word   0x59239100
709 CCM_VAL_0x19239100:     .word   0x19239100
710 CCM_VAL_0xA5A2A020:     .word   0xA5A2A020
711 CCM_VAL_0x00C30321:     .word   0x00C30321
712 CCM_VAL_0x0000D3C0:     .word   0x0000D3C0
713 CCM_VAL_0x033B9145:     .word   0x033B9145
714 CCM_VAL_0x013B9145:     .word   0x013B9145
715 CCM_VAL_0x0000E3C0:     .word   0x0000E3C0
716 PLL_VAL_0x222:          .word   0x222
717 PLL_VAL_0x232:          .word   0x232
718 BASE_ADDR_W_PLL1:       .word   PLL1_BASE_ADDR
719 BASE_ADDR_W_PLL2:       .word   PLL2_BASE_ADDR
720 BASE_ADDR_W_PLL3:       .word   PLL3_BASE_ADDR
721 PLL_VAL_0x1232:         .word   0x1232
722 W_DP_OP_800:            .word   DP_OP_800
723 W_DP_MFD_800:           .word   DP_MFD_800
724 W_DP_MFN_800:           .word   DP_MFN_800
725 W_DP_OP_700:            .word   DP_OP_700
726 W_DP_MFD_700:           .word   DP_MFD_700
727 W_DP_MFN_700:           .word   DP_MFN_700
728 W_DP_OP_400:            .word   DP_OP_400
729 W_DP_MFD_400:           .word   DP_MFD_400
730 W_DP_MFN_400:           .word   DP_MFN_400
731 W_DP_OP_532:            .word   DP_OP_532
732 W_DP_MFD_532:           .word   DP_MFD_532
733 W_DP_MFN_532:           .word   DP_MFN_532
734 W_DP_OP_665:            .word   DP_OP_665
735 W_DP_MFD_665:           .word   DP_MFD_665
736 W_DP_MFN_665:           .word   DP_MFN_665
737 W_DP_OP_216:            .word   DP_OP_216
738 W_DP_MFD_216:           .word   DP_MFD_216
739 W_DP_MFN_216:           .word   DP_MFN_216
740 PLATFORM_BASE_ADDR_W:   .word   PLATFORM_BASE_ADDR
741 PLATFORM_CLOCK_DIV_W:   .word   0x00000725
742 _nand_pg_sz:            .word 0
743
744 /*---------------------------------------------------------------------------*/
745 /* end of hal_platform_setup.h                                               */
746 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */