]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91321/evb/v2_0/include/hal_platform_setup.h
unified MX27, MX25, MX37 trees
[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     orr r1, r1, #0x800                      // enable z bit
405     mcr MMU_CP, 0, r1, MMU_Control, c0
406     mov pc,r2    /* Change address spaces */
407     nop
408     nop
409     nop
410 10:
411
412     // Save shadow copy of BCR, also hardware configuration
413     ldr r1, =_board_BCR
414     str r2, [r1]
415     ldr r1, =_board_CFG
416     str r9, [r1]                // Saved far above...
417
418     .endm                       // _platform_setup1
419
420 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
421 #define PLATFORM_SETUP1
422 #endif
423
424     /* Allow all 3 masters to have access to these shared peripherals */
425     .macro  init_spba
426         ldr r0, SPBA_CTRL_BASE_ADDR_W
427         add r4, r0, #0x38
428         ldr r1, =0x7            /* allow all 3 masters access */
429         ldr r2, SPBA_LOCK_VAL
430 spba_continue:
431         str r1, [r0]
432 spba_check_loop:
433         ldr r3, [r0]
434         cmp r2, r3
435         bne spba_check_loop
436         add r0, r0, #4
437         cmp r0, r4
438         ble spba_continue
439     .endm  /* init_spba */
440
441     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
442     .macro init_aips
443         /*
444          * Set all MPROTx to be non-bufferable, trusted for R/W,
445          * not forced to user-mode.
446          */
447         ldr r0, AIPS1_CTRL_BASE_ADDR_W
448         ldr r1, AIPS1_PARAM_W
449         str r1, [r0, #0x00]
450         str r1, [r0, #0x04]
451         ldr r0, AIPS2_CTRL_BASE_ADDR_W
452         str r1, [r0, #0x00]
453         str r1, [r0, #0x04]
454
455         /*
456          * Clear the on and off peripheral modules Supervisor Protect bit
457          * for SDMA to access them. Did not change the AIPS control registers
458          * (offset 0x20) access type
459          */
460         ldr r0, AIPS1_CTRL_BASE_ADDR_W
461         ldr r1, =0x0
462         str r1, [r0, #0x40]
463         str r1, [r0, #0x44]
464         str r1, [r0, #0x48]
465         str r1, [r0, #0x4C]
466         ldr r1, [r0, #0x50]
467         and r1, r1, #0x00FFFFFF
468         str r1, [r0, #0x50]
469
470         ldr r0, AIPS2_CTRL_BASE_ADDR_W
471         ldr r1, =0x0
472         str r1, [r0, #0x40]
473         str r1, [r0, #0x44]
474         str r1, [r0, #0x48]
475         str r1, [r0, #0x4C]
476         ldr r1, [r0, #0x50]
477         and r1, r1, #0x00FFFFFF
478         str r1, [r0, #0x50]
479     .endm /* init_aips */
480
481     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
482     .macro init_max
483         ldr r0, MAX_BASE_ADDR_W
484         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
485         ldr r1, MAX_PARAM1
486         str r1, [r0, #0x000]        /* for S0 */
487         str r1, [r0, #0x100]        /* for S1 */
488         str r1, [r0, #0x200]        /* for S2 */
489         str r1, [r0, #0x300]        /* for S3 */
490         str r1, [r0, #0x400]        /* for S4 */
491         /* SGPCR - always park on last master */
492         ldr r1, =0x10
493         str r1, [r0, #0x010]        /* for S0 */
494         str r1, [r0, #0x110]        /* for S1 */
495         str r1, [r0, #0x210]        /* for S2 */
496         str r1, [r0, #0x310]        /* for S3 */
497         str r1, [r0, #0x410]        /* for S4 */
498         /* MGPCR - restore default values */
499         ldr r1, =0x0
500         str r1, [r0, #0x800]        /* for M0 */
501         str r1, [r0, #0x900]        /* for M1 */
502         str r1, [r0, #0xA00]        /* for M2 */
503         str r1, [r0, #0xB00]        /* for M3 */
504         str r1, [r0, #0xC00]        /* for M4 */
505         str r1, [r0, #0xD00]        /* for M5 */
506     .endm /* init_max */
507
508     /* Clock setup */
509     .macro init_clock
510         /* RVAL/WVAL for L2 cache memory */
511         ldr r0, RVAL_WVAL_W
512         ldr r1, CLKCTL_BASE_ADDR_W
513         str r0, [r1, #0x10]
514
515         /*
516          * Clock setup
517          * - These are the targeted speed settings (may not be true for now).
518          * Note: the default USBPLL seems to be 286MHz instead of 288MHz?
519
520           Module           Freq (MHz)   Note
521           =========================================================================
522           ARM core         399          ipg_clk_arm
523           AHB              133          known as "hclk", ipg_clk_max
524           IP               66.5         ipg_clk (also used as ipg_per_clk ???)
525           EMI              133          =hclk
526          */
527         ldr r0, CRM_MCU_BASE_ADDR_W
528 #ifdef CYGPKG_HAL_ARM_MXC91331_CHIP
529         ldr r1, CRM_MCR_0x18FF2902
530         str r1, [r0, #CLKCTL_MCR]
531 upll_lock:
532         ldr r1, [r0, #CLKCTL_MCR]
533         ands r1, r1, #0x80
534         beq upll_lock
535 #endif
536 #ifdef CYGPKG_HAL_ARM_MXC91321_CHIP
537         // enable MPLL, UPLL, TurboPLL
538         ldr r1, CRM_MCR_0x18FF2952
539         str r1, [r0, #CLKCTL_MCR]
540 check_pll_lock:
541         ldr r1, [r0, #CLKCTL_MCR]
542         and r1, r1, #0x8C
543         cmp r1, #0x8C
544         bne check_pll_lock
545 #endif
546         /*
547          * J10 (CPU card) - CKO1=MCU_PLL div by 8
548          * J9 (CPU card) - CKO2=IPG_CLK_ARM div by 8
549          */
550         ldr r1, CRM_COSR_0x00036C58
551         str r1, [r0, #CLKCTL_COSR]
552
553 #if defined(CYGPKG_HAL_ARM_MXC91331_CHIP)
554         ldr r1, =0x0
555         ldrb r2, [r1, #0x60]         /* See if pass 1 silicon */
556         cmp r2, #0x1
557         ldr r1, PDR0_399_100_50_W
558 //        ldr r1, PDR0_399_133_66_W
559         ldreq r1, PDR0_399_66_66_W    /* For pass 1, HCLK=66.5MHz*/
560 #elif defined(CYGPKG_HAL_ARM_MXC91321_CHIP)
561 #if 1  // for 133MHz HCLK
562         ldr r1, TPCTL_PARAM_532_W
563         str r1, [r0, #CLKCTL_TPCTL]
564         ldr r1, PDR0_399_133_66_W
565 #else
566         ldr r1, TPCTL_PARAM_500_W
567         str r1, [r0, #CLKCTL_TPCTL]
568         // add some delay here
569         mov r1, #0x100
570     1:  subs r1, r1, #0x1
571         bne 1b
572
573         ldr r1, PDR0_399_100_50_W
574 #endif
575 #endif
576         str r1, [r0, #CLKCTL_PDR0]
577         ldr r1, MPCTL_PARAM_399_W
578         str r1, [r0, #CLKCTL_MPCTL]
579
580         /* Set to default values */
581         ldr r1, PDR1_0x2910AC56_W
582         str r1, [r0, #CLKCTL_PDR1]
583         /* Set UPLL=288MHz */
584         ldr r1, UPCTL_PARAM_288_W
585         str r1, [r0, #CLKCTL_UPCTL]
586     .endm /* init_clock */
587
588     /* M3IF setup */
589     .macro init_m3if
590         /* Configure M3IF registers */
591         ldr r1, M3IF_BASE_W
592         /*
593         * M3IF Control Register (M3IFCTL)
594         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
595         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
596         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
597         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
598         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
599         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
600         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
601         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
602         *                                                       ------------
603         *                                                       0x00000040
604         */
605         ldr r0, =0x00000040
606         str r0, [r1]  /* M3IF control reg */
607     .endm /* init_m3if */
608
609     /* CS0 sync mode setup */
610     .macro init_cs0_sync
611         /*
612          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz)
613          */
614         /* Flash reset command */
615         mov   r0, #CS0_BASE_ADDR
616         ldr     r1, =0xF0F0
617         strh    r1, [r0]
618         /* 1st command */
619         ldr     r2, =0xAAA
620         add   r2, r2, r0
621         ldr     r1, =0xAAAA
622         strh   r1, [r2]
623         /* 2nd command */
624         ldr     r2, =0x554
625         add     r2, r2, r0
626         ldr     r1, =0x5555
627         strh    r1, [r2]
628         /* 3rd command */
629         ldr     r2, =0xAAA
630         add     r2, r2, r0
631         ldr     r1, =0xD0D0
632         strh    r1, [r2]
633         /* Write flash config register */
634         ldr     r1, =0x56CA
635         strh    r1, [r2]
636         /* Flash reset command */
637         ldr     r1, =0xF0F0
638         strh    r1, [r0]
639
640         ldr r0, WEIM_CTRL_CS0_W
641         ldr r1, =0x23524E80
642         str r1, [r0, #CSCRU]
643         ldr r1, =0x10000D03
644         str r1, [r0, #CSCRL]
645         ldr r1, =0x00720900
646         str r1, [r0, #CSCRA]
647     .endm /* init_cs0_sync */
648
649     /* CS0 async mode setup */
650     .macro init_cs0_async
651         /* Async flash mode */
652         ldr r0, WEIM_CTRL_CS0_W
653         ldr r1, CS0_CSCRU_0x11414C80
654         str r1, [r0, #CSCRU]
655         ldr r1, CS0_CSCRL_0x30000D03
656         str r1, [r0, #CSCRL]
657         ldr r1, CS0_CSCRA_0x00310800
658         str r1, [r0, #CSCRA]
659     .endm /* init_cs0_async */
660
661     /* CPLD on CS4 setup */
662     .macro init_cs4
663         ldr r0, =WEIM_CTRL_CS4
664         ldr r1, =0x0000D743
665         str r1, [r0, #CSCRU]
666         ldr r1, =0x42001521
667         str r1, [r0, #CSCRL]
668         ldr r1, =0x00430A00
669         str r1, [r0, #CSCRA]
670
671         ldr r0, CS4_BASE_ADDR_W
672         ldrh r1, [r0, #0x0]
673         and r0, r1, #0xFF00
674         cmp r0, #0x2000
675         bge done_cs4_setup
676
677         ldr r0, =WEIM_CTRL_CS4
678         ldr r1, =0x0000D843
679         str r1, [r0, #CSCRU]
680         ldr r1, =0x22252521
681         str r1, [r0, #CSCRL]
682         ldr r1, =0x22220A00
683         str r1, [r0, #CSCRA]
684
685 done_cs4_setup:
686
687     .endm /* init_cs4 */
688
689 // DDR SDRAM setup
690       /* r4 = burst mode vs full-page mode */
691     .macro  init_ddr_sdram
692         ldr r3, SDRAM_0x82216080     /* 16 bit memory */
693         ldr r0, ESDCTL_BASE_W
694         mov r2, #SDRAM_BASE_ADDR
695         ldr r1, SDRAM_0x0079E73A
696         str r1, [r0, #0x4]
697         mov r1, #0x2            // reset
698         str r1, [r0, #0x10]
699         mov r1, #0x4            // DDR
700         str r1, [r0, #0x10]
701
702         // Hold for more than 200ns
703         mov r1, #0x10000
704     1:
705         subs r1, r1, #0x1
706         bne 1b
707
708         add r1, r3, #0x10000000
709         str r1, [r0]
710         mov r1, #0x0
711
712         add r12, r2, #0x400
713         strh r1, [r12]
714         add r1, r3, #0x20000000     // 0xA2216080
715         str r1, [r0]
716
717         mov r1, #0x0
718         strh r1, [r2]
719         strh r1, [r2]
720
721         add r1, r3, #0x30000000     // 0xB2216080
722         str r1, [r0]
723         mov r1, #0x0
724         strb r1, [r2, #0x33]
725         add r12, r2, #0x01000000
726         strh r1, [r12]
727
728         str r3, [r0]
729         strh r1, [r2]
730     .endm
731
732 // SDR SDRAM setup
733     /* r3 = value for ESDCTL0
734      * r4 = burst mode vs full-page mode */
735     .macro  init_sdr_sdram
736         ldr r0, ESDCTL_BASE_W
737         mov r2, #SDRAM_BASE_ADDR
738         ldr r1, SDRAM_0x0075E73A
739         str r1, [r0, #0x4]
740         ldr r1, =0x2            // reset
741         str r1, [r0, #0x10]
742         ldr r1, =0x0            // sdr
743         str r1, [r0, #0x10]
744
745         // Hold for more than 200ns
746         ldr r1, =0x10000
747 1:
748         subs r1, r1, #0x1
749         bne 1b
750
751         ldr r1, SDRAM_0x92126080
752         str r1, [r0]
753         ldr r1, =0x0
754         mov r12, #0x80000000
755         add r12, r12, #0x00000400
756         str r1, [r12]
757         ldr r1, SDRAM_0xA2126080
758         str r1, [r0]
759
760         ldr r1, =0x0
761         str r1, [r2]
762         str r1, [r2]
763
764         ldr r1, SDRAM_0xB2126180
765         str r1, [r0]
766
767         ldr r1, =0x0
768         strb r1, [r2, r4]
769         mov r12, #0x81000000
770         str r1, [r12]
771         str r3, [r0]
772         ldr r1, =0x0
773         str r1, [r2]
774     .endm
775
776     .macro do_wait_op_done
777 #if defined(CYGPKG_HAL_ARM_MXC91331_CHIP)
778         mov r3, #0x1000
779     1:
780         subs r3, r3, #0x1
781         bne 1b
782 #endif
783     1:
784         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
785         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
786         beq 1b
787         mov r3, #0x0
788         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
789     .endm   // do_wait_op_done
790
791     .macro do_addr_input
792         and r3, r3, #0xFF
793         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
794         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
795         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
796         do_wait_op_done
797     .endm   // do_addr_input
798
799     /* To support 133MHz SDR */
800     .macro  init_drive_strength
801         // max drive strength for all pads except SDQS0/1
802
803         ldr r0, IOMUXC_BASE_ADDR_W
804         add r0, r0, #0x300
805         //=========== set_drive_strenght_ctl_signals =======================
806         /* OE line sw_pad_ctl_dqm3_oe_b_cs0_b */
807         ldr r1, =0x00001800
808         str r1, [r0, #0xC4]
809
810         /* SDRAM DQMx lines sw_pad_ctl_dqm0_dqm1_dqm2 */
811         ldr r1, =0x00700000
812         str r1, [r0, #0xC8]
813
814         /* SDRAM SD16-SD31 data lines sw_pad_ctl_sd15_sd16_sd17 */
815         mov r1, #0x00001C00
816         str r1, [r0, #0xE4]
817
818         //============= set_drive_strength_ctl_data ========================
819         /* SDRAM SD0-SD15 data lines sw_pad_ctl_sd0_sd1_sd2 */
820         mov r1, #0x00700000
821         str r1, [r0, #0xF8]
822
823         //============= set_drive_strength_ctl_addr ========================
824         /* SDRAM address lines sw_pad_ctl_a0_ma0_a1_ma1_a2_ma2 */
825         mov r1, #0x00700000
826         str r1, [r0, #0x11C]
827
828         /* sw_pad_ctl_RAS */
829         mov r1, #0x00700000
830         str r1, [r0, #0xB0]
831
832         /* sw_pad_ctl_SDCLK */
833         mov r1, #0x00000007
834         str r1, [r0, #0xAC]
835
836         /* for SDRAM SDQS lines sw_pad_ctl_DQS0 */
837         mov r1, #0x00000007
838         str r1, [r0, #0xD0]
839         // Add some delay
840         mov r1, #0x10000
841     1:
842         subs r1, r1, #0x1
843         bne 1b
844     .endm /* init_drive_strength */
845
846     .macro init_dsp
847 /*
848  * Deal with DSP reset
849  */
850         /* Set DSP to LE */
851         ldr r0, =0x5001C808
852         ldr r1, [r0]
853         tst r1, #(1 << 5)
854         beq skip_dsp_switch_le
855         bic r1, r1, #(1 << 5)
856         str r1, [r0]
857     skip_dsp_switch_le:
858         ldr r0, =0x43F84024
859         /* Put DSP in reset */
860         ldr r1, =0x00000010
861         str r1, [r0]
862
863         /* Hold for some time */
864         ldr r2, =0x80000
865     dsp_reset_delay:
866         subs r2, r2, #0x1
867         bne dsp_reset_delay
868
869         /* Put DSP out of reset */
870         ldr r1, =0x0
871         str r1, [r0]
872     .endm /* init_dsp */
873 #define PLATFORM_VECTORS         _platform_vectors
874     .macro  _platform_vectors
875         .globl  _board_BCR, _board_CFG
876 _board_BCR:   .long   0       // Board Control register shadow
877 _board_CFG:   .long   0       // Board Configuration (read at RESET)
878     .endm
879
880 #define PLATFORM_PREAMBLE _switch_to_le
881
882     .macro  _switch_to_le
883         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
884         .word 0xE3C00080        // bic r0, r0, #0x80
885         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
886
887         .word 0x0F10EE11        // mrc 15, 0, r0, c1, c0, 0
888         .word 0x0080E3C0        // bic r0, r0, #0x80
889         .word 0x0F10EE01        // mcr 15, 0, r0, c1, c0, 0
890
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         .word 0                 // dummy
900     .endm
901 #if 0 /// good for SDRAM since 32bit
902         .word 0xEE110F10        // mrc 15, 0, r0, c1, c0, 0
903         .word 0xE3C00080        // bic r0, r0, #0x80
904         .word 0xEE010F10        // mcr 15, 0, r0, c1, c0, 0
905 #endif
906
907 ARM_PPMRR:              .word   0x40000015
908 L2CACHE_PARAM:          .word   0x00030024
909 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
910 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
911 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
912 CS4_BASE_ADDR_W:        .word   CS4_BASE_ADDR
913 AIPS1_PARAM_W:          .word   0x77777777
914 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
915 MAX_PARAM1:             .word   0x00302154
916 RVAL_WVAL_W:            .word   0x515
917 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
918 CRM_MCR_0x18FF2902:     .word   0x18FF2902
919 CRM_MCR_0x18FF2952:     .word   0x18FF2952
920 CRM_COSR_0x00036C58:    .word   0x00036C58
921 PDR0_399_100_50_W:      .word   PDR0_399_100_50
922 PDR0_399_133_66_W:      .word   PDR0_399_133_66
923 PDR0_399_66_66_W:       .word   PDR0_399_66_66
924 PDR1_0x2910AC56_W:      .word   0x2910AC56
925 MPCTL_PARAM_399_W:      .word   MPCTL_PARAM_399
926 UPCTL_PARAM_288_W:      .word   UPCTL_PARAM_288
927 TPCTL_PARAM_500_W:      .word   TPCTL_PARAM_500
928 TPCTL_PARAM_532_W:      .word   TPCTL_PARAM_532
929 SPBA_CTRL_BASE_ADDR_W:  .word   SPBA_CTRL_BASE_ADDR
930 SPBA_LOCK_VAL:          .word   0xC0010007
931 ESDCTL_BASE_W:          .word   ESDCTL_BASE
932 M3IF_BASE_W:            .word   M3IF_BASE
933 SDRAM_DDR_X32_W:        .word   0x82226080
934 SDRAM_0x82216080:       .word   0x82216080
935 SDRAM_SDR_X32_W:        .word   0x82126080
936 SDRAM_SDR_X16_W:        .word   0x82116080
937 SDRAM_0x92126080:       .word   0x92126080
938 SDRAM_0xA2126080:       .word   0xA2126080
939 SDRAM_0xB2126180:       .word   0xB2126180
940 SDRAM_0x0075E73A:       .word   0x0075E73A
941 SDRAM_0x0079E73A:       .word   0x0079E73A
942 SDRAM_0x92100000:       .word   0x92100000
943 SDRAM_0xA2100000:       .word   0xA2100000
944 SDRAM_0xB2100000:       .word   0xB2100000
945 SDRAM_0x12344321:       .word   0x12344321
946 SDRAM_COMPARE_CONST1:   .word   0x55555555
947 SDRAM_COMPARE_CONST2:   .word   0xAAAAAAAA
948 WEIM_CTRL_CS0_W:        .word   WEIM_CTRL_CS0
949 CS0_CSCRU_0x11414C80:   .word   0x11414C80
950 CS0_CSCRL_0x30000D03:   .word   0x30000D03
951 CS0_CSCRA_0x00310800:   .word   0x00310800
952 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
953 CRM_MCU_BASE_ADDR_W:    .word   CRM_MCU_BASE_ADDR
954 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
955 CONST_0x0FFF:           .word   0x0FFF
956 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
957 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
958
959 /*---------------------------------------------------------------------------*/
960 /* end of hal_platform_setup.h                                               */
961 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */