blob: 7a63c527ed06668c939d3d0a71c5cc3c37c116c5 [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
Mike Frysinger942f0f592008-10-11 22:38:37 -040042/* PF0 and PF1 are used to switch between the ethernet and flash:
43 * PF0 PF1
44 * flash: 0 0
45 * ether: 1 0
46 */
Aubrey.Li9da597f2007-03-09 13:38:44 +080047void swap_to(int device_id)
48{
Mike Frysinger942f0f592008-10-11 22:38:37 -040049 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0);
50 SSYNC();
51 bfin_write_FIO_FLAG_C(PF1);
52 if (device_id == ETHERNET)
53 bfin_write_FIO_FLAG_S(PF0);
54 else if (device_id == FLASH)
55 bfin_write_FIO_FLAG_C(PF0);
56 else
57 printf("Unknown device to switch\n");
58 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080059}
60
61#if defined(CONFIG_MISC_INIT_R)
62/* miscellaneous platform dependent initialisations */
63int misc_init_r(void)
64{
65 int i;
66 int cf_stat = 0;
67
68 /* Check whether CF card is inserted */
69 *pFIO_EDGE = FIO_EDGE_CF_BITS;
70 *pFIO_POLAR = FIO_POLAR_CF_BITS;
71 for (i = 0; i < 0x300; i++)
72 asm("nop;");
73
74 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
75 cf_stat = 0;
76 } else {
77 cf_stat = 1;
78 }
79
80 *pFIO_EDGE = FIO_EDGE_BITS;
81 *pFIO_POLAR = FIO_POLAR_BITS;
82
83 if (cf_stat) {
84 printf("Booting from COMPACT flash\n");
85
Aubrey.Li9da597f2007-03-09 13:38:44 +080086 for (i = 0; i < 0x1000; i++)
87 asm("nop;");
88 for (i = 0; i < 0x1000; i++)
89 asm("nop;");
90 for (i = 0; i < 0x1000; i++)
91 asm("nop;");
92
93 serial_setbrg();
94 ide_init();
95
96 setenv("bootargs", "");
97 setenv("bootcmd",
98 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
99 } else {
100 printf("Booting from FLASH\n");
101 }
102
103 return 0;
104}
105#endif
106
107#ifdef CONFIG_STAMP_CF
108
109void cf_outb(unsigned char val, volatile unsigned char *addr)
110{
111 /*
112 * Set PF1 PF0 respectively to 0 1 to divert address
113 * to the expansion memory banks
114 */
115 *pFIO_FLAG_S = CF_PF0;
116 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500117 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800118
119 *(addr) = val;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500120 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800121
122 /* Setback PF1 PF0 to 0 0 to address external
123 * memory banks */
124 *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500125 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800126}
127
128unsigned char cf_inb(volatile unsigned char *addr)
129{
130 volatile unsigned char c;
131
132 *pFIO_FLAG_S = CF_PF0;
133 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500134 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800135
136 c = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500137 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800138
139 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500140 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800141
142 return c;
143}
144
145void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
146{
147 int i;
148
149 *pFIO_FLAG_S = CF_PF0;
150 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500151 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800152
153 for (i = 0; i < words; i++) {
154 *(sect_buf + i) = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500155 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800156 }
157
158 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500159 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800160}
161
162void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
163{
164 int i;
165
166 *pFIO_FLAG_S = CF_PF0;
167 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500168 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800169
170 for (i = 0; i < words; i++) {
171 *(addr) = *(sect_buf + i);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500172 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800173 }
174
175 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500176 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800177}
178#endif
179
Mike Frysinger9427ef82008-10-11 22:40:22 -0400180#ifdef CONFIG_SHOW_BOOT_PROGRESS
181
182#define STATUS_LED_OFF 0
183#define STATUS_LED_ON 1
184
185static void stamp_led_set(int LED1, int LED2, int LED3)
Aubrey.Li9da597f2007-03-09 13:38:44 +0800186{
Mike Frysinger9427ef82008-10-11 22:40:22 -0400187 bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
188 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
Aubrey.Li9da597f2007-03-09 13:38:44 +0800189
190 if (LED1 == STATUS_LED_OFF)
191 *pFIO_FLAG_S = PF2;
192 else
193 *pFIO_FLAG_C = PF2;
194 if (LED2 == STATUS_LED_OFF)
195 *pFIO_FLAG_S = PF3;
196 else
197 *pFIO_FLAG_C = PF3;
198 if (LED3 == STATUS_LED_OFF)
199 *pFIO_FLAG_S = PF4;
200 else
201 *pFIO_FLAG_C = PF4;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500202 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800203}
204
205void show_boot_progress(int status)
206{
207 switch (status) {
208 case 1:
209 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
210 break;
211 case 2:
212 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
213 break;
214 case 3:
215 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
216 break;
217 case 4:
218 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
219 break;
220 case 5:
221 case 6:
222 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
223 break;
224 case 7:
225 case 8:
226 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
227 break;
228 case 9:
229 case 10:
230 case 11:
231 case 12:
232 case 13:
233 case 14:
234 case 15:
235 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
236 break;
237 default:
238 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
239 break;
240 }
241}
Mike Frysinger9427ef82008-10-11 22:40:22 -0400242#endif
243
244#ifdef CONFIG_STATUS_LED
245#include <status_led.h>
246
247static void set_led(int pf, int state)
248{
249 switch (state) {
250 case STATUS_LED_OFF: bfin_write_FIO_FLAG_S(pf); break;
251 case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break;
252 case STATUS_LED_ON: bfin_write_FIO_FLAG_C(pf); break;
253 }
254}
255
256static void set_leds(led_id_t mask, int state)
257{
258 if (mask & 0x1) set_led(PF2, state);
259 if (mask & 0x2) set_led(PF3, state);
260 if (mask & 0x4) set_led(PF4, state);
261}
262
263void __led_init(led_id_t mask, int state)
264{
265 bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
266 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
267}
268
269void __led_set(led_id_t mask, int state)
270{
271 set_leds(mask, state);
272}
273
274void __led_toggle(led_id_t mask)
275{
276 set_leds(mask, STATUS_LED_BLINKING);
277}
278
279#endif
Ben Warren0fd6aae2009-10-04 22:37:03 -0700280
281#ifdef CONFIG_SMC91111
282int board_eth_init(bd_t *bis)
283{
284 return smc91111_initialize(0, CONFIG_SMC91111_BASE);
285}
286#endif