blob: 919cef688dbdd5992fb225a42a0f9be8a4b1aa7b [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>
33#include "ether_bf537.h"
34
35#define POST_WORD_ADDR 0xFF903FFC
36
37/*
38 * the bootldr command loads an address, checks to see if there
39 * is a Boot stream that the on-chip BOOTROM can understand,
40 * and loads it via the BOOTROM Callback. It is possible
41 * to also add booting from SPI, or TWI, but this function does
42 * not currently support that.
43 */
44int do_bootldr(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
45{
46 ulong addr, entry;
47 ulong *data;
48
49 /* Get the address */
50 if (argc < 2) {
51 addr = load_addr;
52 } else {
53 addr = simple_strtoul(argv[1], NULL, 16);
54 }
55
56 /* Check if it is a LDR file */
57 data = (ulong *) addr;
58 if (*data == 0xFF800060 || *data == 0xFF800040 || *data == 0xFF800020) {
59 /* We want to boot from FLASH or SDRAM */
60 entry = _BOOTROM_BOOT_DXE_FLASH;
61 printf("## Booting ldr image at 0x%08lx ...\n", addr);
62 if (icache_status())
63 icache_disable();
64 if (dcache_status())
65 dcache_disable();
66
67 __asm__("R7=%[a];\n" "P0=%[b];\n" "JUMP (P0);\n":
68 :[a] "d"(addr),[b] "a"(entry)
69 :"R7", "P0");
70
71 } else {
72 printf("## No ldr image at address 0x%08lx\n", addr);
73 }
74
75 return 0;
76}
77
78U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
79 "bootldr - boot ldr image from memory\n",
80 "[addr]\n - boot ldr image stored in memory\n");
81
82int checkboard(void)
83{
84#if (BFIN_CPU == ADSP_BF534)
85 printf("CPU: ADSP BF534 Rev.: 0.%d\n", *pCHIPID >> 28);
86#elif (BFIN_CPU == ADSP_BF536)
87 printf("CPU: ADSP BF536 Rev.: 0.%d\n", *pCHIPID >> 28);
88#else
89 printf("CPU: ADSP BF537 Rev.: 0.%d\n", *pCHIPID >> 28);
90#endif
91 printf("Board: ADI BF537 stamp board\n");
92 printf(" Support: http://blackfin.uclinux.org/\n");
93 return 0;
94}
95
96#if defined(CONFIG_BFIN_IDE)
97
98void cf_outb(unsigned char val, volatile unsigned char *addr)
99{
100 *(addr) = val;
101 sync();
102}
103
104unsigned char cf_inb(volatile unsigned char *addr)
105{
106 volatile unsigned char c;
107
108 c = *(addr);
109 sync();
110
111 return c;
112}
113
114void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
115{
116 int i;
117
118 for (i = 0; i < words; i++)
119 *(sect_buf + i) = *(addr);
120 sync();
121}
122
123void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
124{
125 int i;
126
127 for (i = 0; i < words; i++)
128 *(addr) = *(sect_buf + i);
129 sync();
130}
131#endif /* CONFIG_BFIN_IDE */
132
133long int initdram(int board_type)
134{
135 DECLARE_GLOBAL_DATA_PTR;
136#ifdef DEBUG
137 int brate;
138 char *tmp = getenv("baudrate");
139 brate = simple_strtoul(tmp, NULL, 16);
140 printf("Serial Port initialized with Baud rate = %x\n", brate);
141 printf("SDRAM attributes:\n");
142 printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
143 "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
144 3, 3, 6, 2, 3);
145 printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
146 printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
147#endif
148 gd->bd->bi_memstart = CFG_SDRAM_BASE;
149 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
150 return CFG_MAX_RAM_SIZE;
151}
152
153#if defined(CONFIG_MISC_INIT_R)
154/* miscellaneous platform dependent initialisations */
155int misc_init_r(void)
156{
157#if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
158 char nid[32];
159 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
160 u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
161
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500162#if defined(CONFIG_CMD_NET)
Aubrey Li26bf7de2007-03-19 01:24:52 +0800163 /* The 0xFF check here is to make sure we don't use the address
164 * in flash if it's simply been erased (aka all 0xFF values) */
165 if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
166 sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
167 pMACaddr[0], pMACaddr[1],
168 pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
169 setenv("ethaddr", nid);
170 }
171 if (getenv("ethaddr")) {
172 SetupMacAddr(SrcAddr);
173 }
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500174#endif
Aubrey Li26bf7de2007-03-19 01:24:52 +0800175#endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
176
177#if defined(CONFIG_BFIN_IDE)
178#if defined(CONFIG_BFIN_TRUE_IDE)
179 /* Enable ATASEL when in True IDE mode */
180 printf("Using CF True IDE Mode\n");
181 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
182 udelay(1000);
183#elif defined(CONFIG_BFIN_CF_IDE)
184 /* Disable ATASEL when we're in Common Memory Mode */
185 printf("Using CF Common Memory Mode\n");
186 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
187 udelay(1000);
188#elif defined(CONFIG_BFIN_HDD_IDE)
189 printf("Using HDD IDE Mode\n");
190#endif
191 ide_init();
192#endif /* CONFIG_BFIN_IDE */
193 return 0;
194}
195#endif /* CONFIG_MISC_INIT_R */
196
197#ifdef CONFIG_POST
198#if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
199/* Using sw10-PF5 as the hotkey */
200int post_hotkeys_pressed(void)
201{
202 return 0;
203}
204#else
205/* Using sw10-PF5 as the hotkey */
206int post_hotkeys_pressed(void)
207{
208 int delay = 3;
209 int i;
210 unsigned short value;
211
212 *pPORTF_FER &= ~PF5;
213 *pPORTFIO_DIR &= ~PF5;
214 *pPORTFIO_INEN |= PF5;
215
216 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
217 while (delay--) {
218 for (i = 0; i < 100; i++) {
219 value = *pPORTFIO & PF5;
220 if (value != 0) {
221 break;
222 }
223 udelay(10000);
224 }
225 printf("\b\b\b%2d ", delay);
226 }
227 printf("\b\b\b 0");
228 printf("\n");
229 if (value == 0)
230 return 0;
231 else {
232 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
233 return 1;
234 }
235}
236#endif
237#endif
238
239#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
240void post_word_store(ulong a)
241{
242 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
243 *save_addr = a;
244}
245
246ulong post_word_load(void)
247{
248 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
249 return *save_addr;
250}
251#endif
252
253#ifdef CONFIG_POST
254int uart_post_test(int flags)
255{
256 return 0;
257}
258
259#define BLOCK_SIZE 0x10000
260#define VERIFY_ADDR 0x2000000
261extern int erase_block_flash(int);
262extern int write_data(long lStart, long lCount, uchar * pnData);
263int flash_post_test(int flags)
264{
265 unsigned short *pbuf, *temp;
266 int offset, n, i;
267 int value = 0;
268 int result = 0;
269 printf("\n");
270 pbuf = (unsigned short *)VERIFY_ADDR;
271 temp = pbuf;
272 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
273 offset = (n - 7) * BLOCK_SIZE;
274 printf("--------Erase block:%2d..", n);
275 erase_block_flash(n);
276 printf("OK\r");
277 printf("--------Program block:%2d...", n);
278 write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
279 printf("OK\r");
280 printf("--------Verify block:%2d...", n);
281 for (i = 0; i < BLOCK_SIZE; i += 2) {
282 if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
283 *temp++) {
284 value = 1;
285 result = 1;
286 }
287 }
288 if (value)
289 printf("failed\n");
290 else
291 printf("OK %3d%%\r",
292 (int)(
293 (n + 1 -
294 FLASH_START_POST_BLOCK) *
295 100 / (FLASH_END_POST_BLOCK -
296 FLASH_START_POST_BLOCK)));
297
298 temp = pbuf;
299 value = 0;
300 }
301 printf("\n");
302 if (result)
303 return -1;
304 else
305 return 0;
306}
307
308/****************************************************
309 * LED1 ---- PF6 LED2 ---- PF7 *
310 * LED3 ---- PF8 LED4 ---- PF9 *
311 * LED5 ---- PF10 LED6 ---- PF11 *
312 ****************************************************/
313int led_post_test(int flags)
314{
315 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
316 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
317 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
318 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
319 udelay(1000000);
320 printf("LED1 on");
321 *pPORTFIO |= PF6;
322 udelay(1000000);
323 printf("\b\b\b\b\b\b\b");
324 printf("LED2 on");
325 *pPORTFIO |= PF7;
326 udelay(1000000);
327 printf("\b\b\b\b\b\b\b");
328 printf("LED3 on");
329 *pPORTFIO |= PF8;
330 udelay(1000000);
331 printf("\b\b\b\b\b\b\b");
332 printf("LED4 on");
333 *pPORTFIO |= PF9;
334 udelay(1000000);
335 printf("\b\b\b\b\b\b\b");
336 printf("LED5 on");
337 *pPORTFIO |= PF10;
338 udelay(1000000);
339 printf("\b\b\b\b\b\b\b");
340 printf("lED6 on");
341 *pPORTFIO |= PF11;
342 printf("\b\b\b\b\b\b\b ");
343 return 0;
344}
345
346/************************************************
347 * SW10 ---- PF5 SW11 ---- PF4 *
348 * SW12 ---- PF3 SW13 ---- PF2 *
349 ************************************************/
350int button_post_test(int flags)
351{
352 int i, delay = 5;
353 unsigned short value = 0;
354 int result = 0;
355
356 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
357 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
358 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
359
360 printf("\n--------Press SW10: %2d ", delay);
361 while (delay--) {
362 for (i = 0; i < 100; i++) {
363 value = *pPORTFIO & PF5;
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 SW11: %2d ", delay);
380 while (delay--) {
381 for (i = 0; i < 100; i++) {
382 value = *pPORTFIO & PF4;
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
397 delay = 5;
398 printf("\n--------Press SW12: %2d ", delay);
399 while (delay--) {
400 for (i = 0; i < 100; i++) {
401 value = *pPORTFIO & PF3;
402 if (value != 0) {
403 break;
404 }
405 udelay(10000);
406 }
407 printf("\b\b\b%2d ", delay);
408 }
409 if (value != 0)
410 printf("\b\bOK");
411 else {
412 result = -1;
413 printf("\b\bfailed");
414 }
415
416 delay = 5;
417 printf("\n--------Press SW13: %2d ", delay);
418 while (delay--) {
419 for (i = 0; i < 100; i++) {
420 value = *pPORTFIO & PF2;
421 if (value != 0) {
422 break;
423 }
424 udelay(10000);
425 }
426 printf("\b\b\b%2d ", delay);
427 }
428 if (value != 0)
429 printf("\b\bOK");
430 else {
431 result = -1;
432 printf("\b\bfailed");
433 }
434 printf("\n");
435 return result;
436}
437#endif