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