]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91231/evb/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mxc91231 / evb / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3
4 //=============================================================================
5 //
6 //      hal_platform_setup.h
7 //
8 //      Platform specific support for HAL (assembly code)
9 //
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //===========================================================================
44
45 #include <pkgconf/system.h>             // System-wide configuration info
46 #include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
47 #include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
48 #include <cyg/hal/hal_soc.h>            // Variant specific hardware definitions
49 #include <cyg/hal/hal_mmu.h>            // MMU definitions
50 #include <cyg/hal/fsl_board.h>          // Platform specific hardware definitions
51
52 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
53 #define PLATFORM_SETUP1 _platform_setup1
54 #define CYGHWR_HAL_ARM_HAS_MMU
55
56 #ifdef CYG_HAL_STARTUP_ROMRAM
57 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
58 #endif
59
60 #define SDRAM_FULL_PAGE_BIT     0x100
61 #define SDRAM_FULL_PAGE_MODE    0x37
62 #define SDRAM_BURST_MODE        0x33
63
64 #define CYGHWR_HAL_ROM_VADDR    0x0
65
66 #define DEBUG_UART_BASE         UART3_BASE_ADDR
67
68 #if 0
69 #define UNALIGNED_ACCESS_ENABLE
70 #define SET_T_BIT_DISABLE
71 #define BRANCH_PREDICTION_ENABLE
72 #endif
73
74 //#define TURN_OFF_IMPRECISE_ABORT
75
76 // This macro represents the initial startup code for the platform
77 // r11 is reserved to contain chip rev info in this file
78     .macro  _platform_setup1
79 FSL_BOARD_SETUP_START:
80 /*
81  *       ARM1136 init
82  *       - invalidate I/D cache/TLB and drain write buffer;
83  *       - invalidate L2 cache
84  *       - unaligned access
85  *       - branch predictions
86  */
87 #ifdef TURN_OFF_IMPRECISE_ABORT
88     mrs r0, cpsr
89     bic r0, r0, #0x100
90     msr cpsr, r0
91 #endif
92
93     mov r0, #0
94     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
95     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
96     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
97
98     /* Also setup the Peripheral Port Remap register inside the core */
99     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
100     mcr p15, 0, r0, c15, c2, 4
101
102     /*** L2 Cache setup/invalidation/disable ***/
103     /* Disable L2 cache first */
104     mov r0, #L2CC_BASE_ADDR
105     ldr r2, [r0, #L2_CACHE_CTL_REG]
106     bic r2, r2, #0x1
107     str r2, [r0, #L2_CACHE_CTL_REG]
108     /*
109      * Configure L2 Cache:
110      * - 128k size(16k way)
111      * - 8-way associativity
112      * - 0 ws TAG/VALID/DIRTY
113      * - 4 ws DATA R/W
114      */
115     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
116     and r1, r1, #0xFE000000
117     ldr r2, L2CACHE_PARAM
118     orr r1, r1, r2
119     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
120
121     /* Invalidate L2 */
122     mov r1, #0x000000FF
123     str r1, [r0, #L2_CACHE_INV_WAY_REG]
124 L2_loop:
125     /* Poll Invalidate By Way register */
126     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
127     cmp r2, #0
128     bne L2_loop
129     /*** End of L2 operations ***/
130
131     mov r0, #SDRAM_NON_FLASH_BOOT
132     ldr r1, AVIC_VECTOR0_ADDR_W
133     str r0, [r1] // for checking boot source from nand, nor or sdram
134 /*
135  * End of ARM1136 init
136  */
137 init_spba_start:
138     init_spba
139 init_aips_start:
140     init_aips
141 init_max_start:
142     init_max
143 init_m3if_start:
144     init_m3if
145
146     mov r11, #CHIP_REV_1_0
147     ldr r0, IIM_SREV_REG_VAL
148     ldr r1, [r0, #0x0]
149     cmp r1, #0x0
150     movne r11, #CHIP_REV_2_0
151 init_cs0_async_start:
152     init_cs0_async
153
154     /* If SDRAM has been setup, bypass clock/WEIM setup */
155     cmp pc, #SDRAM_BASE_ADDR
156     blo init_clock_start
157     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
158     blo HWInitialise_skip_SDRAM_setup
159
160     mov r0, #NOR_FLASH_BOOT
161     ldr r1, AVIC_VECTOR0_ADDR_W
162     str r0, [r1]
163
164 init_clock_start:
165     init_clock
166
167     /* Based on chip rev, setup params for SDRAM controller */
168     ldr r10, =0
169     mov r4, #SDRAM_FULL_PAGE_MODE
170     cmp r11, #CHIP_REV_1_0
171     moveq r10, #SDRAM_FULL_PAGE_BIT
172     movgt r4, #SDRAM_BURST_MODE
173 init_sdram_start:
174
175     /* Assuming DDR memory first */
176     init_drive_strength_ddr
177
178     ldr r3, SDRAM_DDR_X16_W
179     add r3, r3, r10         /* adjust for full-page mode if necessary */
180     init_ddr_sdram
181     /* Testing if it is truly DDR */
182     ldr r1, SDRAM_COMPARE_CONST1
183     mov r0, #SDRAM_BASE_ADDR
184     str r1, [r0]
185     ldr r2, SDRAM_COMPARE_CONST2
186     str r2, [r0, #0x4]
187     ldr r2, [r0]
188     cmp r1, r2
189     beq HWInitialise_skip_SDRAM_setup
190
191     /* Reach here ONLY when SDR */
192     init_drive_strength_sdr
193
194     ldr r3, SDRAM_SDR_X16_W
195     add r3, r3, r10         /* adjust for full-page mode if necessary */
196     init_sdr_sdram
197     /* Test to make sure SDR */
198     ldr r1, SDRAM_COMPARE_CONST1
199     mov r0, #SDRAM_BASE_ADDR
200     str r1, [r0]
201     ldr r2, SDRAM_COMPARE_CONST2
202     str r2, [r0, #0x4]
203     ldr r2, [r0]
204     cmp r1, r2
205     beq HWInitialise_skip_SDRAM_setup
206
207     /* Reach hear means memory setup problem. Try to
208      * increase the HCLK divider */
209     ldr r0, CRM_AP_BASE_ADDR_W
210     ldr r1, [r0, #CRM_AP_ACDR]
211     and r2, r1, #0xF0
212     cmp r2, #0xF0
213     beq loop_forever
214     add r1, r1, #0x12
215     str r1, [r0, #CRM_AP_ACDR]
216     b init_sdram_start
217
218 loop_forever:
219     b loop_forever  /* shouldn't get here */
220
221 HWInitialise_skip_SDRAM_setup:
222
223     mov r0, #NFC_BASE
224     add r2, r0, #0x800      // 2K window
225     cmp pc, r0
226     blo Normal_Boot_Continue
227     cmp pc, r2
228     bhi Normal_Boot_Continue
229 NAND_Boot_Start:
230     /* Copy image from flash to SDRAM first */
231     ldr r1, MXC_REDBOOT_ROM_START
232
233 1:  ldmia r0!, {r3-r10}
234     stmia r1!, {r3-r10}
235     cmp r0, r2
236     blo 1b
237     /* Jump to SDRAM */
238     ldr r1, CONST_0x0FFF
239     and r0, pc, r1     /* offset of pc */
240     ldr r1, MXC_REDBOOT_ROM_START
241     add r1, r1, #0x10
242     add pc, r0, r1
243     nop
244     nop
245     nop
246     nop
247 NAND_Copy_Main:
248     mov r0, #NAND_FLASH_BOOT
249     ldr r1, AVIC_VECTOR0_ADDR_W
250     str r0, [r1]
251     mov r0, #MXCFIS_NAND
252     ldr r1, AVIC_VECTOR1_ADDR_W
253     str r0, [r1]
254
255     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
256     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
257     add r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
258     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
259     ldr r14, MXC_REDBOOT_ROM_START
260     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
261     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
262
263     //unlock internal buffer
264     mov r3, #0x2
265     strh r3, [r12, #0xA]
266
267 Nfc_Read_Page:
268 //  writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
269     mov r3, #0x0;
270     strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
271     mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
272     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
273     do_wait_op_done
274
275 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
276     mov r3, r1
277     do_addr_input       //1st addr cycle
278     mov r3, r1, lsr #9
279     do_addr_input       //2nd addr cycle
280     mov r3, r1, lsr #17
281     do_addr_input       //3rd addr cycle
282
283 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
284 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
285 //               NAND_FLASH_CONFIG1_REG);
286     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
287     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
288
289 //        writew(buf_no, RAM_BUFFER_ADDRESS_REG);
290     mov r3, #0
291     strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
292 //        writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
293     mov r3, #FDO_PAGE_SPARE_VAL
294     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
295 //        wait_op_done();
296     do_wait_op_done
297
298     // check for bad block
299     mov r3, r1, lsl #(32-5-9)
300     cmp r3, #(512 << (32-5-9))
301     bhi Copy_Good_Blk
302     add r4, r0, #0x800  //r3 -> spare area buf 0
303     ldrh r4, [r4, #0x4]
304     and r4, r4, #0xFF00
305     cmp r4, #0xFF00
306     beq Copy_Good_Blk
307     // really sucks. Bad block!!!!
308     cmp r3, #0x0
309     beq Skip_bad_block
310     // even suckier since we already read the first page!
311     sub r14, r14, #512  //rewind 1 page for the sdram pointer
312     sub r1, r1, #512    //rewind 1 page for the flash pointer
313 Skip_bad_block:
314     add r1, r1, #(32*512)
315     b Nfc_Read_Page
316 Copy_Good_Blk:
317     //copying page
318 1:  ldmia r0!, {r3-r10}
319     stmia r14!, {r3-r10}
320     cmp r0, r2
321     blo 1b
322     cmp r14, r13
323     bge NAND_Copy_Main_done
324     add r1, r1, #0x200
325     mov r0, #NFC_BASE
326     b Nfc_Read_Page
327
328 NAND_Copy_Main_done:
329
330 Normal_Boot_Continue:
331
332 init_cs4_start:
333     init_cs4
334
335 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
336     /* Copy image from flash to SDRAM first */
337     ldr r0, =0xFFFFF000
338     and r0, r0, pc
339     ldr r1, MXC_REDBOOT_ROM_START
340     cmp r0, r1
341     beq HWInitialise_skip_SDRAM_copy
342
343     add r2, r0, #REDBOOT_IMAGE_SIZE
344
345 1:  ldmia r0!, {r3-r10}
346     stmia r1!, {r3-r10}
347     cmp r0, r2
348     ble 1b
349     /* Jump to SDRAM */
350     ldr r1, =0xFFFF
351     and r0, pc, r1         /* offset of pc */
352     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
353     add pc, r0, r1
354     nop
355     nop
356     nop
357     nop
358 #endif /* CYG_HAL_STARTUP_ROMRAM */
359 init_cs0_sync_start:
360     init_cs0_sync
361
362 HWInitialise_skip_SDRAM_copy:
363
364 /*
365  * Note:
366  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
367  */
368
369 STACK_Setup:
370     // Set up a stack [for calling C code]
371     ldr r1, =__startup_stack
372     ldr r2, =RAM_BANK0_BASE
373     orr sp, r1, r2
374
375     // Create MMU tables
376     bl hal_mmu_init
377
378     // Enable MMU
379     ldr r2, =10f
380     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
381     orr r1, r1, #7                          // enable MMU bit
382     mcr MMU_CP, 0, r1, MMU_Control, c0
383     mov pc,r2    /* Change address spaces */
384     nop
385     nop
386     nop
387 10:
388
389     // Save shadow copy of BCR, also hardware configuration
390     ldr r1, =_board_BCR
391     str r2, [r1]
392     ldr r1, =_board_CFG
393     str r9, [r1]                // Saved far above...
394
395     .endm                       // _platform_setup1
396
397 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
398 #define PLATFORM_SETUP1
399 #endif
400
401     /* Allow all 3 masters to have access to these shared peripherals */
402     .macro  init_spba
403         ldr r0, SPBA_CTRL_BASE_ADDR_W
404         mov r1, #0x7            /* allow all 3 masters access */
405         str r1, [r0, #0x0C]
406         str r1, [r0, #0x1C]
407         str r1, [r0, #0x24]
408         str r1, [r0, #0x28]
409         str r1, [r0, #0x40]
410         str r1, [r0, #0x44]
411         str r1, [r0, #0x48]
412         str r1, [r0, #0x4C]
413         str r1, [r0, #0x50]
414         str r1, [r0, #0x54]
415         str r1, [r0, #0x58]
416         str r1, [r0, #0x5C]
417     .endm  /* init_spba */
418
419     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
420     .macro init_aips
421         /*
422          * Set all MPROTx to be non-bufferable, trusted for R/W,
423          * not forced to user-mode.
424          */
425         ldr r0, AIPS1_CTRL_BASE_ADDR_W
426         ldr r1, AIPS1_PARAM_W
427         str r1, [r0, #0x00]
428         str r1, [r0, #0x04]
429         ldr r0, AIPS2_CTRL_BASE_ADDR_W
430         str r1, [r0, #0x00]
431         str r1, [r0, #0x04]
432
433         /*
434          * Clear the on and off peripheral modules Supervisor Protect bit
435          * for SDMA to access them. Did not change the AIPS control registers
436          * (offset 0x20) access type
437          */
438         ldr r0, AIPS1_CTRL_BASE_ADDR_W
439         ldr r1, =0x0
440         str r1, [r0, #0x40]
441         str r1, [r0, #0x44]
442         str r1, [r0, #0x48]
443         str r1, [r0, #0x4C]
444         ldr r1, [r0, #0x50]
445         and r1, r1, #0x00FFFFFF
446         str r1, [r0, #0x50]
447
448         ldr r0, AIPS2_CTRL_BASE_ADDR_W
449         ldr r1, =0x0
450         str r1, [r0, #0x40]
451         str r1, [r0, #0x44]
452         str r1, [r0, #0x48]
453         str r1, [r0, #0x4C]
454         ldr r1, [r0, #0x50]
455         and r1, r1, #0x00FFFFFF
456         str r1, [r0, #0x50]
457     .endm /* init_aips */
458
459     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
460     .macro init_max
461         ldr r0, MAX_BASE_ADDR_W
462         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
463         ldr r1, MAX_PARAM1
464         str r1, [r0, #0x000]        /* for S0 */
465         str r1, [r0, #0x100]        /* for S1 */
466         str r1, [r0, #0x200]        /* for S2 */
467         str r1, [r0, #0x300]        /* for S3 */
468         str r1, [r0, #0x400]        /* for S4 */
469         /* SGPCR - always park on last master */
470         ldr r1, =0x10
471         str r1, [r0, #0x010]        /* for S0 */
472         str r1, [r0, #0x110]        /* for S1 */
473         str r1, [r0, #0x210]        /* for S2 */
474         str r1, [r0, #0x310]        /* for S3 */
475         str r1, [r0, #0x410]        /* for S4 */
476         /* MGPCR - restore default values */
477         ldr r1, =0x0
478         str r1, [r0, #0x800]        /* for M0 */
479         str r1, [r0, #0x900]        /* for M1 */
480         str r1, [r0, #0xA00]        /* for M2 */
481         str r1, [r0, #0xB00]        /* for M3 */
482         str r1, [r0, #0xC00]        /* for M4 */
483         str r1, [r0, #0xD00]        /* for M5 */
484     .endm /* init_max */
485
486     /* Clock setup */
487     .macro init_clock
488         /* Setup RVAL/WVAL for internal display memories */
489         ldr r0, CRM_AP_BASE_ADDR_W
490         ldr r1, CRM_AP_AGPR_W
491         str r1, [r0, #CRM_AP_AGPR]
492         /* RVAL/WVAL for L2 cache memory */
493         ldr r0, RVAL_WVAL_W
494         ldr r1, CLKCTL_BASE_ADDR_W
495         str r0, [r1, #0x10]
496
497         /*
498          * Clock setup
499          * After this step, AP domain is running out of PLL0 with:
500
501            Module           Freq (MHz)   Note
502            =========================================================================
503            ARM core         399          ap_clk
504            AHB              133          known as "hclk" for ap_hclk and xxx_ahb_clk's
505            IP               66.5         ap_pclk and ap_com_pclk
506            UART1/2 baud     26           ap_perclk
507            UART3 baud       26           ap_uart3_perclk
508            EMI              133          =hclk
509
510          * All other clocks can be figured out based on this.
511          */
512         /*
513         * Step 1: Check if 26MHz clock is present or not.
514         * For CRM_COM module, the only register we care during bootstrap is the CSCR.
515         * We check this register to see if 26MHz is present or not. All the other
516         * registers are left untouched.
517         */
518         ldr r0, CRM_COM_BASE_ADDR_W
519         ldr r1, [r0, #CRM_COM_CSCR]
520         ands r1, r1, #0x2         /* test if NOCK_CKIH bit is set or not */
521 1:
522         bne 1b                    /* stay here forever if 26MHz clock is not present */
523         /* Now 26MHz clock is available */
524
525         /*
526         * Step 2: Setup PLL0 - ADPLL for AP domain.
527         */
528
529         ldr r0, PLL0_BASE_ADDR_W
530
531         ldr r1, =0x22
532         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
533         ldr r1, =0x2
534         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
535
536         /*
537         * Set PLL0 to be 399MHz.
538         * MFI=7, PDF=0, MFD=51, MFN=35 ->
539         * PLL0=2*26MHzInput*(7+35/(51+1))/(0+1)=399 MHz
540         */
541         ldr r1, =0x70
542         str r1, [r0, #PLL_DP_OP]
543         ldr r1, =51
544         str r1, [r0, #PLL_DP_MFD]
545         ldr r1, =35
546         str r1, [r0, #PLL_DP_MFN]
547
548         ldr r1, =0x70
549         str r1, [r0, #PLL_DP_HFS_OP]
550         ldr r1, =51
551         str r1, [r0, #PLL_DP_HFS_MFD]
552         ldr r1, =35
553         str r1, [r0, #PLL_DP_HFS_MFN]
554
555         /* Now restart DPLL */
556         ldr r1, =0x32
557         str r1, [r0, #PLL_DP_CTL]
558 wait_pll0_lock:
559         ldr r1, [r0, #PLL_DP_CTL]
560         ands r1, r1, #0x1
561         beq wait_pll0_lock
562
563         /* End of PLL0 setup with PLL0 being locked at 399MHz */
564
565         /*
566         * Set PLL2 to 96MHz
567         */
568         ldr r0, PLL2_BASE_ADDR_W
569
570         ldr r1, =0x22
571         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
572         ldr r1, =0x2
573         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
574
575         /*
576         * MFI=5, PDF=2, MFD=12, MFN=7 ->
577         * PLL2 = 2*26*(5+7/(12+1))/(2+1)=96 MHz
578         */
579         ldr r1, =0x52
580         str r1, [r0, #PLL_DP_OP]
581         ldr r1, =12
582         str r1, [r0, #PLL_DP_MFD]
583         ldr r1, =7
584         str r1, [r0, #PLL_DP_MFN]
585
586         ldr r1, =0x52
587         str r1, [r0, #PLL_DP_HFS_OP]
588         ldr r1, =12
589         str r1, [r0, #PLL_DP_HFS_MFD]
590         ldr r1, =7
591         str r1, [r0, #PLL_DP_HFS_MFN]
592
593         /* Now restart DPLL */
594         ldr r1, =0x32
595         str r1, [r0, #PLL_DP_CTL]
596
597 wait_pll2_lock:
598         ldr r1, [r0, #PLL_DP_CTL]
599         ands r1, r1, #0x1
600         beq wait_pll2_lock
601         /* End of PLL2 setup with PLL2 being locked at 48MHz */
602
603         /*
604         * Step 3: switching to DPLL for AP domain and restore default register values.
605         */
606         // AP CKO/CKOH selected
607         ldr r0, CRM_COM_BASE_ADDR_W
608         ldr r1, [r0, #0x0C]
609         orr r1, r1, #0x60000
610         str r1, [r0, #0x0C]
611         ldr r0, CRM_AP_BASE_ADDR_W
612         /* Default CKOH as AP_CLK with div by 10 */
613         //orr r1, r1, #0x5600 /* HCLK */
614         ldr r1, [r0, #CRM_AP_ACR]
615         bic r1, r1, #0xFF00
616         bic r1, r1, #0x00FF
617         orr r1, r1, #0x1600
618         str r1, [r0, #CRM_AP_ACR]
619
620         /*Dividers setup */
621         mov r1, #0x0860
622         add r1, r1, #0x0006
623         str r1, [r0, #CRM_AP_ACDR]      /* ARM core=399MHz, AHB=66.5MHz, IP=66.5MHz */
624         mov r1, #0x0000D500
625         add r1, r1, #0x00000040
626         str r1, [r0, #CRM_AP_ASCSR]     /* restore default value */
627         ldr r1, =0x1
628         str r1, [r0, #CRM_AP_ACSR]      /* select DPLL for AP domain at new freq */
629         ldr r1, CRM_AP_ACDER1_W
630         str r1, [r0, #CRM_AP_ACDER1]    /* restore default */
631         ldr r1, CRM_AP_ACDER2_W
632         str r1, [r0, #CRM_AP_ACDER2]    /* set nfc_div=5 (5+1 actual divider) */
633         ldr r1, CRM_AP_ACGCR_W
634         str r1, [r0, #CRM_AP_ACGCR]     /* restore default */
635         mov r1, #0x124
636         str r1, [r0, #CRM_AP_ACCGCR]    /* restore default */
637         ldr r1, CRM_AP_APRA_W
638         str r1, [r0, #CRM_AP_APRA]      /* restore default to enable UART1/2/3 */
639         /* Set the DIV_BYP bit */
640         mov r1, #0x00200000
641         add r1, r1, #0x168
642         str r1, [r0, #CRM_AP_ADCR]      /* set DFS Divider to Not used */
643
644         /*
645         * Only when NOT directly booting from SDRAM:
646         * ARM core=399MHz, AHB=133MHz, IP=66.5MHz.
647         * This is to work around the booting problem with RVD on EVB only.
648         * Brassboard is fine.
649         */
650         ldr r0, CRM_AP_BASE_ADDR_W
651         mov r1, #0x0830
652         add r1, r1, #0x0006
653         str r1, [r0, #CRM_AP_ACDR]
654         ldr r1, CRM_AP_ADCR_0x0020016A
655         str r1, [r0, #CRM_AP_ADCR]        /* set DFS Divider to Not used */
656
657         // enable display buffer clock
658         ldr r1, [r0, #CRM_AP_AMLPMRG]
659         orr r1, r1, #0x40000000
660         str r1, [r0, #CRM_AP_AMLPMRG]
661
662         // SD clock input select - usb_clk. divider changed to 1
663         mov r1, #0x00009100
664         add r1, r1, #0x00000091
665         str r1, [r0, #CRM_AP_APRB]
666     .endm /* init_clock */
667
668     /* M3IF setup */
669     .macro init_m3if
670         /* Configure M3IF registers */
671         ldr r1, M3IF_BASE_W
672         /*
673         * M3IF Control Register (M3IFCTL)
674         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
675         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
676         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
677         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
678         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
679         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
680         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
681         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
682         *                                                       ------------
683         *                                                       0x00000040
684         */
685         ldr r0, =0x00000040
686         str r0, [r1]  /* M3IF control reg */
687     .endm /* init_m3if */
688
689     /* CS0 sync mode setup */
690     .macro init_cs0_sync
691         /*
692          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
693          */
694         /* Flash reset command */
695         ldr     r0, =CS0_BASE_ADDR
696         ldr     r1, =0xF0F0
697         strh    r1, [r0]
698         /* 1st command */
699         ldr     r2, =0xAAA
700         add     r2, r2, r0
701         ldr     r1, =0xAAAA
702         strh    r1, [r2]
703         /* 2nd command */
704         ldr     r2, =0x554
705         add     r2, r2, r0
706         ldr     r1, =0x5555
707         strh    r1, [r2]
708         /* 3rd command */
709         ldr     r2, =0xAAA
710         add     r2, r2, r0
711         ldr     r1, =0xD0D0
712         strh    r1, [r2]
713         /* Write flash config register */
714         ldr     r1, =0x56CA
715         strh    r1, [r2]
716         /* Flash reset command */
717         ldr     r1, =0xF0F0
718         strh    r1, [r0]
719
720         ldr r0, =WEIM_BASE_ADDR
721         ldr r1, =0x23524E80
722         str r1, [r0, #CSCRU]
723         ldr r1, =0x10000D03
724         str r1, [r0, #CSCRL]
725         ldr r1, =0x00720900
726         str r1, [r0, #CSCRA]
727     .endm /* init_cs0_sync */
728
729     /* CS0 async mode setup */
730     .macro init_cs0_async
731         /* Async flash mode */
732         ldr r0, =WEIM_CTRL_CS0
733         ldr r1, WEIM_CSCRU_0x11414C80
734         str r1, [r0, #CSCRU]
735         ldr r1, WEIM_CSCRL_0x30000D03
736         str r1, [r0, #CSCRL]
737         ldr r1, WEIM_CSCRA_0x00310800
738         str r1, [r0, #CSCRA]
739     .endm /* init_cs0_async */
740
741     /* CPLD on CS4 setup */
742     .macro init_cs4
743         ldr r0, =WEIM_CTRL_CS4
744         ldr r1, =0x0000D743
745         str r1, [r0, #CSCRU]
746         ldr r1, =0x42001521
747         str r1, [r0, #CSCRL]
748         ldr r1, =0x00430A00
749         str r1, [r0, #CSCRA]
750
751         ldr r0, CS4_BASE_ADDR_W
752         ldrh r1, [r0, #0x0]
753         and r0, r1, #0xFF00
754         cmp r0, #0x2000
755         bge done_cs4_setup
756
757         ldr r0, =WEIM_CTRL_CS4
758         ldr r1, =0x0000D843
759         str r1, [r0, #CSCRU]
760         ldr r1, =0x22252521
761         str r1, [r0, #CSCRL]
762         ldr r1, =0x22220A00
763         str r1, [r0, #CSCRA]
764
765 done_cs4_setup:
766
767     .endm /* init_cs4 */
768
769 // DDR SDRAM setup
770      /* r3 = value for ESDCTL0
771       * r4 = burst mode vs full-page mode */
772     .macro  init_ddr_sdram
773         ldr r0, ESDCTL_BASE_W
774         mov r2, #SDRAM_BASE_ADDR
775         ldr r1, SDRAM_0x0075E73A
776         str r1, [r0, #0x4]
777         mov r1, #0x2            // reset
778         str r1, [r0, #0x10]
779         mov r1, #0x4            // DDR
780         str r1, [r0, #0x10]
781
782         // Hold for more than 200ns
783         mov r1, #0x10000
784     1:
785         subs r1, r1, #0x1
786         bne 1b
787
788         ldr r1, SDRAM_0x92100000
789         str r1, [r0]
790         ldr r1, SDRAM_0x12344321
791         mov r12, #0x80000000
792         add r12, r12, #0x00000F00
793         str r1, [r12]
794         ldr r1, SDRAM_0xA2100000
795         str r1, [r0]
796         ldr r1, SDRAM_0x12344321
797         str r1, [r2]
798         ldr r1, SDRAM_0xB2100000
799         str r1, [r0]
800
801         mov r1, #0xDA
802         strb r1, [r2, r4]
803         mov r1, #0xFF
804         mov r12, #0x81000000
805         strb r1, [r12]
806         str r3, [r0]
807         mov r1, #0x0
808         str r1, [r2]
809         mov r1, #0x0000000C
810         str r1, [r0, #0x10]
811     .endm
812
813 // SDR SDRAM setup
814     /* r3 = value for ESDCTL0
815      * r4 = burst mode vs full-page mode */
816     .macro  init_sdr_sdram
817         ldr r0, ESDCTL_BASE_W
818         mov r2, #SDRAM_BASE_ADDR
819         ldr r1, SDRAM_0x0075E73A
820         str r1, [r0, #0x4]
821         ldr r1, =0x2            // reset
822         str r1, [r0, #0x10]
823         ldr r1, =0x0            // sdr
824         str r1, [r0, #0x10]
825
826         // Hold for more than 200ns
827         ldr r1, =0x10000
828 1:
829         subs r1, r1, #0x1
830         bne 1b
831
832         ldr r1, SDRAM_0x92126080
833         str r1, [r0]
834         ldr r1, =0x0
835         mov r12, #0x80000000
836         add r12, r12, #0x00000400
837         str r1, [r12]
838         ldr r1, SDRAM_0xA2126080
839         str r1, [r0]
840
841         ldr r1, =0x0
842         str r1, [r2]
843         str r1, [r2]
844
845         ldr r1, SDRAM_0xB2126180
846         str r1, [r0]
847
848         ldr r1, =0x0
849         strb r1, [r2, r4]
850         mov r12, #0x81000000
851         str r1, [r12]
852         str r3, [r0]
853         ldr r1, =0x0
854         str r1, [r2]
855     .endm
856
857     .macro do_wait_op_done
858     1:
859         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
860         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
861         beq 1b
862         mov r3, #0x0
863         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
864     .endm   // do_wait_op_done
865
866     .macro do_addr_input
867         and r3, r3, #0xFF
868         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
869         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
870         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
871         do_wait_op_done
872     .endm   // do_addr_input
873
874     /* Required for MXC91231 PASS 2 for 133MHz SDR */
875     .macro  init_drive_strength_sdr
876         ldr r0, IOMUX_COM_BASE_ADDR_W
877         add r0, r0, #0x200
878         ldr r1, =0x0082
879         strh r1, [r0, #0x0]
880         ldr r1, =0x0002
881         strh r1, [r0, #0x2]
882         ldr r1, =0x0108
883         strh r1, [r0, #0x4]
884         ldr r1, =0x0103
885         strh r1, [r0, #0x8]
886         ldr r1, =0x01C3
887         strh r1, [r0, #0xA]
888         ldr r1, =0x0183
889         strh r1, [r0, #0xC]
890     .endm
891
892     /* Required for DDR */
893     .macro  init_drive_strength_ddr
894         ldr r0, IOMUX_COM_BASE_ADDR_W
895         add r0, r0, #0x200
896         ldr r1, =0x0092
897         strh r1, [r0, #0x0]
898         ldr r1, =0x0002
899         strh r1, [r0, #0x2]
900         ldr r1, =0x0102
901         strh r1, [r0, #0x4]
902         ldr r1, =0x092
903         strh r1, [r0, #0x6]
904         ldr r1, =0x0103
905         strh r1, [r0, #0x8]
906         ldr r1, =0x01C3
907         strh r1, [r0, #0xA]
908         ldr r1, =0x0183
909         strh r1, [r0, #0xC]
910         ldr r1, =0x0103
911         strh r1, [r0, #0x10]
912         ldr r1, =0x0183
913         strh r1, [r0, #0x12]
914     .endm
915
916 #define PLATFORM_VECTORS         _platform_vectors
917     .macro  _platform_vectors
918         .globl  _board_BCR, _board_CFG
919 _board_BCR:   .long   0       // Board Control register shadow
920 _board_CFG:   .long   0       // Board Configuration (read at RESET)
921     .endm
922
923 ARM_PPMRR:              .word   0x40000015
924 L2CACHE_PARAM:          .word   0x00030024
925 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
926 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
927 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
928 CS4_BASE_ADDR_W:        .word   CS4_BASE_ADDR
929 AIPS1_PARAM_W:          .word   0x77777777
930 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
931 MAX_PARAM1:             .word   0x00302154
932 RVAL_WVAL_W:            .word   0x515
933 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
934 PLL0_BASE_ADDR_W:       .word   PLL0_BASE_ADDR
935 CRM_AP_BASE_ADDR_W:     .word   CRM_AP_BASE_ADDR
936 CRM_COM_BASE_ADDR_W:    .word   CRM_COM_BASE_ADDR
937 IOMUX_COM_BASE_ADDR_W:  .word   IOMUX_COM_BASE_ADDR
938 PLL2_BASE_ADDR_W:       .word   PLL2_BASE_ADDR
939 SPBA_CTRL_BASE_ADDR_W:  .word   SPBA_CTRL_BASE_ADDR
940 CRM_AP_AGPR_W:          .word   0x00050105
941 CRM_AP_ADCR_0x0020016A: .word   0x0020016A
942 WEIM_CSCRU_0x11414C80:  .word   0x11414C80
943 WEIM_CSCRL_0x30000D03:  .word   0x30000D03
944 WEIM_CSCRA_0x00310800:  .word   0x00310800
945 ESDCTL_BASE_W:          .word   ESDCTL_BASE
946 M3IF_BASE_W:            .word   M3IF_BASE
947 CRM_AP_ACDER1_W:        .word   0x05071919
948 CRM_AP_ACDER2_W:        .word   0x00151008
949 CRM_AP_ACGCR_W:         .word   0x00244924
950 CRM_AP_APRA_W:          .word   0x01110101
951 SDRAM_DDR_X16_W:        .word   0x82216080
952 SDRAM_SDR_X16_W:        .word   0x82116080
953 SDRAM_0x92126080:       .word   0x92126080
954 SDRAM_0xA2126080:       .word   0xA2126080
955 SDRAM_0xB2126180:       .word   0xB2126180
956 SDRAM_0x0075E73A:       .word   0x0075E73A
957 SDRAM_0x92100000:       .word   0x92100000
958 SDRAM_0xA2100000:       .word   0xA2100000
959 SDRAM_0xB2100000:       .word   0xB2100000
960 SDRAM_0x12344321:       .word   0x12344321
961 SDRAM_COMPARE_CONST1:   .word   0x55555555
962 SDRAM_COMPARE_CONST2:   .word   0xAAAAAAAA
963 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
964 CONST_0x0FFF:           .word   0x0FFF
965 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
966 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
967
968 /*---------------------------------------------------------------------------*/
969 /* end of hal_platform_setup.h                                               */
970 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */