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