]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx27/3stack/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx27 / 3stack / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3
4 //=============================================================================
5 //
6 //      hal_platform_setup.h
7 //
8 //      Platform specific support for HAL (assembly code)
9 //
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //===========================================================================
44
45 #include <pkgconf/system.h>             // System-wide configuration info
46 #include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
47 #include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
48 #include <cyg/hal/hal_soc.h>            // Variant specific hardware definitions
49 #include <cyg/hal/hal_mmu.h>            // MMU definitions
50 #include <cyg/hal/fsl_board.h>          // Platform specific hardware definitions
51
52 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
53 #define PLATFORM_SETUP1 _platform_setup1
54 #define CYGHWR_HAL_ARM_HAS_MMU
55
56 #ifdef CYG_HAL_STARTUP_ROMRAM
57 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
58 #endif
59
60 #define CYGHWR_HAL_ROM_VADDR        0x0
61
62 // This macro represents the initial startup code for the platform
63 // r11 is reserved to contain chip rev info in this file
64     .macro  _platform_setup1
65 FSL_BOARD_SETUP_START:
66     // invalidate I/D cache/TLB and drain write buffer
67     mov r0, #0
68     mcr 15, 0, r0, c7, c7, 0    /* invalidate I cache and D cache */
69     mcr 15, 0, r0, c8, c7, 0    /* invalidate TLBs */
70     mcr 15, 0, r0, c7, c10, 4   /* Drain the write buffer */
71
72 init_aipi_start:
73     init_aipi
74
75     mov r0, #SDRAM_NON_FLASH_BOOT
76     ldr r1, AVIC_VECTOR0_ADDR_W
77     str r0, [r1] // for checking boot source from nand, nor or sdram
78
79     // setup System Controls
80     ldr r0, SOC_SYSCTRL_BASE_W
81     mov r1, #0x03
82     str r1, [r0, #(SOC_SYSCTRL_PCSR - SOC_SYSCTRL_BASE)]
83     ldr r1, [r0, #(SOC_SYSCTRL_FMCR - SOC_SYSCTRL_BASE)]
84     and r1, r1, #0xFFFFFFF0
85     orr r1, r1, #9
86     str r1, [r0, #(SOC_SYSCTRL_FMCR - SOC_SYSCTRL_BASE)]
87
88 init_max_start:
89     init_max
90 init_drive_strength_start:
91     init_drive_strength
92 init_cs5_start:
93     init_cs5
94
95     // check if sdram has been setup
96     cmp pc, #SDRAM_BASE_ADDR
97     blo init_clock_start
98     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
99     blo HWInitialise_skip_SDRAM_setup
100 init_clock_start:
101     init_clock
102
103     // Now we must boot from Flash
104     mov r0, #NOR_FLASH_BOOT
105     ldr r1, AVIC_VECTOR0_ADDR_W
106     str r0, [r1]
107
108 init_sdram_start:
109     setup_sdram_ddr
110
111 HWInitialise_skip_SDRAM_setup:
112     ldr r0, NFC_BASE_W
113     add r2, r0, #0x800      // 2K window
114     cmp pc, r0
115     blo Normal_Boot_Continue
116     cmp pc, r2
117     bhi Normal_Boot_Continue
118 NAND_Boot_Start:
119     /* Copy image from flash to SDRAM first */
120     ldr r1, MXC_REDBOOT_ROM_START
121
122 1:  ldmia r0!, {r3-r10}
123     stmia r1!, {r3-r10}
124     cmp r0, r2
125     blo 1b
126
127     /* Jump to SDRAM */
128     ldr r1, CONST_0xFFF
129     and r0, pc, r1     /* offset of pc */
130     ldr r1, MXC_REDBOOT_ROM_START
131     add r1, r1, #0x10
132     add pc, r0, r1
133     nop
134     nop
135     nop
136     nop
137
138 NAND_Copy_Main:
139     // Check if x16/2kb page
140     ldr r7, SOC_SYSCTRL_BASE_W
141     ldr r7, [r7, #0x14]
142     ands r7, r7, #(1 << 5)
143
144     mov r0, #NAND_FLASH_BOOT
145     ldr r1, AVIC_VECTOR0_ADDR_W
146     str r0, [r1]
147     mov r0, #MXCFIS_NAND
148     ldr r1, AVIC_VECTOR1_ADDR_W
149     str r0, [r1]
150
151     ldr r0, NFC_BASE_W   //r0: nfc base. Reloaded after each page copying
152     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
153     add r2, r0, #0x800     //2K Page:: r2: end of 1st RAM buf. Doesn't change
154     addeq r2, r0, #0x200   //512 Page:: r2: end of 1st RAM buf. Doesn't change
155     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
156     ldr r11, MXC_REDBOOT_ROM_START
157     add r13, r11, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
158     add r11, r11, r1     //r11: starting SDRAM address for copying. Updated constantly
159
160     //unlock internal buffer
161     mov r3, #0x2
162     strh r3, [r12, #0xA]
163
164 Nfc_Read_Page:
165 //  NFC_CMD_INPUT(FLASH_Read_Mode1);
166     mov r3, #0x0
167     nfc_cmd_input
168
169     // Check if x16/2kb page
170     ldr r7, SOC_SYSCTRL_BASE_W
171     ldr r7, [r7, #0x14]
172     ands r7, r7, #(1 << 5)
173
174     bne nfc_addr_ops_2kb
175 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
176     mov r3, r1
177     do_addr_input       //1st addr cycle
178     mov r3, r1, lsr #9
179     do_addr_input       //2nd addr cycle
180     mov r3, r1, lsr #17
181     do_addr_input       //3rd addr cycle
182     mov r3, r1, lsr #25
183     do_addr_input       //4th addr cycle
184     b end_of_nfc_addr_ops
185
186 nfc_addr_ops_2kb:
187 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
188     mov r3, #0
189     do_addr_input       //1st addr cycle
190     mov r3, #0
191     do_addr_input       //2nd addr cycle
192     mov r3, r1, lsr #11
193     do_addr_input       //3rd addr cycle
194     mov r3, r1, lsr #19
195     do_addr_input       //4th addr cycle
196     mov r3, r1, lsr #27
197     do_addr_input       //4th addr cycle
198
199 //    NFC_CMD_INPUT(FLASH_Read_Mode1_2K);
200     mov r3, #0x30
201     nfc_cmd_input
202
203 end_of_nfc_addr_ops:
204 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
205 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
206 //               NAND_FLASH_CONFIG1_REG);
207     mov r8, #0
208     bl nfc_data_output
209     bl do_wait_op_done
210     // Check if x16/2kb page
211     ldr r7, SOC_SYSCTRL_BASE_W
212     ldr r7, [r7, #0x14]
213     ands r7, r7, #(1 << 5)
214
215     beq nfc_addr_data_output_done_512
216
217 // For 2K page - 2nd 512
218     mov r8, #1
219     bl nfc_data_output
220     bl do_wait_op_done
221
222 // 3rd 512
223     mov r8, #2
224     bl nfc_data_output
225     bl do_wait_op_done
226
227 // 4th 512
228     mov r8, #3
229     bl nfc_data_output
230     bl do_wait_op_done
231 // end of 4th
232
233     // check for bad block
234     mov r3, r1, lsl #(32-17)    // get rid of block number
235     cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
236     b nfc_addr_data_output_done
237 nfc_addr_data_output_done_512:
238     // check for bad block
239     mov r3, r1, lsl #(32-5-9)    // get rid of block number
240     cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
241
242 nfc_addr_data_output_done:
243     bhi Copy_Good_Blk
244     add r4, r0, #0x800  //r3 -> spare area buf 0
245     ldrh r4, [r4, #0x4]
246     and r4, r4, #0xFF00
247     cmp r4, #0xFF00
248     beq Copy_Good_Blk
249     // really sucks. Bad block!!!!
250     cmp r3, #0x0
251     beq Skip_bad_block
252     // even suckier since we already read the first page!
253
254     // Check if x16/2kb page
255     ldr r7, SOC_SYSCTRL_BASE_W
256     ldr r7, [r7, #0x14]
257     ands r7, r7, #(1 << 5)
258
259     subeq r11, r11, #512  //rewind 1 page for the sdram pointer
260     subeq r1, r1, #512    //rewind 1 page for the flash pointer
261
262     // for 2k page
263     subne r11, r11, #0x800  //rewind 1 page for the sdram pointer
264     subne r1, r1, #0x800    //rewind 1 page for the flash pointer
265
266 Skip_bad_block:
267     // Check if x16/2kb page
268     ldr r7, SOC_SYSCTRL_BASE_W
269     ldr r7, [r7, #0x14]
270     ands r7, r7, #(1 << 5)
271
272     addeq r1, r1, #(32*512)
273     addne r1, r1, #(64*2048)
274
275     b Nfc_Read_Page
276 Copy_Good_Blk:
277     //copying page
278 1:  ldmia r0!, {r3-r10}
279     stmia r11!, {r3-r10}
280     cmp r0, r2
281     blo 1b
282     cmp r11, r13
283     bge NAND_Copy_Main_done
284     // Check if x16/2kb page
285     ldr r7, SOC_SYSCTRL_BASE_W
286     ldr r7, [r7, #0x14]
287     ands r7, r7, #(1 << 5)
288
289     addeq r1, r1, #0x200
290     addne r1, r1, #0x800
291     mov r0, #NFC_BASE
292     b Nfc_Read_Page
293
294 NAND_Copy_Main_done:
295
296 Normal_Boot_Continue:
297
298 #ifdef CYG_HAL_STARTUP_ROMRAM    /* enable running from RAM */
299     /* Copy image from flash to SDRAM first */
300     ldr r0, =0xFFFFF000
301     and r0, r0, pc
302     ldr r1, MXC_REDBOOT_ROM_START
303     cmp r0, r1
304     beq HWInitialise_skip_SDRAM_copy
305
306     add r2, r0, #REDBOOT_IMAGE_SIZE
307
308 1:  ldmia r0!, {r3-r10}
309     stmia r1!, {r3-r10}
310     cmp r0, r2
311     ble 1b
312
313     /* Jump to SDRAM */
314     ldr r1, =0xFFFF
315     and r0, pc, r1      /* offset of pc */
316     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
317     add pc, r0, r1
318     nop
319     nop
320     nop
321     nop
322 #endif /* CYG_HAL_STARTUP_ROMRAM */
323
324 HWInitialise_skip_SDRAM_copy:
325
326 //trace
327 init_cs0_sync_start:
328     init_cs0_sync
329
330 NAND_ClockSetup:
331     ldr r1, =(SOC_CRM_BASE)
332     ldr r2, [r1, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
333 /*Get chip ID://eq:i.MX27 TO1; neq:i.MX27 TO2*/
334     ldr r1, =SOC_SI_ID_REG
335     ldr r1, [r1]
336     ands r1, r1, #0xF0000000
337
338     orreq r2, r2, #0xF000
339     orrne r2, r2, #0x01C0
340
341     ldr r1, =(SOC_CRM_BASE)
342     str r2, [r1, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
343
344 /* end of NAND clock divider setup */
345
346     // TLSbo76381: enable USB/PP/DMA burst override bits in GPCR
347     ldr r1, =(SOC_SYSCTRL_GPCR)
348     ldr r2, [r1]
349     orr r2, r2, #0x700
350     str r2, [r1]
351
352     // Set up a stack [for calling C code]
353     ldr r1, =__startup_stack
354     ldr r2, =RAM_BANK0_BASE
355     orr sp, r1, r2
356
357     // Create MMU tables
358     bl hal_mmu_init
359
360     // Enable MMU
361     ldr r2, =10f
362     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
363     orr r1, r1, #7                          // enable MMU bit
364     mcr MMU_CP, 0, r1, MMU_Control, c0
365     mov pc,r2    /* Change address spaces */
366     nop
367     nop
368     nop
369 10:
370     // Save shadow copy of BCR, also hardware configuration
371     ldr r1, =_board_BCR
372     str r2,[r1]
373     ldr r1, =_board_CFG
374     str r9,[r1]                // Saved far above...
375
376     .endm                       // _platform_setup1
377
378 do_wait_op_done:
379     1:
380         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
381         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
382         beq 1b
383     bx lr     // do_wait_op_done
384
385 nfc_data_output:
386     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
387     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
388
389     // writew(buf_no, RAM_BUFFER_ADDRESS_REG);
390     strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
391     // writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
392     mov r3, #FDO_PAGE_SPARE_VAL
393     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
394     bx lr
395
396 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
397 #define PLATFORM_SETUP1
398 #endif
399
400     .macro init_clock
401         ldr r0, SOC_CRM_BASE_W
402         // disable MPLL/SPLL first
403         ldr r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
404         bic r1, r1, #0x3
405         str r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
406
407         /* Get the chip version and configure PLLs*/
408         ldr r1, SOC_SI_ID_REG_W
409         ldr r1, [r1]
410         ands r1, r1, #0xF0000000
411
412         ldreq r1, CRM_MPCTL0_VAL_W
413         ldrne r1, CRM_MPCTL0_VAL2_W
414         str r1, [r0, #(SOC_CRM_MPCTL0 - SOC_CRM_BASE)]
415
416         ldreq r1, CRM_SPCTL0_VAL_W
417         ldrne r1, CRM_SPCTL0_VAL2_W
418         str r1, [r0, #(SOC_CRM_SPCTL0 - SOC_CRM_BASE)]
419
420         // enable/restart SPLL/MPLL
421         ldr r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
422 #ifdef PLL_REF_CLK_32768HZ
423         // Make sure to use CKIL
424         bic r1, r1, #(3 << 16)
425 #else
426         orr r1, r1, #(3 << 16)      // select 26MHz
427 #endif
428         orr r1, r1, #0x000C0000
429         orr r1, r1, #0x00000003
430         str r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
431
432         // add some delay here
433         mov r1, #0x1000
434     1:  subs r1, r1, #0x1
435         bne 1b
436
437         //Check The chip version TO1 or TO2
438         ldr r1, SOC_SI_ID_REG_W
439         ldr r1, [r1]
440         ands r1, r1, #0xF0000000
441
442         ldreq r2, SOC_CRM_CSCR_W
443         ldrne r2, SOC_CRM_CSCR2_W
444         str r2, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
445
446         //for i.MX27 TO2, Set divider of H264_CLK to zero, NFC to 3.
447         ldrne r2, [r0, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
448         bicne r2, r2, #0x0000FC00
449         strne r2, [r0, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
450
451         /* Configure PCDR */
452         /* Configure PCDR1 */
453         ldr r1, SOC_CRM_PCDR1_W
454         str r1, [r0, #(SOC_CRM_PCDR1 - SOC_CRM_BASE)]
455
456         // Configure PCCR0 and PCCR1
457         ldr r1, SOC_CRM_PCCR0_W
458         str r1, [r0, #(SOC_CRM_PCCR0 - SOC_CRM_BASE)]
459
460         ldr r1, [r0, #(SOC_CRM_PCCR1 - SOC_CRM_BASE)]
461         orr r1, r1, #0x0780
462         str r1, [r0, #(SOC_CRM_PCCR1 - SOC_CRM_BASE)]
463         // make default CLKO to be FCLK
464         ldr r1, [r0, #(SOC_CRM_CCSR - SOC_CRM_BASE)]
465         and r1, r1, #0xFFFFFFE0
466         orr r1, r1, #0x7
467         str r1, [r0, #(SOC_CRM_CCSR - SOC_CRM_BASE)]
468     .endm //init_clock
469
470     /* CS0 sync mode setup */
471     .macro init_cs0_sync
472         /*
473          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
474          */
475         /* Flash reset command */
476         ldr     r0, CS0_BASE_ADDR_W
477         mov     r1, #0x00F0
478         strh    r1, [r0]
479         /* 1st command */
480         ldr     r2, CS0_CMD_0xAAA
481         add     r2, r2, r0
482         mov     r1, #0x00AA
483         strh    r1, [r2]
484         /* 2nd command */
485         ldr     r2, CS0_CMD_0x554
486         add     r2, r2, r0
487         mov     r1, #0x0055
488         strh    r1, [r2]
489         /* 3rd command */
490         ldr     r2, CS0_CMD_0xAAA
491         add     r2, r2, r0
492         mov     r1, #0x00D0
493         strh    r1, [r2]
494         /* Write flash config register */
495         ldr     r1, CS0_CFG_0x66CA
496         strh    r1, [r2]
497         /* Flash reset command */
498         mov     r1, #0x00F0
499         strh    r1, [r0]
500
501         ldr r0, =SOC_CS0_CTL_BASE
502         ldr r1, CS0_0x23524E80
503         str r1, [r0, #CSCRU_OFFSET]
504         ldr r1, CS0_0x10000D03
505         str r1, [r0, #CSCRL_OFFSET]
506         ldr r1, CS0_0x00720900
507         str r1, [r0, #CSCRA_OFFSET]
508     .endm /* init_cs0_sync */
509
510     .macro init_cs5 /* 3-Stack board expanded IOs */
511         ldr r1, SOC_CS5_CTL_BASE_W
512         ldr r2, CS5_CSCRU_0x0000DCF6
513         str r2, [r1, #CSCRU_OFFSET]
514         ldr r2, CS5_CSCRL_0x444A4541
515         str r2, [r1, #CSCRL_OFFSET]
516         ldr r2, CS5_CSCRA_0x44443302
517         str r2, [r1, #CSCRA_OFFSET]
518     .endm   /* init_cs5 */
519
520     .macro init_aipi
521         // setup AIPI1 and AIPI2
522         mov r0, #SOC_AIPI1_BASE
523         ldr r1, AIPI1_0x20040304
524         str r1, [r0]  /* PSR0 */
525         ldr r2, AIPI1_0xDFFBFCFB
526         str r2, [r0, #4]  /* PSR1 */
527         // set r0 = AIPI2 base
528         add r0, r0, #0x20000
529         mov r1, #0x0
530         str r1, [r0]  /* PSR0 */
531         mov r2, #0xFFFFFFFF
532         str r2, [r0, #4]  /* PSR1 */
533     .endm // init_aipi
534
535     .macro init_max
536         ldr r0, SOC_MAX_BASE_W
537         add r1, r0, #MAX_SLAVE_PORT1_OFFSET
538         add r2, r0, #MAX_SLAVE_PORT2_OFFSET
539         add r0, r0, #MAX_SLAVE_PORT0_OFFSET
540
541         /* MPR and AMPR */
542         ldr r6, SOC_MAX_0x00302145         /* Priority SLCD>EMMA>DMA>Codec>DAHB>IAHB */
543         str r6, [r0, #MAX_SLAVE_MPR_OFFSET]   /* same for all slave ports */
544         str r6, [r0, #MAX_SLAVE_AMPR_OFFSET]
545         str r6, [r1, #MAX_SLAVE_MPR_OFFSET]
546         str r6, [r1, #MAX_SLAVE_AMPR_OFFSET]
547         str r6, [r2, #MAX_SLAVE_MPR_OFFSET]
548         str r6, [r2, #MAX_SLAVE_AMPR_OFFSET]
549     .endm //init_max
550
551    .macro init_drive_strength
552         ldr r0, SOC_SYSCTRL_BASE_W
553         ldr r1, DS_0x55555555
554         str r1, [r0, #(SOC_SYSCTRL_DSCR3 - SOC_SYSCTRL_BASE)]
555         str r1, [r0, #(SOC_SYSCTRL_DSCR5 - SOC_SYSCTRL_BASE)]
556         str r1, [r0, #(SOC_SYSCTRL_DSCR6 - SOC_SYSCTRL_BASE)]
557         ldr r1, DS_0x00005005
558         str r1, [r0, #(SOC_SYSCTRL_DSCR7 - SOC_SYSCTRL_BASE)]
559         ldr r1, DS_0x15555555
560         str r1, [r0, #(SOC_SYSCTRL_DSCR8 - SOC_SYSCTRL_BASE)]
561     .endm       // init_drive_strength
562
563     .macro setup_sdram_ddr
564         ldr r0, SOC_ESDCTL_BASE_W
565         mov r2, #SOC_CSD0_BASE
566         mov r1, #0x8        // initial reset
567         str r1, [r0, #0x10]
568         // Hold for more than 200ns
569         ldr r1, =0x10000
570     1:
571         subs r1, r1, #0x1
572         bne 1b
573
574         mov r1, #0x4
575         str r1, [r0, #0x10]
576
577         //Check The chip version TO1 or TO2
578         ldr r1, SOC_SI_ID_REG_W
579         ldr r1, [r1]
580         ands r1, r1, #0xF0000000
581         // add Latency on CAS only for TO2
582         ldreq r1, SDRAM_0x00795729
583         ldrne r1, SDRAM_0x00795429
584
585         str r1, [r0, #0x4]
586         ldr r1, SDRAM_0x92200000
587         str r1, [r0, #0x0]
588         ldr r1, [r2, #0xF00]
589         ldr r1, SDRAM_0xA2200000
590         str r1, [r0, #0x0]
591         ldr r1, [r2, #0xF00]
592         ldr r1, [r2, #0xF00]
593         ldr r1, SDRAM_0xB2200000
594         str r1, [r0, #0x0]
595         ldrb r1, [r2, #0x33]
596         add r3, r2, #0x1000000
597         ldrb r1, [r3]
598         ldr r1, SDRAM_0x82228485
599         str r1, [r0, #0x0]
600     .endm   // setup_sdram_ddr
601
602    .macro nfc_cmd_input
603         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
604         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
605         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
606         bl do_wait_op_done
607     .endm   // nfc_cmd_input
608
609     .macro do_addr_input
610         and r3, r3, #0xFF
611         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
612         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
613         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
614         bl do_wait_op_done
615     .endm   // do_addr_input
616
617 #define PLATFORM_VECTORS         _platform_vectors
618     .macro  _platform_vectors
619         .globl  _board_BCR, _board_CFG
620 _board_BCR:   .long   0       // Board Control register shadow
621 _board_CFG:   .long   0       // Board Configuration (read at RESET)
622     .endm
623
624 MXC_REDBOOT_ROM_START:      .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
625 CONST_0xFFF:                .word   0xFFF
626 AVIC_VECTOR0_ADDR_W:        .word   MXCBOOT_FLAG_REG
627 AVIC_VECTOR1_ADDR_W:        .word   MXCFIS_FLAG_REG
628 SOC_SYSCTRL_BASE_W:         .word   SOC_SYSCTRL_BASE
629 SOC_MAX_BASE_W:             .word   SOC_MAX_BASE
630 SOC_MAX_0x00302145:         .word   0x00302145
631 SOC_CRM_BASE_W:             .word   SOC_CRM_BASE
632 CRM_MPCTL0_VAL_W:           .word   CRM_MPCTL0_VAL
633 CRM_SPCTL0_VAL_W:           .word   CRM_SPCTL0_VAL
634 SOC_CRM_CSCR_W:             .word   CRM_CSCR_VAL
635 CRM_MPCTL0_VAL2_W:           .word   CRM_MPCTL0_VAL2
636 CRM_SPCTL0_VAL2_W:           .word   CRM_SPCTL0_VAL2
637 SOC_CRM_CSCR2_W:             .word   CRM_CSCR_VAL2
638 SOC_CRM_PCDR1_W:            .word   0x09030913   // p1=20 p2=10 p3=4 p4=10
639 SOC_CRM_PCCR0_W:            .word   0x3108480F
640 SOC_CS5_CTL_BASE_W:         .word   SOC_CS5_CTL_BASE
641 CS5_CSCRU_0x0000DCF6:       .word   0x0000DCF6
642 CS5_CSCRL_0x444A4541:       .word   0x444A4541
643 CS5_CSCRA_0x44443302:       .word   0x44443302
644 NFC_BASE_W:                 .word   NFC_BASE
645 SOC_ESDCTL_BASE_W:          .word   SOC_ESDCTL_BASE
646 SDRAM_0x00795429:           .word   0x00795429
647 SDRAM_0x00795729:           .word   0x00795729
648 SDRAM_0x92200000:           .word   0x92200000
649 SDRAM_0xA2200000:           .word   0xA2200000
650 SDRAM_0xB2200000:           .word   0xB2200000
651 SDRAM_0x82228485:           .word   0x82228485
652 CS0_0x0000CC03:             .word   0x0000CC03
653 CS0_0xA0330D01:             .word   0xA0330D01
654 CS0_0x00220800:             .word   0x00220800
655 CS0_0x23524E80:             .word   0x23524E80
656 CS0_0x10000D03:             .word   0x10000D03
657 CS0_0x00720900:             .word   0x00720900
658 CS0_CMD_0xAAA:              .word   0x0AAA
659 CS0_CMD_0x554:              .word   0x0554
660 CS0_CFG_0x66CA:             .word   0x66CA
661 CS0_BASE_ADDR_W:            .word   CS0_BASE_ADDR
662 SOC_CS0_CTL_BASE_W:         .word   SOC_CS0_CTL_BASE
663 DS_0x55555555:              .word   0x55555555
664 DS_0x00005005:              .word   0x00005005
665 DS_0x15555555:              .word   0x15555555
666 AIPI1_0x20040304:           .word   0x20040304
667 AIPI1_0xDFFBFCFB:           .word   0xDFFBFCFB
668 PBC_BASE_W:                 .word   PBC_BASE
669 SOC_SI_ID_REG_W:            .word   SOC_SI_ID_REG
670
671 /*---------------------------------------------------------------------------*/
672 /* end of hal_platform_setup.h                                               */
673 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */