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