blob: 560c9b311c38ea81316fe64e584002622e3b4eb0 [file] [log] [blame]
wdenk21136db2003-07-16 21:53:01 +00001/*
Detlev Zundelf7504ec2010-01-20 14:28:48 +01002 * (C) Copyright 2000-2010
wdenk21136db2003-07-16 21:53:01 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <mpc5xxx.h>
Detlev Zundel8b29ad52009-12-18 17:35:57 +010026#include <asm/io.h>
Detlev Zundelf7504ec2010-01-20 14:28:48 +010027#include <watchdog.h>
wdenk21136db2003-07-16 21:53:01 +000028
Wolfgang Denk6405a152006-03-31 18:32:53 +020029DECLARE_GLOBAL_DATA_PTR;
30
wdenk21136db2003-07-16 21:53:01 +000031/*
32 * Breath some life into the CPU...
33 *
34 * Set up the memory map,
35 * initialize a bunch of registers.
36 */
37void cpu_init_f (void)
38{
Detlev Zundel8b29ad52009-12-18 17:35:57 +010039 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;
Detlev Zundel8b29ad52009-12-18 17:35:57 +010043 volatile struct mpc5xxx_gpio *gpio =
44 (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
45 volatile struct mpc5xxx_xlb *xlb =
46 (struct mpc5xxx_xlb *) MPC5XXX_XLBARB;
Wolfgang Denke8cb0e82010-01-31 22:03:15 +010047#if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
48 volatile struct mpc5xxx_cdm *cdm =
49 (struct mpc5xxx_cdm *) MPC5XXX_CDM;
50#endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
Wolfgang Denk5012ff32010-01-31 21:58:48 +010051#if defined(CONFIG_WATCHDOG)
Detlev Zundelf7504ec2010-01-20 14:28:48 +010052 volatile struct mpc5xxx_gpt *gpt0 =
53 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
Wolfgang Denk5012ff32010-01-31 21:58:48 +010054#endif /* CONFIG_WATCHDOG */
wdenk21136db2003-07-16 21:53:01 +000055 unsigned long addecr = (1 << 25); /* Boot_CS */
Wolfgang Denk5012ff32010-01-31 21:58:48 +010056
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
wdenk21136db2003-07-16 21:53:01 +000058 addecr |= (1 << 22); /* SDRAM enable */
59#endif
60 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk21136db2003-07-16 21:53:01 +000062
63 /* Clear initial global data */
64 memset ((void *) gd, 0, sizeof (gd_t));
65
66 /*
67 * Memory Controller: configure chip selects and enable them
68 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010070 out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
71 out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
72 CONFIG_SYS_BOOTCS_SIZE));
wdenk21136db2003-07-16 21:53:01 +000073#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074#if defined(CONFIG_SYS_BOOTCS_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010075 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
wdenk21136db2003-07-16 21:53:01 +000076#endif
77
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078#if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010079 out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
80 out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
81 CONFIG_SYS_CS0_SIZE));
wdenk21136db2003-07-16 21:53:01 +000082 /* CS0 and BOOT_CS cannot be enabled at once. */
83 /* addecr |= (1 << 16); */
84#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085#if defined(CONFIG_SYS_CS0_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010086 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
wdenk21136db2003-07-16 21:53:01 +000087#endif
88
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089#if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010090 out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
91 out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
92 CONFIG_SYS_CS1_SIZE));
wdenk21136db2003-07-16 21:53:01 +000093 addecr |= (1 << 17);
94#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095#if defined(CONFIG_SYS_CS1_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010096 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
wdenk21136db2003-07-16 21:53:01 +000097#endif
98
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099#if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100100 out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
101 out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
102 CONFIG_SYS_CS2_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000103 addecr |= (1 << 18);
104#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105#if defined(CONFIG_SYS_CS2_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100106 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
wdenk21136db2003-07-16 21:53:01 +0000107#endif
108
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109#if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100110 out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
111 out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
112 CONFIG_SYS_CS3_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000113 addecr |= (1 << 19);
114#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115#if defined(CONFIG_SYS_CS3_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100116 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
wdenk21136db2003-07-16 21:53:01 +0000117#endif
118
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119#if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100120 out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
121 out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
122 CONFIG_SYS_CS4_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000123 addecr |= (1 << 20);
124#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200125#if defined(CONFIG_SYS_CS4_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100126 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
wdenk21136db2003-07-16 21:53:01 +0000127#endif
128
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200129#if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100130 out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
131 out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
132 CONFIG_SYS_CS5_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000133 addecr |= (1 << 21);
134#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200135#if defined(CONFIG_SYS_CS5_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100136 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
wdenk21136db2003-07-16 21:53:01 +0000137#endif
138
139#if defined(CONFIG_MPC5200)
140 addecr |= 1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200141#if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100142 out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
143 out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
144 CONFIG_SYS_CS6_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000145 addecr |= (1 << 26);
146#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200147#if defined(CONFIG_SYS_CS6_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100148 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
wdenk21136db2003-07-16 21:53:01 +0000149#endif
150
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151#if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100152 out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
153 out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
154 CONFIG_SYS_CS7_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000155 addecr |= (1 << 27);
156#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157#if defined(CONFIG_SYS_CS7_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100158 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
wdenk21136db2003-07-16 21:53:01 +0000159#endif
160
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200161#if defined(CONFIG_SYS_CS_BURST)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100162 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
wdenk21136db2003-07-16 21:53:01 +0000163#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164#if defined(CONFIG_SYS_CS_DEADCYCLE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100165 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
wdenk21136db2003-07-16 21:53:01 +0000166#endif
167#endif /* CONFIG_MPC5200 */
168
169 /* Enable chip selects */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100170#if defined(CONFIG_MGT5100)
171 out_be32(&mm->addecr, addecr);
172#elif defined(CONFIG_MPC5200)
173 out_be32(&mm->ipbi_ws_ctrl, addecr);
174#endif
175 out_be32(&lpb->cs_ctrl, (1 << 24));
wdenk21136db2003-07-16 21:53:01 +0000176
177 /* Setup pin multiplexing */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178#if defined(CONFIG_SYS_GPS_PORT_CONFIG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100179 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
wdenk21136db2003-07-16 21:53:01 +0000180#endif
wdenka5ae1f02003-07-31 22:56:30 +0000181
182#if defined(CONFIG_MPC5200)
183 /* enable timebase */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100184 setbits_be32(&xlb->config, (1 << 13));
wdenkeb20ad32003-09-05 23:19:14 +0000185
Wolfgang Denkdda81342006-04-18 11:05:03 +0200186 /* Enable snooping for RAM */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100187 setbits_be32(&xlb->config, (1 << 15));
188 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
Wolfgang Denkdda81342006-04-18 11:05:03 +0200189
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190# if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
wdenkeb20ad32003-09-05 23:19:14 +0000191 /* Motorola reports IPB should better run at 133 MHz. */
Wolfgang Denke8cb0e82010-01-31 22:03:15 +0100192# if defined(CONFIG_MGT5100)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100193 setbits_be32(&mm->addecr, 1);
Wolfgang Denke8cb0e82010-01-31 22:03:15 +0100194# elif defined(CONFIG_MPC5200)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100195 setbits_be32(&mm->ipbi_ws_ctrl, 1);
Wolfgang Denke8cb0e82010-01-31 22:03:15 +0100196# endif
wdenkeb20ad32003-09-05 23:19:14 +0000197 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100198 addecr = in_be32(&cdm->cfg);
wdenkeb20ad32003-09-05 23:19:14 +0000199 addecr &= ~0x103;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200200# if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
wdenk64519362004-07-11 17:40:54 +0000201 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
202 addecr |= 0x01;
203# else
204 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
wdenkeb20ad32003-09-05 23:19:14 +0000205 addecr |= 0x02;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206# endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100207 out_be32(&cdm->cfg, addecr);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208# endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
wdenkf5547d32003-09-16 17:06:05 +0000209 /* Configure the XLB Arbiter */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100210 out_be32(&xlb->master_pri_enable, 0xff);
211 out_be32(&xlb->master_priority, 0x11111111);
wdenk391b5742004-10-10 23:27:33 +0000212
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213# if defined(CONFIG_SYS_XLB_PIPELINING)
wdenk391b5742004-10-10 23:27:33 +0000214 /* Enable piplining */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100215 clrbits_be32(&xlb->config, (1 << 31));
wdenk391b5742004-10-10 23:27:33 +0000216# endif
Detlev Zundelf7504ec2010-01-20 14:28:48 +0100217
218#if defined(CONFIG_WATCHDOG)
219 /* Charge the watchdog timer - prescaler = 64k, count = 64k*/
220 out_be32(&gpt0->cir, 0x0000ffff);
221 out_be32(&gpt0->emsr, 0x9004); /* wden|ce|timer_ms */
222
223 reset_5xxx_watchdog();
224#endif /* CONFIG_WATCHDOG */
225
wdenk64519362004-07-11 17:40:54 +0000226#endif /* CONFIG_MPC5200 */
wdenk21136db2003-07-16 21:53:01 +0000227}
228
229/*
230 * initialize higher level parts of CPU like time base and timers
231 */
232int cpu_init_r (void)
233{
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100234 volatile struct mpc5xxx_intr *intr =
235 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
236
wdenk21136db2003-07-16 21:53:01 +0000237 /* mask all interrupts */
238#if defined(CONFIG_MGT5100)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100239 out_be32(&intr->per_mask, 0xfffffc00);
wdenk21136db2003-07-16 21:53:01 +0000240#elif defined(CONFIG_MPC5200)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100241 out_be32(&intr->per_mask, 0xffffff00);
wdenk21136db2003-07-16 21:53:01 +0000242#endif
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100243 setbits_be32(&intr->main_mask, 0x0001ffff);
244 clrbits_be32(&intr->ctrl, 0x00000f00);
wdenkf5547d32003-09-16 17:06:05 +0000245 /* route critical ints to normal ints */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100246 setbits_be32(&intr->ctrl, 0x00000001);
wdenk21136db2003-07-16 21:53:01 +0000247
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500248#if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
wdenk21136db2003-07-16 21:53:01 +0000249 /* load FEC microcode */
250 loadtask(0, 2);
251#endif
252
253 return (0);
254}