]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/coldfire/m5272c3/v2_0/src/plf_startup.c
Initial revision
[karo-tx-redboot.git] / packages / hal / coldfire / m5272c3 / v2_0 / src / plf_startup.c
1 //==========================================================================
2 //
3 //      plf_startup.c
4 //
5 //      M5272C3 platform HAL startup code
6 //
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.
13 //
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.
17 //
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
21 // for more details.
22 //
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.
26 //
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.
33 //
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####
40 //
41 // Author(s):     Enrico Piria
42 // Contributors:
43 // Date:          2005-25-06
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
48 //                to work properly.
49 //
50 //####DESCRIPTIONEND####
51 //========================================================================
52
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>
60
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")));
66
67
68 // Platform-specific reset vector initialization routine
69 void plf_reset(void)
70 {
71     plf_init_sim();
72     plf_init_intc();
73     plf_init_cs();
74     plf_init_sdramc();
75
76     // Call a routine to set  up  the  cache  and  ACRs  for  this  specific
77     // platform.
78     plf_init_cache_acr();
79 }
80
81
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)
86 {
87     // Enable the instruction cache with the following options:
88     // Enable CPUSHL invalidation.
89     // No freeze.
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.
97
98 #ifdef CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP
99     CYGARC_MOVEC((CYG_WORD32) 0x81000102, CYGARC_REG_CACR);
100 #endif
101
102     // Leave the access control registers disabled.
103 }
104
105
106 // Initialize SIM module and system configuration registers
107 void plf_init_sim(void)
108 {
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);
112     
113     // Initialize System Config Register
114     // Setup Watch Dog Timeout
115     HAL_WRITE_UINT16(&MCF5272_DEVS->cfg.scr, MCF5272_SIM_SCR_HWWD_1024);
116         
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
128         )) ;
129 }
130
131
132 // Initialize interrupt controller
133 void plf_init_intc(void)
134 {
135     int i;
136
137     // Initialize the vector base register in the interrupt controller.
138     HAL_WRITE_UINT8(&MCF5272_DEVS->intc.ipvr, HAL_PROG_INT_VEC_BASE);
139
140     // Initialize the  interrupt  control  register.
141     // Disable all interrupts by setting all priorities to zero.
142     for (i = 0; i < 4; i++)
143     {
144         HAL_WRITE_UINT32(&MCF5272_DEVS->intc.icr[i], 0x88888888);
145     }
146
147     // Initialize the processor's vector base register (align to 1M boundary).
148     CYGARC_MOVEC((CYG_WORD32) __ramvec_start & 0xFFF00000, CYGARC_REG_VBR);
149 }
150
151
152 // Initialize chip-select modules
153 void plf_init_cs(void)
154 {
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)
163         | MCF5272_CS_BR_SRAM
164         | MCF5272_CS_BR_PS_16
165         | MCF5272_CS_BR_EN));    
166
167     HAL_WRITE_UINT32(&MCF5272_DEVS->cs[0].csor,
168         (0 | MCF5272_CS_OR_MASK_2M
169         | MCF5272_CS_OR_WS(5)));
170
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)
175         | MCF5272_CS_BR_SRAM
176         | MCF5272_CS_BR_PS_32
177         | MCF5272_CS_BR_EN));
178
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
183
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));
190
191     HAL_WRITE_UINT32(&MCF5272_DEVS->cs[7].csor, (0
192 #if (CYGHWR_INSTALLED_SDRAM_SIZE == 4)
193         | MCF5272_CS_OR_MASK_4M
194 #else
195         | MCF5272_CS_OR_MASK_16M
196 #endif
197         | MCF5272_CS_OR_WS(0x1F)));
198 }
199
200
201 // Initialize SDRAM controller
202 void plf_init_sdramc(void)
203 {
204     cyg_uint16 sdcr;
205
206     
207     HAL_READ_UINT16(&MCF5272_DEVS->sdramc.sdcr, sdcr);
208     
209     // Do not initialize SDRAM if it is already active
210     if (!(sdcr & MCF5272_SDRAMC_SDCCR_ACT))
211     {
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));
219 #else
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));
227 #endif
228
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
233 #else
234             | MCF5272_SDRAMC_SDCCR_BALOC_A22
235 #endif
236             | MCF5272_SDRAMC_SDCCR_REG
237             | MCF5272_SDRAMC_SDCCR_INIT));
238
239         // Start SDRAM controller with a memory write
240         *((volatile char *) CYGMEM_REGION_sdram) = 0;
241
242         // Wait until controller is ready
243         do
244         {
245             HAL_READ_UINT16(&MCF5272_DEVS->sdramc.sdcr, sdcr);
246         } while(!(sdcr & MCF5272_SDRAMC_SDCCR_ACT));
247     }
248 }
249
250
251 // Platform specific data initialization routine
252 void plf_init_data(void)
253 {
254     // Nothing to do
255 }