]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91131/evb/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mxc91131 / 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 #if 0
67 #define UNALIGNED_ACCESS_ENABLE
68 #define SET_T_BIT_DISABLE
69 #define BRANCH_PREDICTION_ENABLE
70 #endif
71
72 //#define TURN_OFF_IMPRECISE_ABORT
73
74 // This macro represents the initial startup code for the platform
75     .macro  _platform_setup1
76 FSL_BOARD_SETUP_START:
77 /*
78  *       ARM1136 init
79  *       - invalidate I/D cache/TLB and drain write buffer;
80  *       - invalidate L2 cache
81  *       - unaligned access
82  *       - branch predictions
83  */
84     mrc 15, 0, r0, c1, c0, 0    /* r0 = system control reg */
85     bic r0, r0, #(1 << 12)        /* disable ICache */
86     bic r0, r0, #(1 << 2)        /* disable DCache */
87     bic r0, r0, #(1 << 0)        /* disable MMU */
88     mcr 15, 0, r0, c1, c0, 0    /* update system control reg */
89 #ifdef TURN_OFF_IMPRECISE_ABORT
90     mrs r0, cpsr
91     bic r0, r0, #0x100
92     msr cpsr, r0
93 #endif
94
95     mov r0, #0
96     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
97     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
98     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
99
100     /* Also setup the Peripheral Port Remap register inside the core */
101     ldr r0, ARM_PPMRR        /* start from AIPS 2GB region */
102     mcr p15, 0, r0, c15, c2, 4
103
104     /*** L2 Cache setup/invalidation/disable ***/
105     /* Disable L2 cache first */
106     mov r0, #L2CC_BASE_ADDR
107     ldr r2, [r0, #L2_CACHE_CTL_REG]
108     bic r2, r2, #0x1
109     str r2, [r0, #L2_CACHE_CTL_REG]
110     /*
111      * Configure L2 Cache:
112      * - 128k size(16k way)
113      * - 8-way associativity
114      * - 0 ws TAG/VALID/DIRTY
115      * - 4 ws DATA R/W
116      */
117     ldr r1, [r0, #L2_CACHE_AUX_CTL_REG]
118     and r1, r1, #0xFE000000
119     ldr r2, L2CACHE_PARAM
120     orr r1, r1, r2
121     str r1, [r0, #L2_CACHE_AUX_CTL_REG]
122
123     /* Invalidate L2 */
124     mov r1, #0x000000FF
125     str r1, [r0, #L2_CACHE_INV_WAY_REG]
126 L2_loop:
127     /* Poll Invalidate By Way register */
128     ldr r2, [r0, #L2_CACHE_INV_WAY_REG]
129     cmp r2, #0
130     bne L2_loop
131     /*** End of L2 operations ***/
132
133     mov r0, #SDRAM_NON_FLASH_BOOT
134     ldr r1, AVIC_VECTOR0_ADDR_W
135     str r0, [r1] // for checking boot source from nand, nor or sdram
136 /*
137  * End of ARM1136 init
138  */
139 init_spba_start:
140     init_spba
141 init_aips_start:
142     init_aips
143 init_max_start:
144     init_max
145 init_m3if_start:
146     init_m3if
147
148 init_cs0_async_start:
149     init_cs0_async
150 init_clock_start:
151     init_clock
152 init_cs4_start:
153     init_cs4
154
155     /* If SDRAM has been setup, bypass clock/WEIM setup */
156     cmp pc, #SDRAM_BASE_ADDR
157     blo init_sdram_start
158     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
159     blo HWInitialise_skip_SDRAM_setup
160
161     mov r0, #NOR_FLASH_BOOT
162     ldr r1, AVIC_VECTOR0_ADDR_W
163     str r0, [r1]
164
165 init_sdram_start:
166     init_drive_strength
167     /* Always burst mode for SDRAM*/
168     ldr r10, =0
169     ldr r4, =SDRAM_BURST_MODE
170     /* Assuming DDR memory first */
171
172 setup_sdram_start:
173 #ifndef CYGHWR_HAL_ARM_MEM1
174     setup_sdram ddr X32 DDR 0
175     beq HWInitialise_skip_SDRAM_setup
176
177     setup_sdram ddr X16 DDR 0
178     beq HWInitialise_skip_SDRAM_setup
179
180     setup_sdram sdr X32 SDR 0
181     beq HWInitialise_skip_SDRAM_setup
182
183     setup_sdram sdr X16 SDR 0
184     beq HWInitialise_skip_SDRAM_setup
185 #else
186     setup_sdram ddr X16 DDR 0
187     beq HWInitialise_skip_SDRAM_setup
188 #endif
189
190     /* Reach hear means memory setup problem. Try to
191      * increase the HCLK divider */
192     ldr r0, CRM_AP_BASE_ADDR_W
193     ldr r1, [r0, #CRM_AP_ACDR]
194     and r2, r1, #0xF0
195     cmp r2, #0xF0
196     beq loop_forever
197     add r1, r1, #0x12
198     str r1, [r0, #CRM_AP_ACDR]
199     b init_sdram_start
200
201 loop_forever:
202     b loop_forever  /* shouldn't get here */
203
204 HWInitialise_skip_SDRAM_setup:
205
206     mov r0, #NFC_BASE
207     add r2, r0, #0x800      // 2K window
208     cmp pc, r0
209     blo Normal_Boot_Continue
210     cmp pc, r2
211     bhi Normal_Boot_Continue
212 NAND_Boot_Start:
213     /* Copy image from flash to SDRAM first */
214     ldr r1, MXC_REDBOOT_ROM_START
215
216 1:  ldmia r0!, {r3-r10}
217     stmia r1!, {r3-r10}
218     cmp r0, r2
219     blo 1b
220     /* Jump to SDRAM */
221     ldr r1, CONST_0xFFFF
222     and r0, pc, r1     /* offset of pc */
223     ldr r1, MXC_REDBOOT_ROM_START
224     add r1, r1, #0x10
225     add pc, r0, r1
226     nop
227     nop
228     nop
229     nop
230 NAND_Copy_Main:
231     mov r0, #NAND_FLASH_BOOT
232     ldr r1, AVIC_VECTOR0_ADDR_W
233     str r0, [r1]
234     mov r0, #MXCFIS_NAND
235     ldr r1, AVIC_VECTOR1_ADDR_W
236     str r0, [r1]
237
238     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
239     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
240     add r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
241     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
242     ldr r14, MXC_REDBOOT_ROM_START
243     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
244     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
245
246     //unlock internal buffer
247     mov r3, #0x2
248     strh r3, [r12, #0xA]
249
250 Nfc_Read_Page:
251 //  writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
252     mov r3, #0x0;
253     strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
254     mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
255     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
256     do_wait_op_done
257
258 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
259     mov r3, r1
260     do_addr_input       //1st addr cycle
261     mov r3, r1, lsr #9
262     do_addr_input       //2nd addr cycle
263     mov r3, r1, lsr #17
264     do_addr_input       //3rd addr cycle
265 #ifdef CYGHWR_HAL_ARM_MEM1
266     mov r3, r1, lsr #25
267     do_addr_input       //4th addr cycle
268 #endif
269
270 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
271 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
272 //               NAND_FLASH_CONFIG1_REG);
273     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
274     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
275
276 //        writew(buf_no, RAM_BUFFER_ADDRESS_REG);
277     mov r3, #0
278     strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
279 //        writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
280     mov r3, #FDO_PAGE_SPARE_VAL
281     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
282 //        wait_op_done();
283     do_wait_op_done
284
285     // check for bad block
286     mov r3, r1, lsl #(32-5-9)
287     cmp r3, #(512 << (32-5-9))
288     bhi Copy_Good_Blk
289     add r4, r0, #0x800  //r3 -> spare area buf 0
290     ldrh r4, [r4, #0x4]
291     and r4, r4, #0xFF00
292     cmp r4, #0xFF00
293     beq Copy_Good_Blk
294     // really sucks. Bad block!!!!
295     cmp r3, #0x0
296     beq Skip_bad_block
297     // even suckier since we already read the first page!
298     sub r14, r14, #512  //rewind 1 page for the sdram pointer
299     sub r1, r1, #512    //rewind 1 page for the flash pointer
300 Skip_bad_block:
301     add r1, r1, #(32*512)
302     b Nfc_Read_Page
303 Copy_Good_Blk:
304     //copying page
305 1:  ldmia r0!, {r3-r10}
306     stmia r14!, {r3-r10}
307     cmp r0, r2
308     blo 1b
309     cmp r14, r13
310     bge NAND_Copy_Main_done
311     add r1, r1, #0x200
312     mov r0, #NFC_BASE
313     b Nfc_Read_Page
314
315 NAND_Copy_Main_done:
316
317 Normal_Boot_Continue:
318 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
319     /* Copy image from flash to SDRAM first */
320     ldr r0, =0xFFFFF000
321     and r0, r0, pc
322     ldr r1, MXC_REDBOOT_ROM_START
323     cmp r0, r1
324     beq HWInitialise_skip_SDRAM_copy
325
326     add r2, r0, #REDBOOT_IMAGE_SIZE
327
328 1:  ldmia r0!, {r3-r10}
329     stmia r1!, {r3-r10}
330     cmp r0, r2
331     ble 1b
332     /* Jump to SDRAM */
333     ldr r1, =0xFFFF
334     and r0, pc, r1         /* offset of pc */
335     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
336     add pc, r0, r1
337     nop
338     nop
339     nop
340     nop
341 #endif /* CYG_HAL_STARTUP_ROMRAM */
342 init_cs0_sync_start:
343     init_cs0_sync
344
345 HWInitialise_skip_SDRAM_copy:
346
347 /*
348  * Note:
349  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
350  */
351
352 STACK_Setup:
353     // Set up a stack [for calling C code]
354     ldr r1, =__startup_stack
355     ldr r2, =RAM_BANK0_BASE
356     orr sp, r1, r2
357
358     // Create MMU tables
359     bl hal_mmu_init
360
361     // Enable MMU
362     ldr r2, =10f
363     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
364     orr r1, r1, #7                          // enable MMU bit
365     mcr MMU_CP, 0, r1, MMU_Control, c0
366     mov pc,r2    /* Change address spaces */
367     nop
368     nop
369     nop
370 10:
371
372     // Save shadow copy of BCR, also hardware configuration
373     ldr r1, =_board_BCR
374     str r2, [r1]
375     ldr r1, =_board_CFG
376     str r9, [r1]        // Saved far above...
377
378     .endm               // _platform_setup1
379
380 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
381 #define PLATFORM_SETUP1
382 #endif
383
384     /* Allow all 3 masters to have access to these shared peripherals */
385     .macro  init_spba
386     /* Do nothing */
387     .endm  /* init_spba */
388
389     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
390     .macro init_aips
391         /*
392          * Set all MPROTx to be non-bufferable, trusted for R/W,
393          * not forced to user-mode.
394          */
395         ldr r0, AIPS1_CTRL_BASE_ADDR_W
396         ldr r1, AIPS1_PARAM_W
397         str r1, [r0, #0x00]
398         str r1, [r0, #0x04]
399         ldr r0, AIPS2_CTRL_BASE_ADDR_W
400         str r1, [r0, #0x00]
401         str r1, [r0, #0x04]
402
403         /*
404          * Clear the on and off peripheral modules Supervisor Protect bit
405          * for SDMA to access them. Did not change the AIPS control registers
406          * (offset 0x20) access type
407          */
408         ldr r0, AIPS1_CTRL_BASE_ADDR_W
409         ldr r1, =0x0
410         str r1, [r0, #0x40]
411         str r1, [r0, #0x44]
412         str r1, [r0, #0x48]
413         str r1, [r0, #0x4C]
414         ldr r1, [r0, #0x50]
415         and r1, r1, #0x00FFFFFF
416         str r1, [r0, #0x50]
417
418         ldr r0, AIPS2_CTRL_BASE_ADDR_W
419         ldr r1, =0x0
420         str r1, [r0, #0x40]
421         str r1, [r0, #0x44]
422         str r1, [r0, #0x48]
423         str r1, [r0, #0x4C]
424         ldr r1, [r0, #0x50]
425         and r1, r1, #0x00FFFFFF
426         str r1, [r0, #0x50]
427     .endm /* init_aips */
428
429     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
430     .macro init_max
431         ldr r0, MAX_BASE_ADDR_W
432         /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
433         ldr r1, MAX_PARAM1
434         str r1, [r0, #0x000]        /* for S0 */
435         str r1, [r0, #0x100]        /* for S1 */
436         str r1, [r0, #0x200]        /* for S2 */
437         str r1, [r0, #0x300]        /* for S3 */
438         str r1, [r0, #0x400]        /* for S4 */
439         /* SGPCR - always park on last master */
440         ldr r1, =0x10
441         str r1, [r0, #0x010]        /* for S0 */
442         str r1, [r0, #0x110]        /* for S1 */
443         str r1, [r0, #0x210]        /* for S2 */
444         str r1, [r0, #0x310]        /* for S3 */
445         str r1, [r0, #0x410]        /* for S4 */
446         /* MGPCR - restore default values */
447         ldr r1, =0x0
448         str r1, [r0, #0x800]        /* for M0 */
449         str r1, [r0, #0x900]        /* for M1 */
450         str r1, [r0, #0xA00]        /* for M2 */
451         str r1, [r0, #0xB00]        /* for M3 */
452         str r1, [r0, #0xC00]        /* for M4 */
453         str r1, [r0, #0xD00]        /* for M5 */
454     .endm /* init_max */
455
456     /* Clock setup */
457     .macro init_clock
458         /* RVAL/WVAL for L2 cache memory */
459         ldr r0, RVAL_WVAL_W
460         ldr r1, CLKCTL_BASE_ADDR_W
461         str r0, [r1, #0x10]
462
463         ldr r0, ADPLL_BASE_ADDR_W
464         ldr r2, CRM_AP_BASE_ADDR_W
465         ldr r3, CRM_COM_BASE_ADDR_W
466
467         /*
468          * If PLL has already been configured via RVD script, skip
469          * ADPLL clock setup.  Running ADPLL setup again can
470          * cause strange behaviors and loss of communication with
471          * RVD.
472          */
473         ldr r1, [r2, #CRM_AP_ACSR]
474         ands r1, r1, #(1 << 0)
475         bne udpll_setup
476
477         // Address TLSbo60450 to default analog VREG setting to 1.6V
478         ldr r1, [r3, #CRM_COM_CSCR]
479         orr r1, r1, #(0x7 << 11)
480         str r1, [r3, #CRM_COM_CSCR]
481
482         /*
483          * Configure ADPLL operation register (DP_OP, DP_HFS_OP):
484          */
485         ldr r1, ADPLL_OP_W
486         str r1, [r0, #PLL_DP_OP]
487         str r1, [r0, #PLL_DP_HFS_OP]
488
489         /*
490          * Configure ADPLL operation register (DP_MFN, DP_HFS_MFN):
491          */
492         ldr r1, ADPLL_MFN_W
493         str r1, [r0, #PLL_DP_MFN]
494         str r1, [r0, #PLL_DP_HFS_MFN]
495
496         /*
497          * Configure ADPLL operation register (DP_MFD, DP_HFS_MFN):
498          */
499         ldr r1, ADPLL_MFD_W
500         str r1, [r0, #PLL_DP_MFD]
501         str r1, [r0, #PLL_DP_HFS_MFD]
502
503         /*
504          * Configure CRM_AP divider register (CRM_AP_ACDR):
505          */
506         ldr r1, CRM_AP_DIV_W
507         str r1, [r2, #CRM_AP_ACDR]
508
509         /*
510          * Configure CRM_COM system control register (CRM_COM_CSCR):
511          *      PDN_CLKMON_CKIH = CLKMON on = (0 << 0)  = 0x00000000
512          *      NOCK_CKIH = READ-ONLY = (0 << 1)    = 0x00000000
513          *      PDN_CLKMON_DIGRF = CLKMON off = (1 << 2)= 0x00000004
514          *      NOCK_DIGRF = READ-ONLY = (0 << 3)       = 0x00000000
515          *      BY_AMP_CKIH = CAMP used = (0 << 4)      = 0x00000000
516          *      PDN_AMP_CKIH = CAMP on = (0 << 5)       = 0x00000000
517          *      REG_MOD = one regulator = (0 << 6)      = 0x00000000
518          *      DIGRF_CLK_EN = DIGRF enabled = (1 << 7) = 0x00000080
519          *      Reserved = (3 << 8)             = 0x00000300
520          *      CNTL = 1.4 V (5 << 11)          = 0x00002800
521          *      MUX_SEL = no test signals = (0 << 14)   = 0x00000000
522          *      BP_PDSM_EN = no pseudo DSM = (1 << 16)  = 0x00000000
523          *      CKO_SEL = AP CKO = (1 << 17)        = 0x00020000
524          *      CKOH_SEL = AP CKOH = (1 << 18)      = 0x00040000
525          *      NF_WIDTH = 8-bit = (0 << 19)        = 0x00000000
526          *      NF_PG_SIZ = 512 bytes (0 << 20)     = 0x00000000
527          *      BY_AMP_DIGRF = CAMP used = (0 << 21)    = 0x00000000
528          *      PDN_AMP_DIGRF = CAMP off = (1 << 22)    = 0x00400000
529          *      VREG_CTRL = VREG disabled = (1 << 23)   = 0x00800000
530          *      CKIH_DBLR_OFF = doubler on = (0 << 24)  = 0x00000000
531          *      DIGRF_DBLR_OFF = doubler off = (1 << 25)= 0x02000000
532          *      PDD0 = CRM disables ADPLL = (0 << 26)   = 0x00000000
533          *      PDD1 = CRM disables BDPLL = (0 << 27)   = 0x00000000
534          *      PDD2 = CRM disables UDPLL = (0 << 28)   = 0x00000000
535          *      Reserved = (0 << 29)            = 0x00000000
536          *      MRCG_PWR_GT = not gated = (0 << 30)     = 0x00000000
537          *      BP_PAT_REF_EN = pat_ref on = (1 << 31)  = 0x80000000
538          *                          ------------
539          *                        0x82C62B84
540          */
541         ldr r1, [r3, #CRM_COM_CSCR]
542         bic r1, r1, #(1 << 24)          // enable the CKIH doubler clock
543         orr r1, r1, #(3 << 17)          // AP CKO/CKOH selected
544         str r1, [r3, #CRM_COM_CSCR]
545
546         /*
547          * Wait for CKIH doubler to lock
548          */
549     ckih_x2_lock:
550         ldr r1, [r3, #CRM_COM_CCCR]
551         ands r1, r1, #(1 << 14)
552         beq ckih_x2_lock
553
554         /*
555          * Configure AP clock observation (CRM_AP_ACR):
556          *      CKOS = AP_PAT_REF_CLK = (2 << 4)    = 0x00000020
557          *      CKOD = CKO enabled = (0 << 7)       = 0x00000000
558          *      CKOHDIV = /4 = (2 << 8)         = 0x00000200
559          *      CKOHS = AP_CLK = (1 << 12)          = 0x00001000
560          *      CKOHD = CKOH enabled = (0 << 15)    = 0x00000000
561          *                          ------------
562          *                        0x00001220
563          */
564         ldr r1, CRM_AP_ACR_VAL
565         str r1, [r2, #CRM_AP_ACR]
566
567         /*
568          * Configure CRM_AP DFS control register (CRM_AP_ADCR):
569          *      DIV_BYP = DFS divider used = (0 << 1)   = 0x00000000
570          *      VSTAT = READ-ONLY = (0 << 3)        = 0x00000000
571          *      TSTAT = READ-ONLY = (0 << 4)        = 0x00000000
572          *      DFS_DIV_EN = non-integer DFS = (0 << 5) = 0x00000000
573          *      CLK_ON = PAT_REF during DFS = (1 << 6)  = 0x00000040
574          *      ALT_PLL = no DVS ALT PLL = (0 << 7)     = 0x00000000
575          *      LFDF = /2 = (1 << 8)            = 0x00000100
576          *      AP_DELAY = 976 us = (32 << 16)      = 0x00200000
577          *                          ------------
578          *                        0x00200140
579          */
580         ldr r1, CRM_AP_ADCR_VAL
581         str r1, [r2, #CRM_AP_ADCR]
582
583         /*
584          * Configure CRM_AP source clock selection register (CRM_AP_ASCSR):
585          *      AP_ISEL = CKIH = (0 << 0)           = 0x00000000
586          *      APSEL = ADPLL = (0 << 3)        = 0x00000000
587          *      SSISEL = UDPLL  = (2 << 5)          = 0x00000040
588          *      SS2SEL = UDPLL  = (2 << 7)          = 0x00000100
589          *      FIRISEL = UDPLL = (2 << 9)          = 0x00000400
590          *      CSSEL = UDPLL = (2 << 11)           = 0x00001000
591          *      USBSEL = UDPLL = (2 << 13)          = 0x00004000
592          *      AP_PAT_REF_DIV = /1 = (0 << 15)     = 0x00000000
593          *      CRS = uncorrected PAT_REF = (0 << 16)   = 0x00000000
594          *                          ------------
595          *                        0x00005540
596          */
597         ldr r1, CRM_AP_ASCSR_VAL
598         str r1, [r2, #CRM_AP_ASCSR]
599
600         /*
601          * Configure ADPLL control register (DP_CTL):
602          *      BRMO = second order = (1 << 1)      = 0x00000002
603          *      PLM = freq only lock = (0 << 2)     = 0x00000000
604          *      RCP = pos edge = (0 << 3)           = 0x00000000
605          *      RST = no restart = (0 << 4)         = 0x00000000
606          *      UPEN = PLL enable = (0 << 5)        = 0x00000020
607          *      PRE = no reset = (0 << 6)           = 0x00000000
608          *      HFSM = normal mode = (0 << 7)       = 0x00000000
609          *      REF_CLK_SEL = ckih_camp_x2 = (2 << 8)   = 0x00000200
610          *      REF_CLK_DIV = /1 = (0 << 10)        = 0x00000000
611          *                          ------------
612          *                        0x00000222
613          */
614
615         ldr r1, DPLL_DP_CTL_VAL
616         str r1, [r0, #PLL_DP_CTL]
617
618         /*
619          * Wait for ADPLL to lock
620          */
621     adpll_lock:
622         ldr r1, [r0, #PLL_DP_CTL]
623         ands r1, r1, #(1 << 0)
624         beq adpll_lock
625
626         /*
627          * Configure AP clock selection register (CRM_AP_ACSR):
628          *      ACS = PLL_CLK = (1 << 0)        = 0x00000001
629          *      WPS = PLL_CLK in wait mode = (0 << 1)   = 0x00000000
630          *      PDS = PLL on in stop mode  = (0 << 2)   = 0x00000000
631          *      SMD = use sync muxes = (1 << 3)     = 0x00000000
632          *      DI = ignore dsm_int = (0 << 7)      = 0x00000000
633          *      ADS = non-doubler path = (0 << 8)       = 0x00000000
634          *                          ------------
635          *                        0x00000001
636          */
637         ldr r1, =0x00000001
638         str r1, [r2, #CRM_AP_ACSR]
639
640
641     udpll_setup:
642         /*
643          * Configure UDPLL registers
644          */
645         ldr r0, UDPLL_BASE_ADDR_W
646
647         /*
648          * Configure UDPLL operation register (DP_OP, DP_HFS_OP):
649          */
650         ldr r1, UDPLL_OP_W
651         str r1, [r0, #PLL_DP_OP]
652         str r1, [r0, #PLL_DP_HFS_OP]
653
654         /*
655          * Configure UDPLL operation register (DP_MFN, DP_HFS_MFN):
656          */
657         ldr r1, UDPLL_MFN_W
658         str r1, [r0, #PLL_DP_MFN]
659         str r1, [r0, #PLL_DP_HFS_MFN]
660
661         /*
662          * Configure UDPLL operation register (DP_MFD, DP_HFS_MFN):
663          */
664         ldr r1, UDPLL_MFD_W
665         str r1, [r0, #PLL_DP_MFD]
666         str r1, [r0, #PLL_DP_HFS_MFD]
667
668         /*
669          * Configure UDPLL control register (DP_CTL):
670          *      BRMO = second order = (1 << 1)      = 0x00000002
671          *      PLM = freq only lock = (0 << 2)     = 0x00000000
672          *      RCP = pos edge = (0 << 3)           = 0x00000000
673          *      RST = no restart = (0 << 4)         = 0x00000000
674          *      UPEN = PLL enable = (0 << 5)        = 0x00000020
675          *      PRE = no reset = (0 << 6)           = 0x00000000
676          *      HFSM = normal mode = (0 << 7)       = 0x00000000
677          *      REF_CLK_SEL = ckih_camp = (0 << 8)      = 0x00000000
678          *      REF_CLK_DIV = /1 = (0 << 10)        = 0x00000000
679          *                          ------------
680          *                        0x00000022
681          */
682         ldr r1, =0x00000022
683         str r1, [r0, #PLL_DP_CTL]
684
685         /*
686          * Wait for UDPLL to lock
687          */
688     udpll_lock:
689         ldr r1, [r0, #PLL_DP_CTL]
690         ands r1, r1, #(1 << 0)
691         beq udpll_lock
692
693         /*
694          * Configure AP accessory clock register (CRM_AP_ACDER1):
695          *      SSI1DIV = /12.5 = (0x19 << 0)       = 0x00000019
696          *      SSI1EN = off = (0 << 6)         = 0x00000000
697          *      SSI2DIV = /12.5 = (0x19 << 8)       = 0x00001900
698          *      SSI2EN = off = (0 << 14)        = 0x00000000
699          *      FIRIEN = off = (1 << 22)        = 0x00000000
700          *      CSEN = off = (0 << 20)          = 0x00000000
701          *                          ------------
702          *                        0x00001919
703          */
704         ldr r1, CRM_AP_ACDER1_W
705         str r1, [r2, #CRM_AP_ACDER1]
706
707         /*
708          * Configure AP accessory clock register (CRM_AP_ACDER2):
709          *      BAUD_DIV = /1 = (8 << 0)        = 0x00000008
710          *      BAUD_ISEL = CKIH_X2 = (1 << 5)      = 0x00000020
711          *      USBEN = USB_CLK enabled = (1 << 12)     = 0x00001000
712          *      NFCEN = NFC_CLK enabled = (1 << 20)     = 0x00100000
713          *                          ------------
714          *                        0x00101028
715          */
716         ldr r1, CRM_AP_ACDER2_W
717         str r1, [r2, #CRM_AP_ACDER2]
718
719         // AP CKO/CKOH selected
720         ldr r0, CRM_COM_BASE_ADDR_W
721         ldr r1, [r0, #0x0C]
722         orr r1, r1, #0x60000
723         str r1, [r0, #0x0C]
724         ldr r0, CRM_AP_BASE_ADDR_W
725         /* Default CKOH as AP_CLK with div by 10 */
726         //orr r1, r1, #0x5600 /* HCLK */
727         ldr r1, [r0, #CRM_AP_ACR]
728         bic r1, r1, #0xFF00
729         bic r1, r1, #0x00FF
730         orr r1, r1, #0x1600
731         str r1, [r0, #CRM_AP_ACR]
732
733         // SD clock input select - usb_clk. divider changed to 1
734         mov r1, #0x00009100
735         add r1, r1, #0x00000091
736         str r1, [r0, #CRM_AP_APRB]
737     .endm /* init_clock */
738
739     /* M3IF setup */
740     .macro init_m3if
741         /* Configure M3IF registers */
742         ldr r1, M3IF_BASE_W
743         /*
744         * M3IF Control Register (M3IFCTL)
745         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
746         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
747         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
748         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
749         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
750         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
751         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
752         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
753         *                                                       ------------
754         *                                                       0x00000040
755         */
756         ldr r0, =0x00000040
757         str r0, [r1]  /* M3IF control reg */
758     .endm /* init_m3if */
759
760     /* CS0 sync mode setup */
761     .macro init_cs0_sync
762 #ifndef CYGHWR_HAL_ARM_MEM1
763         /*
764          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
765          */
766         /* Flash reset command */
767         ldr r0, =CS0_BASE_ADDR
768         ldr r1, =0xF0F0
769         strh r1, [r0]
770         /* 1st command */
771         ldr r2, =0xAAA
772         add r2, r2, r0
773         ldr r1, =0xAAAA
774         strh r1, [r2]
775         /* 2nd command */
776         ldr r2, =0x554
777         add r2, r2, r0
778         ldr r1, =0x5555
779         strh r1, [r2]
780         /* 3rd command */
781         ldr r2, =0xAAA
782         add r2, r2, r0
783         ldr r1, =0xD0D0
784         strh r1, [r2]
785         /* Write flash config register */
786         ldr r1, =0x56CA
787         strh r1, [r2]
788         /* Flash reset command */
789         ldr r1, =0xF0F0
790         strh r1, [r0]
791
792         ldr r0, =WEIM_BASE_ADDR
793         ldr r1, =0x23524E80
794         str r1, [r0, #CSCRU]
795         ldr r1, =0x10000D03
796         str r1, [r0, #CSCRL]
797         ldr r1, =0x00720900
798         str r1, [r0, #CSCRA]
799 #else  // CYGHWR_HAL_ARM_MEM1
800         ldr r0, =WEIM_BASE_ADDR
801         ldr r1, =0x23524E80
802         str r1, [r0, #CSCRU]
803         ldr r1, =0xC0000E03
804         str r1, [r0, #CSCRL]
805         ldr r1, =0x0072BD00
806         str r1, [r0, #CSCRA]
807         /* Flash reset command */
808         ldr r0, =CS0_BASE_ADDR
809         ldr r1, =0xF0F0F0F0
810         str r1, [r0]
811         /* Write 1st command with address multiplied by 2 */
812         ldr r0, =0xA0001554
813         ldr r1, = 0xAAAAAAAA
814         str r1, [r0]
815         /* Write 2nd command with address multiplied by 2 */
816         ldr r0, =0xA0000AA8
817         ldr r1, = 0x55555555
818         str r1, [r0]
819         /* Write 0xB80020003rd command with address multiplied by 2 */
820         ldr r0, =0xA0001554
821         ldr r1, = 0xD0D0D0D0
822         str r1, [r0]
823         /* //  Write Config register  (4 waits, wrap, Burst=8). Burst Enabled
824           "FOR WHEN FCE BROKE!!!" (Sync. Mode) AHB/BCLK=133/44.3MHz   (Optimal
825           configuration) */
826         ldr r0, =0xA0001554
827         ldr r1, = 0x56CA56CA
828         str r1, [r0]
829
830         /* Flash reset command */
831         ldr r0, =CS0_BASE_ADDR
832         ldr r1, =0xF0F0F0F0
833         str r1, [r0]
834 #endif
835     .endm /* init_cs0_sync */
836
837     /* CS0 async mode setup */
838     .macro init_cs0_async
839 init_cs0_async_start:
840         /* Async flash mode */
841 #ifndef CYGHWR_HAL_ARM_MEM1
842         ldr r0, WEIM_CTRL_CS0_W
843         ldr r1, CSCRU_VAL
844         str r1, [r0, #CSCRU]
845         ldr r1, CSCRL_VAL
846         str r1, [r0, #CSCRL]
847         ldr r1, CSCRA_VAL
848         str r1, [r0, #CSCRA]
849 #else
850         ldr r0, WEIM_CTRL_CS0_W
851         ldr r1, CSCRU_VAL
852         str r1, [r0, #CSCRU]
853         ldr r1, CSCRL_VAL
854         str r1, [r0, #CSCRL]
855         ldr r1, CSCRA_VAL
856         str r1, [r0, #CSCRA]
857 #endif /* CYGHWR_HAL_ARM_MEM1 */
858     .endm /* init_cs0_async */
859
860     /* CPLD on CS4 setup */
861     .macro init_cs4
862         ldr r0, WEIM_CTRL_CS4_W
863         ldr r1, CS4_CSCRU_VAL1
864         str r1, [r0, #CSCRU]
865         ldr r1, CS4_CSCRL_VAL1
866         str r1, [r0, #CSCRL]
867         ldr r1, CS4_CSCRA_VAL1
868         str r1, [r0, #CSCRA]
869
870         ldr r0, CS4_BASE_ADDR_W
871         ldrh r1, [r0, #0x0]
872         and r0, r1, #0xFF00
873         cmp r0, #0x2000
874         bge done_cs4_setup
875
876         ldr r0, WEIM_CTRL_CS4_W
877         ldr r1, CS4_CSCRU_VAL
878         str r1, [r0, #CSCRU]
879         ldr r1, CS4_CSCRL_VAL
880         str r1, [r0, #CSCRL]
881         ldr r1, CS4_CSCRA_VAL
882         str r1, [r0, #CSCRA]
883
884 done_cs4_setup:
885
886     .endm /* init_cs4 */
887
888     .macro setup_sdram, name, bus_width, mode, full_page
889         /* It sets the "Z" flag in the CPSR at the end of the macro */
890         ldr r0, ESDCTL_BASE_W
891         mov r2, #SDRAM_BASE_ADDR
892         ldr r1, SDRAM_0x0075E73A
893         str r1, [r0, #0x4]
894         mov r1, #0x2        // reset
895         str r1, [r0, #0x10]
896         ldr r1, SDRAM_PARAM1_\mode
897         str r1, [r0, #0x10]
898
899         // Hold for more than 200ns
900         mov r1, #0x10000
901     1:
902         subs r1, r1, #0x1
903         bne 1b
904
905         ldr r1, SDRAM_0x92100000
906         str r1, [r0]
907         mov r1, #0x0
908         ldr r12, SDRAM_PARAM2_\mode
909         str r1, [r12]
910         ldr r1, SDRAM_0xA2100000
911         str r1, [r0]
912         mov r1, #0x0
913         str r1, [r2]
914         ldr r1, SDRAM_0xB2100000
915         str r1, [r0]
916
917         mov r1, #0x0
918         .if \full_page
919         strb r1, [r2, #SDRAM_FULL_PAGE_MODE]
920         .else
921         strb r1, [r2, #SDRAM_BURST_MODE]
922         .endif
923         mov r1, #0xFF
924         mov r12, #0x81000000
925         strb r1, [r12]
926         ldr r3, SDRAM_0x82116080
927         ldr r4, SDRAM_PARAM3_\mode
928         add r3, r3, r4
929         ldr r4, SDRAM_PARAM4_\bus_width
930         add r3, r3, r4
931         .if \full_page
932         add r3, r3, #0x100   /* Force to full page mode */
933         .endif
934
935         str r3, [r0]
936         mov r1, #0x0
937         str r1, [r2]
938         /* Below only for DDR */
939         ldr r1, [r0, #0x10]
940         ands r1, r1, #0x4
941         movne r1, #0x0000000C
942         strne r1, [r0, #0x10]
943         /* Testing if it is truly DDR */
944         ldr r1, SDRAM_COMPARE_CONST1
945         mov r0, #SDRAM_BASE_ADDR
946         str r1, [r0]
947         ldr r2, SDRAM_COMPARE_CONST2
948         str r2, [r0, #0x4]
949         ldr r2, [r0]
950         cmp r1, r2
951     .endm // setup_sdram
952
953     .macro do_wait_op_done
954     1:
955         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
956         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
957         beq 1b
958         mov r3, #0x0
959         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
960     .endm   // do_wait_op_done
961
962     .macro do_addr_input
963         and r3, r3, #0xFF
964         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
965         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
966         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
967         do_wait_op_done
968     .endm   // do_addr_input
969
970     .macro  init_drive_strength
971         ldr r0, IOMUX_COM_BASE_ADDR_W
972         add r0, r0, #0x200
973         // default is high ds
974         mov r1, #0x0092
975         mov r2, #0x0082
976         mov r3, #0x0002
977         mov r4, #CS4_BASE_ADDR
978 #ifdef DS_SETUP_USE_DEBUG_SWITCH
979         ldrh r5, [r4, #0x2]
980         and r5, r5, #0x3
981         cmp r5, #0x0
982         //  skip ds setup
983         beq drive_strength_ret
984         cmp r5, #0x2
985 #else
986         mov r5, #0x0
987         cmp r5, #0x0
988 #endif
989         // max ds
990         addeq r1, r1, #0x2
991         addeq r2, r2, #0x2
992         addeq r3, r3, #0x2
993
994     setup_drive_strength:
995         strh r1, [r0, #0x00]
996         strh r3, [r0, #0x02]
997         strh r3, [r0, #0x04]
998         strh r1, [r0, #0x06]
999         strh r3, [r0, #0x08]
1000         strh r3, [r0, #0x0A]
1001         strh r3, [r0, #0x0C]
1002         strh r3, [r0, #0x0E]
1003         strh r2, [r0, #0x10]
1004     drive_strength_ret:
1005     .endm
1006
1007 #define PLATFORM_VECTORS         _platform_vectors
1008     .macro  _platform_vectors
1009         .globl  _board_BCR, _board_CFG
1010 _board_BCR:   .long   0       // Board Control register shadow
1011 _board_CFG:   .long   0       // Board Configuration (read at RESET)
1012     .endm
1013
1014 ARM_PPMRR:              .word   0x40000015
1015 L2CACHE_PARAM:          .word   0x00030024
1016 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
1017 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
1018 AIPS1_PARAM_W:          .word   0x77777777
1019 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
1020 MAX_PARAM1:             .word   0x00302154
1021 RVAL_WVAL_W:            .word   0x515
1022 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
1023 ADPLL_BASE_ADDR_W:      .word   ADPLL_BASE_ADDR
1024 CRM_AP_BASE_ADDR_W:     .word   CRM_AP_BASE_ADDR
1025 CRM_COM_BASE_ADDR_W:    .word   CRM_COM_BASE_ADDR
1026 IOMUX_COM_BASE_ADDR_W:  .word   IOMUX_COM_BASE_ADDR
1027 ADPLL_OP_W:             .word   ADPLL_OP
1028 ADPLL_MFN_W:            .word   ADPLL_MFN
1029 ADPLL_MFD_W:            .word   ADPLL_MFD
1030 CRM_AP_DIV_W:           .word   CRM_AP_DIV
1031 CRM_AP_ACR_VAL:         .word   0x00001220
1032 CRM_AP_ADCR_VAL:        .word   0x00200140
1033 CRM_AP_ASCSR_VAL:       .word   0x00005540
1034 DPLL_DP_CTL_VAL:        .word   0x00000222
1035 UDPLL_BASE_ADDR_W:      .word   UDPLL_BASE_ADDR
1036 UDPLL_MFN_W:            .word   UDPLL_MFN
1037 UDPLL_MFD_W:            .word   UDPLL_MFD
1038 UDPLL_OP_W:             .word   UDPLL_OP
1039 CRM_AP_ACDER1_W:        .word   0x00001919 | (FIRI_DIV << 16) | (CS_DIV << 24)
1040 CRM_AP_ACDER2_W:        .word   0x00101028 | (NFC_DIV << 16) | (USB_DIV << 8)
1041 ESDCTL_BASE_W:          .word   ESDCTL_BASE
1042 SDRAM_PARAM1_DDR:       .word   0x4
1043 SDRAM_PARAM1_SDR:       .word   0x0
1044 SDRAM_PARAM2_DDR:       .word   0x80000F00
1045 SDRAM_PARAM2_SDR:       .word   0x80000400
1046 SDRAM_PARAM3_DDR:       .word   0x00100000
1047 SDRAM_PARAM3_SDR:       .word   0x0
1048 SDRAM_PARAM4_X32:       .word   0x00010000
1049 SDRAM_PARAM4_X16:       .word   0x0
1050 WEIM_CTRL_CS0_W:        .word   WEIM_CTRL_CS0
1051 M3IF_BASE_W:            .word   M3IF_BASE
1052 WEIM_CTRL_CS4_W:        .word   WEIM_CTRL_CS4
1053 CS4_BASE_ADDR_W:        .word   CS4_BASE_ADDR
1054 CS4_CSCRU_VAL:          .word   0x0000D843
1055 CS4_CSCRL_VAL:          .word   0x22252521
1056 CS4_CSCRA_VAL:          .word   0x22220A00
1057 CS4_CSCRU_VAL1:         .word   0x0000D743
1058 CS4_CSCRL_VAL1:         .word   0x42001521
1059 CS4_CSCRA_VAL1:         .word   0x00430A00
1060 SDRAM_0x0075E73A:       .word   0x0075E73A
1061 SDRAM_0x82116080:       .word   0x82116080
1062 SDRAM_0x92100000:       .word   0x92100000
1063 SDRAM_0xA2100000:       .word   0xA2100000
1064 SDRAM_0xB2100000:       .word   0xB2100000
1065 SDRAM_COMPARE_CONST1:   .word   0x55555555
1066 SDRAM_COMPARE_CONST2:   .word   0xAAAAAAAA
1067 #ifndef CYGHWR_HAL_ARM_MEM1
1068 CSCRU_VAL:              .word   0x11414C80
1069 CSCRL_VAL:              .word   0x30000D03
1070 CSCRA_VAL:              .word   0x00310800
1071 #else
1072 CSCRU_VAL:              .word   0x11414C80
1073 CSCRL_VAL:              .word   0xC0000E03
1074 CSCRA_VAL:              .word   0x0021BC00
1075 #endif
1076 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
1077 CONST_0xFFFF:           .word   0xFFFF
1078 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
1079 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
1080 /*---------------------------------------------------------------------------*/
1081 /* end of hal_platform_setup.h                                               */
1082 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */