]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx27/karo/v1_0/include/hal_platform_setup.h
added WinCE data structure
[karo-tx-redboot.git] / packages / hal / arm / mx27 / karo / v1_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/karo_tx27.h>          // Platform specific hardware definitions
51 #include CYGHWR_MEMORY_LAYOUT_H
52
53 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
54 #define PLATFORM_SETUP1 _platform_setup1
55 #define CYGHWR_HAL_ARM_HAS_MMU
56
57 #ifdef CYG_HAL_STARTUP_ROMRAM
58 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
59 #endif
60
61 #define TX27_NAND_PAGE_SIZE             2048
62 #define TX27_NAND_BLKS_PER_PAGE         64
63
64 #define CYGHWR_HAL_ROM_VADDR            0x0
65
66 #ifndef CYGOPT_HAL_ARM_TX27_DEBUG
67 #define LED_ON
68 #define LED_OFF
69         .macro  LED_CTRL,val
70         .endm
71         .macro  LED_BLINK,val
72         .endm
73         .macro  DELAY,val
74         .endm
75 #else
76 #define CYGHWR_LED_MACRO        LED_BLINK #\x
77 #define LED_ON                  bl      led_on
78 #define LED_OFF                 bl      led_off
79         .macro  DELAY,ms
80         ldr     r10, =\ms
81 111:
82         subs    r10, r10, #1
83         bmi     113f
84         ldr     r9, =3600
85 112:
86         subs    r9, r9, #1
87         bne     112b
88         b       111b
89         .ltorg
90 113:
91         .endm
92
93         .macro LED_CTRL,val
94         // switch user LED (PF13) on STK5
95         ldr     r10, GPIOF_BASE
96         // PTF_DR
97         mov     r9, \val
98         cmp     r9, #0
99         movne   r9, #(1 << 13)  // LED ON
100         moveq   r9, #0          // LED OFF
101         str     r9, [r10, #GPIO_DR]
102         .endm
103
104         .macro LED_BLINK,val
105         mov     r3, \val
106 211:
107         subs    r3, r3, #1
108         bmi     212f
109         LED_CTRL #1
110         DELAY   200
111         LED_CTRL #0
112         DELAY   300
113         b       211b
114 212:
115         DELAY   1000
116         .endm
117 #endif
118
119         .macro LED_INIT
120         // initialize GPIO PF13 for LED on STK5
121         ldr     r10, GPIOF_BASE
122         // PTF_GIUS
123         ldr     r9, [r10, #GPIO_GIUS]
124         orr     r9, r9, #(1 << 13)
125         str     r9, [r10, #GPIO_GIUS]
126         // PTF_DDIR
127         mov     r9,#(1 << 13)
128         str     r9, [r10, #GPIO_DDIR]
129         // PTF_OCR1
130         mov     r9, #(3 << (2 * 13))
131         str     r9, [r10, #GPIO_OCR1]
132         .endm
133
134 // This macro represents the initial startup code for the platform
135 // r11 is reserved to contain chip rev info in this file
136         .macro  _platform_setup1
137 KARO_TX27_SETUP_START:
138         // invalidate I/D cache/TLB
139         mov     r0, #0
140         mcr     15, 0, r0, c7, c7, 0    /* invalidate I cache and D cache */
141         mcr     15, 0, r0, c8, c7, 0    /* invalidate TLBs */
142         mcr     15, 0, r0, c7, c10, 4   /* Data Write Barrier */
143
144 init_aipi_start:
145         init_aipi
146
147         LED_INIT
148
149         // setup System Controls
150         ldr     r0, SOC_SYSCTRL_BASE_W
151         mov     r1, #0x03
152         str     r1, [r0, #(SOC_SYSCTRL_PCSR - SOC_SYSCTRL_BASE)]
153         // select 2kpage NAND (NF_FMS), CSD0, CS3
154         mvn     r1, #(FMCR_SDCS1_SEL | FMCR_NF_16BIT | FMCR_SLCDC_SEL)
155         str     r1, [r0, #(SOC_SYSCTRL_FMCR - SOC_SYSCTRL_BASE)]
156
157 init_max_start:
158         init_max
159 init_drive_strength_start:
160         init_drive_strength
161 #if 0
162 init_cs4_start:
163         init_cs4
164 #endif
165
166 #if 0
167 init_cs0_start:
168         init_cs0
169 #endif
170         LED_INIT
171
172         // check if sdram has been setup
173         cmp     pc, #SDRAM_BASE_ADDR
174         blo     init_clock_start
175         cmp     pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
176         blo     HWInitialise_skip_SDRAM_setup
177
178 init_clock_start:
179         init_clock
180 init_sdram_start:
181         LED_BLINK #1
182         setup_sdram_ddr
183         LED_BLINK #2
184 HWInitialise_skip_SDRAM_setup:
185         ldr     r0, NFC_BASE_W
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
192 NAND_Boot_Start:
193         /* Copy image from flash to SDRAM first */
194         ldr     r1, MXC_REDBOOT_RAM_START
195 1:
196         ldmia   r0!, {r3-r10}
197         stmia   r1!, {r3-r10}
198         cmp     r0, r2
199         blo     1b
200
201         LED_ON
202         ldr     r1, MXC_REDBOOT_RAM_START
203         ldr     r0, NFC_BASE_W
204 2:
205         ldr     r3, [r1], #4
206         ldr     r4, [r0], #4
207         cmp     r3, r4
208         bne     3f
209
210         cmp     r0, r2
211         blo     2b
212         LED_OFF
213         b       4f
214 3:
215         LED_BLINK #3
216         b       3b
217 4:
218         LED_ON
219         /* Jump to SDRAM */
220         bl      jump_to_sdram
221         LED_OFF
222 NAND_Copy_Main:
223         ldr     r0, NFC_BASE_W  //r0: nfc base. Reloaded after each page copying
224         mov     r1, #TX27_NAND_PAGE_SIZE //r1: starting flash addr to be copied. Updated constantly
225         add     r2, r0, #TX27_NAND_PAGE_SIZE //r2: end of 1st RAM buf. Doesn't change
226         add     r4, r0, #0xE00  //r4: NFC register base. Doesn't change
227         ldr     r5, MXC_REDBOOT_RAM_START
228         add     r6, r5, #REDBOOT_IMAGE_SIZE //r6: end of SDRAM address for copying. Doesn't change
229         add     r5, r5, r1      //r5: starting SDRAM address for copying. Updated constantly
230
231         // enable ECC, disable interrupts
232         mov     r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
233         strh    r3, [r4, #NAND_FLASH_CONFIG1_REG_OFF]
234
235         //unlock internal buffer
236         mov     r3, #0x2
237         strh    r3, [r4, #0xA]
238
239 Nfc_Read_Page:
240         LED_ON
241         mov     r8, #0
242         strh    r8, [r4, #RAM_BUFFER_ADDRESS_REG_OFF]
243
244         mov     r3, #0x0
245         bl      nfc_cmd_input
246
247         LED_ON
248         mov     r3, #0
249         bl      nfc_addr_input
250         LED_ON
251         mov     r3, #0
252         bl      nfc_addr_input  //2nd addr cycle
253         LED_ON
254         mov     r3, r1, lsr #11
255         bl      nfc_addr_input  //3rd addr cycle
256         LED_ON
257         mov     r3, r1, lsr #19
258         bl      nfc_addr_input  //4th addr cycle
259
260         LED_ON
261         mov     r3, #0x30
262         bl      nfc_cmd_input
263
264         LED_ON
265         bl      nfc_data_output
266         LED_ON
267         strh    r8, [r4, #RAM_BUFFER_ADDRESS_REG_OFF]
268         bl      nfc_data_output
269         LED_ON
270         strh    r8, [r4, #RAM_BUFFER_ADDRESS_REG_OFF]
271         bl      nfc_data_output
272         LED_ON
273         strh    r8, [r4, #RAM_BUFFER_ADDRESS_REG_OFF]
274         bl      nfc_data_output
275 #if 1
276         // check for bad block
277         mov     r3, r1, lsl #(32-17)    // get rid of block number
278         cmp     r3, #(TX27_NAND_PAGE_SIZE << (32-17)) // check if not first or second page in block
279         bhi     Copy_Good_Blk
280 #else
281         b       Copy_Good_Blk
282 #endif
283         add     r9, r0, #TX27_NAND_PAGE_SIZE            //r3 -> spare area buf 0
284         ldrh    r9, [r9, #0x4]
285         and     r9, r9, #0xFF00
286         cmp     r9, #0xFF00
287         beq     Copy_Good_Blk
288         // really sucks. Bad block!!!!
289         cmp     r3, #0x0
290         beq     Skip_bad_block
291         // even suckier since we already read the first page!
292         sub     r5, r5, #TX27_NAND_PAGE_SIZE    //rewind 1 page for the sdram pointer
293         sub     r1, r1, #TX27_NAND_PAGE_SIZE            //rewind 1 page for the flash pointer
294 Skip_bad_block:
295 #ifdef CYGOPT_HAL_ARM_TX27_DEBUG
296         LED_BLINK #1
297         b Skip_bad_block
298 #endif
299         add     r1, r1, #(TX27_NAND_BLKS_PER_PAGE*TX27_NAND_PAGE_SIZE)
300         b       Nfc_Read_Page
301
302 Copy_Good_Blk:
303         // copying page
304 1:
305         ldmia   r0!, {r7-r14}
306         stmia   r5!, {r7-r14}
307         cmp     r0, r2
308         blo     1b
309
310         LED_ON
311         LED_OFF
312         cmp     r5, r6
313         bge     NAND_Copy_Main_done
314
315         add     r1, r1, #TX27_NAND_PAGE_SIZE
316         ldr     r0, NFC_BASE_W
317         b       Nfc_Read_Page
318 NAND_Copy_Main_done:
319
320 Normal_Boot_Continue:
321         bl      jump_to_sdram
322 // Code and all data used up to here must fit within the first 2KiB of FLASH ROM!
323 Now_in_SDRAM:
324         LED_BLINK #3
325
326 #ifdef CYG_HAL_STARTUP_ROMRAM   /* enable running from RAM */
327         /* Copy image from flash to SDRAM first */
328         ldr     r0, =0xFFFFF000
329         and     r0, r0, pc
330         ldr     r1, MXC_REDBOOT_RAM_START
331         cmp     r0, r1
332         beq     HWInitialise_skip_SDRAM_copy
333
334         add     r2, r0, #REDBOOT_IMAGE_SIZE
335 1:
336         ldmia   r0!, {r7-r14}
337         stmia   r1!, {r7-r14}
338         cmp     r0, r2
339         ble     1b
340
341         bl      jump_to_sdram
342 #endif /* CYG_HAL_STARTUP_ROMRAM */
343
344 HWInitialise_skip_SDRAM_copy:
345         LED_BLINK #2
346
347 init_cs0_sync_start:
348         init_cs0_sync
349
350 NAND_ClockSetup:
351         ldr     r1, =(SOC_CRM_BASE)
352         ldr     r2, [r1, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
353         bic     r2, r2, #0x0200
354         orr     r2, r2, #0x01C0
355         ldr     r1, =(SOC_CRM_BASE)
356         str     r2, [r1, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
357
358 /* end of NAND clock divider setup */
359
360         // TLSbo76381: enable USB/PP/DMA burst override bits in GPCR
361         ldr     r1, =(SOC_SYSCTRL_GPCR)
362         ldr     r2, [r1]
363         orr     r2, r2, #0x700
364         str     r2, [r1]
365
366         // Set up a stack [for calling C code]
367         ldr     r1, =__startup_stack
368         ldr     r2, =RAM_BANK0_BASE
369         orr     sp, r1, r2
370
371         LED_ON
372         // Create MMU tables
373         bl      hal_mmu_init
374         LED_OFF
375
376         // Enable MMU
377         ldr     r2, =10f
378         mrc     MMU_CP, 0, r1, MMU_Control, c0          // get c1 value to r1 first
379         orr     r1, r1, #7                              // enable MMU bit
380         mcr     MMU_CP, 0, r1, MMU_Control, c0
381         b       9f
382         .align  5
383 9:
384         mov     pc,r2   /* Change address spaces */
385 10:
386         nop
387         .endm                   // _platform_setup1
388
389 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
390 #define PLATFORM_SETUP1
391 #endif
392
393         .macro init_clock
394         ldr     r0, SOC_CRM_BASE_W
395         // disable MPLL/SPLL first
396         ldr     r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
397         bic     r1, r1, #0x3
398         str     r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
399
400         // configure MPCTL0
401         ldr     r1, CRM_MPCTL0_VAL2_W
402         str     r1, [r0, #(SOC_CRM_MPCTL0 - SOC_CRM_BASE)]
403
404         // configure SPCTL0
405         ldr     r1, CRM_SPCTL0_VAL2_W
406         str     r1, [r0, #(SOC_CRM_SPCTL0 - SOC_CRM_BASE)]
407
408         ldr r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
409 #ifdef PLL_REF_CLK_32768HZ
410         // Make sure to use CKIL
411         bic     r1, r1, #(3 << 16)
412 #else
413         orr     r1, r1, #(3 << 16)              // select 26MHz
414 #endif
415         orr     r1, r1, #0x000C0000             // restart SPLL and MPLL
416         orr     r1, r1, #0x00000003             // enable SPLL and MPLL
417         str     r1, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
418
419         // add some delay here
420         mov     r1, #0x1000
421 1:
422         subs r1, r1, #0x1
423         bne     1b
424
425         ldr     r2, SOC_CRM_CSCR2_W
426         str     r2, [r0, #(SOC_CRM_CSCR - SOC_CRM_BASE)]
427
428         // Set divider of H264_CLK to zero, NFC to 3.
429         ldr     r2, [r0, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
430         bic     r2, r2, #0x0000FC00
431         str     r2, [r0, #(SOC_CRM_PCDR0 - SOC_CRM_BASE)]
432
433         /* Configure PCDR1 */
434         ldr     r1, SOC_CRM_PCDR1_W
435         str     r1, [r0, #(SOC_CRM_PCDR1 - SOC_CRM_BASE)]
436
437         // Configure PCCR0 and PCCR1
438         ldr     r1, SOC_CRM_PCCR0_W
439         str     r1, [r0, #(SOC_CRM_PCCR0 - SOC_CRM_BASE)]
440
441         ldr     r1, [r0, #(SOC_CRM_PCCR1 - SOC_CRM_BASE)]
442         orr     r1, r1, #0x0780
443         str     r1, [r0, #(SOC_CRM_PCCR1 - SOC_CRM_BASE)]
444         // make default CLKO to be FCLK
445         ldr     r1, [r0, #(SOC_CRM_CCSR - SOC_CRM_BASE)]
446         and     r1, r1, #0xFFFFFFE0
447         orr     r1, r1, #0x7
448         str     r1, [r0, #(SOC_CRM_CCSR - SOC_CRM_BASE)]
449         .endm //init_clock
450
451         .macro init_cs0
452         ldr     r1, SOC_CS0_CTL_BASE_W
453         ldr     r2, CS0_CSCRU_VAL
454         str     r2, [r1, #CSCRU_OFFSET]
455         ldr     r2, CS0_CSCRL_VAL
456         str     r2, [r1, #CSCRL_OFFSET]
457         ldr     r2, CS0_CSCRA_VAL
458         str     r2, [r1, #CSCRA_OFFSET]
459         .endm // init_cs0
460
461         /* CS0 sync mode setup */
462         .macro init_cs0_sync
463         /*
464         * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
465         */
466         ldr     r0, =SOC_CS0_CTL_BASE
467         ldr     r1, CS0_CSCRU_SYNC_VAL
468         str     r1, [r0, #CSCRU_OFFSET]
469         ldr     r1, CS0_CSCRL_SYNC_VAL
470         str     r1, [r0, #CSCRL_OFFSET]
471         ldr     r1, CS0_CSCRA_SYNC_VAL
472         str     r1, [r0, #CSCRA_OFFSET]
473         .endm /* init_cs0_sync */
474
475         .macro init_cs4 /* ADS board expanded IOs */
476         ldr     r1, SOC_CS4_CTL_BASE_W
477         ldr     r2, CS4_CSCRU_VAL
478         str     r2, [r1, #CSCRU_OFFSET]
479         ldr     r2, CS4_CSCRL_VAL
480         str     r2, [r1, #CSCRL_OFFSET]
481         ldr     r2, CS4_CSCRA_VAL
482         str     r2, [r1, #CSCRA_OFFSET]
483         .endm   /* init_cs4 */
484
485         .macro init_aipi
486         // setup AIPI1 and AIPI2
487         mov     r0, #SOC_AIPI1_BASE
488         ldr     r1, AIPI1_PSR0_VAL
489         str     r1, [r0]  /* PSR0 */
490         ldr     r2, AIPI1_PSR1_VAL
491         str     r2, [r0, #4]  /* PSR1 */
492         // set r0 = AIPI2 base
493         add     r0, r0, #0x20000
494         mov     r1, #0x0
495         str     r1, [r0]  /* PSR0 */
496         mvn     r2, #0
497         str     r2, [r0, #4]  /* PSR1 */
498         .endm // init_aipi
499
500         .macro init_max
501         ldr     r0, SOC_MAX_BASE_W
502         add     r1, r0, #MAX_SLAVE_PORT1_OFFSET
503         add     r2, r0, #MAX_SLAVE_PORT2_OFFSET
504         add     r0, r0, #MAX_SLAVE_PORT0_OFFSET
505
506         /* MPR and AMPR */
507         ldr     r6, SOC_MAX_MPR_VAL     /* Priority SLCD>EMMA>DMA>Codec>DAHB>IAHB */
508         str     r6, [r0, #MAX_SLAVE_MPR_OFFSET]   /* same for all slave ports */
509         str     r6, [r0, #MAX_SLAVE_AMPR_OFFSET]
510         str     r6, [r1, #MAX_SLAVE_MPR_OFFSET]
511         str     r6, [r1, #MAX_SLAVE_AMPR_OFFSET]
512         str     r6, [r2, #MAX_SLAVE_MPR_OFFSET]
513         str     r6, [r2, #MAX_SLAVE_AMPR_OFFSET]
514         .endm //init_max
515
516         .macro init_drive_strength
517         ldr     r0, SOC_SYSCTRL_BASE_W
518         ldr     r1, DS_DSCR_VAL
519         str     r1, [r0, #(SOC_SYSCTRL_DSCR3 - SOC_SYSCTRL_BASE)]
520         str     r1, [r0, #(SOC_SYSCTRL_DSCR5 - SOC_SYSCTRL_BASE)]
521         str     r1, [r0, #(SOC_SYSCTRL_DSCR6 - SOC_SYSCTRL_BASE)]
522         ldr     r1, DS_DSCR7_VAL
523         str     r1, [r0, #(SOC_SYSCTRL_DSCR7 - SOC_SYSCTRL_BASE)]
524         ldr     r1, DS_DSCR8_VAL
525         str     r1, [r0, #(SOC_SYSCTRL_DSCR8 - SOC_SYSCTRL_BASE)]
526         .endm   // init_drive_strength
527
528         .macro setup_sdram_ddr
529         // SDRAM controller base address
530         ldr     r0, SOC_ESDCTL_BASE_W
531         // base address of SDRAM for SET MODE commands written to SDRAM via address lines
532         mov     r2, #SOC_CSD0_BASE
533
534         mov     r1, #(1 << 1)           // SDRAM controller reset
535         str     r1, [r0, #ESDCTL_ESDMISC]
536 1:
537         // wait until SDRAMRDY bit is set indicating SDRAM is usable
538         ldr     r1, [r0, #ESDCTL_ESDMISC]
539         tst     r1, #(1 << 31)
540         beq     1b
541
542         mov     r1, #(1 << 3)           @ delay line soft reset
543         str     r1, [r0, #ESDCTL_ESDMISC]
544 1:
545         // wait until SDRAMRDY bit is set indicating SDRAM is usable
546         ldr     r1, [r0, #ESDCTL_ESDMISC]
547         tst     r1, #(1 << 31)
548         beq     1b
549
550         mov     r1, #(1 << 2)           @ enable DDR pipeline
551         str     r1, [r0, #ESDCTL_ESDMISC]
552
553         ldr     r1, SDRAM_ESDCFG0_VAL
554         str     r1, [r0, #ESDCTL_ESDCFG0]
555
556         ldr     r1, SDRAM_PRE_ALL_CMD
557         str     r1, [r0, #ESDCTL_ESDCTL0]
558
559         str     r1, [r2, #(1 << 10)]    @ contents of r1 irrelevant, data written via A0-A11
560
561         ldr     r1, SDRAM_AUTO_REF_CMD
562         str     r1, [r0, #ESDCTL_ESDCTL0]
563         @ initiate 2 auto refresh cycles
564         .rept 2
565         str     r1, [r2]
566         .endr
567
568         ldr     r1, SDRAM_SET_MODE_REG_CMD
569         str     r1, [r0, #ESDCTL_ESDCTL0]
570
571         @ address offset for extended mode register
572         add     r3, r2, #(2 << 24)
573         @ select drive strength via extended mode register:
574         @ 0=full 1=half 2=quarter 3=3-quarter
575         ldrb    r1, [r2, #(0 << 5)]
576
577         ldrb    r1, [r2, #0x033]        @ write to SDRAM MODE register (via A0-A12)
578
579         ldr     r1, SDRAM_NORMAL_MODE
580         str     r1, [r0, #ESDCTL_ESDCTL0]
581
582         str     r1, [r2]
583         mov     r1, #((1 << 3) | (1 << 2) | (1 << 5))
584         str     r1, [r0, #ESDCTL_ESDMISC]
585         .endm   // setup_sdram_ddr
586
587 #ifdef CYGOPT_HAL_ARM_TX27_DEBUG
588 led_on:
589         ldr     r10, GPIOF_BASE
590         // PTF_DR
591         mov     r9, #(1 << 13)  // LED ON
592         str     r9, [r10, #GPIO_DR]
593         mov     pc, lr
594
595 led_off:
596         ldr     r10, GPIOF_BASE
597         // PTF_DR
598         mov     r9, #0          // LED OFF
599         str     r9, [r10, #GPIO_DR]
600         mov     pc, lr
601 #endif
602         
603 nfc_cmd_input:
604         strh    r3, [r4, #NAND_FLASH_CMD_REG_OFF]
605         mov     r3, #NAND_FLASH_CONFIG2_FCMD_EN
606         strh    r3, [r4, #NAND_FLASH_CONFIG2_REG_OFF]
607         b       nfc_wait_op_done
608
609 nfc_addr_input:
610         and     r3, r3, #0xFF
611         strh    r3, [r4, #NAND_FLASH_ADD_REG_OFF]
612         mov     r3, #NAND_FLASH_CONFIG2_FADD_EN
613         strh    r3, [r4, #NAND_FLASH_CONFIG2_REG_OFF]
614         b       nfc_wait_op_done
615
616 nfc_data_output:
617         mov     r3, #FDO_PAGE_SPARE_VAL
618         strh    r3, [r4, #NAND_FLASH_CONFIG2_REG_OFF]
619         add     r8, r8, #1
620         b       nfc_wait_op_done
621
622 nfc_wait_op_done:
623 311:
624         ldrh    r3, [r4, #NAND_FLASH_CONFIG2_REG_OFF]
625         ands    r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
626         movne   r3, #0x0
627         strneh  r3, [r4, #NAND_FLASH_CONFIG2_REG_OFF]
628         movne   pc, lr
629         b       311b
630
631 jump_to_sdram:
632         b       1f
633         .align  5
634 1:
635         mcr     15, 0, r0, c7, c7, 0    /* invalidate I cache and D cache */
636         mcr     15, 0, r0, c8, c7, 0    /* invalidate TLBs */
637         mcr     15, 0, r0, c7, c10, 4   /* Data Write Barrier */
638         ldr     r0, SDRAM_ADDR_MASK
639         ldr     r1, MXC_REDBOOT_RAM_START
640         and     r0, lr, r0
641         sub     r0, r1, r0
642         add     lr, lr, r0
643         mov     pc, lr
644
645 #define PLATFORM_VECTORS         _platform_vectors
646         .macro  _platform_vectors
647         .globl  _KARO_MAGIC
648 _KARO_MAGIC:
649         .ascii  "KARO_CE6"
650         .globl  _KARO_STRUCT_SIZE
651 _KARO_STRUCT_SIZE:
652         .word   0       // reserve space structure length
653
654         .globl  _KARO_CECFG_START
655 _KARO_CECFG_START:
656         .rept   1024/4
657         .word   0       // reserve space for CE configuration
658         .endr
659
660         .globl  _KARO_CECFG_END
661 _KARO_CECFG_END:
662         .endm
663
664         .align  5
665         .ascii  "KARO TX27 " __DATE__ " " __TIME__
666         .align
667 // All these constants need to be in the first 2KiB of FLASH
668 GPIOF_BASE:                     .word   0x10015500
669 SDRAM_ADDR_MASK:                .word   0xffff0000
670 MXC_REDBOOT_RAM_START:          .word   SDRAM_BASE_ADDR + SDRAM_SIZE - REDBOOT_OFFSET
671 SOC_SYSCTRL_BASE_W:             .word   SOC_SYSCTRL_BASE
672 SOC_MAX_BASE_W:                 .word   SOC_MAX_BASE
673 SOC_MAX_MPR_VAL:                .word   0x00302145
674 SOC_CRM_BASE_W:                 .word   SOC_CRM_BASE
675 CRM_MPCTL0_VAL2_W:              .word   CRM_MPCTL0_VAL2
676 CRM_SPCTL0_VAL2_W:              .word   CRM_SPCTL0_VAL2
677 SOC_CRM_CSCR2_W:                .word   CRM_CSCR_VAL2
678 SOC_CRM_PCDR1_W:                .word   0x09030913      // p1=20 p2=10 p3=4 p4=10
679 SOC_CRM_PCCR0_W:                .word   0x3108480F
680 SOC_CS4_CTL_BASE_W:             .word   SOC_CS4_CTL_BASE
681 CS4_CSCRU_VAL:                  .word   0x0000DCF6
682 CS4_CSCRL_VAL:                  .word   0x444A4541
683 CS4_CSCRA_VAL:                  .word   0x44443302
684 NFC_BASE_W:                     .word   NFC_BASE
685 SOC_ESDCTL_BASE_W:              .word   SOC_ESDCTL_BASE
686 SDRAM_ESDCFG0_VAL:              .word   0x00395729
687 SDRAM_PRE_ALL_CMD:              .word   0x92120000
688 SDRAM_AUTO_REF_CMD:             .word   0xA2120000
689 SDRAM_SET_MODE_REG_CMD:         .word   0xB2120000
690 #if SDRAM_SIZE > SZ_64M
691 SDRAM_NORMAL_MODE:              .word   0x82226485
692 #else
693 SDRAM_NORMAL_MODE:              .word   0x82126485
694 #endif
695 CS0_CSCRU_VAL:                  .word   0x0000CC03
696 CS0_CSCRL_VAL:                  .word   0xA0330D01
697 CS0_CSCRA_VAL:                  .word   0x00220800
698 CS0_CSCRU_SYNC_VAL:             .word   0x23524E80
699 CS0_CSCRL_SYNC_VAL:             .word   0x10000D03
700 CS0_CSCRA_SYNC_VAL:             .word   0x00720900
701 CS0_BASE_ADDR_W:                .word   CS0_BASE_ADDR
702 SOC_CS0_CTL_BASE_W:             .word   SOC_CS0_CTL_BASE
703 DS_DSCR_VAL:                    .word   0x55555555
704 DS_DSCR7_VAL:                   .word   0x00005005
705 DS_DSCR8_VAL:                   .word   0x15555555
706 AIPI1_PSR0_VAL:                 .word   0x20040304
707 AIPI1_PSR1_VAL:                 .word   0xDFFBFCFB
708
709 /*----------------------------------------------------------------------*/
710 /* end of hal_platform_setup.h                                          */
711 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */