blob: 5b619be11b390f90cceafa3f4ee4ef88615a4dac [file] [log] [blame]
Aubrey Li10ebdd92007-03-19 01:24:52 +08001/*
2 * U-boot - BF537.c
3 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li10ebdd92007-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 Li314d22f2007-04-05 18:31:18 +080024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
Aubrey Li10ebdd92007-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-VILLARDb9d57872007-12-10 22:32:14 +010033#include <net.h>
Mike Frysinger66c4cf42008-02-04 19:26:55 -050034#include <asm/mach-common/bits/bootrom.h>
Ben Warren2f2b6b62008-08-31 22:22:04 -070035#include <netdev.h>
Aubrey Li10ebdd92007-03-19 01:24:52 +080036
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020037DECLARE_GLOBAL_DATA_PTR;
38
Aubrey Li10ebdd92007-03-19 01:24:52 +080039#define POST_WORD_ADDR 0xFF903FFC
40
Aubrey Li10ebdd92007-03-19 01:24:52 +080041int checkboard(void)
42{
Aubrey Li10ebdd92007-03-19 01:24:52 +080043 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
50void cf_outb(unsigned char val, volatile unsigned char *addr)
51{
52 *(addr) = val;
Mike Frysinger66c4cf42008-02-04 19:26:55 -050053 SSYNC();
Aubrey Li10ebdd92007-03-19 01:24:52 +080054}
55
56unsigned char cf_inb(volatile unsigned char *addr)
57{
58 volatile unsigned char c;
59
60 c = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050061 SSYNC();
Aubrey Li10ebdd92007-03-19 01:24:52 +080062
63 return c;
64}
65
66void 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);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050072 SSYNC();
Aubrey Li10ebdd92007-03-19 01:24:52 +080073}
74
75void 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);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050081 SSYNC();
Aubrey Li10ebdd92007-03-19 01:24:52 +080082}
83#endif /* CONFIG_BFIN_IDE */
84
Becky Brucebd99ae72008-06-09 16:03:40 -050085phys_size_t initdram(int board_type)
Aubrey Li10ebdd92007-03-19 01:24:52 +080086{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
88 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
Mike Frysinger9036bf92008-10-11 20:31:17 -040089 return gd->bd->bi_memsize;
Aubrey Li10ebdd92007-03-19 01:24:52 +080090}
91
92#if defined(CONFIG_MISC_INIT_R)
93/* miscellaneous platform dependent initialisations */
94int misc_init_r(void)
95{
Mike Frysinger94bae5c2008-03-30 15:46:13 -040096#if defined(CONFIG_CMD_NET)
Aubrey Li10ebdd92007-03-19 01:24:52 +080097 char nid[32];
98 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
Aubrey Li10ebdd92007-03-19 01:24:52 +080099
Aubrey Li10ebdd92007-03-19 01:24:52 +0800100 /* 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 }
Jon Loeligerd299abc2007-07-09 18:19:09 -0500108#endif
Aubrey Li10ebdd92007-03-19 01:24:52 +0800109
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
Ben Warren82c2c6a2008-07-11 23:15:28 -0700130#if defined(CONFIG_BFIN_MAC)
131
Ben Warren82c2c6a2008-07-11 23:15:28 -0700132int board_eth_init(bd_t *bis)
133{
134 return bfin_EMAC_initialize(bis);
135}
136#endif
137
Aubrey Li10ebdd92007-03-19 01:24:52 +0800138#ifdef CONFIG_POST
Aubrey Li10ebdd92007-03-19 01:24:52 +0800139/* Using sw10-PF5 as the hotkey */
140int 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
Aubrey Li10ebdd92007-03-19 01:24:52 +0800171
172#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
173void post_word_store(ulong a)
174{
175 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
176 *save_addr = a;
177}
178
179ulong 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
187int uart_post_test(int flags)
188{
189 return 0;
190}
191
192#define BLOCK_SIZE 0x10000
193#define VERIFY_ADDR 0x2000000
194extern int erase_block_flash(int);
195extern int write_data(long lStart, long lCount, uchar * pnData);
196int 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);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200211 write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
Aubrey Li10ebdd92007-03-19 01:24:52 +0800212 printf("OK\r");
213 printf("--------Verify block:%2d...", n);
214 for (i = 0; i < BLOCK_SIZE; i += 2) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200215 if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
Aubrey Li10ebdd92007-03-19 01:24:52 +0800216 *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 ****************************************************/
246int 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 ************************************************/
283int 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