blob: b15146480b13f25d35d18e69c03fc744bab472c5 [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;
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;
Detlev Zundelf7504ec2010-01-20 14:28:48 +010049 volatile struct mpc5xxx_gpt *gpt0 =
50 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
wdenk21136db2003-07-16 21:53:01 +000051 unsigned long addecr = (1 << 25); /* Boot_CS */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
wdenk21136db2003-07-16 21:53:01 +000053 addecr |= (1 << 22); /* SDRAM enable */
54#endif
55 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020056 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk21136db2003-07-16 21:53:01 +000057
58 /* Clear initial global data */
59 memset ((void *) gd, 0, sizeof (gd_t));
60
61 /*
62 * Memory Controller: configure chip selects and enable them
63 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064#if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010065 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));
wdenk21136db2003-07-16 21:53:01 +000068#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#if defined(CONFIG_SYS_BOOTCS_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010070 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
wdenk21136db2003-07-16 21:53:01 +000071#endif
72
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073#if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010074 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));
wdenk21136db2003-07-16 21:53:01 +000077 /* CS0 and BOOT_CS cannot be enabled at once. */
78 /* addecr |= (1 << 16); */
79#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020080#if defined(CONFIG_SYS_CS0_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010081 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
wdenk21136db2003-07-16 21:53:01 +000082#endif
83
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010085 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));
wdenk21136db2003-07-16 21:53:01 +000088 addecr |= (1 << 17);
89#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090#if defined(CONFIG_SYS_CS1_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010091 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
wdenk21136db2003-07-16 21:53:01 +000092#endif
93
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020094#if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010095 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));
wdenk21136db2003-07-16 21:53:01 +000098 addecr |= (1 << 18);
99#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100#if defined(CONFIG_SYS_CS2_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100101 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
wdenk21136db2003-07-16 21:53:01 +0000102#endif
103
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104#if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100105 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));
wdenk21136db2003-07-16 21:53:01 +0000108 addecr |= (1 << 19);
109#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110#if defined(CONFIG_SYS_CS3_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100111 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
wdenk21136db2003-07-16 21:53:01 +0000112#endif
113
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114#if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100115 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));
wdenk21136db2003-07-16 21:53:01 +0000118 addecr |= (1 << 20);
119#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120#if defined(CONFIG_SYS_CS4_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100121 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
wdenk21136db2003-07-16 21:53:01 +0000122#endif
123
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200124#if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100125 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));
wdenk21136db2003-07-16 21:53:01 +0000128 addecr |= (1 << 21);
129#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130#if defined(CONFIG_SYS_CS5_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100131 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
wdenk21136db2003-07-16 21:53:01 +0000132#endif
133
134#if defined(CONFIG_MPC5200)
135 addecr |= 1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136#if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100137 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));
wdenk21136db2003-07-16 21:53:01 +0000140 addecr |= (1 << 26);
141#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142#if defined(CONFIG_SYS_CS6_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100143 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
wdenk21136db2003-07-16 21:53:01 +0000144#endif
145
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146#if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100147 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));
wdenk21136db2003-07-16 21:53:01 +0000150 addecr |= (1 << 27);
151#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200152#if defined(CONFIG_SYS_CS7_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100153 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
wdenk21136db2003-07-16 21:53:01 +0000154#endif
155
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200156#if defined(CONFIG_SYS_CS_BURST)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100157 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
wdenk21136db2003-07-16 21:53:01 +0000158#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200159#if defined(CONFIG_SYS_CS_DEADCYCLE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100160 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
wdenk21136db2003-07-16 21:53:01 +0000161#endif
162#endif /* CONFIG_MPC5200 */
163
164 /* Enable chip selects */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100165#if defined(CONFIG_MGT5100)
166 out_be32(&mm->addecr, addecr);
167#elif defined(CONFIG_MPC5200)
168 out_be32(&mm->ipbi_ws_ctrl, addecr);
169#endif
170 out_be32(&lpb->cs_ctrl, (1 << 24));
wdenk21136db2003-07-16 21:53:01 +0000171
172 /* Setup pin multiplexing */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200173#if defined(CONFIG_SYS_GPS_PORT_CONFIG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100174 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
wdenk21136db2003-07-16 21:53:01 +0000175#endif
wdenka5ae1f02003-07-31 22:56:30 +0000176
177#if defined(CONFIG_MPC5200)
178 /* enable timebase */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100179 setbits_be32(&xlb->config, (1 << 13));
wdenkeb20ad32003-09-05 23:19:14 +0000180
Wolfgang Denkdda81342006-04-18 11:05:03 +0200181 /* Enable snooping for RAM */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100182 setbits_be32(&xlb->config, (1 << 15));
183 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
Wolfgang Denkdda81342006-04-18 11:05:03 +0200184
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200185# if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
wdenkeb20ad32003-09-05 23:19:14 +0000186 /* Motorola reports IPB should better run at 133 MHz. */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100187#if defined(CONFIG_MGT5100)
188 setbits_be32(&mm->addecr, 1);
189#elif defined(CONFIG_MPC5200)
190 setbits_be32(&mm->ipbi_ws_ctrl, 1);
191#endif
wdenkeb20ad32003-09-05 23:19:14 +0000192 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100193 addecr = in_be32(&cdm->cfg);
wdenkeb20ad32003-09-05 23:19:14 +0000194 addecr &= ~0x103;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200195# if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
wdenk64519362004-07-11 17:40:54 +0000196 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
197 addecr |= 0x01;
198# else
199 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
wdenkeb20ad32003-09-05 23:19:14 +0000200 addecr |= 0x02;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200201# endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100202 out_be32(&cdm->cfg, addecr);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200203# endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
wdenkf5547d32003-09-16 17:06:05 +0000204 /* Configure the XLB Arbiter */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100205 out_be32(&xlb->master_pri_enable, 0xff);
206 out_be32(&xlb->master_priority, 0x11111111);
wdenk391b5742004-10-10 23:27:33 +0000207
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208# if defined(CONFIG_SYS_XLB_PIPELINING)
wdenk391b5742004-10-10 23:27:33 +0000209 /* Enable piplining */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100210 clrbits_be32(&xlb->config, (1 << 31));
wdenk391b5742004-10-10 23:27:33 +0000211# endif
Detlev Zundelf7504ec2010-01-20 14:28:48 +0100212
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 */
217
218 reset_5xxx_watchdog();
219#endif /* CONFIG_WATCHDOG */
220
wdenk64519362004-07-11 17:40:54 +0000221#endif /* CONFIG_MPC5200 */
wdenk21136db2003-07-16 21:53:01 +0000222}
223
224/*
225 * initialize higher level parts of CPU like time base and timers
226 */
227int cpu_init_r (void)
228{
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100229 volatile struct mpc5xxx_intr *intr =
230 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
231
wdenk21136db2003-07-16 21:53:01 +0000232 /* mask all interrupts */
233#if defined(CONFIG_MGT5100)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100234 out_be32(&intr->per_mask, 0xfffffc00);
wdenk21136db2003-07-16 21:53:01 +0000235#elif defined(CONFIG_MPC5200)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100236 out_be32(&intr->per_mask, 0xffffff00);
wdenk21136db2003-07-16 21:53:01 +0000237#endif
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100238 setbits_be32(&intr->main_mask, 0x0001ffff);
239 clrbits_be32(&intr->ctrl, 0x00000f00);
wdenkf5547d32003-09-16 17:06:05 +0000240 /* route critical ints to normal ints */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100241 setbits_be32(&intr->ctrl, 0x00000001);
wdenk21136db2003-07-16 21:53:01 +0000242
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500243#if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
wdenk21136db2003-07-16 21:53:01 +0000244 /* load FEC microcode */
245 loadtask(0, 2);
246#endif
247
248 return (0);
249}