]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91321/mxc30030ads/v2_0/include/hal_platform_setup.h
Merge branch 'master' of git+ssh://git.kernelconcepts.de/karo-tx-redboot
[karo-tx-redboot.git] / packages / hal / arm / mxc91321 / mxc30030ads / 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 CYGHWR_HAL_ROM_VADDR    0x0
61 #undef CLOCK_SETUP_ALIGNED
62
63 // This macro represents the initial startup code for the platform
64     .macro  _platform_setup1
65 FSL_BOARD_SETUP_START:
66 /*
67  *       ARM1136 init
68  *       - invalidate I/D cache/TLB and drain write buffer;
69  *       - invalidate L2 cache
70  *       - unaligned access
71  *       - branch predictions
72  */
73 #ifdef TURN_OFF_IMPRECISE_ABORT
74     mrs r0, cpsr
75     bic r0, r0, #0x100
76     msr cpsr, r0
77 #endif
78     mov r0, #0
79     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
80     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
81     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
82
83     /* Also setup the Peripheral Port Remap register inside the core */
84     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
85     mcr p15, 0, r0, c15, c2, 4
86
87     /*** L2 Cache setup/invalidation/disable ***/
88     /* Disable L2 cache first */
89     mov r0, #L2CC_BASE_ADDR
90     ldr r2, [r0, #L2_CACHE_CTL_REG]
91     bic r2, r2, #0x1
92     str r2, [r0, #L2_CACHE_CTL_REG]
93     /*
94      * Configure L2 Cache:
95      * - 128k size(16k way)
96      * - 8-way associativity
97      * - 0 ws TAG/VALID/DIRTY
98      * - 4 ws DATA R/W
99      */
100     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
101     and r1, r1, #0xFE000000
102     ldr r2, L2CACHE_PARAM
103     orr r1, r1, r2
104     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
105
106     /* Invalidate L2 */
107     mov r1, #0x000000FF
108     str r1, [r0, #L2_CACHE_INV_WAY_REG]
109 L2_loop:
110     /* Poll Invalidate By Way register */
111     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
112     cmp r2, #0
113     bne L2_loop
114     /*** End of L2 operations ***/
115
116     mov r0, #SDRAM_NON_FLASH_BOOT
117     ldr r1, AVIC_VECTOR0_ADDR_W
118     str r0, [r1] // for checking boot source from nand, nor or sdram
119 /*
120  * End of ARM1136 init
121  */
122 init_spba_start:
123     init_spba
124 init_aips_start:
125     init_aips
126 init_max_start:
127     init_max
128 init_m3if_start:
129     init_m3if
130
131     init_drive_strength
132 init_cs0_start:
133 //    init_cs0_async
134     // Note: enabling above setup causes the following "mov r0, #NOR_FLASH_BOOT"
135     // loading r0=0xb8002000 instead of NOR_FLASH_BOOT(0x0). This can be fixed
136     // by force aligning this "mov r0, #NOR_FLASH_BOOT" to 32-byte boundry. 
137     // Remove it now as it is really not needed anyway.
138
139     // If SDRAM has been setup, bypass clock/WEIM setup
140     cmp pc, #SDRAM_BASE_ADDR
141     blo init_clock_start
142     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
143     blo HWInitialise_skip_SDRAM_setup
144
145     mov r0, #NOR_FLASH_BOOT
146     ldr r1, AVIC_VECTOR0_ADDR_W
147     str r0, [r1]
148
149     // Disable the SDCLK by clearing SDE (bit 31) in ESDCTL0 and ESDCTL1
150     // (as the DDR chip needs a stable clock after CKE is high)
151     ldr r0, ESDCTL_BASE_W
152     ldr r1, SDRAM_0x02216080
153     str r1, [r0, #ESDCTL_ESDCTL0]
154     str r1, [r0, #ESDCTL_ESDCTL1]
155
156 init_clock_start:
157     init_clock
158
159 init_sdram_start:
160     init_ddr_sdram
161
162 HWInitialise_skip_SDRAM_setup:
163
164     mov r0, #NFC_BASE
165     add r2, r0, #0x800      // 2K window
166     cmp pc, r0
167     blo Normal_Boot_Continue
168     cmp pc, r2
169     bhi Normal_Boot_Continue
170 NAND_Boot_Start:
171     /* Copy image from flash to SDRAM first */
172     ldr r1, MXC_REDBOOT_ROM_START
173
174 1:  ldmia r0!, {r3-r10}
175     stmia r1!, {r3-r10}
176     cmp r0, r2
177     blo 1b
178     /* Jump to SDRAM */
179     ldr r1, CONST_0x0FFF
180     and r0, pc, r1     /* offset of pc */
181     ldr r1, MXC_REDBOOT_ROM_START
182     add r1, r1, #0x10
183     add pc, r0, r1
184     nop
185     nop
186     nop
187     nop
188 NAND_Copy_Main:
189     mov r0, #NAND_FLASH_BOOT
190     ldr r1, AVIC_VECTOR0_ADDR_W
191     str r0, [r1]
192     mov r0, #MXCFIS_NAND
193     ldr r1, AVIC_VECTOR1_ADDR_W
194     str r0, [r1]
195
196     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
197     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
198     add r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
199     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
200     ldr r14, MXC_REDBOOT_ROM_START
201     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
202     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
203
204     //unlock internal buffer
205     mov r3, #0x2
206     strh r3, [r12, #0xA]
207
208 Nfc_Read_Page:
209 //  writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
210     mov r3, #0x0;
211     strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
212     mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
213     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
214     do_wait_op_done
215
216 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
217     mov r3, r1
218     do_addr_input       //1st addr cycle
219     mov r3, r1, lsr #9
220     do_addr_input       //2nd addr cycle
221     mov r3, r1, lsr #17
222     do_addr_input       //3rd addr cycle
223     mov r3, r1, lsr #25
224     do_addr_input       //4th addr cycle
225
226 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
227 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
228 //               NAND_FLASH_CONFIG1_REG);
229     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
230     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
231
232 //        writew(buf_no, RAM_BUFFER_ADDRESS_REG);
233     mov r3, #0
234     strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
235 //        writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
236     mov r3, #FDO_PAGE_SPARE_VAL
237     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
238 //        wait_op_done();
239     do_wait_op_done
240
241     // check for bad block
242     mov r3, r1, lsl #(32-5-9)
243     cmp r3, #(512 << (32-5-9))
244     bhi Copy_Good_Blk
245     add r4, r0, #0x800  //r3 -> spare area buf 0
246     ldrh r4, [r4, #0x4]
247     and r4, r4, #0xFF00
248     cmp r4, #0xFF00
249     beq Copy_Good_Blk
250     // really sucks. Bad block!!!!
251     cmp r3, #0x0
252     beq Skip_bad_block
253     // even suckier since we already read the first page!
254     sub r14, r14, #512  //rewind 1 page for the sdram pointer
255     sub r1, r1, #512    //rewind 1 page for the flash pointer
256 Skip_bad_block:
257     add r1, r1, #(32*512)
258     b Nfc_Read_Page
259 Copy_Good_Blk:
260     //copying page
261 1:  ldmia r0!, {r3-r10}
262     stmia r14!, {r3-r10}
263     cmp r0, r2
264     blo 1b
265     cmp r14, r13
266     bge NAND_Copy_Main_done
267     add r1, r1, #0x200
268     mov r0, #NFC_BASE
269     b Nfc_Read_Page
270
271 NAND_Copy_Main_done:
272
273 Normal_Boot_Continue:
274
275 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
276     /* Copy image from flash to SDRAM first */
277     ldr r0, =0xFFFFF000
278     and r0, r0, pc
279     ldr r1, MXC_REDBOOT_ROM_START
280     cmp r0, r1
281     beq HWInitialise_skip_SDRAM_copy
282
283     add r2, r0, #REDBOOT_IMAGE_SIZE
284
285 1:  ldmia r0!, {r3-r10}
286     stmia r1!, {r3-r10}
287     cmp r0, r2
288     ble 1b
289     /* Jump to SDRAM */
290     ldr r1, =0xFFFF
291     and r0, pc, r1         /* offset of pc */
292     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
293     add pc, r0, r1
294     nop
295     nop
296     nop
297     nop
298 #endif /* CYG_HAL_STARTUP_ROMRAM */
299
300 HWInitialise_skip_SDRAM_copy:
301     init_dsp
302 init_cs2_start:
303     init_cs2
304 init_cs0_sync_start:
305     init_cs0_sync
306
307 NAND_ClockSetup:
308
309 /*
310  * Note:
311  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
312  */
313
314 STACK_Setup:
315     // Set up a stack [for calling C code]
316     ldr r1, =__startup_stack
317     ldr r2, =RAM_BANK0_BASE
318     orr sp, r1, r2
319
320     // Create MMU tables
321     bl hal_mmu_init
322
323     // Enable MMU
324     ldr r2, =10f
325     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
326     orr r1, r1, #7                          // enable MMU bit
327     orr r1, r1, #0x800                      // enable z bit
328     mcr MMU_CP, 0, r1, MMU_Control, c0
329     mov pc,r2    /* Change address spaces */
330     nop
331     nop
332     nop
333 10:
334
335     // Save shadow copy of BCR, also hardware configuration
336     ldr r1, =_board_BCR
337     str r2, [r1]
338     ldr r1, =_board_CFG
339     str r9, [r1]                // Saved far above...
340
341     .endm                       // _platform_setup1
342
343 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
344 #define PLATFORM_SETUP1
345 #endif
346
347     /* Allow all 3 masters to have access to these shared peripherals */
348     .macro  init_spba
349         ldr r0, SPBA_CTRL_BASE_ADDR_W
350         add r4, r0, #0x38
351         ldr r1, =0x7            /* allow all 3 masters access */
352         ldr r2, SPBA_LOCK_VAL
353 spba_continue:
354         str r1, [r0]
355 spba_check_loop:
356         ldr r3, [r0]
357         cmp r2, r3
358         bne spba_check_loop
359         add r0, r0, #4
360         cmp r0, r4
361         ble spba_continue
362     .endm  /* init_spba */
363
364     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
365     .macro init_aips
366         /*
367          * Set all MPROTx to be non-bufferable, trusted for R/W,
368          * not forced to user-mode.
369          */
370         ldr r0, AIPS1_CTRL_BASE_ADDR_W
371         ldr r1, AIPS1_PARAM_W
372         str r1, [r0, #0x00]
373         str r1, [r0, #0x04]
374         ldr r0, AIPS2_CTRL_BASE_ADDR_W
375         str r1, [r0, #0x00]
376         str r1, [r0, #0x04]
377
378         /*
379          * Clear the on and off peripheral modules Supervisor Protect bit
380          * for SDMA to access them. Did not change the AIPS control registers
381          * (offset 0x20) access type
382          */
383         ldr r0, AIPS1_CTRL_BASE_ADDR_W
384         ldr r1, =0x0
385         str r1, [r0, #0x40]
386         str r1, [r0, #0x44]
387         str r1, [r0, #0x48]
388         str r1, [r0, #0x4C]
389         ldr r1, [r0, #0x50]
390         and r1, r1, #0x00FFFFFF
391         str r1, [r0, #0x50]
392
393         ldr r0, AIPS2_CTRL_BASE_ADDR_W
394         ldr r1, =0x0
395         str r1, [r0, #0x40]
396         str r1, [r0, #0x44]
397         str r1, [r0, #0x48]
398         str r1, [r0, #0x4C]
399         ldr r1, [r0, #0x50]
400         and r1, r1, #0x00FFFFFF
401         str r1, [r0, #0x50]
402     .endm /* init_aips */
403
404     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
405     .macro init_max
406         ldr r0, MAX_BASE_ADDR_W
407         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
408         ldr r1, MAX_PARAM1
409         str r1, [r0, #0x000]        /* for S0 */
410         str r1, [r0, #0x100]        /* for S1 */
411         str r1, [r0, #0x200]        /* for S2 */
412         str r1, [r0, #0x300]        /* for S3 */
413         str r1, [r0, #0x400]        /* for S4 */
414         /* SGPCR - always park on last master */
415         ldr r1, =0x10
416         str r1, [r0, #0x010]        /* for S0 */
417         str r1, [r0, #0x110]        /* for S1 */
418         str r1, [r0, #0x210]        /* for S2 */
419         str r1, [r0, #0x310]        /* for S3 */
420         str r1, [r0, #0x410]        /* for S4 */
421         /* MGPCR - restore default values */
422         ldr r1, =0x0
423         str r1, [r0, #0x800]        /* for M0 */
424         str r1, [r0, #0x900]        /* for M1 */
425         str r1, [r0, #0xA00]        /* for M2 */
426         str r1, [r0, #0xB00]        /* for M3 */
427         str r1, [r0, #0xC00]        /* for M4 */
428         str r1, [r0, #0xD00]        /* for M5 */
429     .endm /* init_max */
430
431     /* Clock setup */
432     .macro init_clock
433 #ifdef CLOCK_SETUP_ALIGNED
434         b 1f
435         .ALIGN 5
436     1:
437 #endif
438         ldr r0, CRM_MCU_BASE_ADDR_W
439         // enable MPLL, UPLL, TurboPLL
440         ldr r1, CRM_MCR_0x18FF2952
441         str r1, [r0, #CLKCTL_MCR]
442
443 check_pll_lock:
444         ldr r1, [r0, #CLKCTL_MCR]
445         and r1, r1, #0x8C
446         cmp r1, #0x8C
447         bne check_pll_lock
448 #if 1  // for 133MHz HCLK
449         ldr r1, TPCTL_PARAM_532_W
450         str r1, [r0, #CLKCTL_TPCTL]
451         ldr r1, PDR0_399_133_66_W
452 #else
453         ldr r1, TPCTL_PARAM_500_W
454         str r1, [r0, #CLKCTL_TPCTL]
455         ldr r1, PDR0_399_100_50_W
456 #endif
457
458         // add some delay here
459         mov r2, #0x1000
460     1:  subs r2, r2, #0x1
461         bne 1b
462
463 #ifdef CLOCK_SETUP_ALIGNED
464         b 1f
465         .ALIGN 5
466     1:
467 #endif
468         str r1, [r0, #CLKCTL_PDR0]
469         ldr r1, MPCTL_PARAM_399_W
470         str r1, [r0, #CLKCTL_MPCTL]
471
472         /* Set to default values */
473         ldr r1, PDR1_0x2910AC56_W
474         str r1, [r0, #CLKCTL_PDR1]
475         /* Set UPLL=288MHz */
476         ldr r1, UPCTL_PARAM_288_W
477         str r1, [r0, #CLKCTL_UPCTL]
478
479         /*
480          * J10 (CPU card) - CKO1=MCU_PLL div by 8
481          * J9 (CPU card) - CKO2=IPG_CLK_ARM div by 8
482          */
483         ldr r1, CRM_COSR_0x00036C58
484         str r1, [r0, #CLKCTL_COSR]
485     .endm /* init_clock */
486
487     /* M3IF setup */
488     .macro init_m3if
489         /* Configure M3IF registers */
490         ldr r1, M3IF_BASE_W
491         /*
492         * M3IF Control Register (M3IFCTL)
493         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
494         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
495         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
496         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
497         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
498         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
499         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
500         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
501         *                                                       ------------
502         *                                                       0x00000040
503         */
504         ldr r0, =0x00000040
505         str r0, [r1]  /* M3IF control reg */
506     .endm /* init_m3if */
507
508     /* CS0 sync mode setup */
509     .macro init_cs0_sync
510         // setup the sync mode in the flash itself first
511         mov r0, #CS0_BASE_ADDR
512         add r0, r0, #0x00004300
513         mov r1, #0x60
514         strh r1, [r0, #0x9E]
515         mov r1, #0x03
516         strh r1, [r0, #0x9E]
517         // setup the sync mode in the WEIM
518         ldr r0, WEIM_BASE_ADDR_W
519         ldr r1, CS0_CSCRU_0x23D29000
520         str r1, [r0, #CSCRU]
521         ldr r1, CS0_CSCRL_0x60000D01
522         str r1, [r0, #CSCRL]
523         mov r1, #0x00000080
524         str r1, [r0, #CSCRA]
525     .endm /* init_cs0_sync */
526
527     /* CS0 async mode setup */
528     .macro init_cs0_async
529         // setup the async mode in the flash itself first
530         mov r0, #CS0_BASE_ADDR
531         add r0, r0, #0x00017000
532         add r0, r0, #0x00000700
533         mov r1, #0x60
534         strh r1, [r0, #0x9E]
535         mov r1, #0x03
536         strh r1, [r0, #0x9E]
537         /* CS0 setup: Configuring the CS0 in Asynchronous mode */
538         ldr r0, WEIM_BASE_ADDR_W        /* 0xB8002000 */
539         ldr r1, CS0_CSCRU_0x23C29000    /* no sync/burst */
540         str r1, [r0, #CSCRU]            /* +0x00 */
541         ldr r1, CS0_CSCRL_0x60000D01    /* 16-bit port, CS enabled */
542         str r1, [r0, #CSCRL]            /* +0x04 */
543         mov r1, #0x00000080             /* decrease Write Wait State enabled */
544         str r1, [r0, #CSCRA]            /* +0x08 */
545     .endm /* init_cs0_async */
546
547     /* CS2 setup */
548     .macro init_cs2
549         ldr r0, =0x50000030
550         ldr r1, =0x00200000
551         str r1, [r0]
552         ldr r0, =WEIM_CTRL_CS2
553         ldr r1, =0x0000DCF6
554         str r1, [r0, #CSCRU]
555         ldr r1, =0x444A4531
556         str r1, [r0, #CSCRL]
557         ldr r1, =0x44443302
558         str r1, [r0, #CSCRA]
559     .endm /* init_cs2 */
560
561 // DDR SDRAM setup
562     .macro  init_ddr_sdram
563         ldr r0, ESDCTL_BASE_W
564         ldr r2, IOMUXC_BASE_ADDR_W
565         mov r12, #SDRAM_BASE_ADDR
566
567         // 3.   Enable the SDCLK by setting SDE (bit 31) in ESDCTL1
568         //      reg32_write(ESDCTL1, 0x82216080);
569         ldr r1, SDRAM_0x02216080
570         add r1, r1, #0x80000000
571         str r1, [r0, #ESDCTL_ESDCTL1]
572         // 4.   Put the CSD0 controller in Manual Self Refresh, with SREFR=0 
573         //      and PWDT=2 or 3. This step is needed to be able to enter properly 
574         //      the Low Power modes
575         //      reg32_write(ESDCTL0, (0xc2216080 & 0xffff13ff) + (3<<10));
576         ldr r1, SDRAM_0x02210C80
577         str r1, [r0, #ESDCTL_ESDCTL0]
578         // 5.   Wait for the SDRAMRDY bit (bit 31 in ESDMISC) to be set. This bit 
579         //      indicates that the SDRAM is ready for use.
580      1:
581         ldr r1, [r0, #ESDCTL_ESDMISC]
582         ands r1, r1, #0x80000000
583         beq 1b
584         // 6. Reset the ESDCTL and the ESDCTL delay lines:
585         //          reg32_write(ESDMISC, 0x000000f)
586         mov r1, #0xF
587         str r1, [r0, #ESDCTL_ESDMISC]
588         // 7.   Set the proper delay lines correction:
589         //      reg32_write(ESDCDLY1, 0x00280000);
590         //      reg32_write(ESDCDLY2, 0x00280000);
591         //      reg32_write(ESDCDLY5, 0x003e0000);
592         //      For Read, only ESDCDLY1 and ESDCDLY2 have to be initialized, as 16 
593         //      bit memory is used.
594         mov r1, #0x00280000
595         str r1, [r0, #ESDCTL_ESDCDLY1]
596         str r1, [r0, #ESDCTL_ESDCDLY2]
597         mov r1, #0x003e0000
598         str r1, [r0, #ESDCTL_ESDCDLY5]
599         // 8.   Configure the ESDCTL timing parameters (see Table 4 for details):
600         //      reg32_write(ESDCFG1, 0x00795729);
601         ldr r1, SDRAM_0x00795729
602         str r1, [r0, #ESDCTL_ESDCFG1]
603         // 9.   Remove ESDRAMC reset (this step is not mandatory, as the RST bit in 
604         //      ESDMISC is auto-clearing)
605         //      reg32_write(ESDMISC, 0x0000000d);
606         mov r1, #0xD
607         str r1, [r0, #ESDCTL_ESDMISC]
608         // 10.  Set the pads drive strengths / DDR mode (MCU accesses):
609         //      reg32_write(0x500003d0, 0x00000007);//sw_pad_ctl_sdqs0="111"
610         //      reg32_write(0x500003c4, 0x00001800);//sw_pad_ctl_oe_b="110"
611         //      reg32_write(0x500003C8, 0x00700000);//sw_pad_ctl_dqm0="111"
612         //      reg32_write(0x500003F8, 0x00700000);//sw_pad_ctl_sd0="111" 
613         //      reg32_write(0x5000041C, 0x00700000);//sw_pad_ctl_a0_ma0='111'
614 #if 1
615         add r2, r2, #0x300
616         mov r1, #0x00000007
617         str r1, [r2, #0xD0]
618         mov r1, #0x00001800
619         str r1, [r2, #0xC4]
620         mov r1, #0x00700000
621         str r1, [r2, #0xC8]
622         str r1, [r2, #0xF8]
623         str r1, [r2, #0x11C]
624 #endif
625
626         // 11.  Wait for 200us (as the DDR clock must be stable for at least 
627         //      200us and the delay line measurement needs at least 16us after 
628         //      a reset before being operational).
629         ldr r1, =0x10000
630      1:
631         subs r1, r1, #0x1
632         bne 1b
633
634         // 12.  Send a Precharge command to all banks, using a Byte access with A10 high.
635         //      reg32_write(ESDCTL1, 0x92216080);
636         //      reg8_write(0x90000400, 0x00);
637         ldr r1, SDRAM_0x92216080
638         str r1, [r0, #ESDCTL_ESDCTL1]
639         ldr r1, =0x0
640         strb r1, [r12, #0x400]
641
642         // 13.  Send (at least) 2 AutoRefresh commands. They must be separated by at 
643         //      least tRFC = 75ns (10 tck at 133 MHz)
644         //      reg32_write(ESDCTL1, 0xA2216080);
645         //      reg16_write(0x90000000, 0x0000);
646         //      delay();
647         //      reg16_write(0x90000000, 0x0000);
648         ldr r1, SDRAM_0xA2216080
649         str r1, [r0, #ESDCTL_ESDCTL1]
650         ldr r1, =0x0
651         strh r1, [r12]
652
653         ldr r1, =0x1000
654      1:
655         subs r1, r1, #0x1
656         bne 1b
657
658         ldr r1, =0x0
659         strh r1, [r12]
660         // 14.  Place the SDCTL in Load Mode Register Command mode
661         //      reg32_write(ESDCTL1, 0xB2216080);
662         ldr r1, SDRAM_0xB2216080
663         str r1, [r0, #ESDCTL_ESDCTL1]
664         // 15.  Set the DDR Mode Register. Set the Burst Size to 8, the Burst Mode 
665         //      to Sequential, the CAS latency to 3. Byte Access is required.
666         //      reg8_write(0x90000033, 0x00);
667         ldr r1, =0x0
668         strb r1, [r12, #0x33]
669         // 16.  Set the DDR Extended Mode Register. The DDR drive strength should 
670         //      be set to Full Drive. The access is done in Bank 2. A Byte Access
671         //      is required. 
672         //      (There should be at least tMRD = 15ns between the access to MR 
673         //      and EMR, but this is taken care by SDCTL).
674         //      reg8_write(0x92000000, 0x00);
675         add r11, r12, #0x02000000
676         strb r1, [r11]
677         // 17.  Put the DDR controller in Normal operating mode
678         //      reg32_write(ESDCTL1, 0x82216080);
679         ldr r3, SDRAM_0x82216080     /* 16 bit memory */
680         str r3, [r0, #ESDCTL_ESDCTL1]
681         // 18.  Perform a 16-bit Read
682         //      reg32_read(0x90000000);
683         ldrh r1, [r12]
684     .endm
685
686     .macro do_wait_op_done
687     1:
688         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
689         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
690         beq 1b
691         mov r3, #0x0
692         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
693     .endm   // do_wait_op_done
694
695     .macro do_addr_input
696         and r3, r3, #0xFF
697         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
698         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
699         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
700         do_wait_op_done
701     .endm   // do_addr_input
702
703     /* To support 133MHz SDR */
704     .macro  init_drive_strength
705         // No need to change the default drive strength for DDR
706     .endm /* init_drive_strength */
707
708     .macro init_dsp
709 /*
710  * Deal with DSP reset
711  */
712         /* Set DSP to LE */
713         ldr r0, =0x5001C808
714         ldr r1, [r0]
715         tst r1, #(1 << 5)
716         beq skip_dsp_switch_le
717         bic r1, r1, #(1 << 5)
718         str r1, [r0]
719     skip_dsp_switch_le:
720         ldr r0, =0x43F84024
721         /* Put DSP in reset */
722         ldr r1, =0x00000010
723         str r1, [r0]
724
725         /* Hold for some time */
726         ldr r2, =0x80000
727 dsp_reset_delay:
728         subs r2, r2, #0x1
729         bne dsp_reset_delay
730
731         /* Put DSP out of reset */
732         ldr r1, =0x0
733         str r1, [r0]
734     .endm /* init_dsp */
735 #define PLATFORM_VECTORS         _platform_vectors
736     .macro  _platform_vectors
737         .globl  _board_BCR, _board_CFG
738 _board_BCR:   .long   0       // Board Control register shadow
739 _board_CFG:   .long   0       // Board Configuration (read at RESET)
740     .endm
741
742 #define PLATFORM_PREAMBLE _switch_to_le
743
744     .macro  _switch_to_le
745         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
746         .word 0xE3C00080        // bic r0, r0, #0x80
747         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
748
749         .word 0x0F10EE11        // mrc 15, 0, r0, c1, c0, 0
750         .word 0x0080E3C0        // bic r0, r0, #0x80
751         .word 0x0F10EE01        // mcr 15, 0, r0, c1, c0, 0
752         .word 0                 // dummy
753         .word 0                 // dummy
754         .word 0                 // dummy
755         .word 0                 // dummy
756         .word 0                 // dummy
757         .word 0                 // dummy
758         .word 0                 // dummy
759         .word 0                 // dummy
760         .word 0                 // dummy
761     .endm
762 #if 0 /// good for SDRAM since 32bit
763         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
764         .word 0xE3C00080        // bic r0, r0, #0x80
765         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
766 #endif
767
768 ARM_PPMRR:              .word   0x40000015
769 L2CACHE_PARAM:          .word   0x00030024
770 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
771 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
772 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
773 AIPS1_PARAM_W:          .word   0x77777777
774 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
775 MAX_PARAM1:             .word   0x00302154
776 RVAL_WVAL_W:            .word   0x515
777 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
778 CRM_MCR_0x18FF2902:     .word   0x18FF2902
779 CRM_MCR_0x18FF2952:     .word   0x18FF2952
780 CRM_COSR_0x00036C58:    .word   0x00036C58
781 PDR0_399_100_50_W:      .word   PDR0_399_100_50
782 PDR0_399_133_66_W:      .word   PDR0_399_133_66
783 PDR0_399_66_66_W:       .word   PDR0_399_66_66
784 PDR1_0x2910AC56_W:      .word   0x2910AC56
785 MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
786 UPCTL_PARAM_288_W:      .word   UPCTL_PARAM_288
787 TPCTL_PARAM_500_W:      .word   TPCTL_PARAM_500
788 TPCTL_PARAM_532_W:      .word   TPCTL_PARAM_532
789 SPBA_CTRL_BASE_ADDR_W:  .word   SPBA_CTRL_BASE_ADDR
790 SPBA_LOCK_VAL:          .word   0xC0010007
791 ESDCTL_BASE_W:          .word   ESDCTL_BASE
792 M3IF_BASE_W:            .word   M3IF_BASE
793 SDRAM_0x02216080:       .word   0x02216080
794 SDRAM_0x82216080:       .word   0x82216080
795 SDRAM_0x92216080:       .word   0x92216080
796 SDRAM_0xA2216080:       .word   0xA2216080
797 SDRAM_0xB2216080:       .word   0xB2216080
798 SDRAM_0x00795729:       .word   0x00795729
799 SDRAM_0x02210C80:       .word   0x02210C80
800 WEIM_BASE_ADDR_W:       .word   WEIM_BASE_ADDR
801 CS0_CSCRU_0x23C29000:   .word   0x23C29000
802 CS0_CSCRL_0x60000D01:   .word   0x60000D01
803 CS0_CSCRU_0x23D29000:   .word   0x23D29000
804 DS_0x12449D24:          .word   0x12449D24
805 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
806 CRM_MCU_BASE_ADDR_W:    .word   CRM_MCU_BASE_ADDR
807 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
808 CONST_0x0FFF:           .word   0x0FFF
809 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
810 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
811
812 /*---------------------------------------------------------------------------*/
813 /* end of hal_platform_setup.h                                               */
814 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */