]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx35/3stack/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx35 / 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
55 //#define BOOT_FROM_MMC
56
57 #if defined(BOOT_FROM_MMC)
58 #define PLATFORM_PREAMBLE setup_flash_header
59 //#define MEMORY_MDDR_ENABLE
60 #endif
61
62 #define CYGHWR_HAL_ARM_HAS_MMU
63
64 #ifdef CYG_HAL_STARTUP_ROMRAM
65 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
66 #endif
67
68 #define CYGHWR_HAL_ROM_VADDR    0x0
69
70 #if 0
71 #define UNALIGNED_ACCESS_ENABLE
72 #define SET_T_BIT_DISABLE
73 #define LOW_INT_LATENCY_ENABLE
74 #define BRANCH_PREDICTION_ENABLE
75 #endif
76
77 #define UNALIGNED_ACCESS_ENABLE
78 #define LOW_INT_LATENCY_ENABLE
79 #define BRANCH_PREDICTION_ENABLE
80
81 //#define TURN_OFF_IMPRECISE_ABORT
82
83 // This macro represents the initial startup code for the platform
84 // r11 is reserved to contain chip rev info in this file
85     .macro  _platform_setup1
86 FSL_BOARD_SETUP_START:
87 /*
88  *       ARM1136 init
89  *       - invalidate I/D cache/TLB and drain write buffer;
90  *       - invalidate L2 cache
91  *       - unaligned access
92  *       - branch predictions
93  */
94 #ifdef TURN_OFF_IMPRECISE_ABORT
95     mrs r0, cpsr
96     bic r0, r0, #0x100
97     msr cpsr, r0
98 #endif
99
100     mrc 15, 0, r1, c1, c0, 0
101     bic r1, r1, #(0x3<<21)
102     bic r1, r1, #(0x3<<11)
103     bic r1, r1, #0x5
104
105 #ifndef BRANCH_PREDICTION_ENABLE
106     mrc 15, 0, r0, c1, c0, 1
107     bic r0, r0, #7
108     mcr 15, 0, r0, c1, c0, 1
109 #else
110     mrc 15, 0, r0, c1, c0, 1
111     orr r0, r0, #7
112     mcr 15, 0, r0, c1, c0, 1
113     orr r1, r1, #(1<<11)
114 #endif
115
116 #ifdef UNALIGNED_ACCESS_ENABLE
117     orr r1, r1, #(1<<22)
118 #endif
119
120 #ifdef LOW_INT_LATENCY_ENABLE
121     orr r1, r1, #(1<<21)
122 #endif
123     mcr 15, 0, r1, c1, c0, 0
124
125 #ifdef BRANCH_PREDICTION_ENABLE
126     mov r0, #0
127     mcr 15, 0, r0, c15, c2, 4
128 #endif
129
130     mov r0, #0
131     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
132     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
133     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
134
135     /* Also setup the Peripheral Port Remap register inside the core */
136     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
137     mcr p15, 0, r0, c15, c2, 4
138
139     /*** L2 Cache setup/invalidation/disable ***/
140     /* Disable L2 cache first */
141     mov r0, #L2CC_BASE_ADDR
142     ldr r2, [r0, #L2_CACHE_CTL_REG]
143     bic r2, r2, #0x1
144     str r2, [r0, #L2_CACHE_CTL_REG]
145     /*
146      * Configure L2 Cache:
147      * - 128k size(16k way)
148      * - 8-way associativity
149      * - 0 ws TAG/VALID/DIRTY
150      * - 4 ws DATA R/W
151      */
152     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
153     and r1, r1, #0xFE000000
154     ldr r2, L2CACHE_PARAM
155     orr r1, r1, r2
156     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
157     ldr r1, ROM_VER_ADDR_W
158     ldr r2, [r1]
159     cmp r2, #0x1
160     /* Workaournd for DDR issue:WT*/
161     ldreq r1, [r0, #L2_CACHE_DBG_CTL_REG]
162     orreq r1, r1, #2
163     streq r1, [r0, #L2_CACHE_DBG_CTL_REG]
164
165     /* Invalidate L2 */
166     mov r1, #0x000000FF
167     str r1, [r0, #L2_CACHE_INV_WAY_REG]
168 L2_loop:
169     /* Poll Invalidate By Way register */
170     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
171     cmp r2, #0
172     bne L2_loop
173     /*** End of L2 operations ***/
174
175 #if defined(BOOT_FROM_MMC)
176     mov r0, #MMC_FLASH_BOOT
177     ldr r1, AVIC_VECTOR0_ADDR_W
178     str r0, [r1] // if MMC is selected, set MXCFIS_FLAG_REG
179 #else
180     mov r0, #SDRAM_NON_FLASH_BOOT
181     ldr r1, AVIC_VECTOR0_ADDR_W
182     str r0, [r1] // for checking boot source from nand or sdram
183 #endif
184 /*
185  * End of ARM1136 init
186  */
187 init_spba_start:
188     init_spba
189 init_aips_start:
190     init_aips
191 init_max_start:
192     init_max
193 init_m3if_start:
194     init_m3if
195
196 /* TODO::
197  * Use default setting is more stable then the settinig from IC team for EINCE
198  */
199     /*init_iomuxc */
200 #ifndef BOOT_FROM_MMC
201     /* If SDRAM has been setup, bypass clock/WEIM setup */
202     cmp pc, #SDRAM_BASE_ADDR
203     blo init_clock_start
204     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
205     blo HWInitialise_skip_SDRAM_setup
206
207     mov r0, #NOR_FLASH_BOOT
208     ldr r1, AVIC_VECTOR0_ADDR_W
209     str r0, [r1]
210 #endif
211 init_clock_start:
212     init_clock
213 #ifndef BOOT_FROM_MMC
214 init_cs5_start:
215     init_cs5
216
217 init_sdram_start:
218     /* Assuming DDR memory first */
219     setup_sdram
220 #endif
221 HWInitialise_skip_SDRAM_setup:
222
223     mov r0, #NFC_BASE
224     add r2, r0, #0x1000      // 4K window
225     cmp pc, r0
226     blo Normal_Boot_Continue
227     cmp pc, r2
228     bhi Normal_Boot_Continue
229 NAND_Boot_Start:
230     /* Copy image from flash to SDRAM first */
231     ldr r1, MXC_REDBOOT_ROM_START
232
233 1:  ldmia r0!, {r3-r10}
234     stmia r1!, {r3-r10}
235     cmp r0, r2
236     blo 1b
237     /* Jump to SDRAM */
238     ldr r1, CONST_0x0FFF
239     and r0, pc, r1     /* offset of pc */
240     ldr r1, MXC_REDBOOT_ROM_START
241     add r1, r1, #0x10
242     add pc, r0, r1
243     nop
244     nop
245     nop
246     nop
247 NAND_Copy_Main:
248     mov r0, #NAND_FLASH_BOOT
249     ldr r1, AVIC_VECTOR0_ADDR_W
250     str r0, [r1]
251     mov r0, #MXCFIS_NAND
252     ldr r1, AVIC_VECTOR1_ADDR_W
253     str r0, [r1]
254
255     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
256     add r12, r0, #0x1E00  //r12: NFC register base. Doesn't change
257     ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
258     orr r3, r3, #0x1
259
260     /* Setting NFC */
261     ldr r7, CCM_BASE_ADDR_W
262     ldr r1, [r7, #CLKCTL_RCSR]
263     /*BUS WIDTH setting*/
264     tst r1, #0x20000000
265     orrne r1, r1, #0x4000
266     biceq r1, r1, #0x4000
267
268     /*4K PAGE*/
269     tst r1, #0x10000000
270     orrne r1, r1, #0x200
271     bne  1f
272     /*2K PAGE*/
273     bic r1, r1, #0x200
274     tst r1, #0x08000000
275     orrne r1, r1, #0x100 /*2KB page size*/
276     biceq r1, r1, #0x100 /*512B page size*/
277     movne r2, #32 /*64 bytes*/
278     moveq r2, #8  /*16 bytes*/
279     b NAND_setup
280 1:
281     tst r1, #0x08000000
282     bicne r3, r3, #1   /*Enable 8bit ECC mode*/
283     movne r2, #109 /*218 bytes*/
284     moveq r2, #64  /*128 bytes*/
285 NAND_setup:
286     str r1, [r7, #CLKCTL_RCSR]
287     strh r2, [r12, #ECC_RSLT_SPARE_AREA_REG_OFF]
288     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
289
290     //unlock internal buffer
291     mov r3, #0x2
292     strh r3, [r12, #NFC_CONFIGURATION_REG_OFF]
293     //unlock nand device
294     mov r3, #0
295     strh r3, [r12, #UNLOCK_START_BLK_ADD_REG_OFF]
296     sub r3, r3, #1
297     strh r3, [r12, #UNLOCK_END_BLK_ADD_REG_OFF]
298     mov r3, #4
299     strh r3, [r12, #NF_WR_PROT_REG_OFF]
300
301     /* r0: NFC base address. RAM buffer base address. [constantly]
302      * r1: starting flash address to be copied. [constantly]
303      * r2: page size. [Doesn't change]
304      * r3: used as argument.
305      * r11: starting SDRAM address for copying. [Updated constantly].
306      * r12: NFC register base address. [constantly].
307      * r13: end of SDRAM address for copying. [Doesn't change].
308      */
309
310     mov r1, #0x1000
311     ldr r3, [r7, #CLKCTL_RCSR]
312     tst r3, #0x200
313     movne r2, #0x1000
314     bne 1f
315     tst r3, #0x100
316     mov r1, #0x800  /*Strang Why is not 4K offset*/
317     movne r2, #0x800
318     moveq r2, #0x200
319 1: /*Update the indicator of copy area */
320     ldr r11, MXC_REDBOOT_ROM_START
321     add r13, r11, #REDBOOT_IMAGE_SIZE
322     add r11, r11, r1
323
324 Nfc_Read_Page:
325     mov r3, #0x0
326     nfc_cmd_input
327
328     cmp r2, #0x800
329     bhi nfc_addr_ops_4kb
330     beq nfc_addr_ops_2kb
331
332     mov r3, r1
333     do_addr_input       //1st addr cycle
334     mov r3, r1, lsr #9
335     do_addr_input       //2nd addr cycle
336     mov r3, r1, lsr #17
337     do_addr_input       //3rd addr cycle
338     mov r3, r1, lsr #25
339     do_addr_input       //4th addr cycle
340     b end_of_nfc_addr_ops
341
342 nfc_addr_ops_2kb:
343     mov r3, #0
344     do_addr_input       //1st addr cycle
345     mov r3, #0
346     do_addr_input       //2nd addr cycle
347     mov r3, r1, lsr #11
348     do_addr_input       //3rd addr cycle
349     mov r3, r1, lsr #19
350     do_addr_input       //4th addr cycle
351     mov r3, r1, lsr #27
352     do_addr_input       //5th addr cycle
353
354     mov r3, #0x30
355     nfc_cmd_input
356     b end_of_nfc_addr_ops
357
358 nfc_addr_ops_4kb:
359     mov r3, #0
360     do_addr_input       //1st addr cycle
361     mov r3, #0
362     do_addr_input       //2nd addr cycle
363     mov r3, r1, lsr #12
364     do_addr_input       //3rd addr cycle
365     mov r3, r1, lsr #20
366     do_addr_input       //4th addr cycle
367     mov r3, r1, lsr #27
368     do_addr_input       //5th addr cycle
369
370     mov r3, #0x30
371     nfc_cmd_input
372
373 end_of_nfc_addr_ops:
374     mov r8, #0
375     bl nfc_data_output
376     bl do_wait_op_done
377     // Check if x16/2kb page
378     cmp r2, #0x800
379     bhi nfc_addr_data_output_done_4k
380     beq nfc_addr_data_output_done_2k
381     beq nfc_addr_data_output_done_512
382
383     // check for bad block
384 //    mov r3, r1, lsl #(32-17)    // get rid of block number
385 //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
386     b nfc_addr_data_output_done
387
388 nfc_addr_data_output_done_4k:
389 //TODO
390     b nfc_addr_data_output_done
391
392 nfc_addr_data_output_done_2k:
393 // end of 4th
394     // check for bad block
395 //TODO    mov r3, r1, lsl #(32-17)    // get rid of block number
396 //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
397     b nfc_addr_data_output_done
398
399 nfc_addr_data_output_done_512:
400     // check for bad block
401 // TODO   mov r3, r1, lsl #(32-5-9)    // get rid of block number
402 // TODO   cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
403
404 nfc_addr_data_output_done:
405 #if 0
406     bhi Copy_Good_Blk
407     add r4, r0, #0x1000  //r3 -> spare area buf 0
408     ldrh r4, [r4, #0x4]
409     and r4, r4, #0xFF00
410     cmp r4, #0xFF00
411     beq Copy_Good_Blk
412     // really sucks. Bad block!!!!
413     cmp r3, #0x0
414     beq Skip_bad_block
415     // even suckier since we already read the first page!
416     // Check if x16/2kb page
417     cmp r2, #0x800
418     // for 4k page
419     subhi r11, r11, #0x1000  //rewind 1 page for the sdram pointer
420     subhi r1, r1, #0x1000    //rewind 1 page for the flash pointer
421     // for 2k page
422     subeq r11, r11, #0x800  //rewind 1 page for the sdram pointer
423     subeq r1, r1, #0x800    //rewind 1 page for the flash pointer
424     // for 512 page
425     sublo r11, r11, #512  //rewind 1 page for the sdram pointer
426     sublo r1, r1, #512    //rewind 1 page for the flash pointer
427 Skip_bad_block:
428     // Check if x16/2kb page
429     ldr r7, CCM_BASE_ADDR_W
430     ldr r7, [r7, #CLKCTL_RCSR]
431     tst r7, #0x200
432     addne r1, r1, #(128*4096)
433     bne Skip_bad_block_done
434     tst r7, #0x100
435     addeq r1, r1, #(32*512)
436     addne r1, r1, #(64*2048)
437 Skip_bad_block_done:
438     b Nfc_Read_Page
439 #endif
440 Copy_Good_Blk:
441     //copying page
442     add r2, r2, #NFC_BASE
443 1:  ldmia r0!, {r3-r10}
444     stmia r11!, {r3-r10}
445     cmp r0, r2
446     blo 1b
447     sub r2, r2, #NFC_BASE
448
449     cmp r11, r13
450     bge NAND_Copy_Main_done
451     // Check if x16/2kb page
452     add r1, r1, r2
453     mov r0, #NFC_BASE
454     b Nfc_Read_Page
455
456 NAND_Copy_Main_done:
457
458 Normal_Boot_Continue:
459
460 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
461     /* Copy image from flash to SDRAM first */
462     ldr r0, =0xFFFFF000
463     and r0, r0, pc
464     ldr r1, MXC_REDBOOT_ROM_START
465     cmp r0, r1
466     beq HWInitialise_skip_SDRAM_copy
467
468     add r2, r0, #REDBOOT_IMAGE_SIZE
469
470 1:  ldmia r0!, {r3-r10}
471     stmia r1!, {r3-r10}
472     cmp r0, r2
473     ble 1b
474     /* Jump to SDRAM */
475     ldr r1, =0xFFFF
476     and r0, pc, r1         /* offset of pc */
477     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
478     add pc, r0, r1
479     nop
480     nop
481     nop
482     nop
483 #endif /* CYG_HAL_STARTUP_ROMRAM */
484
485 HWInitialise_skip_SDRAM_copy:
486    init_cs0
487
488 /*
489  * Note:
490  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
491  */
492
493 STACK_Setup:
494     // Set up a stack [for calling C code]
495     ldr r1, =__startup_stack
496     ldr r2, =RAM_BANK0_BASE
497     orr sp, r1, r2
498
499     // Create MMU tables
500     bl hal_mmu_init
501
502     // Enable MMU
503     ldr r2, =10f
504     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
505     orr r1, r1, #7                          // enable MMU bit
506     orr r1, r1, #0x800                      // enable z bit
507     mcr MMU_CP, 0, r1, MMU_Control, c0
508     mov pc,r2    /* Change address spaces */
509     nop
510     nop
511     nop
512 10:
513
514     // Save shadow copy of BCR, also hardware configuration
515     ldr r1, =_board_BCR
516     str r2, [r1]
517     ldr r1, =_board_CFG
518     str r9, [r1]                // Saved far above...
519
520     .endm                       // _platform_setup1
521
522 do_wait_op_done:
523     1:
524         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
525         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
526         beq 1b
527     bx lr     // do_wait_op_done
528
529 nfc_data_output:
530     ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
531     orr r3, r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
532     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
533
534     strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
535
536     mov r3, #FDO_PAGE_SPARE_VAL
537     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
538     bx lr
539
540 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
541 #define PLATFORM_SETUP1
542 #endif
543
544     /* Do nothing */
545     .macro  init_spba
546     .endm  /* init_spba */
547
548     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
549     .macro init_aips
550         /*
551          * Set all MPROTx to be non-bufferable, trusted for R/W,
552          * not forced to user-mode.
553          */
554         ldr r0, AIPS1_CTRL_BASE_ADDR_W
555         ldr r1, AIPS1_PARAM_W
556         str r1, [r0, #0x00]
557         str r1, [r0, #0x04]
558         ldr r0, AIPS2_CTRL_BASE_ADDR_W
559         str r1, [r0, #0x00]
560         str r1, [r0, #0x04]
561
562         /*
563          * Clear the on and off peripheral modules Supervisor Protect bit
564          * for SDMA to access them. Did not change the AIPS control registers
565          * (offset 0x20) access type
566          */
567         ldr r0, AIPS1_CTRL_BASE_ADDR_W
568         ldr r1, =0x0
569         str r1, [r0, #0x40]
570         str r1, [r0, #0x44]
571         str r1, [r0, #0x48]
572         str r1, [r0, #0x4C]
573         ldr r1, [r0, #0x50]
574         and r1, r1, #0x00FFFFFF
575         str r1, [r0, #0x50]
576
577         ldr r0, AIPS2_CTRL_BASE_ADDR_W
578         ldr r1, =0x0
579         str r1, [r0, #0x40]
580         str r1, [r0, #0x44]
581         str r1, [r0, #0x48]
582         str r1, [r0, #0x4C]
583         ldr r1, [r0, #0x50]
584         and r1, r1, #0x00FFFFFF
585         str r1, [r0, #0x50]
586     .endm /* init_aips */
587
588     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
589     .macro init_max
590         ldr r0, MAX_BASE_ADDR_W
591         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
592         ldr r1, MAX_PARAM1
593         str r1, [r0, #0x000]        /* for S0 */
594         str r1, [r0, #0x100]        /* for S1 */
595         str r1, [r0, #0x200]        /* for S2 */
596         str r1, [r0, #0x300]        /* for S3 */
597         str r1, [r0, #0x400]        /* for S4 */
598         /* SGPCR - always park on last master */
599         ldr r1, =0x10
600         str r1, [r0, #0x010]        /* for S0 */
601         str r1, [r0, #0x110]        /* for S1 */
602         str r1, [r0, #0x210]        /* for S2 */
603         str r1, [r0, #0x310]        /* for S3 */
604         str r1, [r0, #0x410]        /* for S4 */
605         /* MGPCR - restore default values */
606         ldr r1, =0x0
607         str r1, [r0, #0x800]        /* for M0 */
608         str r1, [r0, #0x900]        /* for M1 */
609         str r1, [r0, #0xA00]        /* for M2 */
610         str r1, [r0, #0xB00]        /* for M3 */
611         str r1, [r0, #0xC00]        /* for M4 */
612         str r1, [r0, #0xD00]        /* for M5 */
613     .endm /* init_max */
614
615     /* Clock setup */
616     .macro    init_clock
617         ldr r0, CCM_BASE_ADDR_W
618
619         /* default CLKO to 1/32 of the ARM core*/
620         ldr r1, [r0, #CLKCTL_COSR]
621         bic r1, r1, #0x00000FF00
622         bic r1, r1, #0x0000000FF
623         mov r2, #0x00006C00
624         add r2, r2, #0x67
625         orr r1, r1, r2
626         str r1, [r0, #CLKCTL_COSR]
627
628         ldr r2, CCM_CCMR_W
629         str r2, [r0, #CLKCTL_CCMR]
630
631         /*check clock path*/
632         ldr r3, ROM_VER_ADDR_W
633         ldr r4, [r3]
634         cmp r4, #0x1
635         ldreq r2, [r0, #CLKCTL_PDR0]
636         movne r2, #0x1
637         tst r2, #0x1
638         ldrne r3, MPCTL_PARAM_532_W  /* consumer path*/
639         ldreq r3, MPCTL_PARAM_399_W  /* auto path*/
640
641         /*Set MPLL , arm clock and ahb clock*/
642         str r3, [r0, #CLKCTL_MPCTL]
643
644         ldr r1, PPCTL_PARAM_W
645         str r1, [r0, #CLKCTL_PPCTL]
646
647         cmp r4, #0x1
648         ldreq r1, [r0, #CLKCTL_PDR0]
649         orreq r1, r1, #0x800000
650         streq r1, [r0, #CLKCTL_PDR0]
651
652         ldr r1, CCM_PDR0_W
653         bicne r1, r1, #0x800000
654         str r1, [r0, #CLKCTL_PDR0]
655
656         ldr r1, [r0, #CLKCTL_CGR0]
657         orr r1, r1, #0x00300000
658         str r1, [r0, #CLKCTL_CGR0]
659
660         ldr r1, [r0, #CLKCTL_CGR1]
661         orr r1, r1, #0x00000C00
662         orr r1, r1, #0x00000003
663         str r1, [r0, #CLKCTL_CGR1]
664
665     .endm /* init_clock */
666
667     /* M3IF setup */
668     .macro init_m3if
669         /* Configure M3IF registers */
670         ldr r1, M3IF_BASE_W
671         /*
672         * M3IF Control Register (M3IFCTL)
673         * MRRP[0] = L2CC0 not on priority list (0 << 0)        = 0x00000000
674         * MRRP[1] = MAX1 not on priority list (0 << 0)        = 0x00000000
675         * MRRP[2] = L2CC1 not on priority list (0 << 0)        = 0x00000000
676         * MRRP[3] = USB  not on priority list (0 << 0)        = 0x00000000
677         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
678         * MRRP[5] = GPU not on priority list (0 << 0)       = 0x00000000
679         * MRRP[6] = IPU1 on priority list (1 << 6)             = 0x00000040
680         * MRRP[7] = IPU2 not on priority list (0 << 0)   = 0x00000000
681         *                                                       ------------
682         *                                                       0x00000040
683         */
684         ldr r0, =0x00000040
685         str r0, [r1]  /* M3IF control reg */
686     .endm /* init_m3if */
687
688     .macro init_cs0
689         ldr r0, WEIM_CTRL_CS0_W
690         ldr r1, CS0_CSCRU_0x0000CC03
691         str r1, [r0, #CSCRU]
692         ldr r1, CS0_CSCRL_0xA0330D01
693         str r1, [r0, #CSCRL]
694         ldr r1, CS0_CSCRA_0x00220800
695         str r1, [r0, #CSCRA]
696     .endm
697
698      /* CPLD on CS5 setup */
699     .macro init_cs5
700         ldr r0, WEIM_CTRL_CS5_W
701         ldr r1, CS5_CSCRU_0x0000D843
702         str r1, [r0, #CSCRU]
703         ldr r1, CS5_CSCRL_0x22252521
704         str r1, [r0, #CSCRL]
705         ldr r1, CS5_CSCRA_0x22220A00
706         str r1, [r0, #CSCRA]
707     .endm /* init_cs5 */
708
709     .macro setup_sdram
710         ldr r0, ESDCTL_BASE_W
711         mov r3, #0x2000
712         str r3, [r0, #0x0]
713         ldr r2, ROM_VER_ADDR_W
714         ldr r4, [r2]
715         cmp r4, #0x1
716         streq r3, [r0, #0x8]
717
718         mov r12, #0x00
719         mov r2, #0x00
720         mov r1, #RAM_BANK0_BASE
721         bl setup_sdram_bank
722         cmp r3, #0x0
723         orreq r12, r12, #1
724         eorne r2, r2, #0x1
725         blne setup_sdram_bank
726 #if 0
727         /* CSD1 */
728         mov r1, #RAM_BANK1_BASE
729         bl setup_sdram_bank
730         cmp r3, #0x0
731         beq 1b
732         eorne r2, r2, #0x1
733         blne setup_sdram_bank
734         orr r12, r12, #1
735 1:
736 #endif
737         cmp r12, #0
738         movne r3, #L2CC_BASE_ADDR
739         ldrne r4, [r3, #L2_CACHE_AUX_CTL_REG]
740         orrne r4, r4, #0x1000
741         strne r4, [r3, #L2_CACHE_AUX_CTL_REG]
742
743         ldr r3, ESDCTL_DELAY5
744         str r3, [r0, #0x30]
745     .endm
746
747     .macro nfc_cmd_input
748         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
749         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
750         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
751         bl do_wait_op_done
752     .endm   // nfc_cmd_input
753
754     .macro do_addr_input
755         and r3, r3, #0xFF
756         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
757         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
758         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
759         bl do_wait_op_done
760     .endm   // do_addr_input
761
762     /* To support 133MHz DDR */
763     .macro  init_iomuxc
764         mov r0, #0x2
765         ldr r1, IOMUXC_BASE_ADDR_W
766         add r1, r1, #0x368
767         add r2, r1, #0x4C8 - 0x368
768 1:      str r0, [r1], #4
769         cmp r1, r2
770         ble 1b
771     .endm /* init_iomuxc */
772
773 /*
774  * r0: control base, r1: ram bank base
775  * r2: ddr type(0:DDR2, 1:MDDR) r3, r4: working
776  */
777 setup_sdram_bank:
778         mov r3, #0xE /*0xA + 0x4*/
779         tst r2, #0x1
780         orreq r3, r3, #0x300 /*DDR2*/
781         str r3, [r0, #0x10]
782         bic r3, r3, #0x00A
783         str r3, [r0, #0x10]
784         beq 2f
785
786         mov r3, #0x20000
787 1:      subs r3, r3, #1
788         bne 1b
789
790 2:      adr r4, ESDCTL_CONFIG
791         tst r2, #0x1
792         ldreq r3, [r4, #0x0]
793         ldrne r3, [r4, #0x4]
794         cmp r1, #RAM_BANK1_BASE
795         strlo r3, [r0, #0x4]
796         strhs r3, [r0, #0xC]
797
798         ldr r3, ESDCTL_0x92220000
799         strlo r3, [r0, #0x0]
800         strhs r3, [r0, #0x8]
801         mov r3, #0xDA
802         ldr r4, RAM_PARAM1_MDDR
803         strb r3, [r1, r4]
804
805         tst r2, #0x1
806         bne skip_set_mode
807
808         cmp r1, #RAM_BANK1_BASE
809         ldr r3, ESDCTL_0xB2220000
810         strlo r3, [r0, #0x0]
811         strhs r3, [r0, #0x8]
812         mov r3, #0xDA
813         ldr r4, RAM_PARAM4_MDDR
814         strb r3, [r1, r4]
815         ldr r4, RAM_PARAM5_MDDR
816         strb r3, [r1, r4]
817         ldr r4, RAM_PARAM3_MDDR
818         strb r3, [r1, r4]
819         ldr r4, RAM_PARAM2_MDDR
820         strb r3, [r1, r4]
821
822         ldr r3, ESDCTL_0x92220000
823         strlo r3, [r0, #0x0]
824         strhs r3, [r0, #0x8]
825         mov r3, #0xDA
826         ldr r4, RAM_PARAM1_MDDR
827         strb r3, [r1, r4]
828
829 skip_set_mode:
830         cmp r1, #RAM_BANK1_BASE
831         ldr r3, ESDCTL_0xA2220000
832         strlo r3, [r0, #0x0]
833         strhs r3, [r0, #0x8]
834         mov r3, #0xDA
835         strb r3, [r1]
836         strb r3, [r1]
837
838         ldr r3, ESDCTL_0xB2220000
839         strlo r3, [r0, #0x0]
840         strhs r3, [r0, #0x8]
841         adr r4, RAM_PARAM6_MDDR
842         tst r2, #0x1
843         ldreq r4, [r4, #0x0]
844         ldrne r4, [r4, #0x4]
845         mov r3, #0xDA
846         strb r3, [r1, r4]
847         ldreq r4, RAM_PARAM7_MDDR
848         streqb r3, [r1, r4]
849         adr r4, RAM_PARAM3_MDDR
850         ldreq r4, [r4, #0x0]
851         ldrne r4, [r4, #0x4]
852         strb r3, [r1, r4]
853
854         cmp r1, #RAM_BANK1_BASE
855         ldr r3, ESDCTL_0x82226080
856         strlo r3, [r0, #0x0]
857         strhs r3, [r0, #0x8]
858
859         tst r2, #0x1
860         moveq r4, #0x20000
861         movne r4, #0x200
862 1:      subs r4, r4, #1
863         bne 1b
864
865         str r3, [r1, #0x100]
866         ldr r4, [r1, #0x100]
867         cmp r3, r4
868         movne r3, #1
869         moveq r3, #0
870
871         mov pc, lr
872
873 #define PLATFORM_VECTORS         _platform_vectors
874     .macro  _platform_vectors
875         .globl  _board_BCR, _board_CFG
876 _board_BCR:   .long   0       // Board Control register shadow
877 _board_CFG:   .long   0       // Board Configuration (read at RESET)
878     .endm
879
880 //Internal Boot, from MMC/SD cards
881 #ifdef MXCFLASH_SELECT_MMC
882 #define DCDGEN(i,type, addr, data) \
883 dcd_##i:                         ;\
884     .long type                   ;\
885     .long addr                   ;\
886     .long data
887
888 #define FHEADER_OFFSET 0x400
889 #if 0
890 #define GEN_FHEADERADDR(x) ((x) + FHEADER_OFFSET)
891 #else
892 #define GEN_FHEADERADDR(x) (x)
893 #endif
894
895      .macro setup_flash_header
896      b reset_vector
897      //   .org 0x400
898 #if defined(FHEADER_OFFSET)
899      .org FHEADER_OFFSET
900 #endif
901 app_code_jump_v:    .long GEN_FHEADERADDR(reset_vector)
902 app_code_barker:    .long 0xB1
903 app_code_csf:       .long 0
904 hwcfg_ptr_ptr:      .long GEN_FHEADERADDR(hwcfg_ptr)
905 super_root_key:     .long 0
906 hwcfg_ptr:          .long GEN_FHEADERADDR(dcd_data)
907 app_dest_ptr:       .long SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
908 dcd_data:           .long 0xB17219E9
909 #ifdef MEMORY_MDDR_ENABLE
910                     .long 228
911 //real dcd data
912
913 //arm clock is 266Mhz and ahb clock is 133Mhz
914 //DCDGEN(1, 4, 0x53F80004, 0x00821000)
915
916 //WEIM config-CS5 init
917 DCDGEN(1, 4, 0xB8002054, 0x444a4541)
918 DCDGEN(1_1, 4, 0xB8002050, 0x0000dcf6)
919 DCDGEN(1_2, 4, 0xB8002058, 0x44443302)
920 //MDDR init
921 //enable mDDR
922 DCDGEN(2, 4, 0xB8001010, 0x00000004)
923 //reset delay time
924 DCDGEN(3, 4, 0xB8001010, 0x0000000C)
925 DCDGEN(4, 4, 0xB800100C, 0x007ffc3f)
926 DCDGEN(5, 4, 0xB800100C, 0x007ffc3f)
927 DCDGEN(6, 4, 0xB8001004, 0x007ffc3f)
928 DCDGEN(7, 4, 0xB8001000, 0x92220000)
929 DCDGEN(8, 1, 0x80000400, 0xda)
930 DCDGEN(9, 4, 0xB8001000, 0xA2220000)
931 DCDGEN(10, 4, 0x80000000, 0x87654321)
932 DCDGEN(11, 4, 0x80000000, 0x87654321)
933 DCDGEN(12, 4, 0xB8001000, 0xB2220000)
934 DCDGEN(13, 1, 0x80000033, 0xda)
935 DCDGEN(14, 1, 0x82000000, 0xda)
936 DCDGEN(15, 4, 0xB8001000, 0x82226080)
937 DCDGEN(16, 4, 0xB8001010, 0x00000004)
938 DCDGEN(17, 4, 0xB8001008, 0x00002000)
939
940 //add MMC FLASH BOOT mode in MXCFIS_FLAG_REG
941 //DCDGEN(18, 4, 0x68000100, 0x40000000)
942
943 #else
944                     .long 240
945
946 //arm clock is 266Mhz and ahb clock is 133Mhz
947 //DCDGEN(1, 4, 0x53F80004, 0x00821000)
948
949 //WEIM config-CS5 init
950 DCDGEN(1, 4, 0xB8002050, 0x0000d843)
951 DCDGEN(1_1, 4, 0xB8002054, 0x22252521)
952 DCDGEN(1_2, 4, 0xB8002058, 0x22220a00)
953
954 //DDR2 init
955 DCDGEN(2, 4, 0xB8001010, 0x00000304)
956 DCDGEN(3, 4, 0xB8001010, 0x0000030C)
957 DCDGEN(4, 4, 0xB8001004, 0x007ffc3f)
958 DCDGEN(5, 4, 0xB8001000, 0x92220000)
959 DCDGEN(6, 4, 0x80000400, 0x12345678)
960 DCDGEN(7, 4, 0xB8001000, 0xA2220000)
961 DCDGEN(8, 4, 0x80000000, 0x87654321)
962 DCDGEN(9, 4, 0x80000000, 0x87654321)
963 DCDGEN(10, 4, 0xB8001000, 0xB2220000)
964 DCDGEN(11, 1, 0x80000233, 0xda)
965 DCDGEN(12, 1, 0x82000780, 0xda)
966 DCDGEN(13, 1, 0x82000400, 0xda)
967 DCDGEN(14, 4, 0xB8001000, 0x82226080)
968 DCDGEN(15, 4, 0xB8001004, 0x007ffc3f)
969 DCDGEN(16, 4, 0xB800100C, 0x007ffc3f)
970 DCDGEN(17, 4, 0xB8001010, 0x00000304)
971 DCDGEN(18, 4, 0xB8001008, 0x00002000)
972
973 //add MMC FLASH BOOT mode in MXCFIS_FLAG_REG
974 //DCDGEN(17, 4, #MMC_FLASH_BOOT, #MXCBOOT_FLAG_REG)
975 //DCDGEN(19, 4, 0x68000100, 0x40000000)
976 #endif
977
978 //CARD_FLASH_CFG_PARMS_T---length
979 card_cfg:           .long REDBOOT_IMAGE_SIZE
980      .endm
981 #endif
982
983 ARM_PPMRR:              .word   0x40000015
984 L2CACHE_PARAM:          .word   0x00030024
985 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
986 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
987 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
988 AIPS1_PARAM_W:          .word   0x77777777
989 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
990 MAX_PARAM1:             .word   0x00302154
991 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
992 ESDCTL_BASE_W:          .word   ESDCTL_BASE
993 M3IF_BASE_W:            .word   M3IF_BASE
994 RAM_PARAM1_MDDR:        .word   0x00000400
995 RAM_PARAM2_MDDR:        .word   0x00000333
996 RAM_PARAM3_MDDR:        .word   0x02000400
997                         .word   0x02000000
998 RAM_PARAM4_MDDR:        .word   0x04000000
999 RAM_PARAM5_MDDR:        .word   0x06000000
1000 RAM_PARAM6_MDDR:        .word   0x00000233
1001                         .word   0x00000033
1002 RAM_PARAM7_MDDR:        .word   0x02000780
1003 ESDCTL_0x92220000:      .word   0x92220000
1004 ESDCTL_0xA2220000:      .word   0xA2220000
1005 ESDCTL_0xB2220000:      .word   0xB2220000
1006 ESDCTL_0x82226080:      .word   0x82226080
1007 ESDCTL_CONFIG:          .word   0x007FFC3F      //DDR2
1008                         .word   0x00295729      //MDDR
1009 ESDCTL_DELAY5:          .word   0x00F49F00
1010 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
1011 CCM_CCMR_W:             .word   0x003F4208
1012 CCM_PDR0_W:             .word   0x00801000
1013 MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
1014 MPCTL_PARAM_532_W:      .word   MPCTL_PARAM_532
1015 PPCTL_PARAM_W:          .word   PPCTL_PARAM_300
1016 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
1017 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
1018 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
1019 CONST_0x0FFF:           .word   0x0FFF
1020 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
1021 IPU_CTRL_BASE_ADDR_W:   .word   IPU_CTRL_BASE_ADDR
1022 WEIM_CTRL_CS5_W:    .word   WEIM_CTRL_CS5
1023 WEIM_CTRL_CS0_W:    .word   WEIM_CTRL_CS0
1024 CS0_CSCRU_0x0000CC03:   .word   0x0000DCF6
1025 CS0_CSCRL_0xA0330D01:   .word   0x444A4541
1026 CS0_CSCRA_0x00220800:   .word   0x44443302
1027 CS5_CSCRU_0x0000D843:   .word   0x0000D843
1028 CS5_CSCRL_0x22252521:   .word   0x22252521
1029 CS5_CSCRA_0x22220A00:   .word   0x22220A00
1030 ROM_VER_ADDR_W:         .word   ROM_BASE_ADDR + ROM_SI_REV_OFFSET
1031 /*---------------------------------------------------------------------------*/
1032 /* end of hal_platform_setup.h                                               */
1033 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */