blob: 2aa6e1c82120d725e6abe9e8651d0750c0af7963 [file] [log] [blame]
wdenk945af8d2003-07-16 21:53:01 +00001/*
Detlev Zundela21fb982010-01-20 14:28:48 +01002 * (C) Copyright 2000-2010
wdenk945af8d2003-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 Zundel0f597bc2009-12-18 17:35:57 +010026#include <asm/io.h>
Detlev Zundela21fb982010-01-20 14:28:48 +010027#include <watchdog.h>
wdenk945af8d2003-07-16 21:53:01 +000028
Wolfgang Denkd87080b2006-03-31 18:32:53 +020029DECLARE_GLOBAL_DATA_PTR;
30
wdenk945af8d2003-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 Zundel0f597bc2009-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;
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;
Wolfgang Denk13d8bfe2010-01-31 21:58:48 +010049#if defined(CONFIG_WATCHDOG)
Detlev Zundela21fb982010-01-20 14:28:48 +010050 volatile struct mpc5xxx_gpt *gpt0 =
51 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
Wolfgang Denk13d8bfe2010-01-31 21:58:48 +010052#endif /* CONFIG_WATCHDOG */
wdenk945af8d2003-07-16 21:53:01 +000053 unsigned long addecr = (1 << 25); /* Boot_CS */
Wolfgang Denk13d8bfe2010-01-31 21:58:48 +010054
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
wdenk945af8d2003-07-16 21:53:01 +000056 addecr |= (1 << 22); /* SDRAM enable */
57#endif
58 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk945af8d2003-07-16 21:53:01 +000060
61 /* Clear initial global data */
62 memset ((void *) gd, 0, sizeof (gd_t));
63
64 /*
65 * Memory Controller: configure chip selects and enable them
66 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067#if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010068 out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
69 out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
70 CONFIG_SYS_BOOTCS_SIZE));
wdenk945af8d2003-07-16 21:53:01 +000071#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072#if defined(CONFIG_SYS_BOOTCS_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010073 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
wdenk945af8d2003-07-16 21:53:01 +000074#endif
75
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076#if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010077 out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
78 out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
79 CONFIG_SYS_CS0_SIZE));
wdenk945af8d2003-07-16 21:53:01 +000080 /* CS0 and BOOT_CS cannot be enabled at once. */
81 /* addecr |= (1 << 16); */
82#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020083#if defined(CONFIG_SYS_CS0_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010084 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
wdenk945af8d2003-07-16 21:53:01 +000085#endif
86
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020087#if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010088 out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
89 out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
90 CONFIG_SYS_CS1_SIZE));
wdenk945af8d2003-07-16 21:53:01 +000091 addecr |= (1 << 17);
92#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020093#if defined(CONFIG_SYS_CS1_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010094 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
wdenk945af8d2003-07-16 21:53:01 +000095#endif
96
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097#if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +010098 out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
99 out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
100 CONFIG_SYS_CS2_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000101 addecr |= (1 << 18);
102#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103#if defined(CONFIG_SYS_CS2_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100104 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000105#endif
106
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107#if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100108 out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
109 out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
110 CONFIG_SYS_CS3_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000111 addecr |= (1 << 19);
112#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113#if defined(CONFIG_SYS_CS3_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100114 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000115#endif
116
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200117#if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100118 out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
119 out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
120 CONFIG_SYS_CS4_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000121 addecr |= (1 << 20);
122#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200123#if defined(CONFIG_SYS_CS4_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100124 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000125#endif
126
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200127#if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100128 out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
129 out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
130 CONFIG_SYS_CS5_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000131 addecr |= (1 << 21);
132#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133#if defined(CONFIG_SYS_CS5_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100134 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000135#endif
136
137#if defined(CONFIG_MPC5200)
138 addecr |= 1;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139#if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100140 out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
141 out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
142 CONFIG_SYS_CS6_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000143 addecr |= (1 << 26);
144#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200145#if defined(CONFIG_SYS_CS6_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100146 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000147#endif
148
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149#if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100150 out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
151 out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
152 CONFIG_SYS_CS7_SIZE));
wdenk945af8d2003-07-16 21:53:01 +0000153 addecr |= (1 << 27);
154#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200155#if defined(CONFIG_SYS_CS7_CFG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100156 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
wdenk945af8d2003-07-16 21:53:01 +0000157#endif
158
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200159#if defined(CONFIG_SYS_CS_BURST)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100160 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
wdenk945af8d2003-07-16 21:53:01 +0000161#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162#if defined(CONFIG_SYS_CS_DEADCYCLE)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100163 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
wdenk945af8d2003-07-16 21:53:01 +0000164#endif
165#endif /* CONFIG_MPC5200 */
166
167 /* Enable chip selects */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100168#if defined(CONFIG_MGT5100)
169 out_be32(&mm->addecr, addecr);
170#elif defined(CONFIG_MPC5200)
171 out_be32(&mm->ipbi_ws_ctrl, addecr);
172#endif
173 out_be32(&lpb->cs_ctrl, (1 << 24));
wdenk945af8d2003-07-16 21:53:01 +0000174
175 /* Setup pin multiplexing */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200176#if defined(CONFIG_SYS_GPS_PORT_CONFIG)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100177 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
wdenk945af8d2003-07-16 21:53:01 +0000178#endif
wdenk96dd9af2003-07-31 22:56:30 +0000179
180#if defined(CONFIG_MPC5200)
181 /* enable timebase */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100182 setbits_be32(&xlb->config, (1 << 13));
wdenk7152b1d2003-09-05 23:19:14 +0000183
Wolfgang Denk8419c012006-04-18 11:05:03 +0200184 /* Enable snooping for RAM */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100185 setbits_be32(&xlb->config, (1 << 15));
186 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
Wolfgang Denk8419c012006-04-18 11:05:03 +0200187
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188# if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
wdenk7152b1d2003-09-05 23:19:14 +0000189 /* Motorola reports IPB should better run at 133 MHz. */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100190#if defined(CONFIG_MGT5100)
191 setbits_be32(&mm->addecr, 1);
192#elif defined(CONFIG_MPC5200)
193 setbits_be32(&mm->ipbi_ws_ctrl, 1);
194#endif
wdenk7152b1d2003-09-05 23:19:14 +0000195 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100196 addecr = in_be32(&cdm->cfg);
wdenk7152b1d2003-09-05 23:19:14 +0000197 addecr &= ~0x103;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200198# if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
wdenk56523f12004-07-11 17:40:54 +0000199 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
200 addecr |= 0x01;
201# else
202 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
wdenk7152b1d2003-09-05 23:19:14 +0000203 addecr |= 0x02;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204# endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100205 out_be32(&cdm->cfg, addecr);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200206# endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
wdenk4aeb2512003-09-16 17:06:05 +0000207 /* Configure the XLB Arbiter */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100208 out_be32(&xlb->master_pri_enable, 0xff);
209 out_be32(&xlb->master_priority, 0x11111111);
wdenke1599e82004-10-10 23:27:33 +0000210
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200211# if defined(CONFIG_SYS_XLB_PIPELINING)
wdenke1599e82004-10-10 23:27:33 +0000212 /* Enable piplining */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100213 clrbits_be32(&xlb->config, (1 << 31));
wdenke1599e82004-10-10 23:27:33 +0000214# endif
Detlev Zundela21fb982010-01-20 14:28:48 +0100215
216#if defined(CONFIG_WATCHDOG)
217 /* Charge the watchdog timer - prescaler = 64k, count = 64k*/
218 out_be32(&gpt0->cir, 0x0000ffff);
219 out_be32(&gpt0->emsr, 0x9004); /* wden|ce|timer_ms */
220
221 reset_5xxx_watchdog();
222#endif /* CONFIG_WATCHDOG */
223
wdenk56523f12004-07-11 17:40:54 +0000224#endif /* CONFIG_MPC5200 */
wdenk945af8d2003-07-16 21:53:01 +0000225}
226
227/*
228 * initialize higher level parts of CPU like time base and timers
229 */
230int cpu_init_r (void)
231{
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100232 volatile struct mpc5xxx_intr *intr =
233 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
234
wdenk945af8d2003-07-16 21:53:01 +0000235 /* mask all interrupts */
236#if defined(CONFIG_MGT5100)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100237 out_be32(&intr->per_mask, 0xfffffc00);
wdenk945af8d2003-07-16 21:53:01 +0000238#elif defined(CONFIG_MPC5200)
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100239 out_be32(&intr->per_mask, 0xffffff00);
wdenk945af8d2003-07-16 21:53:01 +0000240#endif
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100241 setbits_be32(&intr->main_mask, 0x0001ffff);
242 clrbits_be32(&intr->ctrl, 0x00000f00);
wdenk4aeb2512003-09-16 17:06:05 +0000243 /* route critical ints to normal ints */
Detlev Zundel0f597bc2009-12-18 17:35:57 +0100244 setbits_be32(&intr->ctrl, 0x00000001);
wdenk945af8d2003-07-16 21:53:01 +0000245
Jon Loeliger44312832007-07-09 19:06:00 -0500246#if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
wdenk945af8d2003-07-16 21:53:01 +0000247 /* load FEC microcode */
248 loadtask(0, 2);
249#endif
250
251 return (0);
252}