blob: 6954b3003d27fb616392f91141b2492c87351ecc [file] [log] [blame]
Aubrey Li26bf7de2007-03-19 01:24:52 +08001/*
2 * U-boot - BF537.c
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li26bf7de2007-03-19 01:24:52 +08005 *
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
Aubrey Li155fd762007-04-05 18:31:18 +080024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
Aubrey Li26bf7de2007-03-19 01:24:52 +080026 */
27
28#include <common.h>
29#include <config.h>
30#include <command.h>
31#include <asm/blackfin.h>
32#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARDb8f41622007-12-10 22:32:14 +010033#include <net.h>
Aubrey Li26bf7de2007-03-19 01:24:52 +080034#include "ether_bf537.h"
35
Jean-Christophe PLAGNIOL-VILLARDb8f41622007-12-10 22:32:14 +010036/**
37 * is_valid_ether_addr - Determine if the given Ethernet address is valid
38 * @addr: Pointer to a six-byte array containing the Ethernet address
39 *
40 * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not
41 * a multicast address, and is not FF:FF:FF:FF:FF:FF.
42 *
43 * Return true if the address is valid.
44 */
45static inline int is_valid_ether_addr(const u8 * addr)
46{
47 /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to
48 * explicitly check for it here. */
49 return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
50}
51
Wolfgang Denk1218abf2007-09-15 20:48:41 +020052DECLARE_GLOBAL_DATA_PTR;
53
Aubrey Li26bf7de2007-03-19 01:24:52 +080054#define POST_WORD_ADDR 0xFF903FFC
55
56/*
57 * the bootldr command loads an address, checks to see if there
58 * is a Boot stream that the on-chip BOOTROM can understand,
59 * and loads it via the BOOTROM Callback. It is possible
60 * to also add booting from SPI, or TWI, but this function does
61 * not currently support that.
62 */
63int do_bootldr(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
64{
65 ulong addr, entry;
66 ulong *data;
67
68 /* Get the address */
69 if (argc < 2) {
70 addr = load_addr;
71 } else {
72 addr = simple_strtoul(argv[1], NULL, 16);
73 }
74
75 /* Check if it is a LDR file */
76 data = (ulong *) addr;
77 if (*data == 0xFF800060 || *data == 0xFF800040 || *data == 0xFF800020) {
78 /* We want to boot from FLASH or SDRAM */
79 entry = _BOOTROM_BOOT_DXE_FLASH;
80 printf("## Booting ldr image at 0x%08lx ...\n", addr);
81 if (icache_status())
82 icache_disable();
83 if (dcache_status())
84 dcache_disable();
85
86 __asm__("R7=%[a];\n" "P0=%[b];\n" "JUMP (P0);\n":
87 :[a] "d"(addr),[b] "a"(entry)
88 :"R7", "P0");
89
90 } else {
91 printf("## No ldr image at address 0x%08lx\n", addr);
92 }
93
94 return 0;
95}
96
97U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
98 "bootldr - boot ldr image from memory\n",
99 "[addr]\n - boot ldr image stored in memory\n");
100
101int checkboard(void)
102{
103#if (BFIN_CPU == ADSP_BF534)
104 printf("CPU: ADSP BF534 Rev.: 0.%d\n", *pCHIPID >> 28);
105#elif (BFIN_CPU == ADSP_BF536)
106 printf("CPU: ADSP BF536 Rev.: 0.%d\n", *pCHIPID >> 28);
107#else
108 printf("CPU: ADSP BF537 Rev.: 0.%d\n", *pCHIPID >> 28);
109#endif
110 printf("Board: ADI BF537 stamp board\n");
111 printf(" Support: http://blackfin.uclinux.org/\n");
112 return 0;
113}
114
115#if defined(CONFIG_BFIN_IDE)
116
117void cf_outb(unsigned char val, volatile unsigned char *addr)
118{
119 *(addr) = val;
120 sync();
121}
122
123unsigned char cf_inb(volatile unsigned char *addr)
124{
125 volatile unsigned char c;
126
127 c = *(addr);
128 sync();
129
130 return c;
131}
132
133void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
134{
135 int i;
136
137 for (i = 0; i < words; i++)
138 *(sect_buf + i) = *(addr);
139 sync();
140}
141
142void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
143{
144 int i;
145
146 for (i = 0; i < words; i++)
147 *(addr) = *(sect_buf + i);
148 sync();
149}
150#endif /* CONFIG_BFIN_IDE */
151
152long int initdram(int board_type)
153{
Aubrey Li26bf7de2007-03-19 01:24:52 +0800154#ifdef DEBUG
155 int brate;
156 char *tmp = getenv("baudrate");
157 brate = simple_strtoul(tmp, NULL, 16);
158 printf("Serial Port initialized with Baud rate = %x\n", brate);
159 printf("SDRAM attributes:\n");
160 printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
161 "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
162 3, 3, 6, 2, 3);
163 printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
164 printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
165#endif
166 gd->bd->bi_memstart = CFG_SDRAM_BASE;
167 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
168 return CFG_MAX_RAM_SIZE;
169}
170
171#if defined(CONFIG_MISC_INIT_R)
172/* miscellaneous platform dependent initialisations */
173int misc_init_r(void)
174{
175#if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
176 char nid[32];
177 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
178 u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
179
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500180#if defined(CONFIG_CMD_NET)
Aubrey Li26bf7de2007-03-19 01:24:52 +0800181 /* The 0xFF check here is to make sure we don't use the address
182 * in flash if it's simply been erased (aka all 0xFF values) */
183 if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
184 sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
185 pMACaddr[0], pMACaddr[1],
186 pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
187 setenv("ethaddr", nid);
188 }
189 if (getenv("ethaddr")) {
190 SetupMacAddr(SrcAddr);
191 }
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500192#endif
Aubrey Li26bf7de2007-03-19 01:24:52 +0800193#endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
194
195#if defined(CONFIG_BFIN_IDE)
196#if defined(CONFIG_BFIN_TRUE_IDE)
197 /* Enable ATASEL when in True IDE mode */
198 printf("Using CF True IDE Mode\n");
199 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
200 udelay(1000);
201#elif defined(CONFIG_BFIN_CF_IDE)
202 /* Disable ATASEL when we're in Common Memory Mode */
203 printf("Using CF Common Memory Mode\n");
204 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
205 udelay(1000);
206#elif defined(CONFIG_BFIN_HDD_IDE)
207 printf("Using HDD IDE Mode\n");
208#endif
209 ide_init();
210#endif /* CONFIG_BFIN_IDE */
211 return 0;
212}
213#endif /* CONFIG_MISC_INIT_R */
214
215#ifdef CONFIG_POST
216#if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
217/* Using sw10-PF5 as the hotkey */
218int post_hotkeys_pressed(void)
219{
220 return 0;
221}
222#else
223/* Using sw10-PF5 as the hotkey */
224int post_hotkeys_pressed(void)
225{
226 int delay = 3;
227 int i;
228 unsigned short value;
229
230 *pPORTF_FER &= ~PF5;
231 *pPORTFIO_DIR &= ~PF5;
232 *pPORTFIO_INEN |= PF5;
233
234 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
235 while (delay--) {
236 for (i = 0; i < 100; i++) {
237 value = *pPORTFIO & PF5;
238 if (value != 0) {
239 break;
240 }
241 udelay(10000);
242 }
243 printf("\b\b\b%2d ", delay);
244 }
245 printf("\b\b\b 0");
246 printf("\n");
247 if (value == 0)
248 return 0;
249 else {
250 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
251 return 1;
252 }
253}
254#endif
255#endif
256
257#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
258void post_word_store(ulong a)
259{
260 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
261 *save_addr = a;
262}
263
264ulong post_word_load(void)
265{
266 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
267 return *save_addr;
268}
269#endif
270
271#ifdef CONFIG_POST
272int uart_post_test(int flags)
273{
274 return 0;
275}
276
277#define BLOCK_SIZE 0x10000
278#define VERIFY_ADDR 0x2000000
279extern int erase_block_flash(int);
280extern int write_data(long lStart, long lCount, uchar * pnData);
281int flash_post_test(int flags)
282{
283 unsigned short *pbuf, *temp;
284 int offset, n, i;
285 int value = 0;
286 int result = 0;
287 printf("\n");
288 pbuf = (unsigned short *)VERIFY_ADDR;
289 temp = pbuf;
290 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
291 offset = (n - 7) * BLOCK_SIZE;
292 printf("--------Erase block:%2d..", n);
293 erase_block_flash(n);
294 printf("OK\r");
295 printf("--------Program block:%2d...", n);
296 write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
297 printf("OK\r");
298 printf("--------Verify block:%2d...", n);
299 for (i = 0; i < BLOCK_SIZE; i += 2) {
300 if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
301 *temp++) {
302 value = 1;
303 result = 1;
304 }
305 }
306 if (value)
307 printf("failed\n");
308 else
309 printf("OK %3d%%\r",
310 (int)(
311 (n + 1 -
312 FLASH_START_POST_BLOCK) *
313 100 / (FLASH_END_POST_BLOCK -
314 FLASH_START_POST_BLOCK)));
315
316 temp = pbuf;
317 value = 0;
318 }
319 printf("\n");
320 if (result)
321 return -1;
322 else
323 return 0;
324}
325
326/****************************************************
327 * LED1 ---- PF6 LED2 ---- PF7 *
328 * LED3 ---- PF8 LED4 ---- PF9 *
329 * LED5 ---- PF10 LED6 ---- PF11 *
330 ****************************************************/
331int led_post_test(int flags)
332{
333 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
334 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
335 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
336 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
337 udelay(1000000);
338 printf("LED1 on");
339 *pPORTFIO |= PF6;
340 udelay(1000000);
341 printf("\b\b\b\b\b\b\b");
342 printf("LED2 on");
343 *pPORTFIO |= PF7;
344 udelay(1000000);
345 printf("\b\b\b\b\b\b\b");
346 printf("LED3 on");
347 *pPORTFIO |= PF8;
348 udelay(1000000);
349 printf("\b\b\b\b\b\b\b");
350 printf("LED4 on");
351 *pPORTFIO |= PF9;
352 udelay(1000000);
353 printf("\b\b\b\b\b\b\b");
354 printf("LED5 on");
355 *pPORTFIO |= PF10;
356 udelay(1000000);
357 printf("\b\b\b\b\b\b\b");
358 printf("lED6 on");
359 *pPORTFIO |= PF11;
360 printf("\b\b\b\b\b\b\b ");
361 return 0;
362}
363
364/************************************************
365 * SW10 ---- PF5 SW11 ---- PF4 *
366 * SW12 ---- PF3 SW13 ---- PF2 *
367 ************************************************/
368int button_post_test(int flags)
369{
370 int i, delay = 5;
371 unsigned short value = 0;
372 int result = 0;
373
374 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
375 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
376 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
377
378 printf("\n--------Press SW10: %2d ", delay);
379 while (delay--) {
380 for (i = 0; i < 100; i++) {
381 value = *pPORTFIO & PF5;
382 if (value != 0) {
383 break;
384 }
385 udelay(10000);
386 }
387 printf("\b\b\b%2d ", delay);
388 }
389 if (value != 0)
390 printf("\b\bOK");
391 else {
392 result = -1;
393 printf("\b\bfailed");
394 }
395
396 delay = 5;
397 printf("\n--------Press SW11: %2d ", delay);
398 while (delay--) {
399 for (i = 0; i < 100; i++) {
400 value = *pPORTFIO & PF4;
401 if (value != 0) {
402 break;
403 }
404 udelay(10000);
405 }
406 printf("\b\b\b%2d ", delay);
407 }
408 if (value != 0)
409 printf("\b\bOK");
410 else {
411 result = -1;
412 printf("\b\bfailed");
413 }
414
415 delay = 5;
416 printf("\n--------Press SW12: %2d ", delay);
417 while (delay--) {
418 for (i = 0; i < 100; i++) {
419 value = *pPORTFIO & PF3;
420 if (value != 0) {
421 break;
422 }
423 udelay(10000);
424 }
425 printf("\b\b\b%2d ", delay);
426 }
427 if (value != 0)
428 printf("\b\bOK");
429 else {
430 result = -1;
431 printf("\b\bfailed");
432 }
433
434 delay = 5;
435 printf("\n--------Press SW13: %2d ", delay);
436 while (delay--) {
437 for (i = 0; i < 100; i++) {
438 value = *pPORTFIO & PF2;
439 if (value != 0) {
440 break;
441 }
442 udelay(10000);
443 }
444 printf("\b\b\b%2d ", delay);
445 }
446 if (value != 0)
447 printf("\b\bOK");
448 else {
449 result = -1;
450 printf("\b\bfailed");
451 }
452 printf("\n");
453 return result;
454}
455#endif