3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 #include <405gp_enet.h>
27 #include <asm/processor.h>
31 #define mtebc(reg, data) mtdcr(ebccfga,reg);mtdcr(ebccfgd,data)
33 #ifdef CFG_INIT_DCACHE_CS
34 # if (CFG_INIT_DCACHE_CS == 0)
37 # if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
38 # define PBxAP_VAL CFG_EBC_PB0AP
39 # define PBxCR_VAL CFG_EBC_PB0CR
42 # if (CFG_INIT_DCACHE_CS == 1)
45 # if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
46 # define PBxAP_VAL CFG_EBC_PB1AP
47 # define PBxCR_VAL CFG_EBC_PB1CR
50 # if (CFG_INIT_DCACHE_CS == 2)
53 # if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
54 # define PBxAP_VAL CFG_EBC_PB2AP
55 # define PBxCR_VAL CFG_EBC_PB2CR
58 # if (CFG_INIT_DCACHE_CS == 3)
61 # if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
62 # define PBxAP_VAL CFG_EBC_PB3AP
63 # define PBxCR_VAL CFG_EBC_PB3CR
66 # if (CFG_INIT_DCACHE_CS == 4)
69 # if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
70 # define PBxAP_VAL CFG_EBC_PB4AP
71 # define PBxCR_VAL CFG_EBC_PB4CR
74 # if (CFG_INIT_DCACHE_CS == 5)
77 # if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
78 # define PBxAP_VAL CFG_EBC_PB5AP
79 # define PBxCR_VAL CFG_EBC_PB5CR
82 # if (CFG_INIT_DCACHE_CS == 6)
85 # if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
86 # define PBxAP_VAL CFG_EBC_PB6AP
87 # define PBxCR_VAL CFG_EBC_PB6CR
90 # if (CFG_INIT_DCACHE_CS == 7)
93 # if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
94 # define PBxAP_VAL CFG_EBC_PB7AP
95 # define PBxCR_VAL CFG_EBC_PB7CR
98 #endif /* CFG_INIT_DCACHE_CS */
102 * Breath some life into the CPU...
104 * Set up the memory map,
105 * initialize a bunch of registers
110 #if defined(CONFIG_405EP)
112 * GPIO0 setup (select GPIO or alternate function)
114 out32(GPIO0_OSRH, CFG_GPIO0_OSRH); /* output select */
115 out32(GPIO0_OSRL, CFG_GPIO0_OSRL);
116 out32(GPIO0_ISR1H, CFG_GPIO0_ISR1H); /* input select */
117 out32(GPIO0_ISR1L, CFG_GPIO0_ISR1L);
118 out32(GPIO0_TSRH, CFG_GPIO0_TSRH); /* three-state select */
119 out32(GPIO0_TSRL, CFG_GPIO0_TSRL);
120 out32(GPIO0_TCR, CFG_GPIO0_TCR); /* enable output driver for outputs */
123 * Set EMAC noise filter bits
125 mtdcr(cpc0_epctl, CPC0_EPRCSR_E0NFE | CPC0_EPRCSR_E1NFE);
126 #endif /* CONFIG_405EP */
129 * External Bus Controller (EBC) Setup
131 #if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
133 * Move the next instructions into icache, since these modify the flash
134 * we are running from!
136 asm volatile(" bl 0f" ::: "lr");
137 asm volatile("0: mflr 3" ::: "r3");
138 asm volatile(" addi 4, 0, 14" ::: "r4");
139 asm volatile(" mtctr 4" ::: "ctr");
140 asm volatile("1: icbt 0, 3");
141 asm volatile(" addi 3, 3, 32" ::: "r3");
142 asm volatile(" bdnz 1b" ::: "ctr", "cr0");
143 asm volatile(" addis 3, 0, 0x0" ::: "r3");
144 asm volatile(" ori 3, 3, 0xA000" ::: "r3");
145 asm volatile(" mtctr 3" ::: "ctr");
146 asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
148 mtebc(pb0ap, CFG_EBC_PB0AP);
149 mtebc(pb0cr, CFG_EBC_PB0CR);
152 #if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR) && !(CFG_INIT_DCACHE_CS == 1))
153 mtebc(pb1ap, CFG_EBC_PB1AP);
154 mtebc(pb1cr, CFG_EBC_PB1CR);
157 #if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR) && !(CFG_INIT_DCACHE_CS == 2))
158 mtebc(pb2ap, CFG_EBC_PB2AP);
159 mtebc(pb2cr, CFG_EBC_PB2CR);
162 #if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR) && !(CFG_INIT_DCACHE_CS == 3))
163 mtebc(pb3ap, CFG_EBC_PB3AP);
164 mtebc(pb3cr, CFG_EBC_PB3CR);
167 #if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR) && !(CFG_INIT_DCACHE_CS == 4))
168 mtebc(pb4ap, CFG_EBC_PB4AP);
169 mtebc(pb4cr, CFG_EBC_PB4CR);
172 #if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR) && !(CFG_INIT_DCACHE_CS == 5))
173 mtebc(pb5ap, CFG_EBC_PB5AP);
174 mtebc(pb5cr, CFG_EBC_PB5CR);
177 #if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR) && !(CFG_INIT_DCACHE_CS == 6))
178 mtebc(pb6ap, CFG_EBC_PB6AP);
179 mtebc(pb6cr, CFG_EBC_PB6CR);
182 #if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR) && !(CFG_INIT_DCACHE_CS == 7))
183 mtebc(pb7ap, CFG_EBC_PB7AP);
184 mtebc(pb7cr, CFG_EBC_PB7CR);
187 #if defined(CONFIG_WATCHDOG)
191 val |= 0xf0000000; /* generate system reset after 2.684 seconds */
195 val |= 0x80000000; /* enable watchdog timer */
198 reset_4xx_watchdog();
199 #endif /* CONFIG_WATCHDOG */
203 * initialize higher level parts of CPU like time base and timers
205 int cpu_init_r (void)
207 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
208 DECLARE_GLOBAL_DATA_PTR;
212 #if defined(CONFIG_405GP)
213 uint pvr = get_pvr();
216 #ifdef CFG_INIT_DCACHE_CS
218 * Flush and invalidate dcache, then disable CS for temporary stack.
219 * Afterwards, this CS can be used for other purposes
221 dcache_disable(); /* flush and invalidate dcache */
223 mtebc(PBxCR, 0); /* disable CS for temporary stack */
225 #if (defined(PBxAP_VAL) && defined(PBxCR_VAL))
227 * Write new value into CS register
229 mtebc(PBxAP, PBxAP_VAL);
230 mtebc(PBxCR, PBxCR_VAL);
232 #endif /* CFG_INIT_DCACHE_CS */
235 * Write Ethernetaddress into on-chip register
238 reg |= bd->bi_enetaddr[0]; /* set high address */
240 reg |= bd->bi_enetaddr[1];
241 out32 (EMAC_IAH, reg);
244 reg |= bd->bi_enetaddr[2]; /* set low address */
246 reg |= bd->bi_enetaddr[3];
248 reg |= bd->bi_enetaddr[4];
250 reg |= bd->bi_enetaddr[5];
251 out32 (EMAC_IAL, reg);
253 #if defined(CONFIG_405GP)
255 * Set edge conditioning circuitry on PPC405GPr
256 * for compatibility to existing PPC405GP designs.
258 if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
259 mtdcr(ecr, 0x60606000);
261 #endif /* defined(CONFIG_405GP) */
262 #endif /* defined(CONFIG_405GP) || defined(CONFIG_405EP) */