]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx35/evb/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx35 / evb / 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
62 //#define SDRAM_FULL_PAGE_BIT     0x100
63 //#define SDRAM_FULL_PAGE_MODE    0x37
64 //#define SDRAM_BURST_MODE        0x33
65
66 #define CYGHWR_HAL_ROM_VADDR    0x0
67
68 #if 0
69 #define UNALIGNED_ACCESS_ENABLE
70 #define SET_T_BIT_DISABLE
71 #define LOW_INT_LATENCY_ENABLE
72 #define BRANCH_PREDICTION_ENABLE
73 #endif
74
75 #define UNALIGNED_ACCESS_ENABLE
76 #define LOW_INT_LATENCY_ENABLE
77 #define BRANCH_PREDICTION_ENABLE
78
79 //#define TURN_OFF_IMPRECISE_ABORT
80
81 // This macro represents the initial startup code for the platform
82 // r11 is reserved to contain chip rev info in this file
83     .macro  _platform_setup1
84 FSL_BOARD_SETUP_START:
85 /*
86  *       ARM1136 init
87  *       - invalidate I/D cache/TLB and drain write buffer;
88  *       - invalidate L2 cache
89  *       - unaligned access
90  *       - branch predictions
91  */
92 #ifdef TURN_OFF_IMPRECISE_ABORT
93     mrs r0, cpsr
94     bic r0, r0, #0x100
95     msr cpsr, r0
96 #endif
97
98     mrc 15, 0, r1, c1, c0, 0
99     bic r1, r1, #(0x3<<21)
100     bic r1, r1, #(0x3<<11)
101     bic r1, r1, #0x5
102
103 #ifndef BRANCH_PREDICTION_ENABLE
104     mrc 15, 0, r0, c1, c0, 1
105     bic r0, r0, #7
106     mcr 15, 0, r0, c1, c0, 1
107 #else
108     mrc 15, 0, r0, c1, c0, 1
109     orr r0, r0, #7
110     mcr 15, 0, r0, c1, c0, 1
111     orr r1, r1, #(1<<11)
112 #endif
113
114 #ifdef UNALIGNED_ACCESS_ENABLE
115     orr r1, r1, #(1<<22)
116 #endif
117
118 #ifdef LOW_INT_LATENCY_ENABLE
119     orr r1, r1, #(1<<21)
120 #endif
121     mcr 15, 0, r1, c1, c0, 0
122
123 #ifdef BRANCH_PREDICTION_ENABLE
124     mov r0, #0
125     mcr 15, 0, r0, c15, c2, 4
126 #endif
127
128     mov r0, #0
129     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
130     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
131     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
132
133     /* Also setup the Peripheral Port Remap register inside the core */
134     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
135     mcr p15, 0, r0, c15, c2, 4
136
137     /* Reload data from spare area to 0x1000 of main area if booting from NAND */
138     mov r0, #NFC_BASE
139     add r1, r0, #0x1000
140     cmp pc, r0
141     blo 1f
142     cmp pc, r1
143     bhi 1f
144
145 #define MXC_NAND_BOOT_LOAD_AT_0x404
146 #ifdef MXC_NAND_BOOT_LOAD_AT_0x404
147     // Recover the word at 0x404 offset using the one stored in the spare area
148     ldr r2, [r0, #0x820]
149     str r2, [r1]
150 #endif
151
152 #ifdef NFC_2K_BI_SWAP
153     ldr r3, [r0, #0x7D0]    // load word at addr 464 of last 512 RAM buffer
154     and r3, r3, #0xFFFFFF00 // mask off the LSB
155     ldr r4, [r0, #0x834]    // load word at addr 4 of the 3rd spare area buffer
156     mov r4, r4, lsr #8      // shift it to get the byte at addr 5
157     and r4, r4, #0xFF       // throw away upper 3 bytes
158     add r3, r4, r3          // construct the word
159     str r3, [r0, #0x7D0]    // write back
160 #endif
161
162 1:
163     /*** L2 Cache setup/invalidation/disable ***/
164     /* Disable L2 cache first */
165     mov r0, #L2CC_BASE_ADDR
166     ldr r2, [r0, #L2_CACHE_CTL_REG]
167     bic r2, r2, #0x1
168     str r2, [r0, #L2_CACHE_CTL_REG]
169     /*
170      * Configure L2 Cache:
171      * - 128k size(16k way)
172      * - 8-way associativity
173      * - 0 ws TAG/VALID/DIRTY
174      * - 4 ws DATA R/W
175      */
176     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
177     and r1, r1, #0xFE000000
178     ldr r2, L2CACHE_PARAM
179     orr r1, r1, r2
180     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
181 /* Workaournd for DDR issue:WT*/
182     ldr r1, [r0, #L2_CACHE_DBG_CTL_REG]
183     orr r1, r1, #2
184     str r1, [r0, #L2_CACHE_DBG_CTL_REG]
185
186     /* Invalidate L2 */
187     mov r1, #0x000000FF
188     str r1, [r0, #L2_CACHE_INV_WAY_REG]
189 L2_loop:
190     /* Poll Invalidate By Way register */
191     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
192     cmp r2, #0
193     bne L2_loop
194     /*** End of L2 operations ***/
195
196     mov r0, #SDRAM_NON_FLASH_BOOT
197     ldr r1, AVIC_VECTOR0_ADDR_W
198     str r0, [r1] // for checking boot source from nand or sdram
199 /*
200  * End of ARM1136 init
201  */
202 init_spba_start:
203     init_spba
204 init_aips_start:
205     init_aips
206 init_max_start:
207     init_max
208 init_m3if_start:
209     init_m3if
210
211     init_iomuxc
212
213     /* If SDRAM has been setup, bypass clock/WEIM setup */
214     cmp pc, #SDRAM_BASE_ADDR
215     blo init_clock_start
216     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
217     blo HWInitialise_skip_SDRAM_setup
218
219     mov r0, #NOR_FLASH_BOOT
220     ldr r1, AVIC_VECTOR0_ADDR_W
221     str r0, [r1]
222
223 init_clock_start:
224     init_clock
225
226 init_cs4_start:
227     init_cs4
228     init_cs5
229
230     /* Based on chip rev, setup params for SDRAM controller */
231 init_sdram_start:
232
233     /* Assuming DDR memory first */
234     setup_sdram
235
236 HWInitialise_skip_SDRAM_setup:
237
238     mov r0, #NFC_BASE
239     add r2, r0, #0x1000      // 4K window
240     cmp pc, r0
241     blo Normal_Boot_Continue
242     cmp pc, r2
243     bhi Normal_Boot_Continue
244 NAND_Boot_Start:
245     /* Copy image from flash to SDRAM first */
246     ldr r1, MXC_REDBOOT_ROM_START
247
248 1:  ldmia r0!, {r3-r10}
249     stmia r1!, {r3-r10}
250     cmp r0, r2
251     blo 1b
252     /* Jump to SDRAM */
253     ldr r1, CONST_0x0FFF
254     and r0, pc, r1     /* offset of pc */
255     ldr r1, MXC_REDBOOT_ROM_START
256     add r1, r1, #0x10
257     add pc, r0, r1
258     nop
259     nop
260     nop
261     nop
262 NAND_Copy_Main:
263     /* Setting NFC */
264     ldr r7, CCM_BASE_ADDR_W
265     ldr r7, [r7, #CLKCTL_RCSR]
266     /*BUS WIDTH*/
267     tst r7, #0x20000000
268     orrne r7, r7, #0x4000
269     biceq r7, r7, #0x4000
270     /*4K PAGE*/
271     tst r7, #0x10000000
272     orrne r7, r7, #0x200
273     bne  1f
274     /*2K PAGE*/
275     bic r7, r7, #0x200
276     tst r7, #0x08000000
277     orrne r7, r7, #0x100
278     biceq r7, r7, #0x100
279 1:
280     mov r0, #NAND_FLASH_BOOT
281     ldr r1, AVIC_VECTOR0_ADDR_W
282     str r0, [r1]
283     mov r0, #MXCFIS_NAND
284     ldr r1, AVIC_VECTOR1_ADDR_W
285     str r0, [r1]
286
287     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
288     mov r1, #0x1000       //r1: starting flash addr to be copied. Updated constantly
289     add r2, r0, #0x1000   //r2: end of 3rd RAM buf. Doesn't change
290     ldr r7, CCM_BASE_ADDR_W
291     ldr r7, [r7, #CLKCTL_RCSR]
292     tst r7, #0x200
293     bne 1f
294     tst r7, #0x100
295     addne r2, r0, #0x800
296     addeq r2, r0, #0x200
297 1:
298     ldr r11, MXC_REDBOOT_ROM_START
299     add r12, r0, #0x1E00  //r12: NFC register base. Doesn't change
300     add r13, r11, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
301     add r11, r11, r1     //r11: starting SDRAM address for copying. Updated constantly
302
303     //unlock internal buffer
304     mov r3, #0x2
305     strh r3, [r12, #NFC_CONFIGURATION_REG_OFF]
306
307 Nfc_Read_Page:
308     mov r3, #0x0
309     nfc_cmd_input
310
311     // Check if x16/2kb page
312     ldr r7, CCM_BASE_ADDR_W
313     ldr r7, [r7, #CLKCTL_RCSR]
314     tst r7, #0x200
315     bne nfc_addr_ops_4kb
316     tst r7, #0x100
317
318     bne nfc_addr_ops_2kb
319     mov r3, r1
320     do_addr_input       //1st addr cycle
321     mov r3, r1, lsr #9
322     do_addr_input       //2nd addr cycle
323     mov r3, r1, lsr #17
324     do_addr_input       //3rd addr cycle
325     mov r3, r1, lsr #25
326     do_addr_input       //4th addr cycle
327     b end_of_nfc_addr_ops
328
329 nfc_addr_ops_2kb:
330     mov r3, #0
331     do_addr_input       //1st addr cycle
332     mov r3, #0
333     do_addr_input       //2nd addr cycle
334     mov r3, r1, lsr #11
335     do_addr_input       //3rd addr cycle
336     mov r3, r1, lsr #19
337     do_addr_input       //4th addr cycle
338     mov r3, r1, lsr #27
339     do_addr_input       //5th addr cycle
340
341     mov r3, #0x30
342     nfc_cmd_input
343     b end_of_nfc_addr_ops
344
345 nfc_addr_ops_4kb:
346     mov r3, #0
347     do_addr_input       //1st addr cycle
348     mov r3, #0
349     do_addr_input       //2nd addr cycle
350     mov r3, r1, lsr #12
351     do_addr_input       //3rd addr cycle
352     mov r3, r1, lsr #19
353     do_addr_input       //4th addr cycle
354     mov r3, r1, lsr #27
355     do_addr_input       //5th addr cycle
356
357     mov r3, #0x30
358     nfc_cmd_input
359
360 end_of_nfc_addr_ops:
361     mov r8, #0
362     bl nfc_data_output
363     bl do_wait_op_done
364     // Check if x16/2kb page
365     ldr r7, CCM_BASE_ADDR_W
366     ldr r7, [r7, #CLKCTL_RCSR]
367     tst r7, #0x300
368     beq nfc_addr_data_output_done_512
369 // For 4K page - 2nd 512
370     mov r8, #1
371     bl nfc_data_output
372     bl do_wait_op_done
373
374 // 3rd 512
375     mov r8, #2
376     bl nfc_data_output
377     bl do_wait_op_done
378
379 // 4th 512
380     mov r8, #3
381     bl nfc_data_output
382     bl do_wait_op_done
383
384     tst r7, #0x200
385     beq nfc_addr_data_output_done_2k
386
387     mov r8, #4
388     bl nfc_data_output
389     bl do_wait_op_done
390
391     mov r8, #5
392     bl nfc_data_output
393     bl do_wait_op_done
394
395     mov r8, #6
396     bl nfc_data_output
397     bl do_wait_op_done
398 #ifdef NFC_4K_BI_SWAP
399     ldr r3, [r0, #0x7D0]    // load word at addr 464 of last 512 RAM buffer
400     and r3, r3, #0xFFFFFF00 // mask off the LSB
401     ldr r4, [r0, #0x834]    // load word at addr 4 of the 3rd spare area buffer
402     mov r4, r4, lsr #8      // shift it to get the byte at addr 5
403     and r4, r4, #0xFF       // throw away upper 3 bytes
404     add r3, r4, r3          // construct the word
405     str r3, [r0, #0x7D0]    // write back
406 #endif
407     // check for bad block
408     mov r3, r1, lsl #(32-17)    // get rid of block number
409     cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
410     b nfc_addr_data_output_done
411
412 nfc_addr_data_output_done_2k:
413 // end of 4th
414 #ifdef NFC_2K_BI_SWAP
415     ldr r3, [r0, #0x7D0]    // load word at addr 464 of last 512 RAM buffer
416     and r3, r3, #0xFFFFFF00 // mask off the LSB
417     ldr r4, [r0, #0x834]    // load word at addr 4 of the 3rd spare area buffer
418     mov r4, r4, lsr #8      // shift it to get the byte at addr 5
419     and r4, r4, #0xFF       // throw away upper 3 bytes
420     add r3, r4, r3          // construct the word
421     str r3, [r0, #0x7D0]    // write back
422 #endif
423     // check for bad block
424     mov r3, r1, lsl #(32-17)    // get rid of block number
425     cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
426     b nfc_addr_data_output_done
427
428 nfc_addr_data_output_done_512:
429     // check for bad block
430     mov r3, r1, lsl #(32-5-9)    // get rid of block number
431     cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
432
433 nfc_addr_data_output_done:
434     bhi Copy_Good_Blk
435     add r4, r0, #0x1000  //r3 -> spare area buf 0
436     ldrh r4, [r4, #0x4]
437     and r4, r4, #0xFF00
438     cmp r4, #0xFF00
439     beq Copy_Good_Blk
440     // really sucks. Bad block!!!!
441     cmp r3, #0x0
442     beq Skip_bad_block
443     // even suckier since we already read the first page!
444     // Check if x16/2kb page
445     ldr r7, CCM_BASE_ADDR_W
446     ldr r7, [r7, #CLKCTL_RCSR]
447     tst r7, #0x200
448     // for 4k page
449     subne r11, r11, #0x1000  //rewind 1 page for the sdram pointer
450     subne r1, r1, #0x1000    //rewind 1 page for the flash pointer
451     bne Skip_bad_block
452     tst r7, #0x100
453     subeq r11, r11, #512  //rewind 1 page for the sdram pointer
454     subeq r1, r1, #512    //rewind 1 page for the flash pointer
455
456     // for 2k page
457     subne r11, r11, #0x800  //rewind 1 page for the sdram pointer
458     subne r1, r1, #0x800    //rewind 1 page for the flash pointer
459
460 Skip_bad_block:
461     // Check if x16/2kb page
462     ldr r7, CCM_BASE_ADDR_W
463     ldr r7, [r7, #CLKCTL_RCSR]
464     tst r7, #0x200
465     addne r1, r1, #(128*4096)
466     bne Skip_bad_block_done
467     tst r7, #0x100
468     addeq r1, r1, #(32*512)
469     addne r1, r1, #(64*2048)
470 Skip_bad_block_done:
471     b Nfc_Read_Page
472 Copy_Good_Blk:
473     //copying page
474 1:  ldmia r0!, {r3-r10}
475     stmia r11!, {r3-r10}
476     cmp r0, r2
477     blo 1b
478     cmp r11, r13
479     bge NAND_Copy_Main_done
480     // Check if x16/2kb page
481     ldr r7, CCM_BASE_ADDR_W
482     ldr r7, [r7, #CLKCTL_RCSR]
483     tst r7, #0x200
484     addne r1, r1, #0x1000
485     bne 1f
486     tst r7, #0x100
487     addne r1, r1, #0x800
488     addeq r1, r1, #0x200
489 1:
490     mov r0, #NFC_BASE
491     b Nfc_Read_Page
492
493 NAND_Copy_Main_done:
494
495 Normal_Boot_Continue:
496
497 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
498     /* Copy image from flash to SDRAM first */
499     ldr r0, =0xFFFFF000
500     and r0, r0, pc
501     ldr r1, MXC_REDBOOT_ROM_START
502     cmp r0, r1
503     beq HWInitialise_skip_SDRAM_copy
504
505     add r2, r0, #REDBOOT_IMAGE_SIZE
506
507 1:  ldmia r0!, {r3-r10}
508     stmia r1!, {r3-r10}
509     cmp r0, r2
510     ble 1b
511     /* Jump to SDRAM */
512     ldr r1, =0xFFFF
513     and r0, pc, r1         /* offset of pc */
514     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
515     add pc, r0, r1
516     nop
517     nop
518     nop
519     nop
520 #endif /* CYG_HAL_STARTUP_ROMRAM */
521
522 HWInitialise_skip_SDRAM_copy:
523    init_cs0
524
525 /*
526  * Note:
527  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
528  */
529
530 STACK_Setup:
531     // Set up a stack [for calling C code]
532     ldr r1, =__startup_stack
533     ldr r2, =SDRAM_BASE_ADDR
534     orr sp, r1, r2
535
536     // Create MMU tables
537     bl hal_mmu_init
538
539     // Enable MMU
540     ldr r2, =10f
541     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
542     orr r1, r1, #7                          // enable MMU bit
543     orr r1, r1, #0x800                      // enable z bit
544     mcr MMU_CP, 0, r1, MMU_Control, c0
545     mov pc,r2    /* Change address spaces */
546     nop
547     nop
548     nop
549 10:
550
551     // Save shadow copy of BCR, also hardware configuration
552     ldr r1, =_board_BCR
553     str r2, [r1]
554     ldr r1, =_board_CFG
555     str r9, [r1]                // Saved far above...
556
557     .endm                       // _platform_setup1
558
559 do_wait_op_done:
560     1:
561         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
562         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
563         beq 1b
564     bx lr     // do_wait_op_done
565
566 nfc_data_output:
567     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
568     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
569
570     // writew(buf_no, RAM_BUFFER_ADDRESS_REG);
571     strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
572     // writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
573     mov r3, #FDO_PAGE_SPARE_VAL
574     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
575     bx lr
576
577 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
578 #define PLATFORM_SETUP1
579 #endif
580
581     /* Do nothing */
582     .macro  init_spba
583     .endm  /* init_spba */
584
585     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
586     .macro init_aips
587         /*
588          * Set all MPROTx to be non-bufferable, trusted for R/W,
589          * not forced to user-mode.
590          */
591         ldr r0, AIPS1_CTRL_BASE_ADDR_W
592         ldr r1, AIPS1_PARAM_W
593         str r1, [r0, #0x00]
594         str r1, [r0, #0x04]
595         ldr r0, AIPS2_CTRL_BASE_ADDR_W
596         str r1, [r0, #0x00]
597         str r1, [r0, #0x04]
598
599         /*
600          * Clear the on and off peripheral modules Supervisor Protect bit
601          * for SDMA to access them. Did not change the AIPS control registers
602          * (offset 0x20) access type
603          */
604         ldr r0, AIPS1_CTRL_BASE_ADDR_W
605         ldr r1, =0x0
606         str r1, [r0, #0x40]
607         str r1, [r0, #0x44]
608         str r1, [r0, #0x48]
609         str r1, [r0, #0x4C]
610         ldr r1, [r0, #0x50]
611         and r1, r1, #0x00FFFFFF
612         str r1, [r0, #0x50]
613
614         ldr r0, AIPS2_CTRL_BASE_ADDR_W
615         ldr r1, =0x0
616         str r1, [r0, #0x40]
617         str r1, [r0, #0x44]
618         str r1, [r0, #0x48]
619         str r1, [r0, #0x4C]
620         ldr r1, [r0, #0x50]
621         and r1, r1, #0x00FFFFFF
622         str r1, [r0, #0x50]
623     .endm /* init_aips */
624
625     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
626     .macro init_max
627         ldr r0, MAX_BASE_ADDR_W
628         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
629         ldr r1, MAX_PARAM1
630         str r1, [r0, #0x000]        /* for S0 */
631         str r1, [r0, #0x100]        /* for S1 */
632         str r1, [r0, #0x200]        /* for S2 */
633         str r1, [r0, #0x300]        /* for S3 */
634         str r1, [r0, #0x400]        /* for S4 */
635         /* SGPCR - always park on last master */
636         ldr r1, =0x10
637         str r1, [r0, #0x010]        /* for S0 */
638         str r1, [r0, #0x110]        /* for S1 */
639         str r1, [r0, #0x210]        /* for S2 */
640         str r1, [r0, #0x310]        /* for S3 */
641         str r1, [r0, #0x410]        /* for S4 */
642         /* MGPCR - restore default values */
643         ldr r1, =0x0
644         str r1, [r0, #0x800]        /* for M0 */
645         str r1, [r0, #0x900]        /* for M1 */
646         str r1, [r0, #0xA00]        /* for M2 */
647         str r1, [r0, #0xB00]        /* for M3 */
648         str r1, [r0, #0xC00]        /* for M4 */
649         str r1, [r0, #0xD00]        /* for M5 */
650     .endm /* init_max */
651
652     /* Clock setup */
653     .macro    init_clock
654         ldr r0, CCM_BASE_ADDR_W
655
656         /* default CLKO to 1/32 of the ARM core*/
657         ldr r1, [r0, #CLKCTL_COSR]
658         bic r1, r1, #0x00000FF00
659         bic r1, r1, #0x0000000FF
660         mov r2, #0x00006C00
661         add r2, r2, #0x67
662         orr r1, r1, r2
663         str r1, [r0, #CLKCTL_COSR]
664
665         ldr r2, CCM_CCMR_W
666         str r2, [r0, #CLKCTL_CCMR]
667
668         /*check clock path*/
669         ldr r2, [r0, #CLKCTL_PDR0]
670         tst r2, #0x1
671         ldrne r3, MPCTL_PARAM_532_W  /* consumer path*/
672         ldreq r3, MPCTL_PARAM_399_W  /* auto path*/
673
674         /*Set MPLL , arm clock and ahb clock*/
675         str r3, [r0, #CLKCTL_MPCTL]
676
677         ldr r1, PPCTL_PARAM_W
678         str r1, [r0, #CLKCTL_PPCTL]
679
680         ldr r1, [r0, #CLKCTL_PDR0]
681         orr r1, r1, #0x800000
682         str r1, [r0, #CLKCTL_PDR0]
683
684         ldr r1, CCM_PDR0_W
685         str r1, [r0, #CLKCTL_PDR0]
686     .endm /* init_clock */
687
688     /* M3IF setup */
689     .macro init_m3if
690         /* Configure M3IF registers */
691         ldr r1, M3IF_BASE_W
692         /*
693         * M3IF Control Register (M3IFCTL)
694         * MRRP[0] = L2CC0 not on priority list (0 << 0)        = 0x00000000
695         * MRRP[1] = L2CC1 not on priority list (0 << 0)        = 0x00000000
696         * MRRP[2] = MBX not on priority list (0 << 0)        = 0x00000000
697         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
698         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
699         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
700         * MRRP[6] = IPU1 on priority list (1 << 6)             = 0x00000040
701         * MRRP[7] = IPU2 not on priority list (0 << 0)   = 0x00000000
702         *                                                       ------------
703         *                                                       0x00000040
704         */
705         ldr r0, =0x00000040
706         str r0, [r1]  /* M3IF control reg */
707     .endm /* init_m3if */
708
709     .macro init_cs0
710         ldr r0, WEIM_CTRL_CS0_W
711         ldr r1, CS0_CSCRU_0x0000CC03
712         str r1, [r0, #CSCRU]
713         ldr r1, CS0_CSCRL_0xA0330D01
714         str r1, [r0, #CSCRL]
715         ldr r1, CS0_CSCRA_0x00220800
716         str r1, [r0, #CSCRA]
717     .endm
718
719      /* CPLD on CS5 setup */
720     .macro init_cs4
721         ldr r0, WEIM_CTRL_CS4_W
722         ldr r1, CS4_CSCRU_0x0000DCF6
723         str r1, [r0, #CSCRU]
724         ldr r1, CS4_CSCRL_0x444A4541
725         str r1, [r0, #CSCRL]
726         ldr r1, CS4_CSCRA_0x44443302
727         str r1, [r0, #CSCRA]
728     .endm /* init_cs4 */
729
730      /* CPLD on CS5 setup */
731     .macro init_cs5
732         ldr r0, WEIM_CTRL_CS5_W
733         ldr r1, CS5_CSCRU_0x0000DCF6
734         str r1, [r0, #CSCRU]
735         ldr r1, CS5_CSCRL_0x444A4541
736         str r1, [r0, #CSCRL]
737         ldr r1, CS5_CSCRA_0x44443302
738         str r1, [r0, #CSCRA]
739     .endm /* init_cs5 */
740
741     .macro setup_sdram
742         ldr r0, ESDCTL_BASE_W
743 //        mov r1, #0x204
744         mov r1, #0x4
745         str r1, [r0, #0x10]
746 //      mov r2, #RAM_BANK0_BASE
747 //      bl setup_sdram_bank
748         add r0, r0, #8
749         mov r2, #RAM_BANK1_BASE
750         bl setup_sdram_bank
751     .endm
752
753     .macro nfc_cmd_input
754         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
755         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
756         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
757         bl do_wait_op_done
758     .endm   // nfc_cmd_input
759
760     .macro do_addr_input
761         and r3, r3, #0xFF
762         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
763         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
764         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
765         bl do_wait_op_done
766     .endm   // do_addr_input
767
768     /* To support 133MHz DDR */
769     .macro  init_iomuxc
770         mov r0, #0x2
771         ldr r1, IOMUXC_BASE_ADDR_W
772         add r1, r1, #0x368
773         add r2, r1, #0x4C8 -0x368
774 1:      str r0, [r1]
775         add r1, r1, #4
776         cmp r1, r2
777         ble 1b
778     .endm /* init_iomuxc */
779
780 /*
781  * r0: control base, r1: working, r2: sdram bank base
782  */
783 setup_sdram_bank:
784         ldr r1, SDRAM_0x00795429
785         str r1, [r0, #0x4]
786         ldr r1, SDRAM_0x92220000
787         str r1, [r0, #0x0]
788         mov r1, #0
789         ldr r12, SDRAM_PARAM1_MDDR
790         str r1, [r12, r2]
791
792         ldr r1, SDRAM_0xA2220000
793         str r1, [r0, #0x0]
794         mov r1, #0
795         ldr r12, SDRAM_PARAM1_MDDR
796         str r1, [r12, r2]
797         str r1, [r12, r2]
798
799         ldr r1, SDRAM_0xB2220000
800         str r1, [r0, #0x0]
801         mov r1, #0xda
802         ldr r12, SDRAM_PARAM2_MDDR
803         strb r1, [r12, r2]
804         mov r1, #0xFF
805         ldr r12, SDRAM_PARAM3_MDDR
806         strb r1, [r12, r2]
807
808         ldr r1, SDRAM_0x82228C80
809         str r1, [r0, #0x0]
810         mov pc, lr
811
812 #define PLATFORM_VECTORS         _platform_vectors
813     .macro  _platform_vectors
814         .globl  _board_BCR, _board_CFG
815 _board_BCR:   .long   0       // Board Control register shadow
816 _board_CFG:   .long   0       // Board Configuration (read at RESET)
817     .endm
818
819 ARM_PPMRR:              .word   0x40000015
820 L2CACHE_PARAM:          .word   0x00030024
821 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
822 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
823 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
824 AIPS1_PARAM_W:          .word   0x77777777
825 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
826 MAX_PARAM1:             .word   0x00302154
827 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
828 ESDCTL_BASE_W:          .word   ESDCTL_BASE
829 M3IF_BASE_W:            .word   M3IF_BASE
830 SDRAM_PARAM1_MDDR:      .word   0x00000400
831 SDRAM_PARAM2_MDDR:      .word   0x00000033
832 SDRAM_PARAM3_MDDR:      .word   0x01000000
833 SDRAM_0x92220000:       .word   0x92200000
834 SDRAM_0xA2220000:       .word   0xA2200000
835 SDRAM_0xB2220000:       .word   0xB2200000
836 SDRAM_0x82228C80:       .word   0x82228C80
837 SDRAM_0x00795429:       .word   0x00795429
838 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
839 CCM_CCMR_W:             .word   0x003F4208
840 CCM_PDR0_W:             .word   0x00881800
841 //MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
842 MPCTL_PARAM_399_W:      .word   0x000F2005
843 MPCTL_PARAM_532_W:      .word   MPCTL_PARAM_532
844 //PPCTL_PARAM_W:        .word   PPCTL_PARAM_300
845 PPCTL_PARAM_W:          .word   0x00031801
846 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
847 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
848 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
849 CONST_0x0FFF:           .word   0x0FFF
850 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
851 IPU_CTRL_BASE_ADDR_W:   .word   IPU_CTRL_BASE_ADDR
852 WEIM_CTRL_CS4_W:    .word   WEIM_CTRL_CS4
853 WEIM_CTRL_CS5_W:    .word   WEIM_CTRL_CS5
854 WEIM_CTRL_CS0_W:    .word   WEIM_CTRL_CS0
855 CS0_CSCRU_0x0000CC03:   .word   0x0000CC03
856 CS0_CSCRL_0xA0330D01:   .word   0xA0330D01
857 CS0_CSCRA_0x00220800:   .word   0x00220800
858 #if 0
859 CS5_CSCRU_0x0000DCF6:   .word   0x0000DCF6
860 CS5_CSCRL_0x444A4541:   .word   0x444A4541
861 CS5_CSCRA_0x44443302:   .word   0x44443302
862 #else
863 CS4_CSCRU_0x0000DCF6:   .word   0x0000DCF6
864 CS4_CSCRL_0x444A4541:   .word   0x444A4541
865 CS4_CSCRA_0x44443302:   .word   0x44443302
866 CS5_CSCRU_0x0000DCF6:   .word   0x0000DCF6
867 CS5_CSCRL_0x444A4541:   .word   0x444A4541
868 CS5_CSCRA_0x44443302:   .word   0x44443302
869 #endif
870 /*---------------------------------------------------------------------------*/
871 /* end of hal_platform_setup.h                                               */
872 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */