]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91321/evb/v2_0/include/hal_platform_setup.h
2b0fcc5627ab69bf0afce3c84b597a6097d8d880
[karo-tx-redboot.git] / packages / hal / arm / mxc91321 / 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 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 #define DEBUG_UART_BASE         UART3_BASE_ADDR
67
68 #if 0
69 #define UNALIGNED_ACCESS_ENABLE
70 #define SET_T_BIT_DISABLE
71 #define BRANCH_PREDICTION_ENABLE
72 #endif
73
74 //#define TURN_OFF_IMPRECISE_ABORT
75
76 // This macro represents the initial startup code for the platform
77 // r11 is reserved to contain chip rev info in this file
78     .macro  _platform_setup1
79 FSL_BOARD_SETUP_START:
80 /*
81  *       ARM1136 init
82  *       - invalidate I/D cache/TLB and drain write buffer;
83  *       - invalidate L2 cache
84  *       - unaligned access
85  *       - branch predictions
86  */
87 #ifdef TURN_OFF_IMPRECISE_ABORT
88     mrs r0, cpsr
89     bic r0, r0, #0x100
90     msr cpsr, r0
91 #endif
92
93     mov r0, #0
94     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
95     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
96     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
97
98     /* Also setup the Peripheral Port Remap register inside the core */
99     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
100     mcr p15, 0, r0, c15, c2, 4
101
102     /*** L2 Cache setup/invalidation/disable ***/
103     /* Disable L2 cache first */
104     mov r0, #L2CC_BASE_ADDR
105     ldr r2, [r0, #L2_CACHE_CTL_REG]
106     bic r2, r2, #0x1
107     str r2, [r0, #L2_CACHE_CTL_REG]
108     /*
109      * Configure L2 Cache:
110      * - 128k size(16k way)
111      * - 8-way associativity
112      * - 0 ws TAG/VALID/DIRTY
113      * - 4 ws DATA R/W
114      */
115     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
116     and r1, r1, #0xFE000000
117     ldr r2, L2CACHE_PARAM
118     orr r1, r1, r2
119     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
120
121     /* Invalidate L2 */
122     mov r1, #0x000000FF
123     str r1, [r0, #L2_CACHE_INV_WAY_REG]
124 L2_loop:
125     /* Poll Invalidate By Way register */
126     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
127     cmp r2, #0
128     bne L2_loop
129     /*** End of L2 operations ***/
130
131     mov r0, #SDRAM_NON_FLASH_BOOT
132     ldr r1, AVIC_VECTOR0_ADDR_W
133     str r0, [r1] // for checking boot source from nand, nor or sdram
134 /*
135  * End of ARM1136 init
136  */
137 init_spba_start:
138     init_spba
139 init_aips_start:
140     init_aips
141 init_max_start:
142     init_max
143 init_m3if_start:
144     init_m3if
145
146     mov r11, #CHIP_REV_2_0
147     ldr r0, IIM_SREV_REG_VAL
148     ldr r1, [r0, #0x0]
149     cmp r1, #0x0
150     movne r11, #CHIP_REV_2_1
151     init_drive_strength
152 init_cs0_async_start:
153 //    init_cs0_async
154
155     /* If SDRAM has been setup, bypass clock/WEIM setup */
156     cmp pc, #SDRAM_BASE_ADDR
157     blo init_clock_start
158     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
159     blo HWInitialise_skip_SDRAM_setup
160
161     mov r0, #NOR_FLASH_BOOT
162     ldr r1, AVIC_VECTOR0_ADDR_W
163     str r0, [r1]
164
165 init_clock_start:
166     init_clock
167
168     /* Based on chip rev, setup params for SDRAM controller */
169 #if 0      // remove code for "old" chip that require for SDRAM full-page workaround
170     ldr r10, =0
171     mov r4, #SDRAM_FULL_PAGE_MODE
172     cmp r11, #CHIP_REV_2_0
173     moveq r10, #SDRAM_FULL_PAGE_BIT
174     movgt r4, #SDRAM_BURST_MODE
175 #endif
176
177     ldr r10, =0
178     mov r4, #SDRAM_BURST_MODE
179
180 init_sdram_start:
181
182     /* Assuming DDR memory first */
183     init_ddr_sdram
184     /* Testing if it is truly DDR */
185     ldr r1, SDRAM_COMPARE_CONST1
186     mov r0, #SDRAM_BASE_ADDR
187     str r1, [r0]
188     ldr r2, SDRAM_COMPARE_CONST2
189     str r2, [r0, #0x4]
190     ldr r2, [r0]
191     cmp r1, r2
192     beq HWInitialise_skip_SDRAM_setup
193
194     /* Reach here ONLY when SDR */
195     ldr r3, SDRAM_SDR_X32_W     /* 32 bit memory */
196     add r3, r3, r10         /* adjust for full-page mode if necessary */
197     init_sdr_sdram
198     /* Test to make sure SDR */
199     ldr r1, SDRAM_COMPARE_CONST1
200     mov r0, #SDRAM_BASE_ADDR
201     str r1, [r0]
202     ldr r2, SDRAM_COMPARE_CONST2
203     str r2, [r0, #0x4]
204     ldr r2, [r0]
205     cmp r1, r2
206     beq HWInitialise_skip_SDRAM_setup
207
208     ldr r3, SDRAM_SDR_X16_W     /* 16 bit memory */
209     add r3, r3, r10         /* adjust for full-page mode if necessary */
210     init_sdr_sdram
211     /* Test to make sure SDR */
212     ldr r1, SDRAM_COMPARE_CONST1
213     mov r0, #SDRAM_BASE_ADDR
214     str r1, [r0]
215     ldr r2, SDRAM_COMPARE_CONST2
216     str r2, [r0, #0x4]
217     ldr r2, [r0]
218     cmp r1, r2
219     beq HWInitialise_skip_SDRAM_setup
220
221     /* Reach hear means memory setup problem. Try to
222      * increase the HCLK divider */
223     ldr r0, CRM_MCU_BASE_ADDR_W
224     ldr r1, [r0, #CLKCTL_PDR0]
225     and r2, r1, #0x38
226     cmp r2, #0x38
227     beq loop_forever
228     add r1, r1, #0x8
229     str r1, [r0, #CLKCTL_PDR0]
230     b init_sdram_start
231
232 loop_forever:
233     b loop_forever  /* shouldn't get here */
234
235 HWInitialise_skip_SDRAM_setup:
236
237     mov r0, #NFC_BASE
238     add r2, r0, #0x800      // 2K window
239     cmp pc, r0
240     blo Normal_Boot_Continue
241     cmp pc, r2
242     bhi Normal_Boot_Continue
243 NAND_Boot_Start:
244     /* Copy image from flash to SDRAM first */
245     ldr r1, MXC_REDBOOT_ROM_START
246
247 1:  ldmia r0!, {r3-r10}
248     stmia r1!, {r3-r10}
249     cmp r0, r2
250     blo 1b
251     /* Jump to SDRAM */
252     ldr r1, CONST_0x0FFF
253     and r0, pc, r1     /* offset of pc */
254     ldr r1, MXC_REDBOOT_ROM_START
255     add r1, r1, #0x10
256     add pc, r0, r1
257     nop
258     nop
259     nop
260     nop
261 NAND_Copy_Main:
262     mov r0, #NAND_FLASH_BOOT
263     ldr r1, AVIC_VECTOR0_ADDR_W
264     str r0, [r1]
265     mov r0, #MXCFIS_NAND
266     ldr r1, AVIC_VECTOR1_ADDR_W
267     str r0, [r1]
268
269     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
270     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
271     add r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
272     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
273     ldr r14, MXC_REDBOOT_ROM_START
274     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
275     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
276
277     //unlock internal buffer
278     mov r3, #0x2
279     strh r3, [r12, #0xA]
280
281 Nfc_Read_Page:
282 //  writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
283     mov r3, #0x0;
284     strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
285     mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
286     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
287     do_wait_op_done
288
289 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
290     mov r3, r1
291     do_addr_input       //1st addr cycle
292     mov r3, r1, lsr #9
293     do_addr_input       //2nd addr cycle
294     mov r3, r1, lsr #17
295     do_addr_input       //3rd addr cycle
296
297 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
298 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
299 //               NAND_FLASH_CONFIG1_REG);
300     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
301     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
302
303 //        writew(buf_no, RAM_BUFFER_ADDRESS_REG);
304     mov r3, #0
305     strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
306 //        writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
307     mov r3, #FDO_PAGE_SPARE_VAL
308     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
309 //        wait_op_done();
310     do_wait_op_done
311
312     // check for bad block
313     mov r3, r1, lsl #(32-5-9)
314     cmp r3, #(512 << (32-5-9))
315     bhi Copy_Good_Blk
316     add r4, r0, #0x800  //r3 -> spare area buf 0
317     ldrh r4, [r4, #0x4]
318     and r4, r4, #0xFF00
319     cmp r4, #0xFF00
320     beq Copy_Good_Blk
321     // really sucks. Bad block!!!!
322     cmp r3, #0x0
323     beq Skip_bad_block
324     // even suckier since we already read the first page!
325     sub r14, r14, #512  //rewind 1 page for the sdram pointer
326     sub r1, r1, #512    //rewind 1 page for the flash pointer
327 Skip_bad_block:
328     add r1, r1, #(32*512)
329     b Nfc_Read_Page
330 Copy_Good_Blk:
331     //copying page
332 1:  ldmia r0!, {r3-r10}
333     stmia r14!, {r3-r10}
334     cmp r0, r2
335     blo 1b
336     cmp r14, r13
337     bge NAND_Copy_Main_done
338     add r1, r1, #0x200
339     mov r0, #NFC_BASE
340     b Nfc_Read_Page
341
342 NAND_Copy_Main_done:
343
344 Normal_Boot_Continue:
345
346 init_cs4_start:
347     init_cs4
348
349 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
350     /* Copy image from flash to SDRAM first */
351     ldr r0, =0xFFFFF000
352     and r0, r0, pc
353     ldr r1, MXC_REDBOOT_ROM_START
354     cmp r0, r1
355     beq HWInitialise_skip_SDRAM_copy
356
357     add r2, r0, #REDBOOT_IMAGE_SIZE
358
359 1:  ldmia r0!, {r3-r10}
360     stmia r1!, {r3-r10}
361     cmp r0, r2
362     ble 1b
363     /* Jump to SDRAM */
364     ldr r1, =0xFFFF
365     and r0, pc, r1         /* offset of pc */
366     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
367     add pc, r0, r1
368     nop
369     nop
370     nop
371     nop
372 #endif /* CYG_HAL_STARTUP_ROMRAM */
373
374 HWInitialise_skip_SDRAM_copy:
375     init_dsp
376 #ifdef CYGPKG_HAL_ARM_MXC91331_CHIP
377 //FIXME! DDTS: TLSbo58944
378 //    init_cs0_sync
379 #endif
380 #ifdef CYGPKG_HAL_ARM_MXC91321_CHIP
381     init_cs0_sync
382 //    init_cs0_async
383 #endif
384 NAND_ClockSetup:
385
386 /*
387  * Note:
388  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
389  */
390
391 STACK_Setup:
392     // Set up a stack [for calling C code]
393     ldr r1, =__startup_stack
394     ldr r2, =RAM_BANK0_BASE
395     orr sp, r1, r2
396
397     // Create MMU tables
398     bl hal_mmu_init
399
400     // Enable MMU
401     ldr r2, =10f
402     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
403     orr r1, r1, #7                          // enable MMU bit
404     mcr MMU_CP, 0, r1, MMU_Control, c0
405     mov pc,r2    /* Change address spaces */
406     nop
407     nop
408     nop
409 10:
410
411     // Save shadow copy of BCR, also hardware configuration
412     ldr r1, =_board_BCR
413     str r2, [r1]
414     ldr r1, =_board_CFG
415     str r9, [r1]                // Saved far above...
416
417     .endm                       // _platform_setup1
418
419 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
420 #define PLATFORM_SETUP1
421 #endif
422
423     /* Allow all 3 masters to have access to these shared peripherals */
424     .macro  init_spba
425         ldr r0, SPBA_CTRL_BASE_ADDR_W
426         add r4, r0, #0x38
427         ldr r1, =0x7            /* allow all 3 masters access */
428         ldr r2, SPBA_LOCK_VAL
429 spba_continue:
430         str r1, [r0]
431 spba_check_loop:
432         ldr r3, [r0]
433         cmp r2, r3
434         bne spba_check_loop
435         add r0, r0, #4
436         cmp r0, r4
437         ble spba_continue
438     .endm  /* init_spba */
439
440     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
441     .macro init_aips
442         /*
443          * Set all MPROTx to be non-bufferable, trusted for R/W,
444          * not forced to user-mode.
445          */
446         ldr r0, AIPS1_CTRL_BASE_ADDR_W
447         ldr r1, AIPS1_PARAM_W
448         str r1, [r0, #0x00]
449         str r1, [r0, #0x04]
450         ldr r0, AIPS2_CTRL_BASE_ADDR_W
451         str r1, [r0, #0x00]
452         str r1, [r0, #0x04]
453
454         /*
455          * Clear the on and off peripheral modules Supervisor Protect bit
456          * for SDMA to access them. Did not change the AIPS control registers
457          * (offset 0x20) access type
458          */
459         ldr r0, AIPS1_CTRL_BASE_ADDR_W
460         ldr r1, =0x0
461         str r1, [r0, #0x40]
462         str r1, [r0, #0x44]
463         str r1, [r0, #0x48]
464         str r1, [r0, #0x4C]
465         ldr r1, [r0, #0x50]
466         and r1, r1, #0x00FFFFFF
467         str r1, [r0, #0x50]
468
469         ldr r0, AIPS2_CTRL_BASE_ADDR_W
470         ldr r1, =0x0
471         str r1, [r0, #0x40]
472         str r1, [r0, #0x44]
473         str r1, [r0, #0x48]
474         str r1, [r0, #0x4C]
475         ldr r1, [r0, #0x50]
476         and r1, r1, #0x00FFFFFF
477         str r1, [r0, #0x50]
478     .endm /* init_aips */
479
480     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
481     .macro init_max
482         ldr r0, MAX_BASE_ADDR_W
483         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
484         ldr r1, MAX_PARAM1
485         str r1, [r0, #0x000]        /* for S0 */
486         str r1, [r0, #0x100]        /* for S1 */
487         str r1, [r0, #0x200]        /* for S2 */
488         str r1, [r0, #0x300]        /* for S3 */
489         str r1, [r0, #0x400]        /* for S4 */
490         /* SGPCR - always park on last master */
491         ldr r1, =0x10
492         str r1, [r0, #0x010]        /* for S0 */
493         str r1, [r0, #0x110]        /* for S1 */
494         str r1, [r0, #0x210]        /* for S2 */
495         str r1, [r0, #0x310]        /* for S3 */
496         str r1, [r0, #0x410]        /* for S4 */
497         /* MGPCR - restore default values */
498         ldr r1, =0x0
499         str r1, [r0, #0x800]        /* for M0 */
500         str r1, [r0, #0x900]        /* for M1 */
501         str r1, [r0, #0xA00]        /* for M2 */
502         str r1, [r0, #0xB00]        /* for M3 */
503         str r1, [r0, #0xC00]        /* for M4 */
504         str r1, [r0, #0xD00]        /* for M5 */
505     .endm /* init_max */
506
507     /* Clock setup */
508     .macro init_clock
509         /* RVAL/WVAL for L2 cache memory */
510         ldr r0, RVAL_WVAL_W
511         ldr r1, CLKCTL_BASE_ADDR_W
512         str r0, [r1, #0x10]
513
514         /*
515          * Clock setup
516          * - These are the targeted speed settings (may not be true for now).
517          * Note: the default USBPLL seems to be 286MHz instead of 288MHz?
518
519           Module           Freq (MHz)   Note
520           =========================================================================
521           ARM core         399          ipg_clk_arm
522           AHB              133          known as "hclk", ipg_clk_max
523           IP               66.5         ipg_clk (also used as ipg_per_clk ???)
524           EMI              133          =hclk
525          */
526         ldr r0, CRM_MCU_BASE_ADDR_W
527 #ifdef CYGPKG_HAL_ARM_MXC91331_CHIP
528         ldr r1, CRM_MCR_0x18FF2902
529         str r1, [r0, #CLKCTL_MCR]
530 upll_lock:
531         ldr r1, [r0, #CLKCTL_MCR]
532         ands r1, r1, #0x80
533         beq upll_lock
534 #endif
535 #ifdef CYGPKG_HAL_ARM_MXC91321_CHIP
536         // enable MPLL, UPLL, TurboPLL
537         ldr r1, CRM_MCR_0x18FF2952
538         str r1, [r0, #CLKCTL_MCR]
539 check_pll_lock:
540         ldr r1, [r0, #CLKCTL_MCR]
541         and r1, r1, #0x8C
542         cmp r1, #0x8C
543         bne check_pll_lock
544 #endif
545         /*
546          * J10 (CPU card) - CKO1=MCU_PLL div by 8
547          * J9 (CPU card) - CKO2=IPG_CLK_ARM div by 8
548          */
549         ldr r1, CRM_COSR_0x00036C58
550         str r1, [r0, #CLKCTL_COSR]
551
552 #if defined(CYGPKG_HAL_ARM_MXC91331_CHIP)
553         ldr r1, =0x0
554         ldrb r2, [r1, #0x60]         /* See if pass 1 silicon */
555         cmp r2, #0x1
556         ldr r1, PDR0_399_100_50_W
557 //        ldr r1, PDR0_399_133_66_W
558         ldreq r1, PDR0_399_66_66_W    /* For pass 1, HCLK=66.5MHz*/
559 #elif defined(CYGPKG_HAL_ARM_MXC91321_CHIP)
560 #if 1  // for 133MHz HCLK
561         ldr r1, TPCTL_PARAM_532_W
562         str r1, [r0, #CLKCTL_TPCTL]
563         ldr r1, PDR0_399_133_66_W
564 #else
565         ldr r1, TPCTL_PARAM_500_W
566         str r1, [r0, #CLKCTL_TPCTL]
567         // add some delay here
568         mov r1, #0x100
569     1:  subs r1, r1, #0x1
570         bne 1b
571
572         ldr r1, PDR0_399_100_50_W
573 #endif
574 #endif
575         str r1, [r0, #CLKCTL_PDR0]
576         ldr r1, MPCTL_PARAM_399_W
577         str r1, [r0, #CLKCTL_MPCTL]
578
579         /* Set to default values */
580         ldr r1, PDR1_0x2910AC56_W
581         str r1, [r0, #CLKCTL_PDR1]
582         /* Set UPLL=288MHz */
583         ldr r1, UPCTL_PARAM_288_W
584         str r1, [r0, #CLKCTL_UPCTL]
585     .endm /* init_clock */
586
587     /* M3IF setup */
588     .macro init_m3if
589         /* Configure M3IF registers */
590         ldr r1, M3IF_BASE_W
591         /*
592         * M3IF Control Register (M3IFCTL)
593         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
594         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
595         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
596         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
597         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
598         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
599         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
600         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
601         *                                                       ------------
602         *                                                       0x00000040
603         */
604         ldr r0, =0x00000040
605         str r0, [r1]  /* M3IF control reg */
606     .endm /* init_m3if */
607
608     /* CS0 sync mode setup */
609     .macro init_cs0_sync
610         /*
611          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
612          */
613         /* Flash reset command */
614         mov     r0, #CS0_BASE_ADDR
615         ldr     r1, =0xF0F0
616         strh    r1, [r0]
617         /* 1st command */
618         ldr     r2, =0xAAA
619         add     r2, r2, r0
620         ldr     r1, =0xAAAA
621         strh    r1, [r2]
622         /* 2nd command */
623         ldr     r2, =0x554
624         add     r2, r2, r0
625         ldr     r1, =0x5555
626         strh    r1, [r2]
627         /* 3rd command */
628         ldr     r2, =0xAAA
629         add     r2, r2, r0
630         ldr     r1, =0xD0D0
631         strh    r1, [r2]
632         /* Write flash config register */
633         ldr     r1, =0x56CA
634         strh    r1, [r2]
635         /* Flash reset command */
636         ldr     r1, =0xF0F0
637         strh    r1, [r0]
638
639         ldr r0, WEIM_CTRL_CS0_W
640         ldr r1, =0x23524E80
641         str r1, [r0, #CSCRU]
642         ldr r1, =0x10000D03
643         str r1, [r0, #CSCRL]
644         ldr r1, =0x00720900
645         str r1, [r0, #CSCRA]
646     .endm /* init_cs0_sync */
647
648     /* CS0 async mode setup */
649     .macro init_cs0_async
650         /* Async flash mode */
651         ldr r0, WEIM_CTRL_CS0_W
652         ldr r1, CS0_CSCRU_0x11414C80
653         str r1, [r0, #CSCRU]
654         ldr r1, CS0_CSCRL_0x30000D03
655         str r1, [r0, #CSCRL]
656         ldr r1, CS0_CSCRA_0x00310800
657         str r1, [r0, #CSCRA]
658     .endm /* init_cs0_async */
659
660     /* CPLD on CS4 setup */
661     .macro init_cs4
662         ldr r0, =WEIM_CTRL_CS4
663         ldr r1, =0x0000D743
664         str r1, [r0, #CSCRU]
665         ldr r1, =0x42001521
666         str r1, [r0, #CSCRL]
667         ldr r1, =0x00430A00
668         str r1, [r0, #CSCRA]
669
670         ldr r0, CS4_BASE_ADDR_W
671         ldrh r1, [r0, #0x0]
672         and r0, r1, #0xFF00
673         cmp r0, #0x2000
674         bge done_cs4_setup
675
676         ldr r0, =WEIM_CTRL_CS4
677         ldr r1, =0x0000D843
678         str r1, [r0, #CSCRU]
679         ldr r1, =0x22252521
680         str r1, [r0, #CSCRL]
681         ldr r1, =0x22220A00
682         str r1, [r0, #CSCRA]
683
684 done_cs4_setup:
685
686     .endm /* init_cs4 */
687
688 // DDR SDRAM setup
689       * r4 = burst mode vs full-page mode */
690     .macro  init_ddr_sdram
691         ldr r3, SDRAM_0x82216080     /* 16 bit memory */
692         ldr r0, ESDCTL_BASE_W
693         mov r2, #SDRAM_BASE_ADDR
694         ldr r1, SDRAM_0x0079E73A
695         str r1, [r0, #0x4]
696         mov r1, #0x2            // reset
697         str r1, [r0, #0x10]
698         mov r1, #0x4            // DDR
699         str r1, [r0, #0x10]
700
701         // Hold for more than 200ns
702         mov r1, #0x10000
703     1:
704         subs r1, r1, #0x1
705         bne 1b
706
707         add r1, r3, #0x10000000
708         str r1, [r0]
709         mov r1, #0x0
710
711         add r12, r2, #0x400
712         strh r1, [r12]
713         add r1, r3, #0x20000000     // 0xA2216080
714         str r1, [r0]
715
716         mov r1, #0x0
717         strh r1, [r2]
718         strh r1, [r2]
719
720         add r1, r3, #0x30000000     // 0xB2216080
721         str r1, [r0]
722         mov r1, #0x0
723         strb r1, [r2, #0x33]
724         add r12, r2, #0x01000000
725         strh r1, [r12]
726
727         str r3, [r0]
728         strh r1, [r2]
729     .endm
730
731 // SDR SDRAM setup
732     /* r3 = value for ESDCTL0
733      * r4 = burst mode vs full-page mode */
734     .macro  init_sdr_sdram
735         ldr r0, ESDCTL_BASE_W
736         mov r2, #SDRAM_BASE_ADDR
737         ldr r1, SDRAM_0x0075E73A
738         str r1, [r0, #0x4]
739         ldr r1, =0x2            // reset
740         str r1, [r0, #0x10]
741         ldr r1, =0x0            // sdr
742         str r1, [r0, #0x10]
743
744         // Hold for more than 200ns
745         ldr r1, =0x10000
746 1:
747         subs r1, r1, #0x1
748         bne 1b
749
750         ldr r1, SDRAM_0x92126080
751         str r1, [r0]
752         ldr r1, =0x0
753         mov r12, #0x80000000
754         add r12, r12, #0x00000400
755         str r1, [r12]
756         ldr r1, SDRAM_0xA2126080
757         str r1, [r0]
758
759         ldr r1, =0x0
760         str r1, [r2]
761         str r1, [r2]
762
763         ldr r1, SDRAM_0xB2126180
764         str r1, [r0]
765
766         ldr r1, =0x0
767         strb r1, [r2, r4]
768         mov r12, #0x81000000
769         str r1, [r12]
770         str r3, [r0]
771         ldr r1, =0x0
772         str r1, [r2]
773     .endm
774
775     .macro do_wait_op_done
776 #if defined(CYGPKG_HAL_ARM_MXC91331_CHIP)
777         mov r3, #0x1000
778     1:
779         subs r3, r3, #0x1
780         bne 1b
781 #endif
782     1:
783         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
784         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
785         beq 1b
786         mov r3, #0x0
787         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
788     .endm   // do_wait_op_done
789
790     .macro do_addr_input
791         and r3, r3, #0xFF
792         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
793         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
794         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
795         do_wait_op_done
796     .endm   // do_addr_input
797
798     /* To support 133MHz SDR */
799     .macro  init_drive_strength
800         // max drive strength for all pads except SDQS0/1
801
802         ldr r0, IOMUXC_BASE_ADDR_W
803         add r0, r0, #0x300
804         //=========== set_drive_strenght_ctl_signals =======================
805         /* OE line sw_pad_ctl_dqm3_oe_b_cs0_b */
806         ldr r1, =0x00001800
807         str r1, [r0, #0xC4]
808
809         /* SDRAM DQMx lines sw_pad_ctl_dqm0_dqm1_dqm2 */
810         ldr r1, =0x00700000
811         str r1, [r0, #0xC8]
812
813         /* SDRAM SD16-SD31 data lines sw_pad_ctl_sd15_sd16_sd17 */
814         mov r1, #0x00001C00
815         str r1, [r0, #0xE4]
816
817         //============= set_drive_strength_ctl_data ========================
818         /* SDRAM SD0-SD15 data lines sw_pad_ctl_sd0_sd1_sd2 */
819         mov r1, #0x00700000
820         str r1, [r0, #0xF8]
821
822         //============= set_drive_strength_ctl_addr ========================
823         /* SDRAM address lines sw_pad_ctl_a0_ma0_a1_ma1_a2_ma2 */
824         mov r1, #0x00700000
825         str r1, [r0, #0x11C]
826
827         /* sw_pad_ctl_RAS */
828         mov r1, #0x00700000
829         str r1, [r0, #0xB0]
830
831         /* sw_pad_ctl_SDCLK */
832         mov r1, #0x00000007
833         str r1, [r0, #0xAC]
834
835         /* for SDRAM SDQS lines sw_pad_ctl_DQS0 */
836         mov r1, #0x00000007
837         str r1, [r0, #0xD0]
838         // Add some delay
839         mov r1, #0x10000
840     1:
841         subs r1, r1, #0x1
842         bne 1b
843     .endm /* init_drive_strength */
844
845     .macro init_dsp
846 /*
847  * Deal with DSP reset
848  */
849         /* Set DSP to LE */
850         ldr r0, =0x5001C808
851         ldr r1, [r0]
852         tst r1, #(1 << 5)
853         beq skip_dsp_switch_le
854         bic r1, r1, #(1 << 5)
855         str r1, [r0]
856     skip_dsp_switch_le:
857         ldr r0, =0x43F84024
858         /* Put DSP in reset */
859         ldr r1, =0x00000010
860         str r1, [r0]
861
862         /* Hold for some time */
863         ldr r2, =0x80000
864     dsp_reset_delay:
865         subs r2, r2, #0x1
866         bne dsp_reset_delay
867
868         /* Put DSP out of reset */
869         ldr r1, =0x0
870         str r1, [r0]
871     .endm /* init_dsp */
872 #define PLATFORM_VECTORS         _platform_vectors
873     .macro  _platform_vectors
874         .globl  _board_BCR, _board_CFG
875 _board_BCR:   .long   0       // Board Control register shadow
876 _board_CFG:   .long   0       // Board Configuration (read at RESET)
877     .endm
878
879 #define PLATFORM_PREAMBLE _switch_to_le
880
881     .macro  _switch_to_le
882         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
883         .word 0xE3C00080        // bic r0, r0, #0x80
884         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
885
886         .word 0x0F10EE11        // mrc 15, 0, r0, c1, c0, 0
887         .word 0x0080E3C0        // bic r0, r0, #0x80
888         .word 0x0F10EE01        // mcr 15, 0, r0, c1, c0, 0
889
890         .word 0                 // dummy
891         .word 0                 // dummy
892         .word 0                 // dummy
893         .word 0                 // dummy
894         .word 0                 // dummy
895         .word 0                 // dummy
896         .word 0                 // dummy
897         .word 0                 // dummy
898         .word 0                 // dummy
899     .endm
900 #if 0 /// good for SDRAM since 32bit
901         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
902         .word 0xE3C00080        // bic r0, r0, #0x80
903         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
904 #endif
905
906 ARM_PPMRR:              .word   0x40000015
907 L2CACHE_PARAM:          .word   0x00030024
908 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
909 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
910 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
911 CS4_BASE_ADDR_W:        .word   CS4_BASE_ADDR
912 AIPS1_PARAM_W:          .word   0x77777777
913 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
914 MAX_PARAM1:             .word   0x00302154
915 RVAL_WVAL_W:            .word   0x515
916 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
917 CRM_MCR_0x18FF2902:     .word   0x18FF2902
918 CRM_MCR_0x18FF2952:     .word   0x18FF2952
919 CRM_COSR_0x00036C58:    .word   0x00036C58
920 PDR0_399_100_50_W:      .word   PDR0_399_100_50
921 PDR0_399_133_66_W:      .word   PDR0_399_133_66
922 PDR0_399_66_66_W:       .word   PDR0_399_66_66
923 PDR1_0x2910AC56_W:      .word   0x2910AC56
924 MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
925 UPCTL_PARAM_288_W:      .word   UPCTL_PARAM_288
926 TPCTL_PARAM_500_W:      .word   TPCTL_PARAM_500
927 TPCTL_PARAM_532_W:      .word   TPCTL_PARAM_532
928 SPBA_CTRL_BASE_ADDR_W:  .word   SPBA_CTRL_BASE_ADDR
929 SPBA_LOCK_VAL:          .word   0xC0010007
930 ESDCTL_BASE_W:          .word   ESDCTL_BASE
931 M3IF_BASE_W:            .word   M3IF_BASE
932 SDRAM_DDR_X32_W:        .word   0x82226080
933 SDRAM_0x82216080:       .word   0x82216080
934 SDRAM_SDR_X32_W:        .word   0x82126080
935 SDRAM_SDR_X16_W:        .word   0x82116080
936 SDRAM_0x92126080:       .word   0x92126080
937 SDRAM_0xA2126080:       .word   0xA2126080
938 SDRAM_0xB2126180:       .word   0xB2126180
939 SDRAM_0x0075E73A:       .word   0x0075E73A
940 SDRAM_0x0079E73A:       .word   0x0079E73A
941 SDRAM_0x92100000:       .word   0x92100000
942 SDRAM_0xA2100000:       .word   0xA2100000
943 SDRAM_0xB2100000:       .word   0xB2100000
944 SDRAM_0x12344321:       .word   0x12344321
945 SDRAM_COMPARE_CONST1:   .word   0x55555555
946 SDRAM_COMPARE_CONST2:   .word   0xAAAAAAAA
947 WEIM_CTRL_CS0_W:        .word   WEIM_CTRL_CS0
948 CS0_CSCRU_0x11414C80:   .word   0x11414C80
949 CS0_CSCRL_0x30000D03:   .word   0x30000D03
950 CS0_CSCRA_0x00310800:   .word   0x00310800
951 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
952 CRM_MCU_BASE_ADDR_W:    .word   CRM_MCU_BASE_ADDR
953 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
954 CONST_0x0FFF:           .word   0x0FFF
955 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
956 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
957
958 /*---------------------------------------------------------------------------*/
959 /* end of hal_platform_setup.h                                               */
960 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */