]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91221/evb/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mxc91221 / 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
61 #define CYGHWR_HAL_ROM_VADDR    0x0
62
63 #if 0
64 #define UNALIGNED_ACCESS_ENABLE
65 #define SET_T_BIT_DISABLE
66 #define BRANCH_PREDICTION_ENABLE
67 #endif
68
69 //#define TURN_OFF_IMPRECISE_ABORT
70
71 // This macro represents the initial startup code for the platform
72 // r11 is reserved to contain chip rev info in this file
73     .macro  _platform_setup1
74 FSL_BOARD_SETUP_START:
75 /*
76  *       ARM1136 init
77  *       - invalidate I/D cache/TLB and drain write buffer;
78  *       - invalidate L2 cache
79  *       - unaligned access
80  *       - branch predictions
81  */
82 #ifdef TURN_OFF_IMPRECISE_ABORT
83     mrs r0, cpsr
84     bic r0, r0, #0x100
85     msr cpsr, r0
86 #endif
87
88     mov r0, #0
89     mcr 15, 0, r0, c7, c7, 0        /* invalidate I cache and D cache */
90     mcr 15, 0, r0, c8, c7, 0        /* invalidate TLBs */
91     mcr 15, 0, r0, c7, c10, 4       /* Drain the write buffer */
92
93     mov r0, #SDRAM_NON_FLASH_BOOT
94     ldr r1, AVIC_VECTOR0_ADDR_W
95     str r0, [r1] // for checking boot source from nand, nor or sdram
96
97 init_spba_start:
98     init_spba
99 init_aips_start:
100     init_aips
101 init_max_start:
102     init_max
103 init_m3if_start:
104     init_m3if
105
106     mov r11, #CHIP_REV_1_0
107     ldr r0, IIM_SREV_REG_VAL
108     ldr r1, [r0, #0x0]
109     cmp r1, #0x0
110     movne r11, #CHIP_REV_2_0
111 init_cs0_async_start:
112     init_cs0_async
113
114     /* If SDRAM has been setup, bypass clock/WEIM setup */
115     cmp pc, #SDRAM_BASE_ADDR
116     blo init_clock_start
117     cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
118     blo HWInitialise_skip_SDRAM_setup
119
120     mov r0, #NOR_FLASH_BOOT
121     ldr r1, AVIC_VECTOR0_ADDR_W
122     str r0, [r1]
123
124 init_clock_start:
125     init_clock
126
127 init_sdram_start:
128
129     /* Assuming DDR memory first */
130     //init_drive_strength_ddr
131     init_ddr_sdram
132     /* Testing if it is truly DDR */
133     ldr r1, SDRAM_COMPARE_CONST1
134     mov r0, #SDRAM_BASE_ADDR
135     str r1, [r0]
136     ldr r2, SDRAM_COMPARE_CONST2
137     str r2, [r0, #0x4]
138     ldr r2, [r0]
139     cmp r1, r2
140     beq HWInitialise_skip_SDRAM_setup
141
142     /* Reach here ONLY when SDR */
143     init_drive_strength_sdr
144     init_sdr_sdram
145     /* Test to make sure SDR */
146     ldr r1, SDRAM_COMPARE_CONST1
147     mov r0, #SDRAM_BASE_ADDR
148     str r1, [r0]
149     ldr r2, SDRAM_COMPARE_CONST2
150     str r2, [r0, #0x4]
151     ldr r2, [r0]
152     cmp r1, r2
153     beq HWInitialise_skip_SDRAM_setup
154
155     /* Reach hear means memory setup problem. Try to
156      * increase the HCLK divider */
157     ldr r0, CRM_AP_BASE_ADDR_W
158     ldr r1, [r0, #CRM_AP_ACDR]
159     and r2, r1, #0x70
160     cmp r2, #0x70
161     beq loop_forever
162     add r1, r1, #0x12
163     str r1, [r0, #CRM_AP_ACDR]
164     b init_sdram_start
165
166 loop_forever:
167     b loop_forever  /* shouldn't get here */
168
169 HWInitialise_skip_SDRAM_setup:
170
171     mov r0, #NFC_BASE
172     add r2, r0, #0x800      // 2K window
173     cmp pc, r0
174     blo Normal_Boot_Continue
175     cmp pc, r2
176     bhi Normal_Boot_Continue
177 NAND_Boot_Start:
178     /* Copy image from flash to SDRAM first */
179     ldr r1, MXC_REDBOOT_ROM_START
180
181 1:  ldmia r0!, {r3-r10}
182     stmia r1!, {r3-r10}
183     cmp r0, r2
184     blo 1b
185     /* Jump to SDRAM */
186     ldr r1, CONST_0x0FFF
187     and r0, pc, r1     /* offset of pc */
188     ldr r1, MXC_REDBOOT_ROM_START
189     add r1, r1, #0x10
190     add pc, r0, r1
191     nop
192     nop
193     nop
194     nop
195 NAND_Copy_Main:
196     mov r0, #NAND_FLASH_BOOT
197     ldr r1, AVIC_VECTOR0_ADDR_W
198     str r0, [r1]
199     mov r0, #MXCFIS_NAND
200     ldr r1, AVIC_VECTOR1_ADDR_W
201     str r0, [r1]
202
203     mov r0, #NFC_BASE;   //r0: nfc base. Reloaded after each page copying
204     mov r1, #0x800       //r1: starting flash addr to be copied. Updated constantly
205     add r2, r0, #0x200   //r2: end of 1st RAM buf. Doesn't change
206     add r12, r0, #0xE00  //r12: NFC register base. Doesn't change
207     ldr r14, MXC_REDBOOT_ROM_START
208     add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
209     add r14, r14, r1     //r14: starting SDRAM address for copying. Updated constantly
210
211     //unlock internal buffer
212     mov r3, #0x2
213     strh r3, [r12, #0xA]
214
215 Nfc_Read_Page:
216 //  writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
217     mov r3, #0x0;
218     strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
219     mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
220     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
221     do_wait_op_done
222
223 //    start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
224     mov r3, r1
225     do_addr_input       //1st addr cycle
226     mov r3, r1, lsr #9
227     do_addr_input       //2nd addr cycle
228     mov r3, r1, lsr #17
229     do_addr_input       //3rd addr cycle
230
231 //    NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
232 //        writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
233 //               NAND_FLASH_CONFIG1_REG);
234     mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
235     strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
236
237 //        writew(buf_no, RAM_BUFFER_ADDRESS_REG);
238     mov r3, #0
239     strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
240 //        writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
241     mov r3, #FDO_PAGE_SPARE_VAL
242     strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
243 //        wait_op_done();
244     do_wait_op_done
245
246     // check for bad block
247     mov r3, r1, lsl #(32-5-9)
248     cmp r3, #(512 << (32-5-9))
249     bhi Copy_Good_Blk
250     add r4, r0, #0x800  //r3 -> spare area buf 0
251     ldrh r4, [r4, #0x4]
252     and r4, r4, #0xFF00
253     cmp r4, #0xFF00
254     beq Copy_Good_Blk
255     // really sucks. Bad block!!!!
256     cmp r3, #0x0
257     beq Skip_bad_block
258     // even suckier since we already read the first page!
259     sub r14, r14, #512  //rewind 1 page for the sdram pointer
260     sub r1, r1, #512    //rewind 1 page for the flash pointer
261 Skip_bad_block:
262     add r1, r1, #(32*512)
263     b Nfc_Read_Page
264 Copy_Good_Blk:
265     //copying page
266 1:  ldmia r0!, {r3-r10}
267     stmia r14!, {r3-r10}
268     cmp r0, r2
269     blo 1b
270     cmp r14, r13
271     bge NAND_Copy_Main_done
272     add r1, r1, #0x200
273     mov r0, #NFC_BASE
274     b Nfc_Read_Page
275
276 NAND_Copy_Main_done:
277
278 Normal_Boot_Continue:
279
280 init_cs4_start:
281     init_cs4
282
283 #ifdef CYG_HAL_STARTUP_ROMRAM     /* enable running from RAM */
284     /* Copy image from flash to SDRAM first */
285     ldr r0, =0xFFFFF000
286     and r0, r0, pc
287     ldr r1, MXC_REDBOOT_ROM_START
288     cmp r0, r1
289     beq HWInitialise_skip_SDRAM_copy
290
291     add r2, r0, #REDBOOT_IMAGE_SIZE
292
293 1:  ldmia r0!, {r3-r10}
294     stmia r1!, {r3-r10}
295     cmp r0, r2
296     ble 1b
297     /* Jump to SDRAM */
298     ldr r1, =0xFFFF
299     and r0, pc, r1         /* offset of pc */
300     ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
301     add pc, r0, r1
302     nop
303     nop
304     nop
305     nop
306 #endif /* CYG_HAL_STARTUP_ROMRAM */
307 init_cs0_sync_start:
308     init_cs0_sync
309
310 HWInitialise_skip_SDRAM_copy:
311
312 /*
313  * Note:
314  *     IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
315  */
316
317 STACK_Setup:
318     // Set up a stack [for calling C code]
319     ldr r1, =__startup_stack
320     ldr r2, =RAM_BANK0_BASE
321     orr sp, r1, r2
322
323     // Create MMU tables
324     bl hal_mmu_init
325
326     // Enable MMU
327     ldr r2, =10f
328     mrc MMU_CP, 0, r1, MMU_Control, c0      // get c1 value to r1 first
329     orr r1, r1, #7                          // enable MMU bit
330     mcr MMU_CP, 0, r1, MMU_Control, c0
331     mov pc,r2    /* Change address spaces */
332     nop
333     nop
334     nop
335 10:
336
337     // Save shadow copy of BCR, also hardware configuration
338     ldr r1, =_board_BCR
339     str r2, [r1]
340     ldr r1, =_board_CFG
341     str r9, [r1]                // Saved far above...
342
343     .endm                       // _platform_setup1
344
345 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
346 #define PLATFORM_SETUP1
347 #endif
348
349     /* Allow all 3 masters to have access to these shared peripherals */
350     .macro  init_spba
351         ldr r0, SPBA_CTRL_BASE_ADDR_W
352         mov r1, #0x7            /* allow all 3 masters access */
353         str r1, [r0, #0x04]
354         str r1, [r0, #0x0C]
355         str r1, [r0, #0x10]
356         str r1, [r0, #0x14]
357         str r1, [r0, #0x18]
358         str r1, [r0, #0x1C]
359         str r1, [r0, #0x24]
360         str r1, [r0, #0x28]
361         str r1, [r0, #0x40]
362         str r1, [r0, #0x44]
363         str r1, [r0, #0x48]
364         str r1, [r0, #0x4C]
365         str r1, [r0, #0x50]
366         str r1, [r0, #0x54]
367         str r1, [r0, #0x58]
368         str r1, [r0, #0x5C]
369     .endm  /* init_spba */
370
371     /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
372     .macro init_aips
373         /*
374          * Set all MPROTx to be non-bufferable, trusted for R/W,
375          * not forced to user-mode.
376          */
377         ldr r0, AIPS1_CTRL_BASE_ADDR_W
378         ldr r1, AIPS1_PARAM_W
379         str r1, [r0, #0x00]
380         str r1, [r0, #0x04]
381         ldr r0, AIPS2_CTRL_BASE_ADDR_W
382         str r1, [r0, #0x00]
383         str r1, [r0, #0x04]
384
385         /*
386          * Clear the on and off peripheral modules Supervisor Protect bit
387          * for SDMA to access them. Did not change the AIPS control registers
388          * (offset 0x20) access type
389          */
390         ldr r0, AIPS1_CTRL_BASE_ADDR_W
391         ldr r1, =0x0
392         str r1, [r0, #0x40]
393         str r1, [r0, #0x44]
394         str r1, [r0, #0x48]
395         str r1, [r0, #0x4C]
396         ldr r1, [r0, #0x50]
397         and r1, r1, #0x00FFFFFF
398         str r1, [r0, #0x50]
399
400         ldr r0, AIPS2_CTRL_BASE_ADDR_W
401         ldr r1, =0x0
402         str r1, [r0, #0x40]
403         str r1, [r0, #0x44]
404         str r1, [r0, #0x48]
405         str r1, [r0, #0x4C]
406         ldr r1, [r0, #0x50]
407         and r1, r1, #0x00FFFFFF
408         str r1, [r0, #0x50]
409     .endm /* init_aips */
410
411     /* MAX (Multi-Layer AHB Crossbar Switch) setup */
412     .macro init_max
413         ldr r0, MAX_BASE_ADDR_W
414         /* MPR - priority is M3 > M0 > M1 > M2 */
415         ldr r1, MAX_PARAM1
416         str r1, [r0, #0x000]        /* for S0 */
417         str r1, [r0, #0x100]        /* for S1 */
418         str r1, [r0, #0x200]        /* for S2 */
419         str r1, [r0, #0x300]        /* for S3 */
420         str r1, [r0, #0x400]        /* for S4 */
421         /* SGPCR - always park on last master */
422         ldr r1, =0x10
423         str r1, [r0, #0x010]        /* for S0 */
424         str r1, [r0, #0x110]        /* for S1 */
425         str r1, [r0, #0x210]        /* for S2 */
426         str r1, [r0, #0x310]        /* for S3 */
427         str r1, [r0, #0x410]        /* for S4 */
428         /* MGPCR - restore default values */
429         ldr r1, =0x0
430         str r1, [r0, #0x800]        /* for M0 */
431         str r1, [r0, #0x900]        /* for M1 */
432         str r1, [r0, #0xA00]        /* for M2 */
433         str r1, [r0, #0xB00]        /* for M3 */
434     .endm /* init_max */
435
436     /* Clock setup */
437     .macro init_clock
438         /*
439          * Clock setup
440          * After this step, AP domain is running out of PLL0 with:
441
442            Module           Freq (MHz)   Note
443            =========================================================================
444            ARM core         266          ap_clk
445            AHB              133          known as "hclk" for ap_hclk and xxx_ahb_clk's
446            IP               66.5         ap_pclk and ap_com_pclk
447            EMI              133          =hclk
448
449          * All other clocks can be figured out based on this.
450          */
451         /*
452         * Step 1: Make CKOH controlled by CKOH.
453         * Switch to patref
454         */
455         ldr r0, IOMUX_COM_BASE_ADDR_W
456         add r0, r0, #0x14
457         ldr r1, =0x0
458         strh r1, [r0, #0x2]
459         ldr r0, CRM_AP_BASE_ADDR_W
460         str r1, [r0, #CRM_AP_ACSR]
461         /*
462         * Step 2: Setup PLL0 - ADPLL for AP domain.
463         */
464         ldr r0, PLL0_BASE_ADDR_W
465         ldr r1, =0x2
466         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
467         ldr r1, =0x12
468         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON; BRMO=1 */
469         ldr r1, =0x0
470         str r1, [r0, #PLL_DP_CTL]
471
472         /*
473         * Set PLL0 to be 399MHz.
474         * MFI=5, PDF=0, MFD=25, MFN=3 ->
475         * PLL0=2*26MHzInput*(5+3/(25+1))/(0+1)=266 MHz
476         */
477         ldr r1, =0x50
478         str r1, [r0, #PLL_DP_OP]
479         ldr r1, =0x19
480         str r1, [r0, #PLL_DP_MFD]
481         ldr r1, =0x3
482         str r1, [r0, #PLL_DP_MFN]
483
484         ldr r1, =0x50
485         str r1, [r0, #PLL_DP_HFS_OP]
486         ldr r1, =0x19
487         str r1, [r0, #PLL_DP_HFS_MFD]
488         ldr r1, =0x3
489         str r1, [r0, #PLL_DP_HFS_MFN]
490
491         /* Now restart DPLL */
492         ldr r1, =0x22
493         str r1, [r0, #PLL_DP_CTL]
494 wait_pll0_lock:
495         ldr r1, [r0, #PLL_DP_CTL]
496         ands r1, r1, #0x1
497         beq wait_pll0_lock
498
499         /* End of PLL0 setup with PLL0 being locked at 399MHz */
500
501         /*
502         * Set PLL2 to 240MHz
503         */
504         ldr r0, PLL2_BASE_ADDR_W
505
506         ldr r1, =0x22
507         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
508         ldr r1, =0x2
509         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
510
511         /*
512         * MFI=9, PDF=1, MFD=12, MFN=3 ->
513         * PLL2 = 2*26*(9+3/(12+1))/(1+1)=240 MHz
514         */
515         ldr r1, =0x91
516         str r1, [r0, #PLL_DP_OP]
517         ldr r1, =0xC
518         str r1, [r0, #PLL_DP_MFD]
519         ldr r1, =0x3
520         str r1, [r0, #PLL_DP_MFN]
521
522         ldr r1, =0x91
523         str r1, [r0, #PLL_DP_HFS_OP]
524         ldr r1, =0xC
525         str r1, [r0, #PLL_DP_HFS_MFD]
526         ldr r1, =0x3
527         str r1, [r0, #PLL_DP_HFS_MFN]
528
529         /* Now restart DPLL */
530         ldr r1, =0x32
531         str r1, [r0, #PLL_DP_CTL]
532
533 wait_pll2_lock:
534         ldr r1, [r0, #PLL_DP_CTL]
535         ands r1, r1, #0x1
536         beq wait_pll2_lock
537         /* End of PLL2 setup with PLL2 being locked at 48MHz */
538
539         /*
540         * Step 3: switching to DPLL for AP domain and restore default register values.
541         */
542         // AP CKO/CKOH selected
543         ldr r0, SRC_BASE_ADDR_W
544         ldr r1, [r0, #SRC_SSCR]
545         orr r1, r1, #0x60000
546         str r1, [r0, #SRC_SSCR]
547         ldr r0, CRM_AP_BASE_ADDR_W
548         /* Default CKOH as AP_CLK with div by 10 */
549         //orr r1, r1, #0x5600 /* HCLK */
550         ldr r1, [r0, #CRM_AP_ACR]
551         bic r1, r1, #0xFF00
552         bic r1, r1, #0x00FF
553         orr r1, r1, #0x02C0
554         str r1, [r0, #CRM_AP_ACR]
555
556         /*Dividers setup */
557         mov r1, #0x030
558         str r1, [r0, #CRM_AP_ACDR]      /* ARM core=266MHz, AHB=66.5MHz, IP=66.5MHz */
559         mov r1, #0xB
560         str r1, [r0, #CRM_AP_ASCSR]     /* Select USB PLL for CS CLK */
561         ldr r1, =0x1
562         str r1, [r0, #CRM_AP_ACSR]      /* select DPLL for AP domain at new freq */
563         ldr r1, CRM_AP_ACDER_W
564         str r1, [r0, #CRM_AP_ACDER]     /* set nfc_div=5 (5+1 actual divider)  */
565         mov r1, #0x6
566         str r1, [r0, #CRM_AP_ACGCR]     /* restore default */
567         mov r1, #0x5
568         str r1, [r0, #CRM_AP_ARCGR]    /* restore default */
569
570         /*
571         * Only when NOT directly booting from SDRAM:
572         * ARM core=266MHz, AHB=133MHz, IP=66.5MHz.
573         * This is to work around the booting problem with RVD on EVB only.
574         * Brassboard is fine.
575         */
576         ldr r0, CRM_AP_BASE_ADDR_W
577         mov r1, #0x011
578         str r1, [r0, #CRM_AP_ACDR]
579
580         // SD clock input select - usb_clk. divider changed to 1
581         mov r1, #0x00000140
582         add r1, r1, #0x00000002
583         str r1, [r0, #CRM_AP_APR]
584     .endm /* init_clock */
585
586     /* M3IF setup */
587     .macro init_m3if
588         /* Configure M3IF registers */
589         ldr r1, M3IF_BASE_W
590         /*
591         * M3IF Control Register (M3IFCTL)
592         * MRRP[0] = TMAX not on priority list (0 << 0)        = 0x00000000
593         * MRRP[1] = SMIF not on priority list (0 << 0)        = 0x00000000
594         * MRRP[2] = MAX0 not on priority list (0 << 0)        = 0x00000000
595         * MRRP[3] = MAX1 not on priority list (0 << 0)        = 0x00000000
596         * MRRP[4] = SDMA not on priority list (0 << 0)        = 0x00000000
597         * MRRP[5] = MPEG4 not on priority list (0 << 0)       = 0x00000000
598         * MRRP[6] = IPU on priority list (1 << 6)             = 0x00000040
599         * MRRP[7] = SMIF-L2CC not on priority list (0 << 0)   = 0x00000000
600         *                                                       ------------
601         *                                                       0x00000040
602         */
603         ldr r0, =0x00000040
604         str r0, [r1]  /* M3IF control reg */
605     .endm /* init_m3if */
606
607     /* CS0 sync mode setup */
608     .macro init_cs0_sync
609         /*
610          * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
611          */
612         /* Flash reset command */
613         ldr     r0, =CS0_BASE_ADDR
614         ldr     r1, =0xF0F0
615         strh    r1, [r0]
616         /* 1st command */
617         ldr     r2, =0xAAA
618         add     r2, r2, r0
619         ldr     r1, =0xAAAA
620         strh    r1, [r2]
621         /* 2nd command */
622         ldr     r2, =0x554
623         add     r2, r2, r0
624         ldr     r1, =0x5555
625         strh    r1, [r2]
626         /* 3rd command */
627         ldr     r2, =0xAAA
628         add     r2, r2, r0
629         ldr     r1, =0xD0D0
630         strh    r1, [r2]
631         /* Write flash config register */
632         ldr     r1, =0x56CA
633         strh    r1, [r2]
634         /* Flash reset command */
635         ldr     r1, =0xF0F0
636         strh    r1, [r0]
637
638         ldr r0, =WEIM_BASE_ADDR
639         ldr r1, =0x23524E80
640         str r1, [r0, #CSCRU]
641         ldr r1, =0x10000D03
642         str r1, [r0, #CSCRL]
643         ldr r1, =0x00720900
644         str r1, [r0, #CSCRA]
645     .endm /* init_cs0_sync */
646
647     /* CS0 async mode setup */
648     .macro init_cs0_async
649         /* Async flash mode */
650         ldr r0, =WEIM_CTRL_CS0
651         ldr r1, WEIM_CSCRU_0x0000CC03
652         str r1, [r0, #CSCRU]
653         ldr r1, WEIM_CSCRL_0xA0330D01
654         str r1, [r0, #CSCRL]
655         ldr r1, WEIM_CSCRA_0x00220800
656         str r1, [r0, #CSCRA]
657     .endm /* init_cs0_async */
658
659     /* CPLD on CS4 setup */
660     .macro init_cs4
661         ldr r0, =WEIM_CTRL_CS4
662         ldr r1, =0x0000D743
663         str r1, [r0, #CSCRU]
664         ldr r1, =0x42001521
665         str r1, [r0, #CSCRL]
666         ldr r1, =0x00430A00
667         str r1, [r0, #CSCRA]
668
669         ldr r0, CS4_BASE_ADDR_W
670         ldrh r1, [r0, #0x0]
671         and r0, r1, #0xFF00
672         cmp r0, #0x2000
673         bge done_cs4_setup
674
675         ldr r0, =WEIM_CTRL_CS4
676         ldr r1, =0x0000DCF6
677         str r1, [r0, #CSCRU]
678         ldr r1, =0x444A4541
679         str r1, [r0, #CSCRL]
680         ldr r1, =0x44443302
681         str r1, [r0, #CSCRA]
682
683 done_cs4_setup:
684
685     .endm /* init_cs4 */
686
687 // DDR SDRAM setup
688     .macro  init_ddr_sdram
689         ldr r0, ESDCTL_BASE_W
690         /*
691          * Configure Enhanced SDRAM Miscellaneous Register (ESDMISC) Register
692          * Set to DDR Mode (Not SDR), Do a delay line reset
693          * as the EMI AHB clock was changed
694          */
695         mov r1, #0xC            // set ESDMISC reg
696         str r1, [r0, #0x10]
697         // Hold for more than 200ns
698         mov r1, #0x10000
699     1:
700         subs r1, r1, #0x1
701         bne 1b
702
703         /*
704          * Configure Enhanced SDRAM Configuration Register 0
705          *  (ESDCFG0) Register. XP=2 MRD=2 RAS=6 CAS=3 Clocks
706          */
707         ldr r1, SDRAM_0x00395728
708         str r1, [r0, #0x4]
709
710         /*
711          * Precharge all rows (ROW/COL Muxing NOT used outside
712          * NORMAL Mode); MODE=PRECHARGE ALL.
713          */
714         ldr r1, SDRAM_0x92210080
715         str r1, [r0]
716
717         /* PRECHARGE ALL (A10=1). */
718         ldr r1, =0x0
719         mov r12, #0x80000000
720         add r12, r12, #0x00000400
721         str r1, [r12]
722         /* Run two refresh cycles; MODE=AUTO REFRESH */
723         ldr r1, SDRAM_0xA2210080
724         str r1, [r0]
725
726         /* AUTO REFRESH 2 times */
727         ldr r1, =0x0
728         mov r12, #0x80000000
729         str r1, [r12]
730         str r1, [r12]
731
732         /*
733          * Configure DDRAM Operating mode to Load Mode
734          * Register Command; MODE=LOAD MODE REGISTER.
735          */
736         ldr r1, SDRAM_0xB2210080
737         str r1, [r0]
738
739         /* LOAD MODE */
740         ldr r1, =0x0
741         mov r12, #0x80000000
742         add r12, r12, #0x00000033
743         strb r1, [r12]
744
745         /* Load Extended Mode register */
746         mov r12, #0x81000000
747         strb r1, [r12]
748
749         /*
750          * Put controller in Normal mode. SDRAM now ready for
751          * accesses; Configure CSD0 ESDCTL0 and go into Normal
752          * Read/Write Mode; 16-bit[D0..D15];  BL=8; row=13;
753          * col=10; MODE=Normal
754          */
755         ldr r1, SDRAM_0x82216080
756         str r1, [r0]
757
758         /* Dummy Write */
759         ldr r1, =0x0
760         mov r12, #0x80000000
761         strb r1, [r12]
762
763         /* Dummy write into DDRAM */
764         ldr r1, SDRAM_0xC001C001
765         mov r12, #0x80000000
766         strb r1, [r12]
767
768         /* Dummy Read From DDRAM */
769         ldr r1, SDRAM_BASE_ADDR_W
770
771         /* DISABLE CSD1 */
772         ldr r1, =0x0
773         str r1, [r0, #0x8]
774     .endm
775
776 // SDR SDRAM setup
777     /* r3 = value for ESDCTL0
778      * r4 = burst mode vs full-page mode */
779     .macro  init_sdr_sdram
780         ldr r0, ESDCTL_BASE_W
781         mov r2, #SDRAM_BASE_ADDR
782         ldr r1, SDRAM_0x0075E73A
783         str r1, [r0, #0x4]
784         ldr r1, =0x2            // reset
785         str r1, [r0, #0x10]
786         ldr r1, =0x0            // sdr
787         str r1, [r0, #0x10]
788
789         // Hold for more than 200ns
790         ldr r1, =0x10000
791 1:
792         subs r1, r1, #0x1
793         bne 1b
794
795         ldr r1, SDRAM_0x92126080
796         str r1, [r0]
797         ldr r1, =0x0
798         mov r12, #0x80000000
799         add r12, r12, #0x00000400
800         str r1, [r12]
801         ldr r1, SDRAM_0xA2126080
802         str r1, [r0]
803
804         ldr r1, =0x0
805         str r1, [r2]
806         str r1, [r2]
807
808         ldr r1, SDRAM_0xB2126180
809         str r1, [r0]
810
811         ldr r1, =0x0
812         strb r1, [r2, r4]
813         mov r12, #0x81000000
814         str r1, [r12]
815         str r3, [r0]
816         ldr r1, =0x0
817         str r1, [r2]
818     .endm
819
820     .macro do_wait_op_done
821     1:
822         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
823         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
824         beq 1b
825         mov r3, #0x0
826         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
827     .endm   // do_wait_op_done
828
829     .macro do_addr_input
830         and r3, r3, #0xFF
831         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
832         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
833         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
834         do_wait_op_done
835     .endm   // do_addr_input
836
837     /* Required for MXC91221 PASS 2 for 133MHz SDR */
838     .macro  init_drive_strength_sdr
839         ldr r0, IOMUX_COM_BASE_ADDR_W
840         add r0, r0, #0x200
841         ldr r1, =0x0082
842         strh r1, [r0, #0x0]
843         ldr r1, =0x0002
844         strh r1, [r0, #0x2]
845         ldr r1, =0x0108
846         strh r1, [r0, #0x4]
847         ldr r1, =0x0103
848         strh r1, [r0, #0x8]
849         ldr r1, =0x01C3
850         strh r1, [r0, #0xA]
851         ldr r1, =0x0183
852         strh r1, [r0, #0xC]
853     .endm
854
855     /* Required for DDR */
856     .macro  init_drive_strength_ddr
857         ldr r0, IOMUX_COM_BASE_ADDR_W
858         add r0, r0, #0x200
859         ldr r1, =0x0082
860         strh r1, [r0, #0x0]
861         ldr r1, =0x0012
862         strh r1, [r0, #0x2]
863         ldr r1, =0x0112
864         strh r1, [r0, #0x4]
865         ldr r1, =0x012
866         strh r1, [r0, #0x6]
867         ldr r1, =0x0103
868         strh r1, [r0, #0x8]
869         ldr r1, =0x0587
870         strh r1, [r0, #0xA]
871         ldr r1, =0x0187
872         strh r1, [r0, #0xC]
873         ldr r1, =0x0107
874         strh r1, [r0, #0xE]
875     .endm
876
877 #define PLATFORM_VECTORS         _platform_vectors
878     .macro  _platform_vectors
879         .globl  _board_BCR, _board_CFG
880 _board_BCR:   .long   0       // Board Control register shadow
881 _board_CFG:   .long   0       // Board Configuration (read at RESET)
882     .endm
883
884 L2CACHE_PARAM:          .word   0x00030024
885 IIM_SREV_REG_VAL:       .word   IIM_BASE_ADDR + IIM_SREV_OFF
886 AIPS1_CTRL_BASE_ADDR_W: .word   AIPS1_CTRL_BASE_ADDR
887 AIPS2_CTRL_BASE_ADDR_W: .word   AIPS2_CTRL_BASE_ADDR
888 CS4_BASE_ADDR_W:        .word   CS4_BASE_ADDR
889 AIPS1_PARAM_W:          .word   0x77777777
890 MAX_BASE_ADDR_W:        .word   MAX_BASE_ADDR
891 MAX_PARAM1:             .word   0x00000321
892 RVAL_WVAL_W:            .word   0x515
893 CLKCTL_BASE_ADDR_W:     .word   CLKCTL_BASE_ADDR
894 PLL0_BASE_ADDR_W:       .word   PLL0_BASE_ADDR
895 CRM_AP_BASE_ADDR_W:     .word   CRM_AP_BASE_ADDR
896 SRC_BASE_ADDR_W:        .word   SRC_BASE_ADDR
897 IOMUX_COM_BASE_ADDR_W:  .word   IOMUX_COM_BASE_ADDR
898 PLL2_BASE_ADDR_W:       .word   PLL2_BASE_ADDR
899 SPBA_CTRL_BASE_ADDR_W:  .word   SPBA_CTRL_BASE_ADDR
900 WEIM_CSCRU_0x0000CC03:  .word   0x0000CC03
901 WEIM_CSCRL_0xA0330D01:  .word   0xA0330D01
902 WEIM_CSCRA_0x00220800:  .word   0x00220800
903 ESDCTL_BASE_W:          .word   ESDCTL_BASE
904 SDRAM_BASE_ADDR_W:      .word   SDRAM_BASE_ADDR
905 M3IF_BASE_W:            .word   M3IF_BASE
906 CRM_AP_ACDER_W:         .word   0x59155912
907 SDRAM_0x92126080:       .word   0x92126080
908 SDRAM_0xA2126080:       .word   0xA2126080
909 SDRAM_0xB2126180:       .word   0xB2126180
910 SDRAM_0x0075E73A:       .word   0x0075E73A
911 SDRAM_0x00395728:       .word   0x00395728
912 SDRAM_0x92210080:       .word   0x92210080
913 SDRAM_0xA2210080:       .word   0xA2210080
914 SDRAM_0xB2210080:       .word   0xB2210080
915 SDRAM_0x82216080:       .word   0x82216080
916 SDRAM_0xC001C001:       .word   0xC001C001
917 SDRAM_COMPARE_CONST1:   .word   0x55555555
918 SDRAM_COMPARE_CONST2:   .word   0xAAAAAAAA
919 MXC_REDBOOT_ROM_START:  .word   SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
920 CONST_0x0FFF:           .word   0x0FFF
921 AVIC_VECTOR0_ADDR_W:    .word   MXCBOOT_FLAG_REG
922 AVIC_VECTOR1_ADDR_W:    .word   MXCFIS_FLAG_REG
923
924 /*---------------------------------------------------------------------------*/
925 /* end of hal_platform_setup.h                                               */
926 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */