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