1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic mcf548x BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | File: init548x.c | |
---|
5 | +-----------------------------------------------------------------+ |
---|
6 | | The file contains the c part of MCF548x init code | |
---|
7 | +-----------------------------------------------------------------+ |
---|
8 | | Copyright (c) 2007 | |
---|
9 | | Embedded Brains GmbH | |
---|
10 | | Obere Lagerstr. 30 | |
---|
11 | | D-82178 Puchheim | |
---|
12 | | Germany | |
---|
13 | | rtems@embedded-brains.de | |
---|
14 | +-----------------------------------------------------------------+ |
---|
15 | | | |
---|
16 | | Parts of the code has been derived from the "dBUG source code" | |
---|
17 | | package Freescale is providing for M548X EVBs. The usage of | |
---|
18 | | the modified or unmodified code and it's integration into the | |
---|
19 | | generic mcf548x BSP has been done according to the Freescale | |
---|
20 | | license terms. | |
---|
21 | | | |
---|
22 | | The Freescale license terms can be reviewed in the file | |
---|
23 | | | |
---|
24 | | Freescale_license.txt | |
---|
25 | | | |
---|
26 | +-----------------------------------------------------------------+ |
---|
27 | | | |
---|
28 | | The generic mcf548x BSP has been developed on the basic | |
---|
29 | | structures and modules of the av5282 BSP. | |
---|
30 | | | |
---|
31 | +-----------------------------------------------------------------+ |
---|
32 | | | |
---|
33 | | The license and distribution terms for this file may be | |
---|
34 | | found in the file LICENSE in this distribution or at | |
---|
35 | | | |
---|
36 | | http://www.rtems.com/license/LICENSE. | |
---|
37 | | | |
---|
38 | +-----------------------------------------------------------------+ |
---|
39 | | | |
---|
40 | | date history ID | |
---|
41 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
42 | | 12.11.07 1.0 ras | |
---|
43 | | | |
---|
44 | \*===============================================================*/ |
---|
45 | |
---|
46 | #include <bsp.h> |
---|
47 | |
---|
48 | #include <string.h> |
---|
49 | |
---|
50 | #include <bsp/linker-symbols.h> |
---|
51 | |
---|
52 | #if defined(HAS_LOW_LEVEL_INIT) |
---|
53 | #define SYSTEM_PERIOD 10 /* system bus period in ns */ |
---|
54 | |
---|
55 | /* SDRAM Timing Parameters */ |
---|
56 | #define SDRAM_TWR 2 /* in clocks */ |
---|
57 | #define SDRAM_CASL 2.5 /* in clocks */ |
---|
58 | #define SDRAM_TRCD 20 /* in ns */ |
---|
59 | #define SDRAM_TRP 20 /* in ns */ |
---|
60 | #define SDRAM_TRFC 75 /* in ns */ |
---|
61 | #define SDRAM_TREFI 7800 /* in ns */ |
---|
62 | #endif /* defined(HAS_LOW_LEVEL_INIT) */ |
---|
63 | |
---|
64 | extern uint8_t _DataRom[]; |
---|
65 | extern uint8_t _DataRam[]; |
---|
66 | extern uint8_t _DataEnd[]; |
---|
67 | extern uint8_t _BssStart[]; |
---|
68 | extern uint8_t _BssEnd[]; |
---|
69 | extern uint8_t _BootFlashBase[]; |
---|
70 | extern uint8_t _CodeFlashBase[]; |
---|
71 | extern uint8_t RamBase[]; |
---|
72 | |
---|
73 | void gpio_init(void); |
---|
74 | void fbcs_init(void); |
---|
75 | void sdramc_init(void); |
---|
76 | void mcf548x_init(void); |
---|
77 | |
---|
78 | |
---|
79 | void mcf548x_init(void) |
---|
80 | { |
---|
81 | size_t i; |
---|
82 | |
---|
83 | #if defined(HAS_LOW_LEVEL_INIT) |
---|
84 | /* set XLB arbiter timeouts */ |
---|
85 | MCF548X_XLB_ADRTO = 0x00000100; |
---|
86 | MCF548X_XLB_DATTO = 0x00000100; |
---|
87 | MCF548X_XLB_BUSTO = 0x00000100; |
---|
88 | #endif |
---|
89 | |
---|
90 | gpio_init(); |
---|
91 | #if defined(HAS_LOW_LEVEL_INIT) |
---|
92 | fbcs_init(); |
---|
93 | sdramc_init(); |
---|
94 | #endif /* defined(HAS_LOW_LEVEL_INIT) */ |
---|
95 | |
---|
96 | /* Copy the vector table to RAM if necessary */ |
---|
97 | if (bsp_vector0_size == bsp_vector1_size) { |
---|
98 | memcpy(bsp_vector1_begin, bsp_vector0_begin, (size_t) bsp_vector1_size); |
---|
99 | m68k_set_vbr((uint32_t)bsp_vector1_begin); |
---|
100 | } |
---|
101 | |
---|
102 | /* Move initialized data from ROM to RAM. */ |
---|
103 | if (bsp_section_data_begin != bsp_section_data_load_begin) { |
---|
104 | memcpy( |
---|
105 | bsp_section_data_begin, |
---|
106 | bsp_section_data_load_begin, |
---|
107 | (size_t) bsp_section_data_size |
---|
108 | ); |
---|
109 | } |
---|
110 | |
---|
111 | /* Zero uninitialized data */ |
---|
112 | memset(bsp_section_bss_begin, 0, (size_t) bsp_section_bss_size); |
---|
113 | |
---|
114 | for (i = 8; i < RTEMS_ARRAY_SIZE(mcf548x_intc_icr_init_values); ++i) { |
---|
115 | volatile uint8_t *icr = &MCF548X_INTC_ICR0; |
---|
116 | |
---|
117 | icr[i] = mcf548x_intc_icr_init_values[i]; |
---|
118 | } |
---|
119 | } |
---|
120 | /********************************************************************/ |
---|
121 | #if defined(HAS_LOW_LEVEL_INIT) |
---|
122 | void |
---|
123 | fbcs_init (void) |
---|
124 | { |
---|
125 | #ifdef M5484FIREENGINE |
---|
126 | |
---|
127 | volatile uint32_t cscr, clk_ratio, fb_period, ws; |
---|
128 | |
---|
129 | /* boot flash already valid ? */ |
---|
130 | if(!(MCF548X_FBCS_CSMR0 & MCF548X_FBCS_CSMR_V)) |
---|
131 | { |
---|
132 | |
---|
133 | /* |
---|
134 | * Boot Flash |
---|
135 | */ |
---|
136 | MCF548X_FBCS_CSAR0 = MCF548X_FBCS_CSAR_BA((uint32_t)(_BootFlashBase)); |
---|
137 | |
---|
138 | cscr = (0 |
---|
139 | | MCF548X_FBCS_CSCR_ASET(1) |
---|
140 | | MCF548X_FBCS_CSCR_WRAH(0) |
---|
141 | | MCF548X_FBCS_CSCR_RDAH(0) |
---|
142 | | MCF548X_FBCS_CSCR_AA |
---|
143 | | MCF548X_FBCS_CSCR_PS_16); |
---|
144 | |
---|
145 | /* |
---|
146 | * Determine the necessary wait states based on the defined system |
---|
147 | * period (XLB clock period) and the CLKIN to XLB ratio. |
---|
148 | * The boot flash has a max access time of 110ns. |
---|
149 | */ |
---|
150 | clk_ratio = (MCF548X_PCI_PCIGSCR >> 24) & 0x7; |
---|
151 | fb_period = SYSTEM_PERIOD * clk_ratio; |
---|
152 | ws = 110 / fb_period; |
---|
153 | |
---|
154 | MCF548X_FBCS_CSCR0 = cscr | MCF548X_FBCS_CSCR_WS(ws); |
---|
155 | MCF548X_FBCS_CSMR0 = (0 |
---|
156 | | MCF548X_FBCS_CSMR_BAM_2M |
---|
157 | | MCF548X_FBCS_CSMR_V); |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | /* code flash already valid ? */ |
---|
162 | if(!(MCF548X_FBCS_CSMR1 & MCF548X_FBCS_CSMR_V)) |
---|
163 | { |
---|
164 | |
---|
165 | /* |
---|
166 | * Code Flash |
---|
167 | */ |
---|
168 | MCF548X_FBCS_CSAR1 = MCF548X_FBCS_CSAR_BA((uint32_t)(_CodeFlashBase)); |
---|
169 | |
---|
170 | /* |
---|
171 | * Determine the necessary wait states based on the defined system |
---|
172 | * period (XLB clock period) and the CLKIN to XLB ratio. |
---|
173 | * The user/code flash has a max access time of 120ns. |
---|
174 | */ |
---|
175 | ws = 120 / fb_period; |
---|
176 | MCF548X_FBCS_CSCR1 = cscr | MCF548X_FBCS_CSCR_WS(ws); |
---|
177 | MCF548X_FBCS_CSMR1 = (0 |
---|
178 | | MCF548X_FBCS_CSMR_BAM_16M |
---|
179 | | MCF548X_FBCS_CSMR_V); |
---|
180 | } |
---|
181 | |
---|
182 | #endif |
---|
183 | } |
---|
184 | #endif /* defined(HAS_LOW_LEVEL_INIT) */ |
---|
185 | |
---|
186 | /********************************************************************/ |
---|
187 | #if defined(HAS_LOW_LEVEL_INIT) |
---|
188 | void |
---|
189 | sdramc_init (void) |
---|
190 | { |
---|
191 | |
---|
192 | /* |
---|
193 | * Check to see if the SDRAM has already been initialized |
---|
194 | * by a run control tool |
---|
195 | */ |
---|
196 | if (!(MCF548X_SDRAMC_SDCR & MCF548X_SDRAMC_SDCR_REF)) |
---|
197 | { |
---|
198 | /* |
---|
199 | * Basic configuration and initialization |
---|
200 | */ |
---|
201 | MCF548X_SDRAMC_SDRAMDS = (0 |
---|
202 | | MCF548X_SDRAMC_SDRAMDS_SB_E(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA) |
---|
203 | | MCF548X_SDRAMC_SDRAMDS_SB_C(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA) |
---|
204 | | MCF548X_SDRAMC_SDRAMDS_SB_A(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA) |
---|
205 | | MCF548X_SDRAMC_SDRAMDS_SB_S(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA) |
---|
206 | | MCF548X_SDRAMC_SDRAMDS_SB_D(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA) |
---|
207 | ); |
---|
208 | MCF548X_SDRAMC_CS0CFG = (0 |
---|
209 | | MCF548X_SDRAMC_CSnCFG_CSBA((uint32_t)(RamBase)) |
---|
210 | | MCF548X_SDRAMC_CSnCFG_CSSZ(MCF548X_SDRAMC_CSnCFG_CSSZ_64MBYTE) |
---|
211 | ); |
---|
212 | MCF548X_SDRAMC_SDCFG1 = (0 |
---|
213 | | MCF548X_SDRAMC_SDCFG1_SRD2RW(7) |
---|
214 | | MCF548X_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1) |
---|
215 | | MCF548X_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL*2) + 2)) |
---|
216 | | MCF548X_SDRAMC_SDCFG1_ACT2RW((int)(((SDRAM_TRCD/SYSTEM_PERIOD) - 1) + 0.5)) |
---|
217 | | MCF548X_SDRAMC_SDCFG1_PRE2ACT((int)(((SDRAM_TRP/SYSTEM_PERIOD) - 1) + 0.5)) |
---|
218 | | MCF548X_SDRAMC_SDCFG1_REF2ACT((int)(((SDRAM_TRFC/SYSTEM_PERIOD) - 1) + 0.5)) |
---|
219 | | MCF548X_SDRAMC_SDCFG1_WTLAT(3) |
---|
220 | ); |
---|
221 | MCF548X_SDRAMC_SDCFG2 = (0 |
---|
222 | | MCF548X_SDRAMC_SDCFG2_BRD2PRE(4) |
---|
223 | | MCF548X_SDRAMC_SDCFG2_BWT2RW(6) |
---|
224 | | MCF548X_SDRAMC_SDCFG2_BRD2WT(7) |
---|
225 | | MCF548X_SDRAMC_SDCFG2_BL(7) |
---|
226 | ); |
---|
227 | |
---|
228 | /* |
---|
229 | * Precharge and enable write to SDMR |
---|
230 | */ |
---|
231 | MCF548X_SDRAMC_SDCR = (0 |
---|
232 | | MCF548X_SDRAMC_SDCR_MODE_EN |
---|
233 | | MCF548X_SDRAMC_SDCR_CKE |
---|
234 | | MCF548X_SDRAMC_SDCR_DDR |
---|
235 | | MCF548X_SDRAMC_SDCR_MUX(1) |
---|
236 | | MCF548X_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI/(SYSTEM_PERIOD*64)) - 1) + 0.5)) |
---|
237 | | MCF548X_SDRAMC_SDCR_IPALL |
---|
238 | ); |
---|
239 | |
---|
240 | /* |
---|
241 | * Write extended mode register |
---|
242 | */ |
---|
243 | MCF548X_SDRAMC_SDMR = (0 |
---|
244 | | MCF548X_SDRAMC_SDMR_BNKAD_LEMR |
---|
245 | | MCF548X_SDRAMC_SDMR_AD(0x0) |
---|
246 | | MCF548X_SDRAMC_SDMR_CMD |
---|
247 | ); |
---|
248 | |
---|
249 | /* |
---|
250 | * Write mode register and reset DLL |
---|
251 | */ |
---|
252 | MCF548X_SDRAMC_SDMR = (0 |
---|
253 | | MCF548X_SDRAMC_SDMR_BNKAD_LMR |
---|
254 | | MCF548X_SDRAMC_SDMR_AD(0x163) |
---|
255 | | MCF548X_SDRAMC_SDMR_CMD |
---|
256 | ); |
---|
257 | |
---|
258 | /* |
---|
259 | * Execute a PALL command |
---|
260 | */ |
---|
261 | MCF548X_SDRAMC_SDCR |=MCF548X_SDRAMC_SDCR_IPALL; |
---|
262 | |
---|
263 | /* |
---|
264 | * Perform two REF cycles |
---|
265 | */ |
---|
266 | MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF; |
---|
267 | MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF; |
---|
268 | |
---|
269 | /* |
---|
270 | * Write mode register and clear reset DLL |
---|
271 | */ |
---|
272 | MCF548X_SDRAMC_SDMR = (0 |
---|
273 | | MCF548X_SDRAMC_SDMR_BNKAD_LMR |
---|
274 | | MCF548X_SDRAMC_SDMR_AD(0x063) |
---|
275 | | MCF548X_SDRAMC_SDMR_CMD |
---|
276 | ); |
---|
277 | |
---|
278 | /* |
---|
279 | * Enable auto refresh and lock SDMR |
---|
280 | */ |
---|
281 | MCF548X_SDRAMC_SDCR &= ~MCF548X_SDRAMC_SDCR_MODE_EN; |
---|
282 | MCF548X_SDRAMC_SDCR |= (0 |
---|
283 | | MCF548X_SDRAMC_SDCR_REF |
---|
284 | | MCF548X_SDRAMC_SDCR_DQS_OE(0xF) |
---|
285 | ); |
---|
286 | } |
---|
287 | |
---|
288 | } |
---|
289 | #endif /* defined(HAS_LOW_LEVEL_INIT) */ |
---|
290 | |
---|
291 | /********************************************************************/ |
---|
292 | void |
---|
293 | gpio_init(void) |
---|
294 | { |
---|
295 | |
---|
296 | #ifdef M5484FIREENGINE |
---|
297 | |
---|
298 | /* |
---|
299 | * Enable Ethernet signals so that, if a cable is plugged into |
---|
300 | * the ports, the lines won't be floating and potentially cause |
---|
301 | * erroneous transmissions |
---|
302 | */ |
---|
303 | MCF548X_GPIO_PAR_FECI2CIRQ = (0 |
---|
304 | |
---|
305 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDC_EMDC |
---|
306 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDIO_EMDIO |
---|
307 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MII |
---|
308 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E17 |
---|
309 | |
---|
310 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDC |
---|
311 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDIO |
---|
312 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MII |
---|
313 | | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E07 |
---|
314 | ); |
---|
315 | |
---|
316 | #endif |
---|
317 | /* |
---|
318 | * make sure the "edge port" has all interrupts disabled |
---|
319 | */ |
---|
320 | MCF548X_EPORT_EPIER = 0; |
---|
321 | } |
---|