1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
4 //=============================================================================
6 // hal_platform_setup.h
8 // Platform specific support for HAL (assembly code)
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.
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.
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
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.
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.
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.
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 //===========================================================================
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
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
56 #ifdef CYG_HAL_STARTUP_ROMRAM
57 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
60 #define SDRAM_BURST_MODE 0x33
62 #define CYGHWR_HAL_ROM_VADDR 0x0
65 #define UNALIGNED_ACCESS_ENABLE
66 #define SET_T_BIT_DISABLE
67 #define BRANCH_PREDICTION_ENABLE
70 //#define TURN_OFF_IMPRECISE_ABORT
72 // This macro represents the initial startup code for the platform
73 // r11 is reserved to contain chip rev info in this file
74 .macro _platform_setup1
75 FSL_BOARD_SETUP_START:
78 * - invalidate I/D cache/TLB and drain write buffer;
80 * - branch predictions
82 #ifdef TURN_OFF_IMPRECISE_ABORT
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 */
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
109 init_cs0_async_start:
112 /* If SDRAM has been setup, bypass clock/WEIM setup */
113 cmp pc, #SDRAM_BASE_ADDR
115 cmp pc, #(SDRAM_BASE_ADDR + SDRAM_SIZE)
116 blo HWInitialise_skip_SDRAM_setup
118 mov r0, #NOR_FLASH_BOOT
119 ldr r1, AVIC_VECTOR0_ADDR_W
126 mov r4, #SDRAM_BURST_MODE
130 /* Assuming DDR memory first */
132 /* Testing if it is truly DDR */
133 ldr r1, SDRAM_COMPARE_CONST1
134 mov r0, #SDRAM_BASE_ADDR
136 ldr r2, SDRAM_COMPARE_CONST2
140 beq HWInitialise_skip_SDRAM_setup
142 /* Reach here ONLY when SDR */
143 ldr r3, SDRAM_SDR_X32_W /* 32 bit memory */
144 add r3, r3, r10 /* adjust for full-page mode if necessary */
146 /* Test to make sure SDR */
147 ldr r1, SDRAM_COMPARE_CONST1
148 mov r0, #SDRAM_BASE_ADDR
150 ldr r2, SDRAM_COMPARE_CONST2
154 beq HWInitialise_skip_SDRAM_setup
156 ldr r3, SDRAM_SDR_X16_W /* 16 bit memory */
157 add r3, r3, r10 /* adjust for full-page mode if necessary */
159 /* Test to make sure SDR */
160 ldr r1, SDRAM_COMPARE_CONST1
161 mov r0, #SDRAM_BASE_ADDR
163 ldr r2, SDRAM_COMPARE_CONST2
167 beq HWInitialise_skip_SDRAM_setup
169 /* Reach hear means memory setup problem. Try to
170 * increase the HCLK divider */
171 ldr r0, CRM_MCU_BASE_ADDR_W
172 ldr r1, [r0, #CLKCTL_PDR0]
177 str r1, [r0, #CLKCTL_PDR0]
181 b loop_forever /* shouldn't get here */
183 HWInitialise_skip_SDRAM_setup:
186 add r2, r0, #0x800 // 2K window
188 blo Normal_Boot_Continue
190 bhi Normal_Boot_Continue
192 /* Copy image from flash to SDRAM first */
193 ldr r1, MXC_REDBOOT_ROM_START
195 1: ldmia r0!, {r3-r10}
201 and r0, pc, r1 /* offset of pc */
202 ldr r1, MXC_REDBOOT_ROM_START
210 mov r0, #NAND_FLASH_BOOT
211 ldr r1, AVIC_VECTOR0_ADDR_W
214 ldr r1, AVIC_VECTOR1_ADDR_W
217 mov r0, #NFC_BASE; //r0: nfc base. Reloaded after each page copying
218 mov r1, #0x800 //r1: starting flash addr to be copied. Updated constantly
219 add r2, r0, #0x200 //r2: end of 1st RAM buf. Doesn't change
220 add r12, r0, #0xE00 //r12: NFC register base. Doesn't change
221 ldr r14, MXC_REDBOOT_ROM_START
222 add r13, r14, #REDBOOT_IMAGE_SIZE //r13: end of SDRAM address for copying. Doesn't change
223 add r14, r14, r1 //r14: starting SDRAM address for copying. Updated constantly
225 //unlock internal buffer
230 // writew(FLASH_Read_Mode1, NAND_FLASH_CMD_REG);
232 strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
233 mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
234 strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
237 // start_nfc_addr_ops(ADDRESS_INPUT_READ_PAGE, addr, nflash_dev_info->base_mask);
239 do_addr_input //1st addr cycle
241 do_addr_input //2nd addr cycle
243 do_addr_input //3rd addr cycle
245 // NFC_DATA_OUTPUT(buf, FDO_PAGE_SPARE_VAL);
246 // writew(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN,
247 // NAND_FLASH_CONFIG1_REG);
248 mov r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
249 strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
251 // writew(buf_no, RAM_BUFFER_ADDRESS_REG);
253 strh r3, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
254 // writew(FDO_PAGE_SPARE_VAL & 0xFF, NAND_FLASH_CONFIG2_REG);
255 mov r3, #FDO_PAGE_SPARE_VAL
256 strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
260 // check for bad block
261 mov r3, r1, lsl #(32-5-9)
262 cmp r3, #(512 << (32-5-9))
264 add r4, r0, #0x800 //r3 -> spare area buf 0
269 // really sucks. Bad block!!!!
272 // even suckier since we already read the first page!
273 sub r14, r14, #512 //rewind 1 page for the sdram pointer
274 sub r1, r1, #512 //rewind 1 page for the flash pointer
276 add r1, r1, #(32*512)
280 1: ldmia r0!, {r3-r10}
285 bge NAND_Copy_Main_done
292 Normal_Boot_Continue:
297 #ifdef CYG_HAL_STARTUP_ROMRAM /* enable running from RAM */
298 /* Copy image from flash to SDRAM first */
301 ldr r1, MXC_REDBOOT_ROM_START
303 beq HWInitialise_skip_SDRAM_copy
305 add r2, r0, #REDBOOT_IMAGE_SIZE
307 1: ldmia r0!, {r3-r10}
313 and r0, pc, r1 /* offset of pc */
314 ldr r1, =(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000 + 0x8)
320 #endif /* CYG_HAL_STARTUP_ROMRAM */
322 HWInitialise_skip_SDRAM_copy:
329 * IOMUX/PBC setup is done in C function plf_hardware_init() for simplicity
333 // Set up a stack [for calling C code]
334 ldr r1, =__startup_stack
335 ldr r2, =RAM_BANK0_BASE
343 mrc MMU_CP, 0, r1, MMU_Control, c0 // get c1 value to r1 first
344 orr r1, r1, #7 // enable MMU bit
345 mcr MMU_CP, 0, r1, MMU_Control, c0
346 mov pc,r2 /* Change address spaces */
352 // Save shadow copy of BCR, also hardware configuration
356 str r9, [r1] // Saved far above...
358 .endm // _platform_setup1
360 #else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
361 #define PLATFORM_SETUP1
364 /* Allow all 3 masters to have access to these shared peripherals */
366 ldr r0, SPBA_CTRL_BASE_ADDR_W
368 ldr r1, =0x7 /* allow all 3 masters access */
369 ldr r2, SPBA_LOCK_VAL
379 .endm /* init_spba */
381 /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
384 * Set all MPROTx to be non-bufferable, trusted for R/W,
385 * not forced to user-mode.
387 ldr r0, AIPS1_CTRL_BASE_ADDR_W
388 ldr r1, AIPS1_PARAM_W
391 ldr r0, AIPS2_CTRL_BASE_ADDR_W
396 * Clear the on and off peripheral modules Supervisor Protect bit
397 * for SDMA to access them. Did not change the AIPS control registers
398 * (offset 0x20) access type
400 ldr r0, AIPS1_CTRL_BASE_ADDR_W
407 and r1, r1, #0x00FFFFFF
410 ldr r0, AIPS2_CTRL_BASE_ADDR_W
417 and r1, r1, #0x00FFFFFF
419 .endm /* init_aips */
421 /* MAX (Multi-Layer AHB Crossbar Switch) setup */
423 ldr r0, MAX_BASE_ADDR_W
424 /* MPR - priority is M3 > M2 > M0 > M1 */
426 str r1, [r0, #0x000] /* for S0 */
427 str r1, [r0, #0x100] /* for S1 */
428 str r1, [r0, #0x200] /* for S2 */
429 str r1, [r0, #0x300] /* for S3 */
430 str r1, [r0, #0x400] /* for S4 */
431 /* SGPCR - always park on last master */
433 str r1, [r0, #0x010] /* for S0 */
434 str r1, [r0, #0x110] /* for S1 */
435 str r1, [r0, #0x210] /* for S2 */
436 str r1, [r0, #0x310] /* for S3 */
437 str r1, [r0, #0x410] /* for S4 */
438 /* MGPCR - restore default values */
440 str r1, [r0, #0x800] /* for M0 */
441 str r1, [r0, #0x900] /* for M1 */
442 str r1, [r0, #0xA00] /* for M2 */
443 str r1, [r0, #0xB00] /* for M3 */
450 * - These are the targeted speed settings (may not be true for now).
451 * Note: the default USBPLL seems to be 286MHz instead of 288MHz?
453 Module Freq (MHz) Note
454 =========================================================================
455 ARM core 266 ipg_clk_arm
456 AHB 133 known as "hclk", ipg_clk_max
457 IP 66.5 ipg_clk (also used as ipg_per_clk ???)
460 ldr r0, CRM_MCU_BASE_ADDR_W
462 // enable MPLL, UPLL, TurboPLL
463 ldr r1, CRM_MCR_0x18FF2952
464 str r1, [r0, #CLKCTL_MCR]
466 ldr r1, [r0, #CLKCTL_MCR]
472 * J10 (CPU card) - CKO1=MCU_PLL div by 8
473 * J9 (CPU card) - CKO2=IPG_CLK_ARM div by 8
475 ldr r1, CRM_COSR_0x00036C58
476 str r1, [r0, #CLKCTL_COSR]
478 #if 1 // for 60MHz HCLK
479 ldr r1, TPCTL_PARAM_399_W
480 str r1, [r0, #CLKCTL_TPCTL]
481 ldr r1, PDR0_266_133_66_W
483 ldr r1, TPCTL_PARAM_360_W
484 str r1, [r0, #CLKCTL_TPCTL]
485 // add some delay here
490 ldr r1, PDR0_266_66_66_W
492 str r1, [r0, #CLKCTL_PDR0]
493 ldr r1, MPCTL_PARAM_266_W
494 str r1, [r0, #CLKCTL_MPCTL]
496 /* Set to default values */
497 ldr r1, PDR1_0x19D0A456_W
498 str r1, [r0, #CLKCTL_PDR1]
499 /* Set UPLL=240MHz */
500 ldr r1, UPCTL_PARAM_240_W
501 str r1, [r0, #CLKCTL_UPCTL]
502 .endm /* init_clock */
506 /* Configure M3IF registers */
509 * M3IF Control Register (M3IFCTL)
510 * MRRP[0] = USB-OTG not on priority list (0 << 0) = 0x00000000
511 * MRRP[1] = SMIF not on priority list (0 << 0) = 0x00000000
512 * MRRP[2] = MAX0 not on priority list (0 << 0) = 0x00000000
513 * MRRP[3] = MAX1 not on priority list (0 << 0) = 0x00000000
514 * MRRP[4] = SDMA not on priority list (0 << 0) = 0x00000000
515 * MRRP[5] = RTIC v2 not on priority list (0 << 0) = 0x00000000
516 * MRRP[6] = SCMFBC on priority list (1 << 6) = 0x00000040
521 str r0, [r1] /* M3IF control reg */
522 .endm /* init_m3if */
524 /* CS0 sync mode setup */
527 * Sync mode (AHB Clk = 133MHz ; BCLK = 44.3MHz):
529 /* Flash reset command */
530 mov r0, #CS0_BASE_ADDR
548 /* Write flash config register */
551 /* Flash reset command */
555 ldr r0, WEIM_CTRL_CS0_W
562 .endm /* init_cs0_sync */
564 /* CS0 async mode setup */
565 .macro init_cs0_async
566 /* Async flash mode */
567 ldr r0, WEIM_CTRL_CS0_W
568 ldr r1, CS0_CSCRU_0x11414C80
570 ldr r1, CS0_CSCRL_0x30000D03
572 ldr r1, CS0_CSCRA_0x00310800
574 .endm /* init_cs0_async */
576 /* CPLD on CS4 setup */
579 ldr r0, =WEIM_CTRL_CS4
587 ldr r0, CS4_BASE_ADDR_W
593 ldr r0, =WEIM_CTRL_CS4
606 * r4 = burst mode vs full-page mode */
607 .macro init_ddr_sdram
608 ldr r3, SDRAM_0x82216080 /* 16 bit memory */
609 ldr r0, ESDCTL_BASE_W
610 mov r2, #SDRAM_BASE_ADDR
611 ldr r1, SDRAM_0x0079E73A
613 mov r1, #0x2 // reset
618 // Hold for more than 200ns
624 add r1, r3, #0x10000000
630 add r1, r3, #0x20000000 // 0xA2216080
637 add r1, r3, #0x30000000 // 0xB2216080
641 add r12, r2, #0x01000000
649 /* r3 = value for ESDCTL0
650 * r4 = burst mode vs full-page mode */
651 .macro init_sdr_sdram
652 ldr r0, ESDCTL_BASE_W
653 mov r2, #SDRAM_BASE_ADDR
654 ldr r1, SDRAM_0x0075E73A
656 ldr r1, =0x2 // reset
661 // Hold for more than 200ns
667 ldr r1, SDRAM_0x92126080
671 add r12, r12, #0x00000400
673 ldr r1, SDRAM_0xA2126080
680 ldr r1, SDRAM_0xB2126180
692 .macro do_wait_op_done
694 ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
695 ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
698 strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
699 .endm // do_wait_op_done
703 strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
704 mov r3, #NAND_FLASH_CONFIG2_FADD_EN
705 strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
707 .endm // do_addr_input
709 /* To support 133MHz SDR */
710 .macro init_drive_strength
711 // max drive strength for all pads except SDQS0/1
713 ldr r0, IOMUXC_BASE_ADDR_W
715 //=========== set_drive_strenght_ctl_signals =======================
720 /* SDRAM DQM0 lines */
724 //============= set_drive_strength_ctl_data ========================
725 /* SDRAM SD0-SD15 data lines sw_pad_ctl_sd0_sd1_sd2 */
729 //============= set_drive_strength_ctl_addr ========================
730 /* SDRAM address lines sw_pad_ctl_a0_ma0_a1_ma1_a2_ma2 */
738 /* sw_pad_ctl_SDCLK */
742 /* for SDRAM SDQS0 lines */
750 .endm /* init_drive_strength */
754 * Deal with DSP reset
760 beq skip_dsp_switch_le
761 bic r1, r1, #(1 << 5)
765 /* Put DSP in reset */
769 /* Hold for some time */
775 /* Put DSP out of reset */
779 #define PLATFORM_VECTORS _platform_vectors
780 .macro _platform_vectors
781 .globl _board_BCR, _board_CFG
782 _board_BCR: .long 0 // Board Control register shadow
783 _board_CFG: .long 0 // Board Configuration (read at RESET)
786 #define PLATFORM_PREAMBLE _switch_to_le
789 .word 0xEE110F10 // mrc 15, 0, r0, c1, c0, 0
790 .word 0xE3C00080 // bic r0, r0, #0x80
791 .word 0xEE010F10 // mcr 15, 0, r0, c1, c0, 0
793 .word 0x0F10EE11 // mrc 15, 0, r0, c1, c0, 0
794 .word 0x0080E3C0 // bic r0, r0, #0x80
795 .word 0x0F10EE01 // mcr 15, 0, r0, c1, c0, 0
808 IIM_SREV_REG_VAL: .word IIM_BASE_ADDR + IIM_SREV_OFF
809 AIPS1_CTRL_BASE_ADDR_W: .word AIPS1_CTRL_BASE_ADDR
810 AIPS2_CTRL_BASE_ADDR_W: .word AIPS2_CTRL_BASE_ADDR
811 CS4_BASE_ADDR_W: .word CS4_BASE_ADDR
812 AIPS1_PARAM_W: .word 0x77777777
813 MAX_BASE_ADDR_W: .word MAX_BASE_ADDR
814 MAX_PARAM1: .word 0x00000132
815 RVAL_WVAL_W: .word 0x515
816 CLKCTL_BASE_ADDR_W: .word CLKCTL_BASE_ADDR
817 CRM_MCR_0x18FF2902: .word 0x18FF2902
818 CRM_MCR_0x18FF2952: .word 0x18FF2952
819 CRM_COSR_0x00036C58: .word 0x00036C58
820 PDR0_240_120_60_W: .word PDR0_240_120_60
821 PDR0_266_66_66_W: .word PDR0_266_66_66
822 PDR0_266_133_66_W: .word PDR0_266_133_66
823 PDR0_240_60_60_W: .word PDR0_240_60_60
824 PDR1_0x19D0A456_W: .word 0x19D0A456
825 MPCTL_PARAM_240_W: .word MPCTL_PARAM_240
826 MPCTL_PARAM_266_W: .word MPCTL_PARAM_266
827 UPCTL_PARAM_240_W: .word UPCTL_PARAM_240
828 TPCTL_PARAM_360_W: .word TPCTL_PARAM_360
829 TPCTL_PARAM_399_W: .word TPCTL_PARAM_399
830 SPBA_CTRL_BASE_ADDR_W: .word SPBA_CTRL_BASE_ADDR
831 SPBA_LOCK_VAL: .word 0xC0010007
832 ESDCTL_BASE_W: .word ESDCTL_BASE
833 M3IF_BASE_W: .word M3IF_BASE
834 SDRAM_DDR_X32_W: .word 0x82226080
835 SDRAM_0x82216080: .word 0x82216080
836 SDRAM_SDR_X32_W: .word 0x82126080
837 SDRAM_SDR_X16_W: .word 0x82116080
838 SDRAM_0x92126080: .word 0x92126080
839 SDRAM_0xA2126080: .word 0xA2126080
840 SDRAM_0xB2126180: .word 0xB2126180
841 SDRAM_0x0075E73A: .word 0x0075E73A
842 SDRAM_0x0079E73A: .word 0x0079E73A
843 SDRAM_0x92100000: .word 0x92100000
844 SDRAM_0xA2100000: .word 0xA2100000
845 SDRAM_0xB2100000: .word 0xB2100000
846 SDRAM_0x12344321: .word 0x12344321
847 SDRAM_COMPARE_CONST1: .word 0x55555555
848 SDRAM_COMPARE_CONST2: .word 0xAAAAAAAA
849 WEIM_CTRL_CS0_W: .word WEIM_CTRL_CS0
850 CS0_CSCRU_0x11414C80: .word 0x11414C80
851 CS0_CSCRL_0x30000D03: .word 0x30000D03
852 CS0_CSCRA_0x00310800: .word 0x00310800
853 IOMUXC_BASE_ADDR_W: .word IOMUXC_BASE_ADDR
854 CRM_MCU_BASE_ADDR_W: .word CRM_MCU_BASE_ADDR
855 MXC_REDBOOT_ROM_START: .word SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000
856 CONST_0x0FFF: .word 0x0FFF
857 AVIC_VECTOR0_ADDR_W: .word MXCBOOT_FLAG_REG
858 AVIC_VECTOR1_ADDR_W: .word MXCFIS_FLAG_REG
860 /*---------------------------------------------------------------------------*/
861 /* end of hal_platform_setup.h */
862 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */