2 * (C) Copyright 2000-2010
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 DECLARE_GLOBAL_DATA_PTR;
32 * Breath some life into the CPU...
34 * Set up the memory map,
35 * initialize a bunch of registers.
37 void cpu_init_f (void)
39 volatile struct mpc5xxx_mmap_ctl *mm =
40 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
41 volatile struct mpc5xxx_lpb *lpb =
42 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
43 volatile struct mpc5xxx_cdm *cdm =
44 (struct mpc5xxx_cdm *) MPC5XXX_CDM;
45 volatile struct mpc5xxx_gpio *gpio =
46 (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
47 volatile struct mpc5xxx_xlb *xlb =
48 (struct mpc5xxx_xlb *) MPC5XXX_XLBARB;
49 volatile struct mpc5xxx_gpt *gpt0 =
50 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
51 unsigned long addecr = (1 << 25); /* Boot_CS */
52 #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
53 addecr |= (1 << 22); /* SDRAM enable */
55 /* Pointer is writable since we allocated a register for it */
56 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
58 /* Clear initial global data */
59 memset ((void *) gd, 0, sizeof (gd_t));
62 * Memory Controller: configure chip selects and enable them
64 #if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
65 out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
66 out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
67 CONFIG_SYS_BOOTCS_SIZE));
69 #if defined(CONFIG_SYS_BOOTCS_CFG)
70 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
73 #if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
74 out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
75 out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
76 CONFIG_SYS_CS0_SIZE));
77 /* CS0 and BOOT_CS cannot be enabled at once. */
78 /* addecr |= (1 << 16); */
80 #if defined(CONFIG_SYS_CS0_CFG)
81 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
84 #if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
85 out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
86 out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
87 CONFIG_SYS_CS1_SIZE));
90 #if defined(CONFIG_SYS_CS1_CFG)
91 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
94 #if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
95 out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
96 out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
97 CONFIG_SYS_CS2_SIZE));
100 #if defined(CONFIG_SYS_CS2_CFG)
101 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
104 #if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
105 out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
106 out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
107 CONFIG_SYS_CS3_SIZE));
110 #if defined(CONFIG_SYS_CS3_CFG)
111 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
114 #if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
115 out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
116 out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
117 CONFIG_SYS_CS4_SIZE));
120 #if defined(CONFIG_SYS_CS4_CFG)
121 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
124 #if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
125 out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
126 out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
127 CONFIG_SYS_CS5_SIZE));
130 #if defined(CONFIG_SYS_CS5_CFG)
131 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
134 #if defined(CONFIG_MPC5200)
136 #if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
137 out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
138 out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
139 CONFIG_SYS_CS6_SIZE));
142 #if defined(CONFIG_SYS_CS6_CFG)
143 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
146 #if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
147 out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
148 out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
149 CONFIG_SYS_CS7_SIZE));
152 #if defined(CONFIG_SYS_CS7_CFG)
153 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
156 #if defined(CONFIG_SYS_CS_BURST)
157 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
159 #if defined(CONFIG_SYS_CS_DEADCYCLE)
160 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
162 #endif /* CONFIG_MPC5200 */
164 /* Enable chip selects */
165 #if defined(CONFIG_MGT5100)
166 out_be32(&mm->addecr, addecr);
167 #elif defined(CONFIG_MPC5200)
168 out_be32(&mm->ipbi_ws_ctrl, addecr);
170 out_be32(&lpb->cs_ctrl, (1 << 24));
172 /* Setup pin multiplexing */
173 #if defined(CONFIG_SYS_GPS_PORT_CONFIG)
174 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
177 #if defined(CONFIG_MPC5200)
178 /* enable timebase */
179 setbits_be32(&xlb->config, (1 << 13));
181 /* Enable snooping for RAM */
182 setbits_be32(&xlb->config, (1 << 15));
183 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
185 # if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
186 /* Motorola reports IPB should better run at 133 MHz. */
187 #if defined(CONFIG_MGT5100)
188 setbits_be32(&mm->addecr, 1);
189 #elif defined(CONFIG_MPC5200)
190 setbits_be32(&mm->ipbi_ws_ctrl, 1);
192 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
193 addecr = in_be32(&cdm->cfg);
195 # if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
196 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
199 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
201 # endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
202 out_be32(&cdm->cfg, addecr);
203 # endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
204 /* Configure the XLB Arbiter */
205 out_be32(&xlb->master_pri_enable, 0xff);
206 out_be32(&xlb->master_priority, 0x11111111);
208 # if defined(CONFIG_SYS_XLB_PIPELINING)
209 /* Enable piplining */
210 clrbits_be32(&xlb->config, (1 << 31));
213 #if defined(CONFIG_WATCHDOG)
214 /* Charge the watchdog timer - prescaler = 64k, count = 64k*/
215 out_be32(&gpt0->cir, 0x0000ffff);
216 out_be32(&gpt0->emsr, 0x9004); /* wden|ce|timer_ms */
218 reset_5xxx_watchdog();
219 #endif /* CONFIG_WATCHDOG */
221 #endif /* CONFIG_MPC5200 */
225 * initialize higher level parts of CPU like time base and timers
227 int cpu_init_r (void)
229 volatile struct mpc5xxx_intr *intr =
230 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
232 /* mask all interrupts */
233 #if defined(CONFIG_MGT5100)
234 out_be32(&intr->per_mask, 0xfffffc00);
235 #elif defined(CONFIG_MPC5200)
236 out_be32(&intr->per_mask, 0xffffff00);
238 setbits_be32(&intr->main_mask, 0x0001ffff);
239 clrbits_be32(&intr->ctrl, 0x00000f00);
240 /* route critical ints to normal ints */
241 setbits_be32(&intr->ctrl, 0x00000001);
243 #if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
244 /* load FEC microcode */