1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup mpc55xx |
---|
5 | * |
---|
6 | * @brief Early initialization code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008-2011 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <bsp/start.h> |
---|
25 | #include <bsp/mpc55xx-config.h> |
---|
26 | |
---|
27 | static BSP_START_TEXT_SECTION void mpc55xx_start_mmu(void) |
---|
28 | { |
---|
29 | #ifdef MPC55XX_BOOTFLAGS |
---|
30 | /* If the low bit of bootflag 0 is clear don't change the MMU. */ |
---|
31 | bool do_mmu_config = (mpc55xx_bootflag_0 [0] & 1) != 0; |
---|
32 | #else |
---|
33 | bool do_mmu_config = true; |
---|
34 | #endif |
---|
35 | |
---|
36 | if (do_mmu_config) { |
---|
37 | mpc55xx_start_mmu_apply_config( |
---|
38 | &mpc55xx_start_config_mmu [0], |
---|
39 | mpc55xx_start_config_mmu_count [0] |
---|
40 | ); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | static BSP_START_TEXT_SECTION void mpc55xx_start_internal_ram(void) |
---|
45 | { |
---|
46 | /* Initialize internal SRAM to zero (ECC) */ |
---|
47 | bsp_start_zero( |
---|
48 | (char *) bsp_ram_start + MPC55XX_EARLY_STACK_SIZE, |
---|
49 | (size_t) bsp_ram_size - MPC55XX_EARLY_STACK_SIZE |
---|
50 | ); |
---|
51 | #ifdef MPC55XX_HAS_SECOND_INTERNAL_RAM_AREA |
---|
52 | bsp_start_zero(&bsp_ram_1_start [0], (size_t) bsp_ram_1_size); |
---|
53 | #endif |
---|
54 | } |
---|
55 | |
---|
56 | static BSP_START_TEXT_SECTION void mpc55xx_start_mode_change(void) |
---|
57 | { |
---|
58 | #ifdef MPC55XX_HAS_MODE_CONTROL |
---|
59 | uint32_t mctl_key1 = 0x5af0; |
---|
60 | uint32_t mctl_key2 = 0xa50f; |
---|
61 | int i = 0; |
---|
62 | |
---|
63 | /* Clear any pending RGM status */ |
---|
64 | RGM.FES.R = 0xffff; |
---|
65 | RGM.DES.R = 0xffff; |
---|
66 | |
---|
67 | /* Make sure XOSC and PLLs are on in RUN0 state */ |
---|
68 | ME.DRUN_MC.R = 0x001f0074; |
---|
69 | ME.RUN_MC [0].R = 0x001f0074; |
---|
70 | |
---|
71 | /* |
---|
72 | * Make sure all peripherals are active in DRUN and RUN0 state. |
---|
73 | * |
---|
74 | * FIXME: This might be optimized to reduce power consumtion. |
---|
75 | */ |
---|
76 | for (i = 0; i < 8; ++i) { |
---|
77 | ME_RUN_PC_32B_tag run_pc = { .R = ME.RUN_PC [i].R }; |
---|
78 | |
---|
79 | run_pc.B.DRUN = 1; |
---|
80 | run_pc.B.RUN0 = 1; |
---|
81 | |
---|
82 | ME.RUN_PC [i].R = run_pc.R; |
---|
83 | } |
---|
84 | |
---|
85 | /* Switch to RUN0 state */ |
---|
86 | ME.MCTL.R = 0x40000000 | mctl_key1; |
---|
87 | ME.MCTL.R = 0x40000000 | mctl_key2; |
---|
88 | |
---|
89 | while (ME.GS.B.S_MTRANS) { |
---|
90 | /* Wait for mode switch to be completed */ |
---|
91 | } |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | static BSP_START_TEXT_SECTION void mpc55xx_start_siu(void) |
---|
96 | { |
---|
97 | size_t i = 0; |
---|
98 | |
---|
99 | #ifdef MPC55XX_BOARD_GWLCFM |
---|
100 | SIU.GPDO[122].B.PDO=1; /* make sure USB reset is kept high */ |
---|
101 | SIU.GPDO[121].B.PDO=1; /* make sure Ethernet reset is kept high */ |
---|
102 | SIU.GPDO[113].B.PDO=1; /* make sure MOST Companion reset is kept high */ |
---|
103 | #endif |
---|
104 | |
---|
105 | for (i = 0; i < mpc55xx_start_config_siu_pcr_count [0]; ++i) { |
---|
106 | const mpc55xx_siu_pcr_config *e = &mpc55xx_start_config_siu_pcr [i]; |
---|
107 | int j = e->index; |
---|
108 | int n = j + e->count; |
---|
109 | uint16_t pcr = e->pcr.R; |
---|
110 | |
---|
111 | while (j < n) { |
---|
112 | SIU.PCR [j].R = pcr; |
---|
113 | ++j; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | static BSP_START_TEXT_SECTION void mpc55xx_start_ebi_chip_select(void) |
---|
119 | { |
---|
120 | #ifdef MPC55XX_HAS_EBI |
---|
121 | size_t i = 0; |
---|
122 | |
---|
123 | for (i = 0; i < mpc55xx_start_config_ebi_cs_count [0]; ++i) { |
---|
124 | EBI.CS [i] = mpc55xx_start_config_ebi_cs [i]; |
---|
125 | } |
---|
126 | |
---|
127 | for (i = 0; i < mpc55xx_start_config_ebi_cal_cs_count [0]; ++i) { |
---|
128 | EBI.CAL_CS [i] = mpc55xx_start_config_ebi_cal_cs [i]; |
---|
129 | } |
---|
130 | #endif |
---|
131 | } |
---|
132 | |
---|
133 | static BSP_START_TEXT_SECTION void mpc55xx_start_ebi(void) |
---|
134 | { |
---|
135 | #if defined(MPC55XX_BOARD_GWLCFM) |
---|
136 | /* |
---|
137 | * init EBI for Muxed AD bus |
---|
138 | */ |
---|
139 | EBI.MCR.B.DBM = 1; |
---|
140 | EBI.MCR.B.AD_MUX = 1; /* use multiplexed bus */ |
---|
141 | EBI.MCR.B.D16_31 = 1; /* use lower AD bus */ |
---|
142 | |
---|
143 | SIU.ECCR.B.EBDF = 3; /* use CLK/4 as bus clock */ |
---|
144 | #elif defined(MPC55XX_BOARD_MPC5674FEVB) |
---|
145 | struct EBI_tag ebi = { |
---|
146 | .MCR = { |
---|
147 | .B = { |
---|
148 | .ACGE = 0, |
---|
149 | .MDIS = 0, |
---|
150 | .D16_31 = 0, |
---|
151 | .AD_MUX = 0, |
---|
152 | .DBM = 0 |
---|
153 | } |
---|
154 | } |
---|
155 | }; |
---|
156 | |
---|
157 | EBI.MCR.R = ebi.MCR.R; |
---|
158 | #endif |
---|
159 | } |
---|
160 | |
---|
161 | BSP_START_TEXT_SECTION void mpc55xx_start_early(void) |
---|
162 | { |
---|
163 | mpc55xx_start_watchdog(); |
---|
164 | mpc55xx_start_clock(); |
---|
165 | mpc55xx_start_flash(); |
---|
166 | #if defined(BSP_DATA_CACHE_ENABLED) || defined(BSP_INSTRUCTION_CACHE_ENABLED) |
---|
167 | mpc55xx_start_cache(); |
---|
168 | #endif |
---|
169 | mpc55xx_start_internal_ram(); |
---|
170 | mpc55xx_start_mmu(); |
---|
171 | mpc55xx_start_mode_change(); |
---|
172 | mpc55xx_start_siu(); |
---|
173 | mpc55xx_start_ebi_chip_select(); |
---|
174 | mpc55xx_start_ebi(); |
---|
175 | } |
---|