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