]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx31/ads/v2_0/include/hal_platform_setup.h
94b9ace28f7cc29a12409b91a7cd8e9eade6f439
[karo-tx-redboot.git] / packages / hal / arm / mx31 / ads / 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 SDRAM_FULL_PAGE_BIT     0x100
61 #define SDRAM_FULL_PAGE_MODE    0x37
62 #define SDRAM_BURST_MODE        0x33
63
64 #define CYGHWR_HAL_ROM_VADDR    0x0
65
66 #if 0
67 #define UNALIGNED_ACCESS_ENABLE
68 #define SET_T_BIT_DISABLE
69 #define BRANCH_PREDICTION_ENABLE
70 #endif
71
72 //#define TURN_OFF_IMPRECISE_ABORT
73
74 // This macro represents the initial startup code for the platform
75 // r11 is reserved to contain chip rev info in this file
76     .macro  _platform_setup1
77 FSL_BOARD_SETUP_START:
78 /*
79  *       ARM1136 init
80  *       - invalidate I/D cache/TLB and drain write buffer;
81  *       - invalidate L2 cache
82  *       - unaligned access
83  *       - branch predictions
84  */
85 #ifdef TURN_OFF_IMPRECISE_ABORT
86     mrs r0, cpsr
87     bic r0, r0, #0x100
88     msr cpsr, r0
89 #endif
90
91     mov r0, #0
92     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
93     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
94     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
95
96     /* Also setup the Peripheral Port Remap register inside the core */
97     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
98     mcr p15, 0, r0, c15, c2, 4
99
100     /*** L2 Cache setup/invalidation/disable ***/
101     /* Disable L2 cache first */
102     mov r0, #L2CC_BASE_ADDR
103     ldr r2, [r0, #L2_CACHE_CTL_REG]
104     bic r2, r2, #0x1
105     str r2, [r0, #L2_CACHE_CTL_REG]
106     /*
107      * Configure L2 Cache:
108      * - 128k size(16k way)
109      * - 8-way associativity
110      * - 0 ws TAG/VALID/DIRTY
111      * - 4 ws DATA R/W
112      */
113     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
114     and r1, r1, #0xFE000000
115     ldr r2, L2CACHE_PARAM
116     orr r1, r1, r2
117     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
118
119     /* Invalidate L2 */
120     mov r1, #0x000000FF
121     str r1, [r0, #L2_CACHE_INV_WAY_REG]
122 L2_loop:
123     /* Poll Invalidate By Way register */
124     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
125     cmp r2, #0
126     bne L2_loop
127     /*** End of L2 operations ***/
128
129     mov r0, #SDRAM_NON_FLASH_BOOT
130     ldr r1, AVIC_VECTOR0_ADDR_W
131     str r0, [r1] // for checking boot source from nand, nor or sdram
132 /*
133  * End of ARM1136 init
134  */
135 init_spba_start:
136     init_spba
137 init_aips_start:
138     init_aips
139 init_max_start:
140     init_max
141 init_m3if_start:
142     init_m3if
143
144     ldr r11, =CHIP_REV_1_0
145     ldr r0, IIM_SREV_REG_VAL
146     ldr r1, [r0, #0x0]
147     cmp r1, #0x0
148     ldrne r11, =CHIP_REV_1_1
149     init_drive_strength
150 init_cs0_async_start:
151 //    init_cs0_async
152
153     /* If SDRAM has been setup, bypass clock/WEIM setup */
154     cmp pc, #SDRAM_BASE_ADDR
155     blo init_clock_start
156     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
157     blo HWInitialise_skip_SDRAM_setup
158
159     mov r0, #NOR_FLASH_BOOT
160     ldr r1, AVIC_VECTOR0_ADDR_W
161     str r0, [r1]
162
163 init_cs4_start:
164     init_cs4
165
166 init_clock_start:
167     init_clock
168
169     /* Based on chip rev, setup params for SDRAM controller */
170     ldr r10, =0
171     mov r4, #SDRAM_BURST_MODE
172
173 init_sdram_start:
174
175     /* Assuming DDR memory first */
176     setup_sdram ddr X32 DDR 0
177 #if 0
178     beq HWInitialise_skip_SDRAM_setup
179     setup_sdram ddr X16 DDR 0
180     beq HWInitialise_skip_SDRAM_setup
181     setup_sdram sdr X32 SDR 0
182     beq HWInitialise_skip_SDRAM_setup
183     setup_sdram sdr X16 SDR 0
184     beq HWInitialise_skip_SDRAM_setup
185
186     /* Reach hear means memory setup problem. Try to 
187      * increase the HCLK divider */
188     ldr r0, CCM_BASE_ADDR_W
189     ldr r1, [r0, #CLKCTL_PDR0]
190     and r2, r1, #0x38
191     cmp r2, #0x38
192     beq loop_forever
193     add r1, r1, #0x8
194     str r1, [r0, #CLKCTL_PDR0]
195     b init_sdram_start
196
197 loop_forever:
198     b loop_forever  /* shouldn't get here */
199 #endif
200
201 HWInitialise_skip_SDRAM_setup:
202
203     mov r0, #NFC_BASE
204     add r2, r0, #0x800      // 2K window
205     cmp pc, r0
206     blo Normal_Boot_Continue
207     cmp pc, r2
208     bhi Normal_Boot_Continue
209 NAND_Boot_Start:
210     /* Copy image from flash to SDRAM first */
211     ldr r1, MXC_REDBOOT_ROM_START
212
213 1:  ldmia r0!, {r3-r10}
214     stmia r1!, {r3-r10}
215     cmp r0, r2
216     blo 1b
217     /* Jump to SDRAM */
218     ldr r1, CONST_0x0FFF
219     and r0, pc, r1     /* offset of pc */
220     ldr r1, MXC_REDBOOT_ROM_START
221     add r1, r1, #0x10
222     add pc, r0, r1
223     nop
224     nop
225     nop
226     nop
227 NAND_Copy_Main:
228     // Check if x16/2kb page
229     ldr r7, CCM_BASE_ADDR_W
230     ldr r7, [r7, #0xC]
231     ands r7, r7, #(1 << 30)
232
233     mov r0, #NAND_FLASH_BOOT
234     ldr r1, AVIC_VECTOR0_ADDR_W
235     str r0, [r1]
236     mov r0, #MXCFIS_NAND
237     ldr r1, AVIC_VECTOR1_ADDR_W
238     str r0, [r1]
239
240     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
241     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
242     add r2, r0, #0x800   //r2: end of 3rd RAM buf. Doesn't change
243     addeq r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
244     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
245     ldr r11, MXC_REDBOOT_ROM_START
246     add r13, r11, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
247     add r11, r11, r1     //r11: starting SDRAM address for copying. Updated constantly
248
249     //unlock internal buffer
250     mov r3, #0x2
251     strh r3, [r12, #0xA]
252
253 Nfc_Read_Page:
254 //  NFC_CMD_INPUT(FLASH_Read_Mode1);
255     mov r3, #0x0
256     nfc_cmd_input
257
258     // Check if x16/2kb page
259     ldr r7, CCM_BASE_ADDR_W
260     ldr r7, [r7, #0xC]
261     ands r7, r7, #(1 << 30)
262     bne nfc_addr_ops_2kb
263 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
264     mov r3, r1
265     do_addr_input       //1st addr cycle
266     mov r3, r1, lsr #9
267     do_addr_input       //2nd addr cycle
268     mov r3, r1, lsr #17
269     do_addr_input       //3rd addr cycle
270     mov r3, r1, lsr #25
271     do_addr_input       //4th addr cycle
272     b end_of_nfc_addr_ops
273
274 nfc_addr_ops_2kb:
275 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
276     mov r3, #0
277     do_addr_input       //1st addr cycle
278     mov r3, #0
279     do_addr_input       //2nd addr cycle
280     mov r3, r1, lsr #11
281     do_addr_input       //3rd addr cycle
282     mov r3, r1, lsr #19
283     do_addr_input       //4th addr cycle
284
285 //    NFC_CMD_INPUT(FLASH_Read_Mode1_2K);
286     mov r3, #0x30
287     nfc_cmd_input
288
289 end_of_nfc_addr_ops:
290 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
291 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
292 //               NAND_FLASH_CONFIG1_REG);
293     mov r8, #0
294     bl nfc_data_output
295     bl do_wait_op_done
296     // Check if x16/2kb page
297     ldr r7, CCM_BASE_ADDR_W
298     ldr r7, [r7, #0xC]
299     ands r7, r7, #(1 << 30)
300     beq nfc_addr_data_output_done_512
301
302 // For 2K page - 2nd 512
303     mov r8, #1
304     bl nfc_data_output
305     bl do_wait_op_done
306
307 // 3rd 512
308     mov r8, #2
309     bl nfc_data_output
310     bl do_wait_op_done
311
312 // 4th 512
313     mov r8, #3
314     bl nfc_data_output
315     bl do_wait_op_done
316 // end of 4th
317
318     // check for bad block
319     mov r3, r1, lsl #(32-17)    // get rid of block number
320     cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
321     b nfc_addr_data_output_done
322
323 nfc_addr_data_output_done_512:
324     // check for bad block
325     mov r3, r1, lsl #(32-5-9)    // get rid of block number
326     cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
327
328 nfc_addr_data_output_done:
329     bhi Copy_Good_Blk
330     add r4, r0, #0x800  //r3 -> spare area buf 0
331     ldrh r4, [r4, #0x4]
332     and r4, r4, #0xFF00
333     cmp r4, #0xFF00
334     beq Copy_Good_Blk
335     // really sucks. Bad block!!!!
336     cmp r3, #0x0
337     beq Skip_bad_block
338     // even suckier since we already read the first page!
339     // Check if x16/2kb page
340     ldr r7, CCM_BASE_ADDR_W
341     ldr r7, [r7, #0xC]
342     ands r7, r7, #(1 << 30)
343
344     subeq r11, r11, #512  //rewind 1 page for the sdram pointer
345     subeq r1, r1, #512    //rewind 1 page for the flash pointer
346
347     // for 2k page
348     subne r11, r11, #0x800  //rewind 1 page for the sdram pointer
349     subne r1, r1, #0x800    //rewind 1 page for the flash pointer
350
351 Skip_bad_block:
352     // Check if x16/2kb page
353     ldr r7, CCM_BASE_ADDR_W
354     ldr r7, [r7, #0xC]
355     ands r7, r7, #(1 << 30)
356
357     addeq r1, r1, #(32*512)
358     addne r1, r1, #(64*2048)
359
360     b Nfc_Read_Page
361 Copy_Good_Blk:
362     //copying page
363 1:  ldmia r0!, {r3-r10}
364     stmia r11!, {r3-r10}
365     cmp r0, r2
366     blo 1b
367     cmp r11, r13
368     bge NAND_Copy_Main_done
369     // Check if x16/2kb page
370     ldr r7, CCM_BASE_ADDR_W
371     ldr r7, [r7, #0xC]
372     ands r7, r7, #(1 << 30)
373     addeq r1, r1, #0x200
374     addne r1, r1, #0x800
375     mov r0, #NFC_BASE
376     b Nfc_Read_Page
377
378 NAND_Copy_Main_done:
379
380 Normal_Boot_Continue:
381
382 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
383     /* Copy image from flash to SDRAM first */
384     ldr r0, =0xFFFFF000
385     and r0, r0, pc
386     ldr r1, MXC_REDBOOT_ROM_START
387     cmp r0, r1
388     beq HWInitialise_skip_SDRAM_copy
389
390     add r2, r0, #REDBOOT_IMAGE_SIZE
391
392 1:  ldmia r0!, {r3-r10}
393     stmia r1!, {r3-r10}
394     cmp r0, r2
395     ble 1b
396     /* Jump to SDRAM */
397     ldr r1, =0xFFFF
398     and r0, pc, r1         /* offset of pc */
399     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
400     add pc, r0, r1
401     nop
402     nop
403     nop
404     nop
405 #endif /* CYG_HAL_STARTUP_ROMRAM */
406
407 HWInitialise_skip_SDRAM_copy:
408     init_cs0_sync
409
410 NAND_ClockSetup:
411
412 /*
413  * Note:
414  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
415  */
416
417 STACK_Setup:
418     // Set up a stack [for calling C code]
419     ldr r1, =__startup_stack
420     ldr r2, =RAM_BANK0_BASE
421     orr sp, r1, r2
422
423     // Create MMU tables
424     bl hal_mmu_init
425
426     // Enable MMU
427     ldr r2, =10f
428     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
429     orr r1, r1, #7                          // enable MMU bit
430     mcr MMU_CP, 0, r1, MMU_Control, c0
431     mov pc,r2    /* Change address spaces */
432     nop
433     nop
434     nop
435 10:
436
437     // Save shadow copy of BCR, also hardware configuration
438     ldr r1, =_board_BCR
439     str r2, [r1]
440     ldr r1, =_board_CFG
441     str r9, [r1]                // Saved far above...
442
443     .endm                       // _platform_setup1
444
445 do_wait_op_done:
446     1:
447         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
448         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
449         beq 1b
450     bx lr     // do_wait_op_done
451
452 nfc_data_output:
453     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
454     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
455
456     // writew(buf_no, RAM_BUFFER_ADDRESS_REG);
457     strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
458     // writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
459     mov r3, #FDO_PAGE_SPARE_VAL
460     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
461     bx lr
462
463 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
464 #define PLATFORM_SETUP1
465 #endif
466
467     /* Do nothing */
468     .macro  init_spba
469     .endm  /* init_spba */
470
471     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
472     .macro init_aips
473         /*
474          * Set all MPROTx to be non-bufferable, trusted for R/W,
475          * not forced to user-mode.
476          */
477         ldr r0, AIPS1_CTRL_BASE_ADDR_W
478         ldr r1, AIPS1_PARAM_W
479         str r1, [r0, #0x00]
480         str r1, [r0, #0x04]
481         ldr r0, AIPS2_CTRL_BASE_ADDR_W
482         str r1, [r0, #0x00]
483         str r1, [r0, #0x04]
484
485         /*
486          * Clear the on and off peripheral modules Supervisor Protect bit
487          * for SDMA to access them. Did not change the AIPS control registers
488          * (offset 0x20) access type
489          */
490         ldr r0, AIPS1_CTRL_BASE_ADDR_W
491         ldr r1, =0x0
492         str r1, [r0, #0x40]
493         str r1, [r0, #0x44]
494         str r1, [r0, #0x48]
495         str r1, [r0, #0x4C]
496         ldr r1, [r0, #0x50]
497         and r1, r1, #0x00FFFFFF
498         str r1, [r0, #0x50]
499
500         ldr r0, AIPS2_CTRL_BASE_ADDR_W
501         ldr r1, =0x0
502         str r1, [r0, #0x40]
503         str r1, [r0, #0x44]
504         str r1, [r0, #0x48]
505         str r1, [r0, #0x4C]
506         ldr r1, [r0, #0x50]
507         and r1, r1, #0x00FFFFFF
508         str r1, [r0, #0x50]
509     .endm /* init_aips */
510
511     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
512     .macro init_max
513         ldr r0, MAX_BASE_ADDR_W
514         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
515         ldr r1, MAX_PARAM1
516         str r1, [r0, #0x000]        /* for S0 */
517         str r1, [r0, #0x100]        /* for S1 */
518         str r1, [r0, #0x200]        /* for S2 */
519         str r1, [r0, #0x300]        /* for S3 */
520         str r1, [r0, #0x400]        /* for S4 */
521         /* SGPCR - always park on last master */
522         ldr r1, =0x10
523         str r1, [r0, #0x010]        /* for S0 */
524         str r1, [r0, #0x110]        /* for S1 */
525         str r1, [r0, #0x210]        /* for S2 */
526         str r1, [r0, #0x310]        /* for S3 */
527         str r1, [r0, #0x410]        /* for S4 */
528         /* MGPCR - restore default values */
529         ldr r1, =0x0
530         str r1, [r0, #0x800]        /* for M0 */
531         str r1, [r0, #0x900]        /* for M1 */
532         str r1, [r0, #0xA00]        /* for M2 */
533         str r1, [r0, #0xB00]        /* for M3 */
534         str r1, [r0, #0xC00]        /* for M4 */
535         str r1, [r0, #0xD00]        /* for M5 */
536     .endm /* init_max */
537
538     /* Clock setup */
539     .macro    init_clock
540         ldr r0, IPU_CTRL_BASE_ADDR_W
541         ldr r1, =0x40
542         str r1, [r0]
543
544         ldr r0, CCM_BASE_ADDR_W
545         ldr r2, CCM_CCMR_0x074B0BF5
546         ldr r3, CCM_CCMR_0x074B0BFD
547         ldr r4, CCM_CCMR_0x074B0B7D
548
549         // Make sure to use CKIH
550         ldr r1, [r0, #CLKCTL_CCMR]
551         bic r1, r1, #0x8            // disable PLL first
552         str r1, [r0, #CLKCTL_CCMR]
553         str r2, [r0, #CLKCTL_CCMR]  // select CKIH (26MHz) as PLL ref clock
554         ldr r1, =0x1000
555     1:
556         subs r1, r1, #0x1
557         bne 1b
558         str r3, [r0, #CLKCTL_CCMR]  // enable PLL
559         str r4, [r0, #CLKCTL_CCMR]  // switch to PLL (SPLL for FIR)
560
561         mov r1, #PBC_BASE
562         ldrh r1, [r1, #PBC_BSTAT2]
563         ands r1, r1, #CLK_INPUT_27MHZ_SET
564
565         // 532-133-66.5
566         ldr r1, CCM_PDR0_532_133_66_W
567         str r1, [r0, #CLKCTL_PDR0]
568         ldr r1, MPCTL_PARAM_532_W
569         ldrne r1, MPCTL_PARAM_532_27_W
570         str r1, [r0, #CLKCTL_MPCTL]
571
572         /* Set UPLL=240MHz, USB=60MHz */
573         ldr r1, CCM_PDR1_0x49FCFE7F
574         str r1, [r0, #CLKCTL_PDR1]
575         ldr r1, CCM_UPCTL_PARAM_240
576         ldrne r1, CCM_UPCTL_PARAM_240_27
577         str r1, [r0, #CLKCTL_UPCTL]
578         // default CLKO to 1/8 of the ARM core
579         mov r1, #0x000002C0
580         add r1, r1, #0x00000006
581         str r1, [r0, #CLKCTL_COSR]
582     .endm /* init_clock */
583
584     /* M3IF setup */
585     .macro init_m3if
586         /* Configure M3IF registers */
587         ldr r1, M3IF_BASE_W
588         /*
589         * M3IF Control Register (M3IFCTL)
590         * MRRP[0] = L2CC0 not on priority list (0 << 0)        = 0x00000000
591         * MRRP[1] = L2CC1 not on priority list (0 << 0)        = 0x00000000
592         * MRRP[2] = MBX not on priority list (0 << 0)        = 0x00000000
593         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
594         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
595         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
596         * MRRP[6] = IPU1 on priority list (1 << 6)             = 0x00000040
597         * MRRP[7] = IPU2 not on priority list (0 << 0)   = 0x00000000
598         *                                                       ------------
599         *                                                       0x00000040
600         */
601         ldr r0, =0x00000040
602         str r0, [r1]  /* M3IF control reg */
603     .endm /* init_m3if */
604
605     /* CS0 sync mode setup */
606     .macro init_cs0_sync
607         /*
608          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
609          */
610         /* Flash reset command */
611         ldr     r0, =CS0_BASE_ADDR
612         ldr     r1, =0xF0F0
613         strh    r1, [r0]
614         /* 1st command */
615         ldr     r2, =0xAAA
616         add     r2, r2, r0
617         ldr     r1, =0xAAAA
618         strh    r1, [r2]
619         /* 2nd command */
620         ldr     r2, =0x554
621         add     r2, r2, r0
622         ldr     r1, =0x5555
623         strh    r1, [r2]
624         /* 3rd command */
625         ldr     r2, =0xAAA
626         add     r2, r2, r0
627         ldr     r1, =0xD0D0
628         strh    r1, [r2]
629         /* Write flash config register */
630         ldr     r1, =0x56CA
631         strh    r1, [r2]
632         /* Flash reset command */
633         ldr     r1, =0xF0F0
634         strh    r1, [r0]
635
636         ldr r0, WEIM_CTRL_CS0_W
637         ldr r1, =0x23524E80
638         str r1, [r0, #CSCRU]
639         ldr r1, =0x10000D03
640         str r1, [r0, #CSCRL]
641         ldr r1, =0x00720900
642         str r1, [r0, #CSCRA]
643     .endm /* init_cs0_sync */
644
645     /* CS0 async mode setup */
646     .macro init_cs0_async
647         /* Async flash mode */
648         ldr r0, WEIM_CTRL_CS0_W
649         ldr r1, CS0_CSCRU_0x11414C80
650         str r1, [r0, #CSCRU]
651         ldr r1, CS0_CSCRL_0x30000D03
652         str r1, [r0, #CSCRL]
653         ldr r1, CS0_CSCRA_0x00310800
654         str r1, [r0, #CSCRA]
655     .endm /* init_cs0_async */
656
657     /* CPLD on CS4 setup */
658     .macro init_cs4
659         ldr r0, WEIM_CTRL_CS4_W
660         ldr r1, CS4_0x0000D843
661         str r1, [r0, #CSCRU]
662         ldr r1, CS4_0x22252521
663         str r1, [r0, #CSCRL]
664         ldr r1, CS4_0x22220A00
665         str r1, [r0, #CSCRA]
666     .endm /* init_cs4 */
667
668     .macro setup_sdram, name, bus_width, mode, full_page
669         /* It sets the "Z" flag in the CPSR at the end of the macro */
670         ldr r0, ESDCTL_BASE_W
671         mov r2, #SDRAM_BASE_ADDR
672         ldr r1, SDRAM_0x0075E73A
673         str r1, [r0, #0x4]
674         ldr r1, =0x2            // reset
675         str r1, [r0, #0x10]
676         ldr r1, SDRAM_PARAM1_\mode
677         str r1, [r0, #0x10]
678         // Hold for more than 200ns
679         ldr r1, =0x10000
680 1:
681         subs r1, r1, #0x1
682         bne 1b
683
684         ldr r1, SDRAM_0x92100000
685         str r1, [r0]
686         ldr r1, =0x0
687         ldr r12, SDRAM_PARAM2_\mode
688         str r1, [r12]
689         ldr r1, SDRAM_0xA2100000
690         str r1, [r0]
691         ldr r1, =0x0
692         str r1, [r2]
693         ldr r1, SDRAM_0xB2100000
694         str r1, [r0]
695
696         ldr r1, =0x0
697         .if \full_page
698         strb r1, [r2, #SDRAM_FULL_PAGE_MODE]
699         .else
700         strb r1, [r2, #SDRAM_BURST_MODE]
701         .endif
702                 
703         ldr r1, =0xFF
704         ldr r12, =0x81000000
705         strb r1, [r12]
706         ldr r3, SDRAM_0x82116080
707         ldr r4, SDRAM_PARAM3_\mode
708         add r3, r3, r4
709         ldr r4, SDRAM_PARAM4_\bus_width
710         add r3, r3, r4
711         .if \full_page
712         add r3, r3, #0x100   /* Force to full page mode */
713         .endif
714
715         str r3, [r0]
716         ldr r1, =0x0
717         str r1, [r2]
718         /* Below only for DDR */
719         ldr r1, [r0, #0x10]
720         ands r1, r1, #0x4
721         ldrne r1, =0x0000000C
722         strne r1, [r0, #0x10]
723         /* Testing if it is truly DDR */
724         ldr r1, SDRAM_0x55555555
725         ldr r0, =SDRAM_BASE_ADDR
726         str r1, [r0]
727         ldr r2, SDRAM_0xAAAAAAAA
728         str r2, [r0, #0x4]
729         ldr r2, [r0]
730         cmp r1, r2
731     .endm
732
733     .macro nfc_cmd_input
734         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
735         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
736         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
737         bl do_wait_op_done
738     .endm   // nfc_cmd_input
739
740     .macro do_addr_input
741         and r3, r3, #0xFF
742         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
743         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
744         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
745         bl do_wait_op_done
746     .endm   // do_addr_input
747
748     /* To support 133MHz DDR */
749     .macro  init_drive_strength
750         /*
751          * Disable maximum drive strength SDRAM/DDR lines by clearing DSE1 bits
752          * in SW_PAD_CTL registers
753          */
754
755         // SDCLK
756         ldr r1, IOMUXC_BASE_ADDR_W
757         add r1, r1, #0x200
758         // Now r1 = (IOMUX_BASE_ADDR + 0x200)
759         ldr r0, [r1, #0x6C]
760         bic r0, r0, #(1 << 12)
761         str r0, [r1, #0x6C]
762         
763         // CAS
764         ldr r0, [r1, #0x70]
765         bic r0, r0, #(1 << 22)
766         str r0, [r1, #0x70]
767         
768         // RAS
769         ldr r0, [r1, #0x74]
770         bic r0, r0, #(1 << 2)
771         str r0, [r1, #0x74]
772         
773         // CS2 (CSD0)
774         ldr r0, [r1, #0x7C]
775         bic r0, r0, #(1 << 22)
776         str r0, [r1, #0x7C]
777         
778         // DQM3
779         ldr r0, [r1, #0x84]
780         bic r0, r0, #(1 << 22)
781         str r0, [r1, #0x84]
782         
783         // DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2DC)
784         ldr r2, =22     // (0x2E0 - 0x288) / 4 = 22
785 pad_loop:
786         ldr r0, [r1, #0x88]
787         bic r0, r0, #(1 << 22)
788         bic r0, r0, #(1 << 12)
789         bic r0, r0, #(1 << 2)
790         str r0, [r1, #0x88]
791         add r1, r1, #4
792         subs r2, r2, #0x1
793         bne pad_loop
794     .endm /* init_drive_strength */
795
796 #define PLATFORM_VECTORS         _platform_vectors
797     .macro  _platform_vectors
798         .globl  _board_BCR, _board_CFG
799 _board_BCR:   .long   0       // Board Control register shadow
800 _board_CFG:   .long   0       // Board Configuration (read at RESET)
801     .endm
802
803 ARM_PPMRR:              .word   0x40000015
804 L2CACHE_PARAM:          .word   0x00030024
805 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
806 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
807 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
808 AIPS1_PARAM_W:          .word   0x77777777
809 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
810 MAX_PARAM1:             .word   0x00302154
811 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
812 ESDCTL_BASE_W:          .word   ESDCTL_BASE
813 M3IF_BASE_W:            .word   M3IF_BASE
814 SDRAM_PARAM1_DDR:           .word       0x4
815 SDRAM_PARAM1_SDR:           .word       0x0
816 SDRAM_PARAM2_DDR:           .word       0x80000F00
817 SDRAM_PARAM2_SDR:           .word       0x80000400
818 SDRAM_PARAM3_DDR:       .word   0x00100000
819 SDRAM_PARAM3_SDR:       .word   0x0
820 SDRAM_PARAM4_X32:       .word   0x00010000
821 SDRAM_PARAM4_X16:       .word   0x0
822 SDRAM_0x55555555:       .word   0x55555555
823 SDRAM_0xAAAAAAAA:       .word   0xAAAAAAAA
824 SDRAM_0x92100000:       .word   0x92100000
825 SDRAM_0xA2100000:       .word   0xA2100000
826 SDRAM_0xB2100000:       .word   0xB2100000
827 SDRAM_0x82116080:       .word   0x82116080
828 SDRAM_0x0075E73A:       .word   0x0075E73A
829 WEIM_CTRL_CS0_W:        .word   WEIM_CTRL_CS0
830 CS0_CSCRU_0x11414C80:   .word   0x11414C80
831 CS0_CSCRL_0x30000D03:   .word   0x30000D03
832 CS0_CSCRA_0x00310800:   .word   0x00310800
833 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
834 CCM_PDR0_532_133_66_W:  .word   PDR0_532_133_66
835 MPCTL_PARAM_532_W:      .word   MPCTL_PARAM_532
836 MPCTL_PARAM_532_27_W:   .word   MPCTL_PARAM_532_27
837 CCM_PDR1_0x49FCFE7F:    .word   0x49FCFE7F
838 CCM_UPCTL_PARAM_240:    .word   UPCTL_PARAM_240
839 CCM_UPCTL_PARAM_240_27: .word   UPCTL_PARAM_240_27
840 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
841 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
842 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
843 CONST_0x0FFF:           .word   0x0FFF
844 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
845 IPU_CTRL_BASE_ADDR_W:   .word   IPU_CTRL_BASE_ADDR
846 CCM_CCMR_0x074B0BF5:    .word   0x074B0BF5
847 CCM_CCMR_0x074B0BFD:    .word   0x074B0BFD
848 CCM_CCMR_0x074B0B7D:    .word   0x074B0B7D
849 WEIM_CTRL_CS4_W:    .word   WEIM_CTRL_CS4
850 CS4_0x0000D843:     .word   0x0000D843
851 CS4_0x22252521:     .word   0x22252521
852 CS4_0x22220A00:     .word   0x22220A00
853
854 /*---------------------------------------------------------------------------*/
855 /* end of hal_platform_setup.h                                               */
856 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */