]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx37/3stack/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx37 / 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 NFC_2K_BI_SWAP
61 #define SDRAM_FULL_PAGE_BIT     0x100
62 #define SDRAM_FULL_PAGE_MODE    0x37
63 #define SDRAM_BURST_MODE        0x33
64
65 #define CYGHWR_HAL_ROM_VADDR    0x0
66
67 #if 0
68 #define UNALIGNED_ACCESS_ENABLE
69 #define SET_T_BIT_DISABLE
70 #define BRANCH_PREDICTION_ENABLE
71 #endif
72
73 //#define ENABLE_IMPRECISE_ABORT
74
75 #define PLATFORM_PREAMBLE flash_header
76
77 //flash header & DCD @ 0x400
78 .macro flash_header
79     b reset_vector
80 .org 0x400
81 app_code_jump_v:        .long reset_vector
82 app_code_barker:        .long 0xB1
83 app_code_csf:           .long 0
84 dcd_ptr_ptr:            .long dcd_ptr
85 super_root_key:         .long 0
86 dcd_ptr:                        .long dcd_data
87 app_dest_ptr:           .long 0x47f00000
88
89 dcd_data:                       .long 0xB17219E9
90 dcd_len:                        .long (49*12)
91
92 //DCD
93 //iomux 1
94 .long 4
95 .long 0xc3fa8008
96 .long 0x1
97 // 2
98 .long 4
99 .long 0xc3fa800c
100 .long 0x1
101 // 3
102 .long 4
103 .long 0xc3fa8010
104 .long 0x1
105 // 4
106 .long 4
107 .long 0xc3fa8014
108 .long 0x1
109 //5
110 .long 4
111 .long 0xc3fa8018
112 .long 0x1
113 //6
114 .long 4
115 .long 0xc3fa801c
116 .long 0x1
117 // 7
118 .long 4
119 .long 0xc3fa8020
120 .long 0x1
121 // 8
122 .long 4
123 .long 0xc3fa8024
124 .long 0x1
125 // 9
126 .long 4
127 .long 0xc3fa8028
128 .long 0x1
129 //10
130 .long 4
131 .long 0xc3fa802c
132 .long 0x1
133 // 11
134 .long 4
135 .long 0xc3fa8030
136 .long 0x1
137 // 12
138 .long 4
139 .long 0xc3fa8034
140 .long 0x1
141 // 13
142 .long 4
143 .long 0xc3fa8038
144 .long 0x1
145 // 14
146 .long 4
147 .long 0xc3fa803c
148 .long 0x1
149 // 15
150 .long 4
151 .long 0xc3fa8040
152 .long 0x1
153 // 16
154 .long 4
155 .long 0xc3fa8044
156 .long 0x1
157 // 17
158 .long 4
159 .long 0xc3fa8048
160 .long 0x1
161 // 18
162 .long 4
163 .long 0xc3fa804c
164 .long 0x1
165 // 19
166 .long 4
167 .long 0xc3fa805c
168 .long 0x1
169 // 20
170 .long 4
171 .long 0xc3fa82bc
172 .long 0x02c4
173 // 21
174 .long 4
175 .long 0xc3fa8060
176 .long 0x1
177 // 22
178 .long 4
179 .long 0xc3fa82c0
180 .long 0x02c4
181 // 23
182 .long 4
183 .long 0xc3fa84a8
184 .long 0x2
185 // 24
186 .long 4
187 .long 0xc3fa84b0
188 .long 0x2
189 // 25
190 .long 4
191 .long 0xc3fa84b4
192 .long 0x2
193 // 26
194 .long 4
195 .long 0xc3fa84e0
196 .long 0x2
197 // 27
198 .long 4
199 .long 0xc3fa8278
200 .long 0x2
201 // 28
202 .long 4
203 .long 0xc3fa827c
204 .long 0x2
205 // 29
206 .long 4
207 .long 0xc3fa8298
208 .long 0x2
209 // 30
210 .long 4
211 .long 0xc3fa829c
212 .long 0x2
213 // 31
214 .long 4
215 .long 0xc3fa84fc
216 .long 0x2
217 // 32
218 .long 4
219 .long 0xc3fa8504
220 .long 0x2
221 // 33
222 .long 4
223 .long 0xc3fa848c
224 .long 0x2
225 // 34
226 .long 4
227 .long 0xc3fa849c
228 .long 0x2
229 // 35
230 .long 4
231 .long 0xc3fa8294
232 .long 0x2
233 // 36
234 .long 4
235 .long 0xc3fa8280
236 .long 0x2
237 // 37
238 .long 4
239 .long 0xc3fa8284
240 .long 0x2
241 // 38
242 .long 4
243 .long 0xc3fa8288
244 .long 0x2
245 // 39
246 .long 4
247 .long 0xc3fa828c
248 .long 0x2
249 // 40
250 .long 4
251 .long 0xc3fa8290
252 .long 0x2
253
254 // set CSD0    1
255 // 41
256 .long 4
257 .long 0xe3fd9000
258 .long 0x80000000
259
260 // Precharge command  2
261 // 42
262 .long 4
263 .long 0xe3fd9014
264 .long 0x04008008
265 // refresh commands  3
266 // 43
267 .long 4
268 .long 0xe3fd9014
269 .long 0x00008010
270
271 // 44
272 .long 4
273 .long 0xe3fd9014
274 .long 0x00008010
275 // LMR with CAS=3 BL=3   5
276 // 45
277 .long 4
278 .long 0xe3fd9014
279 .long 0x00338018
280
281 // 13row 10 col 32 bit sref=4 micro model  6
282 // 46
283 .long 4
284 .long 0xe3fd9000
285 .long 0xb2220000
286
287 // timing parameter 7
288 // 47
289 .long 4
290 .long 0xe3fd9004
291 .long 0x899f6bba
292
293 // mddr enable RLAT=2  8
294 // 48
295 .long 4
296 .long 0xe3fd9010
297 .long 0x000a1104
298
299 // Normal mode  9
300 // 49
301 .long 4
302 .long 0xe3fd9014
303 .long 0x00000000
304
305 image_len:           .long REDBOOT_IMAGE_SIZE
306
307 .endm
308
309
310
311
312 // This macro represents the initial startup code for the platform
313     .macro  _platform_setup1
314 FSL_BOARD_SETUP_START:
315
316 /*
317  *       ARM1136 init
318  *       - invalidate I/D cache/TLB and drain write buffer;
319  *       - invalidate L2 cache
320  *       - unaligned access
321  *       - branch predictions
322  */
323     // mrc p15, 0, r0, c1, c1, 0 // Read Secure Configuration Register data. Why doesn't work???
324     // mcr p15, 0, <Rd>, c1, c1, 0 ; Write Secure Configuration Register data
325 #ifdef ENABLE_IMPRECISE_ABORT
326         mrs r1, spsr            // save old spsr
327         mrs r0, cpsr            // read out the cpsr
328         bic r0, r0, #0x100      // clear the A bit
329         msr spsr, r0            // update spsr
330         add lr, pc, #0x8        // update lr
331         movs pc, lr             // update cpsr
332         nop
333         nop
334         nop
335         nop
336         msr spsr, r1            // restore old spsr
337 #endif
338
339     mov r0, #0
340     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
341     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
342     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
343
344     /* Also setup the Peripheral Port Remap register inside the core */
345     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
346     mcr p15, 0, r0, c15, c2, 4
347
348     /* Reload data from spare area to 0x400 of main area if booting from NAND */
349     ldr r0, NFC_BASE_W
350     cmp pc, r0
351     blo 1f
352     cmp pc, r1
353     bhi 1f
354 #ifdef BARKER_CODE_SWAP_LOC
355 #if BARKER_CODE_SWAP_LOC != 0x404
356 #error FIXME: the following depends on barker code to be 0x404
357 #endif
358     // Recover the word at 0x404 offset using the one stored in the spare area 0
359     add r1, r0, #0x400
360     add r1, r1, #0x4
361     mov r3, #0x1000
362     ldr r2, [r0, r3]
363     str r2, [r1]
364 #endif
365 1:
366 #ifdef L2CC_ENABLED
367     /*** L2 Cache setup/invalidation/disable ***/
368     /* Disable L2 cache first */
369     mov r0, #L2CC_BASE_ADDR
370     mov r2, #0
371     str r2, [r0, #L2_CACHE_CTL_REG]
372     /*
373      * Configure L2 Cache:
374      * - 128k size(16k way)
375      * - 8-way associativity
376      * - 0 ws TAG/VALID/DIRTY
377      * - 4 ws DATA R/W
378      */
379     mov r2, #0xFF000000
380     add r2, r2, #0x00F00000
381     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
382     and r1, r1, r2
383     ldr r2, L2CACHE_PARAM
384     orr r1, r1, r2
385     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
386
387     /* Invalidate L2 */
388     mov r1, #0xFF
389     str r1, [r0, #L2_CACHE_INV_WAY_REG]
390 L2_loop:
391     /* Poll Invalidate By Way register */
392     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
393     ands r2, r2, #0xFF
394     bne L2_loop
395     /*** End of L2 operations ***/
396 #endif
397
398 /*
399  * End of ARM1136 init
400  */
401 init_spba_start:
402     init_spba
403 init_aips_start:
404     init_aips
405 init_max_start:
406     init_max
407 init_m4if_start:
408     init_m4if
409 init_iomux_start:
410     init_iomux
411
412     // disable wdog
413     ldr r0, =0x30
414     ldr r1, WDOG1_BASE_W
415     strh r0, [r1]
416
417     /* If SDRAM has been setup, bypass clock/WEIM setup */
418     cmp pc, #SDRAM_BASE_ADDR
419     blo external_boot_cont
420     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
421     blo internal_boot_cont
422
423 external_boot_cont:
424 init_sdram_start:
425     setup_sdram
426
427 internal_boot_cont:
428 init_clock_start:
429     init_clock
430
431
432 HWInitialise_skip_SDRAM_setup:
433     ldr r0, NFC_BASE_W
434     add r2, r0, #0x1000      // 4K window
435     cmp pc, r0
436     blo Normal_Boot_Continue
437     cmp pc, r2
438     bhi Normal_Boot_Continue
439
440 NAND_Boot_Start:
441     /* Copy image from flash to SDRAM first */
442     ldr r1, MXC_REDBOOT_ROM_START
443 1:  ldmia r0!, {r3-r10}
444     stmia r1!, {r3-r10}
445     cmp r0, r2
446     blo 1b
447
448     /* Jump to SDRAM */
449     ldr r1, CONST_0x0FFF
450     and r0, pc, r1     /* offset of pc */
451     ldr r1, MXC_REDBOOT_ROM_START
452     add r1, r1, #0x10
453     add pc, r0, r1
454     nop
455     nop
456     nop
457     nop
458     nop
459
460 NAND_Copy_Main:
461     // Check if x16/2kb page
462 //    ldr r7, CCM_BASE_ADDR_W
463 //    ldr r7, [r7, #0xC]
464 //    ands r7, r7, #(1 << 30)
465     ldr r0, NFC_BASE_W   //r0: nfc base. Reloaded after each page copying
466     mov r1, #0x1000       //r1: starting flash addr to be copied. Updated constantly
467                         // ???? should be dynamic based on the page size kevin todo
468     add r2, r0, #0x1000   //r2: end of 3rd RAM buf. Doesn't change ?? dynamic
469
470     ldr r11, NFC_IP_BASE_W  //r11: NFC IP register base. Doesn't change
471     add r12, r0, #0x1E00  //r12: NFC AXI register base. Doesn't change
472     ldr r14, MXC_REDBOOT_ROM_START
473     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
474     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
475
476     //unlock internal buffer
477     mov r3, #0xFF000000
478     add r3, r3, #0x00FF0000
479     str r3, [r11, #0x4]
480     str r3, [r11, #0x8]
481     str r3, [r11, #0xC]
482     str r3, [r11, #0x10]
483     mov r3, #0x20000
484     add r3, r3, #0x4
485     str r3, [r11, #0x0]     // kevin - revist for multiple CS ??
486     mov r3, #0
487     str r3, [r11, #0x18]
488
489 Nfc_Read_Page:
490 //  writew(FLASH_Read_Mode1, NAND_ADD_CMD_REG);
491     mov r3, #0x0;
492     str r3, [r12, #0x0]
493     mov r3, #NAND_LAUNCH_FCMD
494     str r3, [r12, #0xC]
495
496     do_wait_op_done
497 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
498     mov r4, r1, lsl #1
499     and r3, r4, #0xFF
500     mov r3, r3, lsl #16
501     do_addr_input       //1st addr cycle
502     mov r3, r4, lsr #8
503     and r3, r3, #0x1F
504     mov r3, r3, lsl #16
505     do_addr_input       //2nd addr cycle
506     mov r3, r4, lsr #13
507     and r3, r3, #0xFF
508     mov r3, r3, lsl #16
509     do_addr_input       //3rd addr cycle
510     mov r3, r4, lsr #21
511     and r3, r3, #0xFF
512     mov r3, r3, lsl #16
513     do_addr_input       //4th addr cycle
514     mov r3, r4, lsr #29
515     and r3, r3, #0xF
516     mov r3, r3, lsl #16
517     do_addr_input       //5th addr cycle TODO
518
519 //  writew(FLASH_Read_Mode1_2K, NAND_ADD_CMD_REG);
520     mov r3, #0x30;
521     str r3, [r12, #0x0]
522     mov r3, #NAND_LAUNCH_FCMD
523     str r3, [r12, #0xC]
524     do_wait_op_done
525
526 // write RBA=0 to NFC_CONFIGURATION1
527     mov r3, #0
528     str r3, [r12, #0x4]
529
530 //    writel(mode & 0xFF, NAND_LAUNCH_REG);
531     mov r3, #0x8
532     str r3, [r12, #0xC]
533 //        wait_op_done();
534     do_wait_op_done
535
536
537 Copy_Good_Blk:
538     //copying page
539 1:  ldmia r0!, {r3-r10}
540     stmia r14!, {r3-r10}
541     cmp r0, r2
542     blo 1b
543     cmp r14, r13
544     bge NAND_Copy_Main_done
545     add r1, r1, #0x1000
546     ldr r0, NFC_BASE_W
547     b Nfc_Read_Page
548
549 NAND_Copy_Main_done:
550
551 Normal_Boot_Continue:
552
553 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
554     /* Copy image from flash to SDRAM first */
555     ldr r0, =0xFFFFF000
556     and r0, r0, pc
557     ldr r1, MXC_REDBOOT_ROM_START
558     cmp r0, r1
559     beq HWInitialise_skip_SDRAM_copy
560
561     add r2, r0, #REDBOOT_IMAGE_SIZE
562
563 1:  ldmia r0!, {r3-r10}
564     stmia r1!, {r3-r10}
565     cmp r0, r2
566     ble 1b
567     /* Jump to SDRAM */
568     ldr r1, =0xFFFF
569     and r0, pc, r1         /* offset of pc */
570     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
571     add pc, r0, r1
572     nop
573     nop
574     nop
575     nop
576 #endif /* CYG_HAL_STARTUP_ROMRAM */
577
578 HWInitialise_skip_SDRAM_copy:
579
580 /*
581  * Note:
582  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
583  */
584
585 STACK_Setup:
586     // Set up a stack [for calling C code]
587     ldr r1, =__startup_stack
588     ldr r2, =RAM_BANK0_BASE
589     orr sp, r1, r2
590
591     // Create MMU tables
592     bl hal_mmu_init
593
594     // Enable MMU
595     ldr r2, =10f
596     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
597     orr r1, r1, #7                          // enable MMU bit
598     orr r1, r1, #0x800                      // enable z bit
599     mcr MMU_CP, 0, r1, MMU_Control, c0
600     mov pc,r2    /* Change address spaces */
601     nop
602     nop
603     nop
604 10:
605
606     // Save shadow copy of BCR, also hardware configuration
607     ldr r1, =_board_BCR
608     str r2, [r1]
609     ldr r1, =_board_CFG
610     str r9, [r1]                // Saved far above...
611
612     .endm                       // _platform_setup1
613
614 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
615 #define PLATFORM_SETUP1
616 #endif
617
618     /* Do nothing */
619     .macro  init_spba
620     .endm  /* init_spba */
621
622     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
623     .macro init_aips
624         /*
625          * Set all MPROTx to be non-bufferable, trusted for R/W,
626          * not forced to user-mode.
627          */
628         ldr r0, AIPS1_CTRL_BASE_ADDR_W
629         ldr r1, AIPS1_PARAM_W
630         str r1, [r0, #0x00]
631         str r1, [r0, #0x04]
632         ldr r0, AIPS2_CTRL_BASE_ADDR_W
633         str r1, [r0, #0x00]
634         str r1, [r0, #0x04]
635
636     .endm /* init_aips */
637
638     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
639     .macro init_max
640         ldr r0, MAX_BASE_ADDR_W
641 #if 0
642         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
643         ldr r1, MAX_PARAM1
644         str r1, [r0, #0x000]        /* for S0 */
645         str r1, [r0, #0x100]        /* for S1 */
646         str r1, [r0, #0x200]        /* for S2 */
647         str r1, [r0, #0x300]        /* for S3 */
648         str r1, [r0, #0x400]        /* for S4 */
649         /* SGPCR - always park on last master */
650         ldr r1, =0x10
651         str r1, [r0, #0x010]        /* for S0 */
652         str r1, [r0, #0x110]        /* for S1 */
653         str r1, [r0, #0x210]        /* for S2 */
654         str r1, [r0, #0x310]        /* for S3 */
655         str r1, [r0, #0x410]        /* for S4 */
656         /* MGPCR - restore default values */
657         ldr r1, =0x0
658         str r1, [r0, #0x800]        /* for M0 */
659         str r1, [r0, #0x900]        /* for M1 */
660         str r1, [r0, #0xA00]        /* for M2 */
661         str r1, [r0, #0xB00]        /* for M3 */
662         str r1, [r0, #0xC00]        /* for M4 */
663         str r1, [r0, #0xD00]        /* for M5 */
664 #endif
665     .endm /* init_max */
666
667     .macro    init_clock
668         /*
669          * Clock setup
670          * After this step,
671
672            Module           Freq (MHz)
673            ===========================
674            ARM core         532          ap_clk
675            AHB              133          ahb_clk
676            IP               66.5         ipg_clk
677            EMI              133          ddr_clk
678
679          * All other clocks can be figured out based on this.
680          */
681         /*
682         * Step 1: Switch to step clock
683         */
684         ldr r0, CCM_BASE_ADDR_W
685         mov r1, #0x00000104
686         str r1, [r0, #CLKCTL_CCSR]
687
688         /* Step 2: Setup PLL's */
689         /* Set PLL1 to be 532MHz */
690         ldr r0, PLL1_BASE_ADDR_W
691
692         mov r1, #0x1200
693         add r1, r1, #0x22
694         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
695         ldr r1, =0x2
696         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
697
698         ldr r1, =0x50
699         str r1, [r0, #PLL_DP_OP]
700         ldr r1, =23
701         str r1, [r0, #PLL_DP_MFD]
702         ldr r1, =13
703         str r1, [r0, #PLL_DP_MFN]
704
705         ldr r1, =0x50
706         str r1, [r0, #PLL_DP_HFS_OP]
707         ldr r1, =23
708         str r1, [r0, #PLL_DP_HFS_MFD]
709         ldr r1, =13
710         str r1, [r0, #PLL_DP_HFS_MFN]
711
712         /* Now restart PLL 1 */
713         ldr r1, PLL_VAL_0x1232
714         str r1, [r0, #PLL_DP_CTL]
715     1:
716         ldr r1, [r0, #PLL_DP_CTL]
717         ands r1, r1, #0x1
718         beq 1b
719
720         /*
721         * Step 2: Setup PLL2 to 665 MHz.
722         */
723         ldr r0, PLL2_BASE_ADDR_W
724
725         ldr r1, =0x1200
726         add r1, r1, #0x22
727         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
728         ldr r1, =0x2
729         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
730
731         ldr r1, =0x60
732         str r1, [r0, #PLL_DP_OP]
733         ldr r1, =95
734         str r1, [r0, #PLL_DP_MFD]
735         ldr r1, =89
736         str r1, [r0, #PLL_DP_MFN]
737
738         ldr r1, =0x60
739         str r1, [r0, #PLL_DP_HFS_OP]
740         ldr r1, =95
741         str r1, [r0, #PLL_DP_HFS_MFD]
742         ldr r1, =89
743         str r1, [r0, #PLL_DP_HFS_MFN]
744
745         /* Now restart PLL 2 */
746         ldr r1, PLL_VAL_0x1232
747         str r1, [r0, #PLL_DP_CTL]
748     1:
749         ldr r1, [r0, #PLL_DP_CTL]
750         ands r1, r1, #0x1
751         beq 1b
752
753         /*
754         * Set PLL 3 to 216MHz
755         */
756         ldr r0, PLL3_BASE_ADDR_W
757
758         ldr r1, PLL_VAL_0x222
759         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
760         ldr r1, =0x2
761         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
762
763         ldr r1, =0x91
764         str r1, [r0, #PLL_DP_OP]
765         ldr r1, =0x0
766         str r1, [r0, #PLL_DP_MFD]
767         ldr r1, =0x0
768         str r1, [r0, #PLL_DP_MFN]
769
770         ldr r1, =0x91
771         str r1, [r0, #PLL_DP_HFS_OP]
772         ldr r1, =0x0
773         str r1, [r0, #PLL_DP_HFS_MFD]
774         ldr r1, =0x0
775         str r1, [r0, #PLL_DP_HFS_MFN]
776
777         /* Now restart PLL 3 */
778         ldr r1, PLL_VAL_0x232
779         str r1, [r0, #PLL_DP_CTL]
780
781     1:
782         ldr r1, [r0, #PLL_DP_CTL]
783         ands r1, r1, #0x1
784         beq 1b
785         /* End of PLL 3 setup */
786
787         /* Setup the ARM platform clock dividers */
788         ldr r0, PLATFORM_BASE_ADDR_W
789         ldr r1, PLATFORM_CLOCK_DIV_W
790         str r1, [r0, #0x18]
791
792         /*
793         * Step 3: switching to PLL 1 and restore default register values.
794         */
795         ldr r0, CCM_BASE_ADDR_W
796         mov r1, #0x00000100
797         str r1, [r0, #CLKCTL_CCSR]
798
799         mov r1, #0x000A0000
800         add r1, r1, #0x00000F0
801         str r1, [r0, #CLKCTL_CCOSR]
802         /* Use 133MHz for DDR clock */
803         mov r1, #0x1C00
804         str r1, [r0, #CLKCTL_CAMR]
805         /* Use PLL 2 for UART's, get 66.5MHz from it */
806         ldr r1, CCM_VAL_0xA5A6A020
807         str r1, [r0, #CLKCTL_CSCMR1]
808         ldr r1, CCM_VAL_0x01450B21
809         str r1, [r0, #CLKCTL_CSCDR1]
810
811         mov r1, #0x1C
812         str r1, [r0, #CLKCTL_CBCDR7]
813         mov r1, #1
814         str r1, [r0, #4]
815     .endm /* init_clock */
816
817     /* M4IF setup */
818     .macro init_m4if
819         /* Configure M4IF registers, VPU and IPU given higher priority (=0x4)
820              IPU accesses with ID=0x1 given highest priority (=0xA) */
821         ldr r1, M4IF_BASE_W
822         ldr r0, M4IF_0x00000a01
823         str r0, [r1, #M4IF_FIDBP]
824
825         ldr r0, M4IF_0x00000404
826         str r0, [r1, #M4IF_FBPM0]
827     .endm /* init_m4if */
828
829     .macro setup_sdram
830         ldr r0, ESDCTL_BASE_W
831         /* Set CSD0 */
832         ldr r1, =0x80000000
833         str r1, [r0, #ESDCTL_ESDCTL0]
834         /* Precharge command */
835         ldr r1, SDRAM_0x04008008
836         str r1, [r0, #ESDCTL_ESDSCR]
837         /* 2 refresh commands */
838         ldr r1, SDRAM_0x00008010
839         str r1, [r0, #ESDCTL_ESDSCR]
840         str r1, [r0, #ESDCTL_ESDSCR]
841         /* LMR with CAS=3 and BL=3 */
842         ldr r1, SDRAM_0x00338018
843         str r1, [r0, #ESDCTL_ESDSCR]
844         /* 13 ROW, 10 COL, 32Bit, SREF=4 Micron Model */
845         ldr r1, SDRAM_0xB2220000
846         str r1, [r0, #ESDCTL_ESDCTL0]
847         /* Timing parameters */
848         ldr r1, SDRAM_0x899F6BBA
849         str r1, [r0, #ESDCTL_ESDCFG0]
850         /* MDDR enable, RLAT=2 */
851         ldr r1, SDRAM_0x000A1104
852         str r1, [r0, #ESDCTL_ESDMISC]
853         /* Normal mode */
854         ldr r1, =0x00000000
855         str r1, [r0, #ESDCTL_ESDSCR]
856     .endm
857
858     .macro do_wait_op_done
859     1:
860         ldr r3, [r11, #0x18]
861         ands r3, r3, #NFC_IPC_INT
862         beq 1b
863         mov r3, #0x0
864         str r3, [r11, #0x18]
865     .endm   // do_wait_op_done
866
867     .macro do_addr_input
868         str r3, [r12, #0x0]
869         mov r3, #NAND_LAUNCH_FADD
870         str r3, [r12, #0xC]
871         do_wait_op_done
872     .endm   // do_addr_input
873
874     /* To support 133MHz DDR */
875     .macro  init_iomux
876         ldr r0, IOMUXC_BASE_ADDR_W
877
878         // DDR signal setup for D16-D31 and drive strength
879         ldr r8, =0x1
880         add r1, r0, #8
881         add r2, r0, #0x4C
882     1:
883         stmia r1!, {r8}
884         cmp r1, r2
885         bls 1b
886
887         str r8, [r0, #0x5C]
888         str r8, [r0, #0x60]
889
890         add r2, r0, #0x200
891         mov r8, #0x2C4
892         str r8, [r2, #0xBC]
893         str r8, [r2, #0xC0]
894
895         ldr r8, =0x2
896         str r8, [r0, #0x4A8]
897         str r8, [r0, #0x4B0]
898         str r8, [r0, #0x4B4]
899         str r8, [r0, #0x4E0]
900         str r8, [r0, #0x4FC]
901         str r8, [r0, #0x504]
902         str r8, [r0, #0x48C]
903         str r8, [r0, #0x49C]
904
905         add r1, r0, #0x278
906         add r2, r0, #0x29C
907     2:
908         stmia r1!, {r8}
909         cmp r1, r2
910         bls 2b
911     .endm /* init_iomux */
912
913 #define PLATFORM_VECTORS         _platform_vectors
914     .macro  _platform_vectors
915         .globl  _board_BCR, _board_CFG
916 _board_BCR:   .long   0       // Board Control register shadow
917 _board_CFG:   .long   0       // Board Configuration (read at RESET)
918     .endm
919
920 ARM_PPMRR:              .word   0x80000016
921 L2CACHE_PARAM:          .word   0x0003001B
922 WDOG1_BASE_W:           .word   WDOG1_BASE_ADDR
923 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
924 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
925 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
926 AIPS1_PARAM_W:          .word   0x77777777
927 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
928 MAX_PARAM1:             .word   0x00302154
929 ESDCTL_BASE_W:          .word   ESDCTL_BASE
930 M4IF_BASE_W:            .word   M4IF_BASE
931 M4IF_0x00000a01:       .word   0x00000a01
932 M4IF_0x00000404:       .word   0x00000404
933 NFC_BASE_W:             .word   NFC_BASE
934 NFC_IP_BASE_W:          .word   NFC_IP_BASE
935 SDRAM_0x04008008:       .word   0x04008008
936 SDRAM_0x00008010:       .word   0x00008010
937 SDRAM_0x00338018:       .word   0x00338018
938 SDRAM_0xB2220000:       .word   0xB2220000
939 SDRAM_0x899F6BBA:       .word   0x899F6BBA
940 SDRAM_0x000A1104:       .word   0x000A1104
941 IOMUXC_BASE_ADDR_W:     .word   IOMUXC_BASE_ADDR
942 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
943 CONST_0x0FFF:           .word   0x0FFF
944 CCM_BASE_ADDR_W:        .word   CCM_BASE_ADDR
945 PLATFORM_BASE_ADDR_W:  .word   PLATFORM_BASE_ADDR
946 PLATFORM_CLOCK_DIV_W:  .word   0x00077713
947 CCM_VAL_0x01450B21:     .word   0x01450B21
948 CCM_VAL_0xA5A6A020:     .word   0xA5A6A020
949 PLL_VAL_0x222:          .word   0x222
950 PLL_VAL_0x232:          .word   0x232
951 PLL1_BASE_ADDR_W:       .word   PLL1_BASE_ADDR
952 PLL2_BASE_ADDR_W:       .word   PLL2_BASE_ADDR
953 PLL3_BASE_ADDR_W:       .word   PLL3_BASE_ADDR
954 PLL_VAL_0x1232:         .word   0x1232
955
956 /*---------------------------------------------------------------------------*/
957 /* end of hal_platform_setup.h                                               */
958 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */