]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx25/3stack/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx25 / 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 #define INTERNAL_BOOT_MODE
57
58 #if defined(INTERNAL_BOOT_MODE)
59 #define PLATFORM_PREAMBLE setup_flash_header
60 #endif
61
62 #ifdef CYG_HAL_STARTUP_ROMRAM
63 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
64 #endif
65
66 #define CYGHWR_HAL_ROM_VADDR        0x0
67
68 // This macro represents the initial startup code for the platform
69 // r11 is reserved to contain chip rev info in this file
70     .macro  _platform_setup1
71 FSL_BOARD_SETUP_START:
72     // invalidate I/D cache/TLB and drain write buffer
73     mov r0, #0
74     mcr 15, 0, r0, c7, c7, 0    /* invalidate I cache and D cache */
75     mcr 15, 0, r0, c8, c7, 0    /* invalidate TLBs */
76     mcr 15, 0, r0, c7, c10, 4   /* Drain the write buffer */
77
78 #if defined(INTERNAL_BOOT_MODE)
79     // On internal boot mode, check MEM CTRL bits for boot source
80     mov r0, #NAND_FLASH_BOOT
81     ldr r1, CCM_BASE_ADDR_W
82     ldr r1, [r1, #CLKCTL_RCSR]
83     tst r1, #0x80000000
84     movne r0, #MMC_FLASH_BOOT
85     ldr r1, MXCBOOT_FLAG_ADDR_W
86     str r0, [r1]
87 #else
88     mov r0, #SDRAM_NON_FLASH_BOOT
89     ldr r1, MXCBOOT_FLAG_ADDR_W
90     str r0, [r1] // for checking boot source from nand, nor or sdram
91 #endif
92
93    .globl  init_spba_start, init_aips_start, init_max_start, init_m3if_start
94 init_spba_start:
95     init_spba
96 init_aips_start:
97     init_aips
98 init_max_start:
99     init_max
100 init_m3if_start:
101     init_m3if
102
103 #ifndef INTERNAL_BOOT_MODE
104     // check if sdram has been setup
105     cmp pc, #SDRAM_BASE_ADDR
106     blo init_clock_start
107     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
108     blo HWInitialise_skip_SDRAM_setup
109
110     // Now we must boot from Flash
111     mov r0, #NOR_FLASH_BOOT
112     ldr r1, MXCBOOT_FLAG_ADDR_W
113     str r0, [r1]
114 #endif
115 init_clock_start:
116     init_clock
117 init_cs5_start:
118 #ifndef INTERNAL_BOOT_MODE
119     init_cs5
120
121 init_sdram_start:
122     /* Assume DDR memory */
123     setup_sdram
124 #endif
125
126 HWInitialise_skip_SDRAM_setup:
127     mov r0, #NFC_BASE
128     add r2, r0, #0x1000         // 4K window
129     cmp pc, r0
130     blo Normal_Boot_Continue
131     cmp pc, r2
132     bhi Normal_Boot_Continue
133 NAND_Boot_Start:
134     /* Copy image from flash to SDRAM first */
135     ldr r1, MXC_REDBOOT_ROM_START
136
137 1:  ldmia r0!, {r3-r10}
138     stmia r1!, {r3-r10}
139     cmp r0, r2
140     blo 1b
141
142     /* Jump to SDRAM */
143     ldr r1, CONST_0x0FFF
144     and r0, pc, r1     /* offset of pc */
145     ldr r1, MXC_REDBOOT_ROM_START
146     add r1, r1, #0x10
147     add pc, r0, r1
148     nop
149     nop
150     nop
151     nop
152 NAND_Copy_Main:
153     mov r0, #NAND_FLASH_BOOT
154     ldr r1, MXCBOOT_FLAG_ADDR_W
155     str r0, [r1]
156     mov r0, #MXCFIS_NAND
157     ldr r1, MXCFIS_FLAG_ADDR_W
158     str r0, [r1]
159
160     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
161     add r12, r0, #0x1E00  //r12: NFC register base. Doesn't change
162     ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
163     orr r3, r3, #0x1
164
165     /* Setting NFC */
166     ldr r7, CCM_BASE_ADDR_W
167     ldr r1, [r7, #CLKCTL_RCSR]
168     /*BUS WIDTH setting*/
169     tst r1, #0x20000000
170     orrne r1, r1, #0x4000
171     biceq r1, r1, #0x4000
172
173     /*4K PAGE*/
174     tst r1, #0x10000000
175     orrne r1, r1, #0x200
176     bne  1f
177     /*2K PAGE*/
178     bic r1, r1, #0x200
179     tst r1, #0x08000000
180     orrne r1, r1, #0x100 /*2KB page size*/
181     biceq r1, r1, #0x100 /*512B page size*/
182     movne r2, #32 /*64 bytes*/
183     moveq r2, #8  /*16 bytes*/
184     b NAND_setup
185 1:
186     tst r1, #0x08000000
187     bicne r3, r3, #1   /*Enable 8bit ECC mode*/
188     movne r2, #109 /*218 bytes*/
189     moveq r2, #64  /*128 bytes*/
190 NAND_setup:
191     str r1, [r7, #CLKCTL_RCSR]
192     strh r2, [r12, #ECC_RSLT_SPARE_AREA_REG_OFF]
193     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
194
195     //unlock internal buffer
196     mov r3, #0x2
197     strh r3, [r12, #NFC_CONFIGURATION_REG_OFF]
198     //unlock nand device
199     mov r3, #0
200     strh r3, [r12, #UNLOCK_START_BLK_ADD_REG_OFF]
201     sub r3, r3, #1
202     strh r3, [r12, #UNLOCK_END_BLK_ADD_REG_OFF]
203     mov r3, #4
204     strh r3, [r12, #NF_WR_PROT_REG_OFF]
205
206     /* r0: NFC base address. RAM buffer base address. [constantly]
207      * r1: starting flash address to be copied. [constantly]
208      * r2: page size. [Doesn't change]
209      * r3: used as argument.
210      * r11: starting SDRAM address for copying. [Updated constantly].
211      * r12: NFC register base address. [constantly].
212      * r13: end of SDRAM address for copying. [Doesn't change].
213      */
214
215     mov r1, #0x1000
216     ldr r3, [r7, #CLKCTL_RCSR]
217     tst r3, #0x200
218     movne r2, #0x1000
219     bne 1f
220     tst r3, #0x100
221     mov r1, #0x800  /*Strang Why is not 4K offset*/
222     movne r2, #0x800
223     moveq r2, #0x200
224 1: /*Update the indicator of copy area */
225     ldr r11, MXC_REDBOOT_ROM_START
226     add r13, r11, #REDBOOT_IMAGE_SIZE
227     add r11, r11, r1
228
229 Nfc_Read_Page:
230     mov r3, #0x0
231     nfc_cmd_input
232
233     cmp r2, #0x800
234     bhi nfc_addr_ops_4kb
235     beq nfc_addr_ops_2kb
236
237     mov r3, r1
238     do_addr_input       //1st addr cycle
239     mov r3, r1, lsr #9
240     do_addr_input       //2nd addr cycle
241     mov r3, r1, lsr #17
242     do_addr_input       //3rd addr cycle
243     mov r3, r1, lsr #25
244     do_addr_input       //4th addr cycle
245     b end_of_nfc_addr_ops
246
247 nfc_addr_ops_2kb:
248     mov r3, #0
249     do_addr_input       //1st addr cycle
250     mov r3, #0
251     do_addr_input       //2nd addr cycle
252     mov r3, r1, lsr #11
253     do_addr_input       //3rd addr cycle
254     mov r3, r1, lsr #19
255     do_addr_input       //4th addr cycle
256     mov r3, r1, lsr #27
257     do_addr_input       //5th addr cycle
258
259     mov r3, #0x30
260     nfc_cmd_input
261     b end_of_nfc_addr_ops
262
263 nfc_addr_ops_4kb:
264     mov r3, #0
265     do_addr_input       //1st addr cycle
266     mov r3, #0
267     do_addr_input       //2nd addr cycle
268     mov r3, r1, lsr #12
269     do_addr_input       //3rd addr cycle
270     mov r3, r1, lsr #20
271     do_addr_input       //4th addr cycle
272     mov r3, r1, lsr #27
273     do_addr_input       //5th addr cycle
274
275     mov r3, #0x30
276     nfc_cmd_input
277
278 end_of_nfc_addr_ops:
279     mov r8, #0
280     bl nfc_data_output
281     bl do_wait_op_done
282     // Check if x16/2kb page
283     cmp r2, #0x800
284     bhi nfc_addr_data_output_done_4k
285     beq nfc_addr_data_output_done_2k
286     beq nfc_addr_data_output_done_512
287
288     // check for bad block
289 //    mov r3, r1, lsl #(32-17)    // get rid of block number
290 //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
291     b nfc_addr_data_output_done
292
293 nfc_addr_data_output_done_4k:
294 //TODO
295     b nfc_addr_data_output_done
296
297 nfc_addr_data_output_done_2k:
298 // end of 4th
299     // check for bad block
300 //TODO    mov r3, r1, lsl #(32-17)    // get rid of block number
301 //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
302     b nfc_addr_data_output_done
303
304 nfc_addr_data_output_done_512:
305     // check for bad block
306 // TODO   mov r3, r1, lsl #(32-5-9)    // get rid of block number
307 // TODO   cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
308
309 nfc_addr_data_output_done:
310 #if 0
311     bhi Copy_Good_Blk
312     add r4, r0, #0x1000  //r3 -> spare area buf 0
313     ldrh r4, [r4, #0x4]
314     and r4, r4, #0xFF00
315     cmp r4, #0xFF00
316     beq Copy_Good_Blk
317     // really sucks. Bad block!!!!
318     cmp r3, #0x0
319     beq Skip_bad_block
320     // even suckier since we already read the first page!
321     // Check if x16/2kb page
322     cmp r2, #0x800
323     // for 4k page
324     subhi r11, r11, #0x1000  //rewind 1 page for the sdram pointer
325     subhi r1, r1, #0x1000    //rewind 1 page for the flash pointer
326     // for 2k page
327     subeq r11, r11, #0x800  //rewind 1 page for the sdram pointer
328     subeq r1, r1, #0x800    //rewind 1 page for the flash pointer
329     // for 512 page
330     sublo r11, r11, #512  //rewind 1 page for the sdram pointer
331     sublo r1, r1, #512    //rewind 1 page for the flash pointer
332 Skip_bad_block:
333     // Check if x16/2kb page
334     ldr r7, CCM_BASE_ADDR_W
335     ldr r7, [r7, #CLKCTL_RCSR]
336     tst r7, #0x200
337     addne r1, r1, #(128*4096)
338     bne Skip_bad_block_done
339     tst r7, #0x100
340     addeq r1, r1, #(32*512)
341     addne r1, r1, #(64*2048)
342 Skip_bad_block_done:
343     b Nfc_Read_Page
344 #endif
345 Copy_Good_Blk:
346     //copying page
347     add r2, r2, #NFC_BASE
348 1:  ldmia r0!, {r3-r10}
349     stmia r11!, {r3-r10}
350     cmp r0, r2
351     blo 1b
352     sub r2, r2, #NFC_BASE
353
354     cmp r11, r13
355     bge NAND_Copy_Main_done
356     // Check if x16/2kb page
357     add r1, r1, r2
358     mov r0, #NFC_BASE
359     b Nfc_Read_Page
360
361 NAND_Copy_Main_done:
362
363 Normal_Boot_Continue:
364
365 #ifdef CYG_HAL_STARTUP_ROMRAM    /* enable running from RAM */
366     /* Copy image from flash to SDRAM first */
367     ldr r0, =0xFFFFF000
368     and r0, r0, pc
369     ldr r1, MXC_REDBOOT_ROM_START
370     cmp r0, r1
371     beq HWInitialise_skip_SDRAM_copy
372
373     add r2, r0, #REDBOOT_IMAGE_SIZE
374
375 1:  ldmia r0!, {r3-r10}
376     stmia r1!, {r3-r10}
377     cmp r0, r2
378     ble 1b
379
380     /* Jump to SDRAM */
381     ldr r1, =0xFFFF
382     and r0, pc, r1      /* offset of pc */
383     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
384     add pc, r0, r1
385     nop
386     nop
387     nop
388     nop
389 #endif /* CYG_HAL_STARTUP_ROMRAM */
390
391 HWInitialise_skip_SDRAM_copy:
392
393 STACK_Setup:
394     // Set up a stack [for calling C code]
395     ldr r1, =__startup_stack
396     ldr r2, =RAM_BANK0_BASE
397     orr sp, r1, r2
398
399     // Create MMU tables
400     bl hal_mmu_init
401
402     // Enable MMU
403     ldr r2, =10f
404     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
405     orr r1, r1, #7                          // enable MMU bit
406     mcr MMU_CP, 0, r1, MMU_Control, c0
407     mov pc,r2    /* Change address spaces */
408     nop
409     nop
410     nop
411 10:
412     // Save shadow copy of BCR, also hardware configuration
413     ldr r1, =_board_BCR
414     str r2,[r1]
415     ldr r1, =_board_CFG
416     str r9,[r1]                // Saved far above...
417
418     .endm                       // _platform_setup1
419
420 do_wait_op_done:
421     1:
422         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
423         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
424         beq 1b
425     bx lr     // do_wait_op_done
426
427
428 nfc_data_output:
429     ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
430     orr r3, r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
431     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
432
433     strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
434
435     mov r3, #FDO_PAGE_SPARE_VAL
436     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
437     bx lr
438
439 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
440 #define PLATFORM_SETUP1
441 #endif
442
443     /* Do nothing */
444     .macro  init_spba
445     .endm  /* init_spba */
446
447     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
448     .macro init_aips
449         /*
450          * Set all MPROTx to be non-bufferable, trusted for R/W,
451          * not forced to user-mode.
452          */
453         ldr r0, AIPS1_CTRL_BASE_ADDR_W
454         ldr r1, AIPS1_PARAM_W
455         str r1, [r0, #0x00]
456         str r1, [r0, #0x04]
457         ldr r0, AIPS2_CTRL_BASE_ADDR_W
458         str r1, [r0, #0x00]
459         str r1, [r0, #0x04]
460     .endm /* init_aips */
461
462     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
463     .macro init_max
464         ldr r0, MAX_BASE_ADDR_W
465         /* MPR - priority for MX25 is IAHB>DAHB>USBOTG>RTIC>(SDHC2/SDMA) */
466         ldr r1, MAX_PARAM1
467         str r1, [r0, #0x000]        /* for S0 */
468         str r1, [r0, #0x100]        /* for S1 */
469         str r1, [r0, #0x200]        /* for S2 */
470         str r1, [r0, #0x300]        /* for S3 */
471         str r1, [r0, #0x400]        /* for S4 */
472         /* SGPCR - always park on last master */
473         ldr r1, =0x10
474         str r1, [r0, #0x010]        /* for S0 */
475         str r1, [r0, #0x110]        /* for S1 */
476         str r1, [r0, #0x210]        /* for S2 */
477         str r1, [r0, #0x310]        /* for S3 */
478         str r1, [r0, #0x410]        /* for S4 */
479         /* MGPCR - restore default values */
480         ldr r1, =0x0
481         str r1, [r0, #0x800]        /* for M0 */
482         str r1, [r0, #0x900]        /* for M1 */
483         str r1, [r0, #0xA00]        /* for M2 */
484         str r1, [r0, #0xB00]        /* for M3 */
485         str r1, [r0, #0xC00]        /* for M4 */
486     .endm /* init_max */
487
488     /* Clock setup */
489     .macro    init_clock
490         ldr r0, CCM_BASE_ADDR_W
491
492         /* default CLKO to 1/32 of the ARM core */
493         ldr r1, [r0, #CLKCTL_MCR]
494         bic r1, r1, #0x00F00000
495         bic r1, r1, #0x7F000000
496         mov r2,     #0x5F000000
497         add r2, r2, #0x00200000
498         orr r1, r1, r2
499         str r1, [r0, #CLKCTL_MCR]
500
501         /* enable all the clocks */
502         ldr r2, CCM_CGR0_W
503         str r2, [r0, #CLKCTL_CGR0]
504         ldr r2, CCM_CGR1_W
505         str r2, [r0, #CLKCTL_CGR1]
506         ldr r2, CCM_CGR2_W
507         str r2, [r0, #CLKCTL_CGR2]
508     .endm /* init_clock */
509
510     /* M3IF setup */
511     .macro init_m3if
512         /* Configure M3IF registers */
513         ldr r1, M3IF_BASE_W
514         /*
515         * M3IF Control Register (M3IFCTL) for MX25
516         * MRRP[0] = LCDC           on priority list (1 << 0)  = 0x00000001
517         * MRRP[1] = MAX1       not on priority list (0 << 1)  = 0x00000000
518         * MRRP[2] = MAX0       not on priority list (0 << 2)  = 0x00000000
519         * MRRP[3] = USB HOST   not on priority list (0 << 3)  = 0x00000000
520         * MRRP[4] = SDMA       not on priority list (0 << 4)  = 0x00000000
521         * MRRP[5] = SD/ATA/FEC not on priority list (0 << 5)  = 0x00000000
522         * MRRP[6] = SCMFBC     not on priority list (0 << 6)  = 0x00000000
523         * MRRP[7] = CSI        not on priority list (0 << 7)  = 0x00000000
524         *                                                       ----------
525         *                                                       0x00000001
526         */
527         ldr r0, =0x00000001
528         str r0, [r1]  /* M3IF control reg */
529     .endm /* init_m3if */
530
531      /* CPLD on CS5 setup */
532     .macro init_cs5
533         ldr r0, WEIM_CTRL_CS5_W
534         ldr r1, CS5_CSCRU_0x0000D843
535         str r1, [r0, #CSCRU]
536         ldr r1, CS5_CSCRL_0x22252521
537         str r1, [r0, #CSCRL]
538         ldr r1, CS5_CSCRA_0x22220A00
539         str r1, [r0, #CSCRA]
540     .endm /* init_cs5 */
541
542     .macro setup_sdram
543         ldr r0, ESDCTL_BASE_W
544         mov r3, #0x2000
545         str r3, [r0, #0x0]
546         str r3, [r0, #0x8]
547
548         mov r12, #0x00
549         mov r2, #0x1    /* mDDR */
550         mov r1, #RAM_BANK0_BASE
551         bl setup_sdram_bank
552         cmp r3, #0x0
553         orreq r12, r12, #1
554         eorne r2, r2, #0x1
555         blne setup_sdram_bank
556
557         ldr r3, ESDCTL_DELAY5
558         str r3, [r0, #0x30]
559     .endm
560
561     .macro nfc_cmd_input
562         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
563         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
564         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
565         bl do_wait_op_done
566     .endm   // nfc_cmd_input
567
568     .macro do_addr_input
569         and r3, r3, #0xFF
570         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
571         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
572         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
573         bl do_wait_op_done
574     .endm   // do_addr_input
575
576     /* To support 133MHz DDR */
577     .macro  init_iomuxc
578         mov r0, #0x2
579         ldr r1, IOMUXC_BASE_ADDR_W
580         add r1, r1, #0x368
581         add r2, r1, #0x4C8 - 0x368
582 1:      str r0, [r1], #4
583         cmp r1, r2
584         ble 1b
585     .endm /* init_iomuxc */
586
587 /*
588  * r0: control base, r1: ram bank base
589  * r2: ddr type(0:DDR2, 1:MDDR) r3, r4: working
590  */
591 setup_sdram_bank:
592         mov r3, #0xE /*0xA + 0x4*/
593         tst r2, #0x1
594         orreq r3, r3, #0x300 /*DDR2*/
595         str r3, [r0, #0x10]
596         bic r3, r3, #0x00A
597         str r3, [r0, #0x10]
598         beq 2f
599
600         mov r3, #0x20000
601 1:      subs r3, r3, #1
602         bne 1b
603
604 2:      adr r4, ESDCTL_CONFIG
605         tst r2, #0x1
606         ldreq r3, [r4, #0x0]
607         ldrne r3, [r4, #0x4]
608         cmp r1, #RAM_BANK1_BASE
609         strlo r3, [r0, #0x4]
610         strhs r3, [r0, #0xC]
611
612         ldr r3, ESDCTL_0x92220000
613         strlo r3, [r0, #0x0]
614         strhs r3, [r0, #0x8]
615         mov r3, #0xDA
616         ldr r4, RAM_PARAM1_MDDR
617         strb r3, [r1, r4]
618
619         tst r2, #0x1
620         bne skip_set_mode
621
622         cmp r1, #RAM_BANK1_BASE
623         ldr r3, ESDCTL_0xB2220000
624         strlo r3, [r0, #0x0]
625         strhs r3, [r0, #0x8]
626         mov r3, #0xDA
627         ldr r4, RAM_PARAM4_MDDR
628         strb r3, [r1, r4]
629         ldr r4, RAM_PARAM5_MDDR
630         strb r3, [r1, r4]
631         ldr r4, RAM_PARAM3_MDDR
632         strb r3, [r1, r4]
633         ldr r4, RAM_PARAM2_MDDR
634         strb r3, [r1, r4]
635
636         ldr r3, ESDCTL_0x92220000
637         strlo r3, [r0, #0x0]
638         strhs r3, [r0, #0x8]
639         mov r3, #0xDA
640         ldr r4, RAM_PARAM1_MDDR
641         strb r3, [r1, r4]
642
643 skip_set_mode:
644         cmp r1, #RAM_BANK1_BASE
645         ldr r3, ESDCTL_0xA2220000
646         strlo r3, [r0, #0x0]
647         strhs r3, [r0, #0x8]
648         mov r3, #0xDA
649         strb r3, [r1]
650         strb r3, [r1]
651
652         ldr r3, ESDCTL_0xB2220000
653         strlo r3, [r0, #0x0]
654         strhs r3, [r0, #0x8]
655         adr r4, RAM_PARAM6_MDDR
656         tst r2, #0x1
657         ldreq r4, [r4, #0x0]
658         ldrne r4, [r4, #0x4]
659         mov r3, #0xDA
660         strb r3, [r1, r4]
661         ldreq r4, RAM_PARAM7_MDDR
662         streqb r3, [r1, r4]
663         adr r4, RAM_PARAM3_MDDR
664         ldreq r4, [r4, #0x0]
665         ldrne r4, [r4, #0x4]
666         strb r3, [r1, r4]
667
668         cmp r1, #RAM_BANK1_BASE
669         ldr r3, ESDCTL_0x82226080
670         strlo r3, [r0, #0x0]
671         strhs r3, [r0, #0x8]
672
673         tst r2, #0x1
674         moveq r4, #0x20000
675         movne r4, #0x200
676 1:      subs r4, r4, #1
677         bne 1b
678
679         str r3, [r1, #0x100]
680         ldr r4, [r1, #0x100]
681         cmp r3, r4
682         movne r3, #1
683         moveq r3, #0
684
685         mov pc, lr
686
687 #define PLATFORM_VECTORS         _platform_vectors
688     .macro  _platform_vectors
689         .globl  _board_BCR, _board_CFG
690 _board_BCR:   .long   0       // Board Control register shadow
691 _board_CFG:   .long   0       // Board Configuration (read at RESET)
692     .endm
693
694 //Internal Boot, from MMC/SD cards or NAND flash
695 #ifdef INTERNAL_BOOT_MODE
696 #define DCDGEN(i,type, addr, data) \
697 dcd_##i:                         ;\
698     .long type                   ;\
699     .long addr                   ;\
700     .long data
701
702 #define FHEADER_OFFSET 0x400
703
704     .macro setup_flash_header
705     b reset_vector
706 #if defined(FHEADER_OFFSET)
707     .org FHEADER_OFFSET
708 #endif
709 app_code_jump_v:        .long reset_vector
710 app_code_barker:        .long 0xB1
711 app_code_csf:           .long 0
712 hwcfg_ptr_ptr:          .long hwcfg_ptr
713 super_root_key:         .long 0
714 hwcfg_ptr:              .long dcd_data
715 app_dest_ptr:           .long SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
716 dcd_data:               .long 0xB17219E9
717 #ifdef MEMORY_MDDR_ENABLE
718                         .long 12*15
719 #else
720                         .long 12*24
721 #endif
722
723 // real dcd data table
724
725 // WEIM config-CS5 init -- CPLD
726 DCDGEN( 1, 4, 0xB8002050, 0x0000D843)   // CS5_CSCRU
727 DCDGEN( 2, 4, 0xB8002054, 0x22252521)   // CS5_CSCRL
728 DCDGEN( 3, 4, 0xB8002058, 0x22220A00)   // CS5_CSCRA
729
730 #ifdef MEMORY_MDDR_ENABLE
731 // MDDR init
732 DCDGEN( 4, 4, 0xB8001010, 0x00000004)   // enable mDDR
733 DCDGEN( 5, 4, 0xB8001000, 0x92100000)   // precharge command
734 DCDGEN( 6, 1, 0x80000400, 0x12344321)   // precharge all dummy write
735 DCDGEN( 7, 4, 0xB8001000, 0xA2100000)   // auto-refresh command
736 DCDGEN( 8, 4, 0x80000000, 0x12344321)   // dummy write for refresh
737 DCDGEN( 9, 4, 0x80000000, 0x12344321)   // dummy write for refresh
738 DCDGEN(10, 4, 0xB8001000, 0xB2100000)   // Load Mode Register command - cas=3 bl=8
739 DCDGEN(11, 1, 0x80000033, 0xda)         // dummy write -- address has the mode bits
740 DCDGEN(12, 1, 0x81000000, 0xff)         // dummy write -- address has the mode bits
741 // 
742 // For DDR clock speed max = 133 MHz, HYB18M1G320BF-7.5 memory
743 // based on data sheet HYx18M1G16x_BF_rev100.pdf.
744 // 
745 // ESDCTL0=0x82216880:
746 //  SDE=1       ESDRAM Controller Enable: Enabled
747 //  SMODE=000   SDRAM Controller Operating Mode: Normal Read/Write
748 //  SP=0        Supervisor Protect: User mode accesses allowed
749 //  ROW=010     Row Address Width: 13 Row Addresses
750 //  COL=10      Column Address Width: 10 Column Addresses
751 //  DSIZ=01     SDRAM Memory Data Width: 16-bit memory width aligned to D[15:0]
752 //  SREFR=011   SDRAM Refresh Rate: 4 rows each refresh clock,
753 //                      8192 rows/64 mS @ 32 kHz
754 //                      7.81 uS row rate at 32 kHz
755 //  PWDT=10     Power Down Timer: 64 clocks (HCLK) after completion of last access
756 //                      with Active Power Down (most aggressive)
757 //  FP=0        Full Page: Not Full Page
758 //  BL=1        Burst Length: 8
759 //  PRCT=000000 Precharge Timer: Disabled
760 //
761 DCDGEN(13, 4, 0xB8001000, 0x82216880)
762 //
763 // ESDCFG0=0x00295729:
764 //   tXP=01     LPDDR exit power down to next valid command delay: 2 clocks
765 //   tWTR=0     LPDDR WRITE to READ Command Delay: 1 clock
766 //   tRP=10     SDRAM Row Precharge Delay: 3 clocks
767 //   tMRD=01    SDRAM Load Mode Register to ACTIVE Command: 2 clocks
768 //   tWR=0      SDRAM WRITE to PRECHARGE Command: 2 clocks
769 //   tRAS=101   SDRAM ACTIVE to PRECHARGE Command: 6 clocks
770 //   tRRD=01    ACTIVE Bank A to ACTIVE Bank B Command: 2 clocks
771 //   tCAS=11    SDRAM CAS Latency: 3 clocks
772 //   tRCD=010   SDRAM Row to Column Delay: 3 clocks
773 //   tRC=1001   SDRAM Row Cycle Delay: 9 clocks
774 //
775 DCDGEN(14, 4, 0xB8001004, 0x00295729)
776 #else
777 // DDR2 init
778 DCDGEN( 4, 4, 0xB8001004, 0x0076E83A)   // initial value for ESDCFG0
779 DCDGEN( 5, 4, 0xB8001010, 0x00000204)   // ESD_MISC
780 DCDGEN( 6, 4, 0xB8001000, 0x92210000)   // CS0 precharge command
781 DCDGEN( 7, 4, 0x80000f00, 0x12344321)   // precharge all dummy write
782 DCDGEN( 8, 4, 0xB8001000, 0xB2210000)   // Load Mode Register command
783 DCDGEN( 9, 1, 0x82000000, 0xda)         // dummy write -- Load EMR2
784 DCDGEN(10, 1, 0x83000000, 0xda)         // dummy write -- Load EMR3
785 DCDGEN(11, 1, 0x81000400, 0xda)         // dummy write -- Load EMR1; enable DLL
786 DCDGEN(12, 1, 0x80000333, 0xda)         // dummy write -- Load MR; reset DLL
787
788 DCDGEN(13, 4, 0xB8001000, 0x92210000)   // CS0 precharge command
789 DCDGEN(14, 1, 0x80000400, 0x12345678)   // precharge all dummy write
790
791 DCDGEN(15, 4, 0xB8001000, 0xA2210000)   // select manual refresh mode
792 DCDGEN(16, 4, 0x80000000, 0x87654321)   // manual refresh
793 DCDGEN(17, 4, 0x80000000, 0x87654321)   // manual refresh twice
794
795 DCDGEN(18, 4, 0xB8001000, 0xB2210000)   // Load Mode Register command
796 DCDGEN(19, 1, 0x80000233, 0xda)         // -- Load MR; CL=3, BL=8, end DLL reset
797 DCDGEN(20, 1, 0x81000780, 0xda)         // -- Load EMR1; OCD default
798 DCDGEN(21, 1, 0x81000400, 0xda)         // -- Load EMR1; OCD exit
799
800 //  ESD_ESDCTL0  SDE_SMODE_SP_ROW_00_COL_00_DSIZ_SREFR_0_PWDT_0_FP_BL_0__PRCT
801 //  ESD_ESDCTL0 32'b1_000__0__010_00__10_00___10___011_0___00_0__0__0_0_000000
802 //  @; normal mode row=010//col=10//dzize=10//self ref=011//PWDT =00//BL =0//prct =000000
803 DCDGEN(22, 4, 0xB8001000, 0x82216080)
804
805 // Init IOMUXC_SW_PAD_CTL_GRP_DDRTYPE_GRP(1-5)
806 DCDGEN(23, 4, 0x43FAC454, 0x00001000)
807 #endif
808 //
809 // CLK 
810 DCDGEN(99, 4, 0x53F80008, 0x20034000)   // CLKCTL ARM=400 AHB=133
811
812 //CARD_FLASH_CFG_PARMS_T---length
813 card_cfg:               .long REDBOOT_IMAGE_SIZE
814      .endm
815 #endif
816
817 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
818 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
819 AIPS1_PARAM_W:          .word   0x77777777
820 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
821 MAX_PARAM1:             .word   0x00043210
822 ESDCTL_BASE_W:          .word   ESDCTL_BASE_ADDR
823 M3IF_BASE_W:            .word   M3IF_BASE
824 RAM_PARAM1_MDDR:        .word   0x00000400
825 RAM_PARAM2_MDDR:        .word   0x00000333
826 RAM_PARAM3_MDDR:        .word   0x02000400
827                         .word   0x02000000
828 RAM_PARAM4_MDDR:        .word   0x04000000
829 RAM_PARAM5_MDDR:        .word   0x06000000
830 RAM_PARAM6_MDDR:        .word   0x00000233
831                         .word   0x00000033
832 RAM_PARAM7_MDDR:        .word   0x02000780
833 ESDCTL_0x92220000:      .word   0x92220000
834 ESDCTL_0xA2220000:      .word   0xA2220000
835 ESDCTL_0xB2220000:      .word   0xB2220000
836 ESDCTL_0x82226080:      .word   0x82226080
837 ESDCTL_CONFIG:          .word   0x007FFC3F
838                         .word   0x007FFC3F
839 ESDCTL_DELAY5:          .word   0x00F49F00
840 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
841 CCM_CCTL_W:             .word   0x20034000      // ARM clk = 400, AHB clk = 133
842 MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
843 MPCTL_PARAM_532_W:      .word   MPCTL_PARAM_532
844 UPCTL_PARAM_W:          .word   UPCTL_PARAM_300
845 CCM_CGR0_W:             .word   0x1FFFFFFF
846 CCM_CGR1_W:             .word   0xFFFFFFFF
847 CCM_CGR2_W:             .word   0x000FDFFF
848 MXCBOOT_FLAG_ADDR_W:    .word   MXCBOOT_FLAG_REG
849 MXCFIS_FLAG_ADDR_W:     .word   MXCFIS_FLAG_REG
850 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
851 CONST_0x0FFF:           .word   0x0FFF
852 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
853 WEIM_CTRL_CS5_W:        .word   WEIM_CTRL_CS5
854 WEIM_CTRL_CS0_W:        .word   WEIM_CTRL_CS0
855 CS0_CSCRU_0x0000CC03:   .word   0x0000DCF6
856 CS0_CSCRL_0xA0330D01:   .word   0x444A4541
857 CS0_CSCRA_0x00220800:   .word   0x44443302
858 CS5_CSCRU_0x0000D843:   .word   0x0000D843
859 CS5_CSCRL_0x22252521:   .word   0x22252521
860 CS5_CSCRA_0x22220A00:   .word   0x22220A00
861 /*---------------------------------------------------------------------------*/
862 /* end of hal_platform_setup.h                                               */
863 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */