2 * U-boot - main board file
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
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.
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.
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
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
31 #include <asm/blackfin.h>
34 #include <asm/mach-common/bits/bootrom.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 #define POST_WORD_ADDR 0xFF903FFC
43 printf("Board: ADI BF537 stamp board\n");
44 printf(" Support: http://blackfin.uclinux.org/\n");
48 #if defined(CONFIG_BFIN_IDE)
50 void cf_outb(unsigned char val, volatile unsigned char *addr)
56 unsigned char cf_inb(volatile unsigned char *addr)
58 volatile unsigned char c;
66 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
70 for (i = 0; i < words; i++)
71 *(sect_buf + i) = *(addr);
75 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
79 for (i = 0; i < words; i++)
80 *(addr) = *(sect_buf + i);
83 #endif /* CONFIG_BFIN_IDE */
85 phys_size_t initdram(int board_type)
87 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
88 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
89 return gd->bd->bi_memsize;
92 void board_reset(void)
94 /* workaround for weak pull ups on ssel */
95 if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_SPI_MASTER) {
96 bfin_write_PORTF_FER(bfin_read_PORTF_FER() & ~PF10);
97 bfin_write_PORTFIO_SET(PF10);
102 #ifdef CONFIG_BFIN_MAC
103 static void board_init_enetaddr(uchar *mac_addr)
105 #ifdef CONFIG_SYS_NO_FLASH
106 # define USE_MAC_IN_FLASH 0
108 # define USE_MAC_IN_FLASH 1
110 bool valid_mac = false;
112 if (USE_MAC_IN_FLASH) {
113 /* we cram the MAC in the last flash sector */
114 uchar *board_mac_addr = (uchar *)0x203F0000;
115 if (is_valid_ether_addr(board_mac_addr)) {
116 memcpy(mac_addr, board_mac_addr, 6);
122 puts("Warning: Generating 'random' MAC address\n");
123 bfin_gen_rand_mac(mac_addr);
126 eth_setenv_enetaddr("ethaddr", mac_addr);
129 int board_eth_init(bd_t *bis)
131 return bfin_EMAC_initialize(bis);
135 #if defined(CONFIG_MISC_INIT_R)
136 /* miscellaneous platform dependent initialisations */
137 int misc_init_r(void)
139 #ifdef CONFIG_BFIN_MAC
141 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
142 board_init_enetaddr(enetaddr);
145 #ifndef CONFIG_SYS_NO_FLASH
146 /* we use the last sector for the MAC address / POST LDR */
147 extern flash_info_t flash_info[];
148 flash_protect(FLAG_PROTECT_SET, 0x203F0000, 0x203FFFFF, &flash_info[0]);
151 #if defined(CONFIG_BFIN_IDE)
152 #if defined(CONFIG_BFIN_TRUE_IDE)
153 /* Enable ATASEL when in True IDE mode */
154 printf("Using CF True IDE Mode\n");
155 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
157 #elif defined(CONFIG_BFIN_CF_IDE)
158 /* Disable ATASEL when we're in Common Memory Mode */
159 printf("Using CF Common Memory Mode\n");
160 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
162 #elif defined(CONFIG_BFIN_HDD_IDE)
163 printf("Using HDD IDE Mode\n");
166 #endif /* CONFIG_BFIN_IDE */
169 #endif /* CONFIG_MISC_INIT_R */
172 /* Using sw10-PF5 as the hotkey */
173 int post_hotkeys_pressed(void)
177 unsigned short value;
180 *pPORTFIO_DIR &= ~PF5;
181 *pPORTFIO_INEN |= PF5;
183 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
185 for (i = 0; i < 100; i++) {
186 value = *pPORTFIO & PF5;
192 printf("\b\b\b%2d ", delay);
199 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
205 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
206 void post_word_store(ulong a)
208 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
212 ulong post_word_load(void)
214 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
220 int uart_post_test(int flags)
225 #define BLOCK_SIZE 0x10000
226 #define VERIFY_ADDR 0x2000000
227 extern int erase_block_flash(int);
228 extern int write_data(long lStart, long lCount, uchar * pnData);
229 int flash_post_test(int flags)
231 unsigned short *pbuf, *temp;
236 pbuf = (unsigned short *)VERIFY_ADDR;
238 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
239 offset = (n - 7) * BLOCK_SIZE;
240 printf("--------Erase block:%2d..", n);
241 erase_block_flash(n);
243 printf("--------Program block:%2d...", n);
244 write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
246 printf("--------Verify block:%2d...", n);
247 for (i = 0; i < BLOCK_SIZE; i += 2) {
248 if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
260 FLASH_START_POST_BLOCK) *
261 100 / (FLASH_END_POST_BLOCK -
262 FLASH_START_POST_BLOCK)));
274 /****************************************************
275 * LED1 ---- PF6 LED2 ---- PF7 *
276 * LED3 ---- PF8 LED4 ---- PF9 *
277 * LED5 ---- PF10 LED6 ---- PF11 *
278 ****************************************************/
279 int led_post_test(int flags)
281 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
282 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
283 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
284 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
289 printf("\b\b\b\b\b\b\b");
293 printf("\b\b\b\b\b\b\b");
297 printf("\b\b\b\b\b\b\b");
301 printf("\b\b\b\b\b\b\b");
305 printf("\b\b\b\b\b\b\b");
308 printf("\b\b\b\b\b\b\b ");
312 /************************************************
313 * SW10 ---- PF5 SW11 ---- PF4 *
314 * SW12 ---- PF3 SW13 ---- PF2 *
315 ************************************************/
316 int button_post_test(int flags)
319 unsigned short value = 0;
322 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
323 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
324 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
326 printf("\n--------Press SW10: %2d ", delay);
328 for (i = 0; i < 100; i++) {
329 value = *pPORTFIO & PF5;
335 printf("\b\b\b%2d ", delay);
341 printf("\b\bfailed");
345 printf("\n--------Press SW11: %2d ", delay);
347 for (i = 0; i < 100; i++) {
348 value = *pPORTFIO & PF4;
354 printf("\b\b\b%2d ", delay);
360 printf("\b\bfailed");
364 printf("\n--------Press SW12: %2d ", delay);
366 for (i = 0; i < 100; i++) {
367 value = *pPORTFIO & PF3;
373 printf("\b\b\b%2d ", delay);
379 printf("\b\bfailed");
383 printf("\n--------Press SW13: %2d ", delay);
385 for (i = 0; i < 100; i++) {
386 value = *pPORTFIO & PF2;
392 printf("\b\b\b%2d ", delay);
398 printf("\b\bfailed");