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