]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/amcc/yosemite/yosemite.c
cmd_nvedit.c: make error message more helpful
[people/ms/u-boot.git] / board / amcc / yosemite / yosemite.c
CommitLineData
c157d8e2 1/*
5a5958b7
SR
2 * (C) Copyright 2006-2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
c157d8e2
SR
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>
b36df561 25#include <asm/ppc4xx.h>
c157d8e2 26#include <asm/processor.h>
5a5958b7 27#include <asm/io.h>
c157d8e2 28#include <spd_sdram.h>
4adb3023
IS
29#include <libfdt.h>
30#include <fdt_support.h>
c157d8e2 31
d87080b7
WD
32DECLARE_GLOBAL_DATA_PTR;
33
6d0f6bcf 34extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
84286386 35
c85b5839
SR
36static inline u32 get_async_pci_freq(void)
37{
38 if (in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) &
39 CONFIG_SYS_BCSR5_PCI66EN)
40 return 66666666;
41 else
42 return 33333333;
43}
44
c157d8e2
SR
45int board_early_init_f(void)
46{
47 register uint reg;
48
49 /*--------------------------------------------------------------------
50 * Setup the external bus controller/chip selects
51 *-------------------------------------------------------------------*/
d1c3b275
SR
52 mtdcr(EBC0_CFGADDR, EBC0_CFG);
53 reg = mfdcr(EBC0_CFGDATA);
54 mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
c157d8e2 55
c157d8e2
SR
56 /*--------------------------------------------------------------------
57 * Setup the GPIO pins
58 *-------------------------------------------------------------------*/
59 /*CPLD cs */
81a3170b
SR
60 /*setup Address lines for flash size 64Meg. */
61 out32(GPIO0_OSRL, in32(GPIO0_OSRL) | 0x50010000);
62 out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x50010000);
63 out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x50000000);
c157d8e2
SR
64
65 /*setup emac */
66 out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xC080);
67 out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x40);
68 out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x55);
69 out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0x50004000);
70 out32(GPIO0_ISR1H, in32(GPIO0_ISR1H) | 0x00440000);
71
72 /*UART1 */
73 out32(GPIO1_TCR, in32(GPIO1_TCR) | 0x02000000);
74 out32(GPIO1_OSRL, in32(GPIO1_OSRL) | 0x00080000);
75 out32(GPIO1_ISR2L, in32(GPIO1_ISR2L) | 0x00010000);
76
e190290b 77 /* external interrupts IRQ0...3 */
b9b2480f
WD
78 out32(GPIO1_TCR, in32(GPIO1_TCR) & ~0x00f00000);
79 out32(GPIO1_TSRL, in32(GPIO1_TSRL) & ~0x0000ff00);
e190290b
SR
80 out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00005500);
81
700200c6 82#ifdef CONFIG_440EP
c157d8e2
SR
83 /*setup USB 2.0 */
84 out32(GPIO1_TCR, in32(GPIO1_TCR) | 0xc0000000);
85 out32(GPIO1_OSRL, in32(GPIO1_OSRL) | 0x50000000);
86 out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xf);
87 out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0xaa);
88 out32(GPIO0_ISR2H, in32(GPIO0_ISR2H) | 0x00000500);
700200c6 89#endif
c157d8e2 90
ef04a0aa
SR
91 /*--------------------------------------------------------------------
92 * Setup the interrupt controller polarities, triggers, etc.
93 *-------------------------------------------------------------------*/
952e7760
SR
94 mtdcr(UIC0SR, 0xffffffff); /* clear all */
95 mtdcr(UIC0ER, 0x00000000); /* disable all */
96 mtdcr(UIC0CR, 0x00000009); /* ATI & UIC1 crit are critical */
97 mtdcr(UIC0PR, 0xfffffe13); /* per ref-board manual */
98 mtdcr(UIC0TR, 0x01c00008); /* per ref-board manual */
99 mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
100 mtdcr(UIC0SR, 0xffffffff); /* clear all */
ef04a0aa 101
952e7760
SR
102 mtdcr(UIC1SR, 0xffffffff); /* clear all */
103 mtdcr(UIC1ER, 0x00000000); /* disable all */
104 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
105 mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
106 mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
107 mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
108 mtdcr(UIC1SR, 0xffffffff); /* clear all */
ef04a0aa 109
c157d8e2
SR
110 /*--------------------------------------------------------------------
111 * Setup other serial configuration
112 *-------------------------------------------------------------------*/
d1c3b275
SR
113 mfsdr(SDR0_PCI0, reg);
114 mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
115 mtsdr(SDR0_PFC0, 0x00003e00); /* Pin function */
116 mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins */
c157d8e2 117
c85b5839
SR
118 /* Check and reconfigure the PCI sync clock if necessary */
119 ppc4xx_pci_sync_clock_config(get_async_pci_freq());
120
c157d8e2 121 /*clear tmrclk divisor */
6d0f6bcf 122 *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x04) = 0x00;
c157d8e2
SR
123
124 /*enable ethernet */
6d0f6bcf 125 *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x08) = 0xf0;
c157d8e2 126
700200c6 127#ifdef CONFIG_440EP
c157d8e2 128 /*enable usb 1.1 fs device and remove usb 2.0 reset */
6d0f6bcf 129 *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x09) = 0x00;
700200c6 130#endif
c157d8e2
SR
131
132 /*get rid of flash write protect */
6d0f6bcf 133 *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x07) = 0x00;
c157d8e2
SR
134
135 return 0;
136}
137
84286386
SR
138int misc_init_r (void)
139{
84286386
SR
140 uint pbcr;
141 int size_val = 0;
142
143 /* Re-do sizing to get full correct info */
d1c3b275
SR
144 mtdcr(EBC0_CFGADDR, PB0CR);
145 pbcr = mfdcr(EBC0_CFGDATA);
84286386
SR
146 switch (gd->bd->bi_flashsize) {
147 case 1 << 20:
148 size_val = 0;
149 break;
150 case 2 << 20:
151 size_val = 1;
152 break;
153 case 4 << 20:
154 size_val = 2;
155 break;
156 case 8 << 20:
157 size_val = 3;
158 break;
159 case 16 << 20:
160 size_val = 4;
161 break;
162 case 32 << 20:
163 size_val = 5;
164 break;
165 case 64 << 20:
166 size_val = 6;
167 break;
168 case 128 << 20:
169 size_val = 7;
170 break;
171 }
172 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
d1c3b275
SR
173 mtdcr(EBC0_CFGADDR, PB0CR);
174 mtdcr(EBC0_CFGDATA, pbcr);
84286386 175
f190c11b
SR
176 /* adjust flash start and offset */
177 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
178 gd->bd->bi_flashoffset = 0;
179
84286386
SR
180 /* Monitor protection ON by default */
181 (void)flash_protect(FLAG_PROTECT_SET,
6d0f6bcf 182 -CONFIG_SYS_MONITOR_LEN,
84286386
SR
183 0xffffffff,
184 &flash_info[0]);
185
186 return 0;
187}
188
c157d8e2
SR
189int checkboard(void)
190{
3d9569b2 191 char *s = getenv("serial#");
36adff36 192 u8 rev;
c85b5839 193 u32 clock = get_async_pci_freq();
c157d8e2 194
700200c6 195#ifdef CONFIG_440EP
93b17ec3 196 printf("Board: Yosemite - AMCC PPC440EP Evaluation Board");
700200c6
SR
197#else
198 printf("Board: Yellowstone - AMCC PPC440GR Evaluation Board");
199#endif
36adff36 200
6d0f6bcf 201 rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
c85b5839 202 printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
36adff36 203
93b17ec3
SR
204 if (s != NULL) {
205 puts(", serial# ");
206 puts(s);
207 }
208 putc('\n');
209
c85b5839
SR
210 /*
211 * Reconfiguration of the PCI sync clock is already done,
212 * now check again if everything is in range:
213 */
214 if (ppc4xx_pci_sync_clock_config(clock)) {
215 printf("ERROR: PCI clocking incorrect (async=%d "
216 "sync=%ld)!\n", clock, get_PCI_freq());
217 }
218
c157d8e2
SR
219 return (0);
220}
221
222/*************************************************************************
bbeff30c 223 * initdram -- doesn't use serial presence detect.
c157d8e2
SR
224 *
225 * Assumes: 256 MB, ECC, non-registered
226 * PLB @ 133 MHz
227 *
228 ************************************************************************/
81a3170b
SR
229#define NUM_TRIES 64
230#define NUM_READS 10
231
232void sdram_tr1_set(int ram_address, int* tr1_value)
233{
234 int i;
235 int j, k;
236 volatile unsigned int* ram_pointer = (unsigned int*)ram_address;
237 int first_good = -1, last_bad = 0x1ff;
238
239 unsigned long test[NUM_TRIES] = {
240 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
241 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
242 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
243 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
244 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
245 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
246 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
247 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
248 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
249 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
250 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
251 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
252 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
253 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
254 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
255 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55 };
256
257 /* go through all possible SDRAM0_TR1[RDCT] values */
258 for (i=0; i<=0x1ff; i++) {
259 /* set the current value for TR1 */
95b602ba 260 mtsdram(SDRAM0_TR1, (0x80800800 | i));
81a3170b
SR
261
262 /* write values */
263 for (j=0; j<NUM_TRIES; j++) {
264 ram_pointer[j] = test[j];
265
266 /* clear any cache at ram location */
267 __asm__("dcbf 0,%0": :"r" (&ram_pointer[j]));
268 }
269
270 /* read values back */
271 for (j=0; j<NUM_TRIES; j++) {
272 for (k=0; k<NUM_READS; k++) {
273 /* clear any cache at ram location */
274 __asm__("dcbf 0,%0": :"r" (&ram_pointer[j]));
275
276 if (ram_pointer[j] != test[j])
277 break;
278 }
279
280 /* read error */
281 if (k != NUM_READS) {
282 break;
283 }
284 }
285
286 /* we have a SDRAM0_TR1[RDCT] that is part of the window */
287 if (j == NUM_TRIES) {
288 if (first_good == -1)
289 first_good = i; /* found beginning of window */
290 } else { /* bad read */
291 /* if we have not had a good read then don't care */
292 if(first_good != -1) {
293 /* first failure after a good read */
294 last_bad = i-1;
295 break;
296 }
297 }
298 }
299
300 /* return the current value for TR1 */
301 *tr1_value = (first_good + last_bad) / 2;
302}
303
9973e3c6 304phys_size_t initdram(int board)
c157d8e2
SR
305{
306 register uint reg;
81a3170b 307 int tr1_bank1, tr1_bank2;
c157d8e2
SR
308
309 /*--------------------------------------------------------------------
310 * Setup some default
311 *------------------------------------------------------------------*/
95b602ba
SR
312 mtsdram(SDRAM0_UABBA, 0x00000000); /* ubba=0 (default) */
313 mtsdram(SDRAM0_SLIO, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
314 mtsdram(SDRAM0_DEVOPT, 0x00000000); /* dll=0 ds=0 (normal) */
315 mtsdram(SDRAM0_CLKTR, 0x40000000); /* ?? */
316 mtsdram(SDRAM0_WDDCTR, 0x40000000); /* ?? */
c157d8e2
SR
317
318 /*clear this first, if the DDR is enabled by a debugger
81a3170b 319 then you can not make changes. */
95b602ba 320 mtsdram(SDRAM0_CFG0, 0x00000000); /* Disable EEC */
c157d8e2
SR
321
322 /*--------------------------------------------------------------------
323 * Setup for board-specific specific mem
324 *------------------------------------------------------------------*/
325 /*
326 * Following for CAS Latency = 2.5 @ 133 MHz PLB
327 */
95b602ba
SR
328 mtsdram(SDRAM0_B0CR, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
329 mtsdram(SDRAM0_B1CR, 0x080a4001); /* SDBA=0x080 128MB, Mode 3, enabled */
c157d8e2 330
95b602ba
SR
331 mtsdram(SDRAM0_TR0, 0x410a4012); /* ?? */
332 mtsdram(SDRAM0_RTR, 0x04080000); /* ?? */
333 mtsdram(SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM */
334 mtsdram(SDRAM0_CFG0, 0x30000000); /* Disable EEC */
c157d8e2
SR
335 udelay(400); /* Delay 200 usecs (min) */
336
337 /*--------------------------------------------------------------------
338 * Enable the controller, then wait for DCEN to complete
339 *------------------------------------------------------------------*/
95b602ba 340 mtsdram(SDRAM0_CFG0, 0x80000000); /* Enable */
c157d8e2
SR
341
342 for (;;) {
95b602ba 343 mfsdram(SDRAM0_MCSTS, reg);
c157d8e2
SR
344 if (reg & 0x80000000)
345 break;
346 }
81a3170b
SR
347
348 sdram_tr1_set(0x00000000, &tr1_bank1);
349 sdram_tr1_set(0x08000000, &tr1_bank2);
95b602ba 350 mtsdram(SDRAM0_TR1, (((tr1_bank1+tr1_bank2)/2) | 0x80800800));
c157d8e2 351
6d0f6bcf 352 return CONFIG_SYS_SDRAM_BANKS * (CONFIG_SYS_KBYTES_SDRAM * 1024); /* return bytes */
c157d8e2
SR
353}
354
c157d8e2
SR
355/*************************************************************************
356 * hw_watchdog_reset
357 *
358 * This routine is called to reset (keep alive) the watchdog timer
359 *
360 ************************************************************************/
361#if defined(CONFIG_HW_WATCHDOG)
362void hw_watchdog_reset(void)
363{
364
365}
366#endif
f3443867
SR
367
368void board_reset(void)
369{
370 /* give reset to BCSR */
6d0f6bcf 371 *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x06) = 0x09;
f3443867 372}