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