blob: a2269105bebdd6e594f862781692df035eedfeab [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
Mike Frysinger9427ef82008-10-11 22:40:22 -04002 * U-boot - main board file
Aubrey.Li9da597f2007-03-09 13:38:44 +08003 *
Mike Frysinger9427ef82008-10-11 22:40:22 -04004 * Copyright (c) 2005-2008 Analog Devices Inc.
Aubrey.Li9da597f2007-03-09 13:38:44 +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.Li9da597f2007-03-09 13:38:44 +080026 */
27
28#include <common.h>
Ben Warren0fd6aae2009-10-04 22:37:03 -070029#include <netdev.h>
Aubrey Li3c569952007-03-12 00:25:14 +080030#include <asm/io.h>
Aubrey.Li9da597f2007-03-09 13:38:44 +080031#include "bf533-stamp.h"
32
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020033DECLARE_GLOBAL_DATA_PTR;
34
Aubrey.Li9da597f2007-03-09 13:38:44 +080035int checkboard(void)
36{
Aubrey.Li9da597f2007-03-09 13:38:44 +080037 printf("Board: ADI BF533 Stamp board\n");
38 printf(" Support: http://blackfin.uclinux.org/\n");
39 return 0;
40}
41
Becky Brucebd99ae72008-06-09 16:03:40 -050042phys_size_t initdram(int board_type)
Aubrey.Li9da597f2007-03-09 13:38:44 +080043{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
45 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
Mike Frysinger9036bf92008-10-11 20:31:17 -040046 return gd->bd->bi_memsize;
Aubrey.Li9da597f2007-03-09 13:38:44 +080047}
48
Mike Frysinger942f0f592008-10-11 22:38:37 -040049/* PF0 and PF1 are used to switch between the ethernet and flash:
50 * PF0 PF1
51 * flash: 0 0
52 * ether: 1 0
53 */
Aubrey.Li9da597f2007-03-09 13:38:44 +080054void swap_to(int device_id)
55{
Mike Frysinger942f0f592008-10-11 22:38:37 -040056 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0);
57 SSYNC();
58 bfin_write_FIO_FLAG_C(PF1);
59 if (device_id == ETHERNET)
60 bfin_write_FIO_FLAG_S(PF0);
61 else if (device_id == FLASH)
62 bfin_write_FIO_FLAG_C(PF0);
63 else
64 printf("Unknown device to switch\n");
65 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080066}
67
68#if defined(CONFIG_MISC_INIT_R)
69/* miscellaneous platform dependent initialisations */
70int misc_init_r(void)
71{
72 int i;
73 int cf_stat = 0;
74
75 /* Check whether CF card is inserted */
76 *pFIO_EDGE = FIO_EDGE_CF_BITS;
77 *pFIO_POLAR = FIO_POLAR_CF_BITS;
78 for (i = 0; i < 0x300; i++)
79 asm("nop;");
80
81 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
82 cf_stat = 0;
83 } else {
84 cf_stat = 1;
85 }
86
87 *pFIO_EDGE = FIO_EDGE_BITS;
88 *pFIO_POLAR = FIO_POLAR_BITS;
89
90 if (cf_stat) {
91 printf("Booting from COMPACT flash\n");
92
Aubrey.Li9da597f2007-03-09 13:38:44 +080093 for (i = 0; i < 0x1000; i++)
94 asm("nop;");
95 for (i = 0; i < 0x1000; i++)
96 asm("nop;");
97 for (i = 0; i < 0x1000; i++)
98 asm("nop;");
99
100 serial_setbrg();
101 ide_init();
102
103 setenv("bootargs", "");
104 setenv("bootcmd",
105 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
106 } else {
107 printf("Booting from FLASH\n");
108 }
109
110 return 0;
111}
112#endif
113
114#ifdef CONFIG_STAMP_CF
115
116void cf_outb(unsigned char val, volatile unsigned char *addr)
117{
118 /*
119 * Set PF1 PF0 respectively to 0 1 to divert address
120 * to the expansion memory banks
121 */
122 *pFIO_FLAG_S = CF_PF0;
123 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500124 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800125
126 *(addr) = val;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500127 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800128
129 /* Setback PF1 PF0 to 0 0 to address external
130 * memory banks */
131 *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500132 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800133}
134
135unsigned char cf_inb(volatile unsigned char *addr)
136{
137 volatile unsigned char c;
138
139 *pFIO_FLAG_S = CF_PF0;
140 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500141 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800142
143 c = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500144 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800145
146 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500147 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800148
149 return c;
150}
151
152void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
153{
154 int i;
155
156 *pFIO_FLAG_S = CF_PF0;
157 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500158 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800159
160 for (i = 0; i < words; i++) {
161 *(sect_buf + i) = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500162 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800163 }
164
165 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500166 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800167}
168
169void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
170{
171 int i;
172
173 *pFIO_FLAG_S = CF_PF0;
174 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500175 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800176
177 for (i = 0; i < words; i++) {
178 *(addr) = *(sect_buf + i);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500179 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800180 }
181
182 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500183 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800184}
185#endif
186
Mike Frysinger9427ef82008-10-11 22:40:22 -0400187#ifdef CONFIG_SHOW_BOOT_PROGRESS
188
189#define STATUS_LED_OFF 0
190#define STATUS_LED_ON 1
191
192static void stamp_led_set(int LED1, int LED2, int LED3)
Aubrey.Li9da597f2007-03-09 13:38:44 +0800193{
Mike Frysinger9427ef82008-10-11 22:40:22 -0400194 bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
195 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
Aubrey.Li9da597f2007-03-09 13:38:44 +0800196
197 if (LED1 == STATUS_LED_OFF)
198 *pFIO_FLAG_S = PF2;
199 else
200 *pFIO_FLAG_C = PF2;
201 if (LED2 == STATUS_LED_OFF)
202 *pFIO_FLAG_S = PF3;
203 else
204 *pFIO_FLAG_C = PF3;
205 if (LED3 == STATUS_LED_OFF)
206 *pFIO_FLAG_S = PF4;
207 else
208 *pFIO_FLAG_C = PF4;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500209 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800210}
211
212void show_boot_progress(int status)
213{
214 switch (status) {
215 case 1:
216 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
217 break;
218 case 2:
219 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
220 break;
221 case 3:
222 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
223 break;
224 case 4:
225 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
226 break;
227 case 5:
228 case 6:
229 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
230 break;
231 case 7:
232 case 8:
233 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
234 break;
235 case 9:
236 case 10:
237 case 11:
238 case 12:
239 case 13:
240 case 14:
241 case 15:
242 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
243 break;
244 default:
245 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
246 break;
247 }
248}
Mike Frysinger9427ef82008-10-11 22:40:22 -0400249#endif
250
251#ifdef CONFIG_STATUS_LED
252#include <status_led.h>
253
254static void set_led(int pf, int state)
255{
256 switch (state) {
257 case STATUS_LED_OFF: bfin_write_FIO_FLAG_S(pf); break;
258 case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break;
259 case STATUS_LED_ON: bfin_write_FIO_FLAG_C(pf); break;
260 }
261}
262
263static void set_leds(led_id_t mask, int state)
264{
265 if (mask & 0x1) set_led(PF2, state);
266 if (mask & 0x2) set_led(PF3, state);
267 if (mask & 0x4) set_led(PF4, state);
268}
269
270void __led_init(led_id_t mask, int state)
271{
272 bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
273 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
274}
275
276void __led_set(led_id_t mask, int state)
277{
278 set_leds(mask, state);
279}
280
281void __led_toggle(led_id_t mask)
282{
283 set_leds(mask, STATUS_LED_BLINKING);
284}
285
286#endif
Ben Warren0fd6aae2009-10-04 22:37:03 -0700287
288#ifdef CONFIG_SMC91111
289int board_eth_init(bd_t *bis)
290{
291 return smc91111_initialize(0, CONFIG_SMC91111_BASE);
292}
293#endif