1 //==========================================================================
5 // M5272C3 platform HAL startup code
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2006 eCosCentric Ltd.
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //==========================================================================
39 //#####DESCRIPTIONBEGIN####
41 // Author(s): Enrico Piria
44 // Purpose: Platform startup code.
45 // Description: This module contains code that sets up the platform specific
46 // hardware and data. All the code must be contained in the
47 // section called ".boot", in order for the ROMRAM startup
50 //####DESCRIPTIONEND####
51 //========================================================================
53 #include <cyg/infra/cyg_type.h>
54 #include <pkgconf/hal.h>
55 #include <cyg/hal/hal_startup.h>
56 #include CYGHWR_MEMORY_LAYOUT_H
57 #include <cyg/hal/hal_arch.h>
58 #include <cyg/hal/hal_io.h>
59 #include <cyg/hal/coldfire_regs.h>
61 static void plf_init_sim(void) __attribute__ ((section (".boot")));
62 static void plf_init_intc(void) __attribute__ ((section (".boot")));
63 static void plf_init_cs(void) __attribute__ ((section (".boot")));
64 static void plf_init_sdramc(void) __attribute__ ((section (".boot")));
65 static void plf_init_cache_acr(void) __attribute__ ((section (".boot")));
68 // Platform-specific reset vector initialization routine
76 // Call a routine to set up the cache and ACRs for this specific
82 // Initialize the cache and access control registers.
83 // The reset procedure already invalidated the cache and ACRs.
84 // This routine only needs to enable the ACRs that it will use.
85 static void plf_init_cache_acr(void)
87 // Enable the instruction cache with the following options:
88 // Enable CPUSHL invalidation.
90 // Invalidate all cache lines (flush).
91 // No external arbiter control.
92 // Disable non-cacheable instruction bursting.
93 // Default memory is cacheable.
94 // Enable buffered writes.
95 // Read and write access permitted by default.
96 // Instruction fetch size is cache line.
98 #ifdef CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP
99 CYGARC_MOVEC((CYG_WORD32) 0x81000102, CYGARC_REG_CACR);
102 // Leave the access control registers disabled.
106 // Initialize SIM module and system configuration registers
107 void plf_init_sim(void)
109 // Set up the mapping of our internal registers. The LSB indicates that
110 // the register contents are valid.
111 CYGARC_MOVEC((CYG_WORD32)(CYGMEM_REGION_devs | 1), CYGARC_REG_MBAR);
113 // Initialize System Config Register
114 // Setup Watch Dog Timeout
115 HAL_WRITE_UINT16(&MCF5272_DEVS->cfg.scr, MCF5272_SIM_SCR_HWWD_1024);
117 // Initialize System Protection Register
118 // Enable all bus error exceptions
119 HAL_WRITE_UINT16(&MCF5272_DEVS->cfg.spr,
120 (0 | MCF5272_SIM_SPR_ADC | MCF5272_SIM_SPR_ADCEN
121 | MCF5272_SIM_SPR_WPV | MCF5272_SIM_SPR_WPVEN
122 | MCF5272_SIM_SPR_SMV | MCF5272_SIM_SPR_SMVEN
123 | MCF5272_SIM_SPR_SBE | MCF5272_SIM_SPR_SBEEN
124 | MCF5272_SIM_SPR_HWT | MCF5272_SIM_SPR_HWTEN
125 | MCF5272_SIM_SPR_RPV | MCF5272_SIM_SPR_RPVEN
126 | MCF5272_SIM_SPR_EXT | MCF5272_SIM_SPR_EXTEN
127 | MCF5272_SIM_SPR_SUV | MCF5272_SIM_SPR_SUVEN
132 // Initialize interrupt controller
133 void plf_init_intc(void)
137 // Initialize the vector base register in the interrupt controller.
138 HAL_WRITE_UINT8(&MCF5272_DEVS->intc.ipvr, HAL_PROG_INT_VEC_BASE);
140 // Initialize the interrupt control register.
141 // Disable all interrupts by setting all priorities to zero.
142 for (i = 0; i < 4; i++)
144 HAL_WRITE_UINT32(&MCF5272_DEVS->intc.icr[i], 0x88888888);
147 // Initialize the processor's vector base register (align to 1M boundary).
148 CYGARC_MOVEC((CYG_WORD32) __ramvec_start & 0xFFF00000, CYGARC_REG_VBR);
152 // Initialize chip-select modules
153 void plf_init_cs(void)
155 // ChipSelect 0 - 2MB FLASH
156 // At startup, CS0 is configured so that addresses starting at 0xXXX00000
157 // are aliased to 0x00000000, so, in ROM startup configuration, code can
158 // be placed starting at VMA address 0xFFE00000. When we are here,
159 // the PC points to addresses in 0xFFE00000 space, and we can safely
160 // reconfigure CS0 to respond uniquely to those addresses.
161 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[0].csbr, (0
162 | MCF5272_CS_BR_BASE(CYGMEM_REGION_flash)
164 | MCF5272_CS_BR_PS_16
165 | MCF5272_CS_BR_EN));
167 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[0].csor,
168 (0 | MCF5272_CS_OR_MASK_2M
169 | MCF5272_CS_OR_WS(5)));
171 #ifdef CYGHWR_EXT_SRAM_INSTALLED
172 // Chip Select 2 - 512KB SRAM
173 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[2].csbr, (0
174 | MCF5272_CS_BR_BASE(CYGMEM_REGION_ext_sram)
176 | MCF5272_CS_BR_PS_32
177 | MCF5272_CS_BR_EN));
179 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[2].csor, (0
180 | MCF5272_CS_OR_MASK_512K
181 | MCF5272_CS_OR_WS(0)));
182 #endif // CYGHWR_EXT_SRAM_INSTALLED
184 // ChipSelect 7 - 16MB SDRAM
185 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[7].csbr, (0
186 | MCF5272_CS_BR_BASE(CYGMEM_REGION_sdram)
187 | MCF5272_CS_BR_SDRAM
188 | MCF5272_CS_BR_PS_LINE
189 | MCF5272_CS_BR_EN));
191 HAL_WRITE_UINT32(&MCF5272_DEVS->cs[7].csor, (0
192 #if (CYGHWR_INSTALLED_SDRAM_SIZE == 4)
193 | MCF5272_CS_OR_MASK_4M
195 | MCF5272_CS_OR_MASK_16M
197 | MCF5272_CS_OR_WS(0x1F)));
201 // Initialize SDRAM controller
202 void plf_init_sdramc(void)
207 HAL_READ_UINT16(&MCF5272_DEVS->sdramc.sdcr, sdcr);
209 // Do not initialize SDRAM if it is already active
210 if (!(sdcr & MCF5272_SDRAMC_SDCCR_ACT))
212 #if (CYGHWR_HAL_SYSTEM_CLOCK_MHZ == 66)
213 HAL_WRITE_UINT16(&MCF5272_DEVS->sdramc.sdtr, (0
214 | MCF5272_SDRAMC_SDCTR_RTP_66MHz
215 | MCF5272_SDRAMC_SDCTR_RC(0)
216 | MCF5272_SDRAMC_SDCTR_RP(1)
217 | MCF5272_SDRAMC_SDCTR_RCD(1)
218 | MCF5272_SDRAMC_SDCTR_CLT_2));
220 // Clock frequency must be 48 Mhz
221 HAL_WRITE_UINT16(&MCF5272_DEVS->sdramc.sdtr, (0
222 | MCF5272_SDRAMC_SDCTR_RTP_48MHz
223 | MCF5272_SDRAMC_SDCTR_RC(0)
224 | MCF5272_SDRAMC_SDCTR_RP(1)
225 | MCF5272_SDRAMC_SDCTR_RCD(0)
226 | MCF5272_SDRAMC_SDCTR_CLT_2));
229 HAL_WRITE_UINT16(&MCF5272_DEVS->sdramc.sdcr, (0
230 | MCF5272_SDRAMC_SDCCR_MCAS_A9
231 #if (CYGHWR_INSTALLED_SDRAM_SIZE == 4)
232 | MCF5272_SDRAMC_SDCCR_BALOC_A21
234 | MCF5272_SDRAMC_SDCCR_BALOC_A22
236 | MCF5272_SDRAMC_SDCCR_REG
237 | MCF5272_SDRAMC_SDCCR_INIT));
239 // Start SDRAM controller with a memory write
240 *((volatile char *) CYGMEM_REGION_sdram) = 0;
242 // Wait until controller is ready
245 HAL_READ_UINT16(&MCF5272_DEVS->sdramc.sdcr, sdcr);
246 } while(!(sdcr & MCF5272_SDRAMC_SDCCR_ACT));
251 // Platform specific data initialization routine
252 void plf_init_data(void)