blob: a9b7a68c549914c5840576ca07ffe8ecb0270932 [file] [log] [blame]
Aubrey Li26bf7de2007-03-19 01:24:52 +08001/*
2 * U-boot - BF537.c
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li26bf7de2007-03-19 01:24:52 +08005 *
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
Aubrey Li155fd762007-04-05 18:31:18 +080024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
Aubrey Li26bf7de2007-03-19 01:24:52 +080026 */
27
28#include <common.h>
29#include <config.h>
30#include <command.h>
31#include <asm/blackfin.h>
32#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARDb8f41622007-12-10 22:32:14 +010033#include <net.h>
Mike Frysingerd4d77302008-02-04 19:26:55 -050034#include <asm/mach-common/bits/bootrom.h>
Aubrey Li26bf7de2007-03-19 01:24:52 +080035
Jean-Christophe PLAGNIOL-VILLARDb8f41622007-12-10 22:32:14 +010036/**
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 */
45static 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
Wolfgang Denk1218abf2007-09-15 20:48:41 +020052DECLARE_GLOBAL_DATA_PTR;
53
Aubrey Li26bf7de2007-03-19 01:24:52 +080054#define POST_WORD_ADDR 0xFF903FFC
55
Aubrey Li26bf7de2007-03-19 01:24:52 +080056int checkboard(void)
57{
Aubrey Li26bf7de2007-03-19 01:24:52 +080058 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
65void cf_outb(unsigned char val, volatile unsigned char *addr)
66{
67 *(addr) = val;
Mike Frysingerd4d77302008-02-04 19:26:55 -050068 SSYNC();
Aubrey Li26bf7de2007-03-19 01:24:52 +080069}
70
71unsigned char cf_inb(volatile unsigned char *addr)
72{
73 volatile unsigned char c;
74
75 c = *(addr);
Mike Frysingerd4d77302008-02-04 19:26:55 -050076 SSYNC();
Aubrey Li26bf7de2007-03-19 01:24:52 +080077
78 return c;
79}
80
81void 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);
Mike Frysingerd4d77302008-02-04 19:26:55 -050087 SSYNC();
Aubrey Li26bf7de2007-03-19 01:24:52 +080088}
89
90void 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);
Mike Frysingerd4d77302008-02-04 19:26:55 -050096 SSYNC();
Aubrey Li26bf7de2007-03-19 01:24:52 +080097}
98#endif /* CONFIG_BFIN_IDE */
99
Becky Bruce9973e3c2008-06-09 16:03:40 -0500100phys_size_t initdram(int board_type)
Aubrey Li26bf7de2007-03-19 01:24:52 +0800101{
Aubrey Li26bf7de2007-03-19 01:24:52 +0800102#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 */
121int misc_init_r(void)
122{
Mike Frysinger9171fc82008-03-30 15:46:13 -0400123#if defined(CONFIG_CMD_NET)
Aubrey Li26bf7de2007-03-19 01:24:52 +0800124 char nid[32];
125 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
Aubrey Li26bf7de2007-03-19 01:24:52 +0800126
Aubrey Li26bf7de2007-03-19 01:24:52 +0800127 /* The 0xFF check here is to make sure we don't use the address
128 * in flash if it's simply been erased (aka all 0xFF values) */
129 if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
130 sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
131 pMACaddr[0], pMACaddr[1],
132 pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
133 setenv("ethaddr", nid);
134 }
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500135#endif
Aubrey Li26bf7de2007-03-19 01:24:52 +0800136
137#if defined(CONFIG_BFIN_IDE)
138#if defined(CONFIG_BFIN_TRUE_IDE)
139 /* Enable ATASEL when in True IDE mode */
140 printf("Using CF True IDE Mode\n");
141 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
142 udelay(1000);
143#elif defined(CONFIG_BFIN_CF_IDE)
144 /* Disable ATASEL when we're in Common Memory Mode */
145 printf("Using CF Common Memory Mode\n");
146 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
147 udelay(1000);
148#elif defined(CONFIG_BFIN_HDD_IDE)
149 printf("Using HDD IDE Mode\n");
150#endif
151 ide_init();
152#endif /* CONFIG_BFIN_IDE */
153 return 0;
154}
155#endif /* CONFIG_MISC_INIT_R */
156
Ben Warren91494732008-07-11 23:15:28 -0700157#if defined(CONFIG_BFIN_MAC)
158
159extern int bfin_EMAC_initialize(bd_t *bis);
160
161int board_eth_init(bd_t *bis)
162{
163 return bfin_EMAC_initialize(bis);
164}
165#endif
166
Aubrey Li26bf7de2007-03-19 01:24:52 +0800167#ifdef CONFIG_POST
Aubrey Li26bf7de2007-03-19 01:24:52 +0800168/* Using sw10-PF5 as the hotkey */
169int 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
Aubrey Li26bf7de2007-03-19 01:24:52 +0800200
201#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
202void post_word_store(ulong a)
203{
204 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
205 *save_addr = a;
206}
207
208ulong post_word_load(void)
209{
210 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
211 return *save_addr;
212}
213#endif
214
215#ifdef CONFIG_POST
216int uart_post_test(int flags)
217{
218 return 0;
219}
220
221#define BLOCK_SIZE 0x10000
222#define VERIFY_ADDR 0x2000000
223extern int erase_block_flash(int);
224extern int write_data(long lStart, long lCount, uchar * pnData);
225int flash_post_test(int flags)
226{
227 unsigned short *pbuf, *temp;
228 int offset, n, i;
229 int value = 0;
230 int result = 0;
231 printf("\n");
232 pbuf = (unsigned short *)VERIFY_ADDR;
233 temp = pbuf;
234 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
235 offset = (n - 7) * BLOCK_SIZE;
236 printf("--------Erase block:%2d..", n);
237 erase_block_flash(n);
238 printf("OK\r");
239 printf("--------Program block:%2d...", n);
240 write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
241 printf("OK\r");
242 printf("--------Verify block:%2d...", n);
243 for (i = 0; i < BLOCK_SIZE; i += 2) {
244 if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
245 *temp++) {
246 value = 1;
247 result = 1;
248 }
249 }
250 if (value)
251 printf("failed\n");
252 else
253 printf("OK %3d%%\r",
254 (int)(
255 (n + 1 -
256 FLASH_START_POST_BLOCK) *
257 100 / (FLASH_END_POST_BLOCK -
258 FLASH_START_POST_BLOCK)));
259
260 temp = pbuf;
261 value = 0;
262 }
263 printf("\n");
264 if (result)
265 return -1;
266 else
267 return 0;
268}
269
270/****************************************************
271 * LED1 ---- PF6 LED2 ---- PF7 *
272 * LED3 ---- PF8 LED4 ---- PF9 *
273 * LED5 ---- PF10 LED6 ---- PF11 *
274 ****************************************************/
275int led_post_test(int flags)
276{
277 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
278 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
279 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
280 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
281 udelay(1000000);
282 printf("LED1 on");
283 *pPORTFIO |= PF6;
284 udelay(1000000);
285 printf("\b\b\b\b\b\b\b");
286 printf("LED2 on");
287 *pPORTFIO |= PF7;
288 udelay(1000000);
289 printf("\b\b\b\b\b\b\b");
290 printf("LED3 on");
291 *pPORTFIO |= PF8;
292 udelay(1000000);
293 printf("\b\b\b\b\b\b\b");
294 printf("LED4 on");
295 *pPORTFIO |= PF9;
296 udelay(1000000);
297 printf("\b\b\b\b\b\b\b");
298 printf("LED5 on");
299 *pPORTFIO |= PF10;
300 udelay(1000000);
301 printf("\b\b\b\b\b\b\b");
302 printf("lED6 on");
303 *pPORTFIO |= PF11;
304 printf("\b\b\b\b\b\b\b ");
305 return 0;
306}
307
308/************************************************
309 * SW10 ---- PF5 SW11 ---- PF4 *
310 * SW12 ---- PF3 SW13 ---- PF2 *
311 ************************************************/
312int button_post_test(int flags)
313{
314 int i, delay = 5;
315 unsigned short value = 0;
316 int result = 0;
317
318 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
319 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
320 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
321
322 printf("\n--------Press SW10: %2d ", delay);
323 while (delay--) {
324 for (i = 0; i < 100; i++) {
325 value = *pPORTFIO & PF5;
326 if (value != 0) {
327 break;
328 }
329 udelay(10000);
330 }
331 printf("\b\b\b%2d ", delay);
332 }
333 if (value != 0)
334 printf("\b\bOK");
335 else {
336 result = -1;
337 printf("\b\bfailed");
338 }
339
340 delay = 5;
341 printf("\n--------Press SW11: %2d ", delay);
342 while (delay--) {
343 for (i = 0; i < 100; i++) {
344 value = *pPORTFIO & PF4;
345 if (value != 0) {
346 break;
347 }
348 udelay(10000);
349 }
350 printf("\b\b\b%2d ", delay);
351 }
352 if (value != 0)
353 printf("\b\bOK");
354 else {
355 result = -1;
356 printf("\b\bfailed");
357 }
358
359 delay = 5;
360 printf("\n--------Press SW12: %2d ", delay);
361 while (delay--) {
362 for (i = 0; i < 100; i++) {
363 value = *pPORTFIO & PF3;
364 if (value != 0) {
365 break;
366 }
367 udelay(10000);
368 }
369 printf("\b\b\b%2d ", delay);
370 }
371 if (value != 0)
372 printf("\b\bOK");
373 else {
374 result = -1;
375 printf("\b\bfailed");
376 }
377
378 delay = 5;
379 printf("\n--------Press SW13: %2d ", delay);
380 while (delay--) {
381 for (i = 0; i < 100; i++) {
382 value = *pPORTFIO & PF2;
383 if (value != 0) {
384 break;
385 }
386 udelay(10000);
387 }
388 printf("\b\b\b%2d ", delay);
389 }
390 if (value != 0)
391 printf("\b\bOK");
392 else {
393 result = -1;
394 printf("\b\bfailed");
395 }
396 printf("\n");
397 return result;
398}
399#endif