Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - BF537.c |
| 3 | * |
Aubrey Li | 314d22f | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
Aubrey Li | 10ebdd9 | 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 | 314d22f | 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 | 10ebdd9 | 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 | b9d5787 | 2007-12-10 22:32:14 +0100 | [diff] [blame] | 33 | #include <net.h> |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 34 | #include <asm/mach-common/bits/bootrom.h> |
Ben Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 35 | #include <netdev.h> |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 36 | |
Jean-Christophe PLAGNIOL-VILLARD | b9d5787 | 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 | d112a2c | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 53 | DECLARE_GLOBAL_DATA_PTR; |
| 54 | |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 55 | #define POST_WORD_ADDR 0xFF903FFC |
| 56 | |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 57 | int checkboard(void) |
| 58 | { |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 59 | printf("Board: ADI BF537 stamp board\n"); |
| 60 | printf(" Support: http://blackfin.uclinux.org/\n"); |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | #if defined(CONFIG_BFIN_IDE) |
| 65 | |
| 66 | void cf_outb(unsigned char val, volatile unsigned char *addr) |
| 67 | { |
| 68 | *(addr) = val; |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 69 | SSYNC(); |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | unsigned char cf_inb(volatile unsigned char *addr) |
| 73 | { |
| 74 | volatile unsigned char c; |
| 75 | |
| 76 | c = *(addr); |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 77 | SSYNC(); |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 78 | |
| 79 | return c; |
| 80 | } |
| 81 | |
| 82 | void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words) |
| 83 | { |
| 84 | int i; |
| 85 | |
| 86 | for (i = 0; i < words; i++) |
| 87 | *(sect_buf + i) = *(addr); |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 88 | SSYNC(); |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words) |
| 92 | { |
| 93 | int i; |
| 94 | |
| 95 | for (i = 0; i < words; i++) |
| 96 | *(addr) = *(sect_buf + i); |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 97 | SSYNC(); |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 98 | } |
| 99 | #endif /* CONFIG_BFIN_IDE */ |
| 100 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 101 | phys_size_t initdram(int board_type) |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 102 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; |
| 104 | gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE; |
Mike Frysinger | 9036bf9 | 2008-10-11 20:31:17 -0400 | [diff] [blame^] | 105 | return gd->bd->bi_memsize; |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | #if defined(CONFIG_MISC_INIT_R) |
| 109 | /* miscellaneous platform dependent initialisations */ |
| 110 | int misc_init_r(void) |
| 111 | { |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 112 | #if defined(CONFIG_CMD_NET) |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 113 | char nid[32]; |
| 114 | unsigned char *pMACaddr = (unsigned char *)0x203F0000; |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 115 | |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 116 | /* The 0xFF check here is to make sure we don't use the address |
| 117 | * in flash if it's simply been erased (aka all 0xFF values) */ |
| 118 | if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) { |
| 119 | sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 120 | pMACaddr[0], pMACaddr[1], |
| 121 | pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]); |
| 122 | setenv("ethaddr", nid); |
| 123 | } |
Jon Loeliger | d299abc | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 124 | #endif |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 125 | |
| 126 | #if defined(CONFIG_BFIN_IDE) |
| 127 | #if defined(CONFIG_BFIN_TRUE_IDE) |
| 128 | /* Enable ATASEL when in True IDE mode */ |
| 129 | printf("Using CF True IDE Mode\n"); |
| 130 | cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA); |
| 131 | udelay(1000); |
| 132 | #elif defined(CONFIG_BFIN_CF_IDE) |
| 133 | /* Disable ATASEL when we're in Common Memory Mode */ |
| 134 | printf("Using CF Common Memory Mode\n"); |
| 135 | cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS); |
| 136 | udelay(1000); |
| 137 | #elif defined(CONFIG_BFIN_HDD_IDE) |
| 138 | printf("Using HDD IDE Mode\n"); |
| 139 | #endif |
| 140 | ide_init(); |
| 141 | #endif /* CONFIG_BFIN_IDE */ |
| 142 | return 0; |
| 143 | } |
| 144 | #endif /* CONFIG_MISC_INIT_R */ |
| 145 | |
Ben Warren | 82c2c6a | 2008-07-11 23:15:28 -0700 | [diff] [blame] | 146 | #if defined(CONFIG_BFIN_MAC) |
| 147 | |
Ben Warren | 82c2c6a | 2008-07-11 23:15:28 -0700 | [diff] [blame] | 148 | int board_eth_init(bd_t *bis) |
| 149 | { |
| 150 | return bfin_EMAC_initialize(bis); |
| 151 | } |
| 152 | #endif |
| 153 | |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 154 | #ifdef CONFIG_POST |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 155 | /* Using sw10-PF5 as the hotkey */ |
| 156 | int post_hotkeys_pressed(void) |
| 157 | { |
| 158 | int delay = 3; |
| 159 | int i; |
| 160 | unsigned short value; |
| 161 | |
| 162 | *pPORTF_FER &= ~PF5; |
| 163 | *pPORTFIO_DIR &= ~PF5; |
| 164 | *pPORTFIO_INEN |= PF5; |
| 165 | |
| 166 | printf("########Press SW10 to enter Memory POST########: %2d ", delay); |
| 167 | while (delay--) { |
| 168 | for (i = 0; i < 100; i++) { |
| 169 | value = *pPORTFIO & PF5; |
| 170 | if (value != 0) { |
| 171 | break; |
| 172 | } |
| 173 | udelay(10000); |
| 174 | } |
| 175 | printf("\b\b\b%2d ", delay); |
| 176 | } |
| 177 | printf("\b\b\b 0"); |
| 178 | printf("\n"); |
| 179 | if (value == 0) |
| 180 | return 0; |
| 181 | else { |
| 182 | printf("Hotkey has been pressed, Enter POST . . . . . .\n"); |
| 183 | return 1; |
| 184 | } |
| 185 | } |
| 186 | #endif |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 187 | |
| 188 | #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER) |
| 189 | void post_word_store(ulong a) |
| 190 | { |
| 191 | volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR; |
| 192 | *save_addr = a; |
| 193 | } |
| 194 | |
| 195 | ulong post_word_load(void) |
| 196 | { |
| 197 | volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR; |
| 198 | return *save_addr; |
| 199 | } |
| 200 | #endif |
| 201 | |
| 202 | #ifdef CONFIG_POST |
| 203 | int uart_post_test(int flags) |
| 204 | { |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | #define BLOCK_SIZE 0x10000 |
| 209 | #define VERIFY_ADDR 0x2000000 |
| 210 | extern int erase_block_flash(int); |
| 211 | extern int write_data(long lStart, long lCount, uchar * pnData); |
| 212 | int flash_post_test(int flags) |
| 213 | { |
| 214 | unsigned short *pbuf, *temp; |
| 215 | int offset, n, i; |
| 216 | int value = 0; |
| 217 | int result = 0; |
| 218 | printf("\n"); |
| 219 | pbuf = (unsigned short *)VERIFY_ADDR; |
| 220 | temp = pbuf; |
| 221 | for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) { |
| 222 | offset = (n - 7) * BLOCK_SIZE; |
| 223 | printf("--------Erase block:%2d..", n); |
| 224 | erase_block_flash(n); |
| 225 | printf("OK\r"); |
| 226 | printf("--------Program block:%2d...", n); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 227 | write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf); |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 228 | printf("OK\r"); |
| 229 | printf("--------Verify block:%2d...", n); |
| 230 | for (i = 0; i < BLOCK_SIZE; i += 2) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 231 | if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) != |
Aubrey Li | 10ebdd9 | 2007-03-19 01:24:52 +0800 | [diff] [blame] | 232 | *temp++) { |
| 233 | value = 1; |
| 234 | result = 1; |
| 235 | } |
| 236 | } |
| 237 | if (value) |
| 238 | printf("failed\n"); |
| 239 | else |
| 240 | printf("OK %3d%%\r", |
| 241 | (int)( |
| 242 | (n + 1 - |
| 243 | FLASH_START_POST_BLOCK) * |
| 244 | 100 / (FLASH_END_POST_BLOCK - |
| 245 | FLASH_START_POST_BLOCK))); |
| 246 | |
| 247 | temp = pbuf; |
| 248 | value = 0; |
| 249 | } |
| 250 | printf("\n"); |
| 251 | if (result) |
| 252 | return -1; |
| 253 | else |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /**************************************************** |
| 258 | * LED1 ---- PF6 LED2 ---- PF7 * |
| 259 | * LED3 ---- PF8 LED4 ---- PF9 * |
| 260 | * LED5 ---- PF10 LED6 ---- PF11 * |
| 261 | ****************************************************/ |
| 262 | int led_post_test(int flags) |
| 263 | { |
| 264 | *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11); |
| 265 | *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11; |
| 266 | *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11); |
| 267 | *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11); |
| 268 | udelay(1000000); |
| 269 | printf("LED1 on"); |
| 270 | *pPORTFIO |= PF6; |
| 271 | udelay(1000000); |
| 272 | printf("\b\b\b\b\b\b\b"); |
| 273 | printf("LED2 on"); |
| 274 | *pPORTFIO |= PF7; |
| 275 | udelay(1000000); |
| 276 | printf("\b\b\b\b\b\b\b"); |
| 277 | printf("LED3 on"); |
| 278 | *pPORTFIO |= PF8; |
| 279 | udelay(1000000); |
| 280 | printf("\b\b\b\b\b\b\b"); |
| 281 | printf("LED4 on"); |
| 282 | *pPORTFIO |= PF9; |
| 283 | udelay(1000000); |
| 284 | printf("\b\b\b\b\b\b\b"); |
| 285 | printf("LED5 on"); |
| 286 | *pPORTFIO |= PF10; |
| 287 | udelay(1000000); |
| 288 | printf("\b\b\b\b\b\b\b"); |
| 289 | printf("lED6 on"); |
| 290 | *pPORTFIO |= PF11; |
| 291 | printf("\b\b\b\b\b\b\b "); |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /************************************************ |
| 296 | * SW10 ---- PF5 SW11 ---- PF4 * |
| 297 | * SW12 ---- PF3 SW13 ---- PF2 * |
| 298 | ************************************************/ |
| 299 | int button_post_test(int flags) |
| 300 | { |
| 301 | int i, delay = 5; |
| 302 | unsigned short value = 0; |
| 303 | int result = 0; |
| 304 | |
| 305 | *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2); |
| 306 | *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2); |
| 307 | *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2); |
| 308 | |
| 309 | printf("\n--------Press SW10: %2d ", delay); |
| 310 | while (delay--) { |
| 311 | for (i = 0; i < 100; i++) { |
| 312 | value = *pPORTFIO & PF5; |
| 313 | if (value != 0) { |
| 314 | break; |
| 315 | } |
| 316 | udelay(10000); |
| 317 | } |
| 318 | printf("\b\b\b%2d ", delay); |
| 319 | } |
| 320 | if (value != 0) |
| 321 | printf("\b\bOK"); |
| 322 | else { |
| 323 | result = -1; |
| 324 | printf("\b\bfailed"); |
| 325 | } |
| 326 | |
| 327 | delay = 5; |
| 328 | printf("\n--------Press SW11: %2d ", delay); |
| 329 | while (delay--) { |
| 330 | for (i = 0; i < 100; i++) { |
| 331 | value = *pPORTFIO & PF4; |
| 332 | if (value != 0) { |
| 333 | break; |
| 334 | } |
| 335 | udelay(10000); |
| 336 | } |
| 337 | printf("\b\b\b%2d ", delay); |
| 338 | } |
| 339 | if (value != 0) |
| 340 | printf("\b\bOK"); |
| 341 | else { |
| 342 | result = -1; |
| 343 | printf("\b\bfailed"); |
| 344 | } |
| 345 | |
| 346 | delay = 5; |
| 347 | printf("\n--------Press SW12: %2d ", delay); |
| 348 | while (delay--) { |
| 349 | for (i = 0; i < 100; i++) { |
| 350 | value = *pPORTFIO & PF3; |
| 351 | if (value != 0) { |
| 352 | break; |
| 353 | } |
| 354 | udelay(10000); |
| 355 | } |
| 356 | printf("\b\b\b%2d ", delay); |
| 357 | } |
| 358 | if (value != 0) |
| 359 | printf("\b\bOK"); |
| 360 | else { |
| 361 | result = -1; |
| 362 | printf("\b\bfailed"); |
| 363 | } |
| 364 | |
| 365 | delay = 5; |
| 366 | printf("\n--------Press SW13: %2d ", delay); |
| 367 | while (delay--) { |
| 368 | for (i = 0; i < 100; i++) { |
| 369 | value = *pPORTFIO & PF2; |
| 370 | if (value != 0) { |
| 371 | break; |
| 372 | } |
| 373 | udelay(10000); |
| 374 | } |
| 375 | printf("\b\b\b%2d ", delay); |
| 376 | } |
| 377 | if (value != 0) |
| 378 | printf("\b\bOK"); |
| 379 | else { |
| 380 | result = -1; |
| 381 | printf("\b\bfailed"); |
| 382 | } |
| 383 | printf("\n"); |
| 384 | return result; |
| 385 | } |
| 386 | #endif |