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