blob: f9b57baf6d3d8108a2f5761633a25a6ac1a541df [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk21136db2003-07-16 21:53:01 +00006 */
7
8#include <common.h>
9#include <mpc5xxx.h>
Detlev Zundel8b29ad52009-12-18 17:35:57 +010010#include <asm/io.h>
Detlev Zundelf7504ec2010-01-20 14:28:48 +010011#include <watchdog.h>
wdenk21136db2003-07-16 21:53:01 +000012
Wolfgang Denk6405a152006-03-31 18:32:53 +020013DECLARE_GLOBAL_DATA_PTR;
14
wdenk21136db2003-07-16 21:53:01 +000015/*
16 * Breath some life into the CPU...
17 *
18 * Set up the memory map,
19 * initialize a bunch of registers.
20 */
21void cpu_init_f (void)
22{
Detlev Zundel8b29ad52009-12-18 17:35:57 +010023 volatile struct mpc5xxx_mmap_ctl *mm =
24 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
25 volatile struct mpc5xxx_lpb *lpb =
26 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
Detlev Zundel8b29ad52009-12-18 17:35:57 +010027 volatile struct mpc5xxx_gpio *gpio =
28 (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
29 volatile struct mpc5xxx_xlb *xlb =
30 (struct mpc5xxx_xlb *) MPC5XXX_XLBARB;
Wolfgang Denke8cb0e82010-01-31 22:03:15 +010031#if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
32 volatile struct mpc5xxx_cdm *cdm =
33 (struct mpc5xxx_cdm *) MPC5XXX_CDM;
34#endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
Wolfgang Denk5012ff32010-01-31 21:58:48 +010035#if defined(CONFIG_WATCHDOG)
Detlev Zundelf7504ec2010-01-20 14:28:48 +010036 volatile struct mpc5xxx_gpt *gpt0 =
37 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
Wolfgang Denk5012ff32010-01-31 21:58:48 +010038#endif /* CONFIG_WATCHDOG */
wdenk21136db2003-07-16 21:53:01 +000039 unsigned long addecr = (1 << 25); /* Boot_CS */
wdenk21136db2003-07-16 21:53:01 +000040 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk21136db2003-07-16 21:53:01 +000042
43 /* Clear initial global data */
44 memset ((void *) gd, 0, sizeof (gd_t));
45
46 /*
47 * Memory Controller: configure chip selects and enable them
48 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049#if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010050 out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
51 out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
52 CONFIG_SYS_BOOTCS_SIZE));
wdenk21136db2003-07-16 21:53:01 +000053#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020054#if defined(CONFIG_SYS_BOOTCS_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010055 out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
wdenk21136db2003-07-16 21:53:01 +000056#endif
57
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058#if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010059 out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
60 out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
61 CONFIG_SYS_CS0_SIZE));
wdenk21136db2003-07-16 21:53:01 +000062 /* CS0 and BOOT_CS cannot be enabled at once. */
63 /* addecr |= (1 << 16); */
64#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065#if defined(CONFIG_SYS_CS0_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010066 out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
wdenk21136db2003-07-16 21:53:01 +000067#endif
68
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010070 out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
71 out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
72 CONFIG_SYS_CS1_SIZE));
wdenk21136db2003-07-16 21:53:01 +000073 addecr |= (1 << 17);
74#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075#if defined(CONFIG_SYS_CS1_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010076 out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
wdenk21136db2003-07-16 21:53:01 +000077#endif
78
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079#if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010080 out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
81 out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
82 CONFIG_SYS_CS2_SIZE));
wdenk21136db2003-07-16 21:53:01 +000083 addecr |= (1 << 18);
84#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085#if defined(CONFIG_SYS_CS2_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010086 out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
wdenk21136db2003-07-16 21:53:01 +000087#endif
88
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089#if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010090 out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
91 out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
92 CONFIG_SYS_CS3_SIZE));
wdenk21136db2003-07-16 21:53:01 +000093 addecr |= (1 << 19);
94#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095#if defined(CONFIG_SYS_CS3_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +010096 out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
wdenk21136db2003-07-16 21:53:01 +000097#endif
98
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099#if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100100 out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
101 out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
102 CONFIG_SYS_CS4_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000103 addecr |= (1 << 20);
104#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105#if defined(CONFIG_SYS_CS4_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100106 out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
wdenk21136db2003-07-16 21:53:01 +0000107#endif
108
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109#if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100110 out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
111 out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
112 CONFIG_SYS_CS5_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000113 addecr |= (1 << 21);
114#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115#if defined(CONFIG_SYS_CS5_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100116 out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
wdenk21136db2003-07-16 21:53:01 +0000117#endif
118
wdenk21136db2003-07-16 21:53:01 +0000119 addecr |= 1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120#if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100121 out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
122 out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
123 CONFIG_SYS_CS6_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000124 addecr |= (1 << 26);
125#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126#if defined(CONFIG_SYS_CS6_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100127 out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
wdenk21136db2003-07-16 21:53:01 +0000128#endif
129
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130#if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100131 out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
132 out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
133 CONFIG_SYS_CS7_SIZE));
wdenk21136db2003-07-16 21:53:01 +0000134 addecr |= (1 << 27);
135#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136#if defined(CONFIG_SYS_CS7_CFG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100137 out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
wdenk21136db2003-07-16 21:53:01 +0000138#endif
139
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140#if defined(CONFIG_SYS_CS_BURST)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100141 out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
wdenk21136db2003-07-16 21:53:01 +0000142#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143#if defined(CONFIG_SYS_CS_DEADCYCLE)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100144 out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
wdenk21136db2003-07-16 21:53:01 +0000145#endif
wdenk21136db2003-07-16 21:53:01 +0000146
147 /* Enable chip selects */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100148 out_be32(&mm->ipbi_ws_ctrl, addecr);
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100149 out_be32(&lpb->cs_ctrl, (1 << 24));
wdenk21136db2003-07-16 21:53:01 +0000150
151 /* Setup pin multiplexing */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200152#if defined(CONFIG_SYS_GPS_PORT_CONFIG)
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100153 out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
wdenk21136db2003-07-16 21:53:01 +0000154#endif
wdenka5ae1f02003-07-31 22:56:30 +0000155
Anatolij Gustschin6d1f5a62012-08-12 23:38:10 +0000156 /* Setup gpios */
157#if defined(CONFIG_SYS_GPIO_DATADIR)
158 out_be32(&gpio->simple_ddr, CONFIG_SYS_GPIO_DATADIR);
159#endif
160#if defined(CONFIG_SYS_GPIO_OPENDRAIN)
161 out_be32(&gpio->simple_ode, CONFIG_SYS_GPIO_OPENDRAIN);
162#endif
163#if defined(CONFIG_SYS_GPIO_DATAVALUE)
164 out_be32(&gpio->simple_dvo, CONFIG_SYS_GPIO_DATAVALUE);
165#endif
166#if defined(CONFIG_SYS_GPIO_ENABLE)
167 out_be32(&gpio->simple_gpioe, CONFIG_SYS_GPIO_ENABLE);
168#endif
169
wdenka5ae1f02003-07-31 22:56:30 +0000170 /* enable timebase */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100171 setbits_be32(&xlb->config, (1 << 13));
wdenkeb20ad32003-09-05 23:19:14 +0000172
Wolfgang Denkdda81342006-04-18 11:05:03 +0200173 /* Enable snooping for RAM */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100174 setbits_be32(&xlb->config, (1 << 15));
175 out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
Wolfgang Denkdda81342006-04-18 11:05:03 +0200176
Detlev Zundela414c7a2010-03-12 10:01:12 +0100177#if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
wdenkeb20ad32003-09-05 23:19:14 +0000178 /* Motorola reports IPB should better run at 133 MHz. */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100179 setbits_be32(&mm->ipbi_ws_ctrl, 1);
wdenkeb20ad32003-09-05 23:19:14 +0000180 /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100181 addecr = in_be32(&cdm->cfg);
wdenkeb20ad32003-09-05 23:19:14 +0000182 addecr &= ~0x103;
Detlev Zundela414c7a2010-03-12 10:01:12 +0100183# if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
wdenk64519362004-07-11 17:40:54 +0000184 /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
185 addecr |= 0x01;
Detlev Zundela414c7a2010-03-12 10:01:12 +0100186# else
wdenk64519362004-07-11 17:40:54 +0000187 /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
wdenkeb20ad32003-09-05 23:19:14 +0000188 addecr |= 0x02;
Detlev Zundela414c7a2010-03-12 10:01:12 +0100189# endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100190 out_be32(&cdm->cfg, addecr);
Detlev Zundela414c7a2010-03-12 10:01:12 +0100191#endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
wdenkf5547d32003-09-16 17:06:05 +0000192 /* Configure the XLB Arbiter */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100193 out_be32(&xlb->master_pri_enable, 0xff);
194 out_be32(&xlb->master_priority, 0x11111111);
wdenk391b5742004-10-10 23:27:33 +0000195
Detlev Zundela414c7a2010-03-12 10:01:12 +0100196#if defined(CONFIG_SYS_XLB_PIPELINING)
wdenk391b5742004-10-10 23:27:33 +0000197 /* Enable piplining */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100198 clrbits_be32(&xlb->config, (1 << 31));
Detlev Zundela414c7a2010-03-12 10:01:12 +0100199#endif
Detlev Zundelf7504ec2010-01-20 14:28:48 +0100200
201#if defined(CONFIG_WATCHDOG)
202 /* Charge the watchdog timer - prescaler = 64k, count = 64k*/
203 out_be32(&gpt0->cir, 0x0000ffff);
204 out_be32(&gpt0->emsr, 0x9004); /* wden|ce|timer_ms */
205
206 reset_5xxx_watchdog();
207#endif /* CONFIG_WATCHDOG */
wdenk21136db2003-07-16 21:53:01 +0000208}
209
210/*
211 * initialize higher level parts of CPU like time base and timers
212 */
213int cpu_init_r (void)
214{
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100215 volatile struct mpc5xxx_intr *intr =
216 (struct mpc5xxx_intr *) MPC5XXX_ICTL;
217
wdenk21136db2003-07-16 21:53:01 +0000218 /* mask all interrupts */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100219 out_be32(&intr->per_mask, 0xffffff00);
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100220 setbits_be32(&intr->main_mask, 0x0001ffff);
221 clrbits_be32(&intr->ctrl, 0x00000f00);
wdenkf5547d32003-09-16 17:06:05 +0000222 /* route critical ints to normal ints */
Detlev Zundel8b29ad52009-12-18 17:35:57 +0100223 setbits_be32(&intr->ctrl, 0x00000001);
wdenk21136db2003-07-16 21:53:01 +0000224
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500225#if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
wdenk21136db2003-07-16 21:53:01 +0000226 /* load FEC microcode */
227 loadtask(0, 2);
228#endif
229
230 return (0);
231}