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