blob: ac34092d8b8d04d62779635756e1c73722ea598d [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
2 * (C) Copyright 2000
3 * 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 <watchdog.h>
26#include <405gp_enet.h>
27#include <asm/processor.h>
28#include <ppc4xx.h>
29
30
31#define mtebc(reg, data) mtdcr(ebccfga,reg);mtdcr(ebccfgd,data)
32
33
34/*
35 * Breath some life into the CPU...
36 *
37 * Set up the memory map,
38 * initialize a bunch of registers
39 */
40void
41cpu_init_f (void)
42{
stroeseb867d702003-05-23 11:18:02 +000043#if defined(CONFIG_405EP)
44 /*
45 * GPIO0 setup (select GPIO or alternate function)
46 */
47 out32(GPIO0_OSRH, CFG_GPIO0_OSRH); /* output select */
48 out32(GPIO0_OSRL, CFG_GPIO0_OSRL);
49 out32(GPIO0_ISR1H, CFG_GPIO0_ISR1H); /* input select */
50 out32(GPIO0_ISR1L, CFG_GPIO0_ISR1L);
51 out32(GPIO0_TSRH, CFG_GPIO0_TSRH); /* three-state select */
52 out32(GPIO0_TSRL, CFG_GPIO0_TSRL);
53 out32(GPIO0_TCR, CFG_GPIO0_TCR); /* enable output driver for outputs */
54
55 /*
56 * Set EMAC noise filter bits
57 */
58 mtdcr(cpc0_epctl, CPC0_EPRCSR_E0NFE | CPC0_EPRCSR_E1NFE);
59#endif /* CONFIG_405EP */
60
wdenk4a9cbbe2002-08-27 09:48:53 +000061 /*
62 * External Bus Controller (EBC) Setup
63 */
64#if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
65 /*
66 * Move the next instructions into icache, since these modify the flash
67 * we are running from!
68 */
69 asm volatile(" bl 0f" ::: "lr");
70 asm volatile("0: mflr 3" ::: "r3");
71 asm volatile(" addi 4, 0, 14" ::: "r4");
72 asm volatile(" mtctr 4" ::: "ctr");
73 asm volatile("1: icbt 0, 3");
74 asm volatile(" addi 3, 3, 32" ::: "r3");
75 asm volatile(" bdnz 1b" ::: "ctr", "cr0");
76 asm volatile(" addis 3, 0, 0x0" ::: "r3");
77 asm volatile(" ori 3, 3, 0xA000" ::: "r3");
78 asm volatile(" mtctr 3" ::: "ctr");
79 asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
80
81 mtebc(pb0ap, CFG_EBC_PB0AP);
82 mtebc(pb0cr, CFG_EBC_PB0CR);
83#endif
84
85#if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
86 mtebc(pb1ap, CFG_EBC_PB1AP);
87 mtebc(pb1cr, CFG_EBC_PB1CR);
88#endif
89
90#if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
91 mtebc(pb2ap, CFG_EBC_PB2AP);
92 mtebc(pb2cr, CFG_EBC_PB2CR);
93#endif
94
95#if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
96 mtebc(pb3ap, CFG_EBC_PB3AP);
97 mtebc(pb3cr, CFG_EBC_PB3CR);
98#endif
99
100#if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
101 mtebc(pb4ap, CFG_EBC_PB4AP);
102 mtebc(pb4cr, CFG_EBC_PB4CR);
103#endif
104
105#if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
106 mtebc(pb5ap, CFG_EBC_PB5AP);
107 mtebc(pb5cr, CFG_EBC_PB5CR);
108#endif
109
110#if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
111 mtebc(pb6ap, CFG_EBC_PB6AP);
112 mtebc(pb6cr, CFG_EBC_PB6CR);
113#endif
114
115#if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
116 mtebc(pb7ap, CFG_EBC_PB7AP);
117 mtebc(pb7cr, CFG_EBC_PB7CR);
118#endif
119
120#if defined(CONFIG_WATCHDOG)
121 unsigned long val;
122
123 val = mfspr(tcr);
124 val |= 0xf0000000; /* generate system reset after 2.684 seconds */
125 mtspr(tcr, val);
126
127 val = mfspr(tsr);
128 val |= 0x80000000; /* enable watchdog timer */
129 mtspr(tsr, val);
130
131 reset_4xx_watchdog();
132#endif /* CONFIG_WATCHDOG */
133}
134
135/*
136 * initialize higher level parts of CPU like time base and timers
137 */
138int cpu_init_r (void)
139{
stroeseb867d702003-05-23 11:18:02 +0000140#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenk4a9cbbe2002-08-27 09:48:53 +0000141 DECLARE_GLOBAL_DATA_PTR;
142
143 bd_t *bd = gd->bd;
144 unsigned long reg;
stroeseb867d702003-05-23 11:18:02 +0000145#if defined(CONFIG_405GP)
stroese38daa272003-03-20 15:21:50 +0000146 uint pvr = get_pvr();
stroeseb867d702003-05-23 11:18:02 +0000147#endif
wdenk4a9cbbe2002-08-27 09:48:53 +0000148
149 /*
150 * Write Ethernetaddress into on-chip register
151 */
152 reg = 0x00000000;
153 reg |= bd->bi_enetaddr[0]; /* set high address */
154 reg = reg << 8;
155 reg |= bd->bi_enetaddr[1];
156 out32 (EMAC_IAH, reg);
157
158 reg = 0x00000000;
159 reg |= bd->bi_enetaddr[2]; /* set low address */
160 reg = reg << 8;
161 reg |= bd->bi_enetaddr[3];
162 reg = reg << 8;
163 reg |= bd->bi_enetaddr[4];
164 reg = reg << 8;
165 reg |= bd->bi_enetaddr[5];
166 out32 (EMAC_IAL, reg);
stroese38daa272003-03-20 15:21:50 +0000167
stroeseb867d702003-05-23 11:18:02 +0000168#if defined(CONFIG_405GP)
stroese38daa272003-03-20 15:21:50 +0000169 /*
170 * Set edge conditioning circuitry on PPC405GPr
171 * for compatibility to existing PPC405GP designs.
172 */
stroesebaa3d522003-04-04 16:00:33 +0000173 if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
stroese38daa272003-03-20 15:21:50 +0000174 mtdcr(ecr, 0x60606000);
175 }
stroeseb867d702003-05-23 11:18:02 +0000176#endif /* defined(CONFIG_405GP) */
177#endif /* defined(CONFIG_405GP) || defined(CONFIG_405EP) */
wdenk4a9cbbe2002-08-27 09:48:53 +0000178 return (0);
179}