blob: acff5f5b3500e32df534bfb0d3f088916d205733 [file] [log] [blame]
wdenk21136db2003-07-16 21:53:01 +00001/*
Detlev Zundel8b29ad52009-12-18 17:35:57 +01002 * (C) Copyright 2000-2009
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>
wdenk21136db2003-07-16 21:53:01 +000027
Wolfgang Denk6405a152006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
wdenk21136db2003-07-16 21:53:01 +000030/*
31 * Breath some life into the CPU...
32 *
33 * Set up the memory map,
34 * initialize a bunch of registers.
35 */
36void cpu_init_f (void)
37{
Detlev Zundel8b29ad52009-12-18 17:35:57 +010038 volatile struct mpc5xxx_mmap_ctl *mm =
39 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
40 volatile struct mpc5xxx_lpb *lpb =
41 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
42 volatile struct mpc5xxx_cdm *cdm =
43 (struct mpc5xxx_cdm *) MPC5XXX_CDM;
44 volatile struct mpc5xxx_gpio *gpio =
45 (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
46 volatile struct mpc5xxx_xlb *xlb =
47 (struct mpc5xxx_xlb *) MPC5XXX_XLBARB;
wdenk21136db2003-07-16 21:53:01 +000048 unsigned long addecr = (1 << 25); /* Boot_CS */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
wdenk21136db2003-07-16 21:53:01 +000050 addecr |= (1 << 22); /* SDRAM enable */
51#endif
52 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk21136db2003-07-16 21:53:01 +000054
55 /* Clear initial global data */
56 memset ((void *) gd, 0, sizeof (gd_t));
57
58 /*
59 * Memory Controller: configure chip selects and enable them
60 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061#if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010062 out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
63 out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
64 CONFIG_SYS_BOOTCS_SIZE));
wdenk21136db2003-07-16 21:53:01 +000065#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066#if defined(CONFIG_SYS_BOOTCS_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010067 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
wdenk21136db2003-07-16 21:53:01 +000068#endif
69
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070#if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010071 out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
72 out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
73 CONFIG_SYS_CS0_SIZE));
wdenk21136db2003-07-16 21:53:01 +000074 /* CS0 and BOOT_CS cannot be enabled at once. */
75 /* addecr |= (1 << 16); */
76#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077#if defined(CONFIG_SYS_CS0_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010078 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
wdenk21136db2003-07-16 21:53:01 +000079#endif
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010082 out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
83 out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
84 CONFIG_SYS_CS1_SIZE));
wdenk21136db2003-07-16 21:53:01 +000085 addecr |= (1 << 17);
86#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#if defined(CONFIG_SYS_CS1_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010088 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
wdenk21136db2003-07-16 21:53:01 +000089#endif
90
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020091#if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010092 out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
93 out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
94 CONFIG_SYS_CS2_SIZE));
wdenk21136db2003-07-16 21:53:01 +000095 addecr |= (1 << 18);
96#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097#if defined(CONFIG_SYS_CS2_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010098 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
wdenk21136db2003-07-16 21:53:01 +000099#endif
100
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101#if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100102 out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
103 out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
104 CONFIG_SYS_CS3_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000105 addecr |= (1 << 19);
106#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200107#if defined(CONFIG_SYS_CS3_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100108 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
wdenk21136db2003-07-16 21:53:01 +0000109#endif
110
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200111#if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100112 out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
113 out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
114 CONFIG_SYS_CS4_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000115 addecr |= (1 << 20);
116#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117#if defined(CONFIG_SYS_CS4_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100118 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
wdenk21136db2003-07-16 21:53:01 +0000119#endif
120
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121#if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100122 out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
123 out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
124 CONFIG_SYS_CS5_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000125 addecr |= (1 << 21);
126#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127#if defined(CONFIG_SYS_CS5_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100128 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
wdenk21136db2003-07-16 21:53:01 +0000129#endif
130
131#if defined(CONFIG_MPC5200)
132 addecr |= 1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133#if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100134 out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
135 out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
136 CONFIG_SYS_CS6_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000137 addecr |= (1 << 26);
138#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139#if defined(CONFIG_SYS_CS6_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100140 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
wdenk21136db2003-07-16 21:53:01 +0000141#endif
142
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143#if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100144 out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
145 out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
146 CONFIG_SYS_CS7_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000147 addecr |= (1 << 27);
148#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149#if defined(CONFIG_SYS_CS7_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100150 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
wdenk21136db2003-07-16 21:53:01 +0000151#endif
152
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153#if defined(CONFIG_SYS_CS_BURST)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100154 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
wdenk21136db2003-07-16 21:53:01 +0000155#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200156#if defined(CONFIG_SYS_CS_DEADCYCLE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100157 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
wdenk21136db2003-07-16 21:53:01 +0000158#endif
159#endif /* CONFIG_MPC5200 */
160
161 /* Enable chip selects */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100162#if defined(CONFIG_MGT5100)
163 out_be32(&mm->addecr, addecr);
164#elif defined(CONFIG_MPC5200)
165 out_be32(&mm->ipbi_ws_ctrl, addecr);
166#endif
167 out_be32(&lpb->cs_ctrl, (1 << 24));
wdenk21136db2003-07-16 21:53:01 +0000168
169 /* Setup pin multiplexing */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170#if defined(CONFIG_SYS_GPS_PORT_CONFIG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100171 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
wdenk21136db2003-07-16 21:53:01 +0000172#endif
wdenka5ae1f02003-07-31 22:56:30 +0000173
174#if defined(CONFIG_MPC5200)
175 /* enable timebase */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100176 setbits_be32(&xlb->config, (1 << 13));
wdenkeb20ad32003-09-05 23:19:14 +0000177
Wolfgang Denkdda81342006-04-18 11:05:03 +0200178 /* Enable snooping for RAM */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100179 setbits_be32(&xlb->config, (1 << 15));
180 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
Wolfgang Denkdda81342006-04-18 11:05:03 +0200181
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200182# if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
wdenkeb20ad32003-09-05 23:19:14 +0000183 /* Motorola reports IPB should better run at 133 MHz. */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100184#if defined(CONFIG_MGT5100)
185 setbits_be32(&mm->addecr, 1);
186#elif defined(CONFIG_MPC5200)
187 setbits_be32(&mm->ipbi_ws_ctrl, 1);
188#endif
wdenkeb20ad32003-09-05 23:19:14 +0000189 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100190 addecr = in_be32(&cdm->cfg);
wdenkeb20ad32003-09-05 23:19:14 +0000191 addecr &= ~0x103;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200192# if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
wdenk64519362004-07-11 17:40:54 +0000193 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
194 addecr |= 0x01;
195# else
196 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
wdenkeb20ad32003-09-05 23:19:14 +0000197 addecr |= 0x02;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200198# endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100199 out_be32(&cdm->cfg, addecr);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200200# endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
wdenkf5547d32003-09-16 17:06:05 +0000201 /* Configure the XLB Arbiter */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100202 out_be32(&xlb->master_pri_enable, 0xff);
203 out_be32(&xlb->master_priority, 0x11111111);
wdenk391b5742004-10-10 23:27:33 +0000204
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205# if defined(CONFIG_SYS_XLB_PIPELINING)
wdenk391b5742004-10-10 23:27:33 +0000206 /* Enable piplining */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100207 clrbits_be32(&xlb->config, (1 << 31));
wdenk391b5742004-10-10 23:27:33 +0000208# endif
wdenk64519362004-07-11 17:40:54 +0000209#endif /* CONFIG_MPC5200 */
wdenk21136db2003-07-16 21:53:01 +0000210}
211
212/*
213 * initialize higher level parts of CPU like time base and timers
214 */
215int cpu_init_r (void)
216{
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100217 volatile struct mpc5xxx_intr *intr =
218 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
219
wdenk21136db2003-07-16 21:53:01 +0000220 /* mask all interrupts */
221#if defined(CONFIG_MGT5100)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100222 out_be32(&intr->per_mask, 0xfffffc00);
wdenk21136db2003-07-16 21:53:01 +0000223#elif defined(CONFIG_MPC5200)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100224 out_be32(&intr->per_mask, 0xffffff00);
wdenk21136db2003-07-16 21:53:01 +0000225#endif
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100226 setbits_be32(&intr->main_mask, 0x0001ffff);
227 clrbits_be32(&intr->ctrl, 0x00000f00);
wdenkf5547d32003-09-16 17:06:05 +0000228 /* route critical ints to normal ints */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100229 setbits_be32(&intr->ctrl, 0x00000001);
wdenk21136db2003-07-16 21:53:01 +0000230
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500231#if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
wdenk21136db2003-07-16 21:53:01 +0000232 /* load FEC microcode */
233 loadtask(0, 2);
234#endif
235
236 return (0);
237}