]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/bf537-stamp/bf537-stamp.c
Blackfin: move bootldr command to common code
[people/ms/u-boot.git] / board / bf537-stamp / bf537-stamp.c
1 /*
2 * U-boot - BF537.c
3 *
4 * Copyright (c) 2005-2007 Analog Devices Inc.
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
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
26 */
27
28 #include <common.h>
29 #include <config.h>
30 #include <command.h>
31 #include <asm/blackfin.h>
32 #include <asm/io.h>
33 #include <net.h>
34 #include "ether_bf537.h"
35 #include <asm/mach-common/bits/bootrom.h>
36
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
53 DECLARE_GLOBAL_DATA_PTR;
54
55 #define POST_WORD_ADDR 0xFF903FFC
56
57 int checkboard(void)
58 {
59 #if (BFIN_CPU == ADSP_BF534)
60 printf("CPU: ADSP BF534 Rev.: 0.%d\n", *pCHIPID >> 28);
61 #elif (BFIN_CPU == ADSP_BF536)
62 printf("CPU: ADSP BF536 Rev.: 0.%d\n", *pCHIPID >> 28);
63 #else
64 printf("CPU: ADSP BF537 Rev.: 0.%d\n", *pCHIPID >> 28);
65 #endif
66 printf("Board: ADI BF537 stamp board\n");
67 printf(" Support: http://blackfin.uclinux.org/\n");
68 return 0;
69 }
70
71 #if defined(CONFIG_BFIN_IDE)
72
73 void cf_outb(unsigned char val, volatile unsigned char *addr)
74 {
75 *(addr) = val;
76 SSYNC();
77 }
78
79 unsigned char cf_inb(volatile unsigned char *addr)
80 {
81 volatile unsigned char c;
82
83 c = *(addr);
84 SSYNC();
85
86 return c;
87 }
88
89 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
90 {
91 int i;
92
93 for (i = 0; i < words; i++)
94 *(sect_buf + i) = *(addr);
95 SSYNC();
96 }
97
98 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
99 {
100 int i;
101
102 for (i = 0; i < words; i++)
103 *(addr) = *(sect_buf + i);
104 SSYNC();
105 }
106 #endif /* CONFIG_BFIN_IDE */
107
108 long int initdram(int board_type)
109 {
110 #ifdef DEBUG
111 int brate;
112 char *tmp = getenv("baudrate");
113 brate = simple_strtoul(tmp, NULL, 16);
114 printf("Serial Port initialized with Baud rate = %x\n", brate);
115 printf("SDRAM attributes:\n");
116 printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
117 "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
118 3, 3, 6, 2, 3);
119 printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
120 printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
121 #endif
122 gd->bd->bi_memstart = CFG_SDRAM_BASE;
123 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
124 return CFG_MAX_RAM_SIZE;
125 }
126
127 #if defined(CONFIG_MISC_INIT_R)
128 /* miscellaneous platform dependent initialisations */
129 int misc_init_r(void)
130 {
131 #if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
132 char nid[32];
133 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
134 u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
135
136 #if defined(CONFIG_CMD_NET)
137 /* The 0xFF check here is to make sure we don't use the address
138 * in flash if it's simply been erased (aka all 0xFF values) */
139 if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
140 sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
141 pMACaddr[0], pMACaddr[1],
142 pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
143 setenv("ethaddr", nid);
144 }
145 if (getenv("ethaddr")) {
146 SetupMacAddr(SrcAddr);
147 }
148 #endif
149 #endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
150
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);
156 udelay(1000);
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);
161 udelay(1000);
162 #elif defined(CONFIG_BFIN_HDD_IDE)
163 printf("Using HDD IDE Mode\n");
164 #endif
165 ide_init();
166 #endif /* CONFIG_BFIN_IDE */
167 return 0;
168 }
169 #endif /* CONFIG_MISC_INIT_R */
170
171 #ifdef CONFIG_POST
172 #if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
173 /* Using sw10-PF5 as the hotkey */
174 int post_hotkeys_pressed(void)
175 {
176 return 0;
177 }
178 #else
179 /* Using sw10-PF5 as the hotkey */
180 int post_hotkeys_pressed(void)
181 {
182 int delay = 3;
183 int i;
184 unsigned short value;
185
186 *pPORTF_FER &= ~PF5;
187 *pPORTFIO_DIR &= ~PF5;
188 *pPORTFIO_INEN |= PF5;
189
190 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
191 while (delay--) {
192 for (i = 0; i < 100; i++) {
193 value = *pPORTFIO & PF5;
194 if (value != 0) {
195 break;
196 }
197 udelay(10000);
198 }
199 printf("\b\b\b%2d ", delay);
200 }
201 printf("\b\b\b 0");
202 printf("\n");
203 if (value == 0)
204 return 0;
205 else {
206 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
207 return 1;
208 }
209 }
210 #endif
211 #endif
212
213 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
214 void post_word_store(ulong a)
215 {
216 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
217 *save_addr = a;
218 }
219
220 ulong post_word_load(void)
221 {
222 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
223 return *save_addr;
224 }
225 #endif
226
227 #ifdef CONFIG_POST
228 int uart_post_test(int flags)
229 {
230 return 0;
231 }
232
233 #define BLOCK_SIZE 0x10000
234 #define VERIFY_ADDR 0x2000000
235 extern int erase_block_flash(int);
236 extern int write_data(long lStart, long lCount, uchar * pnData);
237 int flash_post_test(int flags)
238 {
239 unsigned short *pbuf, *temp;
240 int offset, n, i;
241 int value = 0;
242 int result = 0;
243 printf("\n");
244 pbuf = (unsigned short *)VERIFY_ADDR;
245 temp = pbuf;
246 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
247 offset = (n - 7) * BLOCK_SIZE;
248 printf("--------Erase block:%2d..", n);
249 erase_block_flash(n);
250 printf("OK\r");
251 printf("--------Program block:%2d...", n);
252 write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
253 printf("OK\r");
254 printf("--------Verify block:%2d...", n);
255 for (i = 0; i < BLOCK_SIZE; i += 2) {
256 if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
257 *temp++) {
258 value = 1;
259 result = 1;
260 }
261 }
262 if (value)
263 printf("failed\n");
264 else
265 printf("OK %3d%%\r",
266 (int)(
267 (n + 1 -
268 FLASH_START_POST_BLOCK) *
269 100 / (FLASH_END_POST_BLOCK -
270 FLASH_START_POST_BLOCK)));
271
272 temp = pbuf;
273 value = 0;
274 }
275 printf("\n");
276 if (result)
277 return -1;
278 else
279 return 0;
280 }
281
282 /****************************************************
283 * LED1 ---- PF6 LED2 ---- PF7 *
284 * LED3 ---- PF8 LED4 ---- PF9 *
285 * LED5 ---- PF10 LED6 ---- PF11 *
286 ****************************************************/
287 int led_post_test(int flags)
288 {
289 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
290 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
291 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
292 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
293 udelay(1000000);
294 printf("LED1 on");
295 *pPORTFIO |= PF6;
296 udelay(1000000);
297 printf("\b\b\b\b\b\b\b");
298 printf("LED2 on");
299 *pPORTFIO |= PF7;
300 udelay(1000000);
301 printf("\b\b\b\b\b\b\b");
302 printf("LED3 on");
303 *pPORTFIO |= PF8;
304 udelay(1000000);
305 printf("\b\b\b\b\b\b\b");
306 printf("LED4 on");
307 *pPORTFIO |= PF9;
308 udelay(1000000);
309 printf("\b\b\b\b\b\b\b");
310 printf("LED5 on");
311 *pPORTFIO |= PF10;
312 udelay(1000000);
313 printf("\b\b\b\b\b\b\b");
314 printf("lED6 on");
315 *pPORTFIO |= PF11;
316 printf("\b\b\b\b\b\b\b ");
317 return 0;
318 }
319
320 /************************************************
321 * SW10 ---- PF5 SW11 ---- PF4 *
322 * SW12 ---- PF3 SW13 ---- PF2 *
323 ************************************************/
324 int button_post_test(int flags)
325 {
326 int i, delay = 5;
327 unsigned short value = 0;
328 int result = 0;
329
330 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
331 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
332 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
333
334 printf("\n--------Press SW10: %2d ", delay);
335 while (delay--) {
336 for (i = 0; i < 100; i++) {
337 value = *pPORTFIO & PF5;
338 if (value != 0) {
339 break;
340 }
341 udelay(10000);
342 }
343 printf("\b\b\b%2d ", delay);
344 }
345 if (value != 0)
346 printf("\b\bOK");
347 else {
348 result = -1;
349 printf("\b\bfailed");
350 }
351
352 delay = 5;
353 printf("\n--------Press SW11: %2d ", delay);
354 while (delay--) {
355 for (i = 0; i < 100; i++) {
356 value = *pPORTFIO & PF4;
357 if (value != 0) {
358 break;
359 }
360 udelay(10000);
361 }
362 printf("\b\b\b%2d ", delay);
363 }
364 if (value != 0)
365 printf("\b\bOK");
366 else {
367 result = -1;
368 printf("\b\bfailed");
369 }
370
371 delay = 5;
372 printf("\n--------Press SW12: %2d ", delay);
373 while (delay--) {
374 for (i = 0; i < 100; i++) {
375 value = *pPORTFIO & PF3;
376 if (value != 0) {
377 break;
378 }
379 udelay(10000);
380 }
381 printf("\b\b\b%2d ", delay);
382 }
383 if (value != 0)
384 printf("\b\bOK");
385 else {
386 result = -1;
387 printf("\b\bfailed");
388 }
389
390 delay = 5;
391 printf("\n--------Press SW13: %2d ", delay);
392 while (delay--) {
393 for (i = 0; i < 100; i++) {
394 value = *pPORTFIO & PF2;
395 if (value != 0) {
396 break;
397 }
398 udelay(10000);
399 }
400 printf("\b\b\b%2d ", delay);
401 }
402 if (value != 0)
403 printf("\b\bOK");
404 else {
405 result = -1;
406 printf("\b\bfailed");
407 }
408 printf("\n");
409 return result;
410 }
411 #endif